diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 10eb8fd83..79fadb40f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -46,7 +46,7 @@ set(keepassx_SOURCES format/KeePass2Writer.cpp format/KeePass2XmlReader.cpp format/KeePass2XmlWriter.cpp - gui/DatabaseManager.cpp + gui/DatabaseTabWidget.cpp gui/DatabaseWidget.cpp gui/EditEntryWidget.cpp gui/EditGroupWidget.cpp @@ -72,7 +72,7 @@ set(keepassx_MOC core/Entry.h core/Group.h core/Metadata.h - gui/DatabaseManager.h + gui/DatabaseTabWidget.h gui/DatabaseWidget.h gui/EditEntryWidget.h gui/EditGroupWidget.h diff --git a/src/gui/DatabaseManager.cpp b/src/gui/DatabaseTabWidget.cpp similarity index 76% rename from src/gui/DatabaseManager.cpp rename to src/gui/DatabaseTabWidget.cpp index 29063447a..847bd7e86 100644 --- a/src/gui/DatabaseManager.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -#include "DatabaseManager.h" +#include "DatabaseTabWidget.h" #include #include @@ -37,24 +37,24 @@ DatabaseManagerStruct::DatabaseManagerStruct() { } -DatabaseManager::DatabaseManager(QTabWidget* tabWidget) - : m_tabWidget(tabWidget) - , m_window(tabWidget->window()) +DatabaseTabWidget::DatabaseTabWidget(QWidget* parent) + : QTabWidget(parent) + , m_window(parent->window()) { - connect(m_tabWidget, SIGNAL(tabCloseRequested(int)), SLOT(closeDatabase(int))); - connect(m_tabWidget, SIGNAL(currentChanged(int)), SLOT(emitEntrySelectionChanged())); + connect(this, SIGNAL(tabCloseRequested(int)), SLOT(closeDatabase(int))); + connect(this, SIGNAL(currentChanged(int)), SLOT(emitEntrySelectionChanged())); } -void DatabaseManager::newDatabase() +void DatabaseTabWidget::newDatabase() { DatabaseManagerStruct dbStruct; Database* db = new Database(); - dbStruct.dbWidget = new DatabaseWidget(db, m_tabWidget); + dbStruct.dbWidget = new DatabaseWidget(db, this); insertDatabase(db, dbStruct); } -void DatabaseManager::openDatabase() +void DatabaseTabWidget::openDatabase() { QString fileName = fileDialog()->getOpenFileName(m_window, tr("Open database"), QString(), tr("KeePass 2 Database").append(" (*.kdbx)")); @@ -63,7 +63,7 @@ void DatabaseManager::openDatabase() } } -void DatabaseManager::openDatabase(const QString& fileName) +void DatabaseTabWidget::openDatabase(const QString& fileName) { QScopedPointer file(new QFile(fileName)); // TODO error handling @@ -84,7 +84,7 @@ void DatabaseManager::openDatabase(const QString& fileName) openDatabaseDialog(); } -void DatabaseManager::openDatabaseDialog() +void DatabaseTabWidget::openDatabaseDialog() { m_curKeyDialog = new KeyOpenDialog(m_curDbStruct.fileName, m_window); connect(m_curKeyDialog, SIGNAL(accepted()), SLOT(openDatabaseRead())); @@ -93,7 +93,7 @@ void DatabaseManager::openDatabaseDialog() m_curKeyDialog->show(); } -void DatabaseManager::openDatabaseRead() +void DatabaseTabWidget::openDatabaseRead() { m_curDbStruct.file->reset(); Database* db = m_reader.readDatabase(m_curDbStruct.file, m_curKeyDialog->key()); @@ -104,13 +104,13 @@ void DatabaseManager::openDatabaseRead() openDatabaseDialog(); } else { - m_curDbStruct.dbWidget = new DatabaseWidget(db, m_tabWidget); + m_curDbStruct.dbWidget = new DatabaseWidget(db, this); insertDatabase(db, m_curDbStruct); m_curDbStruct = DatabaseManagerStruct(); } } -void DatabaseManager::openDatabaseCleanup() +void DatabaseTabWidget::openDatabaseCleanup() { delete m_curKeyDialog; m_curKeyDialog = 0; @@ -121,7 +121,7 @@ void DatabaseManager::openDatabaseCleanup() m_curDbStruct = DatabaseManagerStruct(); } -void DatabaseManager::emitEntrySelectionChanged() +void DatabaseTabWidget::emitEntrySelectionChanged() { DatabaseWidget* dbWidget = currentDatabaseWidget(); @@ -133,7 +133,7 @@ void DatabaseManager::emitEntrySelectionChanged() Q_EMIT entrySelectionChanged(isSingleEntrySelected); } -void DatabaseManager::closeDatabase(Database* db) +void DatabaseTabWidget::closeDatabase(Database* db) { Q_ASSERT(db); @@ -146,12 +146,12 @@ void DatabaseManager::closeDatabase(Database* db) int index = databaseIndex(db); Q_ASSERT(index != -1); - m_tabWidget->removeTab(index); + removeTab(index); delete dbStruct.dbWidget; delete db; } -void DatabaseManager::saveDatabase(Database* db) +void DatabaseTabWidget::saveDatabase(Database* db) { DatabaseManagerStruct& dbStruct = m_dbList[db]; @@ -170,7 +170,7 @@ void DatabaseManager::saveDatabase(Database* db) } } -void DatabaseManager::saveDatabaseAs(Database* db) +void DatabaseTabWidget::saveDatabaseAs(Database* db) { DatabaseManagerStruct& dbStruct = m_dbList[db]; QString oldFileName; @@ -197,53 +197,53 @@ void DatabaseManager::saveDatabaseAs(Database* db) } } -void DatabaseManager::closeDatabase(int index) +void DatabaseTabWidget::closeDatabase(int index) { if (index == -1) { - index = m_tabWidget->currentIndex(); + index = currentIndex(); } closeDatabase(indexDatabase(index)); } -void DatabaseManager::saveDatabase(int index) +void DatabaseTabWidget::saveDatabase(int index) { if (index == -1) { - index = m_tabWidget->currentIndex(); + index = currentIndex(); } saveDatabase(indexDatabase(index)); } -void DatabaseManager::saveDatabaseAs(int index) +void DatabaseTabWidget::saveDatabaseAs(int index) { if (index == -1) { - index = m_tabWidget->currentIndex(); + index = currentIndex(); } saveDatabaseAs(indexDatabase(index)); } -void DatabaseManager::createEntry() +void DatabaseTabWidget::createEntry() { currentDatabaseWidget()->createEntry(); } -void DatabaseManager::editEntry() +void DatabaseTabWidget::editEntry() { currentDatabaseWidget()->switchToEntryEdit(); } -void DatabaseManager::createGroup() +void DatabaseTabWidget::createGroup() { currentDatabaseWidget()->createGroup(); } -void DatabaseManager::editGroup() +void DatabaseTabWidget::editGroup() { currentDatabaseWidget()->switchToGroupEdit(); } -void DatabaseManager::updateTabName(Database* db) +void DatabaseTabWidget::updateTabName(Database* db) { int index = databaseIndex(db); Q_ASSERT(index != -1); @@ -262,7 +262,7 @@ void DatabaseManager::updateTabName(Database* db) tabName = db->metadata()->name(); } - m_tabWidget->setTabToolTip(index, dbStruct.fileName); + setTabToolTip(index, dbStruct.fileName); } else { if (db->metadata()->name().isEmpty()) { @@ -273,18 +273,18 @@ void DatabaseManager::updateTabName(Database* db) } } - m_tabWidget->setTabText(index, tabName); + setTabText(index, tabName); } -int DatabaseManager::databaseIndex(Database* db) +int DatabaseTabWidget::databaseIndex(Database* db) { QWidget* dbWidget = m_dbList.value(db).dbWidget; - return m_tabWidget->indexOf(dbWidget); + return indexOf(dbWidget); } -Database* DatabaseManager::indexDatabase(int index) +Database* DatabaseTabWidget::indexDatabase(int index) { - QWidget* dbWidget = m_tabWidget->widget(index); + QWidget* dbWidget = widget(index); QHashIterator i(m_dbList); while (i.hasNext()) { @@ -297,22 +297,22 @@ Database* DatabaseManager::indexDatabase(int index) return 0; } -void DatabaseManager::insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct) +void DatabaseTabWidget::insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct) { m_dbList.insert(db, dbStruct); - m_tabWidget->addTab(dbStruct.dbWidget, ""); + addTab(dbStruct.dbWidget, ""); updateTabName(db); int index = databaseIndex(db); - m_tabWidget->setCurrentIndex(index); + setCurrentIndex(index); connect(db->metadata(), SIGNAL(nameTextChanged(Database*)), SLOT(updateTabName(Database*))); connect(dbStruct.dbWidget->entryView(), SIGNAL(entrySelectionChanged()), SLOT(emitEntrySelectionChanged())); } -DatabaseWidget* DatabaseManager::currentDatabaseWidget() +DatabaseWidget* DatabaseTabWidget::currentDatabaseWidget() { - Database* db = indexDatabase(m_tabWidget->currentIndex()); + Database* db = indexDatabase(currentIndex()); if (db) { return m_dbList[db].dbWidget; } diff --git a/src/gui/DatabaseManager.h b/src/gui/DatabaseTabWidget.h similarity index 95% rename from src/gui/DatabaseManager.h rename to src/gui/DatabaseTabWidget.h index 90ceb1baa..2c42be2b3 100644 --- a/src/gui/DatabaseManager.h +++ b/src/gui/DatabaseTabWidget.h @@ -20,6 +20,7 @@ #include #include +#include #include "format/KeePass2Reader.h" #include "format/KeePass2Writer.h" @@ -40,12 +41,12 @@ struct DatabaseManagerStruct bool readOnly; }; -class DatabaseManager : public QObject +class DatabaseTabWidget : public QTabWidget { Q_OBJECT public: - DatabaseManager(QTabWidget* tabWidget); + DatabaseTabWidget(QWidget* parent); void openDatabase(const QString& fileName); void saveDatabase(Database* db); void saveDatabaseAs(Database* db); @@ -78,7 +79,6 @@ private: Database* indexDatabase(int index); void insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct); - QTabWidget* m_tabWidget; QWidget* m_window; KeePass2Reader m_reader; KeePass2Writer m_writer; diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 0adb11f86..f8cb7d00e 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -20,7 +20,6 @@ #include "core/Database.h" #include "core/Metadata.h" -#include "gui/DatabaseManager.h" #include "gui/DatabaseWidget.h" MainWindow::MainWindow() @@ -28,21 +27,19 @@ MainWindow::MainWindow() { m_ui->setupUi(this); - 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->tabWidget, SIGNAL(entrySelectionChanged(bool)), m_ui->actionEntryEdit, SLOT(setEnabled(bool))); + connect(m_ui->tabWidget, 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())); - connect(m_ui->actionDatabaseSave, SIGNAL(triggered()), m_dbManager, SLOT(saveDatabase())); - 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->actionDatabaseNew, SIGNAL(triggered()), m_ui->tabWidget, SLOT(newDatabase())); + connect(m_ui->actionDatabaseOpen, SIGNAL(triggered()), m_ui->tabWidget, SLOT(openDatabase())); + connect(m_ui->actionDatabaseSave, SIGNAL(triggered()), m_ui->tabWidget, SLOT(saveDatabase())); + connect(m_ui->actionDatabaseSaveAs, SIGNAL(triggered()), m_ui->tabWidget, SLOT(saveDatabaseAs())); + connect(m_ui->actionDatabaseClose, SIGNAL(triggered()), m_ui->tabWidget, SLOT(closeDatabase())); + connect(m_ui->actionEntryNew, SIGNAL(triggered()), m_ui->tabWidget, SLOT(createEntry())); + connect(m_ui->actionEntryEdit, SIGNAL(triggered()), m_ui->tabWidget, SLOT(editEntry())); + connect(m_ui->actionGroupNew, SIGNAL(triggered()), m_ui->tabWidget, SLOT(createGroup())); + connect(m_ui->actionGroupEdit, SIGNAL(triggered()), m_ui->tabWidget, SLOT(editGroup())); connect(m_ui->actionQuit, SIGNAL(triggered()), SLOT(close())); } diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 2f20fd230..b4185660f 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -20,8 +20,6 @@ #include -class Database; -class DatabaseManager; namespace Ui { class MainWindow; } @@ -39,7 +37,6 @@ private Q_SLOTS: private: QScopedPointer m_ui; - DatabaseManager* m_dbManager; Q_DISABLE_COPY(MainWindow) }; diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index 3fe4a1b96..d49a7757e 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -16,7 +16,7 @@ - + -1 @@ -36,7 +36,7 @@ 0 0 800 - 21 + 20 @@ -188,6 +188,14 @@ + + + DatabaseTabWidget + QTabWidget +
gui/DatabaseTabWidget.h
+ 1 +
+