• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

superkaramba

  • sources
  • kde-4.12
  • kdeutils
  • superkaramba
  • src
  • python
task.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 * task_python.cpp - Functions for task python api
3 *
4 * Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se>
5 * Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org>
6 * Copyright (c) 2004 Petri Damstén <damu@iki.fi>
7 *
8 * This file is part of SuperKaramba.
9 *
10 * SuperKaramba is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * SuperKaramba is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with SuperKaramba; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 ****************************************************************************/
24 
25 #if defined(_XOPEN_SOURCE) && !defined(__SUNPRO_CC)
26 #undef _XOPEN_SOURCE
27 #endif
28 
29 #include "python/task.h"
30 
31 #include <Python.h>
32 #include <qobject.h>
33 #include "../karamba.h"
34 #include "taskmanager.h"
35 #include "meters/meter.h"
36 #include "python/meter.h"
37 
38 // This does something with a task, such as minimize or close it
39 int performTaskAction(long widget, long ctask, long action)
40 {
41  Q_UNUSED(widget);
42 
43  Task::TaskPtr currTask;
44  Task::TaskPtr task;
45 
46  QList<Task::TaskPtr> taskList = TaskManager::self()->tasks().values();
47 
48  foreach(task, taskList) {
49  if ((long)task.data() == (long)ctask) {
50  currTask = task;
51  }
52  }
53 
54  if (!currTask.isNull()) {
55  switch (action) {
56  case 1:
57  currTask->setMaximized(true);
58  break;
59 
60  case 2:
61  currTask->restore();
62  break;
63 
64  case 3:
65  currTask->setIconified(true);
66  break;
67 
68  case 4:
69  currTask->close();
70  break;
71 
72  case 5:
73  currTask->activate();
74  break;
75 
76  case 6:
77  currTask->raise();
78  break;
79 
80  case 7:
81  currTask->lower();
82  break;
83 
84  case 8:
85  currTask->activateRaiseOrIconify();
86  break;
87 
88  case 9:
89  currTask->toggleAlwaysOnTop();
90  break;
91 
92  case 10:
93  currTask->toggleShaded();
94  break;
95 
96  default:
97  printf("You are trying to perform an invalid action in \
98  performTaskAction\n");
99  }
100  return 1;
101  } else {
102  return 0;
103  }
104 }
105 
106 PyObject* py_perform_task_action(PyObject *, PyObject *args)
107 {
108  long widget, task, action;
109  if (!PyArg_ParseTuple(args, (char*)"lll:performTaskAction",
110  &widget, &task, &action))
111  return NULL;
112  if (!checkKaramba(widget))
113  return NULL;
114  return Py_BuildValue((char*)"l", performTaskAction(widget, task, action));
115 }
116 
117 // This returns all the info about a certain task
118 // Return type is a Python List
119 PyObject* getTaskInfo(long widget, long ctask)
120 {
121  Q_UNUSED(widget);
122 
123  Task::TaskPtr currTask;
124  Task::TaskPtr task;
125 
126  QList<Task::TaskPtr> taskList = TaskManager::self()->tasks().values();
127 
128  foreach(task, taskList) {
129  if ((long)task.data() == (long)ctask) {
130  currTask = task;
131  }
132 
133  }
134 
135  if (!currTask.isNull()) {
136  PyObject* pList = PyList_New(0);
137 
138  //Task Name
139  if (currTask->name() != NULL) {
140  PyList_Append(pList, PyString_FromString(currTask->name().toLatin1().constData()));
141  } else {
142  PyList_Append(pList, PyString_FromString(""));
143  }
144 
145  //Icon Name
146  if (currTask->info().iconName() != NULL) {
147  PyList_Append(pList, PyString_FromString(
148  currTask->info().iconName().toLatin1().constData()));
149  } else {
150  PyList_Append(pList, PyString_FromString(""));
151  }
152 
153  //Class Name
154  if (currTask->className() != NULL) {
155  PyList_Append(pList, PyString_FromString(currTask->className().toLatin1().constData()));
156  } else {
157  PyList_Append(pList, PyString_FromString(""));
158  }
159 
160  // Desktop this task is on
161  PyList_Append(pList, PyInt_FromLong(currTask->desktop()));
162 
163  // is it maximized?
164  PyList_Append(pList, PyInt_FromLong(currTask->isMaximized()));
165 
166  // is it iconified?
167  PyList_Append(pList, PyInt_FromLong(currTask->isIconified()));
168 
169  // is it shaded?
170  PyList_Append(pList, PyInt_FromLong(currTask->isShaded()));
171 
172  // is it focused?
173  PyList_Append(pList, PyInt_FromLong(currTask->isActive()));
174 
175  // a reference back to itself
176  PyList_Append(pList, PyInt_FromLong((long)currTask));
177 
178  return pList;
179 
180  } else {
181  qWarning("Task not found.");
182  return NULL;
183  }
184 }
185 
186 PyObject* py_get_task_info(PyObject *, PyObject *args)
187 {
188  long widget, task;
189  if (!PyArg_ParseTuple(args, (char*)"ll:getTaskInfo", &widget, &task))
190  return NULL;
191  if (!checkKaramba(widget))
192  return NULL;
193  return getTaskInfo(widget, task);
194 }
195 
196 // This returns all the info about a certain startup
197 // Return type is a Python List
198 PyObject* getStartupInfo(long widget, long cstartup)
199 {
200  Q_UNUSED(widget);
201 
202  Startup::StartupPtr currentStartup;
203  Startup::StartupPtr startup;
204 
205  Startup::List startupList = TaskManager::self()->startups();
206  foreach(currentStartup, startupList) {
207  if ((long)currentStartup.data() == (long)cstartup) {
208  startup = currentStartup;
209  break;
210  }
211  }
212 
213  if (!startup.isNull()) {
214  PyObject* pList = PyList_New(0);
215 
216  //Startup Name
217  if (startup -> text() != NULL) {
218  PyList_Append(pList, PyString_FromString(startup -> text().toLatin1().constData()));
219  } else {
220  PyList_Append(pList, PyString_FromString(""));
221  }
222 
223  //Icon Name
224  if (startup -> icon() != NULL) {
225  PyList_Append(pList, PyString_FromString(startup -> icon().toLatin1().constData()));
226  } else {
227  PyList_Append(pList, PyString_FromString(""));
228  }
229 
230  //Executable Name
231  if (startup -> bin() != NULL) {
232  PyList_Append(pList, PyString_FromString(startup -> bin().toLatin1().constData()));
233  } else {
234  PyList_Append(pList, PyString_FromString(""));
235  }
236 
237  // a reference back to itself
238  PyList_Append(pList, PyInt_FromLong((long) startup));
239 
240  return pList;
241 
242  } else {
243  return NULL;
244  }
245 }
246 
247 PyObject* py_get_startup_info(PyObject*, PyObject* args)
248 {
249  long widget, startup;
250  if (!PyArg_ParseTuple(args, (char*)"ll:getStartupInfo", &widget, &startup))
251  return NULL;
252  if (!checkKaramba(widget))
253  return NULL;
254  return getStartupInfo(widget, startup);
255 }
256 
257 // This gets a system task list
258 // It returns a String List of task names
259 PyObject* getTaskNames(long widget)
260 {
261  Q_UNUSED(widget);
262 
263  PyObject* pList = PyList_New(0);
264  PyObject* pString;
265 
266  QList<Task::TaskPtr> taskList = TaskManager::self()->tasks().values();
267 
268  Task::TaskPtr task;
269  foreach(task, taskList) {
270  const char* tmp = task.data()->name().toLatin1().constData();
271  if (tmp == 0)
272  continue;
273 
274  pString = PyString_FromString(tmp);
275  if (pString)
276  PyList_Append(pList, pString);
277  }
278  return pList;
279 }
280 
281 PyObject* py_get_task_names(PyObject *, PyObject *args)
282 {
283  long widget;
284  if (!PyArg_ParseTuple(args, (char*)"l:getTaskNames", &widget))
285  return NULL;
286  if (!checkKaramba(widget))
287  return NULL;
288  return getTaskNames(widget);
289 }
290 
291 // This gets a system task list
292 PyObject* getTaskList(long widget)
293 {
294  Q_UNUSED(widget);
295 
296  PyObject* pList = PyList_New(0);
297  PyObject* pString;
298 
299  QList<Task::TaskPtr> taskList = TaskManager::self()->tasks().values();
300 
301  Task::TaskPtr task;
302  foreach(task, taskList) {
303  pString = PyInt_FromLong((long)task.data());
304  PyList_Append(pList, pString);
305  }
306  return pList;
307 }
308 
309 PyObject* py_get_task_list(PyObject *, PyObject *args)
310 {
311  long widget;
312  if (!PyArg_ParseTuple(args, (char*)"l:getTaskList", &widget))
313  return NULL;
314  if (!checkKaramba(widget))
315  return NULL;
316  return getTaskList(widget);
317 }
318 
319 // This gets a system startup list
320 PyObject* getStartupList(long widget)
321 {
322  Q_UNUSED(widget);
323 
324  PyObject* pList = PyList_New(0);
325  PyObject* pString;
326 
327  Startup::List startupList = TaskManager::self()->startups();
328 
329  Startup::StartupPtr startup;
330  foreach(startup, startupList) {
331  pString = PyInt_FromLong((long) startup.data());
332  PyList_Append(pList, pString);
333  }
334  return pList;
335 }
336 
337 PyObject* py_get_startup_list(PyObject *, PyObject *args)
338 {
339  long widget;
340  if (!PyArg_ParseTuple(args, (char*)"l:getStartupList", &widget))
341  return NULL;
342  if (!checkKaramba(widget))
343  return NULL;
344  return getStartupList(widget);
345 }
PyObject
struct _object PyObject
Definition: python/karamba.h:35
performTaskAction
int performTaskAction(long widget, long ctask, long action)
Definition: task.cpp:39
meter.h
meter.h
py_get_startup_list
PyObject * py_get_startup_list(PyObject *, PyObject *args)
Task/getStartupList.
Definition: task.cpp:337
taskmanager.h
py_get_startup_info
PyObject * py_get_startup_info(PyObject *, PyObject *args)
Task/getStartupInfo.
Definition: task.cpp:247
Startup::StartupPtr
KSharedPtr< Startup > StartupPtr
Definition: taskmanager.h:555
py_perform_task_action
PyObject * py_perform_task_action(PyObject *, PyObject *args)
Task/performTaskAction.
Definition: task.cpp:106
getTaskInfo
PyObject * getTaskInfo(long widget, long ctask)
Definition: task.cpp:119
py_get_task_names
PyObject * py_get_task_names(PyObject *, PyObject *args)
Task/getTaskNames.
Definition: task.cpp:281
TaskManager::tasks
Task::Dict tasks() const
Returns a list of all current tasks.
Definition: taskmanager.h:636
checkKaramba
bool checkKaramba(long widget)
Definition: python/meter.cpp:26
TaskManager::startups
Startup::List startups() const
Returns a list of all current startups.
Definition: taskmanager.h:644
getStartupInfo
PyObject * getStartupInfo(long widget, long cstartup)
Definition: task.cpp:198
py_get_task_list
PyObject * py_get_task_list(PyObject *, PyObject *args)
Task/getTaskList.
Definition: task.cpp:309
py_get_task_info
PyObject * py_get_task_info(PyObject *, PyObject *args)
Task/getTaskInfo.
Definition: task.cpp:186
TaskManager::self
static TaskManager * self()
Definition: taskmanager.cpp:49
task.h
getStartupList
PyObject * getStartupList(long widget)
Definition: task.cpp:320
getTaskNames
PyObject * getTaskNames(long widget)
Definition: task.cpp:259
Startup::List
QVector< Startup::StartupPtr > List
Definition: taskmanager.h:556
Task::TaskPtr
KSharedPtr< Task > TaskPtr
Definition: taskmanager.h:97
getTaskList
PyObject * getTaskList(long widget)
Definition: task.cpp:292
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:07:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal