mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-25 17:01:17 -05:00
Implement drag&drop support in main form to open database files
This commit is contained in:
parent
cdaf25cb3e
commit
7b9b23b143
@ -114,6 +114,8 @@ MainWindow::MainWindow()
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
setAcceptDrops(true);
|
||||
|
||||
m_ui->toolBar->setContextMenuPolicy(Qt::PreventContextMenu);
|
||||
|
||||
// Setup the search widget in the toolbar
|
||||
@ -997,3 +999,39 @@ void MainWindow::handleScreenLock()
|
||||
lockDatabasesAfterInactivity();
|
||||
}
|
||||
}
|
||||
|
||||
QStringList MainWindow::kdbxFilesFromUrls(const QList<QUrl>& urls)
|
||||
{
|
||||
QStringList kdbxFiles;
|
||||
for (const QUrl& url: urls) {
|
||||
const QFileInfo fInfo(url.toLocalFile());
|
||||
const bool isKdbxFile = fInfo.isFile() && fInfo.suffix().toLower() == "kdbx";
|
||||
if (isKdbxFile) {
|
||||
kdbxFiles.append(fInfo.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
|
||||
return kdbxFiles;
|
||||
}
|
||||
|
||||
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
|
||||
{
|
||||
const QMimeData* mimeData = event->mimeData();
|
||||
if (mimeData->hasUrls()) {
|
||||
const QStringList kdbxFiles = kdbxFilesFromUrls(mimeData->urls());
|
||||
if (!kdbxFiles.isEmpty()) {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::dropEvent(QDropEvent* event)
|
||||
{
|
||||
const QMimeData* mimeData = event->mimeData();
|
||||
if (mimeData->hasUrls()) {
|
||||
const QStringList kdbxFiles = kdbxFilesFromUrls(mimeData->urls());
|
||||
for(const QString &kdbxFile: kdbxFiles) {
|
||||
openDatabase(kdbxFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,10 @@ private:
|
||||
void updateTrayIcon();
|
||||
bool isTrayIconEnabled() const;
|
||||
|
||||
static QStringList kdbxFilesFromUrls(const QList<QUrl>& urls);
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
|
||||
const QScopedPointer<Ui::MainWindow> m_ui;
|
||||
SignalMultiplexer m_actionMultiplexer;
|
||||
QAction* m_clearHistoryAction;
|
||||
|
Loading…
x
Reference in New Issue
Block a user