00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "karamba_python.h"
00025 #include "dcopinterface_stub.h"
00026 #include "richtextlabel.h"
00027 #include "karamba.h"
00028 #include "karambaapp.h"
00029 #include "themesdlg.h"
00030 #include "lineparser.h"
00031 #include "themelocale.h"
00032 #include "superkarambasettings.h"
00033
00034 #include <kdebug.h>
00035 #include <kmessagebox.h>
00036 #include <krun.h>
00037 #include <klocale.h>
00038 #include <kwin.h>
00039 #include <kdeversion.h>
00040 #include <kdirwatch.h>
00041
00042 #include <kparts/componentfactory.h>
00043 #include <kparts/part.h>
00044
00045 #include <tqdir.h>
00046 #include <tqwidgetlist.h>
00047
00048
00049 #define EDITSCRIPT 1
00050 #define THEMECONF 2
00051
00052 karamba::karamba(TQString fn, TQString name, bool reloading, int instance,
00053 bool sub_theme):
00054 TQWidget(0,"karamba", Qt::WGroupLeader | WStyle_Customize |
00055 WRepaintNoErase| WStyle_NoBorder | WDestructiveClose ),
00056 meterList(0), imageList(0), clickList(0), kpop(0), widgetMask(0),
00057 config(0), kWinModule(0), tempUnit('C'), m_instance(instance),
00058 sensorList(0), timeList(0),
00059 themeConfMenu(0), toDesktopMenu(0), kglobal(0), clickPos(0, 0), accColl(0),
00060 menuAccColl(0), toggleLocked(0), pythonIface(0), defaultTextField(0),
00061 trayMenuSeperatorId(-1), trayMenuQuitId(-1), trayMenuToggleId(-1),
00062 trayMenuThemeId(-1),
00063 m_sysTimer(NULL)
00064 {
00065 themeStarted = false;
00066 want_right_button = false;
00067 want_meter_wheel_event = false;
00068 prettyName = name;
00069 m_sub_theme = sub_theme;
00070
00071 KURL url;
00072
00073 if(fn.find('/') == -1)
00074 url.setFileName(fn);
00075 else
00076 url = fn;
00077 if(!m_theme.set(url))
00078 {
00079 setFixedSize(0, 0);
00080 TQTimer::singleShot(100, this, TQT_SLOT(killWidget()));
00081 return;
00082 }
00083
00084
00085 karambaApp->addKaramba(this, reloading);
00086
00087 if(prettyName.isEmpty())
00088 prettyName = TQString("%1 - %2").arg(m_theme.name()).arg(m_instance);
00089
00090 kdDebug() << "Starting theme: " << m_theme.name()
00091 << " pretty name: " << prettyName << endl;
00092 TQString qName = "karamba - " + prettyName;
00093 setName(qName.ascii());
00094
00095 KDirWatch *dirWatch = KDirWatch::self();
00096 connect(dirWatch, TQT_SIGNAL( dirty( const TQString & ) ),
00097 TQT_SLOT( slotFileChanged( const TQString & ) ) );
00098
00099 if(!dirWatch->contains(m_theme.file()))
00100 dirWatch->addFile(m_theme.file());
00101
00102 if(!m_theme.isZipTheme() && m_theme.pythonModuleExists())
00103 {
00104 TQString pythonFile = m_theme.path() + "/" + m_theme.pythonModule() + ".py";
00105 if(!dirWatch->contains(pythonFile))
00106 dirWatch->addFile(pythonFile);
00107 }
00108
00109 widgetUpdate = true;
00110
00111
00112 TQString instanceString;
00113 if(m_instance > 1)
00114 instanceString = TQString("-%1").arg(m_instance);
00115 TQString cfg = TQDir::home().absPath() + "/.superkaramba/"
00116 + m_theme.id() + instanceString + ".rc";
00117 kdDebug() << cfg << endl;
00118 TQFile themeConfigFile(cfg);
00119
00120 if (!TQFileInfo(themeConfigFile).exists())
00121 {
00122
00123 themeConfigFile.open(IO_ReadWrite);
00124 themeConfigFile.close();
00125 }
00126
00127 config = new KConfig(cfg, false, false);
00128 config -> sync();
00129 config -> setGroup("internal");
00130
00131 m_reloading = reloading;
00132 if(m_theme.pythonModuleExists())
00133 {
00134 kdDebug() << "Loading python module: " << m_theme.pythonModule() << endl;
00135 TQTimer::singleShot(0, this, TQT_SLOT(initPythonInterface()));
00136 }
00137
00138 widgetMask = 0;
00139 info = new NETWinInfo( qt_xdisplay(), winId(), qt_xrootwin(), NET::WMState );
00140
00141
00142 kWinModule = new KWinModule();
00143 desktop = 0;
00144
00145 connect( kWinModule,TQT_SIGNAL(currentDesktopChanged(int)), this,
00146 TQT_SLOT(currentDesktopChanged(int)) );
00147 connect( kapp, TQT_SIGNAL(backgroundChanged(int)), this,
00148 TQT_SLOT(currentWallpaperChanged(int)));
00149
00150
00151 connect(&taskManager, TQT_SIGNAL(activeTaskChanged(Task*)), this,
00152 TQT_SLOT(activeTaskChanged(Task*)) );
00153 connect(&taskManager, TQT_SIGNAL(taskAdded(Task*)), this,
00154 TQT_SLOT(taskAdded(Task*)) );
00155 connect(&taskManager, TQT_SIGNAL(taskRemoved(Task*)), this,
00156 TQT_SLOT(taskRemoved(Task*)) );
00157 connect(&taskManager, TQT_SIGNAL(startupAdded(Startup*)), this,
00158 TQT_SLOT(startupAdded(Startup*)) );
00159 connect(&taskManager, TQT_SIGNAL(startupRemoved(Startup*)), this,
00160 TQT_SLOT(startupRemoved(Startup*)) );
00161
00162 themeConfMenu = new KPopupMenu( this);
00163 themeConfMenu -> setCheckable(true);
00164
00165
00166 DesktopChangeSlot *dslot;
00167
00168 int mid;
00169
00170 toDesktopMenu = new KPopupMenu (this);
00171 toDesktopMenu -> setCheckable(true);
00172 mid = toDesktopMenu -> insertItem (i18n("&All Desktops"),
00173 dslot = new DesktopChangeSlot(this,0),
00174 TQT_SLOT(receive()));
00175 dslot->setMenuId(mid);
00176
00177 toDesktopMenu -> insertSeparator();
00178 for (int ndesktop=1; ndesktop <= kWinModule->numberOfDesktops(); ndesktop++)
00179 {
00180 TQString name = i18n("Desktop &");
00181 name += ('0' + ndesktop);
00182
00183 mid = toDesktopMenu -> insertItem (name,
00184 dslot = new DesktopChangeSlot(this, ndesktop), TQT_SLOT(receive()));
00185 dslot->setMenuId(mid);
00186 }
00187
00188
00189 kpop = new KPopupMenu( this );
00190 kpop -> setCheckable(true);
00191
00192 accColl = new KActionCollection( this );
00193 menuAccColl = new KActionCollection( this );
00194
00195 kpop->insertItem( SmallIconSet("reload"),i18n("Update"), this,
00196 TQT_SLOT(updateSensors()), Key_F5 );
00197 toggleLocked = new KToggleAction ( i18n("Toggle &Locked Position"),
00198 SmallIconSet("locked"),
00199 CTRL+Key_L, this,
00200 TQT_SLOT( slotToggleLocked() ),
00201 accColl, "Locked position" );
00202 accColl->insert(toggleLocked);
00203 toggleLocked -> setChecked(true);
00204
00205 toggleLocked->plug(kpop);
00206
00207 toggleFastTransforms = new KToggleAction(i18n("Use &Fast Image Scaling"),
00208 CTRL+Key_F, this,
00209 TQT_SLOT( slotToggleFastTransforms() ),
00210 accColl, "Fast transformations");
00211
00212 accColl->insert(toggleFastTransforms);
00213 toggleFastTransforms -> setChecked(true);
00214
00215 toggleFastTransforms -> plug(kpop);
00216
00217 kpop->insertSeparator();
00218
00219 kpop->insertItem(i18n("Configure &Theme"), themeConfMenu, THEMECONF);
00220 kpop->setItemEnabled(THEMECONF, false);
00221 kpop->insertItem(i18n("To Des&ktop"), toDesktopMenu);
00222
00223 kpop->insertItem( SmallIconSet("reload3"),i18n("&Reload Theme"),this,
00224 TQT_SLOT(reloadConfig()), CTRL+Key_R );
00225 kpop->insertItem( SmallIconSet("fileclose"),i18n("&Close This Theme"), this,
00226 TQT_SLOT(killWidget()), CTRL+Key_C );
00227
00228 if(!SuperKarambaSettings::showSysTray())
00229 showMenuExtension();
00230
00231 kpop->polish();
00232
00233 numberOfConfMenuItems = 0;
00234
00235 systray = 0;
00236 foundKaramba = false;
00237 onTop = false;
00238 managed = false;
00239 fixedPosition = false;
00240 defaultTextField = new TextField();
00241
00242 meterList = new TQObjectList();
00243 meterList->setAutoDelete( true );
00244 sensorList = new TQObjectList();
00245 sensorList->setAutoDelete( true );
00246 clickList = new TQObjectList();
00247 timeList = new TQObjectList();
00248 imageList = new TQObjectList();
00249 menuList = new TQObjectList();
00250 menuList->setAutoDelete( true );
00251
00252 client = kapp->dcopClient();
00253 if (!client->isAttached())
00254 client->attach();
00255 appId = client->registerAs(qApp->name());
00256
00257
00258 setBackgroundMode( NoBackground);
00259 if( !(onTop || managed))
00260 KWin::lowerWindow( winId() );
00261
00262 if( !parseConfig() )
00263 {
00264 setFixedSize(0,0);
00265 TQTimer::singleShot( 100, this, TQT_SLOT(killWidget()) );
00266 qWarning("Could not read config file.");
00267 }
00268 else
00269 {
00270 kroot = new KarambaRootPixmap((TQWidget*)this);
00271 kroot->start();
00272 }
00273
00274
00275 bool locked = toggleLocked->isChecked();
00276 locked = config->readBoolEntry("lockedPosition", locked);
00277 toggleLocked->setChecked(locked);
00278 slotToggleLocked();
00279
00280 if (!config -> readBoolEntry("fastTransforms", true))
00281 {
00282 toggleFastTransforms -> setChecked(false);
00283 slotToggleFastTransforms();
00284 }
00285
00286 desktop = config -> readNumEntry("desktop", desktop);
00287 if (desktop > kWinModule->numberOfDesktops())
00288 {
00289 desktop = 0;
00290 }
00291
00292 if (desktop)
00293 {
00294 info->setDesktop( desktop );
00295 }
00296 else
00297 info->setDesktop( NETWinInfo::OnAllDesktops);
00298
00299
00300 config -> setGroup("theme");
00301 if (config -> hasKey("widgetPosX") && config -> hasKey("widgetPosY"))
00302 {
00303 int xpos = config -> readNumEntry("widgetPosX");
00304 int ypos = config -> readNumEntry("widgetPosY");
00305
00306 if (xpos < 0)
00307 xpos = 0;
00308 if (ypos < 0)
00309 ypos = 0;
00310 move(xpos, ypos);
00311 }
00312
00313 haveUpdated = 0;
00314 this->setMouseTracking(true);
00315
00316
00317 setFocusPolicy(TQWidget::StrongFocus);
00318 }
00319
00320 karamba::~karamba()
00321 {
00322
00323
00324 karambaApp->deleteKaramba(this, m_reloading);
00325
00326 widgetClosed();
00327 if(m_theme.isValid())
00328 writeConfigData();
00329
00330 delete config;
00331
00332 if(meterList != 0)
00333 {
00334 meterList->clear();
00335 delete meterList;
00336 }
00337
00338 if( sensorList != 0 )
00339 {
00340 sensorList->clear();
00341 delete sensorList;
00342 }
00343
00344 if( imageList != 0 )
00345 {
00346 imageList->clear();
00347 delete imageList;
00348 }
00349
00350 if( clickList != 0 )
00351 {
00352 clickList->clear();
00353 delete clickList;
00354 }
00355
00356 if( timeList != 0 )
00357 {
00358 timeList->clear();
00359 delete timeList;
00360 }
00361
00362 delete toggleLocked;
00363 delete accColl;
00364 delete menuAccColl;
00365 delete themeConfMenu;
00366 delete kpop;
00367 delete widgetMask;
00368 delete kWinModule;
00369 delete defaultTextField;
00370 if (pythonIface != NULL)
00371 delete pythonIface;
00372 }
00373
00374 bool karamba::parseConfig()
00375 {
00376
00377 bool passive = true;
00378
00379 if(m_theme.open())
00380 {
00381 TQValueStack<TQPoint> offsetStack;
00382 LineParser lineParser;
00383 int x=0;
00384 int y=0;
00385 int w=0;
00386 int h=0;
00387
00388 offsetStack.push(TQPoint(0,0));
00389
00390 while(m_theme.nextLine(lineParser))
00391 {
00392 x = lineParser.getInt("X") + offsetStack.top().x();
00393 y = lineParser.getInt("Y") + offsetStack.top().y();
00394 w = lineParser.getInt("W");
00395 h = lineParser.getInt("H");
00396
00397 if(lineParser.meter() == "KARAMBA" && !foundKaramba )
00398 {
00399
00400 toggleLocked->setChecked(lineParser.getBoolean("LOCKED"));
00401 slotToggleLocked();
00402
00403 x = ( x < 0 ) ? 0:x;
00404 y = ( y < 0 ) ? 0:y;
00405
00406 if( w == 0 || h == 0)
00407 {
00408 w = 300;
00409 h = 300;
00410 }
00411 setFixedSize(w,h);
00412
00413 if(lineParser.getBoolean("RIGHT"))
00414 {
00415 TQDesktopWidget *d = TQApplication::desktop();
00416 x = d->width() - w;
00417 }
00418 else if(lineParser.getBoolean("LEFT"))
00419 {
00420 x = 0;
00421 }
00422
00423 if(lineParser.getBoolean("BOTTOM"))
00424 {
00425 TQDesktopWidget *d = TQApplication::desktop();
00426 y = d->height() - h;
00427 }
00428 else if(lineParser.getBoolean("TOP"))
00429 {
00430 y = 0;
00431 }
00432
00433 move(x,y);
00434
00435
00436 if(lineParser.getBoolean("ONTOP"))
00437 {
00438 onTop = true;
00439 KWin::setState( winId(), NET::StaysOnTop );
00440 }
00441
00442 if(lineParser.getBoolean("MANAGED"))
00443 {
00444 managed = true;
00445 reparent(0, Qt::WType_Dialog | WStyle_Customize | WStyle_NormalBorder
00446 | WRepaintNoErase | WDestructiveClose, pos());
00447 }
00448 else
00449 {
00450 info->setState( NETWinInfo::SkipTaskbar
00451 | NETWinInfo::SkipPager,NETWinInfo::SkipTaskbar
00452 | NETWinInfo::SkipPager );
00453 if (onTop)
00454 {
00455 KWin::setState( winId(), NET::StaysOnTop );
00456
00457 }
00458 }
00459
00460 if (lineParser.getBoolean("ONALLDESKTOPS"))
00461 {
00462 desktop = 200;
00463 }
00464
00465
00466 bool dfound=false;
00467
00468 if (dfound)
00469 {
00470 info->setDesktop( dfound );
00471 }
00472 if(lineParser.getBoolean("TOPBAR"))
00473 {
00474 move(x,0);
00475 KWin::setStrut( winId(), 0, 0, h, 0 );
00476 toggleLocked->setChecked( true );
00477 slotToggleLocked();
00478 toggleLocked->setEnabled(false);
00479 }
00480
00481 if(lineParser.getBoolean("BOTTOMBAR"))
00482 {
00483 int dh = TQApplication::desktop()->height();
00484 move( x, dh - h );
00485 KWin::setStrut( winId(), 0, 0, 0, h );
00486 toggleLocked->setChecked( true );
00487 slotToggleLocked();
00488 toggleLocked->setEnabled(false);
00489 }
00490
00491 if(lineParser.getBoolean("RIGHTBAR"))
00492 {
00493 int dw = TQApplication::desktop()->width();
00494 move( dw - w, y );
00495 KWin::setStrut( winId(), 0, w, 0, 0 );
00496 toggleLocked->setChecked( true );
00497 slotToggleLocked();
00498 toggleLocked->setEnabled(false);
00499 }
00500
00501 if(lineParser.getBoolean("LEFTBAR"))
00502 {
00503 move( 0, y );
00504 KWin::setStrut( winId(), w, 0, 0, 0 );
00505 toggleLocked->setChecked( true );
00506 slotToggleLocked();
00507 toggleLocked->setEnabled(false);
00508 }
00509
00510 TQString path = lineParser.getString("MASK");
00511
00512 TQFileInfo info(path);
00513 TQString absPath;
00514 TQBitmap bmMask;
00515 TQByteArray ba;
00516 if( info.isRelative() )
00517 {
00518 absPath.setAscii(m_theme.path().ascii());
00519 absPath.append(path.ascii());
00520 ba = m_theme.readThemeFile(path);
00521 }
00522 else
00523 {
00524 absPath.setAscii(path.ascii());
00525 ba = m_theme.readThemeFile(info.fileName());
00526 }
00527 if(m_theme.isZipTheme())
00528 {
00529 bmMask.loadFromData(ba);
00530 }
00531 else
00532 {
00533 bmMask.load(absPath);
00534 }
00535 setMask(bmMask);
00536
00537 m_interval = lineParser.getInt("INTERVAL");
00538 m_interval = (m_interval == 0) ? 1000 : m_interval;
00539
00540 TQString temp = lineParser.getString("TEMPUNIT", "C").upper();
00541 tempUnit = temp.ascii()[0];
00542 foundKaramba = true;
00543 }
00544
00545 if(lineParser.meter() == "THEME")
00546 {
00547 TQString path = lineParser.getString("PATH");
00548 TQFileInfo info(path);
00549 if( info.isRelative())
00550 path = m_theme.path() +"/" + path;
00551 (new karamba( path, TQString() ))->show();
00552 }
00553
00554 if(lineParser.meter() == "<GROUP>")
00555 {
00556 int offsetX = offsetStack.top().x();
00557 int offsetY = offsetStack.top().y();
00558 offsetStack.push( TQPoint( offsetX + lineParser.getInt("X"),
00559 offsetY + lineParser.getInt("Y")));
00560 }
00561
00562 if(lineParser.meter() == "</GROUP>")
00563 {
00564 offsetStack.pop();
00565 }
00566
00567 if(lineParser.meter() == "CLICKAREA")
00568 {
00569 if( !hasMouseTracking() )
00570 setMouseTracking(true);
00571 ClickArea *tmp = new ClickArea(this, x, y, w, h );
00572 tmp->setOnClick(lineParser.getString("ONCLICK"));
00573
00574 setSensor(lineParser, (Meter*)tmp);
00575 clickList->append( tmp );
00576 if( lineParser.getBoolean("PREVIEW"))
00577 meterList->append( tmp );
00578 }
00579
00580
00581 if(lineParser.meter() == "SENSOR=PROGRAM")
00582 {
00583 setSensor(lineParser, 0 );
00584 }
00585
00586 if(lineParser.meter() == "IMAGE")
00587 {
00588 TQString file = lineParser.getString("PATH");
00589 TQString file_roll = lineParser.getString("PATHROLL");
00590 int xon = lineParser.getInt("XROLL");
00591 int yon = lineParser.getInt("YROLL");
00592 TQString tiptext = lineParser.getString("TOOLTIP");
00593 TQString name = lineParser.getString("NAME");
00594 bool bg = lineParser.getBoolean("BACKGROUND");
00595 xon = ( xon <= 0 ) ? x:xon;
00596 yon = ( yon <= 0 ) ? y:yon;
00597
00598 ImageLabel *tmp = new ImageLabel(this, x, y, 0, 0);
00599 tmp->setValue(file);
00600 if(!file_roll.isEmpty())
00601 tmp->parseImages(file, file_roll, x,y, xon, yon);
00602 tmp->setBackground(bg);
00603 if (!name.isEmpty())
00604 tmp->setName(name.ascii());
00605 if (!tiptext.isEmpty())
00606 tmp->setTooltip(tiptext);
00607
00608 connect(tmp, TQT_SIGNAL(pixmapLoaded()), this, TQT_SLOT(externalStep()));
00609 setSensor(lineParser, (Meter*) tmp );
00610 meterList->append (tmp );
00611 imageList->append (tmp );
00612 }
00613
00614 if(lineParser.meter() == "DEFAULTFONT" )
00615 {
00616 delete defaultTextField;
00617 defaultTextField = new TextField( );
00618
00619 defaultTextField->setColor(lineParser.getColor("COLOR",
00620 TQColor("black")));
00621 defaultTextField->setBGColor(lineParser.getColor("BGCOLOR",
00622 TQColor("white")));
00623 defaultTextField->setFont(lineParser.getString("FONT", "Helvetica"));
00624 defaultTextField->setFontSize(lineParser.getInt("FONTSIZE", 12));
00625 defaultTextField->setAlignment(lineParser.getString("ALIGN",
00626 "LEFT"));
00627 defaultTextField->setFixedPitch(lineParser.getBoolean("FIXEDPITCH",
00628 false));
00629 defaultTextField->setShadow(lineParser.getInt("SHADOW", 0));
00630 }
00631
00632 if(lineParser.meter() == "TEXT" ||
00633 lineParser.meter() == "CLICKMAP" ||
00634 lineParser.meter() == "RICHTEXT" ||
00635 lineParser.meter() == "INPUT")
00636 {
00637 TextField defTxt;
00638
00639 if(defaultTextField)
00640 defTxt = *defaultTextField;
00641
00642 TextField* tmpText = new TextField();
00643
00644 tmpText->setColor(lineParser.getColor("COLOR", defTxt.getColor()));
00645 tmpText->setBGColor(lineParser.getColor("BGCOLOR",
00646 defTxt.getBGColor()));
00647 tmpText->setFont(lineParser.getString("FONT", defTxt.getFont()));
00648 tmpText->setFontSize(lineParser.getInt("FONTSIZE",
00649 defTxt.getFontSize()));
00650 tmpText->setAlignment(lineParser.getString("ALIGN",
00651 defTxt.getAlignmentAsString()));
00652 tmpText->setFixedPitch(lineParser.getInt("FIXEDPITCH",
00653 defTxt.getFixedPitch()));
00654
00655 tmpText->setShadow(lineParser.getInt("SHADOW", defTxt.getShadow()));
00656
00657
00658
00659 if(lineParser.meter() == "TEXT")
00660 {
00661
00662 TextLabel *tmp = new TextLabel(this, x, y, w, h );
00663 tmp->setTextProps(tmpText);
00664 tmp->setValue(
00665 m_theme.locale()->translate(lineParser.getString("VALUE")));
00666
00667 TQString name = lineParser.getString("NAME");
00668 if (!name.isEmpty())
00669 tmp->setName(name.ascii());
00670
00671 setSensor(lineParser, (Meter*)tmp);
00672 meterList->append ( tmp );
00673 }
00674
00675 if(lineParser.meter() == "CLICKMAP")
00676 {
00677 if( !hasMouseTracking() )
00678 setMouseTracking(true);
00679 ClickMap *tmp = new ClickMap(this, x, y, w, h);
00680 tmp->setTextProps( tmpText );
00681
00682 setSensor(lineParser, (Meter*)tmp);
00683
00684 clickList -> append(tmp);
00685 meterList->append( tmp );
00686
00687 }
00688
00689 if(lineParser.meter() == "RICHTEXT")
00690 {
00691 RichTextLabel *tmp = new RichTextLabel(this, x, y, w, h);
00692
00693 bool dUl = lineParser.getBoolean("UNDERLINE");
00694
00695 tmp->setText(
00696 m_theme.locale()->translate(lineParser.getString("VALUE").ascii()), dUl);
00697 tmp->setTextProps( tmpText );
00698 tmp->setWidth(w);
00699 tmp->setHeight(h);
00700
00701 TQString name = lineParser.getString("NAME");
00702 if (!name.isEmpty())
00703 tmp->setName(name.ascii());
00704
00705 setSensor(lineParser, (Meter*)tmp);
00706 clickList -> append(tmp);
00707 meterList->append ( tmp );
00708 }
00709
00710 if(lineParser.meter() == "INPUT")
00711 {
00712 Input *tmp = new Input(this, x, y, w, h);
00713
00714 TQString name = lineParser.getString("NAME");
00715 if (!name.isEmpty())
00716 tmp->setName(name.ascii());
00717
00718 tmp->setTextProps(tmpText);
00719 tmp->setValue(
00720 m_theme.locale()->translate(lineParser.getString("VALUE").ascii()));
00721
00722 meterList->append(tmp);
00723 passive = false;
00724 }
00725 }
00726
00727 if(lineParser.meter() == "BAR")
00728 {
00729 Bar *tmp = new Bar(this, x, y, w, h );
00730 tmp->setImage(lineParser.getString("PATH").ascii());
00731 tmp->setVertical(lineParser.getBoolean("VERTICAL"));
00732 tmp->setMax(lineParser.getInt("MAX", 100));
00733 tmp->setMin(lineParser.getInt("MIN", 0));
00734 tmp->setValue(lineParser.getInt("VALUE"));
00735 TQString name = lineParser.getString("NAME");
00736 if (!name.isEmpty())
00737 tmp->setName(name.ascii());
00738 setSensor(lineParser, (Meter*)tmp );
00739 meterList->append ( tmp );
00740 }
00741
00742 if(lineParser.meter() == "GRAPH")
00743 {
00744 int points = lineParser.getInt("POINTS");
00745
00746 Graph *tmp = new Graph(this, x, y, w, h, points);
00747 tmp->setMax(lineParser.getInt("MAX", 100));
00748 tmp->setMin(lineParser.getInt("MIN", 0));
00749 TQString name = lineParser.getString("NAME");
00750 if (!name.isEmpty())
00751 tmp->setName(name.ascii());
00752
00753 tmp->setColor(lineParser.getColor("COLOR"));
00754
00755 setSensor(lineParser, (Graph*)tmp);
00756 meterList->append ( tmp );
00757 }
00758 }
00759
00760 if(passive && !managed)
00761 {
00762
00763
00764 KWin::setType(winId(), NET::Dock);
00765 #if defined(KDE_MAKE_VERSION)
00766 #if KDE_VERSION >= KDE_MAKE_VERSION(3,1,9)
00767
00768 KWin::setState(winId(), NET::KeepBelow);
00769 #endif
00770 #endif
00771 }
00772
00773 m_theme.close();
00774 }
00775
00776 if( !foundKaramba )
00777 {
00778
00779
00780
00781 return false;
00782 }
00783 else
00784 {
00785 return true;
00786 }
00787 }
00788
00789 void karamba::start()
00790 {
00791 m_sysTimer = new TQTimer(this);
00792
00793 connect(m_sysTimer, TQT_SIGNAL(timeout()), TQT_SLOT(step()));
00794
00795 m_sysTimer->start(m_interval);
00796
00797
00798 TQTimer::singleShot( 0, this, TQT_SLOT(step()) );
00799
00800 if( !(onTop || managed) )
00801 lowerTimer.start();
00802 }
00803
00804 void karamba::makeActive()
00805 {
00806 KWin::setType(winId(), NET::Normal);
00807
00808 #if defined(KDE_MAKE_VERSION)
00809 #if KDE_VERSION >= KDE_MAKE_VERSION(3,1,9)
00810
00811 KWin::setState(winId(), NET::Modal);
00812 #endif
00813 #endif
00814 }
00815
00816 void karamba::makePassive()
00817 {
00818 if(managed)
00819 return;
00820
00821 TQObject *meter;
00822 for (meter = meterList->first(); meter; meter = meterList->next())
00823 {
00824 if((meter)->isA("Input"))
00825 return;
00826 }
00827
00828
00829
00830 KWin::setType(winId(), NET::Dock);
00831 #if defined(KDE_MAKE_VERSION)
00832 #if KDE_VERSION >= KDE_MAKE_VERSION(3,1,9)
00833
00834 KWin::setState(winId(), NET::KeepBelow);
00835 #endif
00836 #endif
00837 }
00838
00839 void karamba::popupNotify(int)
00840 {
00841
00842 }
00843
00844 void karamba::reloadConfig()
00845 {
00846
00847 writeConfigData();
00848 if(m_theme.exists())
00849 {
00850 TQFileInfo fileInfo( m_theme.file() );
00851 (new karamba(m_theme.file(), fileInfo.baseName(), true, m_instance))->show();
00852 }
00853 closeTheme(true);
00854 }
00855
00856 void karamba::closeTheme(bool reloading)
00857 {
00858 m_reloading = reloading;
00859 close();
00860 }
00861
00862 void karamba::killWidget()
00863 {
00864 closeTheme();
00865 }
00866
00867 void karamba::initPythonInterface()
00868 {
00869 pythonIface = new KarambaPython(m_theme, m_reloading);
00870 }
00871
00872 void karamba::editConfig()
00873 {
00874
00875 TQFileInfo fileInfo( m_theme.file() );
00876 TQString path;
00877
00878 if( fileInfo.isRelative() )
00879 {
00880 path = m_theme.path() + "/" + m_theme.file();
00881 }
00882 else
00883 {
00884 path = m_theme.file();
00885 }
00886
00887 KRun::runURL( KURL( path ), "text/plain" );
00888 }
00889
00890 void karamba::editScript()
00891 {
00892
00893 TQFileInfo fileInfo( m_theme.file() );
00894 TQString path;
00895
00896 if( fileInfo.isRelative() )
00897 {
00898 path = m_theme.path() + "/" + m_theme.name() + ".py";
00899 }
00900 else
00901 {
00902 path = TQFileInfo(m_theme.file()).dirPath() + "/" + m_theme.name() + ".py";
00903 }
00904 KRun::runURL( KURL( path ), "text/plain" );
00905 }
00906
00907 TQString karamba::findSensorFromMap(Sensor* sensor)
00908 {
00909
00910 TQMap<TQString,Sensor*>::ConstIterator it;
00911 TQMap<TQString,Sensor*>::ConstIterator end( sensorMap.end() );
00912 for ( it = sensorMap.begin(); it != end; ++it )
00913 {
00914 if (it.data() == sensor)
00915 return it.key();
00916 }
00917 return "";
00918 }
00919
00920 Sensor* karamba::findSensorFromList(Meter* meter)
00921 {
00922
00923 TQObjectListIt it( *sensorList );
00924
00925 while ( it != 0 )
00926 {
00927 if (((Sensor*) *it)->hasMeter(meter))
00928 return ((Sensor*)*it);
00929 ++it;
00930 }
00931 return NULL;
00932 }
00933
00934 TQString karamba::getSensor(Meter* meter)
00935 {
00936
00937 TQString s;
00938 Sensor* sensor = findSensorFromList(meter);
00939 if (sensor)
00940 s = findSensorFromMap(sensor);
00941 return s;
00942 }
00943
00944 void karamba::deleteMeterFromSensors(Meter* meter)
00945 {
00946
00947 Sensor* sensor = findSensorFromList(meter);
00948
00949 if (sensor)
00950 {
00951 sensor->deleteMeter(meter);
00952 if (sensor->isEmpty())
00953 {
00954 TQString s = findSensorFromMap(sensor);
00955 sensorMap.erase(s);
00956 sensorList->removeRef(sensor);
00957 }
00958 }
00959 }
00960
00961 void karamba::setSensor(const LineParser& lineParser, Meter* meter)
00962 {
00963
00964 Sensor* sensor = 0;
00965
00966 deleteMeterFromSensors(meter);
00967
00968 TQString sens = lineParser.getString("SENSOR").upper();
00969
00970 if( sens == "CPU" )
00971 {
00972 TQString cpuNbr = lineParser.getString("CPU");
00973 sensor = sensorMap["CPU"+cpuNbr];
00974 if (sensor == 0)
00975 {
00976 int interval = lineParser.getInt("INTERVAL");
00977 interval = (interval == 0)?1000:interval;
00978 sensor = ( sensorMap["CPU"+cpuNbr] = new CPUSensor( cpuNbr, interval ) );
00979 sensorList->append( sensor );
00980 }
00981 SensorParams *sp = new SensorParams(meter);
00982 sp->addParam("FORMAT",
00983 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
00984 sp->addParam("DECIMALS",lineParser.getString("DECIMALS"));
00985
00986 sensor->addMeter(sp);
00987 sensor->setMaxValue(sp);
00988
00989 }
00990
00991 if( sens == "MEMORY" )
00992 {
00993 sensor = sensorMap["MEMORY"];
00994 if (sensor == 0)
00995 {
00996 int interval = lineParser.getInt("INTERVAL");
00997 interval = (interval == 0)?3000:interval;
00998 sensor = ( sensorMap["MEMORY"] = new MemSensor( interval ) );
00999 sensorList->append( sensor );
01000 }
01001 SensorParams *sp = new SensorParams(meter);
01002 sp->addParam("FORMAT",
01003 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
01004
01005 sensor->addMeter(sp);
01006 sensor->setMaxValue(sp);
01007 }
01008
01009
01010 if( sens == "DISK" )
01011 {
01012 sensor = sensorMap["DISK"];
01013 if (sensor == 0)
01014 {
01015 int interval = lineParser.getInt("INTERVAL");
01016 interval = (interval == 0)?5000:interval;
01017 sensor = ( sensorMap["DISK"] = new DiskSensor( interval ) );
01018 connect( sensor, TQT_SIGNAL(initComplete()), this, TQT_SLOT(externalStep()) );
01019 sensorList->append( sensor );
01020 }
01021
01022 SensorParams *sp = new SensorParams(meter);
01023 TQString mntPt = lineParser.getString("MOUNTPOINT");
01024 if( mntPt.isEmpty() )
01025 {
01026 mntPt = "/";
01027 }
01028
01029
01030 if( mntPt.length() > 1 && mntPt.endsWith("/") )
01031 {
01032 mntPt.remove( mntPt.length()-1, 1 );
01033 }
01034 sp->addParam("MOUNTPOINT",mntPt);
01035 sp->addParam("FORMAT",
01036 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
01037 sensor->addMeter(sp);
01038 sensor->setMaxValue(sp);
01039 }
01040
01041 if( sens == "NETWORK")
01042 {
01043 int interval = lineParser.getInt("INTERVAL");
01044 interval = (interval == 0)?2000:interval;
01045 TQString device = lineParser.getString("DEVICE");
01046 sensor = sensorMap["NETWORK"+device];
01047 if (sensor == 0)
01048 {
01049 sensor = ( sensorMap["NETWORK"+device] =
01050 new NetworkSensor(device, interval));
01051 sensorList->append( sensor );
01052 }
01053 SensorParams *sp = new SensorParams(meter);
01054 sp->addParam("FORMAT",
01055 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
01056 sp->addParam("DECIMALS", lineParser.getString("DECIMALS"));
01057 sensor->addMeter(sp);
01058 }
01059
01060 if( sens == "UPTIME" )
01061 {
01062 sensor = sensorMap["UPTIME"];
01063 if (sensor == 0)
01064 {
01065 int interval = lineParser.getInt("INTERVAL");
01066 interval = (interval == 0)?60000:interval;
01067 sensor = ( sensorMap["UPTIME"] = new UptimeSensor( interval ));
01068 sensorList->append( sensor );
01069
01070 }
01071 SensorParams *sp = new SensorParams(meter);
01072 sp->addParam("FORMAT",
01073 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
01074 sensor->addMeter(sp);
01075 }
01076
01077 if( sens == "SENSOR" )
01078 {
01079 sensor = sensorMap["SENSOR"];
01080 if (sensor == 0)
01081 {
01082 int interval = lineParser.getInt("INTERVAL");
01083 interval = (interval == 0)?30000:interval;
01084 sensor = (sensorMap["SENSOR"] = new SensorSensor(interval, tempUnit));
01085 sensorList->append( sensor );
01086 }
01087 SensorParams *sp = new SensorParams(meter);
01088 sp->addParam("FORMAT",
01089 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
01090 sp->addParam("TYPE", lineParser.getString("TYPE"));
01091 sensor->addMeter(sp);
01092 }
01093
01094
01095 if( sens == "TEXTFILE" )
01096 {
01097 TQString path = lineParser.getString("PATH");
01098 bool rdf = lineParser.getBoolean("RDF");
01099 sensor = sensorMap["TEXTFILE"+path];
01100 if (sensor == 0)
01101 {
01102 int interval = lineParser.getInt("INTERVAL");
01103 interval = ( interval == 0 )?60000:interval;
01104 TQString encoding = lineParser.getString("ENCODING");
01105
01106 sensor = ( sensorMap["TEXTFILE"+path] =
01107 new TextFileSensor( path, rdf, interval, encoding ) );
01108 sensorList->append( sensor );
01109 }
01110 SensorParams *sp = new SensorParams(meter);
01111 sp->addParam("LINE",TQString::number(lineParser.getInt("LINE")));
01112 sensor->addMeter(sp);
01113 }
01114
01115
01116 if( sens == "TIME")
01117 {
01118 sensor = sensorMap["DATE"];
01119 if (sensor == 0)
01120 {
01121 int interval = lineParser.getInt("INTERVAL");
01122 interval = (interval == 0)?60000:interval;
01123 sensor = ( sensorMap["DATE"] = new DateSensor( interval ) );
01124 sensorList->append( sensor );
01125 timeList->append( sensor );
01126 }
01127 SensorParams *sp = new SensorParams(meter);
01128 sp->addParam("FORMAT",
01129 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
01130 sp->addParam("CALWIDTH",lineParser.getString("CALWIDTH"));
01131 sp->addParam("CALHEIGHT",lineParser.getString("CALHEIGHT"));
01132 sensor->addMeter(sp);
01133 }
01134
01135 #ifdef HAVE_XMMS
01136
01137 if( sens == "XMMS" )
01138 {
01139 sensor = sensorMap["XMMS"];
01140 if (sensor == 0)
01141 {
01142 int interval = lineParser.getInt("INTERVAL");
01143 interval = (interval == 0)?1000:interval;
01144 TQString encoding = lineParser.getString("ENCODING");
01145
01146 sensor = ( sensorMap["XMMS"] = new XMMSSensor( interval, encoding ) );
01147 sensorList->append( sensor );
01148 }
01149 SensorParams *sp = new SensorParams(meter);
01150 sp->addParam("FORMAT",
01151 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
01152 sensor->addMeter(sp);
01153 sensor->setMaxValue(sp);
01154 }
01155 #endif // HAVE_XMMS
01156
01157
01158 if( sens == "NOATUN" )
01159 {
01160 sensor = sensorMap["NOATUN"];
01161 if (sensor == 0)
01162 {
01163 int interval = lineParser.getInt("INTERVAL");
01164 interval = (interval == 0)?1000:interval;
01165 sensor = ( sensorMap["NOATUN"] = new NoatunSensor( interval, client ) );
01166 sensorList->append( sensor );
01167 }
01168 SensorParams *sp = new SensorParams(meter);
01169 sp->addParam("FORMAT",
01170 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
01171 sensor->addMeter(sp);
01172 sensor->setMaxValue(sp);
01173 }
01174
01175 if( sens == "PROGRAM")
01176 {
01177 TQString progName = lineParser.getString("PROGRAM");
01178 sensor = sensorMap["PROGRAM"+progName];
01179 if (sensor == 0)
01180 {
01181 int interval = lineParser.getInt("INTERVAL");
01182 interval = (interval == 0)?3600000:interval;
01183 TQString encoding = lineParser.getString("ENCODING");
01184
01185 sensor = (sensorMap["PROGRAM"+progName] =
01186 new ProgramSensor( progName, interval, encoding ) );
01187 sensorList->append( sensor );
01188 }
01189 SensorParams *sp = new SensorParams(meter);
01190 sp->addParam( "LINE", TQString::number(lineParser.getInt("LINE")));
01191 sp->addParam( "THEMAPATH", m_theme.path() );
01192 sensor->addMeter(sp);
01193 }
01194
01195 if( sens == "RSS" )
01196 {
01197 TQString source = lineParser.getString("SOURCE");
01198 TQString format =
01199 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii());
01200
01201 sensor = sensorMap["RSS"+source];
01202 if (sensor == 0)
01203 {
01204 int interval = lineParser.getInt( "INTERVAL");
01205 interval = ( interval == 0 )?60000:interval;
01206 TQString encoding = lineParser.getString("ENCODING");
01207
01208 sensor = ( sensorMap["RSS"+source] =
01209 new RssSensor( source, interval, format, encoding ) );
01210 sensorList->append( sensor );
01211 }
01212 SensorParams *sp = new SensorParams(meter);
01213 sp->addParam("SOURCE",lineParser.getString("SOURCE"));
01214 sensor->addMeter(sp);
01215 }
01216
01217 if (sensor != 0)
01218 {
01219 TQTimer::singleShot( 0, sensor, TQT_SLOT(update()) );
01220 sensor->start();
01221 }
01222 }
01223
01224 void karamba::slotFileChanged( const TQString & file)
01225 {
01226
01227
01228 TQString pythonFile = m_theme.path() + "/" + m_theme.pythonModule() + ".py";
01229
01230 if(file == m_theme.file() || file == pythonFile)
01231 reloadConfig();
01232 }
01233
01234 void karamba::passMenuOptionChanged(TQString key, bool value)
01235 {
01236
01237 if (pythonIface && pythonIface->isExtensionLoaded())
01238 pythonIface->menuOptionChanged(this, key, value);
01239 }
01240
01241 void karamba::setIncomingData(TQString theme, TQString obj)
01242 {
01243 KarambaApplication* app = (KarambaApplication*)qApp;
01244
01245 kdDebug() << "karamba::setIncomingData " << theme << obj << endl;
01246
01247
01248
01249
01250
01251
01252
01253 DCOPClient *c = kapp->dcopClient();
01254 if (!c->isAttached())
01255 c->attach();
01256
01257 if(app->dcopStub())
01258 app->dcopStub()->setIncomingData(theme, obj);
01259 }
01260
01261 void karamba::callTheme(TQString theme, TQString txt)
01262 {
01263 KarambaApplication* app = (KarambaApplication*)qApp;
01264 kdDebug() << "karamba::callTheme " << theme << txt << endl;
01265
01266
01267
01268
01269
01270
01271
01272
01273 DCOPClient *c = kapp->dcopClient();
01274 if (!c->isAttached())
01275 c->attach();
01276
01277 if(app->dcopStub())
01278 app->dcopStub()->themeNotify(theme, txt);
01279 }
01280
01281 void karamba::themeNotify(TQString theme, TQString txt)
01282 {
01283 kdDebug() << "karamba::themeNotify" << theme << txt << endl;
01284 if (pythonIface->isExtensionLoaded())
01285 {
01286 pythonIface->themeNotify(this, theme.ascii(), txt.ascii());
01287 }
01288 }
01289
01290 void karamba::meterClicked(TQMouseEvent* e, Meter* meter)
01291 {
01292
01293 if (pythonIface && pythonIface->isExtensionLoaded() && haveUpdated)
01294 {
01295 int button = 0;
01296
01297 if( e->button() == Qt::LeftButton )
01298 button = 1;
01299 else if( e->button() == Qt::MidButton )
01300 button = 2;
01301 else if( e->button() == Qt::RightButton )
01302 button = 3;
01303
01304 if (RichTextLabel* richText = dynamic_cast<RichTextLabel*>(meter))
01305 {
01306 pythonIface->meterClicked(this, richText->anchorAt(e->x(), e->y()),
01307 button);
01308 }
01309 else
01310 {
01311 pythonIface->meterClicked(this, meter, button);
01312 }
01313 }
01314 }
01315
01316 void karamba::changeInterval(int interval)
01317 {
01318 if (m_sysTimer != NULL)
01319 m_sysTimer->changeInterval(interval);
01320 }
01321
01322 void karamba::passClick(TQMouseEvent *e)
01323 {
01324
01325 TQObjectListIt it2( *timeList );
01326 while ( it2 != 0 )
01327 {
01328 (( DateSensor* ) *it2)->toggleCalendar( e );
01329 ++it2;
01330 }
01331
01332
01333
01334
01335 TQObjectList clickListTmp(*clickList);
01336 TQObjectListIt it(clickListTmp);
01337 while (it != 0)
01338 {
01339 Meter* meter = (Meter*)(*it);
01340
01341 if (clickList->containsRef(meter) && meter->click(e))
01342 {
01343
01344 meterClicked(e, meter);
01345 }
01346 ++it;
01347 }
01348
01349
01350 if (pythonIface && pythonIface->isExtensionLoaded() && haveUpdated)
01351 {
01352 int button = 0;
01353
01354 if( e->button() == Qt::LeftButton )
01355 button = 1;
01356 else if( e->button() == Qt::MidButton )
01357 button = 2;
01358 else if( e->button() == Qt::RightButton )
01359 button = 3;
01360
01361 pythonIface->widgetClicked(this, e->x(), e->y(), button);
01362 }
01363 }
01364
01365 void karamba::passWheelClick( TQWheelEvent *e )
01366 {
01367
01368
01369 if (pythonIface && pythonIface->isExtensionLoaded() && haveUpdated)
01370 {
01371 int button = 0;
01372
01373 if( e->delta() > 0 )
01374 button = 4;
01375 else
01376 button = 5;
01377
01378
01379
01380 if (want_meter_wheel_event)
01381 {
01382 TQObjectList clickListTmp(*clickList);
01383 TQObjectListIt it(clickListTmp);
01384
01385 TQMouseEvent fakeEvent(TQEvent::MouseButtonPress, e->pos(), e->globalPos(), button, e->state());
01386
01387 while (it != 0)
01388 {
01389 Meter* meter = (Meter*)(*it);
01390
01391 if (clickList->containsRef(meter) && meter->click(&fakeEvent))
01392 {
01393 if (RichTextLabel* richText = dynamic_cast<RichTextLabel*>(meter))
01394 {
01395 pythonIface->meterClicked(this, richText->anchorAt(fakeEvent.x(), fakeEvent.y()),
01396 button);
01397 }
01398 else
01399 {
01400 pythonIface->meterClicked(this, meter, button);
01401 }
01402 }
01403 ++it;
01404 }
01405 }
01406
01407 pythonIface->widgetClicked(this, e->x(), e->y(), button);
01408 }
01409 }
01410
01411 void karamba::management_popup( void )
01412 {
01413 kpop->popup(TQCursor::pos());
01414 }
01415
01416 void karamba::mousePressEvent( TQMouseEvent *e )
01417 {
01418
01419 if( e->button() == RightButton && !want_right_button )
01420 {
01421 management_popup();
01422 }
01423 else
01424 {
01425 clickPos = e->pos();
01426 if( toggleLocked -> isChecked() )
01427 passClick( e );
01428 if( !(onTop || managed))
01429 KWin::lowerWindow( winId() );
01430 }
01431 }
01432
01433 void karamba::wheelEvent( TQWheelEvent *e )
01434 {
01435
01436 passWheelClick( e );
01437 }
01438
01439 void karamba::mouseReleaseEvent( TQMouseEvent *e )
01440 {
01441
01442 clickPos = e->pos();
01443 }
01444
01445 void karamba::mouseDoubleClickEvent( TQMouseEvent *e )
01446 {
01447
01448 if( !toggleLocked -> isChecked() )
01449 {
01450 passClick( e );
01451 }
01452 }
01453
01454 void karamba::keyPressEvent(TQKeyEvent *e)
01455 {
01456
01457 keyPressed(e->text(), 0);
01458 }
01459
01460 void karamba::keyPressed(const TQString& s, const Meter* meter)
01461 {
01462 if (pythonIface && pythonIface->isExtensionLoaded())
01463 pythonIface->keyPressed(this, meter, s);
01464 }
01465
01466 void karamba::mouseMoveEvent( TQMouseEvent *e )
01467 {
01468
01469 if( e->state() != 0 && e->state() < 16 && !toggleLocked -> isChecked() )
01470 {
01471 move( e->globalPos() - clickPos );
01472 }
01473 else
01474 {
01475
01476 TQObjectListIt it(*clickList);
01477 bool insideArea = false;
01478
01479 while (it != 0)
01480 {
01481 insideArea = ((Meter*)(*it)) -> insideActiveArea(e -> x(), e ->y());
01482 if (insideArea)
01483 {
01484 break;
01485 }
01486 ++it;
01487 }
01488
01489 if(insideArea)
01490 {
01491 if( cursor().shape() != PointingHandCursor )
01492 setCursor( PointingHandCursor );
01493 }
01494 else
01495 {
01496 if( cursor().shape() != ArrowCursor )
01497 setCursor( ArrowCursor );
01498 }
01499
01500 TQObjectListIt image_it( *imageList);
01501 while ( image_it != 0 )
01502 {
01503 ((ImageLabel*) *image_it)->rolloverImage(e);
01504 ++image_it;
01505 }
01506 }
01507
01508 if (pythonIface && pythonIface->isExtensionLoaded())
01509 {
01510 int button = 0;
01511
01512
01513
01514
01515
01516 if( e->state() == LeftButton)
01517 button = 1;
01518
01519 else if( e->state() == MidButton )
01520 button = 2;
01521
01522 else if( e->state() == RightButton )
01523 button = 3;
01524
01525 pythonIface->widgetMouseMoved(this, e->x(), e->y(), button);
01526 }
01527 }
01528
01529 void karamba::closeEvent ( TQCloseEvent * qc)
01530 {
01531
01532 qc->accept();
01533
01534
01535 }
01536
01537 void karamba::paintEvent ( TQPaintEvent *e)
01538 {
01539
01540 if(pm.width() == 0)
01541 return;
01542 if( !(onTop || managed))
01543 {
01544 if( lowerTimer.elapsed() > 100 )
01545 {
01546 KWin::lowerWindow( winId() );
01547 lowerTimer.restart();
01548 }
01549 }
01550 TQRect rect = e->rect();
01551 bitBlt(this,rect.topLeft(),&pm,rect,Qt::CopyROP);
01552 }
01553
01554 void karamba::updateSensors()
01555 {
01556
01557 TQObjectListIt it( *sensorList );
01558 while ( it != 0 )
01559 {
01560 ((Sensor*) *it)->update();
01561 ++it;
01562 }
01563 TQTimer::singleShot( 500, this, TQT_SLOT(step()) );
01564 }
01565
01566 void karamba::updateBackground(KSharedPixmap* kpm)
01567 {
01568
01569
01570
01571
01572 if( !themeStarted )
01573 {
01574 themeStarted = true;
01575 start();
01576 }
01577 background = TQPixmap(*kpm);
01578
01579 TQPixmap buffer = TQPixmap(size());
01580
01581 pm = TQPixmap(size());
01582 buffer.fill(Qt::black);
01583
01584 TQObjectListIt it( *imageList );
01585 p.begin(&buffer);
01586 bitBlt(&buffer,0,0,&background,0,Qt::CopyROP);
01587
01588 while ( it != 0 )
01589 {
01590 if (((ImageLabel*) *it)->background == 1)
01591 {
01592 ((ImageLabel*) *it)->mUpdate(&p, 1);
01593 }
01594 ++it;
01595 }
01596 p.end();
01597
01598 bitBlt(&pm,0,0,&buffer,0,Qt::CopyROP);
01599 background = pm;
01600
01601 TQPixmap buffer2 = TQPixmap(size());
01602
01603 pm = TQPixmap(size());
01604 buffer2.fill(Qt::black);
01605
01606 TQObjectListIt it2( *meterList );
01607 p.begin(&buffer2);
01608 bitBlt(&buffer2,0,0,&background,0,Qt::CopyROP);
01609
01610 while ( it2 != 0 )
01611 {
01612 ((Meter*) *it2)->mUpdate(&p);
01613 ++it2;
01614 }
01615 p.end();
01616
01617 bitBlt(&pm,0,0,&buffer2,0,Qt::CopyROP);
01618 if (systray != 0)
01619 {
01620 systray->updateBackgroundPixmap(buffer2);
01621 }
01622 repaint();
01623 }
01624
01625 void karamba::currentDesktopChanged( int i )
01626 {
01627
01628 kroot->repaint( true );
01629 if (pythonIface && pythonIface->isExtensionLoaded())
01630 pythonIface->desktopChanged(this, i);
01631 }
01632
01633 void karamba::currentWallpaperChanged(int i )
01634 {
01635
01636 kroot->repaint( true );
01637 if (pythonIface && pythonIface->isExtensionLoaded())
01638 pythonIface->wallpaperChanged(this, i);
01639 }
01640
01641 void karamba::externalStep()
01642 {
01643
01644 if (widgetUpdate)
01645 {
01646 TQPixmap buffer = TQPixmap(size());
01647
01648 pm = TQPixmap(size());
01649 buffer.fill(Qt::black);
01650
01651 TQObjectListIt it( *meterList );
01652 p.begin(&buffer);
01653 bitBlt(&buffer,0,0,&background,0,Qt::CopyROP);
01654
01655 while ( it != 0 )
01656 {
01657 ((Meter*) *it)->mUpdate(&p);
01658 ++it;
01659 }
01660 p.end();
01661
01662 bitBlt(&pm,0,0,&buffer,0,Qt::CopyROP);
01663 repaint();
01664 }
01665 }
01666
01667 void karamba::step()
01668 {
01669
01670 if (widgetUpdate && haveUpdated)
01671 {
01672 pm = TQPixmap(size());
01673 TQPixmap buffer = TQPixmap(size());
01674 buffer.fill(Qt::black);
01675
01676 TQObjectListIt it( *meterList );
01677 p.begin(&buffer);
01678
01679 bitBlt(&buffer,0,0,&background,0,Qt::CopyROP);
01680
01681 while (it != 0)
01682 {
01683 ((Meter*) *it)->mUpdate(&p);
01684 ++it;
01685 }
01686 p.end();
01687
01688 bitBlt(&pm,0,0,&buffer,0,Qt::CopyROP);
01689 update();
01690 }
01691
01692 if (pythonIface && pythonIface->isExtensionLoaded())
01693 {
01694 if (haveUpdated == 0)
01695 pythonIface->initWidget(this);
01696 else
01697 pythonIface->widgetUpdated(this);
01698 }
01699
01700 if (haveUpdated == 0)
01701 haveUpdated = 1;
01702 }
01703
01704 void karamba::widgetClosed()
01705 {
01706
01707 if (pythonIface && pythonIface->isExtensionLoaded())
01708 pythonIface->widgetClosed(this);
01709 }
01710
01711 void karamba::slotToggleLocked()
01712 {
01713
01714 if(toggleLocked->isChecked())
01715 {
01716 toggleLocked->setIconSet(SmallIconSet("lock"));
01717 }
01718 else
01719 {
01720 toggleLocked->setIconSet(SmallIconSet("move"));
01721 }
01722 }
01723
01724 void karamba::slotToggleFastTransforms()
01725 {
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739 }
01740
01741
01742 bool karamba::useSmoothTransforms()
01743 {
01744
01745 return !toggleFastTransforms -> isChecked();
01746 }
01747
01748 void karamba::writeConfigData()
01749 {
01750
01751 config -> setGroup("internal");
01752 config -> writeEntry("lockedPosition", toggleLocked -> isChecked() );
01753 config -> writeEntry("fastTransforms", toggleFastTransforms -> isChecked() );
01754 config -> writeEntry("desktop", desktop );
01755 config -> setGroup("theme");
01756
01757 config -> writeEntry("widgetPosX", x());
01758 config -> writeEntry("widgetPosY", y());
01759
01760 config -> writeEntry("widgetWidth", width());
01761 config -> writeEntry("widgetHeight", height());
01762
01763
01764 config -> sync();
01765
01766
01767 }
01768
01769 void karamba::slotToggleConfigOption(TQString key, bool value)
01770 {
01771
01772 config -> setGroup("config menu");
01773 config -> writeEntry(key, value);
01774 passMenuOptionChanged(key, value);
01775 }
01776
01777 void karamba::addMenuConfigOption(TQString key, TQString name)
01778 {
01779
01780 kpop -> setItemEnabled(THEMECONF, true);
01781
01782 SignalBridge* action = new SignalBridge(this, key, menuAccColl);
01783 KToggleAction* confItem = new KToggleAction (name, KShortcut::null(),
01784 action, TQT_SLOT(receive()),
01785 menuAccColl, key.ascii());
01786 confItem -> setName(key.ascii());
01787
01788 menuAccColl -> insert(confItem);
01789
01790 connect(action, TQT_SIGNAL( enabled(TQString, bool) ),
01791 this, TQT_SLOT( slotToggleConfigOption(TQString, bool) ));
01792
01793 config -> setGroup("config menu");
01794 confItem -> setChecked(config -> readBoolEntry(key));
01795
01796 confItem -> plug(themeConfMenu);
01797
01798 numberOfConfMenuItems++;
01799 }
01800
01801 bool karamba::setMenuConfigOption(TQString key, bool value)
01802 {
01803
01804 KToggleAction* menuAction = ((KToggleAction*)menuAccColl -> action(key.ascii()));
01805 if (menuAction == NULL)
01806 {
01807 qWarning("Menu action %s not found.", key.ascii());
01808 return false;
01809 }
01810 else
01811 {
01812 menuAction -> setChecked(value);
01813 return true;
01814 }
01815 }
01816
01817 bool karamba::readMenuConfigOption(TQString key)
01818 {
01819
01820 KToggleAction* menuAction = ((KToggleAction*)menuAccColl -> action(key.ascii()));
01821 if (menuAction == NULL)
01822 {
01823 qWarning("Menu action %s not found.", key.ascii());
01824 return false;
01825 }
01826 else
01827 {
01828 return menuAction -> isChecked();
01829 }
01830 }
01831
01832 void karamba::passMenuItemClicked(int id)
01833 {
01834
01835
01836 if (pythonIface && pythonIface->isExtensionLoaded())
01837 {
01838 KPopupMenu* menu = 0;
01839 for(int i = 0; i < (int)menuList->count(); i++)
01840 {
01841 KPopupMenu* tmp;
01842 if(i==0)
01843 {
01844 tmp = (KPopupMenu*) menuList->first();
01845 }
01846 else
01847 {
01848 tmp = (KPopupMenu*) menuList->next();
01849 }
01850 if(tmp != 0)
01851 {
01852 if(tmp->isItemVisible(id))
01853 {
01854 menu = tmp;
01855 break;
01856 }
01857 }
01858 }
01859 pythonIface->menuItemClicked(this, menu, id);
01860 }
01861 }
01862
01863 void karamba::activeTaskChanged(Task* t)
01864 {
01865
01866
01867 if (pythonIface && pythonIface->isExtensionLoaded())
01868 pythonIface->activeTaskChanged(this, t);
01869 }
01870
01871 void karamba::taskAdded(Task* t)
01872 {
01873
01874
01875 if (pythonIface && pythonIface->isExtensionLoaded())
01876 pythonIface->taskAdded(this, t);
01877 }
01878
01879 void karamba::taskRemoved(Task* t)
01880 {
01881
01882
01883 if (pythonIface && pythonIface->isExtensionLoaded())
01884 pythonIface->taskRemoved(this, t);
01885 }
01886
01887 void karamba::startupAdded(Startup* t)
01888 {
01889
01890
01891 if (pythonIface && pythonIface->isExtensionLoaded())
01892 pythonIface->startupAdded(this, t);
01893 }
01894
01895 void karamba::startupRemoved(Startup* t)
01896 {
01897
01898
01899 if (pythonIface && pythonIface->isExtensionLoaded())
01900 pythonIface->startupRemoved(this, t);
01901 }
01902
01903 void karamba::processExited (KProcess* proc)
01904 {
01905
01906 if (pythonIface && pythonIface->isExtensionLoaded())
01907 pythonIface->commandFinished(this, (int)proc->pid());
01908 }
01909
01910 void karamba::receivedStdout (KProcess *proc, char *buffer, int)
01911 {
01912
01913
01914 if (pythonIface && pythonIface->isExtensionLoaded())
01915 pythonIface->commandOutput(this, (int)proc->pid(), buffer);
01916 }
01917
01918
01919 void karamba::saveProperties(KConfig* config)
01920 {
01921
01922 config->setGroup("session");
01923 config->writeEntry("theme", m_theme.file());
01924 writeConfigData();
01925 }
01926
01927
01928 void karamba::readProperties(KConfig* config)
01929 {
01930
01931 config->setGroup("session");
01932 TQString atheme = config->readEntry("theme");
01933 }
01934
01935
01936 void karamba::dragEnterEvent(TQDragEnterEvent* event)
01937 {
01938
01939 event->accept(TQTextDrag::canDecode(event));
01940 }
01941
01942
01943 void karamba::dropEvent(TQDropEvent* event)
01944 {
01945
01946 TQString text;
01947
01948 if ( TQTextDrag::decode(event, text) )
01949 {
01950
01951 if (pythonIface && pythonIface->isExtensionLoaded())
01952 {
01953 const TQPoint &p = event->pos();
01954 pythonIface->itemDropped(this, text, p.x(), p.y());
01955 }
01956 }
01957 }
01958
01959 void karamba::toDesktop(int id, int menuid)
01960 {
01961
01962 int i;
01963
01964 desktop = id;
01965 for (i=0; ; i++)
01966 {
01967 int mid = toDesktopMenu->idAt(i);
01968 if (mid == -1)
01969 break;
01970
01971 toDesktopMenu->setItemChecked(mid, false);
01972 }
01973 toDesktopMenu->setItemChecked(menuid, true);
01974
01975 if (desktop)
01976 info->setDesktop( desktop);
01977 else
01978 info->setDesktop( NETWinInfo::OnAllDesktops );
01979 }
01980
01981 void karamba::systrayUpdated()
01982 {
01983
01984 if (pythonIface && pythonIface->isExtensionLoaded())
01985 pythonIface->systrayUpdated(this);
01986 }
01987
01988 void karamba::toggleWidgetUpdate( bool b)
01989 {
01990
01991 if (pythonIface && pythonIface->isExtensionLoaded())
01992 widgetUpdate = b;
01993 }
01994
01995 SignalBridge::SignalBridge(TQObject* parent, TQString name, KActionCollection* ac)
01996 : TQObject(parent, name.ascii()), collection(ac)
01997 {
01998 setName(name.ascii());
01999 }
02000
02001 void SignalBridge::receive()
02002 {
02003 emit enabled(name(), ((KToggleAction*)collection -> action(name())) ->
02004 isChecked());
02005 }
02006
02007 DesktopChangeSlot::DesktopChangeSlot(TQObject *parent, int id)
02008 : TQObject(parent, "")
02009 {
02010 desktopid = id;
02011 }
02012
02013 void DesktopChangeSlot::receive()
02014 {
02015 karamba *k = (karamba *)parent();
02016
02017
02018
02019 k->toDesktop(desktopid, menuid);
02020 }
02021
02022 void DesktopChangeSlot::setMenuId(int id)
02023 {
02024 menuid = id;
02025 }
02026
02027 int DesktopChangeSlot::menuId()
02028 {
02029 return menuid;
02030 }
02031
02032 void karamba::showMenuExtension()
02033 {
02034 kglobal = new KPopupMenu(this);
02035
02036 trayMenuToggleId = kglobal->insertItem(SmallIconSet("superkaramba"),
02037 i18n("Show System Tray Icon"), this,
02038 TQT_SLOT(slotToggleSystemTray()),
02039 CTRL+Key_S);
02040
02041 trayMenuThemeId = kglobal->insertItem(SmallIconSet("knewstuff"),
02042 i18n("&Manage Themes..."), this,
02043 TQT_SLOT(slotShowTheme()), CTRL+Key_M);
02044
02045 trayMenuQuitId = kglobal->insertItem(SmallIconSet("exit"),
02046 i18n("&Quit SuperKaramba"), this,
02047 TQT_SLOT(slotQuit()), CTRL+Key_Q);
02048
02049 kglobal->polish();
02050
02051 trayMenuSeperatorId = kpop->insertSeparator();
02052 kpop->insertItem("SuperKaramba", kglobal);
02053 }
02054
02055 void karamba::hideMenuExtension()
02056 {
02057 if(kglobal)
02058 {
02059 kpop->removeItem(trayMenuSeperatorId);
02060 kglobal->removeItem(trayMenuToggleId);
02061 kglobal->removeItem(trayMenuThemeId);
02062 kglobal->removeItem(trayMenuQuitId);
02063
02064 delete kglobal;
02065 kglobal = 0;
02066 }
02067 }
02068
02069 void karamba::slotToggleSystemTray()
02070 {
02071 karambaApp->globalHideSysTray(false);
02072 }
02073
02074 void karamba::slotQuit()
02075 {
02076 karambaApp->globalQuitSuperKaramba();
02077 }
02078
02079 void karamba::slotShowTheme()
02080 {
02081 karambaApp->globalShowThemeDialog();
02082 }
02083
02084 void karamba::setAlwaysOnTop(bool stay)
02085 {
02086 if(stay)
02087 {
02088 onTop = true;
02089 KWin::setState( winId(), NET::KeepAbove );
02090 }
02091 else
02092 {
02093 onTop = false;
02094 KWin::setState( winId(), NET::KeepBelow );
02095 }
02096 }
02097
02098 #include "karamba.moc"