Commit 8959e13f authored by Volker Krause's avatar Volker Krause
Browse files

Forward error messages from command signatures to the consumer

That is, instead of showing a message box for those ourselves. This allows
fixing the problem that we currently get multiple of those message boxes
for the same error while switching signatures in KMail, as the methods to
retrieve the signature content get called several times.

This also allows consumers to use more appropriate or less invasive ways
of displaying the error.
parent c299ecd0
Pipeline #136681 passed with stages
in 48 seconds
# SPDX-FileCopyrightText: none
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
set(PIM_VERSION "5.19.40")
set(PIM_VERSION "5.19.41")
project(KIdentityManagement VERSION ${PIM_VERSION})
......
......@@ -11,7 +11,6 @@
#include "kidentitymanagement_debug.h"
#include <KConfigGroup>
#include <KLocalizedString>
#include <KMessageBox>
#include <KProcess>
#include <QDir>
......@@ -35,7 +34,7 @@ public:
void cleanupImages();
void saveImages() const;
Q_REQUIRED_RESULT QString textFromFile(bool *ok) const;
Q_REQUIRED_RESULT QString textFromCommand(bool *ok) const;
Q_REQUIRED_RESULT QString textFromCommand(bool *ok, QString *errorMessage) const;
/// List of images that belong to this signature. Either added by addImage() or
/// by readConfig().
......@@ -143,7 +142,7 @@ QString SignaturePrivate::textFromFile(bool *ok) const
return QString::fromLocal8Bit(ba.data(), ba.size());
}
QString SignaturePrivate::textFromCommand(bool *ok) const
QString SignaturePrivate::textFromCommand(bool *ok, QString *errorMessage) const
{
assert(type == Signature::FromCommand);
......@@ -166,12 +165,13 @@ QString SignaturePrivate::textFromCommand(bool *ok) const
if (ok) {
*ok = false;
}
const QString wmsg = i18n(
"<qt>Failed to execute signature script<p><b>%1</b>:</p>"
"<p>%2</p></qt>",
path,
QString::fromUtf8(proc.readAllStandardError()));
KMessageBox::error(nullptr, wmsg);
if (errorMessage) {
*errorMessage = i18n(
"<qt>Failed to execute signature script<p><b>%1</b>:</p>"
"<p>%2</p></qt>",
path,
QString::fromUtf8(proc.readAllStandardError()));
}
return {};
}
......@@ -237,7 +237,7 @@ Signature &Signature::operator=(const KIdentityManagement::Signature &that)
Signature::~Signature() = default;
QString Signature::rawText(bool *ok) const
QString Signature::rawText(bool *ok, QString *errorMessage) const
{
switch (d->type) {
case Disabled:
......@@ -253,15 +253,15 @@ QString Signature::rawText(bool *ok) const
case FromFile:
return d->textFromFile(ok);
case FromCommand:
return d->textFromCommand(ok);
return d->textFromCommand(ok, errorMessage);
}
qCritical() << "Signature::type() returned unknown value!";
return {}; // make compiler happy
}
QString Signature::withSeparator(bool *ok) const
QString Signature::withSeparator(bool *ok, QString *errorMessage) const
{
QString signature = rawText(ok);
QString signature = rawText(ok, errorMessage);
if (ok && (*ok) == false) {
return {};
}
......
......@@ -107,14 +107,16 @@ public:
/** @return the raw signature text as entered resp. read from file.
@param ok set to @c true if reading succeeded
@param errorMessage If available, contains a human readable explanation for @p ok being @c false.
*/
Q_REQUIRED_RESULT QString rawText(bool *ok = nullptr) const;
Q_REQUIRED_RESULT QString rawText(bool *ok = nullptr, QString *errorMessage = nullptr) const;
/** @return the signature text with a "-- \n" separator added, if
necessary. A newline will not be appended or prepended.
@param ok set to @c true if reading succeeded
@param errorMessage If available, contains a human readable explanation for @p ok being @c false.
*/
Q_REQUIRED_RESULT QString withSeparator(bool *ok = nullptr) const;
Q_REQUIRED_RESULT QString withSeparator(bool *ok = nullptr, QString *errorMessage = nullptr) const;
/** Set the signature text and mark this signature as being of
"inline text" type. */
......
Markdown is supported
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