1
/*****************************************************************
3
Copyright 2008 Christian Mollekopf <chrigi_1@hotmail.com>
4
Copyright 2009 CasperBoemann <cbr@boemann.dk>
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
of this software and associated documentation files (the "Software"), to deal
8
in the Software without restriction, including without limitation the rights
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
copies of the Software, and to permit persons to whom the Software is
11
furnished to do so, subject to the following conditions:
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
******************************************************************/
25
#include "kustodiangroupingstrategy.h"
34
#include "abstractgroupingstrategy.h"
35
#include "groupmanager.h"
40
class KustodianGroupingStrategy::Private
44
:editableGroupProperties(AbstractGroupingStrategy::None)
47
AbstractGroupingStrategy::EditableGroupProperties editableGroupProperties;
51
KustodianGroupingStrategy::KustodianGroupingStrategy(GroupManager *groupManager)
52
:AbstractGroupingStrategy(groupManager),
55
setType(GroupManager::KustodianGrouping);
57
QStringList defaultApps;
58
defaultApps << "dolphin" << "krita" << "konqueror" << "kwrite" << "konsole" << "gwenview" << "kontact" << "konversation" << "amarok" << "kword";
59
foreach (const QString &name, defaultApps) {
60
QList <AbstractGroupableItem *> list;
61
TaskGroup* group = createGroup(list);
63
group->setPersistentWithLauncher(true);
64
KService::Ptr service = KService::serviceByDesktopName(name);
65
if (service && service->isValid()) {
66
QIcon icon = KIcon(service->icon());
72
KustodianGroupingStrategy::~KustodianGroupingStrategy()
77
QList<QAction*> KustodianGroupingStrategy::strategyActions(QObject *parent, AbstractGroupableItem *item)
81
QList<QAction*> actionList;
85
void KustodianGroupingStrategy::handleItem(AbstractGroupableItem *item)
91
if (item->itemType() == GroupItemType) {
92
rootGroup()->add(item);
96
TaskItem *task = dynamic_cast<TaskItem*>(item);
97
if (task && !programGrouping(task, rootGroup())) {
98
QString name = desktopNameFromClassName(task->task()->classClass());
99
//kDebug() << "create new subgroup in root as this classname doesn't have a group " << name;
101
QList <AbstractGroupableItem *> list;
103
TaskGroup* group = createGroup(list);
104
group->setName(name);
105
group->setColor(Qt::red);
106
KService::Ptr service = KService::serviceByDesktopName(name);
107
if (service && service->isValid()) {
108
QIcon icon = KIcon(service->icon());
109
group->setIcon(icon);
114
bool KustodianGroupingStrategy::programGrouping(TaskItem* taskItem, TaskGroup* groupItem)
117
QHash <QString,AbstractGroupableItem *> itemMap;
119
foreach (AbstractGroupableItem *item, groupItem->members()) { //search for an existing group
120
if (item->itemType() == GroupItemType && programGrouping(taskItem, static_cast<TaskGroup*>(item))) {
121
//maybe add the condition that the subgroup was created by programGrouping
122
//kDebug() << "joined subGroup";
127
QString name = desktopNameFromClassName(taskItem->task()->classClass());
128
if (groupItem->name() == name) { //join this group
129
//kDebug() << "joined this Group";
130
groupItem->add(taskItem);
137
QString KustodianGroupingStrategy::desktopNameFromClassName(const QString & name)
139
KService::Ptr service = KService::serviceByDesktopName(name.toLower());
140
if (service && service->isValid()) {
141
return name.toLower();
143
service = KService::serviceByDesktopName(name);
144
if (service && service->isValid()) {
147
service = KService::serviceByDesktopName(name.toLower().remove(QChar(' ')));
148
if (service && service->isValid()) {
149
return name.toLower().remove(' ');
155
void KustodianGroupingStrategy::checkGroup()
157
TaskGroup *group = qobject_cast<TaskGroup*>(sender());
162
if (group->members().isEmpty() && !group->isPersistentWithLauncher()) {
169
#include "kustodiangroupingstrategy.moc"