not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / applets / systemtray / core / manager.cpp
blob81118554ea429237f1fdd946a410aed3d52172c9
1 /***************************************************************************
2 * manager.cpp *
3 * *
4 * Copyright (C) 2008 Jason Stubbs <jasonbstubbs@gmail.com> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
20 ***************************************************************************/
22 #include "manager.h"
24 #include <KGlobal>
26 #include <plasma/applet.h>
28 #include "notification.h"
29 #include "protocol.h"
30 #include "task.h"
31 #include "job.h"
33 #include "../protocols/notifications/dbusnotificationprotocol.h"
34 #include "../protocols/fdo/fdoprotocol.h"
35 #include "../protocols/plasmoid/plasmoidtaskprotocol.h"
36 #include "../protocols/jobs/dbusjobprotocol.h"
38 namespace SystemTray
42 class Manager::Private
44 public:
45 Private(Manager *manager)
46 : q(manager),
47 jobProtocol(0),
48 notificationProtocol(0)
50 setupProtocol(new PlasmoidProtocol(q));
51 setupProtocol(new SystemTray::FdoProtocol(q));
54 void setupProtocol(Protocol *protocol);
56 Manager *q;
57 QList<Task*> tasks;
58 QList<Notification*> notifications;
59 QList<Job*> jobs;
60 Protocol *jobProtocol;
61 Protocol *notificationProtocol;
65 Manager::Manager()
66 : d(new Private(this))
70 Manager::~Manager()
72 delete d;
76 QList<Task*> Manager::tasks() const
78 return d->tasks;
81 void Manager::addTask(Task *task)
83 connect(task, SIGNAL(destroyed(SystemTray::Task*)),
84 this, SLOT(removeTask(SystemTray::Task*)));
85 connect(task, SIGNAL(changed(SystemTray::Task*)),
86 this, SIGNAL(taskChanged(SystemTray::Task*)));
88 kDebug() << task->name() << "(" << task->typeId() << ")";
90 d->tasks.append(task);
91 emit taskAdded(task);
95 void Manager::removeTask(Task *task)
97 d->tasks.removeAll(task);
98 emit taskRemoved(task);
101 void Manager::registerNotificationProtocol()
103 if (!d->notificationProtocol) {
104 d->notificationProtocol = new DBusNotificationProtocol(this);
105 d->setupProtocol(d->notificationProtocol);
109 void Manager::unregisterNotificationProtocol()
111 if (d->notificationProtocol) {
112 delete d->notificationProtocol;
113 d->notificationProtocol = 0;
117 void Manager::addNotification(Notification* notification)
119 connect(notification, SIGNAL(destroyed(SystemTray::Notification*)),
120 this, SLOT(removeNotification(SystemTray::Notification*)));
121 connect(notification, SIGNAL(changed(SystemTray::Notification*)),
122 this, SIGNAL(notificationChanged(SystemTray::Notification*)));
124 d->notifications.append(notification);
125 emit notificationAdded(notification);
128 void Manager::removeNotification(Notification *notification)
130 d->notifications.removeAll(notification);
131 emit notificationRemoved(notification);
134 QList<Notification*> Manager::notifications() const
136 return d->notifications;
139 void Manager::registerJobProtocol()
141 if (!d->jobProtocol) {
142 d->jobProtocol = new DBusJobProtocol(this);
143 d->setupProtocol(d->jobProtocol);
147 void Manager::unregisterJobProtocol()
149 if (d->jobProtocol) {
150 delete d->jobProtocol;
151 d->jobProtocol = 0;
155 void Manager::Private::setupProtocol(Protocol *protocol)
157 connect(protocol, SIGNAL(jobCreated(SystemTray::Job*)), q, SLOT(addJob(SystemTray::Job*)));
158 connect(protocol, SIGNAL(taskCreated(SystemTray::Task*)), q, SLOT(addTask(SystemTray::Task*)));
159 connect(protocol, SIGNAL(notificationCreated(SystemTray::Notification*)),
160 q, SLOT(addNotification(SystemTray::Notification*)));
161 protocol->init();
164 void Manager::addJob(Job *job)
166 connect(job, SIGNAL(destroyed(SystemTray::Job*)), this, SLOT(removeJob(SystemTray::Job*)));
167 connect(job, SIGNAL(changed(SystemTray::Job*)), this, SIGNAL(jobChanged(SystemTray::Job*)));
169 d->jobs.append(job);
170 emit jobAdded(job);
173 void Manager::removeJob(Job *job)
175 d->jobs.removeAll(job);
176 emit jobRemoved(job);
179 QList<Job*> Manager::jobs() const
181 return d->jobs;
187 #include "manager.moc"