not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / applets / systemtray / protocols / plasmoid / plasmoidtask.cpp
blob43151ebe0c5176c4adb65b42ebaaf5b01c94055e
1 /***************************************************************************
2 * plasmoidtask.cpp *
3 * *
4 * Copyright (C) 2008 Jason Stubbs <jasonbstubbs@gmail.com> *
5 * Copyright (C) 2008 Sebastian Kügler <sebas@kde.org> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
21 ***************************************************************************/
23 #include "plasmoidtask.h"
24 #include <fixx11h.h>
26 #include <plasma/applet.h>
29 namespace SystemTray
32 class PlasmoidTask::Private
34 public:
35 Private(QString name, PlasmoidTask *q)
36 : q(q),
37 name(name),
38 typeId(name),
39 applet(0)
41 if (!name.isEmpty()) {
42 setupApplet();
46 void setupApplet();
48 PlasmoidTask *q;
49 QString name;
50 QString typeId;
51 QIcon icon;
52 Plasma::Applet *applet;
56 PlasmoidTask::PlasmoidTask(QString appletname)
57 : d(new Private(appletname, this))
62 PlasmoidTask::~PlasmoidTask()
64 emit taskDeleted(d->typeId);
65 delete d;
69 bool PlasmoidTask::isEmbeddable() const
71 return d->applet != 0;
74 bool PlasmoidTask::isValid() const
76 return !d->name.isEmpty();
79 QString PlasmoidTask::name() const
81 return d->name;
85 QString PlasmoidTask::typeId() const
87 return d->typeId;
91 QIcon PlasmoidTask::icon() const
93 return d->icon;
97 QGraphicsWidget* PlasmoidTask::createWidget(Plasma::Applet *host)
99 Q_UNUSED(host)
100 return static_cast<QGraphicsWidget*>(d->applet);
104 void PlasmoidTask::Private::setupApplet()
106 applet = Plasma::Applet::load(name);
108 if (!applet) {
109 kDebug() << "Could not load applet" << name;
110 name = QString();
111 return;
114 applet->setParent(q);
115 applet->setFlag(QGraphicsItem::ItemIsMovable, false);
117 //connect(applet, SIGNAL(destroyed(QObject*)), this, SLOT(appletDestroyed(QObject*)));
118 applet->init();
119 applet->setBackgroundHints(Plasma::Applet::NoBackground);
121 // TODO: We'll need the preferred item size here
122 // The applet does need a size, otherwise it won't show up correctly.
123 applet->setMinimumSize(22, 22);
124 kDebug() << applet->name() << " Applet loaded";
129 #include "plasmoidtask.moc"