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

Allow the user to cancel when clicking on an executable file

parent dffbd763
......@@ -119,17 +119,22 @@ bool UrlLoader::isViewLocked() const
void UrlLoader::decideAction()
{
if (decideExecute()) {
m_action = OpenUrlAction::Execute;
m_ready = true;
} else {
if (isViewLocked() || shouldEmbedThis()) {
bool success = decideEmbedOrSave();
if (success) {
return;
m_action = decideExecute();
switch (m_action) {
case OpenUrlAction::Execute:
m_ready = true;
break;
case OpenUrlAction::DoNothing:
m_ready = true;
return;
default:
if (isViewLocked() || shouldEmbedThis()) {
bool success = decideEmbedOrSave();
if (success) {
return;
}
}
}
decideOpenOrSave();
decideOpenOrSave();
}
}
......@@ -230,14 +235,26 @@ void UrlLoader::decideOpenOrSave()
}
}
bool UrlLoader::decideExecute() const {
UrlLoader::OpenUrlAction UrlLoader::decideExecute() const {
if (!m_url.isLocalFile() || !KRun::isExecutable(m_mimeType)) {
return false;
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);
switch (code) {
case KMessageBox::Yes:
return OpenUrlAction::Execute;
case KMessageBox::Cancel:
return OpenUrlAction::DoNothing;
case KMessageBox::No:
return OpenUrlAction::UnknwonAction;
default: //This is here only to avoid a compiler warning
return OpenUrlAction::UnknwonAction;
}
KMessageBox::ButtonCode code = KMessageBox::questionYesNo(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")), QLatin1String("AskExecuting")+m_mimeType);
return code == KMessageBox::Yes;
}
void UrlLoader::performAction()
......@@ -256,6 +273,7 @@ void UrlLoader::performAction()
save();
break;
case OpenUrlAction::DoNothing:
case OpenUrlAction::UnknwonAction: //This should never happen
done();
break;
}
......@@ -514,6 +532,9 @@ QDebug operator<<(QDebug dbg, UrlLoader::OpenUrlAction action)
QDebugStateSaver saver(dbg);
dbg.resetFormat();
switch (action) {
case UrlLoader::OpenUrlAction::UnknwonAction:
dbg << "UnknownAction";
break;
case UrlLoader::OpenUrlAction::DoNothing:
dbg << "DoNothing";
break;
......
......@@ -30,9 +30,6 @@ namespace KIO {
class KonqMainWindow;
class KonqView;
/**
* @todo write docs
*/
class UrlLoader : public QObject
{
Q_OBJECT
......@@ -46,8 +43,22 @@ public:
UrlLoader(KonqMainWindow *mainWindow, KonqView *view, const QUrl &url, const QString &mimeType, const KonqOpenURLRequest &req, bool trustedSource, bool forceOpen=false);
~UrlLoader();
enum class OpenUrlAction{DoNothing, Save, Embed, Open, Execute};
enum class ViewToUse{View, CurrentView, NewTab};
/** @brief Enum describing the possible actions to be taken*/
enum class OpenUrlAction{
UnknwonAction, /**< The action hasn't been decided yet */
DoNothing, /**< No action should be taken */
Save, /**< Save the URL */
Embed, /**< Display the URL in an embedded viewer */
Open, /**< Display the URL in a separate viewer*/
Execute /**< Execute the URL */
};
/** @brief Enum describing the view to use to embed an URL*/
enum class ViewToUse{
View, /**< Use the view passed as argument to the constructor */
CurrentView, /**< Use the current view */
NewTab /**< Create a new tab and use its view */
};
void start();
void performAction();
......@@ -109,7 +120,7 @@ private:
enum class OpenEmbedMode{Open, Embed};
OpenSaveAnswer askSaveOrOpen(OpenEmbedMode mode) const;
bool decideExecute() const;
OpenUrlAction decideExecute() const;
private:
QPointer<KonqMainWindow> m_mainWindow;
......@@ -121,7 +132,7 @@ private:
bool m_dontEmbed;
bool m_ready = false;
bool m_isAsync = false;
OpenUrlAction m_action = OpenUrlAction::DoNothing;
OpenUrlAction m_action = OpenUrlAction::UnknwonAction;
KService::Ptr m_service;
QPointer<KIO::OpenUrlJob> m_openUrlJob;
QPointer<KIO::ApplicationLauncherJob> m_applicationLauncherJob;
......
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