Verified Commit 70c42e4a authored by Ingo Klöcker's avatar Ingo Klöcker Committed by Ingo Klöcker
Browse files

Use GpgME::Error instead of the cryptic encoded error in task results

GpgME::Error provides a nice API, e.g. to check for a canceled operation,
while GpgME's encoded error (code) is a cryptic combination of the
error source and the actual error code which we would have to decode
when needed. And I didn't see a reason not to use GpgME::Error.

GnuPG-bug-id: 6196
parent 0ab233c1
......@@ -367,7 +367,7 @@ std::vector< std::shared_ptr<Task> > DecryptVerifyFilesController::Private::buil
kleo_assert(fileDir.exists());
tasks.push_back(taskFromOperationWidget(m_wizard->operationWidget(static_cast<unsigned int>(i)), fileNames[i], useOutDir ? outDir : fileDir, overwritePolicy));
} catch (const GpgME::Exception &e) {
tasks.push_back(Task::makeErrorTask(e.error().code(), QString::fromLocal8Bit(e.what()), fileNames[i]));
tasks.push_back(Task::makeErrorTask(e.error(), QString::fromLocal8Bit(e.what()), fileNames[i]));
}
return tasks;
......
......@@ -649,7 +649,7 @@ public:
const DecryptionResult &dr,
const QByteArray &stuff,
const QString &fileName,
int errCode,
const GpgME::Error &error,
const QString &errString,
const QString &input,
const QString &output,
......@@ -663,7 +663,7 @@ public:
m_decryptionResult(dr),
m_stuff(stuff),
m_fileName(fileName),
m_error(errCode),
m_error(error),
m_errorString(errString),
m_inputLabel(input),
m_outputLabel(output),
......@@ -697,7 +697,7 @@ public:
DecryptionResult m_decryptionResult;
QByteArray m_stuff;
QString m_fileName;
int m_error;
GpgME::Error m_error;
QString m_errorString;
QString m_inputLabel;
QString m_outputLabel;
......@@ -719,7 +719,7 @@ std::shared_ptr<DecryptVerifyResult> AbstractDecryptVerifyTask::fromDecryptResul
dr,
plaintext,
{},
0,
{},
QString(),
inputLabel(),
outputLabel(),
......@@ -736,7 +736,7 @@ std::shared_ptr<DecryptVerifyResult> AbstractDecryptVerifyTask::fromDecryptResul
DecryptionResult(err),
QByteArray(),
{},
err.code(),
err,
what,
inputLabel(),
outputLabel(),
......@@ -747,7 +747,7 @@ std::shared_ptr<DecryptVerifyResult> AbstractDecryptVerifyTask::fromDecryptResul
std::shared_ptr<DecryptVerifyResult> AbstractDecryptVerifyTask::fromDecryptVerifyResult(const DecryptionResult &dr, const VerificationResult &vr, const QByteArray &plaintext, const QString &fileName, const AuditLog &auditLog)
{
int err = dr.error() ? dr.error().code() : vr.error().code();
const auto err = dr.error() ? dr.error() : vr.error();
return std::shared_ptr<DecryptVerifyResult>(new DecryptVerifyResult(
DecryptVerify,
vr,
......@@ -771,7 +771,7 @@ std::shared_ptr<DecryptVerifyResult> AbstractDecryptVerifyTask::fromDecryptVerif
DecryptionResult(err),
QByteArray(),
{},
err.code(),
err,
details,
inputLabel(),
outputLabel(),
......@@ -788,7 +788,7 @@ std::shared_ptr<DecryptVerifyResult> AbstractDecryptVerifyTask::fromVerifyOpaque
DecryptionResult(),
plaintext,
{},
0,
{},
QString(),
inputLabel(),
outputLabel(),
......@@ -804,7 +804,7 @@ std::shared_ptr<DecryptVerifyResult> AbstractDecryptVerifyTask::fromVerifyOpaque
DecryptionResult(),
QByteArray(),
{},
err.code(),
err,
details,
inputLabel(),
outputLabel(),
......@@ -821,7 +821,7 @@ std::shared_ptr<DecryptVerifyResult> AbstractDecryptVerifyTask::fromVerifyDetach
DecryptionResult(),
QByteArray(),
{},
0,
{},
QString(),
inputLabel(),
outputLabel(),
......@@ -837,7 +837,7 @@ std::shared_ptr<DecryptVerifyResult> AbstractDecryptVerifyTask::fromVerifyDetach
DecryptionResult(),
QByteArray(),
{},
err.code(),
err,
details,
inputLabel(),
outputLabel(),
......@@ -851,14 +851,14 @@ DecryptVerifyResult::DecryptVerifyResult(DecryptVerifyOperation type,
const DecryptionResult &dr,
const QByteArray &stuff,
const QString &fileName,
int errCode,
const GpgME::Error &error,
const QString &errString,
const QString &inputLabel,
const QString &outputLabel,
const AuditLog &auditLog,
Task *parentTask,
const Mailbox &informativeSender)
: Task::Result(), d(new Private(type, vr, dr, stuff, fileName, errCode, errString, inputLabel, outputLabel, auditLog, parentTask, informativeSender, this))
: Task::Result(), d(new Private(type, vr, dr, stuff, fileName, error, errString, inputLabel, outputLabel, auditLog, parentTask, informativeSender, this))
{
}
......@@ -895,7 +895,7 @@ QString DecryptVerifyResult::details() const
d->m_parentTask);
}
int DecryptVerifyResult::errorCode() const
GpgME::Error DecryptVerifyResult::error() const
{
return d->m_error;
}
......
......@@ -220,7 +220,7 @@ public:
QString overview() const override;
QString details() const override;
int errorCode() const override;
GpgME::Error error() const override;
QString errorString() const override;
VisualCode code() const override;
AuditLog auditLog() const override;
......@@ -243,7 +243,7 @@ private:
const GpgME::DecryptionResult &dr,
const QByteArray &stuff,
const QString &fileName,
int errCode,
const GpgME::Error &error,
const QString &errString,
const QString &inputLabel,
const QString &outputLabel,
......
......@@ -45,7 +45,7 @@ public:
QString overview() const override;
QString details() const override;
int errorCode() const override;
GpgME::Error error() const override;
QString errorString() const override;
VisualCode code() const override;
AuditLog auditLog() const override;
......@@ -205,9 +205,9 @@ QString EncryptEMailResult::details() const
return QString();
}
int EncryptEMailResult::errorCode() const
GpgME::Error EncryptEMailResult::error() const
{
return m_result.error().encodedError();
return m_result.error();
}
QString EncryptEMailResult::errorString() const
......
......@@ -49,7 +49,7 @@ public:
QString overview() const override;
QString details() const override;
int errorCode() const override;
GpgME::Error error() const override;
QString errorString() const override;
VisualCode code() const override;
AuditLog auditLog() const override;
......@@ -257,9 +257,9 @@ QString SignEMailResult::details() const
return QString();
}
int SignEMailResult::errorCode() const
GpgME::Error SignEMailResult::error() const
{
return m_result.error().encodedError();
return m_result.error();
}
QString SignEMailResult::errorString() const
......
......@@ -58,9 +58,9 @@ public:
QString overview() const override;
QString details() const override;
int errorCode() const override
GpgME::Error error() const override
{
return m_error.encodedError();
return m_error;
}
QString errorString() const override
{
......@@ -133,7 +133,7 @@ public:
QString overview() const override;
QString details() const override;
int errorCode() const override;
GpgME::Error error() const override;
QString errorString() const override;
VisualCode code() const override;
AuditLog auditLog() const override;
......@@ -646,15 +646,15 @@ QString SignEncryptFilesResult::details() const
return errorString();
}
int SignEncryptFilesResult::errorCode() const
GpgME::Error SignEncryptFilesResult::error() const
{
if (m_sresult.error().code()) {
return m_sresult.error().encodedError();
return m_sresult.error();
}
if (m_eresult.error().code()) {
return m_eresult.error().encodedError();
return m_eresult.error();
}
return 0;
return {};
}
QString SignEncryptFilesResult::errorString() const
......
......@@ -35,8 +35,8 @@ namespace
class ErrorResult : public Task::Result
{
public:
ErrorResult(int code, const QString &details)
: Task::Result(), m_code(code), m_details(details) {}
ErrorResult(const GpgME::Error &error, const QString &details)
: Task::Result(), m_error(error), m_details(details) {}
QString overview() const override
{
......@@ -46,9 +46,9 @@ public:
{
return QString();
}
int errorCode() const override
GpgME::Error error() const override
{
return m_code;
return m_error;
}
QString errorString() const override
{
......@@ -63,7 +63,7 @@ public:
return AuditLog();
}
private:
const int m_code;
const GpgME::Error m_error;
const QString m_details;
};
}
......@@ -112,10 +112,10 @@ bool Task::asciiArmor() const
return d->m_asciiArmor;
}
std::shared_ptr<Task> Task::makeErrorTask(int code, const QString &details, const QString &label)
std::shared_ptr<Task> Task::makeErrorTask(const GpgME::Error &error, const QString &details, const QString &label)
{
const std::shared_ptr<SimpleTask> t(new SimpleTask(label));
t->setResult(t->makeErrorResult(code, details));
t->setResult(t->makeErrorResult(error, details));
return t;
}
......@@ -157,20 +157,20 @@ void Task::start()
try {
doStart();
} catch (const Kleo::Exception &e) {
QMetaObject::invokeMethod(this, "emitError", Qt::QueuedConnection, Q_ARG(int, e.error().encodedError()), Q_ARG(QString, e.message()));
QMetaObject::invokeMethod(this, "emitError", Qt::QueuedConnection, Q_ARG(GpgME::Error, e.error()), Q_ARG(QString, e.message()));
} catch (const GpgME::Exception &e) {
QMetaObject::invokeMethod(this, "emitError", Qt::QueuedConnection, Q_ARG(int, e.error().encodedError()), Q_ARG(QString, QString::fromLocal8Bit(e.what())));
QMetaObject::invokeMethod(this, "emitError", Qt::QueuedConnection, Q_ARG(GpgME::Error, e.error()), Q_ARG(QString, QString::fromLocal8Bit(e.what())));
} catch (const std::exception &e) {
QMetaObject::invokeMethod(this, "emitError", Qt::QueuedConnection, Q_ARG(int, makeGnuPGError(GPG_ERR_UNEXPECTED)), Q_ARG(QString, QString::fromLocal8Bit(e.what())));
QMetaObject::invokeMethod(this, "emitError", Qt::QueuedConnection, Q_ARG(GpgME::Error, Error::fromCode(GPG_ERR_UNEXPECTED)), Q_ARG(QString, QString::fromLocal8Bit(e.what())));
} catch (...) {
QMetaObject::invokeMethod(this, "emitError", Qt::QueuedConnection, Q_ARG(int, makeGnuPGError(GPG_ERR_UNEXPECTED)), Q_ARG(QString, i18n("Unknown exception in Task::start()")));
QMetaObject::invokeMethod(this, "emitError", Qt::QueuedConnection, Q_ARG(GpgME::Error, Error::fromCode(GPG_ERR_UNEXPECTED)), Q_ARG(QString, i18n("Unknown exception in Task::start()")));
}
Q_EMIT started(QPrivateSignal());
}
void Task::emitError(int errCode, const QString &details)
void Task::emitError(const GpgME::Error &error, const QString &details)
{
emitResult(makeErrorResult(errCode, details));
emitResult(makeErrorResult(error, details));
}
void Task::emitResult(const std::shared_ptr<const Task::Result> &r)
......@@ -180,9 +180,9 @@ void Task::emitResult(const std::shared_ptr<const Task::Result> &r)
Q_EMIT result(r, QPrivateSignal());
}
std::shared_ptr<Task::Result> Task::makeErrorResult(int errCode, const QString &details)
std::shared_ptr<Task::Result> Task::makeErrorResult(const GpgME::Error &error, const QString &details)
{
return std::shared_ptr<Task::Result>(new ErrorResult(errCode, details));
return std::shared_ptr<Task::Result>(new ErrorResult(error, details));
}
class Task::Result::Private
......@@ -196,7 +196,7 @@ Task::Result::~Result() {}
bool Task::Result::hasError() const
{
return errorCode() != 0;
return error().code() != 0;
}
static QString image(const char *img)
......
......@@ -55,7 +55,7 @@ public:
int id() const;
static std::shared_ptr<Task> makeErrorTask(int code, const QString &details, const QString &label);
static std::shared_ptr<Task> makeErrorTask(const GpgME::Error &error, const QString &details, const QString &label);
public Q_SLOTS:
virtual void cancel() = 0;
......@@ -66,7 +66,7 @@ Q_SIGNALS:
void started(QPrivateSignal);
protected:
std::shared_ptr<Result> makeErrorResult(int errCode, const QString &details);
std::shared_ptr<Result> makeErrorResult(const GpgME::Error &error, const QString &details);
void emitResult(const std::shared_ptr<const Task::Result> &result);
......@@ -74,7 +74,7 @@ protected Q_SLOTS:
void setProgress(const QString &msg, int processed, int total);
private Q_SLOTS:
void emitError(int errCode, const QString &details);
void emitError(const GpgME::Error &error, const QString &details);
private:
virtual void doStart() = 0;
......@@ -110,7 +110,7 @@ public:
virtual QString icon() const;
virtual QString overview() const = 0;
virtual QString details() const = 0;
virtual int errorCode() const = 0;
virtual GpgME::Error error() const = 0;
virtual QString errorString() const = 0;
virtual VisualCode code() const = 0;
virtual AuditLog auditLog() const = 0;
......
......@@ -305,7 +305,7 @@ public:
config.writeEntry("wasCMS", proto == GpgME::CMS);
}
if (result->errorCode()) {
if (result->error().code()) {
if (!result->errorString().isEmpty()) {
KMessageBox::error(q,
result->errorString(),
......@@ -358,7 +358,7 @@ public:
}
connect (task, &Task::result, q, [this, task] (const std::shared_ptr<const Kleo::Crypto::Task::Result> &result) {
qCDebug(KLEOPATRA_LOG) << "Decrypt / Verify done. Err:" << result->errorCode();
qCDebug(KLEOPATRA_LOG) << "Decrypt / Verify done. Err:" << result->error().code();
task->deleteLater();
cryptDone(result);
});
......@@ -441,7 +441,7 @@ public:
}
connect (task, &Task::result, q, [this, task] (const std::shared_ptr<const Kleo::Crypto::Task::Result> &result) {
qCDebug(KLEOPATRA_LOG) << "Encrypt / Sign done. Err:" << result->errorCode();
qCDebug(KLEOPATRA_LOG) << "Encrypt / Sign done. Err:" << result->error().code();
task->deleteLater();
cryptDone(result);
});
......
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