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

libtaskmanager

abstractgroupingstrategy.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 "abstractgroupingstrategy.h"
00025 
00026 #include <KDebug>
00027 #include <KIcon>
00028 
00029 #include "task.h"
00030 
00031 namespace TaskManager
00032 {
00033 
00034 class AbstractGroupingStrategy::Private
00035 {
00036 public:
00037     Private()
00038         : type(GroupManager::NoGrouping)
00039     {
00040     }
00041 
00042     GroupManager *groupManager;
00043     QStringList usedNames;
00044     QList<QColor> usedColors;
00045     QList<TaskGroup*> createdGroups;
00046     GroupManager::TaskGroupingStrategy type;
00047 };
00048 
00049 AbstractGroupingStrategy::AbstractGroupingStrategy(GroupManager *groupManager)
00050     : QObject(groupManager),
00051       d(new Private)
00052 {
00053     d->groupManager = groupManager;
00054 }
00055 
00056 AbstractGroupingStrategy::~AbstractGroupingStrategy()
00057 {
00058     foreach (TaskGroup *group, d->createdGroups) { //cleanup all created groups
00059         disconnect(group, 0, this, 0);
00060 
00061         TaskGroup *parentGroup = group->parentGroup();
00062         if (!parentGroup) {
00063             parentGroup = d->groupManager->rootGroup();
00064         }
00065 
00066         foreach (const AbstractItemPtr& item, group->members()) {
00067             if (!item->isGroupItem()) {
00068                 parentGroup->add(item);
00069             }
00070         }
00071 
00072         parentGroup->remove(group);
00073         emit groupRemoved(group);
00074     }
00075 
00076     qDeleteAll(d->createdGroups);
00077     delete d;
00078 }
00079 
00080 GroupManager::TaskGroupingStrategy AbstractGroupingStrategy::type() const
00081 {
00082     return d->type;
00083 }
00084 
00085 void AbstractGroupingStrategy::setType(GroupManager::TaskGroupingStrategy type)
00086 {
00087     d->type = type;
00088 }
00089 
00090 void AbstractGroupingStrategy::desktopChanged(int newDesktop)
00091 {
00092     Q_UNUSED(newDesktop)
00093 }
00094 
00095 QList<QAction*> AbstractGroupingStrategy::strategyActions(QObject *parent, AbstractGroupableItem *item)
00096 {
00097     Q_UNUSED(parent)
00098     Q_UNUSED(item)
00099     return QList<QAction*>();
00100 }
00101 
00102 TaskGroup* AbstractGroupingStrategy::createGroup(ItemList items)
00103 {
00104     kDebug();
00105     GroupPtr oldGroup;
00106     if (!items.isEmpty() && items.first()->isGrouped()) {
00107         oldGroup = items.first()->parentGroup();
00108     } else {
00109         oldGroup = d->groupManager->rootGroup();
00110     }
00111 
00112     TaskGroup *newGroup = new TaskGroup(d->groupManager);
00113     d->createdGroups.append(newGroup);
00114     connect(newGroup, SIGNAL(itemRemoved(AbstractItemPtr)), this, SLOT(checkGroup()));
00115     foreach (const AbstractItemPtr& item, items) {
00116         newGroup->add(item);
00117     }
00118 
00119     oldGroup->add(newGroup);
00120     return newGroup;
00121 }
00122 
00123 void AbstractGroupingStrategy::closeGroup(TaskGroup *group)
00124 {
00125     Q_ASSERT(group);
00126     disconnect(group, 0, this, 0);
00127     kDebug();
00128     d->createdGroups.removeAll(group);
00129     d->usedNames.removeAll(group->name());
00130     d->usedColors.removeAll(group->color());
00131     //d->usedIcons.removeAll(group->icon());//TODO
00132 
00133     TaskGroup *parentGroup = group->parentGroup();
00134     if (!parentGroup) {
00135         parentGroup = d->groupManager->rootGroup();
00136     }
00137 
00138     foreach (const AbstractItemPtr& item, group->members()) {
00139         parentGroup->add(item);
00140     }
00141 
00142     parentGroup->remove(group);
00143     emit groupRemoved(group);
00144     group->deleteLater();
00145 }
00146 
00147 void AbstractGroupingStrategy::checkGroup()
00148 {
00149     TaskGroup *group = qobject_cast<TaskGroup*>(sender()); 
00150     if (!group) {
00151         return;
00152     }
00153 
00154     if (group->members().size() <= 0) {
00155         closeGroup(group);
00156     }
00157 }
00158 
00159 bool AbstractGroupingStrategy::addItemToGroup(AbstractGroupableItem *item, TaskGroup *group)
00160 {
00161     if (editableGroupProperties() & Members) {
00162         group->add(item);
00163         return true;
00164     }
00165 
00166     return false; 
00167 }
00168 
00169 bool AbstractGroupingStrategy::setName(const QString &name, TaskGroup *group)
00170 {
00171     d->usedNames.removeAll(group->name());
00172     if ((editableGroupProperties() & Name) && (!d->usedNames.contains(name))) {
00173         //TODO editableGroupProperties shouldn't be tested here i think
00174         d->usedNames.append(name);
00175         group->setName(name);
00176         return true;
00177     }
00178     return false; 
00179 }
00180 
00181 //Returns 6 free names
00182 QList<QString> AbstractGroupingStrategy::nameSuggestions(TaskGroup *)
00183 {
00184     QList<QString> nameList;
00185     int i = 1;
00186 
00187     while (nameList.count() < 6) {
00188         if (!d->usedNames.contains("Group"+QString::number(i))) {
00189             nameList.append("Group"+QString::number(i));
00190         }
00191         i++;
00192     }
00193 
00194     if (nameList.isEmpty()) {
00195         nameList.append("default");
00196     }
00197 
00198     return nameList;
00199 }
00200 
00201 bool AbstractGroupingStrategy::setColor(const QColor &color, TaskGroup *group)
00202 {
00203     d->usedColors.removeAll(group->color());
00204 
00205     if (editableGroupProperties() && (!d->usedColors.contains(color))) {
00206         d->usedColors.append(color);
00207         group->setColor(color);
00208         return true;
00209     }
00210 
00211     return false; 
00212 }
00213 
00214 QList<QColor> AbstractGroupingStrategy::colorSuggestions(TaskGroup *)
00215 {
00216     QList<QColor> colorPool;
00217     //colorPool.append(Qt::red);
00218     colorPool.append(Qt::blue);
00219     colorPool.append(Qt::green);
00220     colorPool.append(Qt::yellow);
00221 
00222     QList<QColor> colorList;
00223     foreach (const QColor &color, colorPool) {
00224         if (!d->usedColors.contains(color)) {
00225             colorList.append(color);
00226         }
00227     }
00228 
00229     if (colorList.isEmpty()) {
00230         colorList.append(Qt::red);
00231     }
00232 
00233     return colorList;
00234 }
00235 
00236 bool AbstractGroupingStrategy::setIcon(const QIcon &icon, TaskGroup *group)
00237 { 
00238     if (editableGroupProperties() & Icon) {
00239         group->setIcon(icon);
00240         return true;
00241     }
00242 
00243     return false;
00244 }
00245 
00246 QList <QIcon> AbstractGroupingStrategy::iconSuggestions(TaskGroup *)
00247 {
00248     QList <QIcon> iconList;
00249     iconList.append(KIcon("xorg"));
00250     return iconList;
00251 }
00252 
00253 }//namespace
00254 
00255 #include "abstractgroupingstrategy.moc"
00256 

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