Commit aca21f70 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add configure plugin widget

parent fcbeb8fa
......@@ -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}
......
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)
/*
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)
/*
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
/*
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)
/*
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
/*
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()
{
}
/*
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
/*
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();
}
/*
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
Supports Markdown
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