diff options
author | Jonathan White <support@dmapps.us> | 2019-05-18 17:55:57 +0300 |
---|---|---|
committer | Jonathan White <support@dmapps.us> | 2019-05-19 07:20:43 +0300 |
commit | ecaa4fd6ce917c9b2dabf780d59503503ec55769 (patch) | |
tree | 00ccc2ad44bde050f4de0961d249ad8146ce49ae /src/gui | |
parent | baa55d15971d9213bae0f7dc0b6aeb3059463c99 (diff) |
Fix opening url's with non-http schema
* Fix #2427
* Changed the openUrl() function to use a QUrl object, which has the appropriate scheme set.
* Preview widget now passes url handling back to DatabaseWidget
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/DatabaseWidget.cpp | 15 | ||||
-rw-r--r-- | src/gui/EntryPreviewWidget.cpp | 14 | ||||
-rw-r--r-- | src/gui/EntryPreviewWidget.h | 2 |
3 files changed, 24 insertions, 7 deletions
diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index e4f175bf2..0d200848d 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -174,7 +174,8 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> db, QWidget* parent) connect(m_mainSplitter, SIGNAL(splitterMoved(int,int)), SIGNAL(mainSplitterSizesChanged())); connect(m_previewSplitter, SIGNAL(splitterMoved(int,int)), SIGNAL(previewSplitterSizesChanged())); connect(this, SIGNAL(currentModeChanged(DatabaseWidget::Mode)), m_previewView, SLOT(setDatabaseMode(DatabaseWidget::Mode))); - connect(m_previewView, SIGNAL(errorOccurred(QString)), this, SLOT(showErrorMessage(QString))); + connect(m_previewView, SIGNAL(errorOccurred(QString)), SLOT(showErrorMessage(QString))); + connect(m_previewView, SIGNAL(entryUrlActivated(Entry*)), SLOT(openUrlForEntry(Entry*))); connect(m_entryView, SIGNAL(viewStateChanged()), SIGNAL(entryViewStateChanged())); connect(m_groupView, SIGNAL(groupSelectionChanged(Group*)), SLOT(onGroupChanged(Group*))); connect(m_groupView, SIGNAL(groupSelectionChanged(Group*)), SIGNAL(groupChanged())); @@ -190,7 +191,7 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> db, QWidget* parent) connect(m_keepass1OpenWidget, SIGNAL(dialogFinished(bool)), SLOT(loadDatabase(bool))); connect(m_csvImportWizard, SIGNAL(importFinished(bool)), SLOT(csvImportFinished(bool))); connect(m_fileWatcher.data(), SIGNAL(fileChanged()), this, SLOT(reloadDatabaseFile())); - connect(this, SIGNAL(currentChanged(int)), this, SLOT(emitCurrentModeChanged())); + connect(this, SIGNAL(currentChanged(int)), SLOT(emitCurrentModeChanged())); // clang-format on connectDatabaseSignals(); @@ -652,6 +653,10 @@ void DatabaseWidget::openUrl() void DatabaseWidget::openUrlForEntry(Entry* entry) { Q_ASSERT(entry); + if (!entry) { + return; + } + QString cmdString = entry->resolveMultiplePlaceholders(entry->url()); if (cmdString.startsWith("cmd://")) { // check if decision to execute command was stored @@ -695,9 +700,9 @@ void DatabaseWidget::openUrlForEntry(Entry* entry) } } } else { - QString urlString = entry->webUrl(); - if (!urlString.isEmpty()) { - QDesktopServices::openUrl(urlString); + QUrl url = QUrl(entry->url()); + if (!url.isEmpty()) { + QDesktopServices::openUrl(url); } } } diff --git a/src/gui/EntryPreviewWidget.cpp b/src/gui/EntryPreviewWidget.cpp index 0fd8826c8..c90d0aa67 100644 --- a/src/gui/EntryPreviewWidget.cpp +++ b/src/gui/EntryPreviewWidget.cpp @@ -54,11 +54,13 @@ EntryPreviewWidget::EntryPreviewWidget(QWidget* parent) m_ui->entryAttachmentsWidget->setReadOnly(true); m_ui->entryAttachmentsWidget->setButtonsVisible(false); + connect(m_ui->entryUrlLabel, SIGNAL(linkActivated(QString)), SLOT(openEntryUrl())); + connect(m_ui->entryTotpButton, SIGNAL(toggled(bool)), m_ui->entryTotpWidget, SLOT(setVisible(bool))); connect(m_ui->entryCloseButton, SIGNAL(clicked()), SLOT(hide())); connect(m_ui->togglePasswordButton, SIGNAL(clicked(bool)), SLOT(setPasswordVisible(bool))); connect(m_ui->entryTabWidget, SIGNAL(tabBarClicked(int)), SLOT(updateTabIndexes()), Qt::QueuedConnection); - connect(&m_totpTimer, SIGNAL(timeout()), this, SLOT(updateTotpLabel())); + connect(&m_totpTimer, SIGNAL(timeout()), SLOT(updateTotpLabel())); // Group m_ui->groupCloseButton->setIcon(filePath()->icon("actions", "dialog-close")); @@ -197,11 +199,12 @@ void EntryPreviewWidget::updateEntryGeneralTab() } m_ui->entryUrlLabel->setRawText(m_currentEntry->displayUrl()); - const QString url = m_currentEntry->webUrl(); + const QString url = m_currentEntry->url(); if (!url.isEmpty()) { // URL is well formed and can be opened in a browser m_ui->entryUrlLabel->setUrl(url); m_ui->entryUrlLabel->setCursor(Qt::PointingHandCursor); + m_ui->entryUrlLabel->setOpenExternalLinks(false); } else { m_ui->entryUrlLabel->setUrl({}); m_ui->entryUrlLabel->setCursor(Qt::ArrowCursor); @@ -327,6 +330,13 @@ void EntryPreviewWidget::updateTabIndexes() m_selectedTabGroup = m_ui->groupTabWidget->currentIndex(); } +void EntryPreviewWidget::openEntryUrl() +{ + if (m_currentEntry) { + emit entryUrlActivated(m_currentEntry); + } +} + void EntryPreviewWidget::setTabEnabled(QTabWidget* tabWidget, QWidget* widget, bool enabled) { const int tabIndex = tabWidget->indexOf(widget); diff --git a/src/gui/EntryPreviewWidget.h b/src/gui/EntryPreviewWidget.h index 5bfd9dbd6..6a50c0feb 100644 --- a/src/gui/EntryPreviewWidget.h +++ b/src/gui/EntryPreviewWidget.h @@ -43,6 +43,7 @@ public slots: signals: void errorOccurred(const QString& error); + void entryUrlActivated(Entry* entry); private slots: void updateEntryHeaderLine(); @@ -63,6 +64,7 @@ private slots: void updateTotpLabel(); void updateTabIndexes(); + void openEntryUrl(); private: void setTabEnabled(QTabWidget* tabWidget, QWidget* widget, bool enabled); |