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

libtaskmanager

manualsortingstrategy.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 #include "manualsortingstrategy.h"
00025 
00026 #include "taskitem.h"
00027 #include "taskgroup.h"
00028 #include "taskmanager.h"
00029 
00030 #include <QMap>
00031 #include <QtAlgorithms>
00032 
00033 #include <KDebug>
00034 
00035 
00036 namespace TaskManager
00037 {
00038 
00039 class ManualSortingStrategy::Private
00040 {
00041 public:
00042     Private()
00043     {
00044     }
00045     GroupManager *groupingStrategy;
00046 
00047     itemHashTable *managedItems;
00048     desktopHashTable *desktops;
00049     int oldDesktop;
00050 };
00051 
00052 
00053 ManualSortingStrategy::ManualSortingStrategy(GroupManager *parent)
00054     :AbstractSortingStrategy(parent),
00055     d(new Private)
00056 {
00057     d->groupingStrategy = parent;
00058     setType(GroupManager::ManualSorting);
00059 
00060     d->desktops = new desktopHashTable();
00061     //TODO add a screenHashTable
00062     d->oldDesktop = TaskManager::TaskManager::self()->currentDesktop();
00063 
00064     if (d->groupingStrategy->showOnlyCurrentDesktop()) {
00065         d->desktops->insert(TaskManager::TaskManager::self()->currentDesktop(), new itemHashTable());
00066         d->managedItems = d->desktops->value(TaskManager::TaskManager::self()->currentDesktop());
00067     } else {
00068         d->desktops->insert(0,new itemHashTable());
00069         d->managedItems = d->desktops->value(0);
00070     }
00071 }
00072 
00073 ManualSortingStrategy::~ManualSortingStrategy()
00074 {
00075     if (d->desktops) {
00076         foreach(itemHashTable *table, *d->desktops) {
00077             if (table) {
00078                 delete table;
00079             }
00080         }
00081         delete d->desktops;
00082     }
00083     delete d;
00084 }
00085 
00086 void ManualSortingStrategy::storePositions(TaskGroup *group)
00087 {
00088     Q_ASSERT(group);
00089     for(int i = 0; i < group->members().size(); i++) {
00090         AbstractGroupableItem *item = group->members().at(i);
00091         Q_ASSERT(item);
00092         if (item->isGroupItem()) {
00093             d->managedItems->insert(item, i);
00094             storePositions(dynamic_cast<TaskGroup*>(item));
00095         } else {
00096             d->managedItems->insert(item, i);
00097         }
00098         kDebug() << item << i;
00099     }
00100 }
00101 
00102 //Here we should store all infos about the sorting
00103 void ManualSortingStrategy::desktopChanged(int newDesktop)
00104 {
00105     kDebug() << "Desktop changed" << d->oldDesktop << newDesktop;
00106     //store positions of old desktop
00107     d->managedItems->clear();
00108     storePositions(d->groupingStrategy->rootGroup());
00109     d->desktops->insert(d->oldDesktop, d->managedItems);
00110 
00111     //load positions of new desktop
00112     if (d->desktops->contains(newDesktop)) {
00113         d->managedItems = d->desktops->value(newDesktop);
00114     } else {
00115         d->managedItems = new itemHashTable();
00116     }
00117 
00118     d->oldDesktop = newDesktop;
00119 }
00120 
00121 void ManualSortingStrategy::sortItems(ItemList &items)
00122 {
00123     kDebug();
00124 
00125     QMap<int, AbstractGroupableItem*> map;
00126     int i = 1000;
00127     foreach (AbstractGroupableItem *item, items) {
00128         if (d->managedItems->contains(item)) {
00129             map.insertMulti(d->managedItems->value(item), item);
00130         } else {//make sure unkwown items are appended
00131             kDebug() << "item not found in managedItems";
00132             map.insertMulti(i, item);
00133             i++;
00134         }
00135     }
00136     items.clear();
00137     items = map.values();
00138 }
00139 
00140 //since we have no way of knowing about a desktop change before it happens we have to track every single change....
00141 void ManualSortingStrategy::handleItem(AbstractItemPtr item)
00142 {
00143     if (d->managedItems->contains(item)) {
00144         if (item->isGroupItem()) {
00145             handleGroup(qobject_cast<TaskGroup*>(item));
00146         }
00147         check(item);
00148     } else {
00149         Q_ASSERT(item->parentGroup());
00150         d->managedItems->insert(item, item->parentGroup()->members().indexOf(item));
00151     }
00152 }
00153 
00154 } //namespace
00155 
00156 #include "manualsortingstrategy.moc"
00157 

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