Merge git://gitorious.org/~blueice/keepassx/blueices-keepassx into merge-request

This commit is contained in:
Felix Geyer 2011-12-24 23:46:57 +01:00
commit f7b95842b9
4 changed files with 57 additions and 7 deletions

View File

@ -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);

View File

@ -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:

View File

@ -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);

View File

@ -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/>