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
00010 themePath = QFileInfo( fn ).dirPath(true);
00011
00012 connect(qApp,SIGNAL(lastWindowClosed()),qApp,SLOT(quit()));
00013
00014
00015
00016 info = new NETWinInfo( qt_xdisplay(), winId(), qt_xrootwin(), NET::WMState );
00017 info->setDesktop( NETWinInfo::OnAllDesktops );
00018 info->setState( NETWinInfo::SkipTaskbar | NETWinInfo::SkipPager,NETWinInfo::SkipTaskbar | NETWinInfo::SkipPager );
00019
00020
00021 kWinModule = new KWinModule();
00022 connect( kWinModule,SIGNAL(currentDesktopChanged(int)), this,SLOT(currentDesktopChanged(int)) );
00023
00024
00025 kpop = new KPopupMenu( this );
00026 accColl = new KActionCollection( this );
00027
00028 kpop->insertItem( SmallIconSet("reload"),tr2i18n("Update"), this, SLOT(updateSensors()), Key_F5 );
00029 toggleLocked = new KToggleAction ( tr2i18n("Toggle &Locked position"), CTRL+Key_L, this,
00030 SLOT( slotToggleLocked() ), accColl , tr2i18n("Locked position") );
00031 accColl->insert(toggleLocked);
00032 toggleLocked->plug(kpop);
00033
00034 kpop->insertSeparator();
00035
00036 kpop->insertItem( SmallIconSet("fileopen"),tr2i18n("&Add new configuration"), this, SLOT(startNewKaramba()), CTRL+Key_O );
00037 kpop->insertItem( SmallIconSet("edit"),tr2i18n("&Edit configuration"),this,SLOT(editConfig()), CTRL+Key_E );
00038 kpop->insertItem( SmallIconSet("reload3"),tr2i18n("&Reload configuration"),this,SLOT(reloadConfig()), CTRL+Key_R );
00039 kpop->insertItem( SmallIconSet("fileclose"),tr2i18n("&Close this configuration"), this, SLOT(close()), CTRL+Key_C );
00040 kpop->insertItem( SmallIconSet("configure"),tr2i18n("C&onfigure Karamba"), this, SLOT(Config()), CTRL+Key_K );
00041
00042 kpop->insertSeparator();
00043
00044 kpop->insertItem( SmallIconSet("exit"),tr2i18n("&Quit"), qApp, SLOT(quit()), CTRL+Key_Q );
00045
00046 kpop->polish();
00047
00048 foundKaramba = false;
00049 onTop = false;
00050 fixedPosition = false;
00051
00052
00053 themeFile = fn;
00054
00055 meterList = new QObjectList();
00056 meterList->setAutoDelete( true );
00057 sensorList = new QObjectList();
00058 sensorList->setAutoDelete( true );
00059 clickList = new QObjectList();
00060 timeList = new QObjectList();
00061 imageList = new QObjectList();
00062
00063
00064 client = kapp->dcopClient();
00065 if (!client->isAttached())
00066 client->attach();
00067 appId = client->registerAs(qApp->name());
00068
00069
00070 this->setBackgroundMode( NoBackground);
00071 if( !onTop)
00072 this->lower();
00073
00074
00075 if( !parseConfig() )
00076 {
00077 setFixedSize(0,0);
00078 QTimer::singleShot( 100, this, SLOT(close()) );
00079
00080 qDebug("false");
00081 }
00082 else
00083 {
00084 kroot = new KarambaRootPixmap((QWidget*)this);
00085 kroot->start();
00086
00087
00088 }
00089 }
00090
00091 karamba::~karamba()
00092 {
00093 if(meterList != 0)
00094 {
00095 meterList->clear();
00096 delete meterList;
00097 }
00098
00099 if( sensorList != 0 )
00100 {
00101 sensorList->clear();
00102 delete sensorList;
00103 }
00104
00105 if( imageList != 0 )
00106 {
00107 imageList->clear();
00108 delete imageList;
00109 }
00110
00111 if( clickList != 0 )
00112 {
00113 clickList->clear();
00114 delete clickList;
00115 }
00116
00117 if( timeList != 0 )
00118 {
00119 timeList->clear();
00120 delete timeList;
00121 }
00122
00123 if( toggleLocked != 0)
00124 delete toggleLocked;
00125 if( accColl != 0)
00126 delete accColl;
00127
00128 if( kpop != 0)
00129 delete kpop;
00130 delete kWinModule;
00131 }
00132
00133 bool karamba::parseConfig()
00134 {
00135 QTimer *m_sysTimer = new QTimer(this);
00136
00137 QFile file(themeFile);
00138 QString line;
00139 QString meter;
00140 int interval = 0;
00141 TextLabel *defaultTextLabel = 0;
00142
00143 if ( file.open(IO_ReadOnly | IO_Translate) )
00144 {
00145 QTextStream t( &file );
00146 QValueStack<QPoint> offsetStack;
00147 offsetStack.push(QPoint(0,0));
00148
00149 int x=0;
00150 int y=0;
00151 int w=0;
00152 int h=0;
00153 while( ( line = t.readLine() ) !=0 )
00154 {
00155 QRegExp rx("^\\s*(\\S+)");
00156 rx.search(line);
00157 meter = rx.cap(1).upper();
00158
00159 x = getInt("X",line)+offsetStack.top().x();
00160 y = getInt("Y",line)+offsetStack.top().y();
00161 w = getInt("W",line);
00162 h = getInt("H",line);
00163
00164
00165
00166
00167 if( meter == "KARAMBA" && !foundKaramba )
00168 {
00169 qDebug("karamba");
00170 toggleLocked->setChecked( getBoolean( "LOCKED", line ) );
00171 slotToggleLocked();
00172
00173
00174 getInt( "X",line );
00175 getInt( "Y",line );
00176
00177 x = ( x < 0 ) ? 0:x;
00178 y = ( y < 0 ) ? 0:y;
00179 move(x,y);
00180
00181
00182 if( w == 0 || h == 0)
00183 {
00184 w = 300;
00185 h = 300;
00186 }
00187 setFixedSize(w,h);
00188
00189 if( getBoolean( "RIGHT", line ) )
00190 {
00191 QDesktopWidget *d = QApplication::desktop();
00192 x = d->width() - w;
00193 }
00194 else
00195 if( getBoolean( "LEFT", line ) )
00196 {
00197 x = 0;
00198 }
00199
00200 if( getBoolean( "BOTTOM", line ) )
00201 {
00202 QDesktopWidget *d = QApplication::desktop();
00203 y = d->height() - h;
00204 }
00205 else
00206 if( getBoolean( "TOP", line ) )
00207 {
00208 y = 0;
00209 }
00210
00211 pm = QPixmap(size());
00212
00213 if( getBoolean("ONTOP", line ) )
00214 {
00215 onTop = true;
00216 KWin::setState( winId(), NET::StaysOnTop );
00217 }
00218
00219 if( getBoolean("TOPBAR", line ) )
00220 {
00221 move(x,0);
00222 KWin::setStrut( winId(), 0, 0, h, 0 );
00223 toggleLocked->setChecked( true );
00224 slotToggleLocked();
00225 toggleLocked->setEnabled(false);
00226
00227 }
00228
00229 if( getBoolean("BOTTOMBAR", line ) )
00230 {
00231 int dh = QApplication::desktop()->height();
00232 move( x, dh - h );
00233 KWin::setStrut( winId(), 0, 0, 0, h );
00234 toggleLocked->setChecked( true );
00235 slotToggleLocked();
00236 toggleLocked->setEnabled(false);
00237
00238
00239 }
00240
00241
00242
00243
00244 interval = getInt("INTERVAL",line);
00245 interval = ( interval == 0 ) ? 5000 : interval;
00246 foundKaramba = true;
00247 }
00248
00249 if( meter == "THEME" )
00250 {
00251 QString path = getString( "PATH", line );
00252 QFileInfo info(path);
00253 if( info.isRelative())
00254 path = themePath +"/" + path;
00255 qDebug("path: "+path);
00256 (new karamba( path ))->show();
00257 }
00258
00259 if( meter == "<GROUP>" )
00260 {
00261 int offsetX = offsetStack.top().x();
00262 int offsetY = offsetStack.top().y();
00263 offsetStack.push( QPoint( offsetX + getInt("X",line),
00264 offsetY + getInt("Y",line) ) );
00265 }
00266
00267 if( meter == "</GROUP>" )
00268 {
00269 offsetStack.pop();
00270 }
00271
00272 if( meter == "CLICKAREA" )
00273 {
00274 if( !hasMouseTracking() )
00275 setMouseTracking(true);
00276 ClickArea *tmp = new ClickArea( x, y, w, h );
00277 tmp->setOnClick( getString( "ONCLICK", line ) );
00278
00279 setSensor( line, (Meter*) tmp );
00280 clickList->append( tmp );
00281 if( getBoolean( "PREVIEW", line ) )
00282 meterList->append( tmp );
00283 }
00284
00285
00286 if(meter == "SENSOR=PROGRAM")
00287 {
00288 setSensor(line, 0 );
00289 }
00290
00291 if(meter == "IMAGE")
00292 {
00293 QString file = getString("PATH",line);
00294 QString file_roll = getString("PATHROLL",line);
00295 int xon = getInt("XROLL",line);
00296 int yon = getInt("YROLL",line);
00297 QString tiptext = getString("TOOLTIP",line);
00298 xon = ( xon <= 0 ) ? x:xon;
00299 yon = ( yon <= 0 ) ? y:yon;
00300
00301 ImageLabel *tmp = new ImageLabel(x,y,0,0);
00302 tmp->setThemePath( themePath );
00303 tmp->setValue( file );
00304 tmp->parseImages(file, file_roll, x,y, xon, yon);
00305 tmp->setKaramba(this);
00306
00307 if (!tiptext.isEmpty())
00308 tmp->setTooltip(tiptext);
00309
00310
00311
00312
00313
00314 setSensor(line, (Meter*) tmp );
00315 meterList->append (tmp );
00316 imageList->append (tmp );
00317 }
00318
00319 if( meter == "DEFAULTFONT" )
00320 {
00321 int r,g,b;
00322
00323 delete defaultTextLabel;
00324 defaultTextLabel = new TextLabel(x, y, w, h );
00325
00326 get3Int( "COLOR", line, r, g, b );
00327 defaultTextLabel->setColor( r, g, b );
00328 get3Int( "BGCOLOR", line, r, g, b );
00329 defaultTextLabel->setBGColor( r, g, b );
00330
00331 defaultTextLabel->setFont( getString( "FONT", line ) );
00332 defaultTextLabel->setFontSize( getInt( "FONTSIZE", line ) );
00333 defaultTextLabel->setAlignment( getString( "ALIGN", line ) );
00334 defaultTextLabel->setFixedPitch( getBoolean( "FIXEDPITCH", line ) );
00335 defaultTextLabel->setShadow( getInt( "SHADOW", line ) );
00336
00337
00338
00339 qDebug(QString::number( getInt( "SHADOW", line ) ));
00340
00341 qDebug("default font: " + defaultTextLabel->getFont());
00342 }
00343
00344
00345 if(meter == "TEXT")
00346 {
00347 int r,g,b;
00348
00349 TextLabel *tmp = new TextLabel(x, y, w, h );
00350 bool paramFound = false;
00351
00352 get3Int( "COLOR", line, r, g, b, paramFound );
00353 if ( paramFound || !defaultTextLabel )
00354 tmp->setColor ( r, g, b );
00355 else
00356 if ( defaultTextLabel )
00357 {
00358 defaultTextLabel->getColor().rgb ( &r, &g, &b );
00359 tmp->setColor( r, g, b );
00360 }
00361
00362 get3Int( "BGCOLOR", line, r, g, b, paramFound );
00363 if ( paramFound || !defaultTextLabel )
00364 tmp->setBGColor( r, g, b );
00365 else
00366 if ( defaultTextLabel )
00367 {
00368 defaultTextLabel->getBGColor().rgb ( &r, &g, &b );
00369 tmp->setBGColor( r, g, b );
00370 }
00371
00372 QString dFont = getString("FONT", line, paramFound);
00373 if( paramFound || !defaultTextLabel )
00374 tmp->setFont( dFont );
00375 else
00376 if( defaultTextLabel )
00377 tmp->setFont( defaultTextLabel->getFont() );
00378
00379
00380 int dFontSize = getInt( "FONTSIZE", line, paramFound );
00381 if( paramFound || !defaultTextLabel )
00382 tmp->setFontSize( dFontSize );
00383 else
00384 if( defaultTextLabel )
00385 tmp->setFontSize( defaultTextLabel->getFontSize() );
00386
00387 int dMove = getInt( "MOVE", line, paramFound );
00388 if( paramFound || !defaultTextLabel )
00389 tmp->setMove( dMove );
00390
00391 int dMaxMove = getInt( "MAXMOVE", line, paramFound );
00392 if( paramFound || !defaultTextLabel )
00393 tmp->setMaxMove( dMaxMove );
00394
00395 QString dAlign = getString( "ALIGN", line, paramFound );
00396 if( paramFound || !defaultTextLabel )
00397 tmp->setAlignment( dAlign );
00398 else
00399 if( defaultTextLabel )
00400 tmp->setAlignment( defaultTextLabel->getAlignment() );
00401
00402 bool dFp = getBoolean( "FIXEDPITCH", line, paramFound );
00403 if( paramFound || !defaultTextLabel )
00404 tmp->setFixedPitch( dFp );
00405 else
00406 if( defaultTextLabel )
00407 tmp->setFixedPitch( defaultTextLabel->getFixedPitch() );
00408
00409 int dShadow = getInt( "SHADOW", line, paramFound );
00410 if( paramFound || !defaultTextLabel )
00411 tmp->setShadow( dShadow );
00412 else
00413 if( defaultTextLabel )
00414 tmp->setShadow( defaultTextLabel->getShadow() );
00415
00416 tmp->setValue( getString( "VALUE", line ) );
00417
00418 setSensor( line, (Meter*)tmp );
00419 meterList->append ( tmp );
00420
00421 }
00422
00423 if(meter == "BAR")
00424 {
00425 Bar *tmp =
00426 new Bar( x, y, w, h );
00427 tmp->setThemePath( themePath );
00428 tmp->setImage( getString( "PATH", line ) );
00429 tmp->setVertical( getBoolean( "VERTICAL", line ) );
00430 bool maxFound = false;
00431 int max = getInt( "MAX", line, maxFound );
00432 if( maxFound )
00433 tmp->setMax( max );
00434 bool minFound = false;
00435 int min = getInt( "MIN", line, minFound );
00436 if( minFound )
00437 tmp->setMin( min );
00438 tmp->setValue( getInt( "VALUE", line ) );
00439 setSensor( line, (Meter*)tmp );
00440 meterList->append ( tmp );
00441 }
00442
00443 if(meter == "GRAPH")
00444 {
00445 int r, g, b;
00446 int points = getInt("POINTS",line);
00447 get3Int("COLOR", line, r, g, b);
00448
00449 Graph *tmp = new Graph( x, y, w, h, points );
00450 bool maxFound = false;
00451 int max = getInt( "MAX", line, maxFound );
00452 if( maxFound )
00453 tmp->setMax( max );
00454 bool minFound = false;
00455 int min = getInt( "MIN", line, minFound );
00456 if( minFound )
00457 tmp->setMin( min );
00458
00459 tmp->setColor( r , g, b );
00460
00461 setSensor( line, (Graph*)tmp );
00462 meterList->append ( tmp );
00463 }
00464 }
00465 }
00466 if( !foundKaramba )
00467 {
00468
00469
00470
00471 return false;
00472 }
00473 else
00474 {
00475 connect(m_sysTimer, SIGNAL(timeout()), SLOT(step()));
00476
00477 interval = interval == 0 ? 1000 : interval;
00478 m_sysTimer->start(interval);
00479 QTimer::singleShot( 1000, this, SLOT(step()) );
00480 QTimer::singleShot( 5000, this, SLOT(step()) );
00481 QTimer::singleShot( 10000, this, SLOT(step()) );
00482
00483 if( !onTop )
00484 lowerTimer.start();
00485
00486
00487 return true;
00488 }
00489 }
00490
00491 void karamba::startNewKaramba()
00492 {
00493 QStringList fileNames;
00494 KSimpleConfig conf("karambarc",true);
00495 conf.setGroup("karamba");
00496 QString dDir = conf.readEntry("ThemeDir", "/usr/share/apps/karamba/themes/");
00497 fileNames = KFileDialog::getOpenFileNames(dDir, "*.theme", 0, "Open configurations");
00498 for ( QStringList::Iterator it = fileNames.begin(); it != fileNames.end(); ++it )
00499 {
00500 QFileInfo file( *it );
00501 if( file.exists() )
00502 {
00503 (new karamba( *it ))->show();
00504 }
00505 }
00506 }
00507
00508 void karamba::Config(){
00509 KarambaConf *kc = 0;
00510 kc = new KarambaConf(0, "karconf", false, 0);
00511 kc->show();
00512 }
00513
00514 void karamba::reloadConfig()
00515 {
00516 QFileInfo file( themeFile );
00517 qDebug(themeFile);
00518 if( file.exists() )
00519 {
00520 (new karamba( themeFile ))->show();
00521 }
00522 close();
00523 }
00524
00525 void karamba::editConfig()
00526 {
00527 QFileInfo fileInfo( themeFile );
00528 QString path;
00529
00530 if( fileInfo.isRelative() )
00531 {
00532 path = themePath + "/" + themeFile;
00533 }
00534 else
00535 {
00536 path = themeFile;
00537 }
00538
00539 KRun::runURL( KURL( path ), "text/plain" );
00540
00541 }
00542
00543
00544 int karamba::getInt(QString w, QString &line )
00545 {
00546 bool b;
00547 return getInt( w, line, b );
00548 }
00549
00550 int karamba::getInt(QString w, QString &line, bool &found )
00551 {
00552 QRegExp rx( "\\W+" + w +"=([-]?\\d+)", false );
00553 found = (rx.search(line)==-1)?false:true;
00554 return rx.cap(1).toInt();
00555 }
00556
00557 void karamba::get3Int(QString w, QString &line, int &a, int &b, int &c )
00558 {
00559 bool bo;
00560 get3Int ( w, line, a, b, c, bo );
00561 }
00562
00563 void karamba::get3Int(QString w, QString &line, int &a, int &b, int &c, bool &found )
00564 {
00565 QRegExp rx( "\\W+" + w + "=([-]?\\d+),([-]?\\d+),([-]?\\d+)", false );
00566 found = (rx.search(line)==-1)?false:true;
00567 a = rx.cap(1).toInt();
00568 b = rx.cap(2).toInt();
00569 c = rx.cap(3).toInt();
00570 }
00571
00572 QString karamba::getString(QString w, QString &line)
00573 {
00574 bool b;
00575 return getString ( w, line, b );
00576 }
00577
00578 QString karamba::getString(QString w, QString &line, bool &found)
00579 {
00580 QRegExp rx( "\\W+" + w + "=\"([^\"]*)\"", false );
00581 found = (rx.search(line)==-1)?false:true;
00582 if (rx.cap(1).isEmpty())
00583 {
00584 rx = QRegExp(w + "=(\\S+)", false);
00585 rx.search(line);
00586 return rx.cap(1);
00587 }
00588 else
00589 {
00590 return rx.cap(1);
00591 }
00592
00593 }
00594
00595 bool karamba::getBoolean( QString w, QString &line )
00596 {
00597 bool b;
00598 return getBoolean ( w, line, b );
00599 }
00600
00601 bool karamba::getBoolean( QString w, QString &line, bool &found )
00602 {
00603 return ( getString( w, line, found ).lower() == "true")?true:false;
00604 }
00605
00606 void karamba::setSensor(QString &line, Meter* meter)
00607 {
00608 Sensor* sensor = 0;
00609
00610 QString sens = getString("SENSOR",line).upper();
00611
00612 if( sens == "CPU" )
00613 {
00614 QString cpuNbr = getString( "CPU", line );
00615 sensor = sensorMap["CPU"+cpuNbr];
00616 if (sensor == 0)
00617 {
00618 int interval = getInt("INTERVAL",line);
00619 interval = (interval == 0)?1000:interval;
00620 sensor = ( sensorMap["CPU"+cpuNbr] = new CPUSensor( cpuNbr, interval ) );
00621 sensorList->append( sensor );
00622 }
00623 SensorParams *sp = new SensorParams(meter);
00624 sp->addParam("FORMAT",getString("FORMAT",line));
00625 sp->addParam("DECIMALS",getString("DECIMALS",line));
00626
00627 sensor->addMeter(sp);
00628 sensor->setMaxValue(sp);
00629
00630 }
00631
00632 if( sens == "MEMORY" )
00633 {
00634 sensor = sensorMap["MEMORY"];
00635 if (sensor == 0)
00636 {
00637 int interval = getInt("INTERVAL",line);
00638 interval = (interval == 0)?3000:interval;
00639 sensor = ( sensorMap["MEMORY"] = new MemSensor( interval ) );
00640 sensorList->append( sensor );
00641 }
00642 SensorParams *sp = new SensorParams(meter);
00643 sp->addParam("FORMAT",getString("FORMAT",line));
00644
00645 sensor->addMeter(sp);
00646 sensor->setMaxValue(sp);
00647 }
00648
00649
00650 if( sens == "DISK" )
00651 {
00652 sensor = sensorMap["DISK"];
00653 if (sensor == 0)
00654 {
00655 int interval = getInt("INTERVAL",line);
00656 interval = (interval == 0)?5000:interval;
00657 sensor = ( sensorMap["DISK"] = new DiskSensor( interval ) );
00658 sensorList->append( sensor );
00659 }
00660
00661 SensorParams *sp = new SensorParams(meter);
00662 QString mntPt = getString("MOUNTPOINT",line);
00663 if( mntPt == "" )
00664 mntPt = "/";
00665
00666 sp->addParam("MOUNTPOINT",mntPt);
00667 sp->addParam("FORMAT",getString("FORMAT",line));
00668 sensor->addMeter(sp);
00669 sensor->setMaxValue(sp);
00670 }
00671
00672 if( sens == "NETWORK")
00673 {
00674 int interval = getInt("INTERVAL",line );
00675 interval = (interval == 0)?2000:interval;
00676 QString device = getString("DEVICE", line );
00677 sensor = sensorMap["NETWORK"+device];
00678 if (sensor == 0)
00679 {
00680 sensor = ( sensorMap["NETWORK"+device] = new NetworkSensor( device, interval ) );
00681 sensorList->append( sensor );
00682 }
00683 SensorParams *sp = new SensorParams(meter);
00684 sp->addParam( "FORMAT", getString( "FORMAT", line ) );
00685 sp->addParam( "DECIMALS", getString( "DECIMALS", line ) );
00686 sensor->addMeter(sp);
00687 }
00688
00689 if( sens == "UPTIME" )
00690 {
00691 sensor = sensorMap["UPTIME"];
00692 if (sensor == 0)
00693 {
00694 int interval = getInt("INTERVAL",line);
00695 interval = (interval == 0)?60000:interval;
00696 sensor = ( sensorMap["UPTIME"] = new UptimeSensor( interval ));
00697 sensorList->append( sensor );
00698
00699 }
00700 SensorParams *sp = new SensorParams(meter);
00701 sp->addParam( "FORMAT", getString( "FORMAT", line ) );
00702 sensor->addMeter(sp);
00703 }
00704
00705 if( sens == "SENSOR" )
00706 {
00707 sensor = sensorMap["SENSOR"];
00708 if (sensor == 0)
00709 {
00710 int interval = getInt("INTERVAL",line);
00711 interval = (interval == 0)?30000:interval;
00712 sensor = ( sensorMap["SENSOR"] = new SensorSensor( interval ) );
00713 sensorList->append( sensor );
00714 }
00715 SensorParams *sp = new SensorParams(meter);
00716 sp->addParam("FORMAT",getString("FORMAT",line));
00717 sp->addParam("TYPE",getString("TYPE",line));
00718 sensor->addMeter(sp);
00719 }
00720
00721
00722 if( sens == "TEXTFILE" )
00723 {
00724 QString path = getString( "PATH", line );
00725 bool rdf = getBoolean( "RDF", line );
00726 sensor = sensorMap["TEXTFILE"+path];
00727 if (sensor == 0)
00728 {
00729 int interval = getInt( "INTERVAL", line );
00730 interval = ( interval == 0 )?60000:interval;
00731 QString encoding = getString( "ENCODING", line );
00732
00733 sensor = ( sensorMap["TEXTFILE"+path] =
00734 new TextFileSensor( path, rdf, interval, encoding ) );
00735 sensorList->append( sensor );
00736 }
00737 SensorParams *sp = new SensorParams(meter);
00738 sp->addParam("LINE",QString::number(getInt("LINE",line)));
00739 sensor->addMeter(sp);
00740 }
00741
00742
00743 if( sens == "TIME")
00744 {
00745 sensor = sensorMap["DATE"];
00746 if (sensor == 0)
00747 {
00748 int interval = getInt("INTERVAL",line);
00749 interval = (interval == 0)?60000:interval;
00750 sensor = ( sensorMap["DATE"] = new DateSensor( interval ) );
00751 sensorList->append( sensor );
00752 timeList->append( sensor );
00753 }
00754 SensorParams *sp = new SensorParams(meter);
00755 sp->addParam("FORMAT",getString("FORMAT",line));
00756 sp->addParam("CALWIDTH",getString("CALWIDTH",line));
00757 sp->addParam("CALHEIGHT",getString("CALHEIGHT",line));
00758 sensor->addMeter(sp);
00759 }
00760
00761 #ifdef HAVE_XMMS
00762
00763 if( sens == "XMMS" )
00764 {
00765 sensor = sensorMap["XMMS"];
00766 if (sensor == 0)
00767 {
00768 int interval = getInt("INTERVAL",line);
00769 interval = (interval == 0)?1000:interval;
00770 QString encoding = getString( "ENCODING", line );
00771
00772 sensor = ( sensorMap["XMMS"] = new XMMSSensor( interval, encoding ) );
00773 sensorList->append( sensor );
00774 }
00775 SensorParams *sp = new SensorParams(meter);
00776 sp->addParam("FORMAT",getString("FORMAT",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"