[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/base/plasma/runners/windows
From:       Ryan P. Bitanga <rjpbitanga () yahoo ! com>
Date:       2009-01-30 16:08:13
Message-ID: 1233331693.523334.9173.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 918735 by rbitanga:

Update window management runner to use libtaskmanager


 M  +5 -1      CMakeLists.txt  
 M  +3 -21     plasma-runner-windowmanager.desktop  
 M  +77 -39    windows.cpp  
 M  +10 -0     windows.h  


--- trunk/playground/base/plasma/runners/windows/CMakeLists.txt #918734:918735
@@ -1,3 +1,7 @@
+project(windowmanagerunner)
+
+include_directories( {$QT_INCLUDES} ${KDE4_INCLUDES} )
+
 set(krunner_windowmanager_SRCS
     windows.cpp
 )
@@ -3,5 +7,5 @@
 
 kde4_add_plugin(krunner_windowmanager ${krunner_windowmanager_SRCS})
-target_link_libraries(krunner_windowmanager ${KDE4_KDEUI_LIBS} ${KDE4_PLASMA_LIBS})
+target_link_libraries(krunner_windowmanager ${KDE4_KDEUI_LIBS} ${KDE4_PLASMA_LIBS} taskmanager)
 
 install(TARGETS krunner_windowmanager DESTINATION ${PLUGIN_INSTALL_DIR})
--- trunk/playground/base/plasma/runners/windows/plasma-runner-windowmanager.desktop #918734:918735
@@ -1,23 +1,5 @@
 [Desktop Entry]
-Name=Window Manager
-Name[de]=Fenstermanager
-Name[el]=Διαχειριστής παραθύρων
-Name[et]=Aknahaldur
-Name[fr]=Gestionnaire de fenêtre
-Name[gl]=Xestor de fiestras
-Name[km]=កម្មវិធី​គ្រប់គ្រង​បង្អួច
-Name[lt]=Langų tvarkyklė
-Name[nds]=Finsterpleger
-Name[nl]=Windowmanager
-Name[nn]=Vindaugshandsamar
-Name[pa]=ਵਿੰਡੋ ਮੈਨੇਜਰ
-Name[pt]=Gestor de Janelas
-Name[pt_BR]=Gestor de Janelas
-Name[ro]=Gestionar de ferestre
-Name[sv]=Fönsterhanterare
-Name[tr]=Pencere Yöneticisi
-Name[uk]=Віконний менеджер
-Name[x-test]=xxWindow Managerxx
+Name=Window Management Runner
 Comment=Control open application windows
 Comment[el]=Έλεγχος ανοιχτών παραθύρων εφαρμογών
 Comment[et]=Avatud rakenduste akende juhtimine
@@ -36,6 +18,6 @@
 Icon=kwin
 X-KDE-Library=krunner_windowmanager
 X-KDE-PluginInfo-Name=krunner_windowmanager
-X-KDE-PluginInfo-Version=0.1
+X-KDE-PluginInfo-Version=0.2
 X-KDE-PluginInfo-License=LGPL
-X-KDE-PluginInfo-EnabledByDefault=true
+X-KDE-PluginInfo-EnabledByDefault=false
--- trunk/playground/base/plasma/runners/windows/windows.cpp #918734:918735
@@ -1,5 +1,5 @@
 /*
- *   Copyright (C) 2008 Ryan P. Bitanga <ryan.bitanga@gmail.com>
+ *   Copyright (C) 2008-2009 Ryan P. Bitanga <ryan.bitanga@gmail.com>
  *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU Library General Public License version 2 as
@@ -22,10 +22,10 @@
 
 #include <KDebug>
 #include <KIcon>
-#include <KWindowSystem>
 
-//#include <Plasma/QueryAction>
-//#include <Plasma/QueryActionPool>
+// Libtaskmanager
+#include <taskmanager/taskmanager.h>
+#include <taskmanager/taskactions.h>
 
 #include "windows.h"
 
@@ -43,15 +43,20 @@
 }
 
 WindowManagerRunner::WindowManagerRunner(QObject *parent, const QVariantList& args)
-    : Plasma::AbstractRunner(parent, args)
+    : Plasma::AbstractRunner(parent, args),
+      m_item(0),
+      m_actionsHolder(0)
 {
     setObjectName("Window Manager Runner");
     setSpeed(AbstractRunner::SlowSpeed);
     m_eventType = QEvent::registerEventType();
+    m_grpManager = new TaskManager::GroupManager(this);
 }
 
 WindowManagerRunner::~WindowManagerRunner()
-{}
+{
+    delete m_actionsHolder;
+}
 
 void WindowManagerRunner::customEvent(QEvent *event)
 {
@@ -72,11 +77,9 @@
 
 void WindowManagerRunner::registerActions()
 {
-    //We need proper icons for these
-    addAction("window-minimize", KIcon("arrow-down"), i18n("Minimize"));
-    addAction("window-restore", KIcon("arrow-up"), i18n("Restore"));
+    // Let libtaskmanager handle all other actions
+    // actions are window specific since they act on particular window ids
     addAction("window-focus", KIcon("page-zoom"), i18n("Focus"));
-    addAction("window-sticky", KIcon("flag-blue"), i18n("Show on all desktops"));
 }
 
 void WindowManagerRunner::match(Plasma::RunnerContext &context)
@@ -98,8 +101,7 @@
     kDebug() << "Sleep while waiting for GUI thread" << endl;
     m_processInGui.wait(&m_mutex);
 
-    --runs;
-    if (runs) {
+    if (--runs) {
         m_mutex.unlock();
         kDebug() << "Aborting in favor of newer search" << endl;
         return;
@@ -128,48 +130,84 @@
     WId win = match.data().toInt();
 
     if (!KWindowSystem::hasWId(win)) {
+        kDebug() << "Window " << win << " does not exist" << endl;
         return;
     }
 
-    if (QAction *action = match.selectedAction()) {
-        QString name = action->objectName();
-        if (name == "window-minimize") {
-            KWindowSystem::minimizeWindow(win);
-        } else if (name == "window-restore") {
-            KWindowSystem::unminimizeWindow(win);
-        } else if (name == "window-focus") {
-            KWindowSystem::forceActiveWindow(win);
-        } else if (name == "window-sticky") {
-            KWindowSystem::setOnAllDesktops(win, true);
-        } else {
-            kDebug() << "Unknown action" << endl;
+    if (QAction *a = match.selectedAction()) {
+        if (a != action("window-focus")) {
+            a->trigger();
+            return;
         }
-    } else {
-        //Just raise the window if not using QuickSand
-        KWindowSystem::forceActiveWindow(win);
     }
+
+    //Just raise the window if not using QuickSand
+    KWindowSystem::forceActiveWindow(win);
 }
 
+// The following code is shared with the nepomuksearch runner
+QList<QAction*> WindowManagerRunner::parseMenu(QMenu *menu, const QString &prefix)
+{
+    QList<QAction*> ret;
+    foreach (QAction *action, menu->actions()) {
+        if (QMenu *submenu = action->menu()) {
+            //Flatten hierarchy and prefix submenu text to all actions in submenu
+            ret << parseMenu(submenu, action->text());
+        } else if (!action->isSeparator() && action->isEnabled()) {
+            QString aText = action->text();
+            if (action->isCheckable()) {
+                // TODO: Use a checkmark instead. This looks nasty.
+                if (action->isChecked()) {
+                    aText = QString("(X) %1").arg(aText);
+                } else {
+                    aText = QString("( ) %1").arg(aText);
+                }
+            }
+            QString text;
+            if (prefix.isEmpty()) {
+                text = aText.replace(QRegExp("&([\\S])"), "\\1");
+            } else {
+                text = QString("%1: %2").arg(prefix).arg(aText).replace(QRegExp("&([\\S])"), "\\1");
+            }
+
+            QAction *a = new QAction(action->icon(), text, this);
+
+            connect(a, SIGNAL(triggered(bool)), action, SIGNAL(triggered(bool)));
+            ret << a;
+        }
+    }
+    return ret;
+}
+
 QList<QAction*> WindowManagerRunner::actionsForMatch(const Plasma::QueryMatch &match)
 {
     QList<QAction*> ret;
+
+    WId win = match.data().toInt();
+
+    TaskManager::TaskPtr task = TaskManager::TaskManager::self()->findTask(win);
+
+    if (!task) {
+        kDebug() << "Can't find the window with id " << win << endl;
+        return ret;
+    }
+
+    delete m_item;
+    m_item = new TaskManager::TaskItem(this, task);
+
     //Check if actions were already loaded
-    if (!action("window-minimize")) {
+    if (!action("window-focus")) {
         registerActions();
     }
+    // Taken out pending focus fix for QuickSand
+    // ret << action("window-focus");
 
-    WId win = match.data().toInt();
-    KWindowInfo info = KWindowSystem::windowInfo(win, NET::WMState | NET::XAWMState);
+    // Unlike KonqMenuActions, slots are handled by BasicMenu itself
+    // thus we keep it alive until the next actionsForMatch call
+    delete m_actionsHolder;
+    m_actionsHolder = new TaskManager::BasicMenu(0, m_item, m_grpManager);
 
-    if (info.isMinimized()) {
-        ret << action("window-restore");
-    } else {
-        ret << action("window-minimize");
-    }
+    ret << parseMenu(m_actionsHolder);
 
-    ret << action("window-focus") << action("window-sticky");
-
     return ret;
 }
-
-//#include "windows.moc"
--- trunk/playground/base/plasma/runners/windows/windows.h #918734:918735
@@ -28,7 +28,13 @@
 #include <Plasma/AbstractRunner>
 
 class QEvent;
+class QMenu;
 
+namespace TaskManager
+{
+    class TaskItem;
+}
+
 struct WindowInfo
 {
     QIcon icon;
@@ -48,9 +54,13 @@
         QList<QAction*> actionsForMatch(const Plasma::QueryMatch &match);
 
     private:
+        QList<QAction*> parseMenu(QMenu *menu, const QString &prefix = QString());
         void customEvent(QEvent *event);
         void registerActions();
 
+        TaskManager::TaskItem *m_item;
+        TaskManager::GroupManager *m_grpManager;
+        QMenu *m_actionsHolder;
         QMutex m_mutex;
         QWaitCondition m_processInGui;
         QHash<WId, WindowInfo> m_winInfo;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic