~ubuntu-branches/ubuntu/trusty/digikam/trusty

« back to all changes in this revision

Viewing changes to extra/libkipi/tests/kipitestpluginloader.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-11-26 18:24:20 UTC
  • mfrom: (1.9.1) (3.1.23 experimental)
  • Revision ID: package-import@ubuntu.com-20121126182420-qoy6z0nx4ai0wzcl
Tags: 4:3.0.0~beta3-0ubuntu1
* New upstream release
  - Add build-deps :  libhupnp-dev, libqtgstreamer-dev, libmagickcore-dev
* Merge from debian, remaining changes:
  - Make sure libqt4-opengl-dev, libgl1-mesa-dev and libglu1-mesa-dev only
    install on i386,amd64 and powerpc
  - Depend on libtiff-dev instead of libtiff4-dev
  - Drop digikam breaks/replaces kipi-plugins-common since we're past the
    LTS release now
  - digikam to recommend mplayerthumbs | ffmpegthumbs. We currently only
    have latter in the archives, even though former is also supposed to
    be part of kdemultimedia. (LP: #890059)
  - kipi-plugins to recommend www-browser rather than konqueror directly
    since 2.8 no direct usage of konqueror is present in the flickr
    plugin anymore (LP: #1011211)
  - Keep kubuntu_mysqld_executable_name.diff
  - Don't install libkipi translations
  - Keep deps on libcv-dev, libcvaux-dev
  - Keep split packaging of libraries
  - Replace icons from KDE 3 time in debian/xpm.d/*.xpm with the new
    versions (LP: #658047)
* Update debian/not-installed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** ===========================================================
 
2
 * @file
 
3
 *
 
4
 * This file is a part of kipi-plugins project
 
5
 * <a href="http://www.digikam.org">http://www.digikam.org</a>
 
6
 *
 
7
 * @date   2012-06-20
 
8
 * @brief  kipi host test application using KDE XML-GUI technology
 
9
 *
 
10
 * @author Copyright (C) 2012 by Victor Dodon
 
11
 *         <a href="mailto:dodonvictor at gmail dot com">dodonvictor at gmail dot com</a>
 
12
 *
 
13
 * This program is free software; you can redistribute it
 
14
 * and/or modify it under the terms of the GNU General
 
15
 * Public License as published by the Free Software Foundation;
 
16
 * either version 2, or (at your option) any later version.
 
17
 *
 
18
 * This program is distributed in the hope that it will be useful,
 
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
21
 * GNU General Public License for more details.
 
22
 *
 
23
 * ============================================================ */
 
24
 
 
25
#include "kipitestpluginloader.moc"
 
26
 
 
27
// Qt includes
 
28
 
 
29
#include <QMap>
 
30
#include <QAction>
 
31
 
 
32
// KDE includes
 
33
 
 
34
#include <kapplication.h>
 
35
#include <kactioncategory.h>
 
36
#include <kactioncollection.h>
 
37
#include <kaction.h>
 
38
#include <kdebug.h>
 
39
#include <kxmlguiclient.h>
 
40
#include <kxmlguifactory.h>
 
41
 
 
42
// Local includes
 
43
 
 
44
#include "kipiinterface.h"
 
45
#include "kipitestmainwindow.h"
 
46
 
 
47
namespace KXMLKipiCmd
 
48
{
 
49
 
 
50
class KipiTestPluginLoader::KipiTestPluginLoaderPriv
 
51
{
 
52
 
 
53
public:
 
54
 
 
55
    KipiTestPluginLoaderPriv()
 
56
    {
 
57
        app                         = 0;
 
58
        kipipluginsActionCollection = 0;
 
59
        kipiPluginLoader            = 0;
 
60
        kipiInterface               = 0;
 
61
    }
 
62
 
 
63
    PluginLoader*               kipiPluginLoader;
 
64
    KipiInterface*              kipiInterface;
 
65
    KXmlGuiWindow*              app;
 
66
 
 
67
    KActionCollection*          kipipluginsActionCollection;
 
68
    QMap<int, KActionCategory*> kipiCategoryMap;
 
69
};
 
70
 
 
71
// -- Static values -------------------------------
 
72
 
 
73
KipiTestPluginLoader* KipiTestPluginLoader::m_instance = 0;
 
74
 
 
75
// -----------------------------------------------
 
76
 
 
77
KipiTestPluginLoader::KipiTestPluginLoader(KXmlGuiWindow* const parent, KipiInterface *const interface)
 
78
    : QObject(parent), d(new KipiTestPluginLoaderPriv)
 
79
{
 
80
    m_instance       = this;
 
81
    d->kipiInterface = interface;
 
82
    d->app           = parent;
 
83
 
 
84
    loadPlugins();
 
85
}
 
86
 
 
87
KipiTestPluginLoader::~KipiTestPluginLoader()
 
88
{
 
89
    delete d;
 
90
    m_instance = 0;
 
91
}
 
92
 
 
93
KipiTestPluginLoader* KipiTestPluginLoader::instance()
 
94
{
 
95
    return m_instance;
 
96
}
 
97
 
 
98
KActionCollection* KipiTestPluginLoader::pluginsActionCollection() const
 
99
{
 
100
    return d->kipipluginsActionCollection;
 
101
}
 
102
 
 
103
QList<PluginLoader::Info*> KipiTestPluginLoader::pluginList()
 
104
{
 
105
    return d->kipiPluginLoader->pluginList();
 
106
}
 
107
 
 
108
QList<QAction*> KipiTestPluginLoader::kipiActionsByCategory(Category cat) const
 
109
{
 
110
    KActionCategory* category = d->kipiCategoryMap[cat];
 
111
 
 
112
    if (category)
 
113
    {
 
114
        return category->actions();
 
115
    }
 
116
 
 
117
    return QList<QAction*>();
 
118
}
 
119
 
 
120
void KipiTestPluginLoader::loadPlugins()
 
121
{
 
122
    d->kipipluginsActionCollection = new KActionCollection(d->app, KGlobal::mainComponent());
 
123
 
 
124
    QStringList ignores;
 
125
 
 
126
    // List of obsoletes plugins to not load
 
127
 
 
128
    // Comment the following two lines if you want to load the HelloWorld and
 
129
    // the KXMLHelloWorld plugins for testing purposes
 
130
    //ignores.append("HelloWorld");
 
131
    //ignores.append("KXMLHelloWorld");
 
132
 
 
133
    ignores.append("KameraKlient");
 
134
 
 
135
    // These plugins have been renamed with 0.2.0-rc1
 
136
    ignores.append("Facebook Exporter");
 
137
    ignores.append("SmugMug Exporter");
 
138
    ignores.append("SlideShow");
 
139
    ignores.append("PrintWizard");
 
140
    ignores.append("SimpleViewer");
 
141
    ignores.append("KioExport");
 
142
 
 
143
    d->kipiPluginLoader = new PluginLoader(d->app);
 
144
    d->kipiPluginLoader->setInterface(d->kipiInterface);
 
145
    d->kipiPluginLoader->setIgnoredPluginsList(ignores);
 
146
    d->kipiPluginLoader->init();
 
147
 
 
148
    connect(d->kipiPluginLoader, SIGNAL(replug()),
 
149
            this, SLOT(slotKipiPluginsPlug()));
 
150
 
 
151
    d->kipiPluginLoader->loadPlugins();
 
152
}
 
153
 
 
154
void KipiTestPluginLoader::slotKipiPluginsPlug()
 
155
{
 
156
    d->kipiCategoryMap.clear();
 
157
    d->kipipluginsActionCollection->clear();
 
158
 
 
159
    PluginLoader::PluginList list = d->kipiPluginLoader->pluginList();
 
160
    int cpt                       = 0;
 
161
 
 
162
    for (PluginLoader::PluginList::ConstIterator it = list.constBegin() ; it != list.constEnd() ; ++it)
 
163
    {
 
164
        Plugin* plugin = (*it)->plugin();
 
165
 
 
166
        if (!plugin || !(*it)->shouldLoad())
 
167
        {
 
168
            continue;
 
169
        }
 
170
 
 
171
        d->app->guiFactory()->removeClient(plugin);
 
172
    }
 
173
 
 
174
    QStringList disabledActions = d->kipiPluginLoader->disabledPluginActions();
 
175
 
 
176
    for (PluginLoader::PluginList::ConstIterator it = list.constBegin() ; it != list.constEnd() ; ++it)
 
177
    {
 
178
        Plugin* plugin = (*it)->plugin();
 
179
 
 
180
        if (!plugin || !(*it)->shouldLoad())
 
181
        {
 
182
            continue;
 
183
        }
 
184
 
 
185
        ++cpt;
 
186
        plugin->setup(d->app);
 
187
        plugin->rebuild();
 
188
 
 
189
        foreach(KAction* const action, plugin->actions())
 
190
        {
 
191
            QString actionName(action->objectName());
 
192
            Category cat = plugin->category(action);
 
193
 
 
194
            if (cat == InvalidCategory)
 
195
            {
 
196
                kWarning() << "Plugin action '" << actionName << "' has invalid category!";
 
197
                continue;
 
198
            }
 
199
 
 
200
            if (!disabledActions.contains(actionName))
 
201
            {
 
202
                KActionCategory* category = d->kipiCategoryMap[cat];
 
203
 
 
204
                if (!category)
 
205
                {
 
206
                    category = new KActionCategory(categoryName(cat), d->kipipluginsActionCollection);
 
207
                    d->kipiCategoryMap.insert(cat, category);
 
208
                }
 
209
 
 
210
                category->addAction(actionName, qobject_cast<QAction*>(action));
 
211
            }
 
212
            else
 
213
            {
 
214
                kDebug() << "Plugin '" << actionName << "' is disabled.";
 
215
            }
 
216
        }
 
217
    }
 
218
 
 
219
    for (PluginLoader::PluginList::ConstIterator it = list.constBegin() ; it != list.constEnd() ; ++it)
 
220
    {
 
221
        Plugin* plugin = (*it)->plugin();
 
222
 
 
223
        if (!plugin || !(*it)->shouldLoad())
 
224
        {
 
225
            continue;
 
226
        }
 
227
 
 
228
        d->app->guiFactory()->addClient(plugin);
 
229
    }
 
230
 
 
231
    // load KIPI actions settings
 
232
    d->kipipluginsActionCollection->readSettings();
 
233
}
 
234
 
 
235
void KipiTestPluginLoader::checkEmptyCategory(Category cat)
 
236
{
 
237
    KActionCategory* category = d->kipiCategoryMap[cat];
 
238
 
 
239
    if (!category)
 
240
    {
 
241
//        QAction* action = new QAction(i18n("No tool available"), d->app);
 
242
        QString actionName = "emptyCategory" + categoryShortName(cat);
 
243
        KAction* action = d->app->actionCollection()->addAction(actionName);
 
244
        action->setEnabled(false);
 
245
        category        = new KActionCategory(categoryName(cat), d->kipipluginsActionCollection);
 
246
        d->kipiCategoryMap.insert(cat, category);
 
247
    }
 
248
}
 
249
 
 
250
QString KipiTestPluginLoader::categoryName(Category cat) const
 
251
{
 
252
    QString res;
 
253
 
 
254
    switch (cat)
 
255
    {
 
256
        case ExportPlugin:
 
257
            res = i18n("Export Tools");
 
258
            break;
 
259
 
 
260
        case ImportPlugin:
 
261
            res = i18n("Import Tools");
 
262
            break;
 
263
 
 
264
        case ImagesPlugin:
 
265
            res = i18n("Images Tools");
 
266
            break;
 
267
 
 
268
        case ToolsPlugin:
 
269
            res = i18n("Miscellaneous Tools");
 
270
            break;
 
271
 
 
272
        case BatchPlugin:
 
273
            res = i18n("Batch Tools");
 
274
            break;
 
275
 
 
276
        case CollectionsPlugin:
 
277
            res = i18n("Albums Tools");
 
278
            break;
 
279
 
 
280
        default:
 
281
            res = i18n("Unknown Tools");
 
282
            break;
 
283
    }
 
284
 
 
285
    return res;
 
286
}
 
287
 
 
288
QString KipiTestPluginLoader::categoryShortName(Category cat) const
 
289
{
 
290
    QString res;
 
291
 
 
292
    switch (cat)
 
293
    {
 
294
    case ExportPlugin:
 
295
        res = i18n("Export");
 
296
        break;
 
297
 
 
298
    case ImportPlugin:
 
299
        res = i18n("Import");
 
300
        break;
 
301
 
 
302
    case ToolsPlugin:
 
303
        res = i18n("Tools");
 
304
        break;
 
305
 
 
306
    case BatchPlugin:
 
307
        res = i18n("Batch");
 
308
        break;
 
309
 
 
310
    case CollectionsPlugin:
 
311
        res = i18n("Collenctions");
 
312
        break;
 
313
 
 
314
    default:
 
315
        res = i18n("Unknown");
 
316
        break;
 
317
    }
 
318
 
 
319
    return res;
 
320
}
 
321
 
 
322
} // namespace KXMLKipiCmd