Ask for save location when creating new DB and change default name to 'Passwords.kdbx', resolves #285

This commit is contained in:
Janek Bevendorff 2017-02-13 17:35:38 +01:00 committed by Jonathan White
parent 012d0ee885
commit ec17199feb

View file

@ -90,8 +90,16 @@ void DatabaseTabWidget::newDatabase()
db->rootGroup()->setName(tr("Root"));
dbStruct.dbWidget = new DatabaseWidget(db, this);
CompositeKey emptyKey;
db->setKey(emptyKey);
insertDatabase(db, dbStruct);
if (!saveDatabaseAs(db)) {
closeDatabase(db);
return;
}
dbStruct.dbWidget->switchToMasterKeyChange();
}
@ -348,13 +356,13 @@ bool DatabaseTabWidget::saveDatabase(Database* db)
bool DatabaseTabWidget::saveDatabaseAs(Database* db)
{
while (true) {
DatabaseManagerStruct& dbStruct = m_dbList[db];
QString oldFileName;
if (dbStruct.saveToFilename) {
oldFileName = dbStruct.filePath;
}
else {
oldFileName = tr("New database").append(".kdbx");
} else {
oldFileName = tr("Passwords").append(".kdbx");
}
QString fileName = fileDialog()->getSaveFileName(this, tr("Save database as"),
oldFileName, tr("KeePass 2 Database").append(" (*.kdbx)"),
@ -365,8 +373,7 @@ bool DatabaseTabWidget::saveDatabaseAs(Database* db)
if (fileInfo.exists()) {
// returns empty string when file doesn't exist
lockFilePath = fileInfo.canonicalPath();
}
else {
} else {
lockFilePath = fileInfo.absolutePath();
}
QString lockFileName = QString("%1/.%2.lock").arg(lockFilePath, fileInfo.fileName());
@ -383,8 +390,7 @@ bool DatabaseTabWidget::saveDatabaseAs(Database* db)
if (result == QMessageBox::No) {
return false;
}
else {
} else {
// take over the lock file if possible
if (lockFile->removeStaleLockFile()) {
lockFile->tryLock();
@ -401,7 +407,7 @@ bool DatabaseTabWidget::saveDatabaseAs(Database* db)
// failed to save, revert back
dbStruct.saveToFilename = false;
dbStruct.canonicalFilePath = oldFileName;
return false;
continue;
}
// refresh fileinfo since the file didn't exist before
@ -419,11 +425,11 @@ bool DatabaseTabWidget::saveDatabaseAs(Database* db)
updateTabName(db);
updateLastDatabases(dbStruct.filePath);
return true;
}
else {
} else {
return false;
}
}
}
bool DatabaseTabWidget::closeDatabase(int index)
{