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

Move isPluginActivated here

parent 0e857aeb
......@@ -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")
......
......@@ -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
......
......@@ -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
)
/*
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)
/*
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
/*
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;
}
/*
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
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