misc_python.cpp

00001 /****************************************************************************
00002 *  misc_python.cpp  -  Misc Functions for python api
00003 *
00004 *  Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se>
00005 *  Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org>
00006 *  Copyright (C) 2004 Petri Damst� <damu@iki.fi>
00007 *  Copyright (C) 2004, 2005 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
00008 *
00009 *  This file is part of SuperKaramba.
00010 *
00011 *  SuperKaramba is free software; you can redistribute it and/or modify
00012 *  it under the terms of the GNU General Public License as published by
00013 *  the Free Software Foundation; either version 2 of the License, or
00014 *  (at your option) any later version.
00015 *
00016 *  SuperKaramba is distributed in the hope that it will be useful,
00017 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 *  GNU General Public License for more details.
00020 *
00021 *  You should have received a copy of the GNU General Public License
00022 *  along with SuperKaramba; if not, write to the Free Software
00023 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00024 ****************************************************************************/
00025 
00026 #ifdef _XOPEN_SOURCE
00027 #undef _XOPEN_SOURCE
00028 #endif
00029 
00030 #include <Python.h>
00031 #include <qglobal.h>
00032 #include <qobject.h>
00033 
00034 #include <kglobal.h>
00035 #include <klocale.h>
00036 
00037 #include "kdebug.h"
00038 #include "karamba.h"
00039 #include "karambaapp.h"
00040 #include "themefile.h"
00041 #include "themelocale.h"
00042 #include "meter.h"
00043 #include "meter_python.h"
00044 #include "misc_python.h"
00045 
00046 /* now a method we need to expose to Python */
00047 long acceptDrops(long widget)
00048 {
00049   karamba* currTheme = (karamba*)widget;
00050 
00051   currTheme->setAcceptDrops(true);
00052 
00053   return 1;
00054 }
00055 
00056 PyObject* py_accept_drops(PyObject *, PyObject *args)
00057 {
00058   long widget;
00059 
00060   if (!PyArg_ParseTuple(args, (char*)"l", &widget))
00061     return NULL;
00062   if (!checkKaramba(widget))
00063     return NULL;
00064   return Py_BuildValue((char*)"l", acceptDrops(widget));
00065 }
00066 
00067 // Runs a command, returns 0 if it could not start command
00068 PyObject* py_run_command(PyObject*, PyObject* args)
00069 {
00070   char* name;
00071   char* command;
00072   char* icon;
00073   PyObject *lst;
00074   if (!PyArg_ParseTuple(args, (char*)"sssO:run", &name, &command, &icon, &lst) ||
00075       lst == NULL || !PyList_Check(lst))
00076       return NULL;
00077 
00078   QString n;
00079   QString c;
00080   QString i;
00081 
00082   n.setAscii(name);
00083   c.setAscii(command);
00084   i.setAscii(icon);
00085 
00086   KService svc(n, c, i);
00087   KURL::List l;
00088 
00089   for (int i = 0; i < PyList_Size(lst); i++)
00090   {
00091     l.append(PyString2QString(PyList_GetItem(lst, i)));
00092   }
00093   KRun::run(svc, l);
00094   return Py_BuildValue("l", 1);
00095 }
00096 
00097 // Runs a command, returns 0 if it could not start command
00098 PyObject* py_execute_command(PyObject *, PyObject* args)
00099 {
00100   PyObject* s;
00101 
00102   if (!PyArg_ParseTuple(args, (char*)"O:execute", &s))
00103       return NULL;
00104   return Py_BuildValue((char*)"l", KRun::runCommand(PyString2QString(s)));
00105 }
00106 
00107 // Runs a command, returns 0 if it could not start command
00108 PyObject* py_execute_command_interactive(PyObject *, PyObject* args)
00109 {
00110   long widget;
00111   //if (!PyArg_ParseTuple(args, (char*)"ls", &widget, &command))
00112   //  return NULL;
00113 
00114   int numLines;       /* how many lines we passed for parsing */
00115   QString line;       /* pointer to the line as a string */
00116 
00117   PyObject * listObj; /* the list of strings */
00118   PyObject * strObj;  /* one string in the list */
00119 
00120   /* the O! parses for a Python object (listObj) checked
00121      to be of type PyList_Type */
00122   if (! PyArg_ParseTuple(args, (char*)"lO!", &widget, &PyList_Type, &listObj))
00123     return NULL;
00124   if (!checkKaramba(widget))
00125     return NULL;
00126 
00127   karamba* currTheme = (karamba*)widget;
00128 
00129   currTheme->currProcess = new KProcess;
00130 
00131   /* get the number of lines passed to us */
00132   numLines = PyList_Size(listObj);
00133 
00134   /* should raise an error here. */
00135   if (numLines < 0) return NULL; /* Not a list */
00136 
00137   /* iterate over items of the list, grabbing strings, and parsing
00138      for numbers */
00139   for (int i=0; i<numLines; i++){
00140 
00141     /* grab the string object from the next element of the list */
00142     strObj = PyList_GetItem(listObj, i); /* Can't fail */
00143 
00144     /* make it a string */
00145     line = PyString2QString(strObj);
00146 
00147     /* now do the parsing */
00148     *(currTheme->currProcess) << line;
00149 
00150   }
00151   QApplication::connect(currTheme->currProcess,
00152                         SIGNAL(processExited(KProcess *)),
00153                         currTheme,
00154                         SLOT(processExited(KProcess *)));
00155   QApplication::connect(currTheme->currProcess,
00156                         SIGNAL(receivedStdout(KProcess *, char *, int)),
00157                         currTheme,
00158                         SLOT(receivedStdout(KProcess *, char *, int)));
00159   currTheme->currProcess->start(KProcess::NotifyOnExit, KProcess::Stdout);
00160 
00161   return Py_BuildValue((char*)"l", (int)(currTheme->currProcess->pid()));
00162 }
00163 
00164 long attachClickArea(long widget, long meter, QString LeftButton, QString MiddleButton, QString RightButton)
00165 {
00166   karamba* currTheme = (karamba*) widget;
00167   Meter* currMeter = (Meter*) meter;
00168 
00169   // Look if currMeter has an ClickArea attached.
00170   bool meterAlreadyClickable = currTheme->clickList->containsRef(currMeter);
00171 
00172   // if currMeter is of type ImageLabel*
00173   if (ImageLabel* image = dynamic_cast<ImageLabel*>(currMeter))
00174   {
00175       image -> attachClickArea(LeftButton, MiddleButton, RightButton);
00176       if (!meterAlreadyClickable)
00177       {
00178           //qWarning("attachClickArea : meter is image");
00179           currTheme -> clickList -> append(image);
00180       }
00181   }
00182   // else if currMeter is of type TextLabel*
00183   else if (TextLabel* text = dynamic_cast<TextLabel*>(currMeter))
00184   {
00185       text -> attachClickArea(LeftButton, MiddleButton, RightButton);
00186       if (!meterAlreadyClickable)
00187       {
00188           //qWarning("attachClickArea : meter is text");
00189           currTheme -> clickList -> append(text);
00190       }
00191   }
00192   else
00193   {
00194       //The given meter does not support attached clickAreas.
00195       qWarning("The given meter is not of type image or text");
00196       return 0;
00197   }
00198   return 1;
00199 }
00200 
00201 PyObject* py_attach_clickArea(PyObject*, PyObject* args, PyObject* dict)
00202 {
00203   long widget;
00204   long meter;
00205   char* LeftButton = NULL;
00206   char* MiddleButton = NULL;
00207   char* RightButton = NULL;
00208   const char* mouseButtons[] = {"Widget", "Meter", "LeftButton", "MiddleButton",
00209                                 "RightButton", NULL};
00210   if (!PyArg_ParseTupleAndKeywords(args, dict, (char*)"ll|sss:attachClickArea",
00211    (char**)mouseButtons, &widget, &meter, &LeftButton, &MiddleButton, &RightButton))
00212     return NULL;
00213   if (!checkKaramba(widget))
00214     return NULL;
00215   QString lB, mB, rB;
00216   if (LeftButton != NULL)
00217   {
00218       lB.setAscii(LeftButton);
00219   }
00220   else
00221   {
00222       lB.setAscii("");
00223   }
00224   if (MiddleButton != NULL)
00225   {
00226       mB.setAscii(MiddleButton);
00227   }
00228   else
00229   {
00230       mB.setAscii("");
00231   }
00232   if (RightButton != NULL)
00233   {
00234        rB.setAscii(RightButton);
00235   }
00236   else
00237   {
00238        rB.setAscii("");
00239   }
00240   return Py_BuildValue((char*)"l", attachClickArea(widget, meter, lB, mB, rB));
00241 }
00242 
00243 /* now a method we need to expose to Python */
00244 long toggleShowDesktop(long)
00245 {
00246   ShowDesktop *s = ShowDesktop::the();
00247   s->toggle();
00248   return 1;
00249 }
00250 
00251 PyObject* py_toggle_show_desktop(PyObject *, PyObject *args)
00252 {
00253   long widget;
00254   if (!PyArg_ParseTuple(args, (char*)"l:toggleShowDesktop", &widget))
00255     return NULL;
00256   if (!checkKaramba(widget))
00257     return NULL;
00258   return Py_BuildValue((char*)"l", toggleShowDesktop(widget));
00259 }
00260 
00261 /* now a method we need to expose to Python */
00262 const char* getPrettyName(long widget) {
00263   karamba* currTheme = (karamba*)widget;
00264 
00265   return currTheme->prettyName.ascii();
00266 }
00267 
00268 PyObject* py_get_pretty_name(PyObject *, PyObject *args)
00269 {
00270   long widget;
00271   if (!PyArg_ParseTuple(args, (char*)"l:getPrettyThemeName", &widget))
00272     return NULL;
00273   return Py_BuildValue((char*)"s", getPrettyName(widget));
00274 }
00275 
00276 /* now a method we need to expose to Python */
00277 const char* getThemePath(long widget) {
00278   karamba* currTheme = (karamba*)widget;
00279 
00280   return currTheme->theme().path().ascii();
00281 }
00282 
00283 PyObject* py_get_theme_path(PyObject *, PyObject *args)
00284 {
00285   long widget;
00286   if (!PyArg_ParseTuple(args, (char*)"l:getThemePath", &widget))
00287     return NULL;
00288   if (!checkKaramba(widget))
00289     return NULL;
00290   return Py_BuildValue((char*)"s", getThemePath(widget));
00291 }
00292 
00293 PyObject* py_language(PyObject *, PyObject *args)
00294 {
00295   long widget;
00296   if (!PyArg_ParseTuple(args, (char*)"l:language", &widget))
00297     return NULL;
00298   if (!checkKaramba(widget))
00299     return NULL;
00300   return Py_BuildValue((char*)"s",
00301       ((karamba*)widget)->theme().locale()->language().ascii());
00302 }
00303 
00304 PyObject* py_userLanguage(PyObject *, PyObject *args)
00305 {
00306   long widget;
00307   if (!PyArg_ParseTuple(args, (char*)"l:language", &widget))
00308     return NULL;
00309   if (!checkKaramba(widget))
00310     return NULL;
00311   return Py_BuildValue((char*)"s", KGlobal::locale()->language().ascii());
00312 }
00313 
00314 PyObject* py_read_theme_file(PyObject *, PyObject *args)
00315 {
00316   long widget;
00317   char *file;
00318   if (!PyArg_ParseTuple(args, (char*)"ls:readThemeFile", &widget, &file))
00319     return NULL;
00320   if (!checkKaramba(widget))
00321     return NULL;
00322   karamba* k = (karamba*)widget;
00323   QByteArray ba = k->theme().readThemeFile(file);
00324   return PyString_FromStringAndSize(ba.data(), ba.size());
00325 }
00326 
00327 /* now a method we need to expose to Python */
00328 long removeClickArea(long widget, long click) {
00329 
00330   karamba* currTheme = (karamba*)widget;
00331   ClickArea *tmp = (ClickArea*)click;
00332 
00333   currTheme -> clickList -> remove(tmp);
00334 
00335   delete tmp;
00336   return (long)tmp;
00337 }
00338 
00339 /* now a method we need to expose to Python */
00340 long createServiceClickArea(long widget, long x, long y, long w, long h, char *name, char* exec, char *icon) {
00341 
00342   karamba* currTheme = (karamba*)widget;
00343   ClickArea *tmp = new ClickArea( currTheme, x, y, w, h );
00344   QString n;
00345   QString e;
00346   QString i;
00347 
00348   n.setAscii(name);
00349   e.setAscii(exec);
00350   i.setAscii(icon);
00351 
00352   tmp->setServiceOnClick(n, e, i);
00353 
00354   currTheme -> clickList -> append(tmp);
00355   return (long)tmp;
00356 }
00357 
00358 long createClickArea(long widget, long x, long y, long w, long h, char* text) {
00359 
00360   karamba* currTheme = (karamba*)widget;
00361   ClickArea *tmp = new ClickArea(currTheme, x, y, w, h );
00362   QString onclick;
00363 
00364   onclick.setAscii(text);
00365 
00366   tmp->setOnClick(onclick );
00367 
00368   currTheme -> clickList -> append(tmp);
00369   return (long)tmp;
00370 }
00371 
00372 PyObject* py_remove_click_area(PyObject *, PyObject *args)
00373 {
00374   long widget, click;
00375   if (!PyArg_ParseTuple(args, (char*)"ll:removeClickArea", &widget, &click))
00376     return NULL;
00377   return Py_BuildValue((char*)"l", removeClickArea(widget, click));
00378 }
00379 
00380 PyObject* py_create_service_click_area(PyObject *, PyObject *args)
00381 {
00382   long widget, x, y, w, h;
00383   char *name;
00384   char *exec;
00385   char *icon;
00386   if (!PyArg_ParseTuple(args, (char*)"lllllsss:createServiceClickArea", &widget, &x, &y,
00387                         &w, &h, &name, &exec, &icon))
00388     return NULL;
00389   return Py_BuildValue((char*)"l", createServiceClickArea(widget, x, y, w, h, name, exec, icon));
00390 }
00391 
00392 PyObject* py_create_click_area(PyObject *, PyObject *args)
00393 {
00394   long widget, x, y, w, h;
00395   char *text;
00396   if (!PyArg_ParseTuple(args, (char*)"llllls:createClickArea", &widget, &x, &y,
00397                         &w, &h, &text))
00398     return NULL;
00399   if (!checkKaramba(widget))
00400     return NULL;
00401   return Py_BuildValue((char*)"l", createClickArea(widget, x, y, w, h, text));
00402 }
00403 
00404 static long callTheme(long widget, char* path, char *str)
00405 {
00406   karamba* currTheme = (karamba*) widget;
00407 
00408   if (currTheme)
00409     currTheme->callTheme(QString(path), QString(str));
00410 
00411   return (long)currTheme;
00412 }
00413 
00414 static long setIncomingData(long widget, char* path, char *obj)
00415 {
00416   karamba* currTheme = (karamba*) widget;
00417 
00418   if (currTheme)
00419     currTheme->setIncomingData(QString(path), QString(obj));
00420 
00421   return (long)currTheme;
00422 }
00423 
00424 static QString getIncomingData(long widget)
00425 {
00426   karamba* currTheme = (karamba*) widget;
00427 
00428   if (currTheme)
00429     return currTheme->getIncomingData();
00430 
00431   return QString("");
00432 }
00433 
00434 /*
00435  * openNamedTheme.  this function checks to see whether the theme
00436  * being opened is unique or not (against all running karamba widgets).
00437  * this is important, as loading themes with the same name causes
00438  * grief.
00439  */
00440 long openNamedTheme(char* path, char *name, bool is_sub_theme) {
00441 
00442   QString filename;
00443   karamba* currTheme = 0;
00444 
00445   filename.setAscii(path);
00446 
00447   QFileInfo file( filename );
00448 
00449   if( file.exists() )
00450   {
00451       QCString prettyName(name);
00452       KarambaApplication* app = (KarambaApplication*)qApp;
00453       if (!app->themeExists(prettyName))
00454       {
00455         currTheme = new karamba( filename, prettyName, false ,
00456                    -1, is_sub_theme);
00457       currTheme->show();
00458     }
00459   }
00460   return (long)currTheme;
00461 }
00462 
00463 /* now a method we need to expose to Python */
00464 long openTheme(char* path)
00465 {
00466 
00467   QString filename;
00468   karamba* currTheme = 0;
00469 
00470   filename.setAscii(path);
00471 
00472   QFileInfo file( filename );
00473 
00474   if( file.exists() )
00475     {
00476       currTheme = new karamba( filename, QString() );
00477       currTheme->show();
00478     }
00479 
00480   return (long)currTheme;
00481 }
00482 
00483 PyObject* py_get_incoming_data(PyObject *, PyObject *args)
00484 {
00485   long widget;
00486   if (!PyArg_ParseTuple(args, (char*)"l:getIncomingData", &widget))
00487     return NULL;
00488   return Py_BuildValue((char*)"O", QString2PyString(getIncomingData(widget)));
00489 }
00490 
00491 PyObject* py_set_incoming_data(PyObject *, PyObject *args)
00492 {
00493   char *themePath;
00494   long widget;
00495   char *obj;
00496   if (!PyArg_ParseTuple(args, (char*)"lss:setIncomingData", &widget, &themePath, &obj))
00497     return NULL;
00498   return Py_BuildValue((char*)"l", setIncomingData(widget, themePath, obj));
00499 }
00500 
00501 PyObject* py_call_theme(PyObject *, PyObject *args)
00502 {
00503   char *themePath;
00504   char *str;
00505   long widget;
00506   if (!PyArg_ParseTuple(args, (char*)"lss:callTheme", &widget, &themePath, &str))
00507     return NULL;
00508   return Py_BuildValue((char*)"l", callTheme(widget, themePath, str));
00509 }
00510 
00511 PyObject* py_open_named_theme(PyObject *, PyObject *args)
00512 {
00513   char *themePath;
00514   char *themeName;
00515   long is_sub_theme;
00516   if (!PyArg_ParseTuple(args, (char*)"ssl:openNamedTheme", &themePath, &themeName, &is_sub_theme))
00517     return NULL;
00518   return Py_BuildValue((char*)"l", openNamedTheme(themePath, themeName, is_sub_theme ? true : false));
00519 }
00520 
00521 PyObject* py_open_theme(PyObject *, PyObject *args)
00522 {
00523   char *themePath;
00524   if (!PyArg_ParseTuple(args, (char*)"s:openTheme", &themePath))
00525     return NULL;
00526   return Py_BuildValue((char*)"l", openTheme(themePath));
00527 }
00528 
00529 PyObject* py_reload_theme(PyObject *, PyObject *args)
00530 {
00531   long widget;
00532   if (!PyArg_ParseTuple(args, (char*)"l:reloadTheme", &widget))
00533     return NULL;
00534   if (!checkKaramba(widget))
00535     return NULL;
00536   ((karamba*)widget)->reloadConfig();
00537   return Py_BuildValue((char*)"l", 1);
00538 }
00539 
00540 /* now a method we need to expose to Python */
00541 int getNumberOfDesktops(long widget)
00542 {
00543   karamba* currTheme = (karamba*)widget;
00544 
00545   return currTheme->kWinModule->numberOfDesktops();
00546 }
00547 
00548 PyObject* py_get_number_of_desktops(PyObject *, PyObject *args)
00549 {
00550   long widget;
00551   if (!PyArg_ParseTuple(args, (char*)"l:getNumberOfDesktops", &widget))
00552     return NULL;
00553   if (!checkKaramba(widget))
00554     return NULL;
00555   return Py_BuildValue((char*)"l", getNumberOfDesktops(widget));
00556 }
00557 
00558 /* now a method we need to expose to Python */
00559 int translateAll(long widget, int x, int y)
00560 {
00561   karamba* currTheme = (karamba*)widget;
00562 
00563   QObjectListIt it2( *currTheme->meterList ); // iterate over meters
00564 
00565   while ( it2 != 0 )
00566   {
00567     ((Meter*) *it2)->setSize(((Meter*) *it2)->getX()+x,
00568                              ((Meter*) *it2)->getY()+y,
00569                              ((Meter*) *it2)->getWidth(),
00570                              ((Meter*) *it2)->getHeight());
00571     ++it2;
00572   }
00573 
00574   if (currTheme->systray != 0)
00575   {
00576     currTheme->systray->move(currTheme->systray->x()+x,
00577                              currTheme->systray->y()+y);
00578   }
00579   return 0;
00580 }
00581 
00582 PyObject* py_translate_all(PyObject *, PyObject *args)
00583 {
00584   long widget;
00585   int x, y;
00586   if (!PyArg_ParseTuple(args, (char*)"lii:translateAll", &widget, &x, &y))
00587     return NULL;
00588   if (!checkKaramba(widget))
00589     return NULL;
00590   return Py_BuildValue((char*)"lii", translateAll(widget, x, y));
00591 }
00592 
00593 /* now a method we need to expose to Python */
00594 int show(long widget)
00595 {
00596   karamba* currTheme = (karamba*)widget;
00597   currTheme->show();
00598   return 0;
00599 }
00600 
00601 PyObject* py_show(PyObject *, PyObject *args)
00602 {
00603   long widget;
00604   if (!PyArg_ParseTuple(args, (char*)"l:show", &widget))
00605     return NULL;
00606   if (!checkKaramba(widget))
00607     return NULL;
00608   return Py_BuildValue((char*)"l", show(widget));
00609 }
00610 
00611 /* now a method we need to expose to Python */
00612 int hide(long widget)
00613 {
00614   karamba* currTheme = (karamba*)widget;
00615   currTheme->hide();
00616   return 0;
00617 }
00618 
00619 PyObject* py_hide(PyObject *, PyObject *args)
00620 {
00621   long widget;
00622   if (!PyArg_ParseTuple(args, (char*)"l:hide", &widget))
00623     return NULL;
00624   if (!checkKaramba(widget))
00625     return NULL;
00626   return Py_BuildValue((char*)"l", hide(widget));
00627 }
00628 
00629 /*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*/
00630 #include <sys/socket.h>
00631 #include <sys/ioctl.h>
00632 #include <net/if.h>
00633 #include <arpa/inet.h>
00634 #ifdef __FreeBSD__
00635 #include <netinet/in.h>
00636 #endif
00637 #if defined(Q_OS_SOLARIS)
00638 #include <sys/sockio.h>
00639 #endif
00640 /* now a method we need to expose to Python */
00641 QString getIp(char *device_name)
00642 {
00643   int i, sd, numdevs;
00644   struct ifconf ifc_conf;
00645   char ifc_conf_buf[sizeof ( struct ifreq ) * 32];
00646   struct ifreq *devptr;
00647   int ifc_conf_buf_size;
00648   static struct in_addr host;
00649   QString retval;
00650 
00651   retval = "Disconnected";
00652 
00653   /*
00654    * Open a socket, any type will do so we choose UDP, and ask it with
00655    * an ioctl call what devices are behind it.
00656    */
00657   if ((sd = socket(AF_INET,SOCK_DGRAM,0)) < 0)
00658   {
00659     qWarning("Error: Unable to create socket (socket)");
00660     return "Error";
00661   }
00662 
00663   /*
00664    * Fill the buffer with our static buffer, probably big enough, and get
00665    * the interface configuration.
00666    */
00667   ifc_conf_buf_size = sizeof ifc_conf_buf;
00668   ifc_conf.ifc_len = ifc_conf_buf_size;
00669   ifc_conf.ifc_buf = ifc_conf_buf;
00670   if (ioctl(sd,SIOCGIFCONF,&ifc_conf) < 0)
00671   {
00672     qWarning("Error: Unable to get network interface conf (ioctl)");
00673     close(sd);
00674     return "Error";
00675   }
00676 
00677   /*
00678    * An array of devices were returned.  Which ones are up right now and
00679    * have broadcast capability?
00680    */
00681   numdevs = ifc_conf.ifc_len / sizeof (struct ifreq);
00682   //qDebug("numdevs = %d", numdevs);
00683   for (i = 0; i < numdevs; i++)
00684   {
00685     //qDebug("iterations: %d", i);
00686     /* devptr points into an array of ifreq structs. */
00687     devptr = &ifc_conf.ifc_req[i];
00688 
00689     if (ioctl(sd, SIOCGIFADDR, devptr) < 0 || devptr->ifr_addr.sa_family != AF_INET)
00690       continue;
00691 
00692     if (ioctl(sd,SIOCGIFFLAGS,devptr) < 0)
00693     {
00694       qWarning("Error: Unable to get device interface flags (ioctl).");
00695       close(sd);
00696       return "Error";
00697     }
00698 
00699   //We generally don't want probing of the loopback devices
00700   if ((devptr->ifr_flags & IFF_LOOPBACK) != 0)
00701    continue;
00702 
00703     if ((devptr->ifr_flags & IFF_UP) == 0)
00704     continue;
00705 
00706     if ((devptr->ifr_flags & IFF_BROADCAST) == 0)
00707     continue;
00708 
00709   /* Get the broadcast address. */
00710   if (ioctl(sd,SIOCGIFFLAGS,devptr) < 0)
00711   {
00712     qWarning("Error: Unable to get device interface flags (ioctl).");
00713     close(sd);
00714     return "Error";
00715   }
00716   else
00717   {
00718     if (!strcmp((char*)devptr->ifr_name, device_name))
00719     {
00720     host.s_addr = ((struct sockaddr_in*)&devptr->ifr_addr)->sin_addr.s_addr;
00721     retval = inet_ntoa(host);
00722     break;
00723     }
00724   }
00725   }
00726   close(sd);
00727   return retval;
00728 }
00729 
00730 PyObject* py_set_update_time(PyObject *, PyObject *args)
00731 {
00732   long widget;
00733   double time;
00734   if (!PyArg_ParseTuple(args, (char*)"ld:setUpdateTime", &widget, &time))
00735     return NULL;
00736   karamba* currTheme = (karamba*)widget;
00737   currTheme->setUpdateTime(time);
00738   return Py_BuildValue((char*)"l", 1);
00739 }
00740 
00741 PyObject* py_get_update_time(PyObject *, PyObject *args)
00742 {
00743   long widget;
00744   double time;
00745   if (!PyArg_ParseTuple(args, (char*)"l:getUpdateTime", &widget, &time))
00746     return NULL;
00747   karamba* currTheme = (karamba*)widget;
00748   return Py_BuildValue((char*)"d", currTheme->getUpdateTime());
00749 }
00750 
00751 PyObject* py_get_ip(PyObject *, PyObject *args)
00752 {
00753   long widget;
00754   char *interface;
00755   if (!PyArg_ParseTuple(args, (char*)"ls:getIp", &widget, &interface))
00756     return NULL;
00757   if (!checkKaramba(widget))
00758     return NULL;
00759   return Py_BuildValue((char*)"O", QString2PyString(getIp(interface)));
00760 }
00761 
00762 static void management_popup(long widget)
00763 {
00764   karamba* currTheme = (karamba*)widget;
00765   currTheme->management_popup();
00766 }
00767 
00768 PyObject* py_management_popup(PyObject *, PyObject *args)
00769 {
00770   long widget;
00771   if (!PyArg_ParseTuple(args, (char*)"l:managementPopup", &widget))
00772     return NULL;
00773   if (!checkKaramba(widget))
00774     return NULL;
00775   management_popup(widget);
00776   return Py_BuildValue((char*)"l", 1);
00777 }
00778 
00779 static void set_want_right_button(long widget, long yesno)
00780 {
00781   karamba* currTheme = (karamba*)widget;
00782   currTheme->setWantRightButton(yesno);
00783 }
00784 
00785 PyObject* py_want_right_button(PyObject *, PyObject *args)
00786 {
00787   long widget, i;
00788   if (!PyArg_ParseTuple(args, (char*)"ll:wantRightButton", &widget, &i))
00789     return NULL;
00790   if (!checkKaramba(widget))
00791     return NULL;
00792   set_want_right_button(widget, i);
00793   return Py_BuildValue((char*)"l", 1);
00794 }
00795 
00796 
00797 static void changeInterval(long widget, long interval)
00798 {
00799   karamba* currTheme = (karamba*)widget;
00800   currTheme->changeInterval(interval);
00801 }
00802 
00803 PyObject* py_change_interval(PyObject *, PyObject *args)
00804 {
00805   long widget, i;
00806   if (!PyArg_ParseTuple(args, (char*)"ll:changeInterval", &widget, &i))
00807     return NULL;
00808   if (!checkKaramba(widget))
00809     return NULL;
00810   changeInterval(widget, i);
00811   return Py_BuildValue((char*)"l", 1);
00812 }
00813 
00814 
KDE Home | KDE Accessibility Home | Description of Access Keys