Add MinimizeOnUrlOpen feature

This commit is contained in:
Jeff 2019-06-21 19:42:27 -05:00 committed by Jonathan White
parent 6dcd00b609
commit a22e8a1f40
5 changed files with 26 additions and 10 deletions

View file

@ -656,15 +656,10 @@ void DatabaseWidget::openUrlForEntry(Entry* entry)
QString cmdString = entry->resolveMultiplePlaceholders(entry->url());
if (cmdString.startsWith("cmd://")) {
// check if decision to execute command was stored
if (entry->attributes()->hasKey(EntryAttributes::RememberCmdExecAttr)) {
if (entry->attributes()->value(EntryAttributes::RememberCmdExecAttr) == "1") {
QProcess::startDetached(cmdString.mid(6));
}
return;
}
bool launch = (entry->attributes()->value(EntryAttributes::RememberCmdExecAttr) == "1");
// otherwise ask user
if (cmdString.length() > 6) {
if (!launch && cmdString.length() > 6) {
QString cmdTruncated = cmdString.mid(6);
if (cmdTruncated.length() > 400) {
cmdTruncated = cmdTruncated.left(400) + " […]";
@ -687,18 +682,28 @@ void DatabaseWidget::openUrlForEntry(Entry* entry)
});
int result = msgbox.exec();
if (result == QMessageBox::Yes) {
QProcess::startDetached(cmdString.mid(6));
}
launch = (result == QMessageBox::Yes);
if (remember) {
entry->attributes()->set(EntryAttributes::RememberCmdExecAttr, result == QMessageBox::Yes ? "1" : "0");
}
}
if (launch) {
QProcess::startDetached(cmdString.mid(6));
if (config()->get("MinimizeOnOpenUrl").toBool()) {
window()->showMinimized();
}
}
} else {
QUrl url = QUrl::fromUserInput(entry->resolveMultiplePlaceholders(entry->url()));
if (!url.isEmpty()) {
QDesktopServices::openUrl(url);
if (config()->get("MinimizeOnOpenUrl").toBool()) {
window()->showMinimized();
}
}
}
}