Commit 89ff3433 authored by Laurent Montel's avatar Laurent Montel 😁

load plugin + add test apps

parent e567b79d
......@@ -54,6 +54,10 @@ set_package_properties(Sasl2 PROPERTIES
TYPE OPTIONAL
)
if(BUILD_TESTING)
add_definitions(-DBUILD_TESTING)
endif(BUILD_TESTING)
########### Targets ###########
add_subdirectory(cmake)
add_subdirectory(src)
......
......@@ -171,6 +171,7 @@ install(FILES
if(BUILD_TESTING)
add_subdirectory(tests)
add_subdirectory(plugins/tests)
endif()
add_subdirectory(plugins/smtp)
/* This file is part of the KDE project
Copyright (C) 2007 David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KMAILTRANSPORTPRIVATE_EXPORT_H
#define KMAILTRANSPORTPRIVATE_EXPORT_H
#include "mailtransport_export.h"
/* Classes which are exported only for unit tests */
#ifdef BUILD_TESTING
# ifndef KMAILTRANSPORT_TESTS_EXPORT
# define KMAILTRANSPORT_TESTS_EXPORT MAILTRANSPORT_EXPORT
# endif
#else /* not compiling tests */
# define KMAILTRANSPORT_TESTS_EXPORT
#endif
#endif
include(ECMMarkAsTest)
find_package(Qt5Test CONFIG REQUIRED)
add_executable(transportmanagertest transportmanagertest.cpp)
ecm_mark_as_test(transportmanagertest)
target_link_libraries(transportmanagertest KF5MailTransport)
/*
Copyright (c) 2017 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "transportmanagertest.h"
#include "kmailtransport/plugins/transportpluginmanager.h"
#include <QCoreApplication>
#include <MailTransport/TransportAbstractPlugin>
#include <QDebug>
TransportManagerTest::TransportManagerTest(QObject *parent)
: QObject(parent)
{
}
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
const QVector<MailTransport::TransportAbstractPlugin *> lst = MailTransport::TransportPluginManager::self()->pluginsList();
for (MailTransport::TransportAbstractPlugin *plugin : lst) {
const QVector<MailTransport::TransportAbstractPluginInfo> lstPluginInfo = plugin->names();
for (const MailTransport::TransportAbstractPluginInfo &info : lstPluginInfo) {
qDebug() << "Plugin name " << info.name;
}
}
return 0;
}
/*
Copyright (c) 2017 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef TRANSPORTMANAGERTEST_H
#define TRANSPORTMANAGERTEST_H
#include <QObject>
class TransportManagerTest : public QObject
{
Q_OBJECT
public:
explicit TransportManagerTest(QObject *parent = nullptr);
};
#endif // TRANSPORTMANAGERTEST_H
......@@ -18,12 +18,15 @@
*/
#include "transportpluginmanager.h"
#include "mailtransport_debug.h"
#include <kpluginmetadata.h>
#include <KPluginLoader>
#include <KPluginFactory>
#include <MailTransport/TransportAbstractPlugin>
#include <QFileInfo>
using namespace MailTransport;
class TransportPluginManagerInstancePrivate
......@@ -48,8 +51,7 @@ class MailTransportPluginInfo
{
public:
MailTransportPluginInfo()
: plugin(nullptr),
isEnabled(true)
: plugin(nullptr)
{
}
......@@ -57,7 +59,6 @@ public:
QString metaDataFileNameBaseName;
QString metaDataFileName;
MailTransport::TransportAbstractPlugin *plugin;
bool isEnabled;
};
namespace
......@@ -89,28 +90,19 @@ bool TransportPluginManagerPrivate::initializePlugins()
if (!mPluginList.isEmpty()) {
return true;
}
/*
static const QString s_serviceTypeName = serviceTypeName;
const QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(pluginName, [](const KPluginMetaData & md) {
return md.serviceTypes().contains(s_serviceTypeName);
const QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("mailtransport"), [](const KPluginMetaData &md) {
return md.serviceTypes().contains(QStringLiteral("MailTransport/Plugin"));
});
const QPair<QStringList, QStringList> pair = PimCommon::PluginUtil::loadPluginSetting(configGroupName(), configPrefixSettingKey());
QVectorIterator<KPluginMetaData> i(plugins);
i.toBack();
QSet<QString> unique;
while (i.hasPrevious()) {
GenericPluginInfo info;
MailTransportPluginInfo info;
const KPluginMetaData data = i.previous();
//1) get plugin data => name/description etc.
info.pluginData = PimCommon::PluginUtil::createPluginMetaData(data);
//2) look at if plugin is activated
const bool isPluginActivated = PimCommon::PluginUtil::isPluginActivated(pair.first, pair.second, info.pluginData.mEnableByDefault, info.pluginData.mIdentifier);
info.isEnabled = isPluginActivated;
info.metaDataFileNameBaseName = QFileInfo(data.fileName()).baseName();
info.metaDataFileName = data.fileName();
if (pluginVersion() == data.version()) {
// only load plugins once, even if found multiple times!
if (unique.contains(info.metaDataFileNameBaseName)) {
......@@ -120,35 +112,29 @@ bool TransportPluginManagerPrivate::initializePlugins()
mPluginList.push_back(info);
unique.insert(info.metaDataFileNameBaseName);
} else {
qCWarning(PIMCOMMON_LOG) << "Plugin " << data.name() << " doesn't have correction plugin version. It will not be loaded.";
qCWarning(MAILTRANSPORT_LOG) << "Plugin " << data.name() << " doesn't have correction plugin version. It will not be loaded.";
}
}
QVector<GenericPluginInfo>::iterator end(mPluginList.end());
for (QVector<GenericPluginInfo>::iterator it = mPluginList.begin(); it != end; ++it) {
const QVector<MailTransportPluginInfo>::iterator end(mPluginList.end());
for (QVector<MailTransportPluginInfo>::iterator it = mPluginList.begin(); it != end; ++it) {
loadPlugin(&(*it));
}
*/
return true;
}
void TransportPluginManagerPrivate::loadPlugin(MailTransportPluginInfo *item)
{
/*
KPluginLoader pluginLoader(item->metaDataFileName);
if (pluginLoader.factory()) {
item->plugin = pluginLoader.factory()->create<PluginEditorInit>(q, QVariantList() << item->metaDataFileNameBaseName);
item->plugin->setIsEnabled(item->isEnabled);
item->pluginData.mHasConfigureDialog = item->plugin->hasConfigureDialog();
mPluginDataList.append(item->pluginData);
item->plugin = pluginLoader.factory()->create<MailTransport::TransportAbstractPlugin>(q, QVariantList() << item->metaDataFileNameBaseName);
}
*/
}
QVector<MailTransport::TransportAbstractPlugin *> TransportPluginManagerPrivate::pluginsList() const
{
QVector<MailTransport::TransportAbstractPlugin *> lst;
QVector<MailTransportPluginInfo>::ConstIterator end(mPluginList.constEnd());
const QVector<MailTransportPluginInfo>::ConstIterator end(mPluginList.constEnd());
for (QVector<MailTransportPluginInfo>::ConstIterator it = mPluginList.constBegin(); it != end; ++it) {
if (auto plugin = (*it).plugin) {
lst << plugin;
......
......@@ -21,10 +21,11 @@
#define TRANSPORTPLUGINMANAGER_H
#include <QObject>
#include "kmailtransport_private_export.h"
namespace MailTransport {
class TransportAbstractPlugin;
class TransportPluginManagerPrivate;
class TransportPluginManager : public QObject
class KMAILTRANSPORT_TESTS_EXPORT TransportPluginManager : public QObject
{
Q_OBJECT
public:
......
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