networkurlinterceptormanager.cpp 3.27 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1 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, 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
*/

Laurent Montel's avatar
Fix api  
Laurent Montel committed
18
#include "networkpluginurlinterceptorinterface.h"
Laurent Montel's avatar
Laurent Montel committed
19 20
#include "networkurlinterceptormanager.h"
#include "networkurlinterceptorpluginmanager.h"
Laurent Montel's avatar
Laurent Montel committed
21

Laurent Montel's avatar
Laurent Montel committed
22 23
using namespace MessageViewer;

Laurent Montel's avatar
Rename  
Laurent Montel committed
24
class MessageViewer::NetworkUrlInterceptorManagerPrivate
Laurent Montel's avatar
Laurent Montel committed
25 26
{
public:
Laurent Montel's avatar
Laurent Montel committed
27
    NetworkUrlInterceptorManagerPrivate(QWebEngineView *webEngine, KActionCollection *ac, NetworkUrlInterceptorManager *qq)
Laurent Montel's avatar
Laurent Montel committed
28
        : q(qq)
Laurent Montel's avatar
Laurent Montel committed
29
    {
Laurent Montel's avatar
Laurent Montel committed
30
        createInterfaces(webEngine, ac);
Laurent Montel's avatar
Laurent Montel committed
31
    }
Laurent Montel's avatar
Laurent Montel committed
32 33

    QList<QAction *> actions() const;
Laurent Montel's avatar
Laurent Montel committed
34
    QVector<NetworkPluginUrlInterceptorConfigureWidgetSetting> configureInterceptorList(QWidget *parent) const;
Laurent Montel's avatar
Laurent Montel committed
35
    void createInterfaces(QWebEngineView *webEngine, KActionCollection *ac);
Laurent Montel's avatar
Rename  
Laurent Montel committed
36
    QVector<MessageViewer::NetworkPluginUrlInterceptorInterface *> mListInterface;
Laurent Montel's avatar
Laurent Montel committed
37
    QList<QAction *> mActionList;
Laurent Montel's avatar
Rename  
Laurent Montel committed
38
    NetworkUrlInterceptorManager *q;
Laurent Montel's avatar
Laurent Montel committed
39 40
};

Laurent Montel's avatar
Laurent Montel committed
41 42 43 44 45
QList<QAction *> NetworkUrlInterceptorManagerPrivate::actions() const
{
    return mActionList;
}

Laurent Montel's avatar
Laurent Montel committed
46
QVector<NetworkPluginUrlInterceptorConfigureWidgetSetting> NetworkUrlInterceptorManagerPrivate::configureInterceptorList(QWidget *parent) const
Laurent Montel's avatar
Laurent Montel committed
47
{
Laurent Montel's avatar
Laurent Montel committed
48
    QVector<NetworkPluginUrlInterceptorConfigureWidgetSetting> lstConfigureWidget;
Laurent Montel's avatar
Laurent Montel committed
49 50 51 52 53 54 55 56
    Q_FOREACH (NetworkPluginUrlInterceptor *plugin, NetworkUrlInterceptorPluginManager::self()->pluginsList()) {
        if (plugin->hasConfigureSupport()) {
            lstConfigureWidget.append(plugin->createConfigureWidget(parent));
        }
    }
    return lstConfigureWidget;
}

Laurent Montel's avatar
Laurent Montel committed
57
void NetworkUrlInterceptorManagerPrivate::createInterfaces(QWebEngineView *webEngine, KActionCollection *ac)
Laurent Montel's avatar
Laurent Montel committed
58
{
Laurent Montel's avatar
Rename  
Laurent Montel committed
59
    Q_FOREACH (NetworkPluginUrlInterceptor *plugin, NetworkUrlInterceptorPluginManager::self()->pluginsList()) {
Laurent Montel's avatar
Laurent Montel committed
60
        MessageViewer::NetworkPluginUrlInterceptorInterface *interface = plugin->createInterface(webEngine, q);
Laurent Montel's avatar
Fix api  
Laurent Montel committed
61
        interface->createActions(ac);
Laurent Montel's avatar
Laurent Montel committed
62
        mActionList.append(interface->actions());
Laurent Montel's avatar
Laurent Montel committed
63 64 65 66
        mListInterface.append(interface);
    }
}

Laurent Montel's avatar
Laurent Montel committed
67
NetworkUrlInterceptorManager::NetworkUrlInterceptorManager(QWebEngineView *webEngine, KActionCollection *ac, QObject *parent)
Laurent Montel's avatar
Laurent Montel committed
68
    : QObject(parent),
Laurent Montel's avatar
Laurent Montel committed
69
      d(new NetworkUrlInterceptorManagerPrivate(webEngine, ac, this))
Laurent Montel's avatar
Laurent Montel committed
70 71 72 73
{

}

Laurent Montel's avatar
Rename  
Laurent Montel committed
74
NetworkUrlInterceptorManager::~NetworkUrlInterceptorManager()
Laurent Montel's avatar
Laurent Montel committed
75 76 77
{
    delete d;
}
Laurent Montel's avatar
Laurent Montel committed
78

Laurent Montel's avatar
Rename  
Laurent Montel committed
79
QVector<MessageViewer::NetworkPluginUrlInterceptorInterface *> NetworkUrlInterceptorManager::interfaceList() const
Laurent Montel's avatar
Laurent Montel committed
80 81 82 83
{
    return d->mListInterface;
}

Laurent Montel's avatar
Laurent Montel committed
84 85 86 87 88
QList<QAction *> NetworkUrlInterceptorManager::actions() const
{
    return d->actions();
}

Laurent Montel's avatar
Laurent Montel committed
89
QVector<NetworkPluginUrlInterceptorConfigureWidgetSetting> NetworkUrlInterceptorManager::configureInterceptorList(QWidget *parent) const
Laurent Montel's avatar
Laurent Montel committed
90 91 92 93
{
    return d->configureInterceptorList(parent);
}