26 #include "karamba.moc"
28 #include <QGraphicsView>
29 #include <QGraphicsScene>
31 #include <QDesktopWidget>
32 #include <QApplication>
35 #include <QSignalMapper>
38 #include <KWindowSystem>
44 #include <KToggleAction>
45 #include <KCmdLineArgs>
47 #include "config-superkaramba.h"
74 #ifdef PLASMASENSOR_ENABLED
91 return new Karamba(theme, view);
95 class Karamba::Private
99 QGraphicsScene *scene;
102 KWindowSystem *KWinModule;
105 #ifdef PYTHON_INCLUDE_PATH
129 QList<Sensor*> sensorList;
130 QMap<QString, Sensor*> sensorMap;
133 KToggleAction *toggleLocked;
134 KAction* reloadTheme;
135 KMenu *themeConfMenu;
136 KMenu *toDesktopMenu;
141 QSignalMapper *signalMapperConfig;
142 QSignalMapper *signalMapperDesktop;
148 QList<KMenu*> menuList;
156 bool wantRightButton;
158 QPoint mouseClickPos;
166 QGraphicsItemAnimation *animation;
171 bool useFancyEffects;
172 bool useAntialiasing;
176 K3Process *currProcess;
180 scene(view ? view->scene() : 0),
184 #ifdef PYTHON_INCLUDE_PATH
204 signalMapperConfig(0),
205 signalMapperDesktop(0),
209 wantRightButton(false),
210 globalView(view ? true : false),
215 useFancyEffects(true),
216 useAntialiasing(true),
229 #ifdef PYTHON_INCLUDE_PATH
239 qDeleteAll(sensorList);
242 delete toDesktopMenu;
243 delete themeConfMenu,
266 d(new Private(view, instance, subTheme))
268 #ifdef PYTHON_INCLUDE_PATH
269 if (!d->globalView) {
270 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
271 if (args->isSet(
"usefallback")) {
277 QString environment = getenv(
"SK_FANCY");
278 if (!environment.compare(
"false", Qt::CaseInsensitive)) {
279 d->useFancyEffects =
false;
282 environment = getenv(
"SK_AA");
283 if (!environment.compare(
"false", Qt::CaseInsensitive)) {
284 d->useAntialiasing =
false;
287 if (!d->globalView) {
288 d->scene =
new QGraphicsScene;
289 d->scene->addItem(
this);
292 if (d->useAntialiasing) {
293 d->view->setRenderHints(QPainter::Antialiasing |
294 QPainter::SmoothPixmapTransform);
297 d->scene->setItemIndexMethod(QGraphicsScene::NoIndex);
304 if (!d->globalView) {
305 d->view->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
308 if (!d->theme.set(themeFile)) {
309 kDebug() <<
"Could not load theme file" ;
310 d->errorInInit =
true;
316 KDirWatch *dirWatch = KDirWatch::self();
317 connect(dirWatch, SIGNAL(dirty(QString)),
320 if (!dirWatch->contains(d->theme.file()))
321 dirWatch->addFile(d->theme.file());
323 if (!d->theme.isZipTheme() && d->theme.scriptModuleExists()) {
324 QString scriptFile = d->theme.path() +
'/' + d->theme.scriptModule();
325 if (!dirWatch->contains(scriptFile))
326 dirWatch->addFile(scriptFile);
329 if (d->prettyName.isEmpty())
330 d->prettyName = QString(
"%1 - %2").arg(d->theme.name()).arg(d->instance);
332 setObjectName( QLatin1String(
"karamba - " ) + d->prettyName);
334 if (!d->globalView) {
335 d->info =
new NETWinInfo(QX11Info::display(), d->view->winId(),
336 QX11Info::appRootWindow(), NET::WMState);
341 d->KWinModule = KWindowSystem::self();
342 connect(d->KWinModule, SIGNAL(currentDesktopChanged(
int)),
this,
343 SLOT(currentDesktopChanged(
int)));
347 d->backgroundInterface =
new org::kde::kdesktop::Background(
"org.kde.kdesktop",
"/Background", QDBusConnection::sessionBus());
348 connect(d->backgroundInterface, SIGNAL(backgroundChanged(
int)),
this,
349 SLOT(currentWallpaperChanged(
int)));
351 setAcceptsHoverEvents(
true);
365 d->signalMapperConfig =
new QSignalMapper(
this);
366 connect(d->signalMapperConfig, SIGNAL(mapped(
QObject*)),
this,
367 SLOT(slotToggleConfigOption(
QObject*)));
369 d->signalMapperDesktop =
new QSignalMapper(
this);
370 connect(d->signalMapperDesktop, SIGNAL(mapped(
int)),
this,
371 SLOT(slotDesktopChanged(
int)));
377 QString instanceString;
379 instanceString = QString(
"-%1").arg(d->instance);
381 QString cfg = QDir::home().absolutePath() +
"/.superkaramba/"
382 + d->theme.id() + instanceString +
".rc";
385 QFile themeConfigFile(cfg);
387 if (!QFileInfo(themeConfigFile).exists()) {
389 themeConfigFile.open(QIODevice::ReadWrite);
390 themeConfigFile.close();
393 d->config =
new KConfig(cfg, KConfig::NoGlobals);
396 KConfigGroup cg(d->config,
"internal");
397 bool locked = d->toggleLocked->isChecked();
398 locked = cg.readEntry(
"lockedPosition", locked);
399 d->toggleLocked->setChecked(locked);
402 desktop = cg.readEntry(
"desktop", desktop);
403 if (desktop > d->KWinModule->numberOfDesktops()) {
407 slotDesktopChanged(desktop);
409 cg = KConfigGroup(d->config,
"theme");
410 if (cg.hasKey(
"widgetPosX") && cg.hasKey(
"widgetPosY")) {
411 int xpos = cg.readEntry(
"widgetPosX", 0);
412 int ypos = cg.readEntry(
"widgetPosY", 0);
419 if (startPos.isNull()) {
424 if (!startPos.isNull()) {
427 d->toggleLocked->setChecked(
false);
430 if (!d->globalView && !reload && d->useFancyEffects) {
431 d->timer =
new QTimeLine(1000);
432 d->timer->setFrameRange(0, 1000);
434 d->animation =
new QGraphicsItemAnimation;
435 d->animation->setItem(
this);
436 d->animation->setTimeLine(d->timer);
439 for (
int i = 0; i < 201; i++) {
440 d->animation->setScaleAt(i / 200.0, 1 / 200.0 * i, 1 / 200.0 * i);
442 boundingRect().width()/2*(1-d->animation->verticalScaleAt(i / 200.0)),
443 boundingRect().height()/2*(1-d->animation->horizontalScaleAt(i / 200.0))
445 d->animation->setPosAt(i / 200.0, animPos);
454 if (!(d->onTop || d->managed) && !d->globalView) {
455 KWindowSystem::setState(d->view->winId(), NET::KeepBelow);
456 KWindowSystem::lowerWindow(d->view->winId());
465 d->scene->removeItem(
this);
472 if (d->errorInInit) {
479 if (d->theme.scriptModuleExists()) {
480 kDebug() <<
"Loading script module: " << d->theme.scriptModule() ;
482 d->stepTimer.setSingleShot(
true);
485 #ifdef PYTHON_INCLUDE_PATH
487 d->python->initWidget(
this);
491 bool interpreterStarted = d->interface->initInterpreter();
493 if (!interpreterStarted) {
497 d->interface->startInterpreter();
498 d->interface->callInitWidget(
this);
504 connect(&d->stepTimer, SIGNAL(timeout()), SLOT(step()));
505 d->stepTimer.start(d->interval);
513 return d->prettyName;
518 d->prettyName = prettyThemeName;
523 d->stepTimer.start(d->interval);
525 #ifdef PYTHON_INCLUDE_PATH
527 d->python->widgetUpdated(
this);
531 d->interface->callWidgetUpdated(
this);
542 bool Karamba::parseConfig()
547 if (d->theme.open()) {
548 QStack<QPoint> offsetStack;
555 offsetStack.push(QPoint(0, 0));
557 while (d->theme.nextLine(lineParser)) {
558 x = lineParser.
getInt(
"X") + offsetStack.top().x();
559 y = lineParser.
getInt(
"Y") + offsetStack.top().y();
560 w = lineParser.
getInt(
"W");
561 h = lineParser.
getInt(
"H");
563 bool hidden = lineParser.
getBoolean(
"HIDDEN");
565 if (lineParser.
meter() ==
"KARAMBA" && !d->foundKaramba) {
566 d->toggleLocked->setChecked(lineParser.
getBoolean(
"LOCKED"));
571 if (w == 0 || h == 0) {
579 d->themeCenter = QPoint(w/2, h/2);
582 if (!d->globalView) {
583 d->view->setFixedSize(w + 5, h + 5);
587 QDesktopWidget *d = QApplication::desktop();
594 QDesktopWidget *d = QApplication::desktop();
604 if (!d->globalView) {
605 KWindowSystem::setState(d->view->winId(), NET::StaysOnTop);
611 if (!d->globalView) {
612 Qt::WindowFlags flags = Qt::Dialog;
613 flags & Qt::WA_DeleteOnClose;
614 d->view->setWindowFlags(flags);
618 if (!d->globalView) {
619 d->info->setState(NETWinInfo::SkipTaskbar
620 | NETWinInfo::SkipPager, NETWinInfo::SkipTaskbar
621 | NETWinInfo::SkipPager);
623 if (d->onTop && !d->globalView) {
624 KWindowSystem::setState(d->view->winId(), NET::KeepAbove);
634 if (dfound && !d->globalView) {
635 d->info->setDesktop(dfound);
639 if (!d->globalView) {
640 KWindowSystem::setStrut(d->view->winId(), 0, 0, h, 0);
646 d->toggleLocked->setChecked(
true);
647 d->toggleLocked->setEnabled(
false);
651 int dh = QApplication::desktop()->height();
655 KWindowSystem::setStrut(d->view->winId(), 0, 0, 0, h);
656 d->view->move(x, dh - h);
658 d->toggleLocked->setChecked(
true);
659 d->toggleLocked->setEnabled(
false);
663 int dw = QApplication::desktop()->width();
667 KWindowSystem::setStrut(d->view->winId(), 0, w, 0, 0);
668 d->view->move(dw - w, y);
670 d->toggleLocked->setChecked(
true);
671 d->toggleLocked->setEnabled(
false);
678 KWindowSystem::setStrut(d->view->winId(), w, 0, 0, 0);
681 d->toggleLocked->setChecked(
true );
682 d->toggleLocked->setEnabled(
false);
686 setFlag(QGraphicsItem::ItemIsMovable,
687 d->toggleLocked->isChecked());
719 d->interval = lineParser.
getInt(
"INTERVAL");
720 d->interval = (d->interval == 0) ? 1000 : d->interval;
722 QString temp = lineParser.
getString(
"TEMPUNIT",
"C").toUpper();
723 d->tempUnit = temp.at(0).toAscii();
724 d->foundKaramba =
true;
727 if (lineParser.
meter() ==
"THEME") {
728 QString path = lineParser.
getString(
"PATH");
729 QFileInfo info(path);
730 if (info.isRelative())
731 path = d->theme.path() +
'/' + path;
736 if (lineParser.
meter() ==
"<GROUP>") {
737 int offsetX = offsetStack.top().x();
738 int offsetY = offsetStack.top().y();
739 offsetStack.push(QPoint(offsetX + lineParser.
getInt(
"X"),
740 offsetY + lineParser.
getInt(
"Y")));
743 if (lineParser.
meter() ==
"</GROUP>") {
747 if (lineParser.
meter() ==
"CLICKAREA") {
748 if (!d->globalView) {
749 d->view->setInteractive(
true);
752 bool preview = lineParser.
getBoolean(
"PREVIEW");
760 if (lineParser.
meter() ==
"SENSOR=PROGRAM") {
764 if (lineParser.
meter() ==
"IMAGE") {
765 QString file = lineParser.
getString(
"PATH");
766 QString file_roll = lineParser.
getString(
"PATHROLL");
767 int xon = lineParser.
getInt(
"XROLL");
768 int yon = lineParser.
getInt(
"YROLL");
769 QString tiptext = lineParser.
getString(
"TOOLTIP");
770 QString name = lineParser.
getString(
"NAME");
771 bool bg = lineParser.
getBoolean(
"BACKGROUND");
772 xon = (xon <= 0) ? x : xon;
773 yon = (yon <= 0) ? y : yon;
778 if (!file_roll.isEmpty())
784 tmp->setObjectName(name);
786 if (!tiptext.isEmpty())
794 if (lineParser.
meter() ==
"DEFAULTFONT") {
795 delete d->defaultTextField;
798 d->defaultTextField->setColor(lineParser.
getColor(
"COLOR",
800 d->defaultTextField->setBGColor(lineParser.
getColor(
"BGCOLOR",
802 d->defaultTextField->setFont(lineParser.
getString(
"FONT",
"Helvetica"));
803 d->defaultTextField->setFontSize(lineParser.
getInt(
"FONTSIZE", 12));
804 d->defaultTextField->setAlignment(lineParser.
getString(
"ALIGN",
806 d->defaultTextField->setFixedPitch(lineParser.
getBoolean(
"FIXEDPITCH",
808 d->defaultTextField->setShadow(lineParser.
getInt(
"SHADOW", 0));
811 if (lineParser.
meter() ==
"TEXT" ||
812 lineParser.
meter() ==
"CLICKMAP" ||
813 lineParser.
meter() ==
"RICHTEXT" ||
814 lineParser.
meter() ==
"INPUT") {
817 if (d->defaultTextField)
818 defTxt = *d->defaultTextField;
837 if (lineParser.
meter() ==
"TEXT") {
840 d->theme.locale()->translate(lineParser.
getString(
"VALUE")));
843 QString name = lineParser.
getString(
"NAME");
845 tmp->setObjectName(name);
853 if (lineParser.
meter() ==
"CLICKMAP") {
854 if (!d->globalView) {
855 d->view->setInteractive(
true);
868 if (lineParser.
meter() ==
"RICHTEXT") {
871 bool dUl = lineParser.
getBoolean(
"UNDERLINE");
874 d->theme.locale()->translate(lineParser.
getString(
"VALUE")), dUl);
879 QString name = lineParser.
getString(
"NAME");
881 tmp->setObjectName(name);
891 if (lineParser.
meter() ==
"INPUT") {
894 QString name = lineParser.
getString(
"NAME");
900 d->theme.locale()->translate(lineParser.
getString(
"VALUE")));
909 if (lineParser.
meter() ==
"BAR") {
910 Bar *tmp =
new Bar(
this, x, y, w, h);
918 QString name = lineParser.
getString(
"NAME");
920 tmp->setObjectName(name);
929 if (lineParser.
meter() ==
"GRAPH") {
930 int points = lineParser.
getInt(
"POINTS");
932 Graph *tmp =
new Graph(
this, x, y, w, h, points);
935 QString name = lineParser.
getString(
"NAME");
937 tmp->setObjectName(name);
943 QString fillString = lineParser.
getString(
"FILLCOLOR");
944 if ( ! fillString.isEmpty() )
955 if (passive && !d->managed && !d->onTop && !d->globalView) {
956 KWindowSystem::setType(d->view->winId(), NET::Dock);
957 KWindowSystem::setState(d->view->winId(), NET::KeepBelow);
963 if (!d->foundKaramba) {
975 if (!d->globalView) {
976 KWindowSystem::setType(d->view->winId(), NET::Normal);
977 KWindowSystem::setState(d->view->winId(), NET::Modal);
987 QList<QGraphicsItem*> items = QGraphicsItemGroup::children();
989 if (dynamic_cast<Input*>(item) != 0) {
994 if (!d->globalView) {
995 KWindowSystem::setType(d->view->winId(), NET::Dock);
996 KWindowSystem::setState(d->view->winId(), NET::KeepBelow);
1002 return d->defaultTextField;
1005 QString Karamba::findSensorFromMap(
const Sensor* sensor)
const
1008 QMap<QString, Sensor*>::ConstIterator it;
1009 QMap<QString, Sensor*>::ConstIterator end(d->sensorMap.constEnd());
1010 for (it = d->sensorMap.constBegin(); it != end; ++it) {
1011 if (it.value() == sensor)
1017 Sensor *Karamba::findSensorFromList(
const Meter* meter)
const
1019 foreach(
Sensor *sensor, d->sensorList) {
1030 Sensor* sensor = findSensorFromList(meter);
1035 QString s = findSensorFromMap(sensor);
1036 d->sensorMap.remove(s);
1037 d->sensorList.removeAll(sensor);
1045 Sensor* sensor = findSensorFromList(meter);
1048 return findSensorFromMap(sensor);
1055 QList<QGraphicsItem*> items = QGraphicsItemGroup::children();
1057 if (items.contains(meter)) {
1071 QString sens = lineParser.
getString(
"SENSOR").toUpper();
1073 if (sens ==
"CPU") {
1074 QString cpuNbr = lineParser.
getString(
"CPU");
1075 sensor = d->sensorMap[
"CPU"+cpuNbr];
1078 int interval = lineParser.
getInt(
"INTERVAL");
1079 interval = (interval == 0) ? 1000 : interval;
1080 sensor = (d->sensorMap[
"CPU" + cpuNbr] =
new CPUSensor(cpuNbr, interval));
1081 d->sensorList.append(sensor);
1086 d->theme.locale()->translate(lineParser.
getString(
"FORMAT")));
1094 if (sens ==
"MEMORY") {
1095 sensor = d->sensorMap[
"MEMORY"];
1097 int interval = lineParser.
getInt(
"INTERVAL");
1098 interval = (interval == 0) ? 3000 : interval;
1099 sensor = (d->sensorMap[
"MEMORY"] =
new MemSensor(interval));
1100 d->sensorList.append(sensor);
1105 d->theme.locale()->translate(lineParser.
getString(
"FORMAT")));
1111 if (sens ==
"DISK") {
1112 sensor = d->sensorMap[
"DISK"];
1115 int interval = lineParser.
getInt(
"INTERVAL");
1116 interval = (interval == 0) ? 5000 : interval;
1117 sensor = (d->sensorMap[
"DISK"] =
new DiskSensor(interval));
1118 d->sensorList.append(sensor);
1122 QString mntPt = lineParser.
getString(
"MOUNTPOINT");
1123 if (mntPt.isEmpty()) {
1128 if (mntPt.length() > 1 && mntPt.endsWith(
'/')) {
1129 mntPt.remove(mntPt.length() - 1, 1);
1133 d->theme.locale()->translate(lineParser.
getString(
"FORMAT")));
1138 if (sens ==
"NETWORK") {
1139 int interval = lineParser.
getInt(
"INTERVAL");
1140 interval = (interval == 0) ? 2000 : interval;
1141 QString device = lineParser.
getString(
"DEVICE");
1142 sensor = d->sensorMap[
"NETWORK"+device];
1145 sensor = (d->sensorMap[
"NETWORK"+device] =
1147 d->sensorList.append(sensor);
1152 d->theme.locale()->translate(lineParser.
getString(
"FORMAT")));
1158 if (sens ==
"UPTIME") {
1159 sensor = d->sensorMap[
"UPTIME"];
1161 int interval = lineParser.
getInt(
"INTERVAL");
1162 interval = (interval == 0) ? 1000 : interval;
1163 sensor = (d->sensorMap[
"UPTIME"] =
new UptimeSensor(interval));
1164 d->sensorList.append(sensor);
1169 d->theme.locale()->translate(lineParser.
getString(
"FORMAT")));
1174 if (sens ==
"SENSOR") {
1175 sensor = d->sensorMap[
"SENSOR"];
1178 int interval = lineParser.
getInt(
"INTERVAL");
1179 interval = (interval == 0) ? 5000 : interval;
1180 sensor = (d->sensorMap[
"SENSOR"] =
new SensorSensor(interval, d->tempUnit));
1181 d->sensorList.append(sensor);
1186 d->theme.locale()->translate(lineParser.
getString(
"FORMAT")));
1191 if (sens ==
"TEXTFILE") {
1192 QString path = lineParser.
getString(
"PATH");
1194 sensor = d->sensorMap[
"TEXTFILE"+path];
1197 int interval = lineParser.
getInt(
"INTERVAL");
1198 interval = (interval == 0) ? 60000 : interval;
1199 QString encoding = lineParser.
getString(
"ENCODING");
1201 sensor = (d->sensorMap[
"TEXTFILE"+path] =
1203 d->sensorList.append(sensor);
1207 sp->
addParam(
"LINE", QString::number(lineParser.
getInt(
"LINE")));
1210 if (sens ==
"TIME") {
1211 sensor = d->sensorMap[
"DATE"];
1213 int interval = lineParser.
getInt(
"INTERVAL");
1214 interval = (interval == 0) ? 1000 : interval;
1215 sensor = (d->sensorMap[
"DATE"] =
new DateSensor(interval));
1216 d->sensorList.append(sensor);
1221 d->theme.locale()->translate(lineParser.
getString(
"FORMAT")));
1230 if (sens ==
"XMMS") {
1231 sensor = sensorMap[
"XMMS"];
1233 int interval = lineParser.
getInt(
"INTERVAL");
1234 interval = (interval == 0) ? 1000 : interval;
1235 QString encoding = lineParser.
getString(
"ENCODING");
1237 sensor = (sensorMap[
"XMMS"] =
new XMMSSensor(interval, encoding));
1238 sensorList->append(sensor);
1242 d->theme.locale()->translate(lineParser.
getString(
"FORMAT")));
1270 if (sens ==
"PROGRAM") {
1271 QString progName = lineParser.
getString(
"PROGRAMNAME");
1272 if (progName.isEmpty()) {
1273 progName = lineParser.
getString(
"PROGRAM");
1276 sensor = d->sensorMap[
"PROGRAM"+progName];
1279 int interval = lineParser.
getInt(
"INTERVAL");
1281 interval = (interval == 0) ? 60000 : interval;
1282 QString encoding = lineParser.
getString(
"ENCODING");
1284 QString prog = lineParser.
getString(
"PROGRAM");
1285 sensor = (d->sensorMap[
"PROGRAM"+progName] =
1287 d->sensorList.append(sensor);
1291 sp->
addParam(
"LINE", QString::number(lineParser.
getInt(
"LINE")));
1292 sp->
addParam(
"THEMAPATH", d->theme.path());
1293 sp->
addParam(
"FORMAT", d->theme.locale()->translate(lineParser.
getString(
"FORMAT")));
1297 if (sens ==
"RSS") {
1298 QString source = lineParser.
getString(
"SOURCE");
1300 d->theme.locale()->translate(lineParser.
getString(
"FORMAT"));
1302 sensor = d->sensorMap[
"RSS"+source];
1304 int interval = lineParser.
getInt(
"INTERVAL");
1305 interval = (interval == 0) ? 60000 : interval;
1306 QString encoding = lineParser.
getString(
"ENCODING");
1308 sensor = (d->sensorMap[
"RSS"+source] =
1309 new RssSensor(source, interval, format, encoding));
1310 d->sensorList.append(sensor);
1317 #ifdef PLASMASENSOR_ENABLED
1318 if (sens ==
"PLASMA") {
1319 QString engine = lineParser.
getString(
"ENGINE");
1320 QString source = lineParser.
getString(
"SOURCE");
1321 kDebug()<<
"PlasmaEngineSensor engine="<<engine<<
" source="<<source<<endl;
1322 sensor = d->sensorMap[
"PLASMA." + engine +
'.' + source];
1326 if( ! source.isEmpty() ) {
1329 c->setFormat( lineParser.
getString(
"FORMAT") );
1333 QString propertiesLine = lineParser.
getString(
"PROPERTIES");
1334 const QStringList properties = propertiesLine.split(
',');
1335 foreach (
const QString &property, properties) {
1336 QStringList options =
property.split(
':');
1337 if (options.count() == 2) {
1338 plasmasensor->
setProperty(options[0].toLatin1(), options[1]);
1342 sensor = plasmasensor;
1343 d->sensorMap[
"PLASMA." + engine +
'.' + source] = sensor;
1344 d->sensorList.append(sensor);
1348 sp->
addParam(
"THEMAPATH", d->theme.path());
1365 foreach(
Sensor *sensor, d->sensorList)
1369 void Karamba::slotToggleLocked()
1372 setFlag(QGraphicsItem::ItemIsMovable,
1373 d->toggleLocked->isChecked());
1378 #ifdef PYTHON_INCLUDE_PATH
1380 d->python->widgetClosed(
this);
1384 d->interface->callWidgetClosed(
this);
1396 KConfigGroup cg(d->config,
"internal");
1397 cg.writeEntry(
"lockedPosition", d->toggleLocked-> isChecked());
1398 cg.writeEntry(
"desktop", d->desktop);
1400 cg = KConfigGroup(d->config,
"theme");
1403 if (!d->globalView) {
1404 cg.writeEntry(
"widgetPosX", d->view->x());
1405 cg.writeEntry(
"widgetPosY", d->view->y());
1408 cg.writeEntry(
"widgetPosX", parentItem()->x());
1409 cg.writeEntry(
"widgetPosY", parentItem()->y());
1411 cg.writeEntry(
"widgetPosX", x());
1412 cg.writeEntry(
"widgetPosY", y());
1418 cg.writeEntry(
"widgetHeight",
boundingRect().height());
1431 k =
new Karamba(d->theme.getUrlPath(), d->view, -1,
false, QPoint(),
true);
1433 k =
new Karamba(d->theme.getUrlPath(), 0, -1,
false, QPoint(),
true);
1441 if (!d->globalView) {
1442 KWindowSystem::setState(d->view->winId(), NET::KeepAbove);
1445 if (!d->globalView) {
1446 KWindowSystem::setState(d->view->winId(), NET::KeepBelow);
1450 d->onTop = stayOnTop;
1453 void Karamba::preparePopupMenu()
1455 d->popupMenu =
new KMenu();
1457 d->popupMenu->addAction(KIcon(
"view-refresh"), i18n(
"Update"),
this,
1460 d->toggleLocked =
new KToggleAction(i18n(
"&Locked Position"),
this);
1461 d->toggleLocked->setObjectName( QLatin1String(
"lockedAction" ));
1462 d->toggleLocked->setShortcut(KShortcut(Qt::CTRL + Qt::Key_L));
1463 d->toggleLocked->setCheckedState(KGuiItem(i18n(
"&Locked Position")));
1464 connect(d->toggleLocked, SIGNAL(triggered()),
this, SLOT(slotToggleLocked()));
1465 d->popupMenu->addAction(d->toggleLocked);
1467 d->popupMenu->addSeparator();
1469 d->themeConfMenu =
new KMenu();
1470 d->themeConfMenu->setTitle(i18n(
"Configure &Theme"));
1471 QAction *newAC = d->popupMenu->addMenu(d->themeConfMenu);
1472 newAC->setObjectName( QLatin1String(
"configureTheme" ));
1473 newAC->setParent(
this);
1474 newAC->setVisible(
false);
1476 if (d->globalView) {
1480 d->toDesktopMenu =
new KMenu();
1481 d->toDesktopMenu->setTitle(i18n(
"To Des&ktop"));
1482 d->popupMenu->addMenu(d->toDesktopMenu);
1484 QAction *allDesktop = d->toDesktopMenu->addAction((i18n(
"&All Desktops")));
1485 connect(allDesktop, SIGNAL(triggered()), d->signalMapperDesktop, SLOT(map()));
1486 allDesktop->setCheckable(
true);
1487 d->signalMapperDesktop->setMapping(allDesktop, 0);
1489 for (
int desktop = 1; desktop <= d->KWinModule->numberOfDesktops(); desktop++) {
1490 QString name = i18n(
"Desktop");
1491 name += QString(
" &%1").arg(desktop);
1492 QAction* action = d->toDesktopMenu->addAction(name);
1493 action->setCheckable(
true);
1494 connect(action, SIGNAL(triggered()), d->signalMapperDesktop, SLOT(map()));
1495 d->signalMapperDesktop->setMapping(action, desktop);
1498 d->reloadTheme =
new KAction(KIcon(
"view-refresh"), i18n(
"&Reload Theme"),
this);
1499 d->reloadTheme->setObjectName( QLatin1String(
"reloadAction" ));
1500 d->reloadTheme->setShortcut(KShortcut(Qt::CTRL + Qt::Key_R));
1501 connect(d->reloadTheme, SIGNAL(triggered()),
this, SLOT(
reloadConfig()));
1502 d->popupMenu->addAction(d->reloadTheme);
1504 d->popupMenu->addAction(KIcon(
"window-close"), i18n(
"&Close This Theme"),
this,
1508 void Karamba::slotDesktopChanged(
int desktop)
1510 if (d->globalView) {
1514 QList<QAction*> actions = d->toDesktopMenu->actions();
1516 for (
int i = 0; i < actions.count(); i++) {
1518 actions[i]->setChecked(
true);
1520 actions[i]->setChecked(
false);
1524 d->info->setDesktop(desktop);
1526 d->info->setDesktop(NETWinInfo::OnAllDesktops);
1530 void Karamba::currentWallpaperChanged(
int desktop)
1532 #ifdef PYTHON_INCLUDE_PATH
1534 d->python->wallpaperChanged(
this, desktop);
1539 d->interface->callWallpaperChanged(
this, desktop);
1545 d->themeConfMenu->menuAction()->setVisible(
true);
1547 KAction *newAction =
new KToggleAction(name,
this);
1549 newAction->setObjectName(key);
1550 connect(newAction, SIGNAL(triggered()), d->signalMapperConfig, SLOT(map()));
1551 d->signalMapperConfig->setMapping(newAction, newAction);
1552 d->themeConfMenu->addAction(newAction);
1554 newAction->setChecked(d->config->group(
"config menu").readEntry(key,
false));
1557 void Karamba::slotToggleConfigOption(
QObject* sender)
1559 KToggleAction *action = (KToggleAction*)sender;
1561 d->config->group(
"config menu").writeEntry(action->objectName(), action->isChecked());
1563 #ifdef PYTHON_INCLUDE_PATH
1565 d->python->menuOptionChanged(
this, action->objectName(), action->isChecked());
1569 d->interface->callMenuOptionChanged(
this, action->objectName(), action->isChecked());
1574 QList<QAction*> actions = d->themeConfMenu->actions();
1576 foreach(action, actions) {
1577 if (action->objectName() == key) {
1578 action->setChecked(value);
1588 QList<QAction*> actions = d->themeConfMenu->actions();
1590 foreach(action, actions) {
1591 if (action->objectName() == key) {
1592 return action->isChecked();
1601 KMenu *tmp =
new KMenu();
1603 connect(tmp, SIGNAL(triggered(QAction*)),
this,
1606 d->menuList.append(tmp);
1612 QAction *action = menu->addAction(KIcon(icon), text);
1618 if (!d->globalView) {
1619 menu->popup(d->view->pos() + pos +
boundingRect().toRect().topLeft());
1621 menu->popup(mapToScene(pos).toPoint());
1627 int index = d->menuList.indexOf(menu);
1628 d->menuList.takeAt(index);
1630 menu->deleteLater();
1635 foreach(KMenu* menu, d->menuList) {
1636 QList<QAction*> actions = menu->actions();
1637 if (actions.contains(action)) {
1638 menu->removeAction(action);
1646 return d->menuList.contains(const_cast<KMenu*>(menu));
1652 if (
ImageLabel *image = dynamic_cast<ImageLabel*>(meter)) {
1653 image->smoothScale(width, height);
1667 #ifdef PYTHON_INCLUDE_PATH
1669 d->python->menuItemClicked(
this, (KMenu*)action->parentWidget(), (long)action);
1673 d->interface->callMenuItemClicked(
this, (KMenu*)action->parentWidget(), action);
1679 d->popupMenu->popup(QCursor::pos());
1684 QList<QGraphicsItem*> items = QGraphicsItemGroup::children();
1685 return items.contains(const_cast<Meter*>(meter));
1740 if (!d->wantRightButton) {
1741 d->popupMenu->exec(event->screenPos());
1747 #ifdef PYTHON_INCLUDE_PATH
1749 d->python->activeTaskChanged(
this, t.data());
1753 d->interface->callActiveTaskChanged(
this, t.data());
1758 #ifdef PYTHON_INCLUDE_PATH
1760 d->python->taskAdded(
this, t.data());
1764 d->interface->callTaskAdded(
this, t.data());
1769 #ifdef PYTHON_INCLUDE_PATH
1771 d->python->taskRemoved(
this, t.data());
1775 d->interface->callTaskRemoved(
this, t.data());
1780 #ifdef PYTHON_INCLUDE_PATH
1782 d->python->startupAdded(
this, t.data());
1786 d->interface->callStartupAdded(
this, t.data());
1791 #ifdef PYTHON_INCLUDE_PATH
1793 d->python->startupRemoved(
this, t.data());
1797 d->interface->callStartupRemoved(
this, t.data());
1802 #ifdef PYTHON_INCLUDE_PATH
1804 d->python->commandFinished(
this, (
int)proc->pid());
1808 d->interface->callCommandFinished(
this, (
int)proc->pid());
1813 #ifdef PYTHON_INCLUDE_PATH
1815 d->python->commandOutput(
this, (
int)proc->pid(), buffer);
1819 d->interface->callCommandOutput(
this, (
int)proc->pid(), buffer);
1825 if (event->mimeData()->hasText())
1826 event->acceptProposedAction();
1831 if (event->mimeData()->hasText()) {
1832 #ifdef PYTHON_INCLUDE_PATH
1834 d->python->itemDropped(
this, event->mimeData()->text(),
1835 (int)event->pos().x(), (int)event->pos().y());
1839 d->interface->callItemDropped(
this, event->mimeData()->text(),
1840 (int)event->pos().x(), (int)event->pos().y());
1847 d->mouseClickPos =
event->pos().toPoint();
1849 if (!(d->onTop || d->managed) && !d->globalView) {
1850 KWindowSystem::lowerWindow(d->view->winId());
1853 if (!d->toggleLocked->isChecked()) {
1857 int button = passEvent(event);
1859 #ifdef PYTHON_INCLUDE_PATH
1861 d->python->widgetClicked(
this, (
int)event->pos().x(),
1862 (int)event->pos().y(), button);
1867 d->interface->callWidgetClicked(
this, (
int)event->pos().x(),
1868 (int)event->pos().y(), button);
1874 if (!d->toggleLocked->isChecked())
1877 QList<QGraphicsItem*>items = d->scene->items(mapToScene(event->pos()));
1879 if (
Input *input = dynamic_cast<Input*>(item)) {
1880 input->mouseEventRelease(event);
1887 d->wantRightButton = enable;
1890 void Karamba::currentDesktopChanged(
int i)
1892 #ifdef PYTHON_INCLUDE_PATH
1894 d->python->desktopChanged(
this, i);
1898 d->interface->callDesktopChanged(
this, i);
1901 int Karamba::passEvent(QEvent *e)
1903 QList<QGraphicsItem*> items;
1907 if (QGraphicsSceneMouseEvent *event = dynamic_cast<QGraphicsSceneMouseEvent*>(e)) {
1908 items = d->scene->items(mapToScene(event->pos()));
1911 if (event->button() == Qt::LeftButton)
1913 else if (event->button() == Qt::MidButton)
1915 else if (event->button() == Qt::RightButton)
1917 }
else if (QGraphicsSceneWheelEvent *event = dynamic_cast<QGraphicsSceneWheelEvent*>(e)) {
1918 items = d->scene->items(mapToScene(event->pos()));
1921 if (event->delta() > 0)
1927 if (button == 3 && !d->wantRightButton) {
1933 bool allowClick =
false;
1938 else if (
ImageLabel* image = dynamic_cast<ImageLabel*>(item)) {
1939 allowClick = image->clickable();
1940 pass = image->mouseEvent(e);
1941 }
else if (
TextLabel* text = dynamic_cast<TextLabel*>(item)) {
1942 allowClick = text->clickable();
1943 pass = text->mouseEvent(e);
1944 }
else if (
ClickArea* area = dynamic_cast<ClickArea*>(item)) {
1945 pass = area->mouseEvent(e);
1946 }
else if (
RichTextLabel* rich = dynamic_cast<RichTextLabel*>(item)) {
1948 pass = rich->mouseEvent(e);
1950 QString anchor = rich->getAnchor(pos);
1951 #ifdef PYTHON_INCLUDE_PATH
1953 d->python->meterClicked(
this, anchor.toAscii().data(), button);
1956 d->interface->callMeterClicked(
this, anchor, button);
1960 if (
Input *input = dynamic_cast<Input*>(item)) {
1962 input->mouseEvent(e);
1965 if (pass && allowClick) {
1966 #ifdef PYTHON_INCLUDE_PATH
1968 d->python->meterClicked(
this, (
Meter*)item, button);
1972 d->interface->callMeterClicked(
this, (
Meter*)item, button);
1981 int button = passEvent(event);
1983 #ifdef PYTHON_INCLUDE_PATH
1985 d->python->widgetClicked(
this, (
int)event->pos().x(), (int)event->pos().y(), button);
1989 d->interface->callWidgetClicked(
this, (
int)event->pos().x(), (int)event->pos().y(), button);
1994 QList<QGraphicsItem*>items = d->scene->items(mapToScene(event->pos()));
1996 if (
Input *input = dynamic_cast<Input*>(item)) {
1997 input->mouseEventMove(event);
2001 foreach (
QGraphicsItem *item, QGraphicsItemGroup::children()) {
2002 if (
ImageLabel *image = dynamic_cast<ImageLabel*>(item)) {
2003 image->rolloverImage(event);
2007 #ifdef PYTHON_INCLUDE_PATH
2009 d->python->widgetMouseMoved(
this, (
int)event->pos().x(), (int)event->pos().y(), 0);
2013 d->interface->callWidgetMouseMoved(
this, (
int)event->pos().x(), (int)event->pos().y(), 0);
2029 return d->KWinModule->numberOfDesktops();
2034 d->interval = newInterval;
2039 return d->updateTime;
2044 d->updateTime = newTime;
2053 #ifdef PYTHON_INCLUDE_PATH
2055 d->python->keyPressed(
this, meter, s);
2060 d->interface->callKeyPressed(
this, (
Meter*)meter, s);
2066 d->size.setWidth(w);
2067 d->size.setHeight(h);
2078 if (!d->globalView) {
2079 if (!d->toggleLocked->isChecked()) {
2080 d->view->move(event->screenPos() - d->mouseClickPos);
2083 if (!d->toggleLocked->isChecked()) {
2084 QPointF diff =
event->pos() - d->mouseClickPos;
2085 parentItem()->moveBy(diff.x(), diff.y());
2094 if (
Input* input = dynamic_cast<Input*>(item)) {
2095 if (input && input->hasFocus()) {
2096 input->keyPress(event);
2105 if(change == QGraphicsItem::ItemPositionHasChanged) {
2108 return QGraphicsItemGroup::itemChange(change, value);
2113 QString pythonFile = d->theme.path() +
'/' + d->theme.scriptModule();
2114 if (file == d->theme.file() || file == pythonFile) {
2121 d->popupMenu->addSeparator();
2123 d->globalMenu = menu;
2124 d->popupMenu->addMenu(menu);
2129 d->popupMenu->removeAction(d->globalMenu->menuAction());
2135 return d->globalMenu != 0;
2150 if (!d->globalView) {
2155 parentItem()->setPos(pos);
2165 if (!d->globalView) {
2166 d->view->setFixedSize(width, height);
2174 if (!d->globalView) {
2175 return d->view->pos();
2178 return parentItem()->pos().toPoint();
2180 return pos().toPoint();
2187 d->storedData = data;
2192 d->interface->callThemeNotify(
this, sender, data);
2209 return d->storedData;
2231 delete d->currProcess;
2237 return d->currProcess;
2242 d->systray = systray;
2252 #ifdef PLASMASENSOR_ENABLED
2253 Sensor* sensor = d->sensorMap[
"PLASMA." + engine +
'.' + source];
2257 sensor = plasmasensor;
2258 d->sensorMap[
"PLASMA." + engine +
'.' + source] = sensor;
2259 d->sensorList.append(sensor);
2271 if ( ! name.isNull() ) {
2275 if( retVal.isEmpty() ) {
2278 if ( intVal >= meter->
getMin() ) {
2279 retVal = QString::number(intVal);
2291 QRegExp rx (
"%named:(\\w+)", Qt::CaseInsensitive);
2293 while ( pos >= 0 ) {
2294 pos = rx.indexIn(*source, pos);
2296 QString namedReplacement = rx.cap(1);
2297 if( !namedReplacement.isEmpty() ) {
2299 if( replacementValue.isNull()) {
2300 replacementValue = QString(
"");
2302 source->replace(QRegExp(
"%named:" + namedReplacement, Qt::CaseInsensitive), replacementValue);
2312 QList<QGraphicsItem*> items = QGraphicsItemGroup::children();
2314 if (
Meter* meter = dynamic_cast<Meter*>(item)) {
2315 if(name == meter->objectName()){
2316 return (
Meter*) meter;
2325 emit
error(errormessage);
void deletePopupMenu(KMenu *menu)
void removeKaramba(Karamba *karamba)
virtual int getHeight() const
void moveMeter(Meter *meter, int x, int y) const
QGraphicsScene * getScene() const
void setBGColor(QColor clr)
virtual int getWidth() const
void emitError(const QString &errormessage)
void moveToPos(QPoint pos)
void startupAdded(Startup::StartupPtr)
const QString & meter() const
void setFont(const QString &)
void slotFileChanged(const QString &file)
void addKaramba(Karamba *newKaramba)
QColor getColor(const QString &w, const QColor &def=QColor()) const
K3Process * process() const
void popupGlobalMenu() const
void keyPressed(const QString &s, const Meter *meter)
QString prettyName() const
QGraphicsView * getView() const
void keyPressEvent(QKeyEvent *event)
void setTextProps(TextField *t)
virtual int getMin() const
virtual void setSize(int x, int y, int width, int height)
Karamba(const KUrl &themeFile, QGraphicsView *view=0, int instance=-1, bool subTheme=false, const QPoint &startPos=QPoint(), bool reload=false, bool startkaramba=true)
void setSystemTray(Systemtray *)
QString getMeterValue(const QString &name)
void removeMenuExtension()
void setMenuExtension(KMenu *)
void setFixedSize(u_int w, u_int h)
void parseImages(const QString &fn, const QString &fn_roll, int, int, int, int)
bool hasMenuExtension() const
void deleteMeterFromSensors(Meter *meter)
void setTextProps(TextField *)
QString getString(const QString &w, const QString &def=QString()) const
void notifyTheme(const QString &sender, const QString &data)
void setValue(const QString &text)
Karamba * getKarambaByName(const QString &name) const
SensorParams * hasMeter(const Meter *meter) const
void startupRemoved(Startup::StartupPtr)
QColor getBGColor() const
const ThemeFile & theme() const
Meter * getMeter(const QString &name)
void processExited(K3Process *proc)
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void setOnClick(const QString &)
void setProcess(K3Process *process)
void mousePressEvent(QGraphicsSceneMouseEvent *event)
virtual QString getStringValue() const
KSharedPtr< Startup > StartupPtr
void deleteMeter(Meter *meter)
bool setImage(const QString &imagePath)
void setPlotDirection(const QString &)
void setColor(QColor clr)
void changeInterval(u_int newInterval)
void replaceNamedValues(QString *source)
QString getSensor(const Meter *meter) const
void setWantRightButton(bool enable)
void addParam(const QString &name, const QString &value)
QString retrieveReceivedData() const
void passMenuItemClicked(QAction *action)
bool getBoolean(const QString &w, bool def=false) const
bool popupMenuExisting(const KMenu *menu) const
QAction * addMenuItem(KMenu *menu, const QString &text, const QString &icon)
void resizeTo(int width, int height)
bool getFixedPitch() const
void activeTaskChanged(Task::TaskPtr)
int getNumberOfDesktops() const
This is a helper class that connects a Plasma::DataEngine together with a SuperKaramba Meter widget...
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
KDE_EXPORT QGraphicsItemGroup * startKaramba(const KUrl &theme, QGraphicsView *view)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
virtual void setEngine(const QString &name)
Set the engine that should be used.
virtual void setMin(int m)
void popupMenu(KMenu *menu, const QPoint &pos) const
void setPrettyName(const QString &prettyThemeName)
void setOnTop(bool stayOnTop)
void setScrollDirection(const QString &)
virtual int getValue() const
void setTooltip(QString txt)
double getUpdateTime() const
void setIncomingData(const QString &data)
static KarambaManager * self()
void error(const QString &errormessage)
virtual void setMax(int max)
void setValue(const QString &imagePath)
virtual void setMaxValue(SensorParams *s)
void receivedStdout(K3Process *proc, char *buffer, int buflen)
void setUpdateTime(double newTime)
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
void setFillColor(QColor)
static TaskManager * self()
QObject * getPlasmaSensor(const QString &engine, const QString &source=QString())
void setBackground(int b)
bool hasMeter(const Meter *meter) const
void deleteMenuItem(QAction *action)
void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
virtual QObject * connectSource(const QString &source, QObject *visualization=0)
Connect with a source.
virtual void setColor(QColor color)
void taskAdded(Task::TaskPtr)
KConfig * getConfig() const
virtual void setMin(int min)
TextField * getDefaultTextProps()
void setTextProps(TextField *)
bool setMenuConfigOption(const QString &key, bool value)
bool removeMeter(Meter *meter)
void addMenuConfigOption(const QString &key, const QString &name)
void dropEvent(QGraphicsSceneDragDropEvent *event)
void wheelEvent(QGraphicsSceneWheelEvent *event)
void taskRemoved(Task::TaskPtr)
QRectF boundingRect() const
Systemtray * systemTray()
void setInstance(int instance)
void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
void scaleImageLabel(Meter *meter, int width, int height) const
void setSensor(const LineParser &lineParser, Meter *meter)
bool readMenuConfigOption(const QString &key) const
QPoint getPosition() const
The PlasmaSensor class implements a SuperKaramba sensor that provides access to Plasma::DataEngine ob...
KSharedPtr< Task > TaskPtr
QString getAlignmentAsString() const
void setValue(const QString &)
void setProperty(const QByteArray &name, const QVariant &value)
Set a property.
bool sendDataToTheme(const QString &prettyThemeName, const QString &data)
void setText(const QString &text, bool linkUnderline=false)
void timerEvent(QTimerEvent *event)
bool sendData(const QString &prettyThemeName, const QString &data)
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
virtual void setMax(int m)
int getInt(const QString &w, int def=0) const
void addMeter(SensorParams *s)