00001
00002
00003
00004
00005 #include "karamba.h"
00006 karamba::karamba(QString fn)
00007 : QWidget( 0,"karamba", Qt::WGroupLeader | WStyle_Customize | WRepaintNoErase| WStyle_NoBorder | WDestructiveClose )
00008 {
00009 themePath = QFileInfo( fn ).dirPath(true);
00010
00011 connect(qApp,SIGNAL(lastWindowClosed()),qApp,SLOT(quit()));
00012
00013
00014
00015 info = new NETWinInfo( qt_xdisplay(), winId(), qt_xrootwin(), NET::WMState );
00016 info->setDesktop( NETWinInfo::OnAllDesktops );
00017 info->setState( NETWinInfo::SkipTaskbar | NETWinInfo::SkipPager,NETWinInfo::SkipTaskbar | NETWinInfo::SkipPager );
00018
00019
00020 kWinModule = new KWinModule();
00021 connect( kWinModule,SIGNAL(currentDesktopChanged(int)), this,SLOT(currentDesktopChanged(int)) );
00022
00023
00024 kpop = new KPopupMenu( this );
00025 accColl = new KActionCollection( this );
00026
00027 kpop->insertItem( SmallIconSet("reload"),tr2i18n("Update"), this, SLOT(updateSensors()), Key_F5 );
00028 toggleLocked = new KToggleAction ( tr2i18n("Toggle &Locked position"), CTRL+Key_L, this,
00029 SLOT( slotToggleLocked() ), accColl , tr2i18n("Locked position") );
00030 accColl->insert(toggleLocked);
00031 toggleLocked->plug(kpop);
00032
00033 kpop->insertSeparator();
00034
00035 kpop->insertItem( SmallIconSet("fileopen"),tr2i18n("&Add new configuration"), this, SLOT(startNewKaramba()), CTRL+Key_O );
00036 kpop->insertItem( SmallIconSet("edit"),tr2i18n("&Edit configuration"),this,SLOT(editConfig()), CTRL+Key_E );
00037 kpop->insertItem( SmallIconSet("reload3"),tr2i18n("&Reload configuration"),this,SLOT(reloadConfig()), CTRL+Key_R );
00038 kpop->insertItem( SmallIconSet("fileclose"),tr2i18n("&Close this configuration"), this, SLOT(close()), CTRL+Key_C );
00039 kpop->insertItem( SmallIconSet("configure"),tr2i18n("C&onfigure Karamba"), this, SLOT(Config()), CTRL+Key_K );
00040
00041 kpop->insertSeparator();
00042
00043 kpop->insertItem( SmallIconSet("exit"),tr2i18n("&Quit"), qApp, SLOT(quit()), CTRL+Key_Q );
00044
00045 kpop->polish();
00046
00047 foundKaramba = false;
00048 onTop = false;
00049 fixedPosition = false;
00050
00051
00052 themeFile = fn;
00053
00054 meterList = new QObjectList();
00055 meterList->setAutoDelete( true );
00056 sensorList = new QObjectList();
00057 sensorList->setAutoDelete( true );
00058 clickList = new QObjectList();
00059 timeList = new QObjectList();
00060 imageList = new QObjectList();
00061
00062
00063 client = kapp->dcopClient();
00064 if (!client->isAttached())
00065 client->attach();
00066 appId = client->registerAs(qApp->name());
00067
00068
00069 this->setBackgroundMode( NoBackground);
00070 if( !onTop)
00071 this->lower();
00072
00073
00074 if( !parseConfig() )
00075 {
00076 setFixedSize(0,0);
00077 QTimer::singleShot( 100, this, SLOT(close()) );
00078
00079 qDebug("false");
00080 }
00081 else
00082 {
00083 kroot = new KarambaRootPixmap((QWidget*)this);
00084 kroot->start();
00085
00086
00087 }
00088 }
00089
00090 karamba::~karamba()
00091 {
00092 if(meterList != 0)
00093 {
00094 meterList->clear();
00095 delete meterList;
00096 }
00097
00098 if( sensorList != 0 )
00099 {
00100 sensorList->clear();
00101 delete sensorList;
00102 }
00103
00104 if( imageList != 0 )
00105 {
00106 imageList->clear();
00107 delete imageList;
00108 }
00109
00110 if( clickList != 0 )
00111 {
00112 clickList->clear();
00113 delete clickList;
00114 }
00115
00116 if( timeList != 0 )
00117 {
00118 timeList->clear();
00119 delete timeList;
00120 }
00121
00122 if( toggleLocked != 0)
00123 delete toggleLocked;
00124 if( accColl != 0)
00125 delete accColl;
00126
00127 if( kpop != 0)
00128 delete kpop;
00129 delete kWinModule;
00130 }
00131
00132 bool karamba::parseConfig()
00133 {
00134 QTimer *m_sysTimer = new QTimer(this);
00135
00136 QFile file(themeFile);
00137 QString line;
00138 QString meter;
00139 int interval = 0;
00140 TextLabel *defaultTextLabel = 0;
00141
00142 if ( file.open(IO_ReadOnly | IO_Translate) )
00143 {
00144 QTextStream t( &file );
00145 QValueStack<QPoint> offsetStack;
00146 offsetStack.push(QPoint(0,0));
00147
00148 int x=0;
00149 int y=0;
00150 int w=0;
00151 int h=0;
00152 while( ( line = t.readLine() ) !=0 )
00153 {
00154 QRegExp rx("^\\s*(\\S+)");
00155 rx.search(line);
00156 meter = rx.cap(1).upper();
00157
00158 x = getInt("X",line)+offsetStack.top().x();
00159 y = getInt("Y",line)+offsetStack.top().y();
00160 w = getInt("W",line);
00161 h = getInt("H",line);
00162
00163
00164
00165
00166 if( meter == "KARAMBA" && !foundKaramba )
00167 {
00168 qDebug("karamba");
00169 toggleLocked->setChecked( getBoolean( "LOCKED", line ) );
00170 slotToggleLocked();
00171
00172
00173 getInt( "X",line );
00174 getInt( "Y",line );
00175
00176 x = ( x < 0 ) ? 0:x;
00177 y = ( y < 0 ) ? 0:y;
00178 move(x,y);
00179
00180
00181 if( w == 0 || h == 0)
00182 {
00183 w = 300;
00184 h = 300;
00185 }
00186 setFixedSize(w,h);
00187
00188 if( getBoolean( "RIGHT", line ) )
00189 {
00190 QDesktopWidget *d = QApplication::desktop();
00191 x = d->width() - w;
00192 }
00193 else
00194 if( getBoolean( "LEFT", line ) )
00195 {
00196 x = 0;
00197 }
00198
00199 if( getBoolean( "BOTTOM", line ) )
00200 {
00201 QDesktopWidget *d = QApplication::desktop();
00202 y = d->height() - h;
00203 }
00204 else
00205 if( getBoolean( "TOP", line ) )
00206 {
00207 y = 0;
00208 }
00209
00210 pm = QPixmap(size());
00211
00212 if( getBoolean("ONTOP", line ) )
00213 {
00214 onTop = true;
00215 KWin::setState( winId(), NET::StaysOnTop );
00216 }
00217
00218 if( getBoolean("TOPBAR", line ) )
00219 {
00220 move(x,0);
00221 KWin::setStrut( winId(), 0, 0, h, 0 );
00222 toggleLocked->setChecked( true );
00223 slotToggleLocked();
00224 toggleLocked->setEnabled(false);
00225
00226 }
00227
00228 if( getBoolean("BOTTOMBAR", line ) )
00229 {
00230 int dh = QApplication::desktop()->height();
00231 move( x, dh - h );
00232 KWin::setStrut( winId(), 0, 0, 0, h );
00233 toggleLocked->setChecked( true );
00234 slotToggleLocked();
00235 toggleLocked->setEnabled(false);
00236
00237
00238 }
00239
00240
00241
00242
00243 interval = getInt("INTERVAL",line);
00244 interval = ( interval == 0 ) ? 5000 : interval;
00245 foundKaramba = true;
00246 }
00247
00248 if( meter == "THEME" )
00249 {
00250 QString path = getString( "PATH", line );
00251 QFileInfo info(path);
00252 if( info.isRelative())
00253 path = themePath +"/" + path;
00254 qDebug("path: "+path);
00255 (new karamba( path ))->show();
00256 }
00257
00258 if( meter == "<GROUP>" )
00259 {
00260 int offsetX = offsetStack.top().x();
00261 int offsetY = offsetStack.top().y();
00262 offsetStack.push( QPoint( offsetX + getInt("X",line),
00263 offsetY + getInt("Y",line) ) );
00264 }
00265
00266 if( meter == "</GROUP>" )
00267 {
00268 offsetStack.pop();
00269 }
00270
00271 if( meter == "CLICKAREA" )
00272 {
00273 if( !hasMouseTracking() )
00274 setMouseTracking(true);
00275 ClickArea *tmp = new ClickArea( x, y, w, h );
00276 tmp->setOnClick( getString( "ONCLICK", line ) );
00277
00278 setSensor( line, (Meter*) tmp );
00279 clickList->append( tmp );
00280 if( getBoolean( "PREVIEW", line ) )
00281 meterList->append( tmp );
00282 }
00283
00284
00285 if(meter == "SENSOR=PROGRAM")
00286 {
00287 setSensor(line, 0 );
00288 }
00289
00290 if(meter == "IMAGE")
00291 {
00292 QString file = getString("PATH",line);
00293 QString file_roll = getString("PATHROLL",line);
00294 int xon = getInt("XROLL",line);
00295 int yon = getInt("YROLL",line);
00296 QString tiptext = getString("TOOLTIP",line);
00297 xon = ( xon <= 0 ) ? x:xon;
00298 yon = ( yon <= 0 ) ? y:yon;
00299
00300 ImageLabel *tmp = new ImageLabel(x,y,0,0);
00301 tmp->setThemePath( themePath );
00302 tmp->setValue( file );
00303 tmp->parseImages(file, file_roll, x,y, xon, yon);
00304 tmp->setKaramba(this);
00305
00306 if (!tiptext.isEmpty())
00307 tmp->setTooltip(tiptext);
00308
00309
00310
00311
00312
00313 setSensor(line, (Meter*) tmp );
00314 meterList->append (tmp );
00315 imageList->append (tmp );
00316 }
00317
00318 if( meter == "DEFAULTFONT" )
00319 {
00320 int r,g,b;
00321
00322 delete defaultTextLabel;
00323 defaultTextLabel = new TextLabel(x, y, w, h );
00324
00325 get3Int( "COLOR", line, r, g, b );
00326 defaultTextLabel->setColor( r, g, b );
00327 get3Int( "BGCOLOR", line, r, g, b );
00328 defaultTextLabel->setBGColor( r, g, b );
00329
00330 defaultTextLabel->setFont( getString( "FONT", line ) );
00331 defaultTextLabel->setFontSize( getInt( "FONTSIZE", line ) );
00332 defaultTextLabel->setAlignment( getString( "ALIGN", line ) );
00333 defaultTextLabel->setFixedPitch( getBoolean( "FIXEDPITCH", line ) );
00334 defaultTextLabel->setShadow( getInt( "SHADOW", line ) );
00335
00336
00337
00338 qDebug(QString::number( getInt( "SHADOW", line ) ));
00339
00340 qDebug("default font: " + defaultTextLabel->getFont());
00341 }
00342
00343
00344 if(meter == "TEXT")
00345 {
00346 int r,g,b;
00347
00348 TextLabel *tmp = new TextLabel(x, y, w, h );
00349 bool paramFound = false;
00350
00351 get3Int( "COLOR", line, r, g, b, paramFound );
00352 if ( paramFound || !defaultTextLabel )
00353 tmp->setColor ( r, g, b );
00354 else
00355 if ( defaultTextLabel )
00356 {
00357 defaultTextLabel->getColor().rgb ( &r, &g, &b );
00358 tmp->setColor( r, g, b );
00359 }
00360
00361 get3Int( "BGCOLOR", line, r, g, b, paramFound );
00362 if ( paramFound || !defaultTextLabel )
00363 tmp->setBGColor( r, g, b );
00364 else
00365 if ( defaultTextLabel )
00366 {
00367 defaultTextLabel->getBGColor().rgb ( &r, &g, &b );
00368 tmp->setBGColor( r, g, b );
00369 }
00370
00371 QString dFont = getString("FONT", line, paramFound);
00372 if( paramFound || !defaultTextLabel )
00373 tmp->setFont( dFont );
00374 else
00375 if( defaultTextLabel )
00376 tmp->setFont( defaultTextLabel->getFont() );
00377
00378
00379 int dFontSize = getInt( "FONTSIZE", line, paramFound );
00380 if( paramFound || !defaultTextLabel )
00381 tmp->setFontSize( dFontSize );
00382 else
00383 if( defaultTextLabel )
00384 tmp->setFontSize( defaultTextLabel->getFontSize() );
00385
00386 int dMove = getInt( "MOVE", line, paramFound );
00387 if( paramFound || !defaultTextLabel )
00388 tmp->setMove( dMove );
00389
00390 int dMaxMove = getInt( "MAXMOVE", line, paramFound );
00391 if( paramFound || !defaultTextLabel )
00392 tmp->setMaxMove( dMaxMove );
00393
00394 QString dAlign = getString( "ALIGN", line, paramFound );
00395 if( paramFound || !defaultTextLabel )
00396 tmp->setAlignment( dAlign );
00397 else
00398 if( defaultTextLabel )
00399 tmp->setAlignment( defaultTextLabel->getAlignment() );
00400
00401 bool dFp = getBoolean( "FIXEDPITCH", line, paramFound );
00402 if( paramFound || !defaultTextLabel )
00403 tmp->setFixedPitch( dFp );
00404 else
00405 if( defaultTextLabel )
00406 tmp->setFixedPitch( defaultTextLabel->getFixedPitch() );
00407
00408 int dShadow = getInt( "SHADOW", line, paramFound );
00409 if( paramFound || !defaultTextLabel )
00410 tmp->setShadow( dShadow );
00411 else
00412 if( defaultTextLabel )
00413 tmp->setShadow( defaultTextLabel->getShadow() );
00414
00415 tmp->setValue( getString( "VALUE", line ) );
00416
00417 setSensor( line, (Meter*)tmp );
00418 meterList->append ( tmp );
00419
00420 }
00421
00422 if(meter == "BAR")
00423 {
00424 Bar *tmp =
00425 new Bar( x, y, w, h );
00426 tmp->setThemePath( themePath );
00427 tmp->setImage( getString( "PATH", line ) );
00428 tmp->setVertical( getBoolean( "VERTICAL", line ) );
00429 bool maxFound = false;
00430 int max = getInt( "MAX", line, maxFound );
00431 if( maxFound )
00432 tmp->setMax( max );
00433 bool minFound = false;
00434 int min = getInt( "MIN", line, minFound );
00435 if( minFound )
00436 tmp->setMin( min );
00437 tmp->setValue( getInt( "VALUE", line ) );
00438 setSensor( line, (Meter*)tmp );
00439 meterList->append ( tmp );
00440 }
00441
00442 if(meter == "GRAPH")
00443 {
00444 int r, g, b;
00445 int points = getInt("POINTS",line);
00446 get3Int("COLOR", line, r, g, b);
00447
00448 Graph *tmp = new Graph( x, y, w, h, points );
00449 bool maxFound = false;
00450 int max = getInt( "MAX", line, maxFound );
00451 if( maxFound )
00452 tmp->setMax( max );
00453 bool minFound = false;
00454 int min = getInt( "MIN", line, minFound );
00455 if( minFound )
00456 tmp->setMin( min );
00457
00458 tmp->setColor( r , g, b );
00459
00460 setSensor( line, (Graph*)tmp );
00461 meterList->append ( tmp );
00462 }
00463 }
00464 }
00465 if( !foundKaramba )
00466 {
00467
00468
00469
00470 return false;
00471 }
00472 else
00473 {
00474 connect(m_sysTimer, SIGNAL(timeout()), SLOT(step()));
00475
00476 interval = interval == 0 ? 1000 : interval;
00477 m_sysTimer->start(interval);
00478 QTimer::singleShot( 1000, this, SLOT(step()) );
00479 QTimer::singleShot( 5000, this, SLOT(step()) );
00480 QTimer::singleShot( 10000, this, SLOT(step()) );
00481
00482 if( !onTop )
00483 lowerTimer.start();
00484
00485
00486 return true;
00487 }
00488 }
00489
00490 void karamba::startNewKaramba()
00491 {
00492 QStringList fileNames;
00493 KSimpleConfig conf("karambarc",true);
00494 conf.setGroup("karamba");
00495 QString dDir = conf.readEntry("ThemeDir", "/usr/share/apps/karamba/themes/");
00496 fileNames = KFileDialog::getOpenFileNames(dDir, "*.theme", 0, "Open configurations");
00497 for ( QStringList::Iterator it = fileNames.begin(); it != fileNames.end(); ++it )
00498 {
00499 QFileInfo file( *it );
00500 if( file.exists() )
00501 {
00502 (new karamba( *it ))->show();
00503 }
00504 }
00505 }
00506
00507 void karamba::Config(){
00508 KarambaConf *kc = 0;
00509 kc = new KarambaConf(0, "karconf", false, 0);
00510 kc->show();
00511 }
00512
00513 void karamba::reloadConfig()
00514 {
00515 QFileInfo file( themeFile );
00516 qDebug(themeFile);
00517 if( file.exists() )
00518 {
00519 (new karamba( themeFile ))->show();
00520 }
00521 close();
00522 }
00523
00524 void karamba::editConfig()
00525 {
00526 QFileInfo fileInfo( themeFile );
00527 QString path;
00528
00529 if( fileInfo.isRelative() )
00530 {
00531 path = themePath + "/" + themeFile;
00532 }
00533 else
00534 {
00535 path = themeFile;
00536 }
00537
00538 KRun::runURL( KURL( path ), "text/plain" );
00539
00540 }
00541
00542
00543 int karamba::getInt(QString w, QString &line )
00544 {
00545 bool b;
00546 return getInt( w, line, b );
00547 }
00548
00549 int karamba::getInt(QString w, QString &line, bool &found )
00550 {
00551 QRegExp rx( "\\W+" + w +"=([-]?\\d+)", false );
00552 found = (rx.search(line)==-1)?false:true;
00553 return rx.cap(1).toInt();
00554 }
00555
00556 void karamba::get3Int(QString w, QString &line, int &a, int &b, int &c )
00557 {
00558 bool bo;
00559 get3Int ( w, line, a, b, c, bo );
00560 }
00561
00562 void karamba::get3Int(QString w, QString &line, int &a, int &b, int &c, bool &found )
00563 {
00564 QRegExp rx( "\\W+" + w + "=([-]?\\d+),([-]?\\d+),([-]?\\d+)", false );
00565 found = (rx.search(line)==-1)?false:true;
00566 a = rx.cap(1).toInt();
00567 b = rx.cap(2).toInt();
00568 c = rx.cap(3).toInt();
00569 }
00570
00571 QString karamba::getString(QString w, QString &line)
00572 {
00573 bool b;
00574 return getString ( w, line, b );
00575 }
00576
00577 QString karamba::getString(QString w, QString &line, bool &found)
00578 {
00579 QRegExp rx( "\\W+" + w + "=\"([^\"]*)\"", false );
00580 found = (rx.search(line)==-1)?false:true;
00581 if (rx.cap(1).isEmpty())
00582 {
00583 rx = QRegExp(w + "=(\\S+)", false);
00584 rx.search(line);
00585 return rx.cap(1);
00586 }
00587 else
00588 {
00589 return rx.cap(1);
00590 }
00591
00592 }
00593
00594 bool karamba::getBoolean( QString w, QString &line )
00595 {
00596 bool b;
00597 return getBoolean ( w, line, b );
00598 }
00599
00600 bool karamba::getBoolean( QString w, QString &line, bool &found )
00601 {
00602 return ( getString( w, line, found ).lower() == "true")?true:false;
00603 }
00604
00605 void karamba::setSensor(QString &line, Meter* meter)
00606 {
00607 Sensor* sensor = 0;
00608
00609 QString sens = getString("SENSOR",line).upper();
00610
00611 if( sens == "CPU" )
00612 {
00613 QString cpuNbr = getString( "CPU", line );
00614 sensor = sensorMap["CPU"+cpuNbr];
00615 if (sensor == 0)
00616 {
00617 int interval = getInt("INTERVAL",line);
00618 interval = (interval == 0)?1000:interval;
00619 sensor = ( sensorMap["CPU"+cpuNbr] = new CPUSensor( cpuNbr, interval ) );
00620 sensorList->append( sensor );
00621 }
00622 SensorParams *sp = new SensorParams(meter);
00623 sp->addParam("FORMAT",getString("FORMAT",line));
00624 sp->addParam("DECIMALS",getString("DECIMALS",line));
00625
00626 sensor->addMeter(sp);
00627 sensor->setMaxValue(sp);
00628
00629 }
00630
00631 if( sens == "MEMORY" )
00632 {
00633 sensor = sensorMap["MEMORY"];
00634 if (sensor == 0)
00635 {
00636 int interval = getInt("INTERVAL",line);
00637 interval = (interval == 0)?3000:interval;
00638 sensor = ( sensorMap["MEMORY"] = new MemSensor( interval ) );
00639 sensorList->append( sensor );
00640 }
00641 SensorParams *sp = new SensorParams(meter);
00642 sp->addParam("FORMAT",getString("FORMAT",line));
00643
00644 sensor->addMeter(sp);
00645 sensor->setMaxValue(sp);
00646 }
00647
00648
00649 if( sens == "DISK" )
00650 {
00651 sensor = sensorMap["DISK"];
00652 if (sensor == 0)
00653 {
00654 int interval = getInt("INTERVAL",line);
00655 interval = (interval == 0)?5000:interval;
00656 sensor = ( sensorMap["DISK"] = new DiskSensor( interval ) );
00657 sensorList->append( sensor );
00658 }
00659
00660 SensorParams *sp = new SensorParams(meter);
00661 QString mntPt = getString("MOUNTPOINT",line);
00662 if( mntPt == "" )
00663 mntPt = "/";
00664
00665 sp->addParam("MOUNTPOINT",mntPt);
00666 sp->addParam("FORMAT",getString("FORMAT",line));
00667 sensor->addMeter(sp);
00668 sensor->setMaxValue(sp);
00669 }
00670
00671 if( sens == "NETWORK")
00672 {
00673 int interval = getInt("INTERVAL",line );
00674 interval = (interval == 0)?2000:interval;
00675 QString device = getString("DEVICE", line );
00676 sensor = sensorMap["NETWORK"+device];
00677 if (sensor == 0)
00678 {
00679 sensor = ( sensorMap["NETWORK"+device] = new NetworkSensor( device, interval ) );
00680 sensorList->append( sensor );
00681 }
00682 SensorParams *sp = new SensorParams(meter);
00683 sp->addParam( "FORMAT", getString( "FORMAT", line ) );
00684 sp->addParam( "DECIMALS", getString( "DECIMALS", line ) );
00685 sensor->addMeter(sp);
00686 }
00687
00688 if( sens == "UPTIME" )
00689 {
00690 sensor = sensorMap["UPTIME"];
00691 if (sensor == 0)
00692 {
00693 int interval = getInt("INTERVAL",line);
00694 interval = (interval == 0)?60000:interval;
00695 sensor = ( sensorMap["UPTIME"] = new UptimeSensor( interval ));
00696 sensorList->append( sensor );
00697
00698 }
00699 SensorParams *sp = new SensorParams(meter);
00700 sp->addParam( "FORMAT", getString( "FORMAT", line ) );
00701 sensor->addMeter(sp);
00702 }
00703
00704 if( sens == "SENSOR" )
00705 {
00706 sensor = sensorMap["SENSOR"];
00707 if (sensor == 0)
00708 {
00709 int interval = getInt("INTERVAL",line);
00710 interval = (interval == 0)?30000:interval;
00711 sensor = ( sensorMap["SENSOR"] = new SensorSensor( interval ) );
00712 sensorList->append( sensor );
00713 }
00714 SensorParams *sp = new SensorParams(meter);
00715 sp->addParam("FORMAT",getString("FORMAT",line));
00716 sp->addParam("TYPE",getString("TYPE",line));
00717 sensor->addMeter(sp);
00718 }
00719
00720
00721 if( sens == "TEXTFILE" )
00722 {
00723 QString path = getString( "PATH", line );
00724 bool rdf = getBoolean( "RDF", line );
00725 sensor = sensorMap["TEXTFILE"+path];
00726 if (sensor == 0)
00727 {
00728 int interval = getInt( "INTERVAL", line );
00729 interval = ( interval == 0 )?60000:interval;
00730 QString encoding = getString( "ENCODING", line );
00731
00732 sensor = ( sensorMap["TEXTFILE"+path] =
00733 new TextFileSensor( path, rdf, interval, encoding ) );
00734 sensorList->append( sensor );
00735 }
00736 SensorParams *sp = new SensorParams(meter);
00737 sp->addParam("LINE",QString::number(getInt("LINE",line)));
00738 sensor->addMeter(sp);
00739 }
00740
00741
00742 if( sens == "TIME")
00743 {
00744 sensor = sensorMap["DATE"];
00745 if (sensor == 0)
00746 {
00747 int interval = getInt("INTERVAL",line);
00748 interval = (interval == 0)?60000:interval;
00749 sensor = ( sensorMap["DATE"] = new DateSensor( interval ) );
00750 sensorList->append( sensor );
00751 timeList->append( sensor );
00752 }
00753 SensorParams *sp = new SensorParams(meter);
00754 sp->addParam("FORMAT",getString("FORMAT",line));
00755 sp->addParam("CALWIDTH",getString("CALWIDTH",line));
00756 sp->addParam("CALHEIGHT",getString("CALHEIGHT",line));
00757 sensor->addMeter(sp);
00758 }
00759
00760 #ifdef HAVE_XMMS
00761
00762 if( sens == "XMMS" )
00763 {
00764 sensor = sensorMap["XMMS"];
00765 if (sensor == 0)
00766 {
00767 int interval = getInt("INTERVAL",line);
00768 interval = (interval == 0)?1000:interval;
00769 QString encoding = getString( "ENCODING", line );
00770
00771 sensor = ( sensorMap["XMMS"] = new XMMSSensor( interval, encoding ) );
00772 sensorList->append( sensor );
00773 }
00774 SensorParams *sp = new SensorParams(meter);
00775 sp->addParam("FORMAT",getString("FORMAT",line));
00776 sp->addParam("ONCLICK",getString("ONCLICK",line));
00777 sp->addParam("X",getString("X",line));
00778 sp->addParam("Y",getString("Y",line));
00779 sensor->addMeter(sp);
00780 sensor->setMaxValue(sp);
00781
00782 }
00783 #endif // HAVE_XMMS
00784
00785
00786 if( sens == "NOATUN" )
00787 {
00788 sensor = sensorMap["NOATUN"];
00789 if (sensor == 0)
00790 {
00791 int interval = getInt("INTERVAL",line);
00792 interval = (interval == 0)?1000:interval;
00793 sensor = ( sensorMap["NOATUN"] = new NoatunSensor( interval, client ) );
00794 sensorList->append( sensor );
00795 }
00796 SensorParams *sp = new SensorParams(meter);
00797 sp->addParam("FORMAT",getString("FORMAT",line));
00798 sensor->addMeter(sp);
00799 sensor->setMaxValue(sp);
00800 }
00801
00802 if( sens == "PROGRAM")
00803 {
00804 QString progName = getString("PROGRAM",line);
00805 sensor = sensorMap["PROGRAM"+progName];
00806 if (sensor == 0)
00807 {
00808 int interval = getInt("INTERVAL",line);
00809 interval = (interval == 0)?3600000:interval;
00810 QString encoding = getString( "ENCODING", line );
00811
00812 sensor = (sensorMap["PROGRAM"+progName] =
00813 new ProgramSensor( progName, interval, encoding ) );
00814 sensorList->append( sensor );
00815 }
00816 SensorParams *sp = new SensorParams(meter);
00817 sp->addParam( "LINE", QString::number( getInt( "LINE", line ) ) );
00818 sp->addParam( "THEMAPATH", themePath );
00819 sensor->addMeter(sp);
00820 }
00821
00822 if (sensor != 0)
00823 {
00824 QTimer::singleShot( 0, sensor, SLOT(update()) );
00825 sensor->start();
00826 }
00827 }
00828
00829
00830 void karamba::passClick( QMouseEvent *e )
00831 {
00832 QObjectListIt it( *clickList );
00833 while ( it != 0 )
00834 {
00835 (( ClickArea* ) *it)->click( e );
00836 ++it;
00837 }
00838
00839 QObjectListIt it2( *timeList );
00840 while ( it2 != 0 )
00841 {
00842 (( DateSensor* ) *it2)->toggleCalendar( e );
00843 ++it2;
00844 }
00845 }
00846
00847 void karamba::mousePressEvent( QMouseEvent *e )
00848 {
00849
00850 if( e->button() == RightButton )
00851 {
00852
00853 kpop->exec(QCursor::pos());
00854 }
00855 else
00856 {
00857 clickPos = e->pos();
00858 if( locked )
00859 passClick( e );
00860 if( !onTop )
00861 lower();
00862 }
00863 }
00864
00865
00866 void karamba::mouseReleaseEvent( QMouseEvent *e )
00867 {
00868
00869
00870
00871
00872
00873
00874 clickPos = e->pos();
00875 qDebug("Click X="+QString::number( clickPos.x() )+" Y="+QString::number( clickPos .y() ) );
00876 qDebug("Window X="+QString::number( ( e->globalPos() - clickPos ).x())+" Y="+QString::number( ( e->globalPos() - clickPos ).y()));
00877
00878
00879 step();
00880 }
00881
00882 void karamba::mouseDoubleClickEvent( QMouseEvent *e )
00883 {
00884 if( !locked )
00885 {
00886 passClick( e );
00887 }
00888 }
00889
00890
00891 void karamba::mouseMoveEvent( QMouseEvent *e )
00892 {
00893
00894
00895
00896 if( e->state() != 0 && e->state() < 16 && !locked )
00897 {
00898 move( e->globalPos() - clickPos );
00899 }
00900 else
00901 {
00902
00903 QObjectListIt it( *clickList );
00904 bool insideArea = false;
00905 while ( it != 0 && !insideArea )
00906 {
00907 insideArea = (((ClickArea*) *it)->getRectangle()).contains(e->pos());
00908 ++it;
00909 }
00910 if(insideArea)
00911 {
00912 if( cursor().shape() != PointingHandCursor )
00913 setCursor( PointingHandCursor );
00914 }
00915 else
00916 {
00917 if( cursor().shape() != ArrowCursor )
00918 setCursor( ArrowCursor );
00919 }
00920
00921 QObjectListIt image_it( *imageList);
00922 while ( image_it != 0 )
00923 {
00924 ((ImageLabel*) *image_it)->rolloverImage(e);
00925 ++image_it;
00926 }
00927 }
00928 }
00929
00930 void karamba::closeEvent ( QCloseEvent * )
00931 {
00932 this->close(true);
00933 delete this;
00934 }
00935
00936 void karamba::paintEvent ( QPaintEvent *e)
00937 {
00938 if( !onTop )
00939 if( lowerTimer.elapsed() > 100 )
00940 {
00941 this->lower();
00942 lowerTimer.restart();
00943 }
00944 QRect rect = e->rect();
00945 bitBlt(this,rect.topLeft(),&pm,rect,Qt::CopyROP);
00946 }
00947
00948 void karamba::updateSensors()
00949 {
00950 QObjectListIt it( *sensorList );
00951 while ( it != 0 )
00952 {
00953 ((Sensor*) *it)->update();
00954 ++it;
00955 }
00956 QTimer::singleShot( 500, this, SLOT(step()) );
00957 }
00958
00959 void karamba::updateBackground(KSharedPixmap* kpm)
00960 {
00961 background = QPixmap(*kpm);
00962 step();
00963 }
00964
00965 void karamba::currentDesktopChanged( int )
00966 {
00967 kroot->repaint( true );
00968 }
00969
00970
00971
00972 void karamba::step()
00973 {
00974 pm = QPixmap(size());
00975
00976 QObjectListIt it( *meterList );
00977 p.begin(&pm);
00978 bitBlt(&pm,0,0,&background,0,Qt::CopyROP);
00979
00980 while ( it != 0 )
00981 {
00982 ((Meter*) *it)->mUpdate(&p);
00983 ++it;
00984 }
00985 p.end();
00986 update();
00987
00988 }
00989
00990 void karamba::slotToggleLocked()
00991 {
00992 qDebug("toggleLocked");
00993 locked = toggleLocked->isChecked();
00994 if( locked )
00995 {
00996 toggleLocked->setIconSet(SmallIconSet("encrypted"));
00997 }
00998 else
00999 {
01000 toggleLocked->setIconSet(SmallIconSet("lockoverlay"));
01001 }
01002
01003 }
01004
01005
01006 #include "karamba.moc"