not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / libs / taskmanager / taskitem.cpp
blob6941a2c6c0ef53aca9deae9b5f8ad5271094066c
1 /*****************************************************************
3 Copyright 2008 Christian Mollekopf <chrigi_1@hotmail.com>
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 ******************************************************************/
24 // Own
25 #include "taskitem.h"
26 #include <KDebug>
29 namespace TaskManager
33 class TaskItem::Private
35 public:
36 Private()
37 :task(0),
38 startupTask(0)
42 TaskPtr task;
43 StartupPtr startupTask;
47 TaskItem::TaskItem(QObject *parent,TaskPtr task)
48 : AbstractGroupableItem(parent),
49 d(new Private)
51 d->task = task;
52 connect(task.data(), SIGNAL(changed(::TaskManager::TaskChanges)),
53 this, SIGNAL(changed(::TaskManager::TaskChanges)));
54 connect(task.data(), SIGNAL(destroyed()), this, SLOT(deleteLater())); //this item isn't useful anymore if the Task was closed
58 TaskItem::TaskItem(QObject *parent, StartupPtr task)
59 : AbstractGroupableItem(parent),
60 d(new Private)
62 d->startupTask = task;
63 connect(task.data(), SIGNAL(changed(::TaskManager::TaskChanges)), this, SIGNAL(changed(::TaskManager::TaskChanges)));
64 connect(task.data(), SIGNAL(destroyed()), this, SLOT(deleteLater())); //this item isn't useful anymore if the Task was closed
67 TaskItem::~TaskItem()
69 //kDebug();
70 /* if (parentGroup()){
71 parentGroup()->remove(this);
72 }*/
73 delete d;
76 void TaskItem::setTaskPointer(TaskPtr task)
78 if (d->startupTask) {
79 disconnect(d->startupTask.data(), 0, 0, 0);
80 d->startupTask = 0;
82 d->task = task;
83 connect(task.data(), SIGNAL(changed(::TaskManager::TaskChanges)),
84 this, SIGNAL(changed(::TaskManager::TaskChanges)));
85 connect(task.data(), SIGNAL(destroyed()), this, SLOT(deleteLater()));
86 emit gotTaskPointer();
89 TaskPtr TaskItem::task() const
92 if (d->task.isNull()) {
93 kDebug() << "pointer is Null";
96 return d->task;
99 StartupPtr TaskItem::startup() const
102 if (d->startupTask.isNull()) {
103 kDebug() << "pointer is Null";
106 return d->startupTask;
109 QIcon TaskItem::icon() const
111 if (!d->task) {
112 return QIcon();
114 return d->task->icon();
117 QString TaskItem::name() const
119 if (!d->task) {
120 return QString();
122 return d->task->visibleName();
125 void TaskItem::setShaded(bool state)
127 if (!d->task) {
128 return;
130 d->task->setShaded(state);
133 void TaskItem::toggleShaded()
135 if (!d->task) {
136 return;
138 d->task->toggleShaded();
141 bool TaskItem::isShaded() const
143 if (!d->task) {
144 return false;
146 return d->task->isShaded();
149 void TaskItem::toDesktop(int desk)
151 if (!d->task) {
152 return;
154 d->task->toDesktop(desk);
157 bool TaskItem::isOnCurrentDesktop() const
159 return d->task && d->task->isOnCurrentDesktop();
162 bool TaskItem::isOnAllDesktops() const
164 return d->task && d->task->isOnAllDesktops();
167 int TaskItem::desktop() const
169 if (!d->task) {
170 return 0;
172 return d->task->desktop();
175 void TaskItem::setMaximized(bool state)
177 if (!d->task) {
178 return;
180 d->task->setMaximized(state);
183 void TaskItem::toggleMaximized()
185 if (!d->task) {
186 return;
188 d->task->toggleMaximized();
191 bool TaskItem::isMaximized() const
193 return d->task && d->task->isMaximized();
196 void TaskItem::setMinimized(bool state)
198 if (!d->task) {
199 return;
201 d->task->setIconified(state);
204 void TaskItem::toggleMinimized()
206 if (!d->task) {
207 return;
209 d->task->toggleIconified();
212 bool TaskItem::isMinimized() const
214 if (!d->task) {
215 return false;
217 return d->task->isMinimized();
220 void TaskItem::setFullScreen(bool state)
222 if (!d->task) {
223 return;
225 d->task->setFullScreen(state);
228 void TaskItem::toggleFullScreen()
230 if (!d->task) {
231 return;
233 d->task->toggleFullScreen();
236 bool TaskItem::isFullScreen() const
238 if (!d->task) {
239 return false;
241 return d->task->isFullScreen();
244 void TaskItem::setKeptBelowOthers(bool state)
246 if (!d->task) {
247 return;
249 d->task->setKeptBelowOthers(state);
252 void TaskItem::toggleKeptBelowOthers()
254 if (!d->task) {
255 return;
257 d->task->toggleKeptBelowOthers();
260 bool TaskItem::isKeptBelowOthers() const
262 if (!d->task) {
263 return false;
265 return d->task->isKeptBelowOthers();
268 void TaskItem::setAlwaysOnTop(bool state)
270 if (!d->task) {
271 return;
273 d->task->setAlwaysOnTop(state);
276 void TaskItem::toggleAlwaysOnTop()
278 if (!d->task) {
279 return;
281 d->task->toggleAlwaysOnTop();
284 bool TaskItem::isAlwaysOnTop() const
286 if (!d->task) {
287 return false;
289 return d->task->isAlwaysOnTop();
292 bool TaskItem::isActionSupported(NET::Action action) const
294 return d->task && d->task->info().actionSupported(action);
297 void TaskItem::addMimeData(QMimeData *mimeData) const
299 if (!d->task) {
300 return;
303 d->task->addMimeData(mimeData);
306 void TaskItem::close()
308 if (!d->task) {
309 return;
311 d->task->close();
314 bool TaskItem::isActive() const
316 if (!d->task) {
317 return false;
319 return d->task->isActive();
322 bool TaskItem::demandsAttention() const
324 if (!d->task) {
325 return false;
327 return d->task->demandsAttention();
330 } // TaskManager namespace
332 #include "taskitem.moc"