Commit 6190245b authored by Laurent Montel's avatar Laurent Montel 😁

Move to common lib

parent be109435
......@@ -13,7 +13,7 @@ macro(add_kmail_grammalecte_unittest _source _additional)
endmacro ()
add_kmail_grammalecte_unittest(grammalecteparsertest.cpp "")
add_kmail_grammalecte_unittest(grammarresultwidgettest.cpp "")
add_kmail_grammalecte_unittest(grammalecteresultwidgettest.cpp "")
add_kmail_grammalecte_unittest(grammalectegrammarerrortest.cpp "")
add_kmail_grammalecte_unittest(grammarresultjobtest.cpp "")
add_kmail_grammalecte_unittest(grammarresulttextedittest.cpp "")
......
......@@ -17,8 +17,8 @@
Boston, MA 02110-1301, USA.
*/
#include "grammarresultwidgettest.h"
#include "grammarresultwidget.h"
#include "grammalecteresultwidgettest.h"
#include "grammalecteresultwidget.h"
#include "grammarresulttextedit.h"
#include <QHBoxLayout>
#include <QTest>
......@@ -31,7 +31,7 @@ GrammarResultWidgetTest::GrammarResultWidgetTest(QObject *parent)
void GrammarResultWidgetTest::shouldHaveDefaultValue()
{
GrammarResultWidget w;
GrammalecteResultWidget w;
QHBoxLayout *mainLayout = w.findChild<QHBoxLayout *>(QStringLiteral("mainlayout"));
QVERIFY(mainLayout);
QCOMPARE(mainLayout->margin(), 0);
......
......@@ -13,5 +13,5 @@ kcoreaddons_add_plugin(kmail_grammalecteplugin JSON kmail_grammalecteplugin.json
${grammalecteplugin_SRCS} INSTALL_NAMESPACE kmail)
target_link_libraries(kmail_grammalecteplugin
KF5::IconThemes KF5::MessageComposer KF5::I18n KF5::PimCommon KF5::XmlGui kmailgrammalecte
KF5::IconThemes KF5::MessageComposer KF5::I18n KF5::PimCommon KF5::XmlGui kmailgrammalecte grammarcommon
)
......@@ -18,7 +18,7 @@
*/
#include "grammalecteinterface.h"
#include "grammarresultwidget.h"
#include "grammalecteresultwidget.h"
#include "grammalecteplugin_debug.h"
#include <KPIMTextEdit/RichTextComposer>
......@@ -35,9 +35,9 @@ GrammalecteInterface::GrammalecteInterface(KActionCollection *ac, QWidget *paren
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setMargin(0);
mGrammarResultWidget = new GrammarResultWidget(this);
connect(mGrammarResultWidget, &GrammarResultWidget::replaceText, this, &GrammalecteInterface::slotReplaceText);
connect(mGrammarResultWidget, &GrammarResultWidget::checkAgain, this, &GrammalecteInterface::checkAgain);
mGrammarResultWidget = new GrammalecteResultWidget(this);
connect(mGrammarResultWidget, &GrammalecteResultWidget::replaceText, this, &GrammalecteInterface::slotReplaceText);
connect(mGrammarResultWidget, &GrammalecteResultWidget::checkAgain, this, &GrammalecteInterface::checkAgain);
layout->addWidget(mGrammarResultWidget);
createAction(ac);
......
......@@ -21,7 +21,7 @@
#include <MessageComposer/PluginEditorGrammarCustomToolsViewInterface>
class KActionCollection;
class GrammarResultWidget;
class GrammalecteResultWidget;
class GrammalecteInterface : public MessageComposer::PluginEditorGrammarCustomToolsViewInterface
{
Q_OBJECT
......@@ -36,7 +36,7 @@ private:
void slotActivateGrammalecte(bool state);
void createAction(KActionCollection *ac);
void checkAgain();
GrammarResultWidget *mGrammarResultWidget = nullptr;
GrammalecteResultWidget *mGrammarResultWidget = nullptr;
KToggleAction *mAction = nullptr;
};
......
......@@ -5,7 +5,7 @@ set(kmailgrammalecte_SRCS
grammalectegenerateconfigoptionjob.cpp
grammalecteconfigdialog.cpp
grammalectemanager.cpp
grammarresultwidget.cpp
grammalecteresultwidget.cpp
grammalectegrammarerror.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 "grammarresulttextedit.h"
#include "grammalecteresultwidget.h"
#include "grammalectemanager.h"
#include "grammarresultjob.h"
#include "grammalecteparser.h"
#include <QHBoxLayout>
#include <QJsonDocument>
#include <QTextEdit>
GrammalecteResultWidget::GrammalecteResultWidget(QWidget *parent)
: GrammarResultWidget(parent)
{
}
GrammalecteResultWidget::~GrammalecteResultWidget()
{
}
void GrammalecteResultWidget::checkGrammar()
{
GrammarResultJob *job = new GrammarResultJob(this);
job->setPythonPath(GrammalecteManager::self()->pythonPath());
job->setGrammarlecteCliPath(GrammalecteManager::self()->grammalectePath());
job->setArguments(GrammalecteManager::self()->options());
job->setText(mResult->toPlainText());
connect(job, &GrammarResultJob::finished, this, &GrammalecteResultWidget::slotCheckGrammarFinished);
job->start();
}
void GrammalecteResultWidget::slotCheckGrammarFinished(const QString &result)
{
GrammalecteParser parser;
const QJsonDocument doc = QJsonDocument::fromJson(result.toUtf8());
const QJsonObject fields = doc.object();
applyGrammarResult(parser.parseResult(fields));
}
/*
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 GRAMMALECTERESULTWIDGET_H
#define GRAMMALECTERESULTWIDGET_H
#include "grammarresultwidget.h"
#include "libkmailgrammalecte_export.h"
#include "grammalectegrammarerror.h"
namespace MessageComposer {
class PluginGrammarAction;
}
class GrammarResultTextEdit;
class LIBKMAILGRAMMALECTE_EXPORT GrammalecteResultWidget : public GrammarResultWidget
{
Q_OBJECT
public:
explicit GrammalecteResultWidget(QWidget *parent = nullptr);
~GrammalecteResultWidget() override;
void checkGrammar() override;
Q_SIGNALS:
void replaceText(const MessageComposer::PluginGrammarAction &act);
void checkAgain();
private:
void slotCheckGrammarFinished(const QString &result);
};
#endif // GRAMMALECTERESULTWIDGET_H
set(grammalecte_gui_SRCS main.cpp grammalectewidget.cpp)
add_executable(grammalecte_gui ${grammalecte_gui_SRCS})
target_link_libraries(grammalecte_gui
KF5::I18n kmailgrammalecte
KF5::I18n kmailgrammalecte grammarcommon
)
......@@ -26,7 +26,7 @@
#include <QPushButton>
#include <QDebug>
#include <QJsonDocument>
#include "grammarresultwidget.h"
#include "grammalecteresultwidget.h"
GrammalecteWidget::GrammalecteWidget(QWidget *parent)
: QWidget(parent)
......@@ -42,7 +42,7 @@ GrammalecteWidget::GrammalecteWidget(QWidget *parent)
mInput = new QTextEdit(this);
mainLayout->addWidget(mInput);
mResultWidget = new GrammarResultWidget(this);
mResultWidget = new GrammalecteResultWidget(this);
mainLayout->addWidget(mResultWidget);
connect(button, &QPushButton::clicked, this, &GrammalecteWidget::slotCheckGrammar);
......
......@@ -22,7 +22,7 @@
#include <QWidget>
#include "grammalectegenerateconfigoptionjob.h"
class GrammarResultWidget;
class GrammalecteResultWidget;
class QTextEdit;
class GrammalecteWidget : public QWidget
{
......@@ -37,7 +37,7 @@ private:
void slotGetSettingsFinished(const QVector<GrammalecteGenerateConfigOptionJob::Option> &result);
void slotResultFinished(const QString &result);
QTextEdit *mInput = nullptr;
GrammarResultWidget *mResultWidget = nullptr;
GrammalecteResultWidget *mResultWidget = nullptr;
};
#endif // GRAMMALECTEWIDGET_H
set(grammarcommon_SRCS
grammarerror.cpp
grammarresulttextedit.cpp
grammarresultwidget.cpp
)
ecm_qt_declare_logging_category(grammarcommon_SRCS HEADER grammarcommon_debug.h IDENTIFIER LIBGRAMMARCOMMON_LOG CATEGORY_NAME org.kde.pim.libgrammarcommon)
......
......@@ -19,9 +19,6 @@
#include "grammarresulttextedit.h"
#include "grammarresultwidget.h"
#include "grammalectemanager.h"
#include "grammarresultjob.h"
#include "grammalecteparser.h"
#include <QHBoxLayout>
#include <QJsonDocument>
#include <QTextEdit>
......@@ -43,25 +40,6 @@ GrammarResultWidget::~GrammarResultWidget()
{
}
void GrammarResultWidget::checkGrammar()
{
GrammarResultJob *job = new GrammarResultJob(this);
job->setPythonPath(GrammalecteManager::self()->pythonPath());
job->setGrammarlecteCliPath(GrammalecteManager::self()->grammalectePath());
job->setArguments(GrammalecteManager::self()->options());
job->setText(mResult->toPlainText());
connect(job, &GrammarResultJob::finished, this, &GrammarResultWidget::slotCheckGrammarFinished);
job->start();
}
void GrammarResultWidget::slotCheckGrammarFinished(const QString &result)
{
GrammalecteParser parser;
const QJsonDocument doc = QJsonDocument::fromJson(result.toUtf8());
const QJsonObject fields = doc.object();
applyGrammarResult(parser.parseResult(fields));
}
void GrammarResultWidget::setText(const QString &str)
{
mResult->setText(str);
......
......@@ -21,26 +21,25 @@
#define GRAMMARRESULTWIDGET_H
#include <QWidget>
#include "libkmailgrammalecte_export.h"
#include "grammalectegrammarerror.h"
#include "grammarcommon_export.h"
#include "grammarerror.h"
namespace MessageComposer {
class PluginGrammarAction;
}
class GrammarResultTextEdit;
class LIBKMAILGRAMMALECTE_EXPORT GrammarResultWidget : public QWidget
class GRAMMARCOMMON_EXPORT GrammarResultWidget : public QWidget
{
Q_OBJECT
public:
explicit GrammarResultWidget(QWidget *parent = nullptr);
~GrammarResultWidget();
void setText(const QString &str);
void checkGrammar();
virtual void checkGrammar() = 0;
void applyGrammarResult(const QVector<GrammarError> &infos);
Q_SIGNALS:
void replaceText(const MessageComposer::PluginGrammarAction &act);
void checkAgain();
private:
void slotCheckGrammarFinished(const QString &result);
protected:
GrammarResultTextEdit *mResult = nullptr;
};
......
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