Commit a91cf4df authored by Laurent Montel's avatar Laurent Montel 😁

improve plugins

parent f2a16ddc
......@@ -40,3 +40,4 @@ org.kde.pim.kmail_markdownplugin kdepim-addons (kmail markdonw plugin) IDENTIFIE
org.kde.pim.mailtransport_sendmail kdepim-addons (kmailtransport sendmail plugin) IDENTIFIER [MAILTRANSPORT_PLUGIN_LOG]
org.kde.pim.kmail_sharetexteditorplugin kdepim-addons (share text editor plugin) IDENTIFIER [KMAIL_EDITOR_SHARETEXT_PLUGIN_LOG]
org.kde.pim.kmail_grammalecteplugin kdepim-addons (grammalecte plugin) IDENTIFIER [KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG]
org.kde.pim.libgrammalecteplugin kdepim-addons (libgramalecte) IDENTIFIER [LIBGRAMMALECTE_PLUGIN_LOG]
......@@ -19,3 +19,4 @@ add_kmail_grammalecte_unittest(grammarresultjobtest.cpp "")
add_kmail_grammalecte_unittest(grammarresulttextedittest.cpp "")
add_kmail_grammalecte_unittest(grammalecteconfigwidgettest.cpp "")
add_kmail_grammalecte_unittest(grammalectegenerateconfigoptionjobtest.cpp "")
add_kmail_grammalecte_unittest(grammalecteconfigdialogtest.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 "grammalecteconfigdialogtest.h"
#include "grammalecteconfigdialog.h"
#include <QTest>
QTEST_MAIN(GrammalecteConfigDialogTest)
GrammalecteConfigDialogTest::GrammalecteConfigDialogTest(QObject *parent)
: QObject(parent)
{
}
void GrammalecteConfigDialogTest::shouldHaveDefaultValue()
{
GrammalecteConfigDialog w;
QVERIFY(!w.windowTitle().isEmpty());
}
/*
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 GRAMMALECTECONFIGDIALOGTEST_H
#define GRAMMALECTECONFIGDIALOGTEST_H
#include <QObject>
class GrammalecteConfigDialogTest : public QObject
{
Q_OBJECT
public:
explicit GrammalecteConfigDialogTest(QObject *parent = nullptr);
~GrammalecteConfigDialogTest() = default;
private Q_SLOTS:
void shouldHaveDefaultValue();
};
#endif // GRAMMALECTECONFIGDIALOGTEST_H
......@@ -7,6 +7,8 @@ set(grammalecteplugin_SRCS
grammalecteinterface.cpp
)
ecm_qt_declare_logging_category(grammalecteplugin_SRCS HEADER grammalecteplugin_debug.h IDENTIFIER KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG CATEGORY_NAME org.kde.pim.kmail_grammalecteplugin)
kcoreaddons_add_plugin(kmail_grammalecteplugin JSON kmail_grammalecteplugin.json SOURCES
${grammalecteplugin_SRCS} INSTALL_NAMESPACE kmail)
......
......@@ -26,7 +26,6 @@
#include <KLocalizedString>
#include <KActionCollection>
#include <QDebug>
#include <QHBoxLayout>
......@@ -37,9 +36,6 @@ GrammalecteInterface::GrammalecteInterface(KActionCollection *ac, QWidget *paren
layout->setMargin(0);
mGrammarResultWidget = new GrammarResultWidget(this);
//TODO ????
//connect(mTranslatorWidget, &PimCommon::TranslatorWidget::toolsWasClosed, this, &TranslatorView::toolsWasClosed);
layout->addWidget(mGrammarResultWidget);
createAction(ac);
}
......@@ -53,6 +49,11 @@ void GrammalecteInterface::slotActivateGrammalecte(bool state)
{
if (state) {
mGrammarResultWidget->show();
if (richTextEditor()) {
mGrammarResultWidget->setText(richTextEditor()->toPlainText());
} else {
}
Q_EMIT activateView(this);
} else {
mGrammarResultWidget->hide();
......@@ -60,18 +61,6 @@ void GrammalecteInterface::slotActivateGrammalecte(bool state)
}
}
void GrammalecteInterface::setText(const QString &text)
{
//TOOD ???? using it ?
Q_UNUSED(text);
if (richTextEditor()) {
mGrammarResultWidget->setText(richTextEditor()->toPlainText());
} else {
//Add qdebug categories
qWarning() << "RichTextEditor not setted";
}
}
KToggleAction *GrammalecteInterface::action() const
{
return mAction;
......@@ -83,7 +72,6 @@ void GrammalecteInterface::createAction(KActionCollection *ac)
connect(mAction, &KToggleAction::triggered, this, &GrammalecteInterface::slotActivateGrammalecte);
if (ac) {
ac->addAction(QStringLiteral("checkgrammar-grammalecte"), mAction);
//ac->setDefaultShortcut(mAction, QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_T));
}
mAction->setChecked(false);
}
......@@ -29,7 +29,6 @@ public:
explicit GrammalecteInterface(KActionCollection *ac, QWidget *parent = nullptr);
~GrammalecteInterface() override;
void setText(const QString &text) override;
KToggleAction *action() const override;
private:
......
......@@ -18,8 +18,14 @@
*/
#include "grammalecteplugin.h"
#include "grammalecteinterface.h"
#include "grammalecteconfigdialog.h"
#include <PimCommon/CustomToolsWidgetng>
#include <KLocalizedString>
#include <kpluginfactory.h>
#include <QPointer>
K_PLUGIN_CLASS_WITH_JSON(GrammalectePlugin, "kmail_grammalecteplugin.json")
GrammalectePlugin::GrammalectePlugin(QObject *parent, const QList<QVariant> &)
: PimCommon::CustomToolsPlugin(parent)
......@@ -35,8 +41,12 @@ GrammalectePlugin::~GrammalectePlugin()
PimCommon::CustomToolsViewInterface *GrammalectePlugin::createView(KActionCollection *ac, PimCommon::CustomToolsWidgetNg *parent)
{
//TODO
return {};
GrammalecteInterface *view = new GrammalecteInterface(ac, parent);
connect(view, &GrammalecteInterface::toolsWasClosed, parent, &PimCommon::CustomToolsWidgetNg::slotToolsWasClosed);
connect(view, &GrammalecteInterface::insertText, parent, &PimCommon::CustomToolsWidgetNg::insertText);
connect(view, &GrammalecteInterface::activateView, parent, &PimCommon::CustomToolsWidgetNg::slotActivateView);
return view;
}
QString GrammalectePlugin::customToolName() const
......@@ -51,12 +61,11 @@ bool GrammalectePlugin::hasConfigureDialog() const
void GrammalectePlugin::showConfigureDialog(QWidget *parent)
{
//TODO
QPointer<GrammalecteConfigDialog> dlg = new GrammalecteConfigDialog(parent);
if (dlg->exec()) {
//TODO
}
delete dlg;
}
QString GrammalectePlugin::description() const
{
//TODO
return {};
}
#include "grammalecteplugin.moc"
......@@ -33,7 +33,6 @@ public:
Q_REQUIRED_RESULT QString customToolName() const override;
Q_REQUIRED_RESULT bool hasConfigureDialog() const override;
void showConfigureDialog(QWidget *parent) override;
Q_REQUIRED_RESULT QString description() const override;
};
#endif // GRAMMALECTEPLUGIN_H
......@@ -7,9 +7,10 @@ set(kmail_grammalecteplugin_SRCS
grammalecteconfigwidget.cpp
grammalecteutil.cpp
grammalectegenerateconfigoptionjob.cpp
grammalecteconfigdialog.cpp
)
ecm_qt_declare_logging_category(kmail_grammalecteplugin_SRCS HEADER grammalecteplugin_debug.h IDENTIFIER KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG CATEGORY_NAME org.kde.pim.kmail_grammalecteplugin)
ecm_qt_declare_logging_category(kmail_grammalecteplugin_SRCS HEADER libgrammalecte_debug.h IDENTIFIER LIBGRAMMALECTE_PLUGIN_LOG CATEGORY_NAME org.kde.pim.libgrammalecteplugin)
add_library(libkmailgrammalecte ${kmail_grammalecteplugin_SRCS})
......
/*
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 "grammalecteconfigdialog.h"
#include "grammalecteconfigwidget.h"
#include <KLocalizedString>
#include <QVBoxLayout>
#include <QDialogButtonBox>
GrammalecteConfigDialog::GrammalecteConfigDialog(QWidget *parent)
: QDialog(parent)
{
setWindowTitle(i18n("Configure Grammalecte"));
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setObjectName(QStringLiteral("mainlayout"));
mConfigWidget = new GrammalecteConfigWidget(this);
mConfigWidget->setObjectName(QStringLiteral("configwidget"));
mainLayout->addWidget(mConfigWidget);
QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
box->setObjectName(QStringLiteral("box"));
mainLayout->addWidget(box);
connect(box, &QDialogButtonBox::accepted, this, &GrammalecteConfigDialog::accept);
connect(box, &QDialogButtonBox::rejected, this, &GrammalecteConfigDialog::reject);
}
GrammalecteConfigDialog::~GrammalecteConfigDialog()
{
}
/*
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 GRAMMALECTECONFIGDIALOG_H
#define GRAMMALECTECONFIGDIALOG_H
#include <QDialog>
#include "libkmailgrammalecte_export.h"
class GrammalecteConfigWidget;
class LIBKMAILGRAMMALECTE_EXPORT GrammalecteConfigDialog : public QDialog
{
Q_OBJECT
public:
explicit GrammalecteConfigDialog(QWidget *parent = nullptr);
~GrammalecteConfigDialog();
private:
GrammalecteConfigWidget *mConfigWidget = nullptr;
};
#endif // GRAMMALECTECONFIGDIALOG_H
......@@ -25,6 +25,7 @@
#include <KLocalizedString>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QCheckBox>
GrammalecteConfigWidget::GrammalecteConfigWidget(QWidget *parent)
: QWidget(parent)
......@@ -37,7 +38,9 @@ GrammalecteConfigWidget::GrammalecteConfigWidget(QWidget *parent)
mTab->setObjectName(QStringLiteral("mTab"));
mainLayout->addWidget(mTab);
mTab->addTab(addGeneralTab(), i18n("General"));
mTab->addTab(addGrammarTab(), i18n("Grammar Settings"));
mGrammarTabWidget = addGrammarTab();
mTab->addTab(mGrammarTabWidget, i18n("Grammar Settings"));
loadSettings(); //First
loadGrammarSettings();
}
......@@ -58,16 +61,23 @@ void GrammalecteConfigWidget::loadGrammarSettings()
void GrammalecteConfigWidget::slotGetSettingsFinished(const QVector<GrammalecteGenerateConfigOptionJob::Option> &result)
{
mListOptions.reserve(result.count());
for (const GrammalecteGenerateConfigOptionJob::Option &opt : result) {
//TODO
QCheckBox *box = new QCheckBox(opt.description, this);
box->setProperty("optionname", opt.optionName);
mGrammarTabWidget->layout()->addWidget(box);
mListOptions.append(box);
}
}
QWidget *GrammalecteConfigWidget::addGrammarTab()
{
QWidget *w = new QWidget(this);
w->setObjectName(QStringLiteral("grammar"));
return w;
QWidget *grammarTabWidget = new QWidget(this);
grammarTabWidget->setObjectName(QStringLiteral("grammar"));
QVBoxLayout *layout = new QVBoxLayout(grammarTabWidget);
layout->setObjectName(QStringLiteral("grammartablayout"));
layout->setMargin(0);
return grammarTabWidget;
}
QWidget *GrammalecteConfigWidget::addGeneralTab()
......
......@@ -21,9 +21,10 @@
#define GRAMMALECTECONFIGWIDGET_H
#include <QWidget>
#include "libgrammalect_private_export.h"
#include "libkmailgrammalecte_export.h"
#include "grammalectegenerateconfigoptionjob.h"
class LIBGRAMMALECTPRIVATE_TESTS_EXPORT GrammalecteConfigWidget : public QWidget
class QCheckBox;
class LIBKMAILGRAMMALECTE_EXPORT GrammalecteConfigWidget : public QWidget
{
Q_OBJECT
public:
......@@ -36,6 +37,8 @@ private:
void loadGrammarSettings();
QWidget *addGeneralTab();
QWidget *addGrammarTab();
QWidget *mGrammarTabWidget = nullptr;
QList<QCheckBox *> mListOptions;
};
#endif // GRAMMALECTECONFIGWIDGET_H
......@@ -18,7 +18,7 @@
*/
#include "grammalectegenerateconfigoptionjob.h"
#include "grammalecteplugin_debug.h"
#include "libgrammalecte_debug.h"
#include <QRegularExpression>
#include <QRegularExpressionMatch>
......@@ -46,12 +46,12 @@ void GrammalecteGenerateConfigOptionJob::start()
connect(mProcess, &QProcess::readyReadStandardOutput, this, &GrammalecteGenerateConfigOptionJob::receivedStandardOutput);
mProcess->start();
if (!mProcess->waitForStarted()) {
qCWarning(KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG) << "Impossible to start GrammalecteGenerateConfigOptionJob";
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Impossible to start GrammalecteGenerateConfigOptionJob";
Q_EMIT error();
deleteLater();
}
} else {
qCWarning(KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG) << "Impossible to start GrammalecteGenerateConfigOptionJob";
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Impossible to start GrammalecteGenerateConfigOptionJob";
Q_EMIT error();
deleteLater();
}
......@@ -93,7 +93,7 @@ void GrammalecteGenerateConfigOptionJob::receivedStandardOutput()
void GrammalecteGenerateConfigOptionJob::slotFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
if (exitStatus != 0 || exitCode != 0) {
qDebug() << " ERROR :!!!!!!!!!!!!!!!!!!!!";
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "GrammalecteGenerateConfigOptionJob ERROR :!!!!!!!!!!!!!!!!!!!!" ;
} else {
Q_EMIT finished(parseResult());
}
......
......@@ -18,7 +18,7 @@
*/
#include "grammalectegrammarerror.h"
#include "grammalecteplugin_debug.h"
#include "libgrammalecte_debug.h"
#include <QJsonArray>
#include <QJsonObject>
......@@ -185,7 +185,7 @@ QColor GrammalecteGrammarError::parseColor(const QJsonObject &obj)
// }
col = QColor(array.at(0).toInt(), array.at(1).toInt(), array.at(2).toInt());
} else {
qCWarning(KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG) << "Parsing color: Array is not correct:" << array;
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Parsing color: Array is not correct:" << array;
}
return col;
}
......
......@@ -79,5 +79,5 @@ private:
};
Q_DECLARE_METATYPE(GrammalecteGrammarError)
Q_DECLARE_TYPEINFO(GrammalecteGrammarError, Q_MOVABLE_TYPE);
LIBKMAILGRAMMALECT_EXPORT QDebug operator <<(QDebug d, const GrammalecteGrammarError &t);
LIBKMAILGRAMMALECTE_EXPORT QDebug operator <<(QDebug d, const GrammalecteGrammarError &t);
#endif // GRAMMALECTEINFO_H
......@@ -18,7 +18,7 @@
*/
#include "grammalecteparser.h"
#include "grammalecteplugin_debug.h"
#include "libgrammalecte_debug.h"
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonValue>
......@@ -37,7 +37,7 @@ QVector<GrammalecteGrammarError> GrammalecteParser::parseResult(const QJsonObjec
{
QVector<GrammalecteGrammarError> infos;
if (!obj.contains(QLatin1String("grammalecte"))) {
qCWarning(KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG) << "Error in json " << obj;
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Error in json " << obj;
return infos;
}
const QJsonArray array = obj.value(QLatin1String("data")).toArray();
......@@ -57,11 +57,11 @@ QVector<GrammalecteGrammarError> GrammalecteParser::parseResult(const QJsonObjec
infos.append(info);
}
} else {
qCWarning(KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG) << "Problem when parsing grammalecte error" << error;
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Problem when parsing grammalecte error" << error;
}
}
} else {
qCWarning(KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG) << "Problem when parsing grammalecte result" << current;
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Problem when parsing grammalecte result" << current;
}
}
return infos;
......
......@@ -18,7 +18,7 @@
*/
#include "grammarresultjob.h"
#include "grammalecteplugin_debug.h"
#include "libgrammalecte_debug.h"
#include <QTemporaryFile>
......@@ -55,12 +55,12 @@ void GrammarResultJob::start()
mProcess->start();
if (!mProcess->waitForStarted()) {
qCWarning(KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG) << "Impossible to start grammarresultjob";
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Impossible to start grammarresultjob";
Q_EMIT error();
deleteLater();
}
} else {
qCWarning(KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG) << "Impossible to start grammarresultjob";
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Impossible to start grammarresultjob";
Q_EMIT error();
deleteLater();
}
......@@ -84,7 +84,7 @@ void GrammarResultJob::receivedStdErr()
void GrammarResultJob::slotFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
if (exitStatus != 0 || exitCode != 0) {
qCWarning(KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG) << "Error during running GrammarResultJob: " << mLastError;
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Error during running GrammarResultJob: " << mLastError;
} else {
Q_EMIT finished(mResult);
}
......
......@@ -19,7 +19,7 @@
#include "grammarresulttextedit.h"
#include "grammalecteplugin_debug.h"
#include "libgrammalecte_debug.h"
#include <QTextBlock>
#include <QTextDocument>
......@@ -52,7 +52,7 @@ void GrammarResultTextEdit::applyGrammarResult(const QVector<GrammalecteGrammarE
cur.setPosition(position + info.end(), QTextCursor::KeepAnchor);
cur.mergeCharFormat(format);
} else {
qCWarning(KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG) << "Unable to find block Id" << (info.blockId() -1);
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Unable to find block Id" << (info.blockId() -1);
}
}
}
......
......@@ -21,10 +21,10 @@
#define GRAMMARRESULTWIDGET_H
#include <QWidget>
#include "libkmailgrammalect_export.h"
#include "libkmailgrammalecte_export.h"
#include "grammalectegrammarerror.h"
class GrammarResultTextEdit;
class LIBKMAILGRAMMALECT_EXPORT GrammarResultWidget : public QWidget
class LIBKMAILGRAMMALECTE_EXPORT GrammarResultWidget : public QWidget
{
Q_OBJECT
public:
......
......@@ -20,12 +20,12 @@
#ifndef LIBGRAMMALECTPRIVATE_EXPORT_H
#define LIBGRAMMALECTPRIVATE_EXPORT_H
#include "libkmailgrammalect_export.h"
#include "libkmailgrammalecte_export.h"
/* Classes which are exported only for unit tests */
#ifdef BUILD_TESTING
# ifndef LIBGRAMMALECTPRIVATE_TESTS_EXPORT
# define LIBGRAMMALECTPRIVATE_TESTS_EXPORT LIBKMAILGRAMMALECT_EXPORT
# define LIBGRAMMALECTPRIVATE_TESTS_EXPORT LIBKMAILGRAMMALECTE_EXPORT
# endif
#else /* not compiling tests */
# define LIBGRAMMALECTPRIVATE_TESTS_EXPORT
......
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