summaryrefslogtreecommitdiffstats
path: root/superkaramba/src/task_python.cpp
blob: e8d1d3e17f5ce61ace8b453eeafe508f8acf34bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/****************************************************************************
*  task_python.cpp  -  Functions for task python api
*
*  Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se>
*  Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org>
*  Copyright (c) 2004 Petri Damstén <damu@iki.fi>
*
*  This file is part of SuperKaramba.
*
*  SuperKaramba 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.
*
*  SuperKaramba 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 SuperKaramba; if not, write to the Free Software
*  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
****************************************************************************/

#ifdef _XOPEN_SOURCE
#undef _XOPEN_SOURCE
#endif

#include <Python.h>
#include <tqobject.h>
#include "karamba.h"
#include "meter.h"
#include "meter_python.h"
#include "task_python.h"

// This does something with a task, such as minimize or close it
int performTaskAction(long widget, long ctask, long action)
{
  karamba* currTheme = (karamba*)widget;
  Task* currTask = 0;
  Task* task;

  TaskList taskList = currTheme -> taskManager.tasks();

  for (task = taskList.first(); task; task = taskList.next())
  {
    if ((long)task == (long)ctask)
    {
      currTask = task;
    }
  }

  if (currTask != 0)
  {
    switch (action)
    {
      case 1:
        currTask->maximize();
        break;

      case 2:
        currTask->restore();
        break;

      case 3:
        currTask->iconify();
        break;

      case 4:
        currTask->close();
        break;

      case 5:
        currTask->activate();
        break;

      case 6:
        currTask->raise();
        break;

      case 7:
        currTask->lower();
        break;

      case 8:
        currTask->activateRaiseOrIconify();
        break;

      case 9:
        currTask->toggleAlwaysOnTop();
        break;

      case 10:
        currTask->toggleShaded();
        break;

      default:
        printf("You are trying to perform an invalid action in \
                performTaskAction\n");
    }
    return 1;
  }
  else
  {
    return 0;
  }
}

PyObject* py_perform_task_action(PyObject *, PyObject *args)
{
  long widget, task, action;
  if (!PyArg_ParseTuple(args, (char*)"lll:performTaskAction",
                        &widget, &task, &action))
    return NULL;
  if (!checkKaramba(widget))
    return NULL;
  return Py_BuildValue((char*)"l", performTaskAction(widget, task, action));
}

// This returns all the info about a certain task
// Return type is a Python List
PyObject* getTaskInfo(long widget, long ctask)
{
  karamba* currTheme = (karamba*)widget;
  Task* currTask = 0;
  Task* task;

  TaskList taskList = currTheme -> taskManager.tasks();

  for (task = taskList.first(); task; task = taskList.next())
  {
    if ((long)task == (long)ctask)
    {
      currTask = task;
    }

  }

  if (currTask != 0)
  {
    PyObject* pList = PyList_New(0);

    //Task Name
    if (currTask->name() != NULL)
    {
      PyList_Append(pList, PyBytes_FromString(currTask->name().latin1()));
    }
    else
    {
      PyList_Append(pList, PyBytes_FromString(""));
    }

    //Icon Name
    if (currTask->iconName() != NULL)
    {
      PyList_Append(pList, PyBytes_FromString(currTask->iconName().latin1()));
    }
    else
    {
      PyList_Append(pList, PyBytes_FromString(""));
    }

    //Class Name
    if (currTask->className() != NULL)
    {
      PyList_Append(pList, PyBytes_FromString(currTask->className().latin1()));
    }
    else
    {
      PyList_Append(pList, PyBytes_FromString(""));
    }

    // Desktop this task is on
    PyList_Append(pList, PyLong_FromLong(currTask->desktop()));

    // is it maximized?
    PyList_Append(pList, PyLong_FromLong(currTask->isMaximized()));

    // is it iconified?
    PyList_Append(pList, PyLong_FromLong(currTask->isIconified()));

    // is it shaded?
    PyList_Append(pList, PyLong_FromLong(currTask->isShaded()));

    // is it focused?
    PyList_Append(pList, PyLong_FromLong(currTask->isActive()));

    // a reference back to itself
    PyList_Append(pList, PyLong_FromLong((long)currTask));

    return pList;

  }
  else
  {
    tqWarning("Task not found.");
    return NULL;
  }
}

PyObject* py_get_task_info(PyObject *, PyObject *args)
{
  long widget, task;
  if (!PyArg_ParseTuple(args, (char*)"ll:getTaskInfo", &widget, &task))
    return NULL;
  if (!checkKaramba(widget))
    return NULL;
  return getTaskInfo(widget, task);
}

// This returns all the info about a certain startup
// Return type is a Python List
PyObject* getStartupInfo(long widget, long cstartup)
{
    karamba* currTheme = (karamba*)widget;
    Startup* currentStartup = (Startup*) cstartup;
    Startup* startup;

    StartupList startupList = currTheme -> taskManager.startups();

    for (startup = startupList.first(); startup; startup = startupList.next())
    {
        if ((long)startup == (long)cstartup)
        {
            break;
        }
    }

    startup = currentStartup;

    if (startup != 0)
    {
        PyObject* pList = PyList_New(0);

        //Startup Name
        if (startup -> text() != NULL)
        {
            PyList_Append(pList, PyBytes_FromString(startup -> text().latin1()));
        }
        else
        {
            PyList_Append(pList, PyBytes_FromString(""));
        }

        //Icon Name
        if (startup -> icon() != NULL)
        {
            PyList_Append(pList, PyBytes_FromString(startup -> icon().latin1()));
        }
        else
        {
            PyList_Append(pList, PyBytes_FromString(""));
        }

        //Executable Name
        if (startup -> bin() != NULL)
        {
            PyList_Append(pList, PyBytes_FromString(startup -> bin().latin1()));
        }
        else
        {
            PyList_Append(pList, PyBytes_FromString(""));
        }

        // a reference back to itself
        PyList_Append(pList, PyLong_FromLong((long) startup));

        return pList;

    }
    else
    {
        return NULL;
    }
}

PyObject* py_get_startup_info(PyObject*, PyObject* args)
{
  long widget, startup;
  if (!PyArg_ParseTuple(args, (char*)"ll:getStartupInfo", &widget, &startup))
    return NULL;
  if (!checkKaramba(widget))
    return NULL;
  return getStartupInfo(widget, startup);
}

// This gets a system task list
// It returns a String List of task names
PyObject* getTaskNames(long widget)
{
    karamba* currTheme = (karamba*)widget;
    PyObject* pList = PyList_New(0);
    PyObject* pString;

    TaskList taskList = currTheme -> taskManager.tasks();

    Task* task;
    for (task = taskList.first(); task; task = taskList.next())
    {
        const char* tmp = task->name().latin1();
        if(tmp == 0)
          continue;
        pString = PyBytes_FromString(tmp);
        if(pString)
          PyList_Append(pList, pString);
    }
    return pList;
}

PyObject* py_get_task_names(PyObject *, PyObject *args)
{
  long widget;
  if(!PyArg_ParseTuple(args, (char*)"l:getTaskNames", &widget))
    return NULL;
  if (!checkKaramba(widget))
    return NULL;
  return getTaskNames(widget);
}

// This gets a system task list
PyObject* getTaskList(long widget)
{
    karamba* currTheme = (karamba*)widget;
    PyObject* pList = PyList_New(0);
    PyObject* pString;

    TaskList taskList = currTheme -> taskManager.tasks();

    Task* task;
    for (task = taskList.first(); task; task = taskList.next())
    {
        pString = PyLong_FromLong((long)task);
        PyList_Append(pList, pString);
    }
    return pList;
}

PyObject* py_get_task_list(PyObject *, PyObject *args)
{
  long widget;
  if(!PyArg_ParseTuple(args, (char*)"l:getTaskList", &widget))
    return NULL;
  if (!checkKaramba(widget))
    return NULL;
  return getTaskList(widget);
}

// This gets a system startup list
PyObject* getStartupList(long widget)
{
    karamba* currTheme = (karamba*)widget;
    PyObject* pList = PyList_New(0);
    PyObject* pString;

    StartupList startupList = currTheme -> taskManager.startups();

    Startup* startup;

    for (startup = startupList.first(); startup; startup = startupList.next())
    {
        pString = PyLong_FromLong((long) startup);
        PyList_Append(pList, pString);
    }
    return pList;
}

PyObject* py_get_startup_list(PyObject *, PyObject *args)
{
  long widget;
  if(!PyArg_ParseTuple(args, (char*)"l:getStartupList", &widget))
    return NULL;
  if (!checkKaramba(widget))
    return NULL;
  return getStartupList(widget);
}