Commit 9bad434f authored by Nicolas Fella's avatar Nicolas Fella Committed by Nate Graham
Browse files

kcms/autostart: Warn when adding a non-executable script and offer to fix it

The login/logout script files need to be executable. To avoid the user
wondering why their script isn't executing, warn them if the file is not
executable and offer to fix it.

CCBUG: 391609
parent e87d29c2
Pipeline #198058 passed with stage
in 6 minutes and 40 seconds
......@@ -298,6 +298,12 @@ void AutostartModel::addScript(const QUrl &url, AutostartModel::AutostartEntrySo
return;
}
QFile scriptFile(url.toLocalFile());
if (!(scriptFile.permissions() & QFile::ExeUser)) {
Q_EMIT nonExecutableScript(url.toLocalFile(), kind);
}
const QString fileName = url.fileName();
if (kind == AutostartModel::AutostartEntrySource::XdgScripts) {
......@@ -410,3 +416,10 @@ void AutostartModel::editApplication(int row, QQuickItem *context)
});
dlg->open();
}
void AutostartModel::makeFileExecutable(const QString &fileName)
{
QFile file(fileName);
file.setPermissions(file.permissions() | QFile::ExeUser);
}
......@@ -49,11 +49,13 @@ public:
Q_INVOKABLE void editApplication(int row, QQuickItem *context);
Q_INVOKABLE void addScript(const QUrl &url, AutostartEntrySource kind);
Q_INVOKABLE void showApplicationDialog(QQuickItem *context);
Q_INVOKABLE void makeFileExecutable(const QString &fileName);
void load();
Q_SIGNALS:
void error(const QString &message);
void nonExecutableScript(const QString &fileName, AutostartModel::AutostartEntrySource kind);
private:
void addApplication(const KService::Ptr &service);
......
......@@ -21,16 +21,43 @@ KCM.ScrollViewKCM {
header: Kirigami.InlineMessage {
id: errorMessage
type: Kirigami.MessageType.Error
showCloseButton: true
Connections {
target: kcm.model
function onError(message) {
errorMessage.type = Kirigami.MessageType.Error
errorMessage.visible = true
errorMessage.text = message
}
}
Connections {
target: kcm.model
property var fixItAction: Kirigami.Action {
property string fileName
text: i18n("Make Executable")
icon.name: "dialog-ok"
onTriggered: {
kcm.model.makeFileExecutable(fileName)
errorMessage.visible = false
}
}
function onNonExecutableScript(fileName, kind) {
fixItAction.fileName = fileName
errorMessage.type = Kirigami.MessageType.Warning
errorMessage.visible = true
errorMessage.actions = [fixItAction]
if (kind === AutostartModel.PlasmaShutdown) {
errorMessage.text = i18nd("kcm_autostart", "The file '%1' must be executable to run at logout.", fileName)
} else { ' '
errorMessage.text = i18nd("kcm_autostart", "The file '%1' must be executable to run at login.", fileName)
}
}
}
}
view: ListView {
......
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