kmailplugineditorcheckbeforesendmanagerinterface.cpp 2.87 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
Laurent Montel's avatar
Laurent Montel committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
   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 as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   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; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
Laurent Montel's avatar
Laurent Montel committed
18 19 20
*/

#include "kmailplugineditorcheckbeforesendmanagerinterface.h"
Laurent Montel's avatar
Laurent Montel committed
21 22 23 24
#include "kmail_debug.h"
#include <MessageComposer/PluginEditorCheckBeforeSendInterface>
#include <MessageComposer/PluginEditorCheckBeforeSend>
#include <MessageComposer/PluginEditorCheckBeforeSendManager>
Laurent Montel's avatar
Laurent Montel committed
25 26

KMailPluginEditorCheckBeforeSendManagerInterface::KMailPluginEditorCheckBeforeSendManagerInterface(QObject *parent)
Laurent Montel's avatar
Laurent Montel committed
27
    : QObject(parent),
28 29
      mParentWidget(Q_NULLPTR),
      mIdentityManagement(Q_NULLPTR)
Laurent Montel's avatar
Laurent Montel committed
30 31 32 33 34 35 36 37
{

}

KMailPluginEditorCheckBeforeSendManagerInterface::~KMailPluginEditorCheckBeforeSendManagerInterface()
{

}
Laurent Montel's avatar
Laurent Montel committed
38 39 40 41 42 43 44 45 46 47 48

QWidget *KMailPluginEditorCheckBeforeSendManagerInterface::parentWidget() const
{
    return mParentWidget;
}

void KMailPluginEditorCheckBeforeSendManagerInterface::setParentWidget(QWidget *parentWidget)
{
    mParentWidget = parentWidget;
}

49 50 51 52 53
void KMailPluginEditorCheckBeforeSendManagerInterface::setIdentityManagement(KIdentityManagement::IdentityManager *identityManagement)
{
    mIdentityManagement = identityManagement;
}

Laurent Montel's avatar
Laurent Montel committed
54 55 56 57 58 59 60 61 62 63
void KMailPluginEditorCheckBeforeSendManagerInterface::initializePlugins()
{
    if (!mListPluginInterface.isEmpty()) {
        qCDebug(KMAIL_LOG) << "Plugin was already initialized. This is a bug";
        return;
    }
    const QVector<MessageComposer::PluginEditorCheckBeforeSend *> lstPlugin = MessageComposer::PluginEditorCheckBeforeSendManager::self()->pluginsList();
    Q_FOREACH (MessageComposer::PluginEditorCheckBeforeSend *plugin, lstPlugin) {
        MessageComposer::PluginEditorCheckBeforeSendInterface *interface = plugin->createInterface(this);
        interface->setParentWidget(mParentWidget);
64
        interface->setIdentityManagement(mIdentityManagement);
Laurent Montel's avatar
Laurent Montel committed
65
        interface->reloadConfig();
Laurent Montel's avatar
Laurent Montel committed
66 67 68
        mListPluginInterface.append(interface);
    }
}
Laurent Montel's avatar
Laurent Montel committed
69

Laurent Montel's avatar
Laurent Montel committed
70
bool KMailPluginEditorCheckBeforeSendManagerInterface::execute(const MessageComposer::PluginEditorCheckBeforeSendParams &params) const
Laurent Montel's avatar
Laurent Montel committed
71 72
{
    Q_FOREACH (MessageComposer::PluginEditorCheckBeforeSendInterface *interface, mListPluginInterface) {
Laurent Montel's avatar
Laurent Montel committed
73
        if (!interface->exec(params)) {
Laurent Montel's avatar
Laurent Montel committed
74 75 76 77 78
            return false;
        }
    }
    return true;
}