[pim/pim-sieve-editor] src/internaltoolsjob: Fix emit signal when we can't start

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit c3130e79d9b676edaff963b6f156344b1eb13e47 by Laurent Montel.
Committed on 14/08/2026 at 17:46.
Pushed by mlaurent into branch 'master'.

Fix emit signal when we can't start

M  +30   -19   src/internaltoolsjob/addnewscripttoolinternaljob.cpp
M  +1    -0    src/internaltoolsjob/addnewscripttoolinternaljob.h

https://invent.kde.org/pim/pim-sieve-editor/-/commit/c3130e79d9b676edaff963b6f156344b1eb13e47

diff --git a/src/internaltoolsjob/addnewscripttoolinternaljob.cpp b/src/internaltoolsjob/addnewscripttoolinternaljob.cpp
index 94329c9a..e3d30b24 100644
--- a/src/internaltoolsjob/addnewscripttoolinternaljob.cpp
+++ b/src/internaltoolsjob/addnewscripttoolinternaljob.cpp
@@ -29,27 +29,38 @@ QByteArray AddNewScriptToolInternalJob::toolId()
 
 void AddNewScriptToolInternalJob::start()
 {
-    if (mSieveEditorMainWidget) {
-        QString title;
-        for (const auto &resultTool : std::as_const(mToolArguments)) {
-            if (resultTool.keyTool == "title"_L1) {
-                title = resultTool.value;
-                mSieveEditorMainWidget->addNewScript(title);
-            } else {
-                qCWarning(SIEVEEDITOR_LOG) << "Invalid json tools result:" << resultTool.keyTool;
-            }
+    if (!canStart()) {
+        qCWarning(SIEVEEDITOR_LOG) << "Impossible to start AddNewScriptToolInternalJob";
+        emitFinished(i18n("Impossible to create a new sieve script: invalid arguments."));
+        return;
+    }
+    if (!mSieveEditorMainWidget) {
+        qCWarning(SIEVEEDITOR_LOG) << "mSieveEditorMainWidget is not set. It's a bug";
+        emitFinished(i18n("Impossible to create a new sieve script."));
+        return;
+    }
+    QString title;
+    for (const auto &resultTool : std::as_const(mToolArguments)) {
+        if (resultTool.keyTool == "title"_L1) {
+            title = resultTool.value;
+            mSieveEditorMainWidget->addNewScript(title);
+        } else {
+            qCWarning(SIEVEEDITOR_LOG) << "Invalid json tools result:" << resultTool.keyTool;
         }
-        const TextAutoGenerateText::TextAutoGenerateTextToolInternalJob::TextToolPluginInfo info{
-            .content = i18n("Create New Sieve Script named \"%1\"", title),
-            .messageUuid = mMessageUuid,
-            .chatId = mChatId,
-            .toolIdentifier = mToolIdentifier,
-            .attachementInfoList = {},
-        };
-        Q_EMIT finished(info);
-    } else {
-        qCWarning(SIEVEEDITOR_LOG) << "mSieveEditorMainWidget is not settings. It's a bug";
     }
+    emitFinished(i18n("Create New Sieve Script named \"%1\"", title));
+}
+
+void AddNewScriptToolInternalJob::emitFinished(const QString &content)
+{
+    const TextAutoGenerateText::TextAutoGenerateTextToolInternalJob::TextToolPluginInfo info{
+        .content = content,
+        .messageUuid = mMessageUuid,
+        .chatId = mChatId,
+        .toolIdentifier = mToolIdentifier,
+        .attachementInfoList = {},
+    };
+    Q_EMIT finished(info);
     deleteLater();
 }
 
diff --git a/src/internaltoolsjob/addnewscripttoolinternaljob.h b/src/internaltoolsjob/addnewscripttoolinternaljob.h
index 602ece0a..4a947cb6 100644
--- a/src/internaltoolsjob/addnewscripttoolinternaljob.h
+++ b/src/internaltoolsjob/addnewscripttoolinternaljob.h
@@ -19,5 +19,6 @@ public:
     void start() override;
 
 private:
+    void emitFinished(const QString &content);
     SieveEditorMainWidget *const mSieveEditorMainWidget;
 };
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.