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

List:       kde-panel-devel
Subject:    Tasks DataEngine Cleanup and Service
From:       "Alain Boyer" <alainboyer () gmail ! com>
Date:       2008-09-21 21:46:55
Message-ID: 270f3b8f0809211446j14f24daye34f02c9ce6b1b0e () mail ! gmail ! com
[Download RAW message or body]

Hello,

Here is my first patch to the KDE project! Basically, it cleans up the
existing tasks data engine and adds a service to it that enables
interaction with the tasks or windows (ex: maximize, minimize,
activate...). Only a subset of data and operations are exposed; those
deemed "safe" by me. Should more data be exposed? Should more
operations (such as closing a task) be permitted? I'm thinking we can
address these issues later.

I divided the patch in two: tasks_existing.diff and tasks_new.diff.
The first patch contains changes to the existing headers and sources.
The changes are quite extensive; I hope it is not too hard to follow.
The second patch contains new headers and sources for the service.

I'm also including a patch to ConfigXml. It is a workaround that
addresses the current problem with KConfigSkeleton (see thread on
kde-core-devel for more info). Essentially, it forces writing to the
config file. What is nice is that the change is within the plasma
library and not kdelibs. This change makes sense for the Service
Explorer although I'm not sure if it negatively affects other uses of
ConfigXml.

I'd be happy to make some changes to these patches if need be.

Alain.

["tasks_existing.diff" (text/x-diff)]

Index: tasksengine.h
===================================================================
--- tasksengine.h	(revision 862967)
+++ tasksengine.h	(working copy)
@@ -1,55 +1,72 @@
 /*
- *   Copyright (C) 2007 Robert Knight <robertknight@gmail.com> 
+ * Copyright 2008 Robert Knight <robertknight@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
- *   published by the Free Software Foundation
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   You should have received a copy of the GNU Library General Public
- *   License along with this program; if not, write to the
- *   Free Software Foundation, Inc.,
- *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifndef TASKSENGINE_H
 #define TASKSENGINE_H
 
-// Plasma
+// plasma
 #include <plasma/dataengine.h>
+#include <plasma/service.h>
+
+// libtaskmanager
 #include <taskmanager/taskmanager.h>
-
 using TaskManager::StartupPtr;
 using TaskManager::TaskPtr;
 
 /**
- * This class evaluates the basic expressions given in the interface.
+ * Tasks Data Engine
+ *
+ * This engine provides information regarding tasks (windows that are currently \
open) + * as well as startup tasks (windows that are about to open).
+ * Each task and startup is represented by a unique source. Sources are added and \
removed + * as windows are opened and closed. You cannot request a customized source.
+ *
+ * A service is also provided for each task. It exposes some operations that can be
+ * performed on the windows (ex: maximize, minimize, activate).
+ *
+ * The data and operations are provided and handled by the taskmanager library.
+ * It should be noted that only a subset of data and operations are exposed.
  */
 class TasksEngine : public Plasma::DataEngine
 {
+
     Q_OBJECT
 
     public:
-        TasksEngine(QObject* parent, const QVariantList& args);
+        TasksEngine(QObject *parent, const QVariantList &args);
+        ~TasksEngine();
+        Plasma::Service *serviceForSource(const QString &name);
 
     protected:
-        virtual void init();
+        static const QString getStartupName(StartupPtr startup);
+        static const QString getTaskName(TaskPtr task);
+        void init();
 
     private slots:
-        void taskChanged();
+        void startupAdded(StartupPtr startup);
+        void startupRemoved(StartupPtr startup);
         void taskAdded(TaskPtr task);
         void taskRemoved(TaskPtr task);
-        void startupChanged();
-        void startupAdded(StartupPtr task);
-        void startupRemoved(StartupPtr);
 
     private:
-        void setDataForTask(TaskPtr task);
-        void setDataForStartup(StartupPtr task);
+        friend class TaskSource;
+        void addStartup(StartupPtr startup);
+        void addTask(TaskPtr task);
+
 };
 
 #endif // TASKSENGINE_H
