Applets
manager.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "manager.h"
00023
00024 #include <KGlobal>
00025
00026 #include <plasma/applet.h>
00027
00028 #include "notification.h"
00029 #include "protocol.h"
00030 #include "task.h"
00031 #include "job.h"
00032
00033 #include "../protocols/notifications/dbusnotificationprotocol.h"
00034 #include "../protocols/fdo/fdoprotocol.h"
00035 #include "../protocols/plasmoid/plasmoidtaskprotocol.h"
00036 #include "../protocols/jobs/dbusjobprotocol.h"
00037
00038 namespace SystemTray
00039 {
00040
00041
00042 class Manager::Private
00043 {
00044 public:
00045 Private(Manager *manager)
00046 : q(manager),
00047 jobProtocol(0),
00048 notificationProtocol(0)
00049 {
00050 setupProtocol(new PlasmoidProtocol(q));
00051 setupProtocol(new SystemTray::FdoProtocol(q));
00052 }
00053
00054 void setupProtocol(Protocol *protocol);
00055
00056 Manager *q;
00057 QList<Task*> tasks;
00058 QList<Notification*> notifications;
00059 QList<Job*> jobs;
00060 Protocol *jobProtocol;
00061 Protocol *notificationProtocol;
00062 };
00063
00064
00065 Manager::Manager()
00066 : d(new Private(this))
00067 {
00068 }
00069
00070 Manager::~Manager()
00071 {
00072 delete d;
00073 }
00074
00075
00076 QList<Task*> Manager::tasks() const
00077 {
00078 return d->tasks;
00079 }
00080
00081 void Manager::addTask(Task *task)
00082 {
00083 connect(task, SIGNAL(destroyed(SystemTray::Task*)),
00084 this, SLOT(removeTask(SystemTray::Task*)));
00085 connect(task, SIGNAL(changed(SystemTray::Task*)),
00086 this, SIGNAL(taskChanged(SystemTray::Task*)));
00087
00088 kDebug() << task->name() << "(" << task->typeId() << ")";
00089
00090 d->tasks.append(task);
00091 emit taskAdded(task);
00092 }
00093
00094
00095 void Manager::removeTask(Task *task)
00096 {
00097 d->tasks.removeAll(task);
00098 emit taskRemoved(task);
00099 }
00100
00101 void Manager::registerNotificationProtocol()
00102 {
00103 if (!d->notificationProtocol) {
00104 d->notificationProtocol = new DBusNotificationProtocol(this);
00105 d->setupProtocol(d->notificationProtocol);
00106 }
00107 }
00108
00109 void Manager::addNotification(Notification* notification)
00110 {
00111 connect(notification, SIGNAL(destroyed(SystemTray::Notification*)),
00112 this, SLOT(removeNotification(SystemTray::Notification*)));
00113 connect(notification, SIGNAL(changed(SystemTray::Notification*)),
00114 this, SIGNAL(notificationChanged(SystemTray::Notification*)));
00115
00116 d->notifications.append(notification);
00117 emit notificationAdded(notification);
00118 }
00119
00120
00121 void Manager::removeNotification(Notification *notification)
00122 {
00123 d->notifications.removeAll(notification);
00124 emit notificationRemoved(notification);
00125 }
00126
00127 QList<Notification*> Manager::notifications() const
00128 {
00129 return d->notifications;
00130 }
00131
00132 void Manager::registerJobProtocol()
00133 {
00134 if (!d->jobProtocol) {
00135 d->jobProtocol = new DBusJobProtocol(this);
00136 d->setupProtocol(d->jobProtocol);
00137 }
00138 }
00139
00140 void Manager::Private::setupProtocol(Protocol *protocol)
00141 {
00142 connect(protocol, SIGNAL(jobCreated(SystemTray::Job*)), q, SLOT(addJob(SystemTray::Job*)));
00143 connect(protocol, SIGNAL(taskCreated(SystemTray::Task*)), q, SLOT(addTask(SystemTray::Task*)));
00144 connect(protocol, SIGNAL(notificationCreated(SystemTray::Notification*)),
00145 q, SLOT(addNotification(SystemTray::Notification*)));
00146 protocol->init();
00147 }
00148
00149 void Manager::addJob(Job *job)
00150 {
00151 connect(job, SIGNAL(destroyed(SystemTray::Job*)), this, SLOT(removeJob(SystemTray::Job*)));
00152 connect(job, SIGNAL(changed(SystemTray::Job*)), this, SIGNAL(jobChanged(SystemTray::Job*)));
00153
00154 d->jobs.append(job);
00155 emit jobAdded(job);
00156 }
00157
00158 void Manager::removeJob(Job *job)
00159 {
00160 d->jobs.removeAll(job);
00161 emit jobRemoved(job);
00162 }
00163
00164 QList<Job*> Manager::jobs() const
00165 {
00166 return d->jobs;
00167 }
00168
00169 }
00170
00171
00172 #include "manager.moc"