Commit a67a2def authored by Stefano Crocco's avatar Stefano Crocco Committed by David Faure
Browse files

Don't suggest to display an executable file if there aren't services for it

parent e776b30e
......@@ -239,19 +239,30 @@ UrlLoader::OpenUrlAction UrlLoader::decideExecute() const {
if (!m_url.isLocalFile() || !KRun::isExecutable(m_mimeType)) {
return OpenUrlAction::UnknwonAction;
}
KMessageBox::ButtonCode code = KMessageBox::questionYesNoCancel(m_mainWindow, i18nc("The user has to decide whether to execute an executable file or not",
"%1 is a script file. Do you want to execute it or to display it?", m_url.path()),
QString(), KGuiItem(i18nc("Execute a script file", "Execute it")),
KGuiItem(i18nc("Display a script file", "Display it")),
KStandardGuiItem::cancel(),
QLatin1String("AskExecuting")+m_mimeType, KMessageBox::Dangerous);
bool canDisplay = !KMimeTypeTrader::self()->query(m_mimeType).isEmpty();
KMessageBox::ButtonCode code;
KGuiItem executeGuiItem(i18nc("Execute an executable file", "Execute it"));
QString dontShowAgainId(QLatin1String("AskExecuting")+m_mimeType);
if (canDisplay) {
code = KMessageBox::questionYesNoCancel(m_mainWindow, i18nc("The user has to decide whether to execute an executable file or display it",
"<tt>%1</tt> can be executed. Do you want to execute it or to display it?", m_url.path()),
QString(), executeGuiItem, KGuiItem(i18nc("Display an executable file", "Display it")),
KStandardGuiItem::cancel(), dontShowAgainId, KMessageBox::Dangerous);
} else {
code = KMessageBox::questionYesNo(m_mainWindow, i18nc("The user has to decide whether to execute an executable file or not",
"<tt>%1</tt> can be executed. Do you want to execute it?", m_url.path()),
QString(), executeGuiItem, KStandardGuiItem::cancel(),
dontShowAgainId, KMessageBox::Dangerous);}
switch (code) {
case KMessageBox::Yes:
return OpenUrlAction::Execute;
case KMessageBox::Cancel:
return OpenUrlAction::DoNothing;
case KMessageBox::No:
return OpenUrlAction::UnknwonAction;
//The "No" button actually corresponds to the "Cancel" action if the file can't be displayed
return canDisplay ? OpenUrlAction::UnknwonAction : OpenUrlAction::DoNothing;
default: //This is here only to avoid a compiler warning
return OpenUrlAction::UnknwonAction;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment