diff options
author | Felix Geyer <debfx@fobos.de> | 2011-12-27 19:04:59 +0400 |
---|---|---|
committer | Felix Geyer <debfx@fobos.de> | 2011-12-27 19:04:59 +0400 |
commit | 4d8e9561a7fb2dc9b995732f44af68f02e2e6864 (patch) | |
tree | 177661106af6c2929e4c4858c3473e5260cc3d3b | |
parent | 019bcd380e5545f2dc8b34eb43f4987959c40e9b (diff) |
Implement GUI for creating entries.
-rw-r--r-- | src/gui/DatabaseManager.cpp | 7 | ||||
-rw-r--r-- | src/gui/DatabaseManager.h | 1 | ||||
-rw-r--r-- | src/gui/DatabaseWidget.cpp | 37 | ||||
-rw-r--r-- | src/gui/DatabaseWidget.h | 5 | ||||
-rw-r--r-- | src/gui/EditEntryWidget.cpp | 9 | ||||
-rw-r--r-- | src/gui/EditEntryWidget.h | 2 | ||||
-rw-r--r-- | src/gui/MainWindow.cpp | 1 |
7 files changed, 51 insertions, 11 deletions
diff --git a/src/gui/DatabaseManager.cpp b/src/gui/DatabaseManager.cpp index b36d34397..0fa77a3dc 100644 --- a/src/gui/DatabaseManager.cpp +++ b/src/gui/DatabaseManager.cpp @@ -206,6 +206,13 @@ void DatabaseManager::saveDatabaseAs(int index) saveDatabaseAs(indexDatabase(index)); } +void DatabaseManager::createEntry() +{ + Database* db = indexDatabase(m_tabWidget->currentIndex()); + DatabaseWidget* dbWidget = m_dbList[db].dbWidget; + dbWidget->createEntry(); +} + void DatabaseManager::createGroup() { Database* db = indexDatabase(m_tabWidget->currentIndex()); diff --git a/src/gui/DatabaseManager.h b/src/gui/DatabaseManager.h index 08b2dd5b0..80838e852 100644 --- a/src/gui/DatabaseManager.h +++ b/src/gui/DatabaseManager.h @@ -57,6 +57,7 @@ public Q_SLOTS: void saveDatabase(int index = -1); void saveDatabaseAs(int index = -1); void closeDatabase(int index = -1); + void createEntry(); void createGroup(); void editGroup(); diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 0708795d4..c958807d0 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -28,7 +28,7 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent) : QStackedWidget(parent) , m_newGroup(0) - , m_newGroupParent(0) + , m_newParent(0) { m_mainWidget = new QWidget(this); QLayout* layout = new QHBoxLayout(m_mainWidget); @@ -78,11 +78,19 @@ EntryView* DatabaseWidget::entryView() return m_entryView; } +void DatabaseWidget::createEntry() +{ + m_newEntry = new Entry(); + m_newEntry->setUuid(Uuid::random()); + m_newParent = m_groupView->currentGroup(); + switchToEntryEdit(m_newEntry, true); +} + void DatabaseWidget::createGroup() { m_newGroup = new Group(); m_newGroup->setUuid(Uuid::random()); - m_newGroupParent = m_groupView->currentGroup(); + m_newParent = m_groupView->currentGroup(); switchToGroupEdit(m_newGroup, true); } @@ -90,14 +98,25 @@ void DatabaseWidget::switchToView(bool accepted) { if (m_newGroup) { if (accepted) { - m_newGroup->setParent(m_newGroupParent); + m_newGroup->setParent(m_newParent); } else { delete m_newGroup; } m_newGroup = 0; - m_newGroupParent = 0; + m_newParent = 0; + } + else if (m_newEntry) { + if (accepted) { + m_newEntry->setGroup(m_newParent); + } + else { + delete m_newEntry; + } + + m_newEntry = 0; + m_newParent = 0; } setCurrentIndex(0); @@ -105,7 +124,12 @@ void DatabaseWidget::switchToView(bool accepted) void DatabaseWidget::switchToEntryEdit(Entry* entry) { - m_editEntryWidget->loadEntry(entry); + switchToEntryEdit(entry, false); +} + +void DatabaseWidget::switchToEntryEdit(Entry* entry, bool create) +{ + m_editEntryWidget->loadEntry(entry, create, m_groupView->currentGroup()->name()); setCurrentIndex(1); } @@ -116,11 +140,10 @@ void DatabaseWidget::switchToGroupEdit(Group* group, bool create) } void DatabaseWidget::switchToEntryEdit() { - // TODO switchToEntryEdit(m_entryView->currentEntry()); + // TODO switchToEntryEdit(m_entryView->currentEntry(), false); } void DatabaseWidget::switchToGroupEdit() { switchToGroupEdit(m_groupView->currentGroup(), false); } - diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 2218bbed7..1f30bf434 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -38,6 +38,7 @@ public: EntryView* entryView(); public Q_SLOTS: + void createEntry(); void createGroup(); void switchToEntryEdit(); void switchToGroupEdit(); @@ -45,6 +46,7 @@ public Q_SLOTS: private Q_SLOTS: void switchToView(bool accepted); void switchToEntryEdit(Entry* entry); + void switchToEntryEdit(Entry* entry, bool create); void switchToGroupEdit(Group* entry, bool create); private: @@ -54,7 +56,8 @@ private: GroupView* m_groupView; EntryView* m_entryView; Group* m_newGroup; - Group* m_newGroupParent; + Entry* m_newEntry; + Group* m_newParent; }; #endif // KEEPASSX_DATABASEWIDGET_H diff --git a/src/gui/EditEntryWidget.cpp b/src/gui/EditEntryWidget.cpp index 9254c2acb..57a19c5e9 100644 --- a/src/gui/EditEntryWidget.cpp +++ b/src/gui/EditEntryWidget.cpp @@ -62,11 +62,16 @@ EditEntryWidget::~EditEntryWidget() { } -void EditEntryWidget::loadEntry(Entry* entry) +void EditEntryWidget::loadEntry(Entry* entry, bool create, const QString& groupName) { m_entry = entry; - m_ui->headerLabel->setText(m_entry->group()->name()+" > "+tr("Edit entry")); + if (create) { + m_ui->headerLabel->setText(groupName+" > "+tr("Add entry")); + } + else { + m_ui->headerLabel->setText(groupName+" > "+tr("Edit entry")); + } m_mainUi->titleEdit->setText(entry->title()); m_mainUi->usernameEdit->setText(entry->username()); diff --git a/src/gui/EditEntryWidget.h b/src/gui/EditEntryWidget.h index 7a2886d24..9ee32a65d 100644 --- a/src/gui/EditEntryWidget.h +++ b/src/gui/EditEntryWidget.h @@ -39,7 +39,7 @@ public: explicit EditEntryWidget(QWidget* parent = 0); ~EditEntryWidget(); - void loadEntry(Entry* entry); + void loadEntry(Entry* entry, bool create, const QString& groupName); Q_SIGNALS: void editFinished(bool accepted); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index d3cdf002f..c02e1d3b5 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -37,6 +37,7 @@ MainWindow::MainWindow() 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->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())); |