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

libtaskmanager

taskrmbmenu.cpp

Go to the documentation of this file.
00001 /*****************************************************************
00002 
00003 Copyright (c) 2001 Matthias Elter <elter@kde.org>
00004 Copyright (c) 2001 John Firebaugh <jfirebaugh@kde.org>
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a copy
00007 of this software and associated documentation files (the "Software"), to deal
00008 in the Software without restriction, including without limitation the rights
00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, subject to the following conditions:
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 ******************************************************************/
00024 
00025 // Own
00026 #include "taskmanager.h"
00027 
00028 // System
00029 #include <assert.h>
00030 
00031 // KDE
00032 #include <kicon.h>
00033 #include <klocale.h>
00034 
00035 #include "config-X11.h"
00036 
00037 #if defined(HAVE_XCOMPOSITE) && \
00038     defined(HAVE_XRENDER) && \
00039     defined(HAVE_XFIXES)
00040 #include <fixx11h.h>
00041 #endif
00042 
00043 #include "taskrmbmenu.h"
00044 
00045 namespace TaskManager
00046 {
00047 
00048 TaskRMBMenu::TaskRMBMenu(const TaskList& theTasks, bool show, QWidget *parent)
00049     : QMenu( parent )
00050     , tasks( theTasks )
00051     , showAll( show )
00052 {
00053     assert(tasks.count() > 0);
00054     if (tasks.count() == 1)
00055     {
00056         fillMenu(tasks.first());
00057     }
00058     else
00059     {
00060         fillMenu();
00061     }
00062 }
00063 
00064 TaskRMBMenu::TaskRMBMenu(TaskPtr task, bool show, QWidget *parent)
00065     : QMenu( parent )
00066     , showAll( show )
00067 {
00068     fillMenu(task);
00069 }
00070 
00071 void TaskRMBMenu::fillMenu(TaskPtr t)
00072 {
00073     QAction *a;
00074 
00075     addMenu(makeAdvancedMenu(t));
00076     bool checkActions = KWindowSystem::allowedActionsSupported();
00077 
00078     if (TaskManager::self()->numberOfDesktops() > 1)
00079     {
00080         a = addMenu(makeDesktopsMenu(t));
00081 
00082         if (showAll)
00083         {
00084             a = addAction(i18n("&To Current Desktop"),
00085                             t.data(), SLOT(toCurrentDesktop()));
00086             a->setEnabled(!t->isOnCurrentDesktop());
00087         }
00088 
00089         if (checkActions)
00090         {
00091             a->setEnabled(t->info().actionSupported(NET::ActionChangeDesktop));
00092         }
00093     }
00094 
00095     a = addAction(KIcon("transform-move"), i18n("&Move"), t.data(), SLOT(move()));
00096     a->setEnabled(!checkActions || t->info().actionSupported(NET::ActionMove));
00097 
00098     a = addAction(i18n("Re&size"), t.data(), SLOT(resize()));
00099     a->setEnabled(!checkActions || t->info().actionSupported(NET::ActionResize));
00100 
00101     a = addAction(i18n("Mi&nimize"), t.data(), SLOT(toggleIconified()));
00102     a->setCheckable(true);
00103     a->setChecked(t->isIconified());
00104     a->setEnabled(!checkActions || t->info().actionSupported(NET::ActionMinimize));
00105 
00106     a = addAction(i18n("Ma&ximize"), t.data(), SLOT(toggleMaximized()));
00107     a->setCheckable(true);
00108     a->setChecked(t->isMaximized());
00109     a->setEnabled(!checkActions || t->info().actionSupported(NET::ActionMax));
00110 
00111     a = addAction(i18n("&Shade"), t.data(), SLOT(toggleShaded()));
00112     a->setCheckable(true);
00113     a->setChecked(t->isShaded());
00114     a->setEnabled(!checkActions || t->info().actionSupported(NET::ActionShade));
00115 
00116     addSeparator();
00117 
00118     a = addAction(KIcon("window-close"), i18n("&Close"), t.data(), SLOT(close()));
00119     a->setEnabled(!checkActions || t->info().actionSupported(NET::ActionClose));
00120 }
00121 
00122 void TaskRMBMenu::fillMenu()
00123 {
00124     QAction *a;
00125 
00126     TaskList::iterator itEnd = tasks.end();
00127     for (TaskList::iterator it = tasks.begin(); it != itEnd; ++it)
00128     {
00129         TaskPtr t = (*it);
00130 
00131         a = addMenu( new TaskRMBMenu(t, this) );
00132         a->setIcon( QIcon( t->pixmap() ) );
00133         a->setText( t->visibleNameWithState() );
00134         a->setChecked(t->isActive());
00135         connect( a, SIGNAL(triggered()), t.data(), SLOT( activateRaiseOrIconify() ) );
00136     }
00137 
00138     addSeparator();
00139 
00140     bool enable = false;
00141 
00142     if (TaskManager::self()->numberOfDesktops() > 1)
00143     {
00144         a = addMenu(makeDesktopsMenu());
00145 
00146         a = addAction(i18n("All &to Current Desktop"), this, SLOT(slotAllToCurrentDesktop()));
00147         TaskList::iterator itEnd = tasks.end();
00148         for (TaskList::iterator it = tasks.begin(); it != itEnd; ++it)
00149         {
00150             if (!(*it)->isOnCurrentDesktop())
00151             {
00152                 enable = true;
00153                 break;
00154             }
00155         }
00156         a->setEnabled(enable);
00157     }
00158 
00159     enable = false;
00160 
00161     a = addAction( i18n( "Mi&nimize All" ), this, SLOT( slotMinimizeAll() ) );
00162     itEnd = tasks.end();
00163     for (TaskList::iterator it = tasks.begin(); it != itEnd; ++it)
00164     {
00165         if( !(*it)->isIconified() ) {
00166             enable = true;
00167             break;
00168         }
00169     }
00170     a->setEnabled( enable );
00171 
00172     enable = false;
00173 
00174     a = addAction( i18n( "Ma&ximize All" ), this, SLOT( slotMaximizeAll() ) );
00175     itEnd = tasks.end();
00176     for (TaskList::iterator it = tasks.begin(); it != itEnd; ++it)
00177     {
00178         if( !(*it)->isMaximized() ) {
00179             enable = true;
00180             break;
00181         }
00182     }
00183     a->setEnabled( enable );
00184 
00185     enable = false;
00186 
00187     a = addAction( i18n( "&Restore All" ), this, SLOT( slotRestoreAll() ) );
00188     itEnd = tasks.end();
00189     for (TaskList::iterator it = tasks.begin(); it != itEnd; ++it)
00190     {
00191         if( (*it)->isIconified() || (*it)->isMaximized() ) {
00192             enable = true;
00193             break;
00194         }
00195     }
00196     a->setEnabled( enable );
00197 
00198     addSeparator();
00199 
00200     enable = false;
00201 
00202     addAction( KIcon( "list-remove" ), i18n( "&Close All" ), this, SLOT( slotCloseAll() ) );
00203 }
00204 
00205 QMenu* TaskRMBMenu::makeAdvancedMenu(TaskPtr t)
00206 {
00207     QAction *a;
00208     QMenu* menu = new QMenu(this);
00209     menu->setTitle(i18n("Ad&vanced"));
00210 
00211     a = menu->addAction(KIcon("go-up"),
00212                           i18n("Keep &Above Others"),
00213                           t.data(), SLOT(toggleAlwaysOnTop()));
00214     a->setCheckable(true);
00215     a->setChecked(t->isAlwaysOnTop());
00216 
00217     a = menu->addAction(KIcon("go-down"),
00218                           i18n("Keep &Below Others"),
00219                           t.data(), SLOT(toggleKeptBelowOthers()));
00220     a->setCheckable(true);
00221     a->setChecked(t->isKeptBelowOthers());
00222 
00223     a = menu->addAction(KIcon("view-fullscreen"),
00224                           i18n("&Fullscreen"),
00225                           t.data(), SLOT(toggleFullScreen()));
00226     a->setCheckable(true);
00227     a->setChecked(t->isFullScreen());
00228 
00229     if (KWindowSystem::allowedActionsSupported())
00230     {
00231         a->setEnabled(t->info().actionSupported(NET::ActionFullScreen));
00232     }
00233 
00234     return menu;
00235 }
00236 
00237 QMenu* TaskRMBMenu::makeDesktopsMenu(TaskPtr t)
00238 {
00239     QMenu* m = new QMenu( this );
00240     m->setTitle( i18n("To &Desktop") );
00241 
00242     QAction *a = m->addAction( i18n("&All Desktops"), this, SLOT( slotToDesktop() ) );
00243     a->setCheckable(true);
00244     toDesktopMap.append( QPair<TaskPtr, int>( t, 0 ) ); // 0 means all desktops
00245     a->setData( 0 );
00246     a->setChecked( t->isOnAllDesktops() );
00247 
00248     m->addSeparator();
00249 
00250     for (int i = 1; i <= TaskManager::self()->numberOfDesktops(); i++) {
00251         QString name = QString("&%1 %2").arg(i).arg(TaskManager::self()->desktopName(i).replace('&', "&&"));
00252         a = m->addAction( name, this, SLOT( slotToDesktop() ) );
00253         a->setCheckable(true);
00254         toDesktopMap.append( QPair<TaskPtr, int>( t, i ) );
00255         a->setData( i );
00256         a->setChecked( !t->isOnAllDesktops() && t->desktop() == i );
00257     }
00258 
00259     return m;
00260 }
00261 
00262 QMenu* TaskRMBMenu::makeDesktopsMenu()
00263 {
00264     QMenu* m = new QMenu( this );
00265     QAction *a;
00266 
00267     a = m->addAction( i18n("&All Desktops"), this, SLOT( slotAllToDesktop() ) );
00268     a->setData( 0 ); // 0 means all desktops
00269 
00270     m->addSeparator();
00271 
00272     for (int i = 1; i <= TaskManager::self()->numberOfDesktops(); i++) {
00273         QString name = QString("&%1 %2").arg(i).arg(TaskManager::self()->desktopName(i).replace('&', "&&"));
00274         a = m->addAction( name, this, SLOT( slotAllToDesktop() ) );
00275         a->setData( i );
00276     }
00277 
00278     return m;
00279 }
00280 
00281 void TaskRMBMenu::slotMinimizeAll()
00282 {
00283     TaskList::iterator itEnd = tasks.end();
00284     for (TaskList::iterator it = tasks.begin(); it != itEnd; ++it)
00285     {
00286         (*it)->setIconified(true);
00287     }
00288 }
00289 
00290 void TaskRMBMenu::slotMaximizeAll()
00291 {
00292     TaskList::iterator itEnd = tasks.end();
00293     for (TaskList::iterator it = tasks.begin(); it != itEnd; ++it)
00294     {
00295         (*it)->setMaximized(true);
00296     }
00297 }
00298 
00299 void TaskRMBMenu::slotRestoreAll()
00300 {
00301     TaskList::iterator itEnd = tasks.end();
00302     for (TaskList::iterator it = tasks.begin(); it != itEnd; ++it)
00303     {
00304         (*it)->restore();
00305     }
00306 }
00307 
00308 void TaskRMBMenu::slotShadeAll()
00309 {
00310     TaskList::iterator itEnd = tasks.end();
00311     for (TaskList::iterator it = tasks.begin(); it != itEnd; ++it)
00312     {
00313         (*it)->setShaded( !(*it)->isShaded() );
00314     }
00315 }
00316 
00317 void TaskRMBMenu::slotCloseAll()
00318 {
00319     TaskList::iterator itEnd = tasks.end();
00320     for (TaskList::iterator it = tasks.begin(); it != itEnd; ++it)
00321     {
00322         (*it)->close();
00323     }
00324 }
00325 
00326 void TaskRMBMenu::slotAllToDesktop()
00327 {
00328     QAction *action = qobject_cast<QAction *>( sender() );
00329     if( action ) {
00330       int desktop = action->data().toInt();
00331       TaskList::iterator itEnd = tasks.end();
00332       for (TaskList::iterator it = tasks.begin(); it != itEnd; ++it)
00333       {
00334           (*it)->toDesktop( desktop );
00335       }
00336     }
00337 }
00338 
00339 void TaskRMBMenu::slotAllToCurrentDesktop()
00340 {
00341     TaskList::iterator itEnd = tasks.end();
00342     for (TaskList::iterator it = tasks.begin(); it != itEnd; ++it)
00343     {
00344         (*it)->toCurrentDesktop();
00345     }
00346 }
00347 
00348 void TaskRMBMenu::slotToDesktop()
00349 {
00350     QAction *action = qobject_cast<QAction *>( sender() );
00351     if( action ) {
00352         QPair<TaskPtr, int> pair = toDesktopMap[action->data().toInt()];
00353         pair.first->toDesktop( pair.second );
00354     }
00355 }
00356 
00357 } // TaskManager namespace
00358 
00359 
00360 #include "taskrmbmenu.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
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
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