mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-05-11 11:05:23 -04:00
Implement save as.
This commit is contained in:
parent
1e4587c7a3
commit
1dc90c1a77
4 changed files with 57 additions and 7 deletions
|
@ -65,6 +65,7 @@ void DatabaseManager::openDatabase(const QString& fileName)
|
||||||
DatabaseManagerStruct dbStruct;
|
DatabaseManagerStruct dbStruct;
|
||||||
|
|
||||||
QScopedPointer<QFile> file(new QFile(fileName));
|
QScopedPointer<QFile> file(new QFile(fileName));
|
||||||
|
// TODO error handling
|
||||||
if (!file->open(QIODevice::ReadWrite)) {
|
if (!file->open(QIODevice::ReadWrite)) {
|
||||||
if (!file->open(QIODevice::ReadOnly)) {
|
if (!file->open(QIODevice::ReadOnly)) {
|
||||||
// can only open read-only
|
// can only open read-only
|
||||||
|
@ -117,6 +118,7 @@ void DatabaseManager::saveDatabase(Database* db)
|
||||||
DatabaseManagerStruct& dbStruct = m_dbList[db];
|
DatabaseManagerStruct& dbStruct = m_dbList[db];
|
||||||
|
|
||||||
// TODO ensure that the data is actually written to disk
|
// TODO ensure that the data is actually written to disk
|
||||||
|
if (dbStruct.file) {
|
||||||
dbStruct.file->reset();
|
dbStruct.file->reset();
|
||||||
m_writer.writeDatabase(dbStruct.file, db);
|
m_writer.writeDatabase(dbStruct.file, db);
|
||||||
dbStruct.file->resize(dbStruct.file->pos());
|
dbStruct.file->resize(dbStruct.file->pos());
|
||||||
|
@ -125,6 +127,33 @@ void DatabaseManager::saveDatabase(Database* db)
|
||||||
dbStruct.modified = false;
|
dbStruct.modified = false;
|
||||||
updateTabName(db);
|
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)
|
void DatabaseManager::closeDatabase(int index)
|
||||||
{
|
{
|
||||||
|
@ -144,6 +173,14 @@ void DatabaseManager::saveDatabase(int index)
|
||||||
saveDatabase(indexDatabase(index));
|
saveDatabase(indexDatabase(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DatabaseManager::saveDatabaseAs(int index)
|
||||||
|
{
|
||||||
|
if (index == -1) {
|
||||||
|
index = m_tabWidget->currentIndex();
|
||||||
|
}
|
||||||
|
saveDatabaseAs(indexDatabase(index));
|
||||||
|
}
|
||||||
|
|
||||||
void DatabaseManager::updateTabName(Database* db)
|
void DatabaseManager::updateTabName(Database* db)
|
||||||
{
|
{
|
||||||
int index = databaseIndex(db);
|
int index = databaseIndex(db);
|
||||||
|
|
|
@ -45,12 +45,14 @@ public:
|
||||||
DatabaseManager(QTabWidget* tabWidget);
|
DatabaseManager(QTabWidget* tabWidget);
|
||||||
void openDatabase(const QString& fileName);
|
void openDatabase(const QString& fileName);
|
||||||
void saveDatabase(Database* db);
|
void saveDatabase(Database* db);
|
||||||
|
void saveDatabaseAs(Database* db);
|
||||||
void closeDatabase(Database* db);
|
void closeDatabase(Database* db);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void newDatabase();
|
void newDatabase();
|
||||||
void openDatabase();
|
void openDatabase();
|
||||||
void saveDatabase(int index = -1);
|
void saveDatabase(int index = -1);
|
||||||
|
void saveDatabaseAs(int index = -1);
|
||||||
void closeDatabase(int index = -1);
|
void closeDatabase(int index = -1);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
|
|
@ -33,6 +33,7 @@ MainWindow::MainWindow()
|
||||||
connect(actionDatabaseNew, SIGNAL(triggered()), m_dbManager, SLOT(newDatabase()));
|
connect(actionDatabaseNew, SIGNAL(triggered()), m_dbManager, SLOT(newDatabase()));
|
||||||
connect(actionDatabaseOpen, SIGNAL(triggered()), m_dbManager, SLOT(openDatabase()));
|
connect(actionDatabaseOpen, SIGNAL(triggered()), m_dbManager, SLOT(openDatabase()));
|
||||||
connect(actionDatabaseSave, SIGNAL(triggered()), m_dbManager, SLOT(saveDatabase()));
|
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(actionDatabaseClose, SIGNAL(triggered()), m_dbManager, SLOT(closeDatabase()));
|
||||||
connect(actionQuit, SIGNAL(triggered()), SLOT(close()));
|
connect(actionQuit, SIGNAL(triggered()), SLOT(close()));
|
||||||
}
|
}
|
||||||
|
@ -42,6 +43,7 @@ void MainWindow::currentTabChanged(int index)
|
||||||
bool hasTab = (index != -1);
|
bool hasTab = (index != -1);
|
||||||
|
|
||||||
actionDatabaseSave->setEnabled(hasTab);
|
actionDatabaseSave->setEnabled(hasTab);
|
||||||
|
actionDatabaseSaveAs->setEnabled(hasTab);
|
||||||
actionDatabaseClose->setEnabled(hasTab);
|
actionDatabaseClose->setEnabled(hasTab);
|
||||||
actionEntryNew->setEnabled(hasTab);
|
actionEntryNew->setEnabled(hasTab);
|
||||||
actionGroupNew->setEnabled(hasTab);
|
actionGroupNew->setEnabled(hasTab);
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>20</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
|
@ -46,6 +46,7 @@
|
||||||
<addaction name="actionDatabaseNew"/>
|
<addaction name="actionDatabaseNew"/>
|
||||||
<addaction name="actionDatabaseOpen"/>
|
<addaction name="actionDatabaseOpen"/>
|
||||||
<addaction name="actionDatabaseSave"/>
|
<addaction name="actionDatabaseSave"/>
|
||||||
|
<addaction name="actionDatabaseSaveAs"/>
|
||||||
<addaction name="actionDatabaseClose"/>
|
<addaction name="actionDatabaseClose"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionQuit"/>
|
<addaction name="actionQuit"/>
|
||||||
|
@ -178,6 +179,14 @@
|
||||||
<string>Delete group</string>
|
<string>Delete group</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionDatabaseSaveAs">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Save database as</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue