summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-09-08 05:29:33 (GMT)
committerMontel Laurent <montel@kde.org>2016-09-08 05:29:33 (GMT)
commitea44df6f2c7833a4d5d2cff76a92925f08273d1d (patch)
tree53acf508607f524e3854f3123f55fce6bda594bb
parent0e857aeb41eaf6f3a489c69dd9acae8a1c09effc (diff)
Move isPluginActivated here
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/genericplugins/autotests/CMakeLists.txt6
-rw-r--r--src/genericplugins/autotests/pluginutiltest.cpp73
-rw-r--r--src/genericplugins/autotests/pluginutiltest.h35
-rw-r--r--src/genericplugins/pluginutil.cpp33
-rw-r--r--src/genericplugins/pluginutil.h35
7 files changed, 185 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cc30337..c0875af 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,7 +21,7 @@ include(ECMQtDeclareLoggingCategory)
include(ECMAddTests)
include(ECMInstallIcons)
-set(PIM_VERSION "5.3.43")
+set(PIM_VERSION "5.3.44")
set(PIMCOMMON_LIB_VERSION ${PIM_VERSION})
set(AKONADIMIME_LIB_VERSION "5.3.40")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 682beb6..89fb265 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -179,6 +179,7 @@ set(libpimcommon_generericplugin_SRCS
genericplugins/genericplugin.cpp
genericplugins/genericplugininterface.cpp
genericplugins/plugininterface.cpp
+ genericplugins/pluginutil.cpp
)
@@ -343,6 +344,7 @@ ecm_generate_headers(PimCommon_CamelCasegenericplugins_HEADERS
GenericPluginManager
GenericPlugin
GenericPluginInterface
+ PluginUtil
PluginInterface
REQUIRED_HEADERS PimCommon_genericplugins_HEADERS
PREFIX PimCommon
diff --git a/src/genericplugins/autotests/CMakeLists.txt b/src/genericplugins/autotests/CMakeLists.txt
index 683e0d2..8eb7d28 100644
--- a/src/genericplugins/autotests/CMakeLists.txt
+++ b/src/genericplugins/autotests/CMakeLists.txt
@@ -8,3 +8,9 @@ ecm_add_test(actiontypetest.cpp
NAME_PREFIX "pimcommon-genericplugins-"
LINK_LIBRARIES Qt5::Test KF5::PimCommon
)
+
+ecm_add_test(pluginutiltest.cpp
+ NAME_PREFIX "pimcommon-genericplugins-"
+ LINK_LIBRARIES Qt5::Test KF5::PimCommon
+)
+
diff --git a/src/genericplugins/autotests/pluginutiltest.cpp b/src/genericplugins/autotests/pluginutiltest.cpp
new file mode 100644
index 0000000..4127dbe
--- /dev/null
+++ b/src/genericplugins/autotests/pluginutiltest.cpp
@@ -0,0 +1,73 @@
+/*
+ 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 "pluginutiltest.h"
+#include "../pluginutil.h"
+#include <QTest>
+
+PluginUtilTest::PluginUtilTest(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+PluginUtilTest::~PluginUtilTest()
+{
+
+}
+
+
+void PluginUtilTest::shouldTestIsEnabled_data()
+{
+ QTest::addColumn<QStringList>("enabledPluginsList");
+ QTest::addColumn<QStringList>("disabledPluginsList");
+ QTest::addColumn<bool>("isEnabledByDefault");
+ QTest::addColumn<QString>("pluginId");
+ QTest::addColumn<bool>("result");
+
+ //Use default value
+ QTest::newRow("emptysettings") << QStringList() << QStringList() << true << QStringLiteral("foo") << true;
+ QTest::newRow("emptysettings-2") << QStringList() << QStringList() << false << QStringLiteral("foo") << false;
+
+ //Return false each time that pluginid is empty
+ QTest::newRow("pluginidempty") << QStringList() << QStringList() << true << QString() << false;
+ QTest::newRow("pluginidempty-2") << QStringList() << QStringList() << false << QString() << false;
+
+ //Use setting from user settings
+ QStringList disabled{ QStringLiteral("foo") };
+ QTest::newRow("usersettingdisabled") << QStringList() << disabled << true << QStringLiteral("foo") << false;
+ QTest::newRow("usersettingdisabled-2") << QStringList() << disabled << false << QStringLiteral("foo") << false;
+
+
+ QStringList enabled{ QStringLiteral("foo") };
+ QTest::newRow("usersettingenabled") << enabled << QStringList() << true << QStringLiteral("foo") << true;
+ QTest::newRow("usersettingenabled-2") << enabled << QStringList() << false << QStringLiteral("foo") << true;
+}
+
+void PluginUtilTest::shouldTestIsEnabled()
+{
+ QFETCH(QStringList, enabledPluginsList);
+ QFETCH(QStringList, disabledPluginsList);
+ QFETCH(bool, isEnabledByDefault);
+ QFETCH(QString, pluginId);
+ QFETCH(bool, result);
+
+ QCOMPARE(PimCommon::PluginUtil::isPluginActivated(enabledPluginsList, disabledPluginsList, isEnabledByDefault, pluginId), result);
+}
+
+QTEST_MAIN(PluginUtilTest)
diff --git a/src/genericplugins/autotests/pluginutiltest.h b/src/genericplugins/autotests/pluginutiltest.h
new file mode 100644
index 0000000..ffcfc04
--- /dev/null
+++ b/src/genericplugins/autotests/pluginutiltest.h
@@ -0,0 +1,35 @@
+/*
+ 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 PluginUtilTest_H
+#define PluginUtilTest_H
+
+#include <QObject>
+
+class PluginUtilTest : public QObject
+{
+ Q_OBJECT
+public:
+ explicit PluginUtilTest(QObject *parent = Q_NULLPTR);
+ ~PluginUtilTest();
+private Q_SLOTS:
+ void shouldTestIsEnabled_data();
+ void shouldTestIsEnabled();
+};
+
+#endif // PluginUtilTest_H
diff --git a/src/genericplugins/pluginutil.cpp b/src/genericplugins/pluginutil.cpp
new file mode 100644
index 0000000..f5faf87
--- /dev/null
+++ b/src/genericplugins/pluginutil.cpp
@@ -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
+*/
+
+
+#include "pluginutil.h"
+
+bool PimCommon::PluginUtil::isPluginActivated(const QStringList &enabledPluginsList, const QStringList &disabledPluginsList, bool isEnabledByDefault, const QString &pluginId)
+{
+ if (pluginId.isEmpty()) {
+ return false;
+ }
+ const bool pluginEnabledByUser = enabledPluginsList.contains(pluginId);
+ const bool pluginDisabledByUser = disabledPluginsList.contains(pluginId);
+ if ((isEnabledByDefault && !pluginDisabledByUser)
+ || (!isEnabledByDefault && pluginEnabledByUser)) {
+ return true;
+ }
+ return false;
+}
diff --git a/src/genericplugins/pluginutil.h b/src/genericplugins/pluginutil.h
new file mode 100644
index 0000000..89dee33
--- /dev/null
+++ b/src/genericplugins/pluginutil.h
@@ -0,0 +1,35 @@
+/*
+ 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 PLUGINUTIL_H
+#define PLUGINUTIL_H
+
+#include "pimcommon_export.h"
+
+#include <QString>
+#include <QStringList>
+
+namespace PimCommon
+{
+namespace PluginUtil
+{
+PIMCOMMON_EXPORT bool isPluginActivated(const QStringList &enabledPluginsList, const QStringList &disabledPluginsList, bool isEnabledByDefault, const QString &pluginId);
+}
+}
+
+#endif // PLUGINUTIL_H