mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-11-23 00:10:37 -05:00
Re-implement AutoOpen functionality after refactor (#2504)
The database refactor in #2491 removed auto-open functionality.
This commit is contained in:
parent
785a64cc3b
commit
ff7191eef3
4 changed files with 75 additions and 10 deletions
|
|
@ -126,8 +126,10 @@ 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
|
||||
*/
|
||||
void DatabaseTabWidget::addDatabaseTab(const QString& filePath)
|
||||
void DatabaseTabWidget::addDatabaseTab(const QString& filePath, bool inBackground, const QString& password)
|
||||
{
|
||||
QFileInfo fileInfo(filePath);
|
||||
QString canonicalFilePath = fileInfo.canonicalFilePath();
|
||||
|
|
@ -140,32 +142,44 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath)
|
|||
auto* dbWidget = databaseWidgetFromIndex(i);
|
||||
Q_ASSERT(dbWidget);
|
||||
if (dbWidget && dbWidget->database()->filePath() == canonicalFilePath) {
|
||||
// switch to existing tab if file is already open
|
||||
setCurrentIndex(indexOf(dbWidget));
|
||||
if (!password.isEmpty()) {
|
||||
dbWidget->performUnlockDatabase(password);
|
||||
}
|
||||
if (!inBackground) {
|
||||
// switch to existing tab if file is already open
|
||||
setCurrentIndex(indexOf(dbWidget));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto* dbWidget = new DatabaseWidget(QSharedPointer<Database>::create(filePath), this);
|
||||
addDatabaseTab(dbWidget);
|
||||
addDatabaseTab(dbWidget, inBackground);
|
||||
if (!password.isEmpty()) {
|
||||
dbWidget->performUnlockDatabase(password);
|
||||
}
|
||||
updateLastDatabases(filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new database tab containing the given DatabaseWidget
|
||||
* @param filePath
|
||||
* @param inBackground optional, don't focus tab after opening
|
||||
*/
|
||||
void DatabaseTabWidget::addDatabaseTab(DatabaseWidget* dbWidget)
|
||||
void DatabaseTabWidget::addDatabaseTab(DatabaseWidget* dbWidget, bool inBackground)
|
||||
{
|
||||
auto db = dbWidget->database();
|
||||
Q_ASSERT(db);
|
||||
Q_ASSERT(dbWidget->database());
|
||||
|
||||
int index = addTab(dbWidget, "");
|
||||
updateTabName(index);
|
||||
setCurrentIndex(index);
|
||||
toggleTabbar();
|
||||
|
||||
if (!inBackground) {
|
||||
setCurrentIndex(index);
|
||||
}
|
||||
|
||||
connect(dbWidget, SIGNAL(databaseFilePathChanged(QString,QString)), SLOT(updateTabName()));
|
||||
connect(dbWidget, SIGNAL(requestOpenDatabase(QString,bool,QString)), SLOT(addDatabaseTab(QString,bool,QString)));
|
||||
connect(dbWidget, SIGNAL(closeRequest()), SLOT(closeDatabaseTabFromSender()));
|
||||
connect(dbWidget, SIGNAL(databaseModified()), SLOT(updateTabName()));
|
||||
connect(dbWidget, SIGNAL(databaseSaved()), SLOT(updateTabName()));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue