Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 021ffb26 authored by Laurent Montel's avatar Laurent Montel 😁

Return type of error

parent 15e26572
......@@ -60,12 +60,13 @@ void GrammalecteResultJob::start()
mProcess->start();
if (!mProcess->waitForStarted()) {
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Impossible to start grammarresultjob";
Q_EMIT error();
Q_EMIT error(ErrorType::Unknown);
deleteLater();
}
} else {
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Impossible to start grammarresultjob";
Q_EMIT error();
if (mErrorType != ErrorType::TextIsEmpty) {
Q_EMIT error(mErrorType);
}
deleteLater();
}
}
......@@ -135,12 +136,21 @@ static bool hasNotEmptyText(const QString &text)
return false;
}
bool GrammalecteResultJob::canStart() const
bool GrammalecteResultJob::canStart()
{
if (hasNotEmptyText(mText) && !mGrammarlecteCliPath.isEmpty() && !mPythonPath.isEmpty()) {
return true;
if (!hasNotEmptyText(mText)) {
mErrorType = ErrorType::TextIsEmpty;
return false;
}
return false;
if (mGrammarlecteCliPath.isEmpty()) {
mErrorType = ErrorType::GrammalecteMissing;
return false;
}
if (mPythonPath.isEmpty()) {
mErrorType = ErrorType::PythonPathMissing;
return false;
}
return true;
}
QString GrammalecteResultJob::text() const
......
......@@ -30,9 +30,17 @@ public:
explicit GrammalecteResultJob(QObject *parent = nullptr);
~GrammalecteResultJob();
enum class ErrorType {
NoError = 0,
TextIsEmpty = 1,
PythonPathMissing = 2,
GrammalecteMissing = 3,
Unknown = 4,
};
void start();
Q_REQUIRED_RESULT bool canStart() const;
Q_REQUIRED_RESULT bool canStart();
Q_REQUIRED_RESULT QString text() const;
void setText(const QString &text);
......@@ -48,7 +56,7 @@ public:
Q_SIGNALS:
void finished(const QString &result);
void error();
void error(GrammalecteResultJob::ErrorType type);
private:
Q_DISABLE_COPY(GrammalecteResultJob)
......@@ -62,6 +70,7 @@ private:
QString mPythonPath;
QString mGrammarlecteCliPath;
QString mLastError;
GrammalecteResultJob::ErrorType mErrorType = ErrorType::NoError;
QProcess *mProcess = nullptr;
};
......
......@@ -19,8 +19,8 @@
#include "grammarresulttextedit.h"
#include "grammalecteresultwidget.h"
#include "libgrammalecte_debug.h"
#include "grammalectemanager.h"
#include "grammalecteresultjob.h"
#include "grammalecteparser.h"
#include <QHBoxLayout>
#include <QJsonDocument>
......@@ -55,7 +55,22 @@ void GrammalecteResultWidget::slotCheckGrammarFinished(const QString &result)
applyGrammarResult(parser.parseResult(fields));
}
void GrammalecteResultWidget::slotError()
void GrammalecteResultWidget::slotError(GrammalecteResultJob::ErrorType error)
{
//TODO
switch (error) {
case GrammalecteResultJob::ErrorType::NoError:
break;
case GrammalecteResultJob::ErrorType::TextIsEmpty:
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "An error found during executing GrammalecteResultJob: text is empty";
break;
case GrammalecteResultJob::ErrorType::PythonPathMissing:
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "An error found during executing GrammalecteResultJob: missing python path";
break;
case GrammalecteResultJob::ErrorType::GrammalecteMissing:
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "An error found during executing GrammalecteResultJob: missing grammalectepath" ;
break;
case GrammalecteResultJob::ErrorType::Unknown:
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "An error found during executing GrammalecteResultJob: unknow error";
break;
}
}
......@@ -23,10 +23,12 @@
#include "grammarresultwidget.h"
#include "libkmailgrammalecte_export.h"
#include "grammalectegrammarerror.h"
#include "grammalecteresultjob.h"
namespace MessageComposer {
class PluginGrammarAction;
}
class GrammarResultTextEdit;
class GrammalecteResultJob;
class LIBKMAILGRAMMALECTE_EXPORT GrammalecteResultWidget : public GrammarResultWidget
{
Q_OBJECT
......@@ -36,7 +38,7 @@ public:
void checkGrammar() override;
private:
void slotCheckGrammarFinished(const QString &result);
void slotError();
void slotError(GrammalecteResultJob::ErrorType error);
};
#endif // GRAMMALECTERESULTWIDGET_H
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