From bf906a7867ed9a1d2633169868a802d6889fd3f7 Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Sun, 7 Apr 2013 21:05:52 +0200 Subject: [PATCH] Open url when an entry is activated via its url column. Closes #55 --- src/gui/DatabaseWidget.cpp | 10 ++++++++-- src/gui/DatabaseWidget.h | 1 + src/gui/entry/EntryView.cpp | 13 ++++++++++--- src/gui/entry/EntryView.h | 3 ++- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 277853e5b..08e580f32 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -138,6 +138,7 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent) connect(m_groupView, SIGNAL(groupChanged(Group*)), SIGNAL(groupChanged())); connect(m_groupView, SIGNAL(groupChanged(Group*)), m_entryView, SLOT(setGroup(Group*))); connect(m_entryView, SIGNAL(entryActivated(Entry*)), SLOT(switchToEntryEdit(Entry*))); + connect(m_entryView, SIGNAL(openUrl(Entry*)), SLOT(openUrlForEntry(Entry*))); connect(m_entryView, SIGNAL(entrySelectionChanged()), SIGNAL(entrySelectionChanged())); connect(m_editEntryWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool))); connect(m_editEntryWidget, SIGNAL(historyEntryActivated(Entry*)), SLOT(switchToHistoryView(Entry*))); @@ -303,8 +304,13 @@ void DatabaseWidget::openUrl() return; } - if (!currentEntry->url().isEmpty()) { - QDesktopServices::openUrl(currentEntry->url()); + openUrlForEntry(currentEntry); +} + +void DatabaseWidget::openUrlForEntry(Entry* entry) +{ + if (!entry->url().isEmpty()) { + QDesktopServices::openUrl(entry->url()); } } diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index a39b085da..2f323dd10 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -89,6 +89,7 @@ public Q_SLOTS: void copyAttribute(QAction* action); void performAutoType(); void openUrl(); + void openUrlForEntry(Entry* entry); void createGroup(); void deleteGroup(); void switchToEntryEdit(); diff --git a/src/gui/entry/EntryView.cpp b/src/gui/entry/EntryView.cpp index 243037a21..c603bcad3 100644 --- a/src/gui/entry/EntryView.cpp +++ b/src/gui/entry/EntryView.cpp @@ -43,7 +43,7 @@ EntryView::EntryView(QWidget* parent) // QAbstractItemView::startDrag() uses this property as the default drag action setDefaultDropAction(Qt::MoveAction); - connect(this, SIGNAL(activated(QModelIndex)), SLOT(emitEntryActivated(QModelIndex))); + connect(this, SIGNAL(activated(QModelIndex)), SLOT(emitEntryActivationSignal(QModelIndex))); connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SIGNAL(entrySelectionChanged())); connect(m_model, SIGNAL(switchedToEntryListMode()), SLOT(switchToEntryListMode())); connect(m_model, SIGNAL(switchedToGroupMode()), SLOT(switchToGroupMode())); @@ -66,9 +66,16 @@ bool EntryView::inEntryListMode() return m_inEntryListMode; } -void EntryView::emitEntryActivated(const QModelIndex& index) +void EntryView::emitEntryActivationSignal(const QModelIndex& index) { - Q_EMIT entryActivated(entryFromIndex(index)); + Entry* entry = entryFromIndex(index); + + if (m_sortModel->mapToSource(index).column() == 3) { + Q_EMIT openUrl(entry); + } + else { + Q_EMIT entryActivated(entry); + } } void EntryView::setModel(QAbstractItemModel* model) diff --git a/src/gui/entry/EntryView.h b/src/gui/entry/EntryView.h index 125a4b858..a92f0ef07 100644 --- a/src/gui/entry/EntryView.h +++ b/src/gui/entry/EntryView.h @@ -46,10 +46,11 @@ public Q_SLOTS: Q_SIGNALS: void entryActivated(Entry* entry); + void openUrl(Entry* entry); void entrySelectionChanged(); private Q_SLOTS: - void emitEntryActivated(const QModelIndex& index); + void emitEntryActivationSignal(const QModelIndex& index); void switchToEntryListMode(); void switchToGroupMode();