Skip to content

Commit

Permalink
Add DB_DIR placeholder for autoopen urls
Browse files Browse the repository at this point in the history
  • Loading branch information
stingray21 authored and droidmonkey committed May 21, 2020
1 parent bcb64a2 commit d863496
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/core/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,10 @@ QString Entry::resolvePlaceholderRecursive(const QString& placeholder, int maxDe
return url();
}
return resolveMultiplePlaceholdersRecursive(url(), maxDepth - 1);
case PlaceholderType::DbDir: {
QFileInfo fileInfo(database()->filePath());
return fileInfo.absoluteDir().absolutePath();
}
case PlaceholderType::UrlWithoutScheme:
case PlaceholderType::UrlScheme:
case PlaceholderType::UrlHost:
Expand Down Expand Up @@ -1237,7 +1241,8 @@ Entry::PlaceholderType Entry::placeholderType(const QString& placeholder) const
{QStringLiteral("{DT_UTC_DAY}"), PlaceholderType::DateTimeUtcDay},
{QStringLiteral("{DT_UTC_HOUR}"), PlaceholderType::DateTimeUtcHour},
{QStringLiteral("{DT_UTC_MINUTE}"), PlaceholderType::DateTimeUtcMinute},
{QStringLiteral("{DT_UTC_SECOND}"), PlaceholderType::DateTimeUtcSecond}};
{QStringLiteral("{DT_UTC_SECOND}"), PlaceholderType::DateTimeUtcSecond},
{QStringLiteral("{DB_DIR}"), PlaceholderType::DbDir}};

return placeholders.value(placeholder.toUpper(), PlaceholderType::Unknown);
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/Entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ class Entry : public QObject
DateTimeUtcDay,
DateTimeUtcHour,
DateTimeUtcMinute,
DateTimeUtcSecond
DateTimeUtcSecond,
DbDir
};

/**
Expand Down
9 changes: 5 additions & 4 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1973,15 +1973,16 @@ void DatabaseWidget::processAutoOpen()
}
QFileInfo filepath;
QFileInfo keyfile;
QString databaseUrl = entry->resolveMultiplePlaceholders(entry->url());

if (entry->url().startsWith("file://")) {
QUrl url(entry->url());
if (databaseUrl.startsWith("file://")) {
QUrl url(databaseUrl);
filepath.setFile(url.toLocalFile());
} else {
filepath.setFile(entry->url());
filepath.setFile(databaseUrl);
if (filepath.isRelative()) {
QFileInfo currentpath(m_db->filePath());
filepath.setFile(currentpath.absoluteDir(), entry->url());
filepath.setFile(currentpath.absoluteDir(), databaseUrl);
}
}

Expand Down

0 comments on commit d863496

Please sign in to comment.