diff --git a/src/gui/DatabaseManager.cpp b/src/gui/DatabaseManager.cpp index 999c1cd16..f94843682 100644 --- a/src/gui/DatabaseManager.cpp +++ b/src/gui/DatabaseManager.cpp @@ -25,6 +25,7 @@ #include "format/KeePass2XmlReader.h" #include "gui/DatabaseWidget.h" #include "gui/FileDialog.h" +#include "gui/EntryView.h" #include "gui/GroupView.h" #include "gui/KeyOpenDialog.h" @@ -41,6 +42,7 @@ DatabaseManager::DatabaseManager(QTabWidget* tabWidget) , m_window(tabWidget->window()) { connect(m_tabWidget, SIGNAL(tabCloseRequested(int)), SLOT(closeDatabase(int))); + connect(m_tabWidget, SIGNAL(currentChanged(int)), SLOT(emitEntrySelectionChanged())); } void DatabaseManager::newDatabase() @@ -119,6 +121,18 @@ void DatabaseManager::openDatabaseCleanup() m_curDbStruct = DatabaseManagerStruct(); } +void DatabaseManager::emitEntrySelectionChanged() +{ + Database* db = indexDatabase(m_tabWidget->currentIndex()); + + bool isSingleEntrySelected = false; + if (db) { + isSingleEntrySelected = m_dbList[db].dbWidget->entryView()->isSingleEntrySelected(); + } + + Q_EMIT entrySelectionChanged(isSingleEntrySelected); +} + void DatabaseManager::closeDatabase(Database* db) { Q_ASSERT(db); @@ -216,6 +230,13 @@ void DatabaseManager::createEntry() dbWidget->createEntry(); } +void DatabaseManager::editEntry() +{ + Database* db = indexDatabase(m_tabWidget->currentIndex()); + DatabaseWidget* dbWidget = m_dbList[db].dbWidget; + dbWidget->switchToEntryEdit(); +} + void DatabaseManager::createGroup() { Database* db = indexDatabase(m_tabWidget->currentIndex()); @@ -294,4 +315,5 @@ void DatabaseManager::insertDatabase(Database* db, const DatabaseManagerStruct& m_tabWidget->setCurrentIndex(index); connect(db->metadata(), SIGNAL(nameTextChanged(Database*)), SLOT(updateTabName(Database*))); + connect(dbStruct.dbWidget->entryView(), SIGNAL(entrySelectionChanged()), SLOT(emitEntrySelectionChanged())); } diff --git a/src/gui/DatabaseManager.h b/src/gui/DatabaseManager.h index 80838e852..0627489bc 100644 --- a/src/gui/DatabaseManager.h +++ b/src/gui/DatabaseManager.h @@ -58,6 +58,7 @@ public Q_SLOTS: void saveDatabaseAs(int index = -1); void closeDatabase(int index = -1); void createEntry(); + void editEntry(); void createGroup(); void editGroup(); @@ -66,6 +67,10 @@ private Q_SLOTS: void openDatabaseDialog(); void openDatabaseRead(); void openDatabaseCleanup(); + void emitEntrySelectionChanged(); + +Q_SIGNALS: + void entrySelectionChanged(bool singleEntrySelected); private: int databaseIndex(Database* db); diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index c958807d0..e7f34f907 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -140,7 +140,7 @@ void DatabaseWidget::switchToGroupEdit(Group* group, bool create) } void DatabaseWidget::switchToEntryEdit() { - // TODO switchToEntryEdit(m_entryView->currentEntry(), false); + switchToEntryEdit(m_entryView->currentEntry(), false); } void DatabaseWidget::switchToGroupEdit() diff --git a/src/gui/EntryView.cpp b/src/gui/EntryView.cpp index e2d216d77..2c4695e29 100644 --- a/src/gui/EntryView.cpp +++ b/src/gui/EntryView.cpp @@ -29,6 +29,7 @@ EntryView::EntryView(QWidget* parent) setRootIsDecorated(false); connect(this, SIGNAL(activated(const QModelIndex&)), SLOT(emitEntryActivated(const QModelIndex&))); + connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SIGNAL(entrySelectionChanged())); } void EntryView::setGroup(Group* group) @@ -46,3 +47,14 @@ void EntryView::setModel(QAbstractItemModel* model) Q_UNUSED(model); Q_ASSERT(false); } + +Entry* EntryView::currentEntry() +{ + // TODO use selection instead of current? + return m_model->entryFromIndex(currentIndex()); +} + +bool EntryView::isSingleEntrySelected() +{ + return (selectionModel()->selectedRows().size() == 1); +} diff --git a/src/gui/EntryView.h b/src/gui/EntryView.h index a7d27495f..7eef18bd9 100644 --- a/src/gui/EntryView.h +++ b/src/gui/EntryView.h @@ -31,6 +31,8 @@ class EntryView : public QTreeView public: explicit EntryView(QWidget* parent = 0); void setModel(QAbstractItemModel* model); + Entry* currentEntry(); + bool isSingleEntrySelected(); public Q_SLOTS: void setGroup(Group* group); @@ -40,6 +42,7 @@ private Q_SLOTS: Q_SIGNALS: void entryActivated(Entry* entry); + void entrySelectionChanged(); private: EntryModel* m_model; diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index c02e1d3b5..0adb11f86 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -31,6 +31,8 @@ MainWindow::MainWindow() m_dbManager = new DatabaseManager(m_ui->tabWidget); connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(currentTabChanged(int))); + connect(m_dbManager, SIGNAL(entrySelectionChanged(bool)), m_ui->actionEntryEdit, SLOT(setEnabled(bool))); + connect(m_dbManager, SIGNAL(entrySelectionChanged(bool)), m_ui->actionEntryDelete, SLOT(setEnabled(bool))); connect(m_ui->actionDatabaseNew, SIGNAL(triggered()), m_dbManager, SLOT(newDatabase())); connect(m_ui->actionDatabaseOpen, SIGNAL(triggered()), m_dbManager, SLOT(openDatabase())); @@ -38,6 +40,7 @@ MainWindow::MainWindow() connect(m_ui->actionDatabaseSaveAs, SIGNAL(triggered()), m_dbManager, SLOT(saveDatabaseAs())); connect(m_ui->actionDatabaseClose, SIGNAL(triggered()), m_dbManager, SLOT(closeDatabase())); connect(m_ui->actionEntryNew, SIGNAL(triggered()), m_dbManager, SLOT(createEntry())); + connect(m_ui->actionEntryEdit, SIGNAL(triggered()), m_dbManager, SLOT(editEntry())); connect(m_ui->actionGroupNew, SIGNAL(triggered()), m_dbManager, SLOT(createGroup())); connect(m_ui->actionGroupEdit, SIGNAL(triggered()), m_dbManager, SLOT(editGroup())); connect(m_ui->actionQuit, SIGNAL(triggered()), SLOT(close()));