Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Geyer <debfx@fobos.de>2011-12-25 02:46:57 +0400
committerFelix Geyer <debfx@fobos.de>2011-12-25 02:46:57 +0400
commitf7b95842b9782913e4ff954c7c59e76f0bce69ff (patch)
tree58cbff0c27a21b9ae049353e6ca0a85c5e70c723 /src
parentc5100594b28ab7d69701a4762c9cb8e35f69d543 (diff)
parent1dc90c1a7787bec84bf972f9a7cf8d4d2f51159f (diff)
Merge git://gitorious.org/~blueice/keepassx/blueices-keepassx into merge-request
Diffstat (limited to 'src')
-rw-r--r--src/gui/DatabaseManager.cpp49
-rw-r--r--src/gui/DatabaseManager.h2
-rw-r--r--src/gui/MainWindow.cpp2
-rw-r--r--src/gui/MainWindow.ui11
4 files changed, 57 insertions, 7 deletions
diff --git a/src/gui/DatabaseManager.cpp b/src/gui/DatabaseManager.cpp
index 6b92005df..6546cebc8 100644
--- a/src/gui/DatabaseManager.cpp
+++ b/src/gui/DatabaseManager.cpp
@@ -65,6 +65,7 @@ void DatabaseManager::openDatabase(const QString& fileName)
DatabaseManagerStruct dbStruct;
QScopedPointer<QFile> file(new QFile(fileName));
+ // TODO error handling
if (!file->open(QIODevice::ReadWrite)) {
if (!file->open(QIODevice::ReadOnly)) {
// can only open read-only
@@ -117,13 +118,41 @@ void DatabaseManager::saveDatabase(Database* db)
DatabaseManagerStruct& dbStruct = m_dbList[db];
// TODO ensure that the data is actually written to disk
- dbStruct.file->reset();
- m_writer.writeDatabase(dbStruct.file, db);
- dbStruct.file->resize(dbStruct.file->pos());
- dbStruct.file->flush();
+ if (dbStruct.file) {
+ dbStruct.file->reset();
+ m_writer.writeDatabase(dbStruct.file, db);
+ dbStruct.file->resize(dbStruct.file->pos());
+ dbStruct.file->flush();
- dbStruct.modified = false;
- updateTabName(db);
+ dbStruct.modified = false;
+ updateTabName(db);
+ }
+ else {
+ saveDatabaseAs(db);
+ }
+}
+
+void DatabaseManager::saveDatabaseAs(Database* db)
+{
+ QString fileName = QFileDialog::getSaveFileName(m_window, tr("Save database as"),
+ QString(), tr("KeePass 2 Database").append(" (*.kdbx)"));
+ if (!fileName.isEmpty()) {
+ DatabaseManagerStruct& dbStruct = m_dbList[db];
+
+ delete dbStruct.file;
+ QScopedPointer<QFile> file(new QFile(fileName));
+ // TODO error handling
+ if (!file->open(QIODevice::ReadWrite)) {
+ return;
+ }
+ dbStruct.file = file.take();
+ // TODO ensure that the data is actually written to disk
+ m_writer.writeDatabase(dbStruct.file, db);
+ dbStruct.file->flush();
+
+ dbStruct.modified = false;
+ updateTabName(db);
+ }
}
void DatabaseManager::closeDatabase(int index)
@@ -144,6 +173,14 @@ void DatabaseManager::saveDatabase(int index)
saveDatabase(indexDatabase(index));
}
+void DatabaseManager::saveDatabaseAs(int index)
+{
+ if (index == -1) {
+ index = m_tabWidget->currentIndex();
+ }
+ saveDatabaseAs(indexDatabase(index));
+}
+
void DatabaseManager::updateTabName(Database* db)
{
int index = databaseIndex(db);
diff --git a/src/gui/DatabaseManager.h b/src/gui/DatabaseManager.h
index d562f4778..9f93614da 100644
--- a/src/gui/DatabaseManager.h
+++ b/src/gui/DatabaseManager.h
@@ -45,12 +45,14 @@ public:
DatabaseManager(QTabWidget* tabWidget);
void openDatabase(const QString& fileName);
void saveDatabase(Database* db);
+ void saveDatabaseAs(Database* db);
void closeDatabase(Database* db);
public Q_SLOTS:
void newDatabase();
void openDatabase();
void saveDatabase(int index = -1);
+ void saveDatabaseAs(int index = -1);
void closeDatabase(int index = -1);
private Q_SLOTS:
diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp
index 2b331304a..813e400cc 100644
--- a/src/gui/MainWindow.cpp
+++ b/src/gui/MainWindow.cpp
@@ -33,6 +33,7 @@ MainWindow::MainWindow()
connect(actionDatabaseNew, SIGNAL(triggered()), m_dbManager, SLOT(newDatabase()));
connect(actionDatabaseOpen, SIGNAL(triggered()), m_dbManager, SLOT(openDatabase()));
connect(actionDatabaseSave, SIGNAL(triggered()), m_dbManager, SLOT(saveDatabase()));
+ connect(actionDatabaseSaveAs, SIGNAL(triggered()), m_dbManager, SLOT(saveDatabaseAs()));
connect(actionDatabaseClose, SIGNAL(triggered()), m_dbManager, SLOT(closeDatabase()));
connect(actionQuit, SIGNAL(triggered()), SLOT(close()));
}
@@ -42,6 +43,7 @@ void MainWindow::currentTabChanged(int index)
bool hasTab = (index != -1);
actionDatabaseSave->setEnabled(hasTab);
+ actionDatabaseSaveAs->setEnabled(hasTab);
actionDatabaseClose->setEnabled(hasTab);
actionEntryNew->setEnabled(hasTab);
actionGroupNew->setEnabled(hasTab);
diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui
index 0a9f8240a..3fe4a1b96 100644
--- a/src/gui/MainWindow.ui
+++ b/src/gui/MainWindow.ui
@@ -36,7 +36,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
- <height>20</height>
+ <height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@@ -46,6 +46,7 @@
<addaction name="actionDatabaseNew"/>
<addaction name="actionDatabaseOpen"/>
<addaction name="actionDatabaseSave"/>
+ <addaction name="actionDatabaseSaveAs"/>
<addaction name="actionDatabaseClose"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
@@ -178,6 +179,14 @@
<string>Delete group</string>
</property>
</action>
+ <action name="actionDatabaseSaveAs">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Save database as</string>
+ </property>
+ </action>
</widget>
<resources/>
<connections/>