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én <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 <tqglobal.h> 00032 #include <tqobject.h> 00033 00034 #include <tdeglobal.h> 00035 #include <tdelocale.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 TQString n; 00079 TQString c; 00080 TQString 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(PyString2TQString(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(PyString2TQString(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 TQString 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 TDEProcess; 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 = PyString2TQString(strObj); 00146 00147 /* now do the parsing */ 00148 *(currTheme->currProcess) << line; 00149 00150 } 00151 TQApplication::connect(currTheme->currProcess, 00152 TQT_SIGNAL(processExited(TDEProcess *)), 00153 currTheme, 00154 TQT_SLOT(processExited(TDEProcess *))); 00155 TQApplication::connect(currTheme->currProcess, 00156 TQT_SIGNAL(receivedStdout(TDEProcess *, char *, int)), 00157 currTheme, 00158 TQT_SLOT(receivedStdout(TDEProcess *, char *, int))); 00159 currTheme->currProcess->start(TDEProcess::NotifyOnExit, TDEProcess::Stdout); 00160 00161 return Py_BuildValue((char*)"l", (int)(currTheme->currProcess->pid())); 00162 } 00163 00164 long attachClickArea(long widget, long meter, TQString LeftButton, TQString MiddleButton, TQString 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 //tqWarning("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 //tqWarning("attachClickArea : meter is text"); 00189 currTheme -> clickList -> append(text); 00190 } 00191 } 00192 else 00193 { 00194 //The given meter does not support attached clickAreas. 00195 tqWarning("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 TQString 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", TDEGlobal::locale()->language().ascii()); 00312 } 00313 00314 PyObject* py_userLanguages(PyObject *, PyObject *args) 00315 { 00316 long widget; 00317 if (!PyArg_ParseTuple(args, (char*)"l:language", &widget)) 00318 return NULL; 00319 if (!checkKaramba(widget)) 00320 return NULL; 00321 00322 unsigned int noOfLangs = TDEGlobal::locale()->languageList().count(); 00323 00324 PyObject *list, *item; 00325 list = PyList_New(noOfLangs); 00326 00327 for(unsigned int i = 0; i < noOfLangs; i++) 00328 { 00329 item = Py_BuildValue((char*)"s", TDEGlobal::locale()->languageList()[i].ascii()); 00330 PyList_SetItem(list, i, item); 00331 } 00332 00333 return list; 00334 } 00335 00336 PyObject* py_read_theme_file(PyObject *, PyObject *args) 00337 { 00338 long widget; 00339 char *file; 00340 if (!PyArg_ParseTuple(args, (char*)"ls:readThemeFile", &widget, &file)) 00341 return NULL; 00342 if (!checkKaramba(widget)) 00343 return NULL; 00344 karamba* k = (karamba*)widget; 00345 TQByteArray ba = k->theme().readThemeFile(file); 00346 return PyBytes_FromStringAndSize(ba.data(), ba.size()); 00347 } 00348 00349 /* now a method we need to expose to Python */ 00350 long removeClickArea(long widget, long click) { 00351 00352 karamba* currTheme = (karamba*)widget; 00353 ClickArea *tmp = (ClickArea*)click; 00354 00355 currTheme -> clickList -> remove(tmp); 00356 00357 delete tmp; 00358 return (long)tmp; 00359 } 00360 00361 /* now a method we need to expose to Python */ 00362 long createServiceClickArea(long widget, long x, long y, long w, long h, char *name, char* exec, char *icon) { 00363 00364 karamba* currTheme = (karamba*)widget; 00365 ClickArea *tmp = new ClickArea( currTheme, x, y, w, h ); 00366 TQString n; 00367 TQString e; 00368 TQString i; 00369 00370 n.setAscii(name); 00371 e.setAscii(exec); 00372 i.setAscii(icon); 00373 00374 tmp->setServiceOnClick(n, e, i); 00375 00376 currTheme -> clickList -> append(tmp); 00377 return (long)tmp; 00378 } 00379 00380 long createClickArea(long widget, long x, long y, long w, long h, char* text) { 00381 00382 karamba* currTheme = (karamba*)widget; 00383 ClickArea *tmp = new ClickArea(currTheme, x, y, w, h ); 00384 TQString onclick; 00385 00386 onclick.setAscii(text); 00387 00388 tmp->setOnClick(onclick ); 00389 00390 currTheme -> clickList -> append(tmp); 00391 return (long)tmp; 00392 } 00393 00394 PyObject* py_remove_click_area(PyObject *, PyObject *args) 00395 { 00396 long widget, click; 00397 if (!PyArg_ParseTuple(args, (char*)"ll:removeClickArea", &widget, &click)) 00398 return NULL; 00399 return Py_BuildValue((char*)"l", removeClickArea(widget, click)); 00400 } 00401 00402 PyObject* py_create_service_click_area(PyObject *, PyObject *args) 00403 { 00404 long widget, x, y, w, h; 00405 char *name; 00406 char *exec; 00407 char *icon; 00408 if (!PyArg_ParseTuple(args, (char*)"lllllsss:createServiceClickArea", &widget, &x, &y, 00409 &w, &h, &name, &exec, &icon)) 00410 return NULL; 00411 return Py_BuildValue((char*)"l", createServiceClickArea(widget, x, y, w, h, name, exec, icon)); 00412 } 00413 00414 PyObject* py_create_click_area(PyObject *, PyObject *args) 00415 { 00416 long widget, x, y, w, h; 00417 char *text; 00418 if (!PyArg_ParseTuple(args, (char*)"llllls:createClickArea", &widget, &x, &y, 00419 &w, &h, &text)) 00420 return NULL; 00421 if (!checkKaramba(widget)) 00422 return NULL; 00423 return Py_BuildValue((char*)"l", createClickArea(widget, x, y, w, h, text)); 00424 } 00425 00426 static long callTheme(long widget, char* path, char *str) 00427 { 00428 karamba* currTheme = (karamba*) widget; 00429 00430 if (currTheme) 00431 currTheme->callTheme(TQString(path), TQString(str)); 00432 00433 return (long)currTheme; 00434 } 00435 00436 static long setIncomingData(long widget, char* path, char *obj) 00437 { 00438 karamba* currTheme = (karamba*) widget; 00439 00440 if (currTheme) 00441 currTheme->setIncomingData(TQString(path), TQString(obj)); 00442 00443 return (long)currTheme; 00444 } 00445 00446 static TQString getIncomingData(long widget) 00447 { 00448 karamba* currTheme = (karamba*) widget; 00449 00450 if (currTheme) 00451 return currTheme->getIncomingData(); 00452 00453 return TQString(""); 00454 } 00455 00456 /* 00457 * openNamedTheme. this function checks to see whether the theme 00458 * being opened is unique or not (against all running karamba widgets). 00459 * this is important, as loading themes with the same name causes 00460 * grief. 00461 */ 00462 long openNamedTheme(char* path, char *name, bool is_sub_theme) { 00463 00464 TQString filename; 00465 karamba* currTheme = 0; 00466 00467 filename.setAscii(path); 00468 00469 TQFileInfo file( filename ); 00470 00471 if( file.exists() ) 00472 { 00473 TQCString prettyName(name); 00474 KarambaApplication* app = (KarambaApplication*)tqApp; 00475 if (!app->themeExists(prettyName)) 00476 { 00477 currTheme = new karamba( filename, prettyName, false , 00478 -1, is_sub_theme); 00479 currTheme->show(); 00480 } 00481 } 00482 return (long)currTheme; 00483 } 00484 00485 /* now a method we need to expose to Python */ 00486 long openTheme(char* path) 00487 { 00488 00489 TQString filename; 00490 karamba* currTheme = 0; 00491 00492 filename.setAscii(path); 00493 00494 TQFileInfo file( filename ); 00495 00496 if( file.exists() ) 00497 { 00498 currTheme = new karamba( filename, TQString() ); 00499 currTheme->show(); 00500 } 00501 00502 return (long)currTheme; 00503 } 00504 00505 PyObject* py_get_incoming_data(PyObject *, PyObject *args) 00506 { 00507 long widget; 00508 if (!PyArg_ParseTuple(args, (char*)"l:getIncomingData", &widget)) 00509 return NULL; 00510 return Py_BuildValue((char*)"O", TQString2PyString(getIncomingData(widget))); 00511 } 00512 00513 PyObject* py_set_incoming_data(PyObject *, PyObject *args) 00514 { 00515 char *themePath; 00516 long widget; 00517 char *obj; 00518 if (!PyArg_ParseTuple(args, (char*)"lss:setIncomingData", &widget, &themePath, &obj)) 00519 return NULL; 00520 return Py_BuildValue((char*)"l", setIncomingData(widget, themePath, obj)); 00521 } 00522 00523 PyObject* py_call_theme(PyObject *, PyObject *args) 00524 { 00525 char *themePath; 00526 char *str; 00527 long widget; 00528 if (!PyArg_ParseTuple(args, (char*)"lss:callTheme", &widget, &themePath, &str)) 00529 return NULL; 00530 return Py_BuildValue((char*)"l", callTheme(widget, themePath, str)); 00531 } 00532 00533 PyObject* py_open_named_theme(PyObject *, PyObject *args) 00534 { 00535 char *themePath; 00536 char *themeName; 00537 long is_sub_theme; 00538 if (!PyArg_ParseTuple(args, (char*)"ssl:openNamedTheme", &themePath, &themeName, &is_sub_theme)) 00539 return NULL; 00540 return Py_BuildValue((char*)"l", openNamedTheme(themePath, themeName, is_sub_theme ? true : false)); 00541 } 00542 00543 PyObject* py_open_theme(PyObject *, PyObject *args) 00544 { 00545 char *themePath; 00546 if (!PyArg_ParseTuple(args, (char*)"s:openTheme", &themePath)) 00547 return NULL; 00548 return Py_BuildValue((char*)"l", openTheme(themePath)); 00549 } 00550 00551 PyObject* py_reload_theme(PyObject *, PyObject *args) 00552 { 00553 long widget; 00554 if (!PyArg_ParseTuple(args, (char*)"l:reloadTheme", &widget)) 00555 return NULL; 00556 if (!checkKaramba(widget)) 00557 return NULL; 00558 ((karamba*)widget)->reloadConfig(); 00559 return Py_BuildValue((char*)"l", 1); 00560 } 00561 00562 /* now a method we need to expose to Python */ 00563 int getNumberOfDesktops(long widget) 00564 { 00565 karamba* currTheme = (karamba*)widget; 00566 00567 return currTheme->kWinModule->numberOfDesktops(); 00568 } 00569 00570 PyObject* py_get_number_of_desktops(PyObject *, PyObject *args) 00571 { 00572 long widget; 00573 if (!PyArg_ParseTuple(args, (char*)"l:getNumberOfDesktops", &widget)) 00574 return NULL; 00575 if (!checkKaramba(widget)) 00576 return NULL; 00577 return Py_BuildValue((char*)"l", getNumberOfDesktops(widget)); 00578 } 00579 00580 /* now a method we need to expose to Python */ 00581 int translateAll(long widget, int x, int y) 00582 { 00583 karamba* currTheme = (karamba*)widget; 00584 00585 TQObjectListIt it2( *currTheme->meterList ); // iterate over meters 00586 00587 while ( it2 != 0 ) 00588 { 00589 ((Meter*) *it2)->setSize(((Meter*) *it2)->getX()+x, 00590 ((Meter*) *it2)->getY()+y, 00591 ((Meter*) *it2)->getWidth(), 00592 ((Meter*) *it2)->getHeight()); 00593 ++it2; 00594 } 00595 00596 if (currTheme->systray != 0) 00597 { 00598 currTheme->systray->move(currTheme->systray->x()+x, 00599 currTheme->systray->y()+y); 00600 } 00601 return 0; 00602 } 00603 00604 PyObject* py_translate_all(PyObject *, PyObject *args) 00605 { 00606 long widget; 00607 int x, y; 00608 if (!PyArg_ParseTuple(args, (char*)"lii:translateAll", &widget, &x, &y)) 00609 return NULL; 00610 if (!checkKaramba(widget)) 00611 return NULL; 00612 return Py_BuildValue((char*)"lii", translateAll(widget, x, y)); 00613 } 00614 00615 /* now a method we need to expose to Python */ 00616 int show(long widget) 00617 { 00618 karamba* currTheme = (karamba*)widget; 00619 currTheme->show(); 00620 return 0; 00621 } 00622 00623 PyObject* py_show(PyObject *, PyObject *args) 00624 { 00625 long widget; 00626 if (!PyArg_ParseTuple(args, (char*)"l:show", &widget)) 00627 return NULL; 00628 if (!checkKaramba(widget)) 00629 return NULL; 00630 return Py_BuildValue((char*)"l", show(widget)); 00631 } 00632 00633 /* now a method we need to expose to Python */ 00634 int hide(long widget) 00635 { 00636 karamba* currTheme = (karamba*)widget; 00637 currTheme->hide(); 00638 return 0; 00639 } 00640 00641 PyObject* py_hide(PyObject *, PyObject *args) 00642 { 00643 long widget; 00644 if (!PyArg_ParseTuple(args, (char*)"l:hide", &widget)) 00645 return NULL; 00646 if (!checkKaramba(widget)) 00647 return NULL; 00648 return Py_BuildValue((char*)"l", hide(widget)); 00649 } 00650 00651 /*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*/ 00652 #include <sys/socket.h> 00653 #include <sys/ioctl.h> 00654 #include <net/if.h> 00655 #include <arpa/inet.h> 00656 #if defined(__FreeBSD__) || defined(__DragonFly__) 00657 #include <netinet/in.h> 00658 #endif 00659 #if defined(Q_OS_SOLARIS) 00660 #include <sys/sockio.h> 00661 #endif 00662 /* now a method we need to expose to Python */ 00663 TQString getIp(char *device_name) 00664 { 00665 int i, sd, numdevs; 00666 struct ifconf ifc_conf; 00667 char ifc_conf_buf[sizeof ( struct ifreq ) * 32]; 00668 struct ifreq *devptr; 00669 int ifc_conf_buf_size; 00670 static struct in_addr host; 00671 TQString retval; 00672 00673 retval = "Disconnected"; 00674 00675 /* 00676 * Open a socket, any type will do so we choose UDP, and ask it with 00677 * an ioctl call what devices are behind it. 00678 */ 00679 if ((sd = socket(AF_INET,SOCK_DGRAM,0)) < 0) 00680 { 00681 tqWarning("Error: Unable to create socket (socket)"); 00682 return "Error"; 00683 } 00684 00685 /* 00686 * Fill the buffer with our static buffer, probably big enough, and get 00687 * the interface configuration. 00688 */ 00689 ifc_conf_buf_size = sizeof ifc_conf_buf; 00690 ifc_conf.ifc_len = ifc_conf_buf_size; 00691 ifc_conf.ifc_buf = ifc_conf_buf; 00692 if (ioctl(sd,SIOCGIFCONF,&ifc_conf) < 0) 00693 { 00694 tqWarning("Error: Unable to get network interface conf (ioctl)"); 00695 close(sd); 00696 return "Error"; 00697 } 00698 00699 /* 00700 * An array of devices were returned. Which ones are up right now and 00701 * have broadcast capability? 00702 */ 00703 numdevs = ifc_conf.ifc_len / sizeof (struct ifreq); 00704 //tqDebug("numdevs = %d", numdevs); 00705 for (i = 0; i < numdevs; i++) 00706 { 00707 //tqDebug("iterations: %d", i); 00708 /* devptr points into an array of ifreq structs. */ 00709 devptr = &ifc_conf.ifc_req[i]; 00710 00711 if (ioctl(sd, SIOCGIFADDR, devptr) < 0 || devptr->ifr_addr.sa_family != AF_INET) 00712 continue; 00713 00714 if (ioctl(sd,SIOCGIFFLAGS,devptr) < 0) 00715 { 00716 tqWarning("Error: Unable to get device interface flags (ioctl)."); 00717 close(sd); 00718 return "Error"; 00719 } 00720 00721 //We generally don't want probing of the loopback devices 00722 if ((devptr->ifr_flags & IFF_LOOPBACK) != 0) 00723 continue; 00724 00725 if ((devptr->ifr_flags & IFF_UP) == 0) 00726 continue; 00727 00728 if ((devptr->ifr_flags & IFF_BROADCAST) == 0) 00729 continue; 00730 00731 /* Get the broadcast address. */ 00732 if (ioctl(sd,SIOCGIFFLAGS,devptr) < 0) 00733 { 00734 tqWarning("Error: Unable to get device interface flags (ioctl)."); 00735 close(sd); 00736 return "Error"; 00737 } 00738 else 00739 { 00740 if (!strcmp((char*)devptr->ifr_name, device_name)) 00741 { 00742 host.s_addr = ((struct sockaddr_in*)&devptr->ifr_addr)->sin_addr.s_addr; 00743 retval = inet_ntoa(host); 00744 break; 00745 } 00746 } 00747 } 00748 close(sd); 00749 return retval; 00750 } 00751 00752 PyObject* py_set_update_time(PyObject *, PyObject *args) 00753 { 00754 long widget; 00755 double time; 00756 if (!PyArg_ParseTuple(args, (char*)"ld:setUpdateTime", &widget, &time)) 00757 return NULL; 00758 karamba* currTheme = (karamba*)widget; 00759 currTheme->setUpdateTime(time); 00760 return Py_BuildValue((char*)"l", 1); 00761 } 00762 00763 PyObject* py_get_update_time(PyObject *, PyObject *args) 00764 { 00765 long widget; 00766 double time; 00767 if (!PyArg_ParseTuple(args, (char*)"l:getUpdateTime", &widget, &time)) 00768 return NULL; 00769 karamba* currTheme = (karamba*)widget; 00770 return Py_BuildValue((char*)"d", currTheme->getUpdateTime()); 00771 } 00772 00773 PyObject* py_get_ip(PyObject *, PyObject *args) 00774 { 00775 long widget; 00776 char *interface; 00777 if (!PyArg_ParseTuple(args, (char*)"ls:getIp", &widget, &interface)) 00778 return NULL; 00779 if (!checkKaramba(widget)) 00780 return NULL; 00781 return Py_BuildValue((char*)"O", TQString2PyString(getIp(interface))); 00782 } 00783 00784 static void management_popup(long widget) 00785 { 00786 karamba* currTheme = (karamba*)widget; 00787 currTheme->management_popup(); 00788 } 00789 00790 PyObject* py_management_popup(PyObject *, PyObject *args) 00791 { 00792 long widget; 00793 if (!PyArg_ParseTuple(args, (char*)"l:managementPopup", &widget)) 00794 return NULL; 00795 if (!checkKaramba(widget)) 00796 return NULL; 00797 management_popup(widget); 00798 return Py_BuildValue((char*)"l", 1); 00799 } 00800 00801 static void set_want_right_button(long widget, long yesno) 00802 { 00803 karamba* currTheme = (karamba*)widget; 00804 currTheme->setWantRightButton(yesno); 00805 } 00806 00807 PyObject* py_want_right_button(PyObject *, PyObject *args) 00808 { 00809 long widget, i; 00810 if (!PyArg_ParseTuple(args, (char*)"ll:setWantRightButton", &widget, &i)) 00811 return NULL; 00812 if (!checkKaramba(widget)) 00813 return NULL; 00814 set_want_right_button(widget, i); 00815 return Py_BuildValue((char*)"l", 1); 00816 } 00817 00818 static void set_want_wheel_event(long widget, long yesno) 00819 { 00820 karamba* currTheme = (karamba*)widget; 00821 currTheme->setWantMeterWheelEvent(yesno); 00822 } 00823 00824 PyObject* py_want_wheel_event(PyObject *, PyObject *args) 00825 { 00826 long widget, i; 00827 if (!PyArg_ParseTuple(args, (char*)"ll:setWantMeterWheelEvent", &widget, &i)) 00828 return NULL; 00829 if (!checkKaramba(widget)) 00830 return NULL; 00831 set_want_wheel_event(widget, i); 00832 return Py_BuildValue((char*)"l", 1); 00833 } 00834 00835 static void changeInterval(long widget, long interval) 00836 { 00837 karamba* currTheme = (karamba*)widget; 00838 currTheme->changeInterval(interval); 00839 } 00840 00841 PyObject* py_change_interval(PyObject *, PyObject *args) 00842 { 00843 long widget, i; 00844 if (!PyArg_ParseTuple(args, (char*)"ll:changeInterval", &widget, &i)) 00845 return NULL; 00846 if (!checkKaramba(widget)) 00847 return NULL; 00848 changeInterval(widget, i); 00849 return Py_BuildValue((char*)"l", 1); 00850 } 00851 00852