summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-09-08 11:49:45 (GMT)
committerMontel Laurent <montel@kde.org>2016-09-08 11:49:45 (GMT)
commitaca21f7075b999fabc4c32664ffb1d3a33efa0c2 (patch)
treeeb31b28fa0b70214731561ac5eef4316dc9290d2
parentfcbeb8fa67c4d4b4a3fe9384c50820a753a315c8 (diff)
Add configure plugin widget
-rw-r--r--src/CMakeLists.txt7
-rw-r--r--src/configureplugins/autotests/CMakeLists.txt14
-rw-r--r--src/configureplugins/autotests/configurepluginslistwidgettest.cpp47
-rw-r--r--src/configureplugins/autotests/configurepluginslistwidgettest.h33
-rw-r--r--src/configureplugins/autotests/configurepluginswidgettest.cpp60
-rw-r--r--src/configureplugins/autotests/configurepluginswidgettest.h33
-rw-r--r--src/configureplugins/autotests/git0
-rw-r--r--src/configureplugins/configurepluginslistwidget.cpp82
-rw-r--r--src/configureplugins/configurepluginslistwidget.h65
-rw-r--r--src/configureplugins/configurepluginswidget.cpp123
-rw-r--r--src/configureplugins/configurepluginswidget.h55
11 files changed, 519 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 89fb265..12708dd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -182,6 +182,12 @@ set(libpimcommon_generericplugin_SRCS
genericplugins/pluginutil.cpp
)
+set(libpimcommon_configure_plugins_SRCS
+ configureplugins/configurepluginslistwidget.cpp
+ configureplugins/configurepluginswidget.cpp
+ )
+
+
set(libpimcommon_genericgrantlee_SRCS
genericgrantlee/genericgrantleeformatter.cpp
@@ -189,6 +195,7 @@ set(libpimcommon_genericgrantlee_SRCS
set(libpimcommon_SRCS
settings/pimcommonsettings.cpp
+ ${libpimcommon_configure_plugins_SRCS}
${libpimcommon_job_SRCS}
${libpimcommon_genericgrantlee_SRCS}
${libpimcommon_manageserversidesubscription_SRCS}
diff --git a/src/configureplugins/autotests/CMakeLists.txt b/src/configureplugins/autotests/CMakeLists.txt
new file mode 100644
index 0000000..b8bd1da
--- /dev/null
+++ b/src/configureplugins/autotests/CMakeLists.txt
@@ -0,0 +1,14 @@
+set( kmail_configureplugins_source_SRCS configurepluginswidgettest.cpp ../configurepluginswidget.cpp ../configurepluginslistwidget.cpp )
+add_executable( configurepluginswidgettest ${kmail_configureplugins_source_SRCS} )
+add_test( configurepluginswidgettest configurepluginswidgettest )
+ecm_mark_as_test(kmail-configurepluginswidgettest)
+target_link_libraries( configurepluginswidgettest Qt5::Test KF5::I18n Qt5::Widgets
+ KF5::ConfigCore KF5::TextWidgets KF5::WidgetsAddons KF5::PimCommon KF5::MessageViewer KF5::MessageComposer)
+
+
+set( kmail_configurepluginslist_source_SRCS configurepluginslistwidgettest.cpp ../configurepluginslistwidget.cpp )
+add_executable( configurepluginslistwidgettest ${kmail_configurepluginslist_source_SRCS} )
+add_test( configurepluginslistwidgettest configurepluginslistwidgettest )
+ecm_mark_as_test(kmail-configurepluginslistwidgettest)
+target_link_libraries( configurepluginslistwidgettest Qt5::Test KF5::I18n Qt5::Widgets
+ KF5::ConfigCore KF5::TextWidgets KF5::WidgetsAddons KF5::PimCommon KF5::MessageViewer KF5::MessageComposer)
diff --git a/src/configureplugins/autotests/configurepluginslistwidgettest.cpp b/src/configureplugins/autotests/configurepluginslistwidgettest.cpp
new file mode 100644
index 0000000..d1d65f2
--- /dev/null
+++ b/src/configureplugins/autotests/configurepluginslistwidgettest.cpp
@@ -0,0 +1,47 @@
+/*
+ Copyright (c) 2016 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, version 2, as
+ published by the Free Software Foundation.
+
+ 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; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "configurepluginslistwidgettest.h"
+#include "../configurepluginslistwidget.h"
+#include <QHBoxLayout>
+#include <QTest>
+#include <QTreeWidget>
+
+ConfigurePluginsListWidgetTest::ConfigurePluginsListWidgetTest(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+ConfigurePluginsListWidgetTest::~ConfigurePluginsListWidgetTest()
+{
+
+}
+
+void ConfigurePluginsListWidgetTest::shouldHaveDefaultValue()
+{
+ ConfigurePluginsListWidget w;
+
+ QVBoxLayout *mainLayout = w.findChild<QVBoxLayout *>(QStringLiteral("mainlayout"));
+ QVERIFY(mainLayout);
+ QCOMPARE(mainLayout->margin(), 0);
+
+ QTreeWidget *mListWidget = w.findChild<QTreeWidget *>(QStringLiteral("listwidget"));
+ QVERIFY(mListWidget);
+}
+
+QTEST_MAIN(ConfigurePluginsListWidgetTest)
diff --git a/src/configureplugins/autotests/configurepluginslistwidgettest.h b/src/configureplugins/autotests/configurepluginslistwidgettest.h
new file mode 100644
index 0000000..734f4a5
--- /dev/null
+++ b/src/configureplugins/autotests/configurepluginslistwidgettest.h
@@ -0,0 +1,33 @@
+/*
+ Copyright (c) 2016 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, version 2, as
+ published by the Free Software Foundation.
+
+ 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; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef CONFIGUREPLUGINSLISTWIDGETTEST_H
+#define CONFIGUREPLUGINSLISTWIDGETTEST_H
+
+#include <QObject>
+
+class ConfigurePluginsListWidgetTest : public QObject
+{
+ Q_OBJECT
+public:
+ explicit ConfigurePluginsListWidgetTest(QObject *parent = Q_NULLPTR);
+ ~ConfigurePluginsListWidgetTest();
+private Q_SLOTS:
+ void shouldHaveDefaultValue();
+};
+
+#endif // CONFIGUREPLUGINSLISTWIDGETTEST_H
diff --git a/src/configureplugins/autotests/configurepluginswidgettest.cpp b/src/configureplugins/autotests/configurepluginswidgettest.cpp
new file mode 100644
index 0000000..122882a
--- /dev/null
+++ b/src/configureplugins/autotests/configurepluginswidgettest.cpp
@@ -0,0 +1,60 @@
+/*
+ Copyright (c) 2016 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, version 2, as
+ published by the Free Software Foundation.
+
+ 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; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "configurepluginswidgettest.h"
+#include "../configurepluginswidget.h"
+#include "../configurepluginslistwidget.h"
+
+#include <KTextEdit>
+#include <KMessageWidget>
+#include <QSplitter>
+#include <QTest>
+
+ConfigurePluginsWidgetTest::ConfigurePluginsWidgetTest(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+ConfigurePluginsWidgetTest::~ConfigurePluginsWidgetTest()
+{
+
+}
+
+void ConfigurePluginsWidgetTest::shouldHaveDefaultValue()
+{
+ ConfigurePluginsWidget w;
+
+ KMessageWidget *messageWidget = w.findChild<KMessageWidget *>(QStringLiteral("messagewidget"));
+ QVERIFY(messageWidget);
+ QVERIFY(!messageWidget->isCloseButtonVisible());
+ QVERIFY(!messageWidget->text().isEmpty());
+
+ QSplitter *mSplitter = w.findChild<QSplitter *>(QStringLiteral("splitter"));
+ QVERIFY(mSplitter);
+ QCOMPARE(mSplitter->count(), 2);
+
+ ConfigurePluginsListWidget *mConfigureListWidget = mSplitter->findChild<ConfigurePluginsListWidget *>(QStringLiteral("configureListWidget"));
+ QVERIFY(mConfigureListWidget);
+
+ KTextEdit *mDescription = mSplitter->findChild<KTextEdit *>(QStringLiteral("description"));
+ QVERIFY(mDescription);
+ QVERIFY(mDescription->isReadOnly());
+ QVERIFY(mDescription->document()->isEmpty());
+}
+
+QTEST_MAIN(ConfigurePluginsWidgetTest)
diff --git a/src/configureplugins/autotests/configurepluginswidgettest.h b/src/configureplugins/autotests/configurepluginswidgettest.h
new file mode 100644
index 0000000..2ab81f4
--- /dev/null
+++ b/src/configureplugins/autotests/configurepluginswidgettest.h
@@ -0,0 +1,33 @@
+/*
+ Copyright (c) 2016 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, version 2, as
+ published by the Free Software Foundation.
+
+ 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; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef CONFIGUREPLUGINSWIDGETTEST_H
+#define CONFIGUREPLUGINSWIDGETTEST_H
+
+#include <QObject>
+
+class ConfigurePluginsWidgetTest : public QObject
+{
+ Q_OBJECT
+public:
+ explicit ConfigurePluginsWidgetTest(QObject *parent = Q_NULLPTR);
+ ~ConfigurePluginsWidgetTest();
+private Q_SLOTS:
+ void shouldHaveDefaultValue();
+};
+
+#endif // CONFIGUREPLUGINSWIDGETTEST_H
diff --git a/src/configureplugins/autotests/git b/src/configureplugins/autotests/git
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/configureplugins/autotests/git
diff --git a/src/configureplugins/configurepluginslistwidget.cpp b/src/configureplugins/configurepluginslistwidget.cpp
new file mode 100644
index 0000000..6f273e2
--- /dev/null
+++ b/src/configureplugins/configurepluginslistwidget.cpp
@@ -0,0 +1,82 @@
+/*
+ Copyright (c) 2016 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, version 2, as
+ published by the Free Software Foundation.
+
+ 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; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "configurepluginslistwidget.h"
+
+#include <KConfigGroup>
+#include <KSharedConfig>
+#include <KLocalizedString>
+
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QTreeWidget>
+
+using namespace PimCommon;
+ConfigurePluginsListWidget::ConfigurePluginsListWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+ mainLayout->setObjectName(QStringLiteral("mainlayout"));
+ mainLayout->setMargin(0);
+
+ mListWidget = new QTreeWidget(this);
+ mListWidget->setObjectName(QStringLiteral("listwidget"));
+ mListWidget->setHeaderHidden(true);
+ mListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
+ connect(mListWidget, &QTreeWidget::itemSelectionChanged, this, &ConfigurePluginsListWidget::slotItemSelectionChanged);
+ connect(mListWidget, &QTreeWidget::itemChanged, this, &ConfigurePluginsListWidget::slotItemChanged);
+
+ mainLayout->addWidget(mListWidget);
+
+}
+
+ConfigurePluginsListWidget::~ConfigurePluginsListWidget()
+{
+}
+
+void ConfigurePluginsListWidget::slotItemChanged(QTreeWidgetItem *item, int column)
+{
+ Q_UNUSED(item);
+ if (column == 0) {
+ Q_EMIT changed();
+ }
+}
+
+void ConfigurePluginsListWidget::slotItemSelectionChanged()
+{
+ QTreeWidgetItem *item = mListWidget->currentItem();
+ if (PluginItem *pluginItem = dynamic_cast<PluginItem *>(item)) {
+ Q_EMIT descriptionChanged(pluginItem->mDescription);
+ }
+}
+
+void ConfigurePluginsListWidget::save()
+{
+}
+
+void ConfigurePluginsListWidget::doLoadFromGlobalSettings()
+{
+ initialize();
+}
+
+void ConfigurePluginsListWidget::doResetToDefaultsOther()
+{
+}
+
+void ConfigurePluginsListWidget::initialize()
+{
+}
diff --git a/src/configureplugins/configurepluginslistwidget.h b/src/configureplugins/configurepluginslistwidget.h
new file mode 100644
index 0000000..58adec4
--- /dev/null
+++ b/src/configureplugins/configurepluginslistwidget.h
@@ -0,0 +1,65 @@
+/*
+ Copyright (c) 2016 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, version 2, as
+ published by the Free Software Foundation.
+
+ 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; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef CONFIGUREPLUGINSLISTWIDGET_H
+#define CONFIGUREPLUGINSLISTWIDGET_H
+
+#include <QWidget>
+#include "pimcommon_export.h"
+
+#include <QTreeWidgetItem>
+class QTreeWidget;
+namespace PimCommon
+{
+class PIMCOMMON_EXPORT ConfigurePluginsListWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit ConfigurePluginsListWidget(QWidget *parent = Q_NULLPTR);
+ ~ConfigurePluginsListWidget();
+
+ virtual void save();
+ virtual void doLoadFromGlobalSettings();
+ virtual void doResetToDefaultsOther();
+ virtual void initialize();
+Q_SIGNALS:
+ void descriptionChanged(const QString &description);
+ void changed();
+
+private:
+ void slotItemSelectionChanged();
+ void slotItemChanged(QTreeWidgetItem *item, int column);
+
+protected:
+ class PluginItem : public QTreeWidgetItem
+ {
+ public:
+ PluginItem(QTreeWidgetItem *parent)
+ : QTreeWidgetItem(parent),
+ mEnableByDefault(false)
+ {
+
+ }
+ QString mIdentifier;
+ QString mDescription;
+ bool mEnableByDefault;
+ };
+ QTreeWidget *mListWidget;
+};
+}
+
+#endif // CONFIGUREPLUGINSLISTWIDGET_H
diff --git a/src/configureplugins/configurepluginswidget.cpp b/src/configureplugins/configurepluginswidget.cpp
new file mode 100644
index 0000000..8d196fa
--- /dev/null
+++ b/src/configureplugins/configurepluginswidget.cpp
@@ -0,0 +1,123 @@
+/*
+ Copyright (c) 2016 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, version 2, as
+ published by the Free Software Foundation.
+
+ 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; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "configurepluginslistwidget.h"
+#include "configurepluginswidget.h"
+
+#include <QVBoxLayout>
+#include <KLocalizedString>
+#include <KConfigGroup>
+#include <QTextEdit>
+#include <KSharedConfig>
+#include <KMessageWidget>
+#include <QSplitter>
+
+using namespace PimCommon;
+
+ConfigurePluginsWidget::ConfigurePluginsWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ initLayout();
+}
+
+ConfigurePluginsWidget::ConfigurePluginsWidget(ConfigurePluginsListWidget *configurePluginListWidget, QWidget *parent)
+ : QWidget(parent)
+{
+ initLayout(configurePluginListWidget);
+}
+
+ConfigurePluginsWidget::~ConfigurePluginsWidget()
+{
+ writeConfig();
+}
+
+void ConfigurePluginsWidget::initLayout(ConfigurePluginsListWidget *configurePluginListWidget)
+{
+ QVBoxLayout *layout = new QVBoxLayout(this);
+
+ KMessageWidget *messageWidget = new KMessageWidget(this);
+ messageWidget->setObjectName(QStringLiteral("messagewidget"));
+ messageWidget->setText(i18n("Restart is necessary for applying the changes."));
+ messageWidget->setCloseButtonVisible(false);
+ layout->addWidget(messageWidget);
+
+ mSplitter = new QSplitter(this);
+ mSplitter->setObjectName(QStringLiteral("splitter"));
+ mSplitter->setChildrenCollapsible(false);
+ layout->addWidget(mSplitter);
+
+ if (!configurePluginListWidget) {
+ mConfigureListWidget = new ConfigurePluginsListWidget(this);
+ } else {
+ mConfigureListWidget = configurePluginListWidget;
+ }
+ mConfigureListWidget->setObjectName(QStringLiteral("configureListWidget"));
+ mSplitter->addWidget(mConfigureListWidget);
+
+ mDescription = new QTextEdit(this);
+ mDescription->setObjectName(QStringLiteral("description"));
+ mDescription->setReadOnly(true);
+
+ mSplitter->addWidget(mDescription);
+
+ connect(mConfigureListWidget, &ConfigurePluginsListWidget::descriptionChanged, mDescription, &QTextEdit::setText);
+ connect(mConfigureListWidget, &ConfigurePluginsListWidget::changed, this, &ConfigurePluginsWidget::changed);
+
+ initialize();
+ readConfig();
+}
+
+
+void ConfigurePluginsWidget::save()
+{
+ mConfigureListWidget->save();
+}
+
+QString ConfigurePluginsWidget::helpAnchor() const
+{
+ //TODO
+ return {};
+}
+
+void ConfigurePluginsWidget::doLoadFromGlobalSettings()
+{
+ mConfigureListWidget->doLoadFromGlobalSettings();
+}
+
+void ConfigurePluginsWidget::doResetToDefaultsOther()
+{
+ mConfigureListWidget->doResetToDefaultsOther();
+}
+
+void ConfigurePluginsWidget::readConfig()
+{
+ KConfigGroup group(KSharedConfig::openConfig(), "ConfigurePluginsWidget");
+ QList<int> size;
+ size << 400 << 100;
+ mSplitter->setSizes(group.readEntry("splitter", size));
+}
+
+void ConfigurePluginsWidget::writeConfig()
+{
+ KConfigGroup group(KSharedConfig::openConfig(), "ConfigurePluginsWidget");
+ group.writeEntry("splitter", mSplitter->sizes());
+}
+
+void ConfigurePluginsWidget::initialize()
+{
+ mConfigureListWidget->initialize();
+}
diff --git a/src/configureplugins/configurepluginswidget.h b/src/configureplugins/configurepluginswidget.h
new file mode 100644
index 0000000..23ad2c2
--- /dev/null
+++ b/src/configureplugins/configurepluginswidget.h
@@ -0,0 +1,55 @@
+/*
+ Copyright (c) 2016 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, version 2, as
+ published by the Free Software Foundation.
+
+ 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; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef CONFIGUREPLUGINSWIDGET_H
+#define CONFIGUREPLUGINSWIDGET_H
+
+#include <QWidget>
+#include "pimcommon_export.h"
+class QSplitter;
+class QTextEdit;
+namespace PimCommon
+{
+class ConfigurePluginsListWidget;
+class PIMCOMMON_EXPORT ConfigurePluginsWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit ConfigurePluginsWidget(QWidget *parent = Q_NULLPTR);
+ explicit ConfigurePluginsWidget(ConfigurePluginsListWidget *configurePluginListWidget, QWidget *parent = Q_NULLPTR);
+ ~ConfigurePluginsWidget();
+
+ void save();
+ QString helpAnchor() const;
+ void doLoadFromGlobalSettings();
+ void doResetToDefaultsOther();
+
+Q_SIGNALS:
+ void changed();
+
+private:
+ void initialize();
+ void readConfig();
+ void writeConfig();
+ void initLayout(ConfigurePluginsListWidget *configurePluginListWidget = Q_NULLPTR);
+
+ QSplitter *mSplitter;
+ ConfigurePluginsListWidget *mConfigureListWidget;
+ QTextEdit *mDescription;
+};
+}
+#endif // CONFIGUREPLUGINSWIDGET_H