• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libtaskmanager

taskgroup.cpp

Go to the documentation of this file.
00001 /*****************************************************************
00002 
00003 Copyright 2008 Christian Mollekopf <chrigi_1@hotmail.com>
00004 
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011 
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00018 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00019 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00020 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00021 
00022 ******************************************************************/
00023 
00024 // Own
00025 #include "taskgroup.h"
00026 #include "taskmanager.h"
00027 #include "taskitem.h"
00028 #include "groupmanager.h"
00029 
00030 // Qt
00031 #include <QColor>
00032 #include <QMimeData>
00033 
00034 // KDE
00035 #include <KDebug>
00036 #include <KIcon>
00037 #include <ksharedptr.h>
00038 
00039 
00040 
00041 namespace TaskManager
00042 {
00043 
00044 
00045 class TaskGroup::Private
00046 {
00047 public:
00048     Private()
00049     {
00050     }
00051 
00052     QList<WId> winIds() const;
00053 
00054     ItemList members;
00055     QString groupName;
00056     QColor groupColor;
00057     QIcon groupIcon;
00058     bool aboutToDie;
00059     GroupManager *groupingStrategy;
00060 };
00061 
00062 TaskGroup::TaskGroup(GroupManager *parent,const QString &name, const QColor &color)
00063 :   AbstractGroupableItem(parent),
00064     d(new Private)
00065 {
00066     d->groupingStrategy = parent;
00067     d->groupName = name;
00068     d->groupColor = color;
00069     d->groupIcon = KIcon("xorg");
00070     connect(this, SLOT(editRequest()), this, SIGNAL(groupEditRequest()));
00071     //kDebug() << "Group Created: Name: " << d->groupName << "Color: " << d->groupColor;
00072 }
00073 
00074 TaskGroup::TaskGroup(GroupManager *parent)
00075 :   AbstractGroupableItem(parent),
00076     d(new Private)
00077 {
00078     d->groupingStrategy = parent;
00079 //    d->groupName = "default";
00080     d->groupColor = Qt::red;
00081     d->groupIcon = KIcon("xorg");
00082     connect(this, SLOT(editRequest()), this, SIGNAL(groupEditRequest()));
00083     //kDebug() << "Group Created: Name: " << d->groupName << "Color: " << d->groupColor;
00084 }
00085 
00086 
00087 TaskGroup::~TaskGroup()
00088 {
00089     //kDebug() << name();
00090     delete d;
00091 }
00092 
00093 
00094 void TaskGroup::add(AbstractItemPtr item)
00095 {
00096 /*    if (!item->isGroupItem()) {
00097         if ((dynamic_cast<TaskItem*>(item))->task()) {
00098             kDebug() << "Add item" << (dynamic_cast<TaskItem*>(item))->task()->visibleName();
00099         }
00100         kDebug() << " to Group " << name();
00101     }
00102 */
00103 
00104     if (d->members.contains(item)) {
00105         //kDebug() << "already in this group";
00106         return;
00107     }
00108 
00109     if (d->groupName.isEmpty()) {
00110         TaskItem *taskItem = qobject_cast<TaskItem*>(item);
00111         if (taskItem) {
00112             d->groupName = taskItem->task()->classClass();
00113         }
00114     }
00115 
00116     if (item->parentGroup()) {
00117         item->parentGroup()->remove(item);
00118     }
00119 
00120     d->members.append(item);
00121     item->setParentGroup(this);
00122 
00123     connect(item, SIGNAL(changed(::TaskManager::TaskChanges)),
00124             this, SIGNAL(changed(::TaskManager::TaskChanges)));
00125     //For debug
00126    /* foreach (AbstractGroupableItem *item, d->members) {
00127         if (item->isGroupItem()) {
00128             kDebug() << (dynamic_cast<TaskGroup*>(item))->name();
00129         } else {
00130             kDebug() << (dynamic_cast<TaskItem*>(item))->task()->visibleName();
00131         }
00132     }*/
00133     emit itemAdded(item);
00134 }
00135 
00136 void TaskGroup::remove(AbstractItemPtr item)
00137 {
00138     Q_ASSERT(item);
00139 
00140     /*
00141     if (item->isGroupItem()) {
00142         kDebug() << "Remove group" << (dynamic_cast<TaskGroup*>(item))->name();
00143     } else if ((dynamic_cast<TaskItem*>(item))->task()) {
00144         kDebug() << "Remove item" << (dynamic_cast<TaskItem*>(item))->task()->visibleName();
00145     }
00146     kDebug() << "from Group: " << name();
00147     */
00148 
00149    /* kDebug() << "GroupMembers: ";
00150     foreach (AbstractGroupableItem *item, d->members) {
00151         if (item->isGroupItem()) {
00152             kDebug() << (dynamic_cast<TaskGroup*>(item))->name();
00153         } else {
00154             kDebug() << (dynamic_cast<TaskItem*>(item))->task()->visibleName();
00155         }
00156     }*/
00157 
00158     if (!d->members.contains(item)) {
00159         //kDebug() << "couldn't find item";
00160         return;
00161     }
00162 
00163     disconnect(item, 0, this, 0);
00164 
00165     d->members.removeAll(item);
00166     item->setParentGroup(0);
00167     /*if(d->members.isEmpty()){
00168         kDebug() << "empty";
00169         emit empty(this);
00170     }*/
00171     emit itemRemoved(item);
00172 }
00173 
00174 void TaskGroup::clear()
00175 {
00176    // kDebug() << "size " << d->members.size();
00177     foreach(AbstractGroupableItem *item, d->members) {
00178     //    kDebug();
00179         Q_ASSERT(item);
00180         if (item->isGroupItem()) { 
00181             (dynamic_cast<GroupPtr>(item))->clear();
00182         }
00183         remove(item);
00184     }
00185 
00186     if (!d->members.isEmpty()) {
00187         kDebug() << "clear doesn't work";
00188     }
00189 }
00190 
00191 ItemList TaskGroup::members() const
00192 {
00193     return d->members;
00194 }
00195 
00196 void TaskGroup::setColor(const QColor &color)
00197 {
00198     d->groupColor = color;
00199     emit changed(ColorChanged);
00200 }
00201 
00202 QColor TaskGroup::color() const
00203 {
00204     return d->groupColor;
00205 }
00206 
00207 QString TaskGroup::name() const
00208 {
00209     return d->groupName;
00210 }
00211 
00212 void TaskGroup::setName(const QString &newName)
00213 {
00214     d->groupName = newName;
00215     emit changed(NameChanged);
00216 }
00217 
00218 QIcon TaskGroup::icon() const
00219 {
00220     return d->groupIcon;
00221 }
00222 
00223 void TaskGroup::setIcon(const QIcon &newIcon)
00224 {
00225     d->groupIcon = newIcon;
00226     emit changed(IconChanged);
00227 }
00228 
00229 bool TaskGroup::isRootGroup() const
00230 {
00231     return !parentGroup();
00232 }
00233 
00235 bool TaskGroup::hasDirectMember(AbstractItemPtr item) const
00236 {
00237     return d->members.contains(item);
00238 }
00239 
00241 bool TaskGroup::hasMember(AbstractItemPtr item) const
00242 {
00243     //kDebug();
00244     TaskGroup *group = item->parentGroup();
00245     while (group) {
00246         if (group == this) {
00247             return true;
00248         }
00249         group = group->parentGroup();
00250     }
00251     return false;
00252 }
00253 
00255 AbstractItemPtr TaskGroup::directMember(AbstractItemPtr item) const
00256 {
00257     AbstractItemPtr tempItem = item;
00258     while (tempItem) {
00259         if (d->members.contains(item)) {
00260             return item;
00261         }
00262         tempItem = tempItem->parentGroup();
00263     }
00264 
00265     kDebug() << "item not found";
00266     return AbstractItemPtr();
00267 }
00268 
00269 void TaskGroup::setShaded(bool state)
00270 {
00271     foreach (AbstractItemPtr item, d->members) {
00272         item->setShaded(state);
00273     }
00274 }
00275 
00276 void TaskGroup::toggleShaded()
00277 {
00278     setShaded(!isShaded());
00279 }
00280 
00281 bool TaskGroup::isShaded() const
00282 {
00283     foreach (AbstractItemPtr item, d->members) {
00284         if (!item->isShaded()) {
00285             return false;
00286         }
00287     }
00288     return true;
00289 }
00290 
00291 void TaskGroup::toDesktop(int desk)
00292 {
00293     foreach (AbstractItemPtr item, d->members) {
00294         item->toDesktop(desk);
00295     }
00296     emit movedToDesktop(desk);
00297 }
00298 
00299 bool TaskGroup::isOnCurrentDesktop() const
00300 {
00301     foreach (AbstractItemPtr item, d->members) {
00302         if (!item->isOnCurrentDesktop()) {
00303             return false;
00304         }
00305     }
00306     return true;
00307 }
00308 
00309 QList<WId> TaskGroup::Private::winIds() const
00310 {
00311     QList<WId> ids;
00312 
00313     foreach (AbstractGroupableItem *groupable, members) {
00314         if (groupable->isGroupItem()) {
00315             TaskGroup *group = dynamic_cast<TaskGroup*>(groupable);
00316             if (group) {
00317                 ids << group->d->winIds();
00318             }
00319         } else {
00320             TaskItem * item = dynamic_cast<TaskItem*>(groupable);
00321             if (item) {
00322                 ids << item->task()->info().win();
00323             }
00324         }
00325     }
00326 
00327     return ids;
00328 }
00329 
00330 void TaskGroup::addMimeData(QMimeData *mimeData) const
00331 {
00332     //kDebug() << d->members.count();
00333     if (d->members.isEmpty()) {
00334         return;
00335     }
00336 
00337     QByteArray data;
00338     QList<WId> ids = d->winIds();
00339     int count = ids.count();
00340     data.resize(sizeof(int) + sizeof(WId) * count);
00341     memcpy(data.data(), &count, sizeof(int));
00342     int i = 0;
00343     foreach (WId id, ids) {
00344         //kDebug() << "adding" << id;
00345         memcpy(data.data() + sizeof(int) + sizeof(WId) * i, &id, sizeof(WId));
00346         ++i;
00347     }
00348 
00349     //kDebug() << "done:" << data.size() << count;
00350     mimeData->setData(Task::groupMimetype(), data);
00351 }
00352 
00353 bool TaskGroup::isOnAllDesktops() const
00354 {
00355     foreach (AbstractItemPtr item, d->members) {
00356         if (!item->isOnAllDesktops()) {
00357             return false;
00358         }
00359     }
00360     return true;
00361 }
00362 
00363 //return 0 if tasks are on different desktops or on all dektops
00364 int TaskGroup::desktop() const
00365 {
00366     if (d->members.isEmpty()) {
00367         return 0;
00368     }
00369 
00370     int desk = d->members.first()->desktop();
00371     foreach (AbstractItemPtr item, d->members) {
00372         if (item->desktop() != desk) {
00373             return 0;
00374         }
00375         desk = item->desktop();
00376     }
00377     return desk;
00378 }
00379 
00380 void TaskGroup::setMaximized(bool state)
00381 {
00382     foreach (AbstractItemPtr item, d->members) {
00383         item->setMaximized(state);
00384     }
00385 }
00386 
00387 void TaskGroup::toggleMaximized()
00388 {
00389     setMaximized(!isMaximized());
00390 }
00391 
00392 bool TaskGroup::isMaximized() const
00393 {
00394     foreach (AbstractItemPtr item, d->members) {
00395         if (!item->isMaximized()) {
00396             return false;
00397         }
00398     }
00399     return true;
00400 }
00401 
00402 void TaskGroup::setMinimized(bool state)
00403 {
00404     foreach (AbstractItemPtr item, d->members) {
00405         item->setMinimized(state);
00406     }
00407 }
00408 
00409 void TaskGroup::toggleMinimized()
00410 {
00411     setMinimized(!isMinimized());
00412 }
00413 
00414 bool TaskGroup::isMinimized() const
00415 {
00416     foreach (AbstractItemPtr item, d->members) {
00417         if (!item->isMinimized()) {
00418             return false;
00419         }
00420     }
00421     return true;
00422 }
00423 
00424 void TaskGroup::setFullScreen(bool state)
00425 {
00426     foreach (AbstractItemPtr item, d->members) {
00427         item->setFullScreen(state);
00428     }
00429 }
00430 
00431 void TaskGroup::toggleFullScreen()
00432 {
00433     setFullScreen(!isFullScreen());
00434 }
00435 
00436 bool TaskGroup::isFullScreen() const
00437 {
00438     foreach (AbstractItemPtr item, d->members) {
00439         if (!item->isFullScreen()) {
00440             return false;
00441         }
00442     }
00443     return true;
00444 }
00445 
00446 void TaskGroup::setKeptBelowOthers(bool state)
00447 {
00448     foreach (AbstractItemPtr item, d->members) {
00449         item->setKeptBelowOthers(state);
00450     }
00451 }
00452 
00453 void TaskGroup::toggleKeptBelowOthers()
00454 {
00455     setKeptBelowOthers(!isKeptBelowOthers());
00456 }
00457 
00458 bool TaskGroup::isKeptBelowOthers() const
00459 {
00460     foreach (AbstractItemPtr item, d->members) {
00461         if (!item->isKeptBelowOthers()) {
00462             return false;
00463         }
00464     }
00465     return true;
00466 }
00467 
00468 void TaskGroup::setAlwaysOnTop(bool state)
00469 {
00470     foreach (AbstractItemPtr item, d->members) {
00471         item->setAlwaysOnTop(state);
00472     }
00473 }
00474 
00475 void TaskGroup::toggleAlwaysOnTop()
00476 {
00477     setAlwaysOnTop(!isAlwaysOnTop());
00478 }
00479 
00480 bool TaskGroup::isAlwaysOnTop() const
00481 {
00482     foreach (AbstractItemPtr item, d->members) {
00483         if (!item->isAlwaysOnTop()) {
00484             return false;
00485         }
00486     }
00487     return true;
00488 }
00489 
00490 bool TaskGroup::isActionSupported(NET::Action action) const
00491 {
00492     if (KWindowSystem::allowedActionsSupported()) {
00493         foreach (AbstractItemPtr item, d->members) {
00494             if (!item->isActionSupported(action)) {
00495                 return false;
00496             }
00497         }
00498         return true;
00499     }
00500     return false;
00501 }
00502 
00503 void TaskGroup::close()
00504 {
00505     foreach (AbstractItemPtr item, d->members) {
00506         item->close();
00507     }
00508 }
00509 
00510 bool TaskGroup::isActive() const
00511 {
00512     foreach (AbstractItemPtr item, d->members) {
00513         if (item->isActive()) {
00514             return true;
00515         }
00516     }
00517 
00518     return false;
00519 }
00520 
00521 bool TaskGroup::demandsAttention() const
00522 {
00523     foreach (AbstractItemPtr item, d->members) {
00524         if (item->demandsAttention()) {
00525             return true;
00526         }
00527     }
00528 
00529     return false;
00530 }
00531 
00532 bool TaskGroup::moveItem(int oldIndex, int newIndex)
00533 {
00534     //kDebug() << oldIndex << newIndex;
00535     if ((d->members.count() <= newIndex) || (newIndex < 0) ||
00536         (d->members.count() <= oldIndex || oldIndex < 0)) {
00537         kDebug() << "index out of bounds";
00538         return false;
00539     }
00540 
00541     AbstractItemPtr item = d->members.at(oldIndex);
00542     d->members.move(oldIndex, newIndex);
00543     //kDebug() << "new index " << d->members.indexOf(item);
00544     emit itemPositionChanged(item);
00545     return true;
00546 }
00547 
00548 } // TaskManager namespace
00549 
00550 #include "taskgroup.moc"

libtaskmanager

Skip menu "libtaskmanager"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal