• 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
misc.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 * misc_python.cpp - Misc Functions for 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 * Copyright (C) 2004, 2005 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
8 *
9 * This file is part of SuperKaramba.
10 *
11 * SuperKaramba is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * SuperKaramba is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with SuperKaramba; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 ****************************************************************************/
25 
26 #if defined(_XOPEN_SOURCE) && !defined(__SUNPRO_CC)
27 #undef _XOPEN_SOURCE
28 #endif
29 
30 #include "python/misc.h"
31 
32 #include <Python.h>
33 
34 #include <QObject>
35 #include <QList>
36 
37 #include <kglobal.h>
38 #include <klocale.h>
39 #include <kservice.h>
40 #include <krun.h>
41 #include <kdebug.h>
42 
43 #include "meters/meter.h"
44 #include "meters/imagelabel.h"
45 #include "meters/textlabel.h"
46 #include "meters/clickarea.h"
47 
48 #include "python/meter.h"
49 
50 #include "showdesktop.h"
51 #include "karambaapp.h"
52 #include "themefile.h"
53 #include "themelocale.h"
54 #include "../karamba.h"
55 #include "../systemtray.h"
56 
57 /* now a method we need to expose to Python */
58 long acceptDrops(long widget)
59 {
60  Karamba* currTheme = (Karamba*)widget;
61 
62  currTheme->setAcceptDrops(true);
63 
64  return 1;
65 }
66 
67 PyObject* py_accept_drops(PyObject *, PyObject *args)
68 {
69  long widget;
70 
71  if (!PyArg_ParseTuple(args, (char*)"l", &widget))
72  return NULL;
73  if (!checkKaramba(widget))
74  return NULL;
75  return Py_BuildValue((char*)"l", acceptDrops(widget));
76 }
77 
78 // Runs a command, returns 0 if it could not start command
79 PyObject* py_run_command(PyObject*, PyObject* args)
80 {
81  char* name;
82  char* command;
83  char* icon;
84  PyObject *lst;
85  if (!PyArg_ParseTuple(args, (char*)"sssO:run", &name, &command, &icon, &lst) ||
86  lst == NULL || !PyList_Check(lst))
87  return NULL;
88 
89  QString n;
90  QString c;
91  QString i;
92 
93  n = QString::fromAscii(name);
94  c = QString::fromAscii(command);
95  i = QString::fromAscii(icon);
96 
97  KService svc(n, c, i);
98  KUrl::List l;
99 
100  for (int i = 0; i < PyList_Size(lst); i++) {
101  l.append(PyString2QString(PyList_GetItem(lst, i)));
102  }
103  KRun::run(svc, l, 0);
104  return Py_BuildValue("l", 1);
105 }
106 
107 // Runs a command, returns 0 if it could not start command
108 PyObject* py_execute_command(PyObject *, PyObject* args)
109 {
110  PyObject* s;
111 
112  if (!PyArg_ParseTuple(args, (char*)"O:execute", &s))
113  return NULL;
114  return Py_BuildValue((char*)"l", KRun::runCommand(PyString2QString(s),0L));
115 }
116 
117 // Runs a command, returns 0 if it could not start command
118 PyObject* py_execute_command_interactive(PyObject *, PyObject* args)
119 {
120  long widget;
121  //if (!PyArg_ParseTuple(args, (char*)"ls", &widget, &command))
122  // return NULL;
123 
124  int numLines; /* how many lines we passed for parsing */
125  QString line; /* pointer to the line as a string */
126 
127  PyObject * listObj; /* the list of strings */
128  PyObject * strObj; /* one string in the list */
129 
130  /* the O! parses for a Python object (listObj) checked
131  to be of type PyList_Type */
132  if (! PyArg_ParseTuple(args, (char*)"lO!", &widget, &PyList_Type, &listObj))
133  return NULL;
134  if (!checkKaramba(widget))
135  return NULL;
136 
137  Karamba* currTheme = (Karamba*)widget;
138 
139  K3Process *currProcess = new K3Process;
140  currTheme->setProcess(currProcess);
141 
142  /* get the number of lines passed to us */
143  numLines = PyList_Size(listObj);
144 
145  /* should raise an error here. */
146  if (numLines < 0) return NULL; /* Not a list */
147 
148  /* iterate over items of the list, grabbing strings, and parsing
149  for numbers */
150  for (int i = 0; i < numLines; i++) {
151 
152  /* grab the string object from the next element of the list */
153  strObj = PyList_GetItem(listObj, i); /* Can't fail */
154 
155  /* make it a string */
156  line = PyString2QString(strObj);
157 
158  /* now do the parsing */
159  *(currProcess) << line;
160 
161  }
162  QApplication::connect(currProcess,
163  SIGNAL(processExited(K3Process*)),
164  currTheme,
165  SLOT(processExited(K3Process*)));
166  QApplication::connect(currProcess,
167  SIGNAL(receivedStdout(K3Process*,char*,int)),
168  currTheme,
169  SLOT(receivedStdout(K3Process*,char*,int)));
170  currProcess->start(K3Process::NotifyOnExit, K3Process::Stdout);
171 
172  return Py_BuildValue((char*)"l", (int)(currProcess->pid()));
173 }
174 
175 long attachClickArea(long widget, long meter, QString LeftButton, QString MiddleButton, QString RightButton)
176 {
177  Q_UNUSED(widget);
178 
179  Meter* currMeter = (Meter*) meter;
180 
181  // if currMeter is of type ImageLabel*
182  if (ImageLabel* image = dynamic_cast<ImageLabel*>(currMeter)) {
183  image->attachClickArea(LeftButton, MiddleButton, RightButton);
184  image->allowClick(true);
185  }
186  // else if currMeter is of type TextLabel*
187  else if (TextLabel* text = dynamic_cast<TextLabel*>(currMeter)) {
188  text->attachClickArea(LeftButton, MiddleButton, RightButton);
189  text->allowClick(true);
190  } else {
191  //The given meter does not support attached clickAreas.
192  qWarning("The given meter is not of type image or text");
193  return 0;
194  }
195  return 1;
196 }
197 
198 PyObject* py_attach_clickArea(PyObject*, PyObject* args, PyObject* dict)
199 {
200  long widget;
201  long meter;
202  char* LeftButton = NULL;
203  char* MiddleButton = NULL;
204  char* RightButton = NULL;
205  const char* const mouseButtons[] = {"Widget", "Meter", "LeftButton", "MiddleButton",
206  "RightButton", NULL
207  };
208  if (!PyArg_ParseTupleAndKeywords(args, dict, (char*)"ll|sss:attachClickArea",
209  (char**)mouseButtons, &widget, &meter, &LeftButton, &MiddleButton, &RightButton))
210  return NULL;
211  if (!checkKaramba(widget))
212  return NULL;
213  QString lB, mB, rB;
214  if (LeftButton != NULL) {
215  lB = QString::fromAscii(LeftButton);
216  } else {
217  lB = QString::fromAscii("");
218  }
219  if (MiddleButton != NULL) {
220  mB = QString::fromAscii(MiddleButton);
221  } else {
222  mB = QString::fromAscii("");
223  }
224  if (RightButton != NULL) {
225  rB = QString::fromAscii(RightButton);
226  } else {
227  rB = QString::fromAscii("");
228  }
229  return Py_BuildValue((char*)"l", attachClickArea(widget, meter, lB, mB, rB));
230 }
231 
232 /* now a method we need to expose to Python */
233 long toggleShowDesktop(long)
234 {
235  ShowDesktop *s = ShowDesktop::self();
236  s->toggle();
237  return 1;
238 }
239 
240 PyObject* py_toggle_show_desktop(PyObject *, PyObject *args)
241 {
242  long widget;
243  if (!PyArg_ParseTuple(args, (char*)"l:toggleShowDesktop", &widget))
244  return NULL;
245  if (!checkKaramba(widget))
246  return NULL;
247  return Py_BuildValue((char*)"l", toggleShowDesktop(widget));
248 }
249 
250 /* now a method we need to expose to Python */
251 const char* getPrettyName(long widget)
252 {
253  Karamba* currTheme = (Karamba*)widget;
254 
255  return currTheme->prettyName().toAscii().constData();
256 }
257 
258 PyObject* py_get_pretty_name(PyObject *, PyObject *args)
259 {
260  long widget;
261  if (!PyArg_ParseTuple(args, (char*)"l:getPrettyThemeName", &widget))
262  return NULL;
263  return Py_BuildValue((char*)"s", getPrettyName(widget));
264 }
265 
266 /* now a method we need to expose to Python */
267 const char* getThemePath(long widget)
268 {
269  Karamba* currTheme = (Karamba*)widget;
270  return currTheme->theme().path().toAscii().constData();
271 }
272 
273 PyObject* py_get_theme_path(PyObject *, PyObject *args)
274 {
275  long widget;
276  if (!PyArg_ParseTuple(args, (char*)"l:getThemePath", &widget))
277  return NULL;
278  if (!checkKaramba(widget))
279  return NULL;
280  return Py_BuildValue((char*)"s", getThemePath(widget));
281 }
282 
283 PyObject* py_language(PyObject *, PyObject *args)
284 {
285  long widget;
286  if (!PyArg_ParseTuple(args, (char*)"l:language", &widget))
287  return NULL;
288  if (!checkKaramba(widget))
289  return NULL;
290  return Py_BuildValue((char*)"s",
291  ((Karamba*)widget)->theme().locale()->language().toAscii().constData());
292 }
293 
294 PyObject* py_userLanguage(PyObject *, PyObject *args)
295 {
296  long widget;
297  if (!PyArg_ParseTuple(args, (char*)"l:language", &widget))
298  return NULL;
299  if (!checkKaramba(widget))
300  return NULL;
301  return Py_BuildValue((char*)"s", KGlobal::locale()->language().toAscii().constData());
302 }
303 
304 PyObject* py_userLanguages(PyObject *, PyObject *args)
305 {
306  long widget;
307  if (!PyArg_ParseTuple(args, (char*)"l:language", &widget))
308  return NULL;
309  if (!checkKaramba(widget))
310  return NULL;
311 
312  unsigned int noOfLangs = KGlobal::locale()->languageList().count();
313 
314  PyObject *list, *item;
315  list = PyList_New(noOfLangs);
316 
317  for (unsigned int i = 0; i < noOfLangs; i++) {
318  item = Py_BuildValue((char*)"s", KGlobal::locale()->languageList()[i].toAscii().constData());
319  PyList_SetItem(list, i, item);
320  }
321 
322  return list;
323 }
324 
325 PyObject* py_read_theme_file(PyObject *, PyObject *args)
326 {
327  long widget;
328  char *file;
329  if (!PyArg_ParseTuple(args, (char*)"ls:readThemeFile", &widget, &file))
330  return NULL;
331  if (!checkKaramba(widget))
332  return NULL;
333  Karamba* k = (Karamba*)widget;
334  QByteArray ba = k->theme().readThemeFile(file);
335  return PyString_FromStringAndSize(ba.data(), ba.size());
336 }
337 
338 /* now a method we need to expose to Python */
339 long removeClickArea(long widget, long click)
340 {
341  Karamba* currTheme = (Karamba*) widget;
342  ClickArea* currMeter = (ClickArea*) click;
343 
344  if (currTheme->removeMeter(currMeter))
345  currMeter = 0; // deleted
346  return (long)currMeter;
347 }
348 
349 /* now a method we need to expose to Python */
350 long createServiceClickArea(long widget, long x, long y, long w, long h, char *name, char* exec, char *icon)
351 {
352  Karamba* currTheme = (Karamba*)widget;
353  ClickArea *tmp = new ClickArea(currTheme, false, x, y, w, h);
354  QString n;
355  QString e;
356  QString i;
357 
358  n = QString::fromAscii(name);
359  e = QString::fromAscii(exec);
360  i = QString::fromAscii(icon);
361 
362  tmp->setServiceOnClick(n, e, i);
363 
364  return (long)tmp;
365 }
366 
367 long createClickArea(long widget, long x, long y, long w, long h, char* text)
368 {
369  Karamba* currTheme = (Karamba*)widget;
370  ClickArea *tmp = new ClickArea(currTheme, false, x, y, w, h);
371  QString onclick;
372 
373  onclick = QString::fromAscii(text);
374 
375  tmp->setOnClick(onclick);
376 
377  return (long)tmp;
378 }
379 
380 PyObject* py_remove_click_area(PyObject *, PyObject *args)
381 {
382  long widget, click;
383  if (!PyArg_ParseTuple(args, (char*)"ll:removeClickArea", &widget, &click))
384  return NULL;
385  return Py_BuildValue((char*)"l", removeClickArea(widget, click));
386 }
387 
388 PyObject* py_create_service_click_area(PyObject *, PyObject *args)
389 {
390  long widget, x, y, w, h;
391  char *name;
392  char *exec;
393  char *icon;
394  if (!PyArg_ParseTuple(args, (char*)"lllllsss:createServiceClickArea", &widget, &x, &y,
395  &w, &h, &name, &exec, &icon))
396  return NULL;
397  return Py_BuildValue((char*)"l", createServiceClickArea(widget, x, y, w, h, name, exec, icon));
398 }
399 
400 PyObject* py_create_click_area(PyObject *, PyObject *args)
401 {
402  long widget, x, y, w, h;
403  char *text;
404  if (!PyArg_ParseTuple(args, (char*)"llllls:createClickArea", &widget, &x, &y,
405  &w, &h, &text))
406  return NULL;
407  if (!checkKaramba(widget))
408  return NULL;
409  return Py_BuildValue((char*)"l", createClickArea(widget, x, y, w, h, text));
410 }
411 
412 static long callTheme(long widget, char* path, char *str)
413 {
414 
415  Karamba* currTheme = (Karamba*) widget;
416  if (currTheme)
417  currTheme->sendDataToTheme(QString(path), QString(str));
418 
419  return (long)currTheme;
420 }
421 
422 static long setIncomingData(long widget, char* path, char *obj)
423 {
424  Karamba* currTheme = (Karamba*) widget;
425  if (currTheme)
426  currTheme->sendData(QString(path), QString(obj));
427 
428  return (long)currTheme;
429 }
430 
431 static QString getIncomingData(long widget)
432 {
433  Karamba* currTheme = (Karamba*) widget;
434 
435  if (currTheme)
436  return currTheme->retrieveReceivedData();
437 
438  return QString("");
439 }
440 
441 /*
442  * openNamedTheme. this function checks to see whether the theme
443  * being opened is unique or not (against all running Karamba widgets).
444  * this is important, as loading themes with the same name causes
445  * grief.
446  */
447 long openNamedTheme(char* path, char *name, bool is_sub_theme)
448 {
449  Q_UNUSED(name)
450  QString filename;
451  Karamba* newTheme = 0;
452 
453  filename = QString::fromAscii(path);
454 
455  QFileInfo file(filename);
456 
457  if (file.exists()) {
458 /* QString prettyName(name);
459  KarambaApplication* app = (KarambaApplication*)qApp;
460  if (!app->themeExists(prettyName)) {*/
461  newTheme = new Karamba(KUrl(filename), 0, -1, is_sub_theme);
462 
463  newTheme->show();
464 // }
465  }
466  return (long)newTheme;
467 }
468 
469 /* now a method we need to expose to Python */
470 long openTheme(char* path)
471 {
472 
473  QString filename;
474  Karamba* newTheme = 0;
475 
476  filename = QString::fromAscii(path);
477 
478  QFileInfo file(filename);
479 
480  if (file.exists()) {
481  newTheme = new Karamba(KUrl(filename));
482  newTheme->show();
483  }
484 
485  return (long)newTheme;
486 }
487 
488 PyObject* py_get_incoming_data(PyObject *, PyObject *args)
489 {
490  long widget;
491  if (!PyArg_ParseTuple(args, (char*)"l:getIncomingData", &widget))
492  return NULL;
493  return Py_BuildValue((char*)"O", QString2PyString(getIncomingData(widget)));
494 }
495 
496 PyObject* py_set_incoming_data(PyObject *, PyObject *args)
497 {
498  char *themePath;
499  long widget;
500  char *obj;
501  if (!PyArg_ParseTuple(args, (char*)"lss:setIncomingData", &widget, &themePath, &obj))
502  return NULL;
503  return Py_BuildValue((char*)"l", setIncomingData(widget, themePath, obj));
504 }
505 
506 PyObject* py_call_theme(PyObject *, PyObject *args)
507 {
508  char *themePath;
509  char *str;
510  long widget;
511  if (!PyArg_ParseTuple(args, (char*)"lss:callTheme", &widget, &themePath, &str))
512  return NULL;
513  return Py_BuildValue((char*)"l", callTheme(widget, themePath, str));
514 }
515 
516 PyObject* py_open_named_theme(PyObject *, PyObject *args)
517 {
518  char *themePath;
519  char *themeName;
520  long is_sub_theme;
521  if (!PyArg_ParseTuple(args, (char*)"ssl:openNamedTheme", &themePath, &themeName, &is_sub_theme))
522  return NULL;
523  return Py_BuildValue((char*)"l", openNamedTheme(themePath, themeName, is_sub_theme ? true : false));
524 }
525 
526 PyObject* py_open_theme(PyObject *, PyObject *args)
527 {
528  char *themePath;
529  if (!PyArg_ParseTuple(args, (char*)"s:openTheme", &themePath))
530  return NULL;
531  return Py_BuildValue((char*)"l", openTheme(themePath));
532 }
533 
534 PyObject* py_reload_theme(PyObject *, PyObject *args)
535 {
536  long widget;
537  if (!PyArg_ParseTuple(args, (char*)"l:reloadTheme", &widget))
538  return NULL;
539  if (!checkKaramba(widget))
540  return NULL;
541  ((Karamba*)widget)->reloadConfig();
542  return Py_BuildValue((char*)"l", 1);
543 }
544 
545 /* now a method we need to expose to Python */
546 int getNumberOfDesktops(long widget)
547 {
548  Karamba* currTheme = (Karamba*)widget;
549 
550  return currTheme->getNumberOfDesktops();
551 }
552 
553 PyObject* py_get_number_of_desktops(PyObject *, PyObject *args)
554 {
555  long widget;
556  if (!PyArg_ParseTuple(args, (char*)"l:getNumberOfDesktops", &widget))
557  return NULL;
558  if (!checkKaramba(widget))
559  return NULL;
560  return Py_BuildValue((char*)"l", getNumberOfDesktops(widget));
561 }
562 
563 /* now a method we need to expose to Python */
564 int translateAll(long widget, int x, int y)
565 {
566  Q_UNUSED(widget);
567  Q_UNUSED(x);
568  Q_UNUSED(y);
569  /*
570  Karamba* currTheme = (Karamba*)widget;
571  QList <QGraphicsItem*> items = ((QGraphicsItemGroup*)currTheme)->children();
572 
573  QGraphicsItem *meter;
574  foreach(meter, items) {
575  ((Meter*) meter)->setSize(((Meter*) meter)->getX() + x,
576  ((Meter*) meter)->getY() + y,
577  ((Meter*) meter)->getWidth(),
578  ((Meter*) meter)->getHeight());
579  }
580  if (currTheme->systray != 0) {
581  currTheme->systray->move(currTheme->systray->x() + x,
582  currTheme->systray->y() + y);
583  }
584  */
585  return 0;
586 }
587 
588 PyObject* py_translate_all(PyObject *, PyObject *args)
589 {
590  long widget;
591  int x, y;
592  if (!PyArg_ParseTuple(args, (char*)"lii:translateAll", &widget, &x, &y))
593  return NULL;
594  if (!checkKaramba(widget))
595  return NULL;
596  return Py_BuildValue((char*)"lii", translateAll(widget, x, y));
597 }
598 
599 /* now a method we need to expose to Python */
600 int show(long widget)
601 {
602  Karamba* currTheme = (Karamba*)widget;
603  currTheme->show();
604  return 0;
605 }
606 
607 PyObject* py_show(PyObject *, PyObject *args)
608 {
609  long widget;
610  if (!PyArg_ParseTuple(args, (char*)"l:show", &widget))
611  return NULL;
612  if (!checkKaramba(widget))
613  return NULL;
614  return Py_BuildValue((char*)"l", show(widget));
615 }
616 
617 /* now a method we need to expose to Python */
618 int hide(long widget)
619 {
620  Karamba* currTheme = (Karamba*)widget;
621  currTheme->hide();
622  return 0;
623 }
624 
625 PyObject* py_hide(PyObject *, PyObject *args)
626 {
627  long widget;
628  if (!PyArg_ParseTuple(args, (char*)"l:hide", &widget))
629  return NULL;
630  if (!checkKaramba(widget))
631  return NULL;
632  return Py_BuildValue((char*)"l", hide(widget));
633 }
634 
635 /*Putting includes here to show the dependency for the call(s) below (if we ever decide to move the networking callbacks into a separate file*/
636 #include <sys/socket.h>
637 #include <sys/ioctl.h>
638 #include <net/if.h>
639 #include <arpa/inet.h>
640 #if defined(__FreeBSD__) || defined(__DragonFly__)
641 #include <netinet/in.h>
642 #endif
643 #ifdef __OpenBSD__
644 #include <sys/types.h>
645 #include <netinet/in.h>
646 #endif
647 #if defined(Q_OS_SOLARIS)
648 #include <sys/sockio.h>
649 #endif
650 /* now a method we need to expose to Python */
651 QString getIp(char *device_name)
652 {
653  int i, sd, numdevs;
654  struct ifconf ifc_conf;
655  char ifc_conf_buf[sizeof(struct ifreq) * 32];
656  struct ifreq *devptr;
657  int ifc_conf_buf_size;
658  static struct in_addr host;
659  QString retval;
660 
661  retval = "Disconnected";
662 
663  /*
664  * Open a socket, any type will do so we choose UDP, and ask it with
665  * an ioctl call what devices are behind it.
666  */
667  if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
668  qWarning("Error: Unable to create socket (socket)");
669  return "Error";
670  }
671 
672  /*
673  * Fill the buffer with our static buffer, probably big enough, and get
674  * the interface configuration.
675  */
676  ifc_conf_buf_size = sizeof ifc_conf_buf;
677  ifc_conf.ifc_len = ifc_conf_buf_size;
678  ifc_conf.ifc_buf = ifc_conf_buf;
679  if (ioctl(sd, SIOCGIFCONF, &ifc_conf) < 0) {
680  qWarning("Error: Unable to get network interface conf (ioctl)");
681  close(sd);
682  return "Error";
683  }
684 
685  /*
686  * An array of devices were returned. Which ones are up right now and
687  * have broadcast capability?
688  */
689  numdevs = ifc_conf.ifc_len / sizeof(struct ifreq);
690  //qDebug("numdevs = %d", numdevs);
691  for (i = 0; i < numdevs; i++) {
692  //qDebug("iterations: %d", i);
693  /* devptr points into an array of ifreq structs. */
694  devptr = &ifc_conf.ifc_req[i];
695 
696  if (ioctl(sd, SIOCGIFADDR, devptr) < 0 || devptr->ifr_addr.sa_family != AF_INET)
697  continue;
698 
699  if (ioctl(sd, SIOCGIFFLAGS, devptr) < 0) {
700  qWarning("Error: Unable to get device interface flags (ioctl).");
701  close(sd);
702  return "Error";
703  }
704 
705  //We generally don't want probing of the loopback devices
706  if ((devptr->ifr_flags & IFF_LOOPBACK) != 0)
707  continue;
708 
709  if ((devptr->ifr_flags & IFF_UP) == 0)
710  continue;
711 
712  if ((devptr->ifr_flags & IFF_BROADCAST) == 0)
713  continue;
714 
715  /* Get the broadcast address. */
716  if (ioctl(sd, SIOCGIFFLAGS, devptr) < 0) {
717  qWarning("Error: Unable to get device interface flags (ioctl).");
718  close(sd);
719  return "Error";
720  } else {
721  if (!strcmp((char*)devptr->ifr_name, device_name)) {
722  host.s_addr = ((struct sockaddr_in*) & devptr->ifr_addr)->sin_addr.s_addr;
723  retval = inet_ntoa(host);
724  break;
725  }
726  }
727  }
728  close(sd);
729  return retval;
730 }
731 
732 PyObject* py_set_update_time(PyObject *, PyObject *args)
733 {
734  long widget;
735  double time;
736  if (!PyArg_ParseTuple(args, (char*)"ld:setUpdateTime", &widget, &time))
737  return NULL;
738  Karamba* currTheme = (Karamba*)widget;
739  currTheme->setUpdateTime(time);
740  return Py_BuildValue((char*)"l", 1);
741 }
742 
743 PyObject* py_get_update_time(PyObject *, PyObject *args)
744 {
745  long widget;
746  double time;
747  if (!PyArg_ParseTuple(args, (char*)"l:getUpdateTime", &widget, &time))
748  return NULL;
749  Karamba* currTheme = (Karamba*)widget;
750  return Py_BuildValue((char*)"d", currTheme->getUpdateTime());
751 }
752 
753 PyObject* py_get_ip(PyObject *, PyObject *args)
754 {
755  long widget;
756  char *interface;
757  if (!PyArg_ParseTuple(args, (char*)"ls:getIp", &widget, &interface))
758  return NULL;
759  if (!checkKaramba(widget))
760  return NULL;
761  return Py_BuildValue((char*)"O", QString2PyString(getIp(interface)));
762 }
763 
764 static void management_popup(long widget)
765 {
766  Karamba* currTheme = (Karamba*)widget;
767  currTheme->popupGlobalMenu();
768 }
769 
770 PyObject* py_management_popup(PyObject *, PyObject *args)
771 {
772  long widget;
773  if (!PyArg_ParseTuple(args, (char*)"l:managementPopup", &widget))
774  return NULL;
775  if (!checkKaramba(widget))
776  return NULL;
777  management_popup(widget);
778  return Py_BuildValue((char*)"l", 1);
779 }
780 
781 static void set_want_right_button(long widget, long yesno)
782 {
783  Karamba* currTheme = (Karamba*)widget;
784  currTheme->setWantRightButton(yesno);
785 }
786 
787 PyObject* py_want_right_button(PyObject *, PyObject *args)
788 {
789  long widget, i;
790  if (!PyArg_ParseTuple(args, (char*)"ll:wantRightButton", &widget, &i))
791  return NULL;
792  if (!checkKaramba(widget))
793  return NULL;
794  set_want_right_button(widget, i);
795  return Py_BuildValue((char*)"l", 1);
796 }
797 
798 
799 static void changeInterval(long widget, long interval)
800 {
801  Karamba* currTheme = (Karamba*)widget;
802  currTheme->changeInterval(interval);
803 }
804 
805 PyObject* py_change_interval(PyObject *, PyObject *args)
806 {
807  long widget, i;
808  if (!PyArg_ParseTuple(args, (char*)"ll:changeInterval", &widget, &i))
809  return NULL;
810  if (!checkKaramba(widget))
811  return NULL;
812  changeInterval(widget, i);
813  return Py_BuildValue((char*)"l", 1);
814 }
815 
816 
ShowDesktop::toggle
void toggle()
Definition: showdesktop.h:47
py_reload_theme
PyObject * py_reload_theme(PyObject *, PyObject *args)
Misc/reloadTheme.
Definition: misc.cpp:534
PyObject
struct _object PyObject
Definition: python/karamba.h:35
callTheme
static long callTheme(long widget, char *path, char *str)
Definition: misc.cpp:412
ShowDesktop::self
static ShowDesktop * self()
Definition: showdesktop.cpp:28
py_execute_command_interactive
PyObject * py_execute_command_interactive(PyObject *, PyObject *args)
Misc/executeInteractive.
Definition: misc.cpp:118
misc.h
These are global functions that are used to interpret certain Python calls.
hide
int hide(long widget)
Definition: misc.cpp:618
TextLabel
Definition: meters/textlabel.h:19
py_open_theme
PyObject * py_open_theme(PyObject *, PyObject *args)
Misc/openTheme.
Definition: misc.cpp:526
PyString2QString
QString PyString2QString(PyObject *text)
Definition: python/meter.cpp:92
createServiceClickArea
long createServiceClickArea(long widget, long x, long y, long w, long h, char *name, char *exec, char *icon)
Definition: misc.cpp:350
py_userLanguages
PyObject * py_userLanguages(PyObject *, PyObject *args)
Misc/userLanguages.
Definition: misc.cpp:304
Karamba::popupGlobalMenu
void popupGlobalMenu() const
Definition: karamba.cpp:1677
py_userLanguage
PyObject * py_userLanguage(PyObject *, PyObject *args)
Misc/language.
Definition: misc.cpp:294
meter.h
Karamba::prettyName
QString prettyName() const
Definition: karamba.cpp:511
management_popup
static void management_popup(long widget)
Definition: misc.cpp:764
py_set_update_time
PyObject * py_set_update_time(PyObject *, PyObject *args)
Misc/setUpdateTime.
Definition: misc.cpp:732
meter.h
imagelabel.h
openNamedTheme
long openNamedTheme(char *path, char *name, bool is_sub_theme)
Definition: misc.cpp:447
themelocale.h
py_hide
PyObject * py_hide(PyObject *, PyObject *args)
Misc/hide.
Definition: misc.cpp:625
py_management_popup
PyObject * py_management_popup(PyObject *, PyObject *args)
Misc/managementPopup.
Definition: misc.cpp:770
createClickArea
long createClickArea(long widget, long x, long y, long w, long h, char *text)
Definition: misc.cpp:367
py_get_number_of_desktops
PyObject * py_get_number_of_desktops(PyObject *, PyObject *args)
Misc/getNumberOfDesktop.
Definition: misc.cpp:553
getIp
QString getIp(char *device_name)
Definition: misc.cpp:651
py_accept_drops
PyObject * py_accept_drops(PyObject *, PyObject *args)
Misc/acceptDrops.
Definition: misc.cpp:67
openTheme
long openTheme(char *path)
Definition: misc.cpp:470
py_get_theme_path
PyObject * py_get_theme_path(PyObject *, PyObject *args)
Misc/getThemePath.
Definition: misc.cpp:273
Karamba::theme
const ThemeFile & theme() const
Definition: karamba.cpp:2071
py_translate_all
PyObject * py_translate_all(PyObject *, PyObject *args)
Misc/translateAll.
Definition: misc.cpp:588
ClickArea::setOnClick
void setOnClick(const QString &)
Definition: clickarea.cpp:58
Karamba::setProcess
void setProcess(K3Process *process)
Definition: karamba.cpp:2229
py_language
PyObject * py_language(PyObject *, PyObject *args)
Misc/language.
Definition: misc.cpp:283
py_get_pretty_name
PyObject * py_get_pretty_name(PyObject *, PyObject *args)
Misc/getPrettyName.
Definition: misc.cpp:258
QString2PyString
PyObject * QString2PyString(QString string)
Definition: python/meter.cpp:111
Karamba
Definition: karamba.h:52
toggleShowDesktop
long toggleShowDesktop(long)
Definition: misc.cpp:233
acceptDrops
long acceptDrops(long widget)
Definition: misc.cpp:58
Karamba::changeInterval
void changeInterval(u_int newInterval)
Definition: karamba.cpp:2032
Karamba::setWantRightButton
void setWantRightButton(bool enable)
Definition: karamba.cpp:1885
Karamba::retrieveReceivedData
QString retrieveReceivedData() const
Definition: karamba.cpp:2207
textlabel.h
themefile.h
py_toggle_show_desktop
PyObject * py_toggle_show_desktop(PyObject *, PyObject *args)
Misc/toggleShowDesktop.
Definition: misc.cpp:240
py_change_interval
PyObject * py_change_interval(PyObject *, PyObject *args)
Misc/changeInterval.
Definition: misc.cpp:805
py_get_incoming_data
PyObject * py_get_incoming_data(PyObject *, PyObject *args)
Misc/getIncomingData.
Definition: misc.cpp:488
Karamba::getNumberOfDesktops
int getNumberOfDesktops() const
Definition: karamba.cpp:2027
getThemePath
const char * getThemePath(long widget)
Definition: misc.cpp:267
py_create_click_area
PyObject * py_create_click_area(PyObject *, PyObject *args)
Misc/createClickArea.
Definition: misc.cpp:400
py_run_command
PyObject * py_run_command(PyObject *, PyObject *args)
Misc/run.
Definition: misc.cpp:79
getPrettyName
const char * getPrettyName(long widget)
Definition: misc.cpp:251
py_set_incoming_data
PyObject * py_set_incoming_data(PyObject *, PyObject *args)
Misc/setIncomingData.
Definition: misc.cpp:496
py_execute_command
PyObject * py_execute_command(PyObject *, PyObject *args)
Misc/execute.
Definition: misc.cpp:108
py_get_ip
PyObject * py_get_ip(PyObject *, PyObject *args)
Misc/getIp.
Definition: misc.cpp:753
getIncomingData
static QString getIncomingData(long widget)
Definition: misc.cpp:431
checkKaramba
bool checkKaramba(long widget)
Definition: python/meter.cpp:26
py_attach_clickArea
PyObject * py_attach_clickArea(PyObject *, PyObject *args, PyObject *dict)
Misc/attachClickArea.
Definition: misc.cpp:198
set_want_right_button
static void set_want_right_button(long widget, long yesno)
Definition: misc.cpp:781
Karamba::getUpdateTime
double getUpdateTime() const
Definition: karamba.cpp:2037
py_show
PyObject * py_show(PyObject *, PyObject *args)
Misc/show.
Definition: misc.cpp:607
py_call_theme
PyObject * py_call_theme(PyObject *, PyObject *args)
Misc/callTheme.
Definition: misc.cpp:506
ClickArea
Hans Karlsson.
Definition: clickarea.h:36
ShowDesktop
Singleton class that handles desktop access (minimizing all windows)
Definition: showdesktop.h:34
Karamba::setUpdateTime
void setUpdateTime(double newTime)
Definition: karamba.cpp:2042
changeInterval
static void changeInterval(long widget, long interval)
Definition: misc.cpp:799
py_remove_click_area
PyObject * py_remove_click_area(PyObject *, PyObject *args)
Misc/removeClickArea.
Definition: misc.cpp:380
removeClickArea
long removeClickArea(long widget, long click)
Definition: misc.cpp:339
attachClickArea
long attachClickArea(long widget, long meter, QString LeftButton, QString MiddleButton, QString RightButton)
Definition: misc.cpp:175
clickarea.h
ThemeFile::path
const QString & path() const
Definition: themefile.cpp:571
Meter
Definition: meters/meter.h:23
Karamba::removeMeter
bool removeMeter(Meter *meter)
Definition: karamba.cpp:1053
py_want_right_button
PyObject * py_want_right_button(PyObject *, PyObject *args)
Misc/wantRightButton.
Definition: misc.cpp:787
setIncomingData
static long setIncomingData(long widget, char *path, char *obj)
Definition: misc.cpp:422
py_create_service_click_area
PyObject * py_create_service_click_area(PyObject *, PyObject *args)
Misc/createServiceClickArea.
Definition: misc.cpp:388
karambaapp.h
getNumberOfDesktops
int getNumberOfDesktops(long widget)
Definition: misc.cpp:546
py_get_update_time
PyObject * py_get_update_time(PyObject *, PyObject *args)
Misc/getUpdateTime.
Definition: misc.cpp:743
ThemeFile::readThemeFile
QByteArray readThemeFile(const QString &filename) const
Definition: themefile.cpp:443
showdesktop.h
Karamba::sendDataToTheme
bool sendDataToTheme(const QString &prettyThemeName, const QString &data)
Definition: karamba.cpp:2195
translateAll
int translateAll(long widget, int x, int y)
Definition: misc.cpp:564
py_open_named_theme
PyObject * py_open_named_theme(PyObject *, PyObject *args)
Misc/openNamedTheme.
Definition: misc.cpp:516
Karamba::sendData
bool sendData(const QString &prettyThemeName, const QString &data)
Definition: karamba.cpp:2212
ClickArea::setServiceOnClick
void setServiceOnClick(const QString &, const QString &, const QString &)
Definition: clickarea.cpp:63
py_read_theme_file
PyObject * py_read_theme_file(PyObject *, PyObject *args)
Misc/readThemeFile.
Definition: misc.cpp:325
ImageLabel
Definition: meters/imagelabel.h:108
show
int show(long widget)
Definition: misc.cpp:600
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