delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / workspace / plasma / dataengines / tasks / tasksengine.cpp
blobef710f2dc796d3a46fa5c657be45fb5c7bab8bf2
1 /*
2 * Copyright 2007 Robert Knight <robertknight@gmail.com>
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 version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "tasksengine.h"
21 // own
22 #include "tasksource.h"
24 TasksEngine::TasksEngine(QObject *parent, const QVariantList &args) :
25 Plasma::DataEngine(parent, args)
27 Q_UNUSED(args);
30 TasksEngine::~TasksEngine()
34 Plasma::Service *TasksEngine::serviceForSource(const QString &name)
36 TaskSource *source = dynamic_cast<TaskSource*>(containerForSource(name));
37 // if source does not exist, return null service
38 if (!source) {
39 return Plasma::DataEngine::serviceForSource(name);
41 // if source represents a startup task, return null service
42 if (!source->isTask()) {
43 return Plasma::DataEngine::serviceForSource(name);
45 // if source represent a proper task, return task service
46 Plasma::Service *service = source->createService();
47 service->setParent(this);
48 return service;
51 const QString TasksEngine::getStartupName(StartupPtr startup)
53 return startup->id().id();
56 const QString TasksEngine::getTaskName(TaskPtr task)
58 return QString::number(task->window());
61 void TasksEngine::init()
63 foreach (const TaskPtr &task, TaskManager::TaskManager::self()->tasks()) {
64 Q_ASSERT(task);
65 addTask(task);
67 connect(TaskManager::TaskManager::self(), SIGNAL(startupAdded(StartupPtr)), this, SLOT(startupAdded(StartupPtr)));
68 connect(TaskManager::TaskManager::self(), SIGNAL(startupRemoved(StartupPtr)), this, SLOT(startupRemoved(StartupPtr)));
69 connect(TaskManager::TaskManager::self(), SIGNAL(taskAdded(TaskPtr)), this, SLOT(taskAdded(TaskPtr)));
70 connect(TaskManager::TaskManager::self(), SIGNAL(taskRemoved(TaskPtr)), this, SLOT(taskRemoved(TaskPtr)));
73 void TasksEngine::startupAdded(StartupPtr startup)
75 Q_ASSERT(startup);
76 addStartup(startup);
79 void TasksEngine::startupRemoved(StartupPtr startup)
81 Q_ASSERT(startup);
82 removeSource(getStartupName(startup));
85 void TasksEngine::taskAdded(TaskPtr task)
87 Q_ASSERT(task);
88 addTask(task);
91 void TasksEngine::taskRemoved(TaskPtr task)
93 Q_ASSERT(task);
94 removeSource(getTaskName(task));
97 void TasksEngine::addStartup(StartupPtr startup)
99 TaskSource *taskSource = new TaskSource(startup, this);
100 connect(startup.constData(), SIGNAL(changed(::TaskManager::TaskChanges)), taskSource, SLOT(updateStartup(::TaskManager::TaskChanges)));
101 addSource(taskSource);
104 void TasksEngine::addTask(TaskPtr task)
106 TaskSource *taskSource = new TaskSource(task, this);
107 connect(task.constData(), SIGNAL(changed(::TaskManager::TaskChanges)), taskSource, SLOT(updateTask(::TaskManager::TaskChanges)));
108 connect(TaskManager::TaskManager::self(), SIGNAL(desktopChanged(int)), taskSource, SLOT(updateDesktop(int)));
109 addSource(taskSource);
112 K_EXPORT_PLASMA_DATAENGINE(tasks, TasksEngine)
114 #include "tasksengine.moc"