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")); 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)
{ {