Merge pull request #1053 from alterratz/feature/autoopen

added autoopen functionality (#477)
This commit is contained in:
TheZ3ro 2017-11-30 15:13:41 +01:00 committed by GitHub
commit fb6636d182
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 5 deletions

View File

@ -624,6 +624,36 @@ void DatabaseTabWidget::updateTabNameFromDbWidgetSender()
DatabaseWidget* dbWidget = static_cast<DatabaseWidget*>(sender());
updateTabName(databaseFromDatabaseWidget(dbWidget));
Database* db = dbWidget->database();
Group *autoload = db->rootGroup()->findChildByName("AutoOpen");
if (autoload) {
const DatabaseManagerStruct& dbStruct = m_dbList.value(db);
QFileInfo dbpath(dbStruct.canonicalFilePath);
QDir dbFolder(dbpath.canonicalPath());
for (auto entry : autoload->entries()) {
if (entry->url().isEmpty() || entry->password().isEmpty()) {
continue;
}
QFileInfo filepath;
if (entry->url().startsWith("file://")) {
QUrl url(entry->url());
filepath.setFile(url.toLocalFile());
}
else {
filepath.setFile(entry->url());
if (filepath.isRelative()) {
filepath.setFile(dbFolder, entry->url());
}
}
if (!filepath.isFile()) {
continue;
}
openDatabase(filepath.canonicalFilePath(), entry->password(), "");
}
}
}
int DatabaseTabWidget::databaseIndex(Database* db)

View File

@ -950,8 +950,13 @@ void DatabaseWidget::switchToDatabaseSettings()
void DatabaseWidget::switchToOpenDatabase(const QString& fileName)
{
updateFilename(fileName);
m_databaseOpenWidget->load(fileName);
setCurrentWidget(m_databaseOpenWidget);
if (m_databaseOpenWidget) {
m_databaseOpenWidget->load(fileName);
setCurrentWidget(m_databaseOpenWidget);
} else if (m_unlockDatabaseWidget) {
m_unlockDatabaseWidget->load(fileName);
setCurrentWidget(m_unlockDatabaseWidget);
}
}
void DatabaseWidget::switchToOpenDatabase(const QString& fileName, const QString& password,
@ -959,7 +964,11 @@ void DatabaseWidget::switchToOpenDatabase(const QString& fileName, const QString
{
updateFilename(fileName);
switchToOpenDatabase(fileName);
m_databaseOpenWidget->enterKey(password, keyFile);
if (m_databaseOpenWidget) {
m_databaseOpenWidget->enterKey(password, keyFile);
} else if (m_unlockDatabaseWidget) {
m_unlockDatabaseWidget->enterKey(password, keyFile);
}
}
void DatabaseWidget::switchToImportCsv(const QString& fileName)