Index: plasma-dataengine-tasks.desktop
===================================================================
--- plasma-dataengine-tasks.desktop	(revision 862967)
+++ plasma-dataengine-tasks.desktop	(working copy)
@@ -12,7 +12,7 @@
 Name[uk]=Інформація про вікна
 Name[zh_TW]=視窗資訊
 Type=Service
-Icon=alarmclock
+Icon=user-desktop
 
 X-KDE-ServiceTypes=Plasma/DataEngine
 X-KDE-Library=plasma_engine_tasks
@@ -24,5 +24,5 @@
 X-KDE-PluginInfo-Website=http://plasma.kde.org/
 X-KDE-PluginInfo-Category=Windows and Tasks
 X-KDE-PluginInfo-Depends=
-X-KDE-PluginInfo-License=LGPL
+X-KDE-PluginInfo-License=GPL
 X-KDE-PluginInfo-EnabledByDefault=true
Index: tasksengine.cpp
===================================================================
--- tasksengine.cpp	(revision 862967)
+++ tasksengine.cpp	(working copy)
@@ -1,124 +1,112 @@
 /*
- *   Copyright (C) 2007 Robert Knight <robertknight@gmail.com>
+ * Copyright 2008 Robert Knight <robertknight@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
- *   published by the Free Software Foundation
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   You should have received a copy of the GNU Library General Public
- *   License along with this program; if not, write to the
- *   Free Software Foundation, Inc.,
- *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "tasksengine.h"
 
-using namespace Plasma;
+// own
+#include "tasksource.h"
 
-TasksEngine::TasksEngine(QObject* parent, const QVariantList& args)
-    : Plasma::DataEngine(parent, args)
+TasksEngine::TasksEngine(QObject *parent, const QVariantList &args) :
+    Plasma::DataEngine(parent, args)
 {
     Q_UNUSED(args);
 }
 
-void TasksEngine::init()
+TasksEngine::~TasksEngine()
 {
-    foreach(const TaskPtr& task, TaskManager::TaskManager::self()->tasks().values()) \
                {
-        connect(task.constData(), SIGNAL(changed()),
-                this,             SLOT(taskChanged()));
-        setDataForTask(task);
-    }
+}
 
-    connect(TaskManager::TaskManager::self(), SIGNAL(taskAdded(TaskPtr)),
-            this,                             SLOT(taskAdded(TaskPtr)));
-    connect(TaskManager::TaskManager::self(), SIGNAL(taskRemoved(TaskPtr)),
-            this,                             SLOT(taskRemoved(TaskPtr)));
-    connect(TaskManager::TaskManager::self(), SIGNAL(startupAdded(StartupPtr)),
-            this,                             SLOT(startupAdded(StartupPtr)));
-    connect(TaskManager::TaskManager::self(), SIGNAL(startupRemoved(StartupPtr)),
-            this,                             SLOT(startupRemoved(StartupPtr)));
+Plasma::Service *TasksEngine::serviceForSource(const QString &name)
+{
+    TaskSource *source = dynamic_cast<TaskSource*>(containerForSource(name));
+    // if source does not exist, return null service
+    if (!source) {
+        return Plasma::DataEngine::serviceForSource(name);
+    }
+    // if source represents a startup task, return null service
+    if (!source->isTask()) {
+        return Plasma::DataEngine::serviceForSource(name);
+    }
+    // if source represent a proper task, return task service
+    Plasma::Service *service = source->createService();
+    service->setParent(this);
+    return service;
 }
 
-void TasksEngine::startupAdded(StartupPtr startup)
+const QString TasksEngine::getStartupName(StartupPtr startup)
 {
-    connect(startup.constData(), SIGNAL(changed()), this, SLOT(startupChanged()));
-    setDataForStartup(startup);
+    return startup->id().id();
 }
 
-void TasksEngine::startupRemoved(StartupPtr startup)
+const QString TasksEngine::getTaskName(TaskPtr task)
 {
-    removeSource(startup->id().id());
+    return QString::number(task->window());
 }
 
-void TasksEngine::startupChanged()
+void TasksEngine::init()
 {
-    TaskManager::Startup* startup = qobject_cast<TaskManager::Startup*>(sender());
+    foreach (const TaskPtr &task, \
TaskManager::TaskManager::self()->tasks().values()) { +        Q_ASSERT(task);
+        addTask(task);
+    }
+    connect(TaskManager::TaskManager::self(), SIGNAL(startupAdded(StartupPtr)), \
this, SLOT(startupAdded(StartupPtr))); +    connect(TaskManager::TaskManager::self(), \
SIGNAL(startupRemoved(StartupPtr)), this, SLOT(startupRemoved(StartupPtr))); +    \
connect(TaskManager::TaskManager::self(), SIGNAL(taskAdded(TaskPtr)), this, \
SLOT(taskAdded(TaskPtr))); +    connect(TaskManager::TaskManager::self(), \
SIGNAL(taskRemoved(TaskPtr)), this, SLOT(taskRemoved(TaskPtr))); +}
 
+void TasksEngine::startupAdded(StartupPtr startup)
+{
     Q_ASSERT(startup);
-
-    setDataForStartup(StartupPtr(startup));
+    addStartup(startup);
 }
 
-void TasksEngine::setDataForStartup(StartupPtr startup)
+void TasksEngine::startupRemoved(StartupPtr startup)
 {
     Q_ASSERT(startup);
-
-    QString name(startup->id().id());
-
-    const QMetaObject* metaObject = startup->metaObject();
-
-    for (int i = 0; i < metaObject->propertyCount(); i++) {
-        QMetaProperty property = metaObject->property(i);
-
-        setData(name, property.name(), property.read(startup.constData()));
-    }
-    setData(name, "TaskOrStartup", "startup");
+    removeSource(getStartupName(startup));
 }
 
 void TasksEngine::taskAdded(TaskPtr task)
 {
-    connect(task.constData(), SIGNAL(changed()),
-            this,             SLOT(taskChanged()));
-    setDataForTask(task);
+    Q_ASSERT(task);
+    addTask(task);
 }
 
 void TasksEngine::taskRemoved(TaskPtr task)
 {
-    removeSource(QString::number(task->window()));
+    Q_ASSERT(task);
+    removeSource(getTaskName(task));
 }
 
-void TasksEngine::taskChanged()
+void TasksEngine::addStartup(StartupPtr startup)
 {
-    TaskManager::Task* task = qobject_cast<TaskManager::Task*>(sender());
-
-    Q_ASSERT(task);
-
-    setDataForTask(TaskPtr(task));
+    TaskSource *taskSource = new TaskSource(startup, this);
+    connect(startup.constData(), SIGNAL(changed()), taskSource, \
SLOT(updateStartup())); +    addSource(taskSource);
 }
 
-void TasksEngine::setDataForTask(TaskPtr task)
+void TasksEngine::addTask(TaskPtr task)
 {
-    Q_ASSERT(task);
-
-    QString name = QString::number(task->window());
-
-    const QMetaObject* metaObject = task->metaObject();
-
-    for (int i = 0; i < metaObject->propertyCount(); i++) {
-        QMetaProperty property = metaObject->property(i);
-
-        setData(name,property.name(),property.read(task.constData()));
-    }
-    setData(name, "WId", static_cast<qulonglong>(task->window()));
-    setData(name, "TaskOrStartup", "task");
+    TaskSource *taskSource = new TaskSource(task, this);
+    connect(task.constData(), SIGNAL(changed(::TaskManager::TaskChanges)), \
taskSource, SLOT(updateTask(::TaskManager::TaskChanges))); +    \
addSource(taskSource);  }
 
 K_EXPORT_PLASMA_DATAENGINE(tasks, TasksEngine)
 
-
 #include "tasksengine.moc"
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 862967)
+++ CMakeLists.txt	(working copy)
@@ -1,11 +1,13 @@
 set(tasks_engine_SRCS
     tasksengine.cpp
+    tasksource.cpp
+    taskservice.cpp
+    taskjob.cpp
 )
 
 kde4_add_plugin(plasma_engine_tasks ${tasks_engine_SRCS})
-target_link_libraries(plasma_engine_tasks ${KDE4_KDEUI_LIBS} plasma
-                      taskmanager)
+target_link_libraries(plasma_engine_tasks ${KDE4_KDEUI_LIBS} plasma taskmanager)
 
 install(TARGETS plasma_engine_tasks DESTINATION ${PLUGIN_INSTALL_DIR})
-install(FILES plasma-dataengine-tasks.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
-
+install(FILES plasma-dataengine-tasks.desktop DESTINATION ${SERVICES_INSTALL_DIR})
+install(FILES tasks.operations DESTINATION ${DATA_INSTALL_DIR}/plasma/services)


["tasks_new.diff" (text/x-diff)]

Index: taskjob.h
===================================================================
--- taskjob.h	(revision 0)
+++ taskjob.h	(revision 0)
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2008 Alain Boyer <alainboyer@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TASKJOB_H
+#define TASKJOB_H
+
+// plasma
+#include <plasma/servicejob.h>
+
+// own
+#include "tasksource.h"
+
+/**
+ * Task Job
+ */
+class TaskJob : public Plasma::ServiceJob
+{
+
+    Q_OBJECT
+
+    public:
+        TaskJob(TaskSource *source, const QString &operation, QMap<QString, \
QVariant> &parameters, QObject *parent = NULL); +        ~TaskJob();
+
+    protected:
+        void start();
+
+    private:
+        TaskSource *m_source;
+
+};
+
+#endif // TASKJOB_H
Index: tasksource.cpp
===================================================================
--- tasksource.cpp	(revision 0)
+++ tasksource.cpp	(revision 0)
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2008 Alain Boyer <alainboyer@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "tasksource.h"
+
+// own
+#include "tasksengine.h"
+#include "taskservice.h"
+
+TaskSource::TaskSource(TaskPtr task, QObject *parent) :
+    Plasma::DataContainer(parent),
+    m_task(task),
+    m_startup(),
+    m_isTask(true)
+{
+    setObjectName(TasksEngine::getTaskName(m_task));
+    setData("startup", false);
+    setData("task", true);
+    updateTask(TaskManager::EverythingChanged);
+}
+
+TaskSource::TaskSource(StartupPtr startup, QObject *parent) :
+    Plasma::DataContainer(parent),
+    m_task(),
+    m_startup(startup),
+    m_isTask(false)
+{
+    setObjectName(TasksEngine::getStartupName(m_startup));
+    setData("startup", true);
+    setData("task", false);
+    updateStartup();
+}
+
+TaskSource::~TaskSource()
+{
+}
+
+Plasma::Service *TaskSource::createService()
+{
+    return new TaskService(this);
+}
+
+TaskPtr TaskSource::getTask()
+{
+    return m_task;
+}
+
+const bool TaskSource::isTask()
+{
+    return m_isTask;
+}
+
+void TaskSource::updateTask(::TaskManager::TaskChanges taskChanges)
+{
+    // only a subset of task information is exported
+    switch (taskChanges) {
+        case TaskManager::EverythingChanged:
+            setData("name", m_task->name());
+            setData("visibleName", m_task->visibleName());
+            setData("visibleNameWithState", m_task->visibleNameWithState());
+            setData("maximized", m_task->isMaximized());
+            setData("minimized", m_task->isMinimized());
+            setData("shaded", m_task->isShaded());
+            setData("fullScreen", m_task->isFullScreen());
+            setData("alwaysOnTop", m_task->isAlwaysOnTop());
+            setData("keptBelowOthers", m_task->isKeptBelowOthers());
+            setData("active", m_task->isActive());
+            setData("onTop", m_task->isOnTop());
+            setData("onCurrentDesktop", m_task->isOnCurrentDesktop());
+            setData("onAllDesktops", m_task->isOnAllDesktops());
+            setData("desktop", m_task->desktop());
+            break;
+        case TaskManager::NameChanged:
+            setData("name", m_task->name());
+            setData("visibleName", m_task->visibleName());
+            setData("visibleNameWithState", m_task->visibleNameWithState());
+            break;
+        case TaskManager::StateChanged:
+            setData("maximized", m_task->isMaximized());
+            setData("minimized", m_task->isMinimized());
+            setData("shaded", m_task->isShaded());
+            setData("fullScreen", m_task->isFullScreen());
+            setData("alwaysOnTop", m_task->isAlwaysOnTop());
+            setData("keptBelowOthers", m_task->isKeptBelowOthers());
+            setData("active", m_task->isActive());
+            setData("onTop", m_task->isOnTop());
+            break;
+        case TaskManager::DesktopChanged:
+            setData("onCurrentDesktop", m_task->isOnCurrentDesktop());
+            setData("onAllDesktops", m_task->isOnAllDesktops());
+            setData("desktop", m_task->desktop());
+            break;
+        default:
+            break;
+    }
+    checkForUpdate();
+}
+
+void TaskSource::updateStartup()
+{
+    setData("text", m_startup->text());
+    setData("bin", m_startup->bin());
+    setData("icon", m_startup->icon());
+    checkForUpdate();
+}
+
+#include "tasksource.moc"
Index: taskservice.cpp
===================================================================
--- taskservice.cpp	(revision 0)
+++ taskservice.cpp	(revision 0)
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2008 Alain Boyer <alainboyer@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "taskservice.h"
+
+// own
+#include "taskjob.h"
+
+TaskService::TaskService(TaskSource *source) :
+    Plasma::Service(source),
+    m_source(source)
+{
+    setName("tasks");
+}
+
+TaskService::~TaskService()
+{
+}
+
+Plasma::ServiceJob *TaskService::createJob(const QString &operation, QMap<QString, \
QVariant> &parameters) +{
+    return new TaskJob(m_source, operation, parameters, this);
+}
+
+#include "taskservice.moc"
Index: tasksource.h
===================================================================
--- tasksource.h	(revision 0)
+++ tasksource.h	(revision 0)
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2008 Alain Boyer <alainboyer@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TASKSOURCE_H
+#define TASKSOURCE_H
+
+// plasma
+#include <plasma/datacontainer.h>
+
+// libtaskmanager
+#include <taskmanager/taskmanager.h>
+using TaskManager::StartupPtr;
+using TaskManager::TaskPtr;
+
+/**
+ * Task Source
+ *
+ * This custom DataContainer represents a task or startup task as a unique source.
+ * It holds a shared pointer to the task or startup task and is responsible for \
setting + * and updating the data exposed by the source.
+ */
+class TaskSource : public Plasma::DataContainer
+{
+
+    Q_OBJECT
+
+    public:
+        TaskSource(TaskPtr task, QObject *parent);
+        TaskSource(StartupPtr startup, QObject *parent);
+        ~TaskSource();
+
+    protected:
+        Plasma::Service *createService();
+        TaskPtr getTask();
+        const bool isTask();
+
+    private slots:
+        void updateTask(::TaskManager::TaskChanges taskChanges);
+        void updateStartup();
+
+    private:
+        friend class TasksEngine;
+        friend class TaskJob;
+        TaskPtr m_task;
+        StartupPtr m_startup;
+        bool m_isTask;
+
+};
+
+#endif // TASKSOURCE_H
Index: taskservice.h
===================================================================
--- taskservice.h	(revision 0)
+++ taskservice.h	(revision 0)
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2008 Alain Boyer <alainboyer@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TASKSERVICE_H
+#define TASKSERVICE_H
+
+// plasma
+#include <plasma/service.h>
+#include <plasma/servicejob.h>
+
+// own
+#include "tasksource.h"
+
+/**
+ * Task Service
+ */
+class TaskService : public Plasma::Service
+{
+
+    Q_OBJECT
+
+    public:
+        TaskService(TaskSource *source);
+        ~TaskService();
+
+    protected:
+        Plasma::ServiceJob *createJob(const QString &operation, QMap<QString, \
QVariant> &parameters); +
+    private:
+        TaskSource *m_source;
+};
+
+#endif // TASKSERVICE_H
Index: taskjob.cpp
===================================================================
--- taskjob.cpp	(revision 0)
+++ taskjob.cpp	(revision 0)
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2008 Alain Boyer <alainboyer@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "taskjob.h"
+
+TaskJob::TaskJob(TaskSource *source, const QString &operation, QMap<QString, \
QVariant> &parameters, QObject *parent) : +    ServiceJob(source->objectName(), \
operation, parameters, parent), +    m_source(source)
+{
+}
+
+TaskJob::~TaskJob()
+{
+}
+
+void TaskJob::start()
+{
+    // only a subset of task operations are exported
+    QString operation = operationName();
+    if (operation.startsWith("set")) {
+        if (operation == "setMaximized") {
+            m_source->getTask()->setMaximized(parameters().value("maximized").toBool());
 +            setResult(true);
+            return;
+        }
+        else if (operation == "setMinimized") {
+            m_source->getTask()->setIconified(parameters().value("minimized").toBool());
 +            setResult(true);
+            return;
+        }
+        else if (operation == "setShaded") {
+            m_source->getTask()->setShaded(parameters().value("shaded").toBool());
+            setResult(true);
+            return;
+        }
+        else if (operation == "setFullScreen") {
+            m_source->getTask()->setFullScreen(parameters().value("fullScreen").toBool());
 +            setResult(true);
+            return;
+        }
+        else if (operation == "setAlwaysOnTop") {
+            m_source->getTask()->setAlwaysOnTop(parameters().value("alwaysOnTop").toBool());
 +            setResult(true);
+            return;
+        }
+        else if (operation == "setKeptBelowOthers") {
+            m_source->getTask()->setKeptBelowOthers(parameters().value("keptBelowOthers").toBool());
 +            setResult(true);
+            return;
+        }
+    }
+    else if (operation.startsWith("toggle")) {
+        if (operation == "toggleMaximized") {
+            m_source->getTask()->toggleMaximized();
+            setResult(true);
+            return;
+        }
+        else if (operation == "toggleMinimized") {
+            m_source->getTask()->toggleIconified();
+            setResult(true);
+            return;
+        }
+        else if (operation == "toggleShaded") {
+            m_source->getTask()->toggleShaded();
+            setResult(true);
+            return;
+        }
+        else if (operation == "toggleFullScreen") {
+            m_source->getTask()->toggleFullScreen();
+            setResult(true);
+            return;
+        }
+        else if (operation == "toggleAlwaysOnTop") {
+            m_source->getTask()->toggleAlwaysOnTop();
+            setResult(true);
+            return;
+        }
+        else if (operation == "toggleKeptBelowOthers") {
+            m_source->getTask()->toggleKeptBelowOthers();
+            setResult(true);
+            return;
+        }
+    }
+    else {
+        if (operation == "restore") {
+            m_source->getTask()->restore();
+            setResult(true);
+            return;
+        }
+        else if (operation == "raise") {
+            m_source->getTask()->raise();
+            setResult(true);
+            return;
+        }
+        else if (operation == "lower") {
+            m_source->getTask()->lower();
+            setResult(true);
+            return;
+        }
+        else if (operation == "activate") {
+            m_source->getTask()->activate();
+            setResult(true);
+            return;
+        }
+        else if (operation == "activateRaiseOrMinimize") {
+            m_source->getTask()->activateRaiseOrIconify();
+            setResult(true);
+            return;
+        }
+        else if (operation == "toDesktop") {
+            m_source->getTask()->toDesktop(parameters().value("desktop").toInt());
+            setResult(true);
+            return;
+        }
+        else if (operation == "toCurrentDesktop") {
+            m_source->getTask()->toCurrentDesktop();
+            setResult(true);
+            return;
+        }
+    }
+    setResult(false);
+}
+
+#include "taskjob.moc"


["configxml.diff" (text/x-diff)]

Index: configxml.cpp
===================================================================
--- configxml.cpp	(revision 862967)
+++ configxml.cpp	(working copy)
@@ -545,4 +545,13 @@
     return d->groups;
 }
 
+void ConfigXml::usrWriteConfig()
+{
+    KConfigSkeletonItem::List itemList = items();
+    for(int i = 0; i < itemList.size(); i++) {
+        KConfigGroup cg(config(), itemList.at(i)->group());
+        cg.writeEntry(itemList.at(i)->key(), "");
+    }
+}
+
 } // Plasma namespace
Index: configxml.h
===================================================================
--- configxml.h	(revision 862967)
+++ configxml.h	(working copy)
@@ -130,6 +130,12 @@
      */
     QStringList groupList() const;
 
+    /**
+     * Hack used to force writing when no default exists in config file.
+     * FIXME/WARNING: This should be removed once KConfigSkeleton is fixed.
+     */
+    void usrWriteConfig();
+
 private:
     ConfigXmlPrivate * const d;
 };


_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


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

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