Use existing database open function on startup

* Fix #2828
This commit is contained in:
Jonathan White 2019-03-21 17:36:57 -04:00
parent 3404b4ac58
commit 28a3824d2d
4 changed files with 16 additions and 27 deletions

View File

@ -137,10 +137,15 @@ void DatabaseTabWidget::openDatabase()
* database has been opened already.
*
* @param filePath database file path
* @param password optional, password to unlock database
* @param inBackground optional, don't focus tab after opening
* @param password optional, password to unlock database
* @param keyfile optional, path to keyfile to unlock database
*
*/
void DatabaseTabWidget::addDatabaseTab(const QString& filePath, bool inBackground, const QString& password)
void DatabaseTabWidget::addDatabaseTab(const QString& filePath,
bool inBackground,
const QString& password,
const QString& keyfile)
{
QFileInfo fileInfo(filePath);
QString canonicalFilePath = fileInfo.canonicalFilePath();
@ -154,7 +159,7 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath, bool inBackgroun
Q_ASSERT(dbWidget);
if (dbWidget && dbWidget->database()->filePath() == canonicalFilePath) {
if (!password.isEmpty()) {
dbWidget->performUnlockDatabase(password);
dbWidget->performUnlockDatabase(password, keyfile);
}
if (!inBackground) {
// switch to existing tab if file is already open
@ -167,7 +172,7 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath, bool inBackgroun
auto* dbWidget = new DatabaseWidget(QSharedPointer<Database>::create(filePath), this);
addDatabaseTab(dbWidget, inBackground);
if (!password.isEmpty()) {
dbWidget->performUnlockDatabase(password);
dbWidget->performUnlockDatabase(password, keyfile);
}
updateLastDatabases(filePath);
}

View File

@ -48,7 +48,10 @@ public:
bool hasLockableDatabases() const;
public slots:
void addDatabaseTab(const QString& filePath, bool inBackground = false, const QString& password = {});
void addDatabaseTab(const QString& filePath,
bool inBackground = false,
const QString& password = {},
const QString& keyfile = {});
void addDatabaseTab(DatabaseWidget* dbWidget, bool inBackground = false);
bool closeDatabaseTab(int index);
bool closeDatabaseTab(DatabaseWidget* dbWidget);

View File

@ -496,28 +496,9 @@ void MainWindow::clearLastDatabases()
}
}
void MainWindow::openDatabase(const QString& filePath, const QString& pw, const QString& keyFile)
void MainWindow::openDatabase(const QString& filePath, const QString& password, const QString& keyfile)
{
if (pw.isEmpty() && keyFile.isEmpty()) {
m_ui->tabWidget->addDatabaseTab(filePath);
return;
}
auto db = QSharedPointer<Database>::create();
auto key = QSharedPointer<CompositeKey>::create();
if (!pw.isEmpty()) {
key->addKey(QSharedPointer<PasswordKey>::create(pw));
}
if (!keyFile.isEmpty()) {
auto fileKey = QSharedPointer<FileKey>::create();
fileKey->load(keyFile);
key->addKey(fileKey);
}
if (db->open(filePath, key, nullptr, false)) {
auto* dbWidget = new DatabaseWidget(db, this);
m_ui->tabWidget->addDatabaseTab(dbWidget);
dbWidget->switchToMainView(true);
}
m_ui->tabWidget->addDatabaseTab(filePath, false, password, keyfile);
}
void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)

View File

@ -56,7 +56,7 @@ public:
};
public slots:
void openDatabase(const QString& filePath, const QString& pw = {}, const QString& keyFile = {});
void openDatabase(const QString& filePath, const QString& password = {}, const QString& keyfile = {});
void appExit();
void displayGlobalMessage(const QString& text,
MessageWidget::MessageType type,