mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-04-06 05:57:37 +03:00
Ask for save location when creating new DB and change default name to 'Passwords.kdbx', resolves #285
This commit is contained in:
parent
012d0ee885
commit
ec17199feb
1 changed files with 71 additions and 65 deletions
|
@ -90,8 +90,16 @@ void DatabaseTabWidget::newDatabase()
|
||||||
db->rootGroup()->setName(tr("Root"));
|
db->rootGroup()->setName(tr("Root"));
|
||||||
dbStruct.dbWidget = new DatabaseWidget(db, this);
|
dbStruct.dbWidget = new DatabaseWidget(db, this);
|
||||||
|
|
||||||
|
CompositeKey emptyKey;
|
||||||
|
db->setKey(emptyKey);
|
||||||
|
|
||||||
insertDatabase(db, dbStruct);
|
insertDatabase(db, dbStruct);
|
||||||
|
|
||||||
|
if (!saveDatabaseAs(db)) {
|
||||||
|
closeDatabase(db);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dbStruct.dbWidget->switchToMasterKeyChange();
|
dbStruct.dbWidget->switchToMasterKeyChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,13 +356,13 @@ bool DatabaseTabWidget::saveDatabase(Database* db)
|
||||||
|
|
||||||
bool DatabaseTabWidget::saveDatabaseAs(Database* db)
|
bool DatabaseTabWidget::saveDatabaseAs(Database* db)
|
||||||
{
|
{
|
||||||
|
while (true) {
|
||||||
DatabaseManagerStruct& dbStruct = m_dbList[db];
|
DatabaseManagerStruct& dbStruct = m_dbList[db];
|
||||||
QString oldFileName;
|
QString oldFileName;
|
||||||
if (dbStruct.saveToFilename) {
|
if (dbStruct.saveToFilename) {
|
||||||
oldFileName = dbStruct.filePath;
|
oldFileName = dbStruct.filePath;
|
||||||
}
|
} else {
|
||||||
else {
|
oldFileName = tr("Passwords").append(".kdbx");
|
||||||
oldFileName = tr("New database").append(".kdbx");
|
|
||||||
}
|
}
|
||||||
QString fileName = fileDialog()->getSaveFileName(this, tr("Save database as"),
|
QString fileName = fileDialog()->getSaveFileName(this, tr("Save database as"),
|
||||||
oldFileName, tr("KeePass 2 Database").append(" (*.kdbx)"),
|
oldFileName, tr("KeePass 2 Database").append(" (*.kdbx)"),
|
||||||
|
@ -365,8 +373,7 @@ bool DatabaseTabWidget::saveDatabaseAs(Database* db)
|
||||||
if (fileInfo.exists()) {
|
if (fileInfo.exists()) {
|
||||||
// returns empty string when file doesn't exist
|
// returns empty string when file doesn't exist
|
||||||
lockFilePath = fileInfo.canonicalPath();
|
lockFilePath = fileInfo.canonicalPath();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
lockFilePath = fileInfo.absolutePath();
|
lockFilePath = fileInfo.absolutePath();
|
||||||
}
|
}
|
||||||
QString lockFileName = QString("%1/.%2.lock").arg(lockFilePath, fileInfo.fileName());
|
QString lockFileName = QString("%1/.%2.lock").arg(lockFilePath, fileInfo.fileName());
|
||||||
|
@ -383,8 +390,7 @@ bool DatabaseTabWidget::saveDatabaseAs(Database* db)
|
||||||
|
|
||||||
if (result == QMessageBox::No) {
|
if (result == QMessageBox::No) {
|
||||||
return false;
|
return false;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// take over the lock file if possible
|
// take over the lock file if possible
|
||||||
if (lockFile->removeStaleLockFile()) {
|
if (lockFile->removeStaleLockFile()) {
|
||||||
lockFile->tryLock();
|
lockFile->tryLock();
|
||||||
|
@ -401,7 +407,7 @@ bool DatabaseTabWidget::saveDatabaseAs(Database* db)
|
||||||
// failed to save, revert back
|
// failed to save, revert back
|
||||||
dbStruct.saveToFilename = false;
|
dbStruct.saveToFilename = false;
|
||||||
dbStruct.canonicalFilePath = oldFileName;
|
dbStruct.canonicalFilePath = oldFileName;
|
||||||
return false;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// refresh fileinfo since the file didn't exist before
|
// refresh fileinfo since the file didn't exist before
|
||||||
|
@ -419,11 +425,11 @@ bool DatabaseTabWidget::saveDatabaseAs(Database* db)
|
||||||
updateTabName(db);
|
updateTabName(db);
|
||||||
updateLastDatabases(dbStruct.filePath);
|
updateLastDatabases(dbStruct.filePath);
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool DatabaseTabWidget::closeDatabase(int index)
|
bool DatabaseTabWidget::closeDatabase(int index)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue