Commit 7c4ee348 authored by Laurent Montel's avatar Laurent Montel 😁

Continue to implement grammalecte support

parent 1f011709
......@@ -17,3 +17,4 @@ add_kmail_grammalecte_unittest(grammarresultwidgettest.cpp "")
add_kmail_grammalecte_unittest(grammalectegrammarerrortest.cpp "")
add_kmail_grammalecte_unittest(grammarresultjobtest.cpp "")
add_kmail_grammalecte_unittest(grammarresulttextedittest.cpp "")
add_kmail_grammalecte_unittest(grammalecteconfigwidgettest.cpp "")
/*
Copyright (C) 2019 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "grammalecteconfigwidgettest.h"
#include "grammalecteconfigwidget.h"
#include <QTabWidget>
#include <QTest>
#include <QVBoxLayout>
#include <QStandardPaths>
QTEST_MAIN(GrammalecteConfigWidgetTest)
GrammalecteConfigWidgetTest::GrammalecteConfigWidgetTest(QObject *parent)
: QObject(parent)
{
QStandardPaths::setTestModeEnabled(true);
}
void GrammalecteConfigWidgetTest::shouldHaveDefaultValue()
{
GrammalecteConfigWidget w;
QVBoxLayout *mainLayout = w.findChild<QVBoxLayout *>(QStringLiteral("mainlayout"));
QVERIFY(mainLayout);
QCOMPARE(mainLayout->margin(), 0);
QTabWidget *mTab = w.findChild<QTabWidget *>(QStringLiteral("mTab"));
QVERIFY(mTab);
}
/*
Copyright (C) 2019 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef GRAMMALECTECONFIGWIDGETTEST_H
#define GRAMMALECTECONFIGWIDGETTEST_H
#include <QObject>
class GrammalecteConfigWidgetTest : public QObject
{
Q_OBJECT
public:
explicit GrammalecteConfigWidgetTest(QObject *parent = nullptr);
~GrammalecteConfigWidgetTest() = default;
private Q_SLOTS:
void shouldHaveDefaultValue();
};
#endif // GRAMMALECTECONFIGWIDGETTEST_H
......@@ -32,4 +32,21 @@ void GrammarResultJobTest::shouldHaveDefaultValue()
GrammarResultJob job;
QVERIFY(!job.canStart());
QVERIFY(job.text().isEmpty());
QVERIFY(job.pythonPath().isEmpty());
QVERIFY(job.grammarlecteCliPath().isEmpty());
QVERIFY(job.arguments().isEmpty());
}
void GrammarResultJobTest::shouldBeAbleToStart()
{
GrammarResultJob job;
QVERIFY(!job.canStart());
job.setText(QStringLiteral("ff"));
QVERIFY(!job.canStart());
job.setPythonPath(QStringLiteral("ff"));
QVERIFY(!job.canStart());
job.setGrammarlecteCliPath(QStringLiteral("ff"));
QVERIFY(!job.canStart());
job.setArguments(QStringList() << QStringLiteral("ff"));
QVERIFY(job.canStart());
}
......@@ -30,6 +30,7 @@ public:
~GrammarResultJobTest() = default;
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldBeAbleToStart();
};
#endif // GRAMMARRESULTJOBTEST_H
......@@ -16,6 +16,7 @@ generate_export_header(libkmailgrammalect BASE_NAME libkmailgrammalect)
target_link_libraries(libkmailgrammalect
KF5::I18n
KF5::IconThemes
KF5::ConfigCore
)
set_target_properties(libkmailgrammalect
......
......@@ -19,7 +19,10 @@
#include "grammalecteconfigwidget.h"
#include <QVBoxLayout>
#include <QTabWidget>
#include <KLocalizedString>
#include <KConfigGroup>
#include <KSharedConfig>
GrammalecteConfigWidget::GrammalecteConfigWidget(QWidget *parent)
: QWidget(parent)
......@@ -27,9 +30,41 @@ GrammalecteConfigWidget::GrammalecteConfigWidget(QWidget *parent)
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setObjectName(QStringLiteral("mainlayout"));
mainLayout->setMargin(0);
QTabWidget *mTab = new QTabWidget(this);
mTab->setObjectName(QStringLiteral("mTab"));
mainLayout->addWidget(mTab);
mTab->addTab(addGeneralTab(), i18n("General"));
mTab->addTab(addGrammarTab(), i18n("Grammar Settings"));
}
GrammalecteConfigWidget::~GrammalecteConfigWidget()
{
}
QWidget *GrammalecteConfigWidget::addGrammarTab()
{
QWidget *w = new QWidget(this);
w->setObjectName(QStringLiteral("grammar"));
return w;
}
QWidget *GrammalecteConfigWidget::addGeneralTab()
{
QWidget *w = new QWidget(this);
w->setObjectName(QStringLiteral("general"));
return w;
}
void GrammalecteConfigWidget::loadSettings()
{
KConfigGroup grp(KSharedConfig::openConfig(), "Grammalecte");
//TODO
}
void GrammalecteConfigWidget::saveSettings()
{
KConfigGroup grp(KSharedConfig::openConfig(), "Grammalecte");
//TODO
}
......@@ -28,6 +28,11 @@ class LIBGRAMMALECTPRIVATE_TESTS_EXPORT GrammalecteConfigWidget : public QWidget
public:
explicit GrammalecteConfigWidget(QWidget *parent = nullptr);
~GrammalecteConfigWidget();
void loadSettings();
void saveSettings();
private:
QWidget *addGeneralTab();
QWidget *addGrammarTab();
};
#endif // GRAMMALECTECONFIGWIDGET_H
......@@ -28,3 +28,8 @@ QString GrammalecteUtil::pythonPath() const
{
return mPythonPath;
}
QString GrammalecteUtil::grammalectePath() const
{
return mGrammalectePath;
}
......@@ -28,9 +28,12 @@ class LIBGRAMMALECTPRIVATE_TESTS_EXPORT GrammalecteUtil
public:
GrammalecteUtil();
QString pythonPath() const;
Q_REQUIRED_RESULT QString pythonPath() const;
Q_REQUIRED_RESULT QString grammalectePath() const;
private:
QString mPythonPath;
QString mGrammalectePath;
};
#endif // GRAMMALECTEUTIL_H
......@@ -19,7 +19,6 @@
#include "grammarresultjob.h"
#include "grammalecteplugin_debug.h"
#include <QProcess>
GrammarResultJob::GrammarResultJob(QObject *parent)
: QObject(parent)
......@@ -35,7 +34,16 @@ GrammarResultJob::~GrammarResultJob()
void GrammarResultJob::start()
{
if (canStart()) {
//TODO
QProcess *process = new QProcess(this);
process->setProgram(mPythonPath);
//TODO add argument!!!
process->setArguments(QStringList() << mGrammarlecteCliPath << mArguments);
connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &GrammarResultJob::slotFinished);
if (!process->waitForStarted()) {
qCWarning(KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG) << "Impossible to start grammarresultjob";
Q_EMIT error();
deleteLater();
}
} else {
qCWarning(KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG) << "Impossible to start grammarresultjob";
Q_EMIT error();
......@@ -43,6 +51,41 @@ void GrammarResultJob::start()
}
}
void GrammarResultJob::slotFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
//TODO emit signal
}
QStringList GrammarResultJob::arguments() const
{
return mArguments;
}
void GrammarResultJob::setArguments(const QStringList &arguments)
{
mArguments = arguments;
}
QString GrammarResultJob::grammarlecteCliPath() const
{
return mGrammarlecteCliPath;
}
void GrammarResultJob::setGrammarlecteCliPath(const QString &grammarlecteCliPath)
{
mGrammarlecteCliPath = grammarlecteCliPath;
}
QString GrammarResultJob::pythonPath() const
{
return mPythonPath;
}
void GrammarResultJob::setPythonPath(const QString &pythonPath)
{
mPythonPath = pythonPath;
}
static bool hasNotEmptyText(const QString &text)
{
for (int i = 0; i < text.length(); ++i) {
......@@ -55,7 +98,7 @@ static bool hasNotEmptyText(const QString &text)
bool GrammarResultJob::canStart() const
{
if (hasNotEmptyText(mText)) {
if (hasNotEmptyText(mText) && !mGrammarlecteCliPath.isEmpty() && !mPythonPath.isEmpty() && !mArguments.isEmpty()) {
return true;
}
return false;
......
......@@ -21,6 +21,7 @@
#define GRAMMARRESULTJOB_H
#include <QObject>
#include <QProcess>
#include "libgrammalect_private_export.h"
class LIBGRAMMALECTPRIVATE_TESTS_EXPORT GrammarResultJob : public QObject
{
......@@ -36,12 +37,25 @@ public:
Q_REQUIRED_RESULT QString text() const;
void setText(const QString &text);
Q_REQUIRED_RESULT QString pythonPath() const;
void setPythonPath(const QString &pythonPath);
Q_REQUIRED_RESULT QString grammarlecteCliPath() const;
void setGrammarlecteCliPath(const QString &grammarlecteCliPath);
Q_REQUIRED_RESULT QStringList arguments() const;
void setArguments(const QStringList &arguments);
Q_SIGNALS:
void finished(const QString &result);
void error();
private:
void slotFinished(int exitCode, QProcess::ExitStatus exitStatus);
QStringList mArguments;
QString mText;
QString mPythonPath;
QString mGrammarlecteCliPath;
};
#endif // GRAMMARRESULTJOB_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