From eb82df5994920129d219c719e74aaa7aff5c5b1c Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Tue, 15 May 2012 21:10:39 +0200 Subject: [PATCH] Add entry clone functionality. --- src/core/Entry.cpp | 13 +++++++++++++ src/core/Entry.h | 1 + src/gui/DatabaseTabWidget.cpp | 5 +++++ src/gui/DatabaseTabWidget.h | 1 + src/gui/DatabaseWidget.cpp | 10 ++++++++++ src/gui/DatabaseWidget.h | 2 ++ src/gui/MainWindow.cpp | 11 +++++++++++ src/gui/MainWindow.ui | 8 +++++++- 8 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 9877b73c9..878bb641a 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -413,6 +413,19 @@ void Entry::truncateHistory() { } } +Entry* Entry::clone() const +{ + Entry* entry = new Entry(); + entry->setUpdateTimeinfo(false); + entry->m_uuid = m_uuid; + entry->m_data = m_data; + *entry->m_attributes = *m_attributes; + *entry->m_attachments = *m_attachments; + entry->setUpdateTimeinfo(true); + + return entry; +} + void Entry::beginUpdate() { Q_ASSERT(!m_tmpHistoryItem); diff --git a/src/core/Entry.h b/src/core/Entry.h index 24e58610f..0f45bef0b 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -117,6 +117,7 @@ public: const QList& historyItems() const; void addHistoryItem(Entry* entry); void truncateHistory(); + Entry* clone() const; /** * Call before and after set*() methods to create a history item diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index 92430dea0..66a297336 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -334,6 +334,11 @@ void DatabaseTabWidget::createEntry() currentDatabaseWidget()->createEntry(); } +void DatabaseTabWidget::cloneEntry() +{ + currentDatabaseWidget()->cloneEntry(); +} + void DatabaseTabWidget::editEntry() { currentDatabaseWidget()->switchToEntryEdit(); diff --git a/src/gui/DatabaseTabWidget.h b/src/gui/DatabaseTabWidget.h index 5a942f61e..c8737bef6 100644 --- a/src/gui/DatabaseTabWidget.h +++ b/src/gui/DatabaseTabWidget.h @@ -65,6 +65,7 @@ public Q_SLOTS: void changeMasterKey(); void changeDatabaseSettings(); void createEntry(); + void cloneEntry(); void editEntry(); void deleteEntry(); void createGroup(); diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index c5bb3b66c..460034b44 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -156,6 +156,16 @@ void DatabaseWidget::createEntry() switchToEntryEdit(m_newEntry, true); } +void DatabaseWidget::cloneEntry() +{ + Entry* currentEntry = m_entryView->currentEntry(); + Entry* entry = currentEntry->clone(); + entry->setUuid(Uuid::random()); + entry->setGroup(currentEntry->group()); + m_entryView->setFocus(); + m_entryView->setCurrentEntry(entry); +} + void DatabaseWidget::deleteEntry() { bool inRecylceBin = Tools::hasChild(m_db->metadata()->recycleBin(), m_entryView->currentEntry()); diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 2ab526968..22d74e89f 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -49,8 +49,10 @@ public: GroupView* groupView(); EntryView* entryView(); bool dbHasKey(); + void cloneEntry(); void deleteEntry(); void deleteGroup(); + bool canDeleteCurrentGoup(); int addWidget(QWidget* w); void setCurrentIndex(int index); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index adddb51ec..dfc98f792 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -71,6 +71,8 @@ MainWindow::MainWindow() connect(m_ui->actionEntryNew, SIGNAL(triggered()), m_ui->tabWidget, SLOT(createEntry())); + connect(m_ui->actionEntryClone, SIGNAL(triggered()), m_ui->tabWidget, + SLOT(cloneEntry())); connect(m_ui->actionEntryEdit, SIGNAL(triggered()), m_ui->tabWidget, SLOT(editEntry())); connect(m_ui->actionEntryDelete, SIGNAL(triggered()), m_ui->tabWidget, @@ -114,6 +116,13 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) else { m_ui->actionEntryNew->setEnabled(true); } + if (dbWidget->entryView()->inSearch() || + !dbWidget->entryView()->currentIndex().isValid()) { + m_ui->actionEntryClone->setEnabled(false); + } + else { + m_ui->actionEntryClone->setEnabled(true); + } if (dbWidget->entryView()->currentIndex().isValid()) { m_ui->actionEntryEdit->setEnabled(true); @@ -147,6 +156,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) case DatabaseWidget::EditMode: m_ui->actionEntryNew->setEnabled(false); m_ui->actionGroupNew->setEnabled(false); + m_ui->actionEntryClone->setEnabled(false); m_ui->actionEntryEdit->setEnabled(false); m_ui->actionGroupEdit->setEnabled(false); m_ui->actionEntryDelete->setEnabled(false); @@ -164,6 +174,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) else { m_ui->actionEntryNew->setEnabled(false); m_ui->actionGroupNew->setEnabled(false); + m_ui->actionEntryClone->setEnabled(false); m_ui->actionEntryEdit->setEnabled(false); m_ui->actionGroupEdit->setEnabled(false); m_ui->actionEntryDelete->setEnabled(false); diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index b71800586..579a62b35 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -36,7 +36,7 @@ 0 0 800 - 21 + 20 @@ -67,6 +67,7 @@ Entries + @@ -216,6 +217,11 @@ Import KeePass 1 database + + + Clone entry + +