1/*
2 * Copyright 2008 by Marco Martin <notmart@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#include "abstracttoolbox.h"
21
22#include "containment.h"
23
24#include <kservicetypetrader.h>
25
26namespace Plasma
27{
28
29class AbstractToolBoxPrivate
30{
31public:
32 AbstractToolBoxPrivate(Containment *c)
33 : containment(c)
34 {}
35
36 Containment *containment;
37};
38
39AbstractToolBox::AbstractToolBox(Containment *parent)
40 : QGraphicsWidget(parent),
41 d(new AbstractToolBoxPrivate(parent))
42{
43}
44
45AbstractToolBox::AbstractToolBox(QObject *parent, const QVariantList & /*args*/)
46 : QGraphicsWidget(dynamic_cast<QGraphicsItem *>(parent)),
47 d(new AbstractToolBoxPrivate(qobject_cast<Containment *>(parent)))
48{
49 if (!parentItem()) {
50 setParent(parent);
51 }
52}
53
54AbstractToolBox::~AbstractToolBox()
55{
56 delete d;
57}
58
59AbstractToolBox *AbstractToolBox::load(const QString &name, const QVariantList &args, Plasma::Containment *containment)
60{
61 const QString constraint = name.isEmpty() ? QString() : QString("[X-KDE-PluginInfo-Name] == '%1'").arg(name);
62 KService::List offers = KServiceTypeTrader::self()->query("Plasma/ToolBox", constraint);
63
64 if (!offers.isEmpty()) {
65 KService::Ptr offer = offers.first();
66
67 KPluginLoader plugin(*offer);
68 if (Plasma::isPluginVersionCompatible(plugin.pluginVersion())) {
69 return offer->createInstance<AbstractToolBox>(containment, args);
70 }
71 }
72
73 return 0;
74}
75
76KPluginInfo::List AbstractToolBox::listToolBoxInfo(const QString
77 &parentApp)
78{
79 KPluginInfo::List list;
80
81 if (parentApp.isEmpty() || parentApp == KGlobal::mainComponent().componentName()) {
82 list = KPluginInfo::List();
83 }
84
85 QString constraint;
86 if (parentApp.isEmpty()) {
87 constraint.append("not exist [X-KDE-ParentApp]");
88 } else {
89 constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
90 }
91
92 KService::List offers = KServiceTypeTrader::self()->query("Plasma/ToolBox", constraint);
93 return list + KPluginInfo::fromServices(offers);
94}
95
96Containment *AbstractToolBox::containment() const
97{
98 return d->containment;
99}
100
101void AbstractToolBox::restore(const KConfigGroup &group)
102{
103 Q_UNUSED(group)
104}
105
106void AbstractToolBox::save(const KConfigGroup &group)
107{
108 Q_UNUSED(group)
109}
110
111void AbstractToolBox::reposition()
112{}
113
114} // plasma namespace
115
116#include "abstracttoolbox.moc"
117
118