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

libtaskmanager

taskactions.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 "taskactions.h"
00025 #include "taskactions_p.h"
00026 
00027 // Own
00028 
00029 #include "taskgroup.h"
00030 #include "task.h"
00031 #include "taskitem.h"
00032 #include "taskmanager.h"
00033 #include "abstractgroupingstrategy.h"
00034 
00035 // KDE
00036 #include <kicon.h>
00037 #include <klocale.h>
00038 #include <KDebug>
00039 
00040 namespace TaskManager
00041 {
00042 
00043 
00044 QAction *standardGroupableAction(GroupableAction action, AbstractItemPtr item, QObject *parent, int desktop)
00045 {
00046     Q_ASSERT(item);
00047 
00048     switch (action) {
00049         case MaximizeAction:
00050             return new MaximizeActionImpl(parent, item);
00051             break;
00052         case MinimizeAction:
00053             return new MinimizeActionImpl(parent, item);
00054             break;
00055         case ToCurrentDesktopAction:
00056             return new ToCurrentDesktopActionImpl(parent, item);
00057             break;
00058         case ToDesktopAction:
00059             return new ToDesktopActionImpl(parent, item, desktop);
00060             break;
00061         case ShadeAction:
00062             return new ShadeActionImpl(parent, item);
00063             break;
00064         case CloseAction:
00065             return new CloseActionImpl(parent, item);
00066             break;
00067         case ViewFullscreenAction:
00068             return new ViewFullscreenActionImpl(parent, item);
00069             break;
00070         case KeepBelowAction:
00071             return new KeepBelowActionImpl(parent, item);
00072             break;
00073     }
00074 
00075     return 0;
00076 }
00077 
00078 QAction* standardTaskAction(TaskAction action, TaskItem *item, QObject *parent)
00079 {
00080     Q_ASSERT(item);
00081 
00082     switch (action) {
00083         case ResizeAction:
00084             return new ResizeActionImpl(parent, item);
00085             break;
00086         case MoveAction:
00087             return new MoveActionImpl(parent, item);
00088             break;
00089     }
00090 
00091     return 0;
00092 }
00093 
00094 QAction* standardGroupingAction(GroupingAction action, AbstractItemPtr item, GroupManager *strategy, QObject *parent)
00095 {
00096     Q_ASSERT(item);
00097     Q_ASSERT(strategy);
00098 
00099     switch (action) {
00100         case LeaveGroupAction:
00101             return new LeaveGroupActionImpl(parent, item, strategy);
00102             break;
00103     }
00104 
00105     return 0;
00106 }
00107 
00108 MinimizeActionImpl::MinimizeActionImpl(QObject *parent, AbstractItemPtr item)
00109     : QAction(parent)
00110 {
00111     connect(this, SIGNAL(triggered()), item, SLOT(toggleMinimized()));
00112     setText(i18n("Mi&nimize"));
00113     setCheckable(true);
00114     setChecked(item->isMinimized());
00115     setEnabled(item->isActionSupported(NET::ActionMinimize));
00116 }
00117 
00118 
00119 MaximizeActionImpl::MaximizeActionImpl(QObject *parent, AbstractItemPtr item)
00120     : QAction(parent)
00121 {
00122     connect(this, SIGNAL(triggered()), item, SLOT(toggleMaximized()));
00123     setText(i18n("Ma&ximize"));
00124     setCheckable(true);
00125     setChecked(item->isMaximized());
00126     setEnabled(item->isActionSupported(NET::ActionMax));
00127 }
00128 
00129 ShadeActionImpl::ShadeActionImpl(QObject *parent, AbstractItemPtr item)
00130     : QAction(parent)
00131 {
00132     connect(this, SIGNAL(triggered()), item, SLOT(toggleShaded()));
00133     setText(i18n("&Shade"));
00134     setCheckable(true);
00135     setChecked(item->isShaded());
00136     setEnabled(item->isActionSupported(NET::ActionShade));
00137 }
00138 
00139 ResizeActionImpl::ResizeActionImpl(QObject *parent, TaskItem* item)
00140     : QAction(parent)
00141 {
00142     TaskPtr task = item->task();
00143     connect(this, SIGNAL(triggered()), task.data(), SLOT(resize()));
00144     setText(i18n("Re&size"));
00145     setEnabled(item->isActionSupported(NET::ActionResize));
00146 }
00147 
00148 MoveActionImpl::MoveActionImpl(QObject *parent, TaskItem* item)
00149     : QAction(parent)
00150 {
00151     TaskPtr task = item->task();
00152     connect(this, SIGNAL(triggered()), task.data(), SLOT(move()));
00153     setText(i18n("&Move"));
00154     setIcon(KIcon("transform-move"));
00155     setEnabled(item->isActionSupported(NET::ActionMove));
00156 }
00157 
00158 CloseActionImpl::CloseActionImpl(QObject *parent, AbstractItemPtr item)
00159     : QAction(parent)
00160 {
00161     connect(this, SIGNAL(triggered()), item, SLOT(close()));
00162     setText(i18n("&Close"));
00163     setIcon(KIcon("window-close"));
00164     setEnabled(item->isActionSupported(NET::ActionClose));
00165 }
00166 
00167 
00168 ToCurrentDesktopActionImpl::ToCurrentDesktopActionImpl(QObject *parent, AbstractItemPtr item)
00169     : QAction(parent),
00170       m_item(item)
00171 {
00172     connect(this, SIGNAL(triggered()), this, SLOT(slotToCurrentDesktop()));
00173     setText(i18n("&To Current Desktop"));
00174     setEnabled(!item->isOnCurrentDesktop() && item->isActionSupported(NET::ActionChangeDesktop));
00175 }
00176 
00177 void ToCurrentDesktopActionImpl::slotToCurrentDesktop() 
00178 {
00179     m_item->toDesktop(KWindowSystem::currentDesktop());
00180 }
00181 
00182 
00183 
00184 ToDesktopActionImpl::ToDesktopActionImpl(QObject *parent, AbstractItemPtr item, int desktop)
00185     : QAction(parent),
00186       m_desktop(desktop),
00187       m_item(item)
00188 {
00189     connect(this, SIGNAL(triggered()), this, SLOT(slotToDesktop()));
00190     setCheckable(true);
00191     if (!desktop) { //to All Desktops
00192         setText(i18n("&All Desktops"));
00193         setChecked(item->isOnAllDesktops());
00194     } else {
00195         QString name = QString("&%1 %2").arg(desktop).arg(TaskManager::self()->desktopName(desktop).replace('&', "&&"));
00196         setText(name);
00197         setChecked(!item->isOnAllDesktops() && item->desktop() == desktop);
00198     }
00199 
00200 }
00201 
00202 void ToDesktopActionImpl::slotToDesktop() 
00203 {
00204     m_item->toDesktop(m_desktop);
00205 }
00206 
00207 
00208 
00209 DesktopsMenu::DesktopsMenu(QWidget *parent, AbstractItemPtr item)
00210     : QMenu(parent)
00211 {
00212     setTitle( i18n("To &Desktop") );
00213     addAction( new ToDesktopActionImpl(this,item,0) );      //0 means all desktops
00214     addSeparator();
00215     for (int i = 1; i <= TaskManager::self()->numberOfDesktops(); i++) {
00216         addAction( new ToDesktopActionImpl(this,item,i) );
00217     }
00218     setEnabled(item->isActionSupported(NET::ActionChangeDesktop));
00219 }
00220 
00221 KeepAboveActionImpl::KeepAboveActionImpl(QObject *parent, AbstractItemPtr item)
00222     : QAction(parent)
00223 {
00224     connect(this, SIGNAL(triggered()), item, SLOT(toggleAlwaysOnTop()));
00225     setText(i18n("Keep &Above Others"));
00226     setIcon(KIcon("go-up"));
00227     setCheckable(true);
00228     setChecked(item->isAlwaysOnTop());
00229 }
00230 
00231 KeepBelowActionImpl::KeepBelowActionImpl(QObject *parent, AbstractItemPtr item)
00232     : QAction(parent)
00233 {
00234     connect(this, SIGNAL(triggered()), item, SLOT(toggleKeptBelowOthers()));
00235     setText(i18n("Keep &Below Others"));
00236     setIcon(KIcon("go-down"));
00237     setCheckable(true);
00238     setChecked(item->isKeptBelowOthers());
00239 }
00240 
00241 ViewFullscreenActionImpl::ViewFullscreenActionImpl(QObject *parent, AbstractItemPtr item)
00242     : QAction(parent)
00243 {
00244     connect(this, SIGNAL(triggered()), item, SLOT(toggleFullScreen()));
00245     setText(i18n("&Fullscreen"));
00246     setIcon(KIcon("view-fullscreen"));
00247     setCheckable(true);
00248     setChecked(item->isFullScreen());
00249     setEnabled(item->isActionSupported(NET::ActionFullScreen));
00250 }
00251 
00252 AdvancedMenu::AdvancedMenu(QWidget *parent, AbstractItemPtr item)
00253     :QMenu(parent)
00254 {
00255     setTitle(i18n("Ad&vanced"));
00256     addAction(new KeepAboveActionImpl(this, item));
00257     addAction(new KeepBelowActionImpl(this, item));
00258     addAction(new ViewFullscreenActionImpl(this, item));
00259 }
00260 
00261 LeaveGroupActionImpl::LeaveGroupActionImpl(QObject *parent, AbstractItemPtr item, GroupManager *strategy)
00262     : QAction(parent), abstractItem(item), groupingStrategy(strategy)
00263 {
00264     Q_ASSERT(strategy);
00265     connect(this, SIGNAL(triggered()), this, SLOT(leaveGroup()));
00266     setText(i18n("&Leave Group"));
00267     setIcon(KIcon("window-close"));
00268     setEnabled(item->isGrouped());
00269 }
00270 
00271 void LeaveGroupActionImpl::leaveGroup()
00272 {
00273     groupingStrategy->manualGroupingRequest(abstractItem,abstractItem->parentGroup()->parentGroup());
00274 }
00275 
00276 EditGroupActionImpl::EditGroupActionImpl(QObject *parent, TaskGroup *group, GroupManager *groupManager)
00277     : QAction(parent)
00278 {
00279     Q_ASSERT(groupManager);
00280     connect(this, SIGNAL(triggered()), group, SIGNAL(groupEditRequest()));
00281     setText(i18n("&Edit Group"));
00282     //setIcon(KIcon("window-close"));
00283     if (groupManager->groupingStrategy()) {
00284         setEnabled(groupManager->taskGrouper()->editableGroupProperties());
00285     } else {
00286         setEnabled(false);
00287     }
00288 }
00289 
00290 GroupingStrategyMenu::GroupingStrategyMenu(QWidget *parent, AbstractGroupableItem* item, GroupManager *strategy)
00291     : QMenu(parent)
00292 {
00293     Q_ASSERT(item);
00294     Q_ASSERT(strategy);
00295 
00296     setTitle("Grouping strategy actions");
00297     if (strategy->taskGrouper()) {
00298         QList<QAction*> groupingStrategyActions = strategy->taskGrouper()->strategyActions(this, item);
00299         if (!groupingStrategyActions.empty()) {
00300             addSeparator();
00301             foreach (QAction *action, groupingStrategyActions) {
00302                 addAction(action);
00303             }
00304         }
00305     }
00306 
00307 }
00308 
00309 
00310 BasicMenu::BasicMenu(QWidget *parent, TaskItem* item, GroupManager *strategy, QList<QAction *> visualizationActions)
00311     : QMenu(parent)
00312 {
00313     Q_ASSERT(item);
00314     Q_ASSERT(strategy);
00315 
00316     setTitle(item->name());
00317     setIcon(item->icon());
00318     addMenu(new AdvancedMenu(this, item));
00319 
00320     if (TaskManager::self()->numberOfDesktops() > 1) {
00321         addMenu(new DesktopsMenu(this, item));
00322         addAction(new ToCurrentDesktopActionImpl(this, item));
00323     }
00324 
00325     addAction(new MoveActionImpl(this, item));
00326     addAction(new ResizeActionImpl(this, item));
00327     addAction(new MinimizeActionImpl(this, item));
00328     addAction(new MaximizeActionImpl(this, item));
00329     addAction(new ShadeActionImpl(this, item));
00330 
00331     if (strategy->taskGrouper()) {
00332         QList<QAction*> groupingStrategyActions = strategy->taskGrouper()->strategyActions(this, item);
00333         if (!groupingStrategyActions.isEmpty()) {
00334             addSeparator();
00335             foreach (QAction *action, groupingStrategyActions) {
00336                 addAction(action);
00337             }
00338             // delete groupingStrategyActions;
00339         }
00340     }
00341 
00342     foreach (QAction *action, visualizationActions) {
00343         addAction(action);
00344     }
00345 
00346     addSeparator();
00347     addAction(new CloseActionImpl(this, item));
00348 }
00349 
00350 BasicMenu::BasicMenu(QWidget *parent, TaskGroup* group, GroupManager *strategy, QList <QAction*> visualizationActions)
00351     : QMenu(parent)
00352 {
00353     Q_ASSERT(group);
00354     Q_ASSERT(strategy);
00355 
00356     setTitle(group->name());
00357     setIcon(group->icon());
00358     foreach (AbstractGroupableItem *item, group->members()) {
00359         if (item->isGroupItem()) {
00360             addMenu(new BasicMenu(this, dynamic_cast<TaskGroup*>(item), strategy));
00361         } else {
00362             addMenu(new BasicMenu(this, dynamic_cast<TaskItem*>(item), strategy));
00363         }
00364     }
00365     addSeparator();
00366     addMenu(new AdvancedMenu(this, group));
00367 
00368     if (TaskManager::self()->numberOfDesktops() > 1) {
00369         addMenu(new DesktopsMenu(this, group));
00370         addAction(new ToCurrentDesktopActionImpl(this, group));
00371     }
00372 
00373     addAction(new MinimizeActionImpl(this, group));
00374     addAction(new MaximizeActionImpl(this, group));
00375     addAction(new ShadeActionImpl(this, group));
00376 
00377     if (strategy->taskGrouper()) {
00378         QList<QAction*> groupingStrategyActions = strategy->taskGrouper()->strategyActions(this, group);
00379         if (!groupingStrategyActions.isEmpty()) {
00380             addSeparator();
00381             foreach (QAction *action, groupingStrategyActions) {
00382                 addAction(action);
00383             }
00384         }
00385     }
00386     addAction(new EditGroupActionImpl(this, group, strategy));
00387     foreach(QAction *action, visualizationActions) {
00388         addAction(action);
00389     }
00390 
00391     addSeparator();
00392     addAction(new CloseActionImpl(this, group));
00393 }
00394 
00395 GroupPopupMenu::GroupPopupMenu(QWidget *parent, TaskGroup *group, GroupManager *groupManager)
00396     :QMenu(parent)
00397 {
00398     setTitle(group->name());
00399     setIcon(group->icon());
00400     foreach (AbstractGroupableItem *item, group->members()) {
00401         if (!item) {
00402             kDebug() << "invalid Item";
00403             continue;
00404         }
00405 
00406         if (item->isGroupItem()) {
00407             QMenu* menu = new GroupPopupMenu (this, qobject_cast<TaskGroup*>(item), groupManager);
00408             addMenu(menu);
00409         } else {
00410             QAction* action = new QAction(item->icon(), item->name(), this);
00411             connect(action, SIGNAL(triggered(bool)), (qobject_cast<TaskItem*>(item))->task().data() , SLOT(activateRaiseOrIconify()));
00412             addAction(action);
00413         }
00414     }
00415 }
00416 
00417 } // TaskManager namespace
00418 
00419 #include "taskactions.moc"
00420 #include "taskactions_p.moc"
00421 

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