• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

  • superkaramba
  • src
karamba.cpp
1/*
2 * Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org>
3 * Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se>
4 * Copyright (C) 2004,2005 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
5 * Copyright (c) 2005 Ryan Nickell <p0z3r@earthlink.net>
6 *
7 * This file is part of SuperKaramba.
8 *
9 * SuperKaramba is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * SuperKaramba is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with SuperKaramba; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 ****************************************************************************/
23
24#include "karamba_python.h"
25#include "dcopinterface_stub.h"
26#include "richtextlabel.h"
27#include "karamba.h"
28#include "karambaapp.h"
29#include "themesdlg.h"
30#include "lineparser.h"
31#include "themelocale.h"
32#include "superkarambasettings.h"
33
34#include <kdebug.h>
35#include <tdemessagebox.h>
36#include <krun.h>
37#include <tdelocale.h>
38#include <twin.h>
39#include <kdirwatch.h>
40
41#include <tdeparts/componentfactory.h>
42#include <tdeparts/part.h>
43
44#include <tqdir.h>
45#include <tqwidgetlist.h>
46
47// Menu IDs
48#define EDITSCRIPT 1
49#define THEMECONF 2
50
51karamba::karamba(TQString fn, TQString name, bool reloading, int instance,
52 bool sub_theme):
53 TQWidget(0,"karamba", TQt::WGroupLeader | WStyle_Customize |
54 WRepaintNoErase| WStyle_NoBorder | WDestructiveClose ),
55 meterList(0), imageList(0), clickList(0), kpop(0), widgetMask(0),
56 config(0), kWinModule(0), tempUnit('C'), m_instance(instance),
57 sensorList(0), timeList(0),
58 themeConfMenu(0), toDesktopMenu(0), kglobal(0), clickPos(0, 0), accColl(0),
59 menuAccColl(0), toggleLocked(0), pythonIface(0), defaultTextField(0),
60 trayMenuSeperatorId(-1), trayMenuQuitId(-1), trayMenuToggleId(-1),
61 trayMenuThemeId(-1),
62 m_sysTimer(NULL)
63{
64 themeStarted = false;
65 want_right_button = false;
66 want_meter_wheel_event = false;
67 prettyName = name;
68 m_sub_theme = sub_theme;
69
70 KURL url;
71
72 if(fn.find('/') == -1)
73 url.setFileName(fn);
74 else
75 url = fn;
76 if(!m_theme.set(url))
77 {
78 setFixedSize(0, 0);
79 TQTimer::singleShot(100, this, TQ_SLOT(killWidget()));
80 return;
81 }
82 // Add self to list of open themes
83 // This also updates instance number
84 karambaApp->addKaramba(this, reloading);
85
86 if(prettyName.isEmpty())
87 prettyName = TQString("%1 - %2").arg(m_theme.name()).arg(m_instance);
88
89 kdDebug() << "Starting theme: " << m_theme.name()
90 << " pretty name: " << prettyName << endl;
91 TQString qName = "karamba - " + prettyName;
92 setName(qName.ascii());
93
94 KDirWatch *dirWatch = KDirWatch::self();
95 connect(dirWatch, TQ_SIGNAL( dirty( const TQString & ) ),
96 TQ_SLOT( slotFileChanged( const TQString & ) ) );
97
98 if(!dirWatch->contains(m_theme.file()))
99 dirWatch->addFile(m_theme.file());
100
101 if(!m_theme.isZipTheme() && m_theme.pythonModuleExists())
102 {
103 TQString pythonFile = m_theme.path() + "/" + m_theme.pythonModule() + ".py";
104 if(!dirWatch->contains(pythonFile))
105 dirWatch->addFile(pythonFile);
106 }
107
108 widgetUpdate = true;
109
110 // Creates TDEConfig Object
111 TQString instanceString;
112 if(m_instance > 1)
113 instanceString = TQString("-%1").arg(m_instance);
114 TQString cfg = TQDir::home().absPath() + "/.superkaramba/"
115 + m_theme.id() + instanceString + ".rc";
116 kdDebug() << cfg << endl;
117 TQFile themeConfigFile(cfg);
118 // Tests if config file Exists
119 if (!TQFileInfo(themeConfigFile).exists())
120 {
121 // Create config file
122 themeConfigFile.open(IO_ReadWrite);
123 themeConfigFile.close();
124 }
125
126 config = new TDEConfig(cfg, false, false);
127 config -> sync();
128 config -> setGroup("internal");
129
130 m_reloading = reloading;
131 if(m_theme.pythonModuleExists())
132 {
133 kdDebug() << "Loading python module: " << m_theme.pythonModule() << endl;
134 TQTimer::singleShot(0, this, TQ_SLOT(initPythonInterface()));
135 }
136
137 widgetMask = 0;
138 info = new NETWinInfo( tqt_xdisplay(), winId(), tqt_xrootwin(), NET::WMState );
139
140 // could be replaced with TaskManager
141 kWinModule = new KWinModule();
142 desktop = 0;
143
144 connect( kWinModule,TQ_SIGNAL(currentDesktopChanged(int)), this,
145 TQ_SLOT(currentDesktopChanged(int)) );
146 connect( kapp, TQ_SIGNAL(backgroundChanged(int)), this,
147 TQ_SLOT(currentWallpaperChanged(int)));
148
149 // Setup of the Task Manager Callbacks
150 connect(&taskManager, TQ_SIGNAL(activeTaskChanged(Task*)), this,
151 TQ_SLOT(activeTaskChanged(Task*)) );
152 connect(&taskManager, TQ_SIGNAL(taskAdded(Task*)), this,
153 TQ_SLOT(taskAdded(Task*)) );
154 connect(&taskManager, TQ_SIGNAL(taskRemoved(Task*)), this,
155 TQ_SLOT(taskRemoved(Task*)) );
156 connect(&taskManager, TQ_SIGNAL(startupAdded(Startup*)), this,
157 TQ_SLOT(startupAdded(Startup*)) );
158 connect(&taskManager, TQ_SIGNAL(startupRemoved(Startup*)), this,
159 TQ_SLOT(startupRemoved(Startup*)) );
160
161 themeConfMenu = new TDEPopupMenu( this);
162 themeConfMenu -> setCheckable(true);
163
164 /* XXX - need to be able to delete all these DesktopChangeSlot objects */
165 DesktopChangeSlot *dslot;
166
167 int mid;
168
169 toDesktopMenu = new TDEPopupMenu (this);
170 toDesktopMenu -> setCheckable(true);
171 mid = toDesktopMenu -> insertItem (i18n("&All Desktops"),
172 dslot = new DesktopChangeSlot(this,0),
173 TQ_SLOT(receive()));
174 dslot->setMenuId(mid);
175
176 toDesktopMenu -> insertSeparator();
177 for (int ndesktop=1; ndesktop <= kWinModule->numberOfDesktops(); ndesktop++)
178 {
179 TQString name = i18n("Desktop &");
180 name += ('0' + ndesktop);
181
182 mid = toDesktopMenu -> insertItem (name,
183 dslot = new DesktopChangeSlot(this, ndesktop), TQ_SLOT(receive()));
184 dslot->setMenuId(mid);
185 }
186
187
188 kpop = new TDEPopupMenu( this );
189 kpop -> setCheckable(true);
190
191 accColl = new TDEActionCollection( this );
192 menuAccColl = new TDEActionCollection( this );
193
194 kpop->insertItem( SmallIconSet("reload"),i18n("Update"), this,
195 TQ_SLOT(updateSensors()), Key_F5 );
196 toggleLocked = new TDEToggleAction ( i18n("Toggle &Locked Position"),
197 SmallIconSet("locked"),
198 CTRL+Key_L, this,
199 TQ_SLOT( slotToggleLocked() ),
200 accColl, "Locked position" );
201 accColl->insert(toggleLocked);
202 toggleLocked -> setChecked(true);
203
204 toggleLocked->plug(kpop);
205
206 toggleFastTransforms = new TDEToggleAction(i18n("Use &Fast Image Scaling"),
207 CTRL+Key_F, this,
208 TQ_SLOT( slotToggleFastTransforms() ),
209 accColl, "Fast transformations");
210
211 accColl->insert(toggleFastTransforms);
212 toggleFastTransforms -> setChecked(true);
213
214 toggleFastTransforms -> plug(kpop);
215
216 kpop->insertSeparator();
217
218 kpop->insertItem(i18n("Configure &Theme"), themeConfMenu, THEMECONF);
219 kpop->setItemEnabled(THEMECONF, false);
220 kpop->insertItem(i18n("To Des&ktop"), toDesktopMenu);
221
222 kpop->insertItem( SmallIconSet("reload3"),i18n("&Reload Theme"),this,
223 TQ_SLOT(reloadConfig()), CTRL+Key_R );
224 kpop->insertItem( SmallIconSet("window-close"),i18n("&Close This Theme"), this,
225 TQ_SLOT(killWidget()), CTRL+Key_C );
226
227 if(!SuperKarambaSettings::showSysTray())
228 showMenuExtension();
229
230 kpop->polish();
231
232 numberOfConfMenuItems = 0;
233
234 systray = 0;
235 foundKaramba = false;
236 onTop = false;
237 managed = false;
238 fixedPosition = false;
239 defaultTextField = new TextField();
240
241 meterList = new TQObjectList();
242 meterList->setAutoDelete( true );
243 sensorList = new TQObjectList();
244 sensorList->setAutoDelete( true );
245 clickList = new TQObjectList();
246 timeList = new TQObjectList();
247 imageList = new TQObjectList();
248 menuList = new TQObjectList();
249 menuList->setAutoDelete( true );
250
251 client = kapp->dcopClient();
252 if (!client->isAttached())
253 client->attach();
254 appId = client->registerAs(tqApp->name());
255
256
257 setBackgroundMode( NoBackground);
258 if( !(onTop || managed))
259 KWin::lowerWindow( winId() );
260
261 if( !parseConfig() )
262 {
263 setFixedSize(0,0);
264 TQTimer::singleShot( 100, this, TQ_SLOT(killWidget()) );
265 tqWarning("Could not read config file.");
266 }
267 else
268 {
269 kroot = new KarambaRootPixmap((TQWidget*)this);
270 kroot->start();
271 }
272
273 // Karamba specific Config Entries
274 bool locked = toggleLocked->isChecked();
275 locked = config->readBoolEntry("lockedPosition", locked);
276 toggleLocked->setChecked(locked);
277 slotToggleLocked();
278
279 if (!config -> readBoolEntry("fastTransforms", true))
280 {
281 toggleFastTransforms -> setChecked(false);
282 slotToggleFastTransforms();
283 }
284
285 desktop = config -> readNumEntry("desktop", desktop);
286 if (desktop > kWinModule->numberOfDesktops())
287 {
288 desktop = 0;
289 }
290
291 if (desktop)
292 {
293 info->setDesktop( desktop );
294 }
295 else
296 info->setDesktop( NETWinInfo::OnAllDesktops);
297
298 // Read Themespecific Config Entries
299 config -> setGroup("theme");
300 if (config -> hasKey("widgetPosX") && config -> hasKey("widgetPosY"))
301 {
302 int xpos = config -> readNumEntry("widgetPosX");
303 int ypos = config -> readNumEntry("widgetPosY");
304
305 if (xpos < 0)
306 xpos = 0;
307 if (ypos < 0)
308 ypos = 0;
309 move(xpos, ypos);
310 }
311
312 haveUpdated = false;
313 this->setMouseTracking(true);
314
315
316 setFocusPolicy(TQWidget::StrongFocus);
317}
318
319karamba::~karamba()
320{
321 //tqDebug("karamba::~karamba");
322 //Remove self from list of open themes
323 karambaApp->deleteKaramba(this, m_reloading);
324
325 widgetClosed();
326 if(m_theme.isValid())
327 writeConfigData();
328
329 delete config;
330
331 if(meterList != 0)
332 {
333 meterList->clear();
334 delete meterList;
335 }
336
337 if( sensorList != 0 )
338 {
339 sensorList->clear();
340 delete sensorList;
341 }
342
343 if( imageList != 0 )
344 {
345 imageList->clear();
346 delete imageList;
347 }
348
349 if( clickList != 0 )
350 {
351 clickList->clear();
352 delete clickList;
353 }
354
355 if( timeList != 0 )
356 {
357 timeList->clear();
358 delete timeList;
359 }
360
361 delete toggleLocked;
362 delete accColl;
363 delete menuAccColl;
364 delete themeConfMenu;
365 delete kpop;
366 delete widgetMask;
367 delete kWinModule;
368 delete defaultTextField;
369 if (pythonIface != NULL)
370 delete pythonIface;
371}
372
373bool karamba::parseConfig()
374{
375 //tqDebug("karamba::parseConfig");
376 bool passive = true;
377
378 if(m_theme.open())
379 {
380 TQValueStack<TQPoint> offsetStack;
381 LineParser lineParser;
382 int x=0;
383 int y=0;
384 int w=0;
385 int h=0;
386
387 offsetStack.push(TQPoint(0,0));
388
389 while(m_theme.nextLine(lineParser))
390 {
391 x = lineParser.getInt("X") + offsetStack.top().x();
392 y = lineParser.getInt("Y") + offsetStack.top().y();
393 w = lineParser.getInt("W");
394 h = lineParser.getInt("H");
395
396 if(lineParser.meter() == "KARAMBA" && !foundKaramba )
397 {
398 //tqDebug("karamba found");
399 toggleLocked->setChecked(lineParser.getBoolean("LOCKED"));
400 slotToggleLocked();
401
402 x = ( x < 0 ) ? 0:x;
403 y = ( y < 0 ) ? 0:y;
404
405 if( w == 0 || h == 0)
406 {
407 w = 300;
408 h = 300;
409 }
410 setFixedSize(w,h);
411
412 if(lineParser.getBoolean("RIGHT"))
413 {
414 TQDesktopWidget *d = TQApplication::desktop();
415 x = d->width() - w;
416 }
417 else if(lineParser.getBoolean("LEFT"))
418 {
419 x = 0;
420 }
421
422 if(lineParser.getBoolean("BOTTOM"))
423 {
424 TQDesktopWidget *d = TQApplication::desktop();
425 y = d->height() - h;
426 }
427 else if(lineParser.getBoolean("TOP"))
428 {
429 y = 0;
430 }
431
432 move(x,y);
433 //pm = TQPixmap(size());
434
435 if(lineParser.getBoolean("ONTOP"))
436 {
437 onTop = true;
438 KWin::setState( winId(), NET::StaysOnTop );
439 }
440
441 if(lineParser.getBoolean("MANAGED"))
442 {
443 managed = true;
444 reparent(0, TQt::WType_Dialog | WStyle_Customize | WStyle_NormalBorder
445 | WRepaintNoErase | WDestructiveClose, pos());
446 }
447 else
448 {
449 info->setState( NETWinInfo::SkipTaskbar
450 | NETWinInfo::SkipPager,NETWinInfo::SkipTaskbar
451 | NETWinInfo::SkipPager );
452 if (onTop)
453 {
454 KWin::setState( winId(), NET::StaysOnTop );
455
456 }
457 }
458
459 if (lineParser.getBoolean("ONALLDESKTOPS"))
460 {
461 desktop = 200; // ugly
462 }
463
464
465 bool dfound=false;
466 //int desktop = lineParser.getInt("DESKTOP", line, dfound);
467 if (dfound)
468 {
469 info->setDesktop( dfound );
470 }
471 if(lineParser.getBoolean("TOPBAR"))
472 {
473 move(x,0);
474 KWin::setStrut( winId(), 0, 0, h, 0 );
475 toggleLocked->setChecked( true );
476 slotToggleLocked();
477 toggleLocked->setEnabled(false);
478 }
479
480 if(lineParser.getBoolean("BOTTOMBAR"))
481 {
482 int dh = TQApplication::desktop()->height();
483 move( x, dh - h );
484 KWin::setStrut( winId(), 0, 0, 0, h );
485 toggleLocked->setChecked( true );
486 slotToggleLocked();
487 toggleLocked->setEnabled(false);
488 }
489
490 if(lineParser.getBoolean("RIGHTBAR"))
491 {
492 int dw = TQApplication::desktop()->width();
493 move( dw - w, y );
494 KWin::setStrut( winId(), 0, w, 0, 0 );
495 toggleLocked->setChecked( true );
496 slotToggleLocked();
497 toggleLocked->setEnabled(false);
498 }
499
500 if(lineParser.getBoolean("LEFTBAR"))
501 {
502 move( 0, y );
503 KWin::setStrut( winId(), w, 0, 0, 0 );
504 toggleLocked->setChecked( true );
505 slotToggleLocked();
506 toggleLocked->setEnabled(false);
507 }
508
509 TQString path = lineParser.getString("MASK");
510
511 TQFileInfo info(path);
512 TQString absPath;
513 TQBitmap bmMask;
514 TQByteArray ba;
515 if( info.isRelative() )
516 {
517 absPath.setAscii(m_theme.path().ascii());
518 absPath.append(path.ascii());
519 ba = m_theme.readThemeFile(path);
520 }
521 else
522 {
523 absPath.setAscii(path.ascii());
524 ba = m_theme.readThemeFile(info.fileName());
525 }
526 if(m_theme.isZipTheme())
527 {
528 bmMask.loadFromData(ba);
529 }
530 else
531 {
532 bmMask.load(absPath);
533 }
534 setMask(bmMask);
535
536 m_interval = lineParser.getInt("INTERVAL");
537 m_interval = (m_interval == 0) ? 1000 : m_interval;
538
539 TQString temp = lineParser.getString("TEMPUNIT", "C").upper();
540 tempUnit = temp.ascii()[0];
541 foundKaramba = true;
542 }
543
544 if(lineParser.meter() == "THEME")
545 {
546 TQString path = lineParser.getString("PATH");
547 TQFileInfo info(path);
548 if( info.isRelative())
549 path = m_theme.path() +"/" + path;
550 (new karamba( path, TQString() ))->show();
551 }
552
553 if(lineParser.meter() == "<GROUP>")
554 {
555 int offsetX = offsetStack.top().x();
556 int offsetY = offsetStack.top().y();
557 offsetStack.push( TQPoint( offsetX + lineParser.getInt("X"),
558 offsetY + lineParser.getInt("Y")));
559 }
560
561 if(lineParser.meter() == "</GROUP>")
562 {
563 offsetStack.pop();
564 }
565
566 if(lineParser.meter() == "CLICKAREA")
567 {
568 if( !hasMouseTracking() )
569 setMouseTracking(true);
570 ClickArea *tmp = new ClickArea(this, x, y, w, h );
571 tmp->setOnClick(lineParser.getString("ONCLICK"));
572
573 setSensor(lineParser, (Meter*)tmp);
574 clickList->append( tmp );
575 if( lineParser.getBoolean("PREVIEW"))
576 meterList->append( tmp );
577 }
578
579 // program sensor without a meter
580 if(lineParser.meter() == "SENSOR=PROGRAM")
581 {
582 setSensor(lineParser, 0 );
583 }
584
585 if(lineParser.meter() == "IMAGE")
586 {
587 TQString file = lineParser.getString("PATH");
588 TQString file_roll = lineParser.getString("PATHROLL");
589 int xon = lineParser.getInt("XROLL");
590 int yon = lineParser.getInt("YROLL");
591 TQString tiptext = lineParser.getString("TOOLTIP");
592 TQString name = lineParser.getString("NAME");
593 bool bg = lineParser.getBoolean("BACKGROUND");
594 xon = ( xon <= 0 ) ? x:xon;
595 yon = ( yon <= 0 ) ? y:yon;
596
597 ImageLabel *tmp = new ImageLabel(this, x, y, 0, 0);
598 tmp->setValue(file);
599 if(!file_roll.isEmpty())
600 tmp->parseImages(file, file_roll, x,y, xon, yon);
601 tmp->setBackground(bg);
602 if (!name.isEmpty())
603 tmp->setName(name.ascii());
604 if (!tiptext.isEmpty())
605 tmp->setTooltip(tiptext);
606
607 connect(tmp, TQ_SIGNAL(pixmapLoaded()), this, TQ_SLOT(externalStep()));
608 setSensor(lineParser, (Meter*) tmp );
609 meterList->append (tmp );
610 imageList->append (tmp );
611 }
612
613 if(lineParser.meter() == "DEFAULTFONT" )
614 {
615 delete defaultTextField;
616 defaultTextField = new TextField( );
617
618 defaultTextField->setColor(lineParser.getColor("COLOR",
619 TQColor("black")));
620 defaultTextField->setBGColor(lineParser.getColor("BGCOLOR",
621 TQColor("white")));
622 defaultTextField->setFont(lineParser.getString("FONT", "Helvetica"));
623 defaultTextField->setFontSize(lineParser.getInt("FONTSIZE", 12));
624 defaultTextField->setAlignment(lineParser.getString("ALIGN",
625 "LEFT"));
626 defaultTextField->setFixedPitch(lineParser.getBoolean("FIXEDPITCH",
627 false));
628 defaultTextField->setShadow(lineParser.getInt("SHADOW", 0));
629 }
630
631 if(lineParser.meter() == "TEXT" ||
632 lineParser.meter() == "CLICKMAP" ||
633 lineParser.meter() == "RICHTEXT" ||
634 lineParser.meter() == "INPUT")
635 {
636 TextField defTxt;
637
638 if(defaultTextField)
639 defTxt = *defaultTextField;
640
641 TextField* tmpText = new TextField();
642
643 tmpText->setColor(lineParser.getColor("COLOR", defTxt.getColor()));
644 tmpText->setBGColor(lineParser.getColor("BGCOLOR",
645 defTxt.getBGColor()));
646 tmpText->setFont(lineParser.getString("FONT", defTxt.getFont()));
647 tmpText->setFontSize(lineParser.getInt("FONTSIZE",
648 defTxt.getFontSize()));
649 tmpText->setAlignment(lineParser.getString("ALIGN",
650 defTxt.getAlignmentAsString()));
651 tmpText->setFixedPitch(lineParser.getInt("FIXEDPITCH",
652 defTxt.getFixedPitch()));
653
654 tmpText->setShadow(lineParser.getInt("SHADOW", defTxt.getShadow()));
655
656 // ////////////////////////////////////////////////////
657 // Now handle the specifics
658 if(lineParser.meter() == "TEXT")
659 {
660
661 TextLabel *tmp = new TextLabel(this, x, y, w, h );
662 tmp->setTextProps(tmpText);
663 tmp->setValue(
664 m_theme.locale()->translate(lineParser.getString("VALUE")));
665
666 TQString name = lineParser.getString("NAME");
667 if (!name.isEmpty())
668 tmp->setName(name.ascii());
669
670 setSensor(lineParser, (Meter*)tmp);
671 meterList->append ( tmp );
672 }
673
674 if(lineParser.meter() == "CLICKMAP")
675 {
676 if( !hasMouseTracking() )
677 setMouseTracking(true);
678 ClickMap *tmp = new ClickMap(this, x, y, w, h);
679 tmp->setTextProps( tmpText );
680
681 setSensor(lineParser, (Meter*)tmp);
682 // set all params
683 clickList -> append(tmp);
684 meterList->append( tmp );
685
686 }
687
688 if(lineParser.meter() == "RICHTEXT")
689 {
690 RichTextLabel *tmp = new RichTextLabel(this, x, y, w, h);
691
692 bool dUl = lineParser.getBoolean("UNDERLINE");
693
694 tmp->setText(
695 m_theme.locale()->translate(lineParser.getString("VALUE").ascii()), dUl);
696 tmp->setTextProps( tmpText );
697 tmp->setWidth(w);
698 tmp->setHeight(h);
699
700 TQString name = lineParser.getString("NAME");
701 if (!name.isEmpty())
702 tmp->setName(name.ascii());
703
704 setSensor(lineParser, (Meter*)tmp);
705 clickList -> append(tmp);
706 meterList->append ( tmp );
707 }
708
709 if(lineParser.meter() == "INPUT")
710 {
711 Input *tmp = new Input(this, x, y, w, h);
712
713 TQString name = lineParser.getString("NAME");
714 if (!name.isEmpty())
715 tmp->setName(name.ascii());
716
717 tmp->setTextProps(tmpText);
718 tmp->setValue(
719 m_theme.locale()->translate(lineParser.getString("VALUE").ascii()));
720
721 meterList->append(tmp);
722 passive = false;
723 }
724 }
725
726 if(lineParser.meter() == "BAR")
727 {
728 Bar *tmp = new Bar(this, x, y, w, h );
729 tmp->setImage(lineParser.getString("PATH").ascii());
730 tmp->setVertical(lineParser.getBoolean("VERTICAL"));
731 tmp->setMax(lineParser.getInt("MAX", 100));
732 tmp->setMin(lineParser.getInt("MIN", 0));
733 tmp->setValue(lineParser.getInt("VALUE"));
734 TQString name = lineParser.getString("NAME");
735 if (!name.isEmpty())
736 tmp->setName(name.ascii());
737 setSensor(lineParser, (Meter*)tmp );
738 meterList->append ( tmp );
739 }
740
741 if(lineParser.meter() == "GRAPH")
742 {
743 int points = lineParser.getInt("POINTS");
744
745 Graph *tmp = new Graph(this, x, y, w, h, points);
746 tmp->setMax(lineParser.getInt("MAX", 100));
747 tmp->setMin(lineParser.getInt("MIN", 0));
748 TQString name = lineParser.getString("NAME");
749 if (!name.isEmpty())
750 tmp->setName(name.ascii());
751
752 tmp->setColor(lineParser.getColor("COLOR"));
753
754 setSensor(lineParser, (Graph*)tmp);
755 meterList->append ( tmp );
756 }
757 }
758
759 if(passive && !managed)
760 {
761 // Matthew Kay: set window type to "dock"
762 // (plays better with taskbar themes this way)
763 KWin::setType(winId(), NET::Dock);
764 KWin::setState(winId(), NET::KeepBelow);
765 }
766
767 m_theme.close();
768 }
769 //tqDebug("parseConfig ok: %d", foundKaramba);
770 if( !foundKaramba )
771 {
772 // interval = initKaramba( "", 0, 0, 0, 0 );
773 // this->close(true);
774 //delete this;
775 return false;
776 }
777 else
778 {
779 return true;
780 }
781}
782
783void karamba::start()
784{
785 m_sysTimer = new TQTimer(this);
786
787 connect(m_sysTimer, TQ_SIGNAL(timeout()), TQ_SLOT(step()));
788
789 m_sysTimer->start(m_interval);
790
791 //Start the widget running
792 TQTimer::singleShot( 0, this, TQ_SLOT(step()) );
793
794 if( !(onTop || managed) )
795 lowerTimer.start();
796}
797
798void karamba::makeActive()
799{
800 KWin::setType(winId(), NET::Normal);
801 KWin::setState(winId(), NET::Modal);
802}
803
804void karamba::makePassive()
805{
806 if(managed)
807 return;
808
809 TQObject *meter;
810 for (meter = meterList->first(); meter; meter = meterList->next())
811 {
812 if((meter)->isA("Input"))
813 return;
814 }
815
816 // Matthew Kay: set window type to "dock" (plays better with taskbar themes
817 // this way)
818 KWin::setType(winId(), NET::Dock);
819 KWin::setState(winId(), NET::KeepBelow);
820}
821
822void karamba::popupNotify(int)
823{
824 //tqDebug("karamba::popupNotify");
825}
826
827void karamba::reloadConfig()
828{
829 //tqDebug("karamba::reloadConfig: %s", m_theme.file().ascii());
830 writeConfigData();
831 if(m_theme.exists())
832 {
833 TQFileInfo fileInfo( m_theme.file() );
834 (new karamba(m_theme.file(), fileInfo.baseName(), true, m_instance))->show();
835 }
836 closeTheme(true);
837}
838
839void karamba::closeTheme(bool reloading)
840{
841 m_reloading = reloading;
842 close();
843}
844
845void karamba::killWidget()
846{
847 closeTheme();
848}
849
850void karamba::initPythonInterface()
851{
852 pythonIface = new KarambaPython(m_theme, m_reloading);
853}
854
855void karamba::editConfig()
856{
857 //tqDebug("karamba::editConfig");
858 TQFileInfo fileInfo( m_theme.file() );
859 TQString path;
860
861 if( fileInfo.isRelative() )
862 {
863 path = m_theme.path() + "/" + m_theme.file();
864 }
865 else
866 {
867 path = m_theme.file();
868 }
869
870 KRun::runURL( KURL( path ), "text/plain" );
871}
872
873void karamba::editScript()
874{
875 //tqDebug("karamba::editScript");
876 TQFileInfo fileInfo( m_theme.file() );
877 TQString path;
878
879 if( fileInfo.isRelative() )
880 {
881 path = m_theme.path() + "/" + m_theme.name() + ".py";
882 }
883 else
884 {
885 path = TQFileInfo(m_theme.file()).dirPath() + "/" + m_theme.name() + ".py";
886 }
887 KRun::runURL( KURL( path ), "text/plain" );
888}
889
890TQString karamba::findSensorFromMap(Sensor* sensor)
891{
892 //tqDebug("karamba::findSensorFromMap");
893 TQMap<TQString,Sensor*>::ConstIterator it;
894 TQMap<TQString,Sensor*>::ConstIterator end( sensorMap.end() );
895 for ( it = sensorMap.begin(); it != end; ++it )
896 {
897 if (it.data() == sensor)
898 return it.key();
899 }
900 return "";
901}
902
903Sensor* karamba::findSensorFromList(Meter* meter)
904{
905 //tqDebug("karamba::findSensorFromList");
906 TQObjectListIt it( *sensorList ); // iterate over meters
907
908 while ( it != 0 )
909 {
910 if (((Sensor*) *it)->hasMeter(meter))
911 return ((Sensor*)*it);
912 ++it;
913 }
914 return NULL;
915}
916
917TQString karamba::getSensor(Meter* meter)
918{
919 //tqDebug("karamba::getSensor");
920 TQString s;
921 Sensor* sensor = findSensorFromList(meter);
922 if (sensor)
923 s = findSensorFromMap(sensor);
924 return s;
925}
926
927void karamba::deleteMeterFromSensors(Meter* meter)
928{
929 //tqDebug("karamba::deleteMeterFromSensors");
930 Sensor* sensor = findSensorFromList(meter);
931
932 if (sensor)
933 {
934 sensor->deleteMeter(meter);
935 if (sensor->isEmpty())
936 {
937 TQString s = findSensorFromMap(sensor);
938 sensorMap.erase(s);
939 sensorList->removeRef(sensor);
940 }
941 }
942}
943
944void karamba::setSensor(const LineParser& lineParser, Meter* meter)
945{
946 //tqDebug("karamba::setSensor");
947 Sensor* sensor = 0;
948
949 deleteMeterFromSensors(meter);
950
951 TQString sens = lineParser.getString("SENSOR").upper();
952
953 if( sens == "CPU" )
954 {
955 TQString cpuNbr = lineParser.getString("CPU");
956 sensor = sensorMap["CPU"+cpuNbr];
957 if (sensor == 0)
958 {
959 int interval = lineParser.getInt("INTERVAL");
960 interval = (interval == 0)?1000:interval;
961 sensor = ( sensorMap["CPU"+cpuNbr] = new CPUSensor( cpuNbr, interval ) );
962 sensorList->append( sensor );
963 }
964 SensorParams *sp = new SensorParams(meter);
965 sp->addParam("FORMAT",
966 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
967 sp->addParam("DECIMALS",lineParser.getString("DECIMALS"));
968
969 sensor->addMeter(sp);
970 sensor->setMaxValue(sp);
971
972 }
973
974 if (sens == "GPU")
975 {
976 TQString gpuId = lineParser.getString("GPU");
977 TQString gpuDriver = lineParser.getString("DRIVER");
978 TQString sensorId = TQString("GPU_%1_%2").arg(gpuDriver, gpuId);
979 sensor = sensorMap[sensorId];
980 if (sensor == 0)
981 {
982 int interval = lineParser.getInt("INTERVAL");
983 interval = (interval == 0) ? 1000 : interval;
984 sensor = (sensorMap[sensorId] = new GPUSensor(gpuDriver, gpuId, interval));
985 sensorList->append(sensor);
986 }
987
988 SensorParams *sp = new SensorParams(meter);
989 sp->addParam("FORMAT", m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
990 sensor->addMeter(sp);
991 sensor->setMaxValue(sp);
992 }
993
994 if( sens == "MEMORY" )
995 {
996 sensor = sensorMap["MEMORY"];
997 if (sensor == 0)
998 {
999 int interval = lineParser.getInt("INTERVAL");
1000 interval = (interval == 0)?3000:interval;
1001 sensor = ( sensorMap["MEMORY"] = new MemSensor( interval ) );
1002 sensorList->append( sensor );
1003 }
1004 SensorParams *sp = new SensorParams(meter);
1005 sp->addParam("FORMAT",
1006 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
1007
1008 sensor->addMeter(sp);
1009 sensor->setMaxValue(sp);
1010 }
1011
1012
1013 if( sens == "DISK" )
1014 {
1015 sensor = sensorMap["DISK"];
1016 if (sensor == 0)
1017 {
1018 int interval = lineParser.getInt("INTERVAL");
1019 interval = (interval == 0)?5000:interval;
1020 sensor = ( sensorMap["DISK"] = new DiskSensor( interval ) );
1021 connect( sensor, TQ_SIGNAL(initComplete()), this, TQ_SLOT(externalStep()) );
1022 sensorList->append( sensor );
1023 }
1024 // meter->setMax( ((DiskSensor*)sensor)->getTotalSpace(mntPt)/1024 );
1025 SensorParams *sp = new SensorParams(meter);
1026 TQString mntPt = lineParser.getString("MOUNTPOINT");
1027 if( mntPt.isEmpty() )
1028 {
1029 mntPt = "/";
1030 }
1031 // remove any trailing '/' from mount points in the .theme config, our
1032 // mntMap doesn't like trailing '/'s for matching in DiskSensor
1033 if( mntPt.length() > 1 && mntPt.endsWith("/") )
1034 {
1035 mntPt.remove( mntPt.length()-1, 1 );
1036 }
1037 sp->addParam("MOUNTPOINT",mntPt);
1038 sp->addParam("FORMAT",
1039 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
1040 sensor->addMeter(sp);
1041 sensor->setMaxValue(sp);
1042 }
1043
1044 if( sens == "NETWORK")
1045 {
1046 int interval = lineParser.getInt("INTERVAL");
1047 interval = (interval == 0)?2000:interval;
1048 TQString device = lineParser.getString("DEVICE");
1049 sensor = sensorMap["NETWORK"+device];
1050 if (sensor == 0)
1051 {
1052 sensor = ( sensorMap["NETWORK"+device] =
1053 new NetworkSensor(device, interval));
1054 sensorList->append( sensor );
1055 }
1056 SensorParams *sp = new SensorParams(meter);
1057 sp->addParam("FORMAT",
1058 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
1059 sp->addParam("DECIMALS", lineParser.getString("DECIMALS"));
1060 sensor->addMeter(sp);
1061 }
1062
1063 if( sens == "UPTIME" )
1064 {
1065 sensor = sensorMap["UPTIME"];
1066 if (sensor == 0)
1067 {
1068 int interval = lineParser.getInt("INTERVAL");
1069 interval = (interval == 0)?60000:interval;
1070 sensor = ( sensorMap["UPTIME"] = new UptimeSensor( interval ));
1071 sensorList->append( sensor );
1072
1073 }
1074 SensorParams *sp = new SensorParams(meter);
1075 sp->addParam("FORMAT",
1076 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
1077 sensor->addMeter(sp);
1078 }
1079
1080 if( sens == "SENSOR" )
1081 {
1082 sensor = sensorMap["SENSOR"];
1083 if (sensor == 0)
1084 {
1085 int interval = lineParser.getInt("INTERVAL");
1086 interval = (interval == 0)?30000:interval;
1087 sensor = (sensorMap["SENSOR"] = new SensorSensor(interval, tempUnit));
1088 sensorList->append( sensor );
1089 }
1090 SensorParams *sp = new SensorParams(meter);
1091 sp->addParam("FORMAT",
1092 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
1093 sp->addParam("TYPE", lineParser.getString("TYPE"));
1094 sensor->addMeter(sp);
1095 }
1096
1097
1098 if( sens == "TEXTFILE" )
1099 {
1100 TQString path = lineParser.getString("PATH");
1101 bool rdf = lineParser.getBoolean("RDF");
1102 sensor = sensorMap["TEXTFILE"+path];
1103 if (sensor == 0)
1104 {
1105 int interval = lineParser.getInt("INTERVAL");
1106 interval = ( interval == 0 )?60000:interval;
1107 TQString encoding = lineParser.getString("ENCODING");
1108
1109 sensor = ( sensorMap["TEXTFILE"+path] =
1110 new TextFileSensor( path, rdf, interval, encoding ) );
1111 sensorList->append( sensor );
1112 }
1113 SensorParams *sp = new SensorParams(meter);
1114 sp->addParam("LINE",TQString::number(lineParser.getInt("LINE")));
1115 sensor->addMeter(sp);
1116 }
1117
1118
1119 if( sens == "TIME")
1120 {
1121 sensor = sensorMap["DATE"];
1122 if (sensor == 0)
1123 {
1124 int interval = lineParser.getInt("INTERVAL");
1125 interval = (interval == 0)?60000:interval;
1126 sensor = ( sensorMap["DATE"] = new DateSensor( interval ) );
1127 sensorList->append( sensor );
1128 timeList->append( sensor );
1129 }
1130 SensorParams *sp = new SensorParams(meter);
1131 sp->addParam("FORMAT",
1132 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
1133 sp->addParam("CALWIDTH",lineParser.getString("CALWIDTH"));
1134 sp->addParam("CALHEIGHT",lineParser.getString("CALHEIGHT"));
1135 sensor->addMeter(sp);
1136 }
1137
1138#ifdef HAVE_XMMS
1139
1140 if( sens == "XMMS" )
1141 {
1142 sensor = sensorMap["XMMS"];
1143 if (sensor == 0)
1144 {
1145 int interval = lineParser.getInt("INTERVAL");
1146 interval = (interval == 0)?1000:interval;
1147 TQString encoding = lineParser.getString("ENCODING");
1148
1149 sensor = ( sensorMap["XMMS"] = new XMMSSensor( interval, encoding ) );
1150 sensorList->append( sensor );
1151 }
1152 SensorParams *sp = new SensorParams(meter);
1153 sp->addParam("FORMAT",
1154 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
1155 sensor->addMeter(sp);
1156 sensor->setMaxValue(sp);
1157 }
1158#endif // HAVE_XMMS
1159
1160
1161 if( sens == "NOATUN" )
1162 {
1163 sensor = sensorMap["NOATUN"];
1164 if (sensor == 0)
1165 {
1166 int interval = lineParser.getInt("INTERVAL");
1167 interval = (interval == 0)?1000:interval;
1168 sensor = ( sensorMap["NOATUN"] = new NoatunSensor( interval, client ) );
1169 sensorList->append( sensor );
1170 }
1171 SensorParams *sp = new SensorParams(meter);
1172 sp->addParam("FORMAT",
1173 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii()));
1174 sensor->addMeter(sp);
1175 sensor->setMaxValue(sp);
1176 }
1177
1178 if( sens == "PROGRAM")
1179 {
1180 TQString progName = lineParser.getString("PROGRAM");
1181 sensor = sensorMap["PROGRAM"+progName];
1182 if (sensor == 0)
1183 {
1184 int interval = lineParser.getInt("INTERVAL");
1185 interval = (interval == 0)?3600000:interval;
1186 TQString encoding = lineParser.getString("ENCODING");
1187
1188 sensor = (sensorMap["PROGRAM"+progName] =
1189 new ProgramSensor( progName, interval, encoding ) );
1190 sensorList->append( sensor );
1191 }
1192 SensorParams *sp = new SensorParams(meter);
1193 sp->addParam( "LINE", TQString::number(lineParser.getInt("LINE")));
1194 sp->addParam( "THEMAPATH", m_theme.path() );
1195 sensor->addMeter(sp);
1196 }
1197
1198 if( sens == "RSS" )
1199 {
1200 TQString source = lineParser.getString("SOURCE");
1201 TQString format =
1202 m_theme.locale()->translate(lineParser.getString("FORMAT").ascii());
1203
1204 sensor = sensorMap["RSS"+source];
1205 if (sensor == 0)
1206 {
1207 int interval = lineParser.getInt( "INTERVAL");
1208 interval = ( interval == 0 )?60000:interval;
1209 TQString encoding = lineParser.getString("ENCODING");
1210
1211 sensor = ( sensorMap["RSS"+source] =
1212 new RssSensor( source, interval, format, encoding ) );
1213 sensorList->append( sensor );
1214 }
1215 SensorParams *sp = new SensorParams(meter);
1216 sp->addParam("SOURCE",lineParser.getString("SOURCE"));
1217 sensor->addMeter(sp);
1218 }
1219
1220 if (sensor != 0)
1221 {
1222 TQTimer::singleShot( 0, sensor, TQ_SLOT(update()) );
1223 sensor->start();
1224 }
1225}
1226
1227void karamba::slotFileChanged( const TQString & file)
1228{
1229 //kdDebug() << "fileChanged: " << file << endl;
1230
1231 TQString pythonFile = m_theme.path() + "/" + m_theme.pythonModule() + ".py";
1232
1233 if(file == m_theme.file() || file == pythonFile)
1234 reloadConfig();
1235}
1236
1237void karamba::passMenuOptionChanged(TQString key, bool value)
1238{
1239 //Everything below is to call the python callback function
1240 if (pythonIface && pythonIface->isExtensionLoaded())
1241 pythonIface->menuOptionChanged(this, key, value);
1242}
1243
1244void karamba::setIncomingData(TQString theme, TQString obj)
1245{
1246 KarambaApplication* app = (KarambaApplication*)tqApp;
1247
1248 kdDebug() << "karamba::setIncomingData " << theme << obj << endl;
1249 //TQByteArray data;
1250 //TQDataStream dataStream( data, IO_WriteOnly );
1251 //dataStream << theme;
1252 //dataStream << txt;
1253
1254 //kapp->dcopClient()->send( app->dcopClient()->appId(), "KarambaIface", "themeNotify(TQString,TQString)", data );
1255
1256 DCOPClient *c = kapp->dcopClient();
1257 if (!c->isAttached())
1258 c->attach();
1259
1260 if(app->dcopStub())
1261 app->dcopStub()->setIncomingData(theme, obj);
1262}
1263
1264void karamba::callTheme(TQString theme, TQString txt)
1265{
1266 KarambaApplication* app = (KarambaApplication*)tqApp;
1267 kdDebug() << "karamba::callTheme " << theme << txt << endl;
1268 //tqWarning("karamba::callTheme");
1269 //TQByteArray data;
1270 //TQDataStream dataStream( data, IO_WriteOnly );
1271 //dataStream << theme;
1272 //dataStream << txt;
1273
1274 //kapp->dcopClient()->send( app->dcopClient()->appId(), "KarambaIface", "themeNotify(TQString,TQString)", data );
1275
1276 DCOPClient *c = kapp->dcopClient();
1277 if (!c->isAttached())
1278 c->attach();
1279
1280 if(app->dcopStub())
1281 app->dcopStub()->themeNotify(theme, txt);
1282}
1283
1284void karamba::themeNotify(TQString theme, TQString txt)
1285{
1286 kdDebug() << "karamba::themeNotify" << theme << txt << endl;
1287 if (pythonIface->isExtensionLoaded())
1288 {
1289 pythonIface->themeNotify(this, theme.ascii(), txt.ascii());
1290 }
1291}
1292
1293void karamba::meterClicked(TQMouseEvent* e, Meter* meter)
1294{
1295 //tqWarning("karamba::meterClicked");
1296 if (pythonIface && pythonIface->isExtensionLoaded() && haveUpdated)
1297 {
1298 int button = 0;
1299
1300 if( e->button() == TQt::LeftButton )
1301 button = 1;
1302 else if( e->button() == TQt::MidButton )
1303 button = 2;
1304 else if( e->button() == TQt::RightButton )
1305 button = 3;
1306
1307 if (RichTextLabel* richText = dynamic_cast<RichTextLabel*>(meter))
1308 {
1309 pythonIface->meterClicked(this, richText->anchorAt(e->x(), e->y()),
1310 button);
1311 }
1312 else
1313 {
1314 pythonIface->meterClicked(this, meter, button);
1315 }
1316 }
1317}
1318
1319void karamba::changeInterval(int interval)
1320{
1321 if (m_sysTimer != NULL)
1322 m_sysTimer->changeInterval(interval);
1323}
1324
1325void karamba::passClick(TQMouseEvent *e)
1326{
1327 //tqDebug("karamba::passClick");
1328 TQObjectListIt it2( *timeList ); // iterate over meters
1329 while ( it2 != 0 )
1330 {
1331 (( DateSensor* ) *it2)->toggleCalendar( e );
1332 ++it2;
1333 }
1334
1335
1336 // We create a temporary click list here because original
1337 // can change during the loop (infinite loop Bug 994359)
1338 TQObjectList clickListTmp(*clickList);
1339 TQObjectListIt it(clickListTmp);
1340 while (it != 0)
1341 {
1342 Meter* meter = (Meter*)(*it);
1343 // Check if meter is still in list
1344 if (clickList->containsRef(meter) && meter->click(e))
1345 {
1346 // callback
1347 meterClicked(e, meter);
1348 }
1349 ++it;
1350 }
1351
1352 //Everything below is to call the python callback function
1353 if (pythonIface && pythonIface->isExtensionLoaded() && haveUpdated)
1354 {
1355 int button = 0;
1356
1357 if( e->button() == TQt::LeftButton )
1358 button = 1;
1359 else if( e->button() == TQt::MidButton )
1360 button = 2;
1361 else if( e->button() == TQt::RightButton )
1362 button = 3;
1363
1364 pythonIface->widgetClicked(this, e->x(), e->y(), button);
1365 }
1366}
1367
1368void karamba::passWheelClick( TQWheelEvent *e )
1369{
1370 //tqDebug("karamba::passWheelClick");
1371 //Everything below is to call the python callback function
1372 if (pythonIface && pythonIface->isExtensionLoaded() && haveUpdated)
1373 {
1374 int button = 0;
1375
1376 if( e->delta() > 0 )
1377 button = 4;
1378 else
1379 button = 5;
1380
1381 // We create a temporary click list here because original
1382 // can change during the loop (infinite loop Bug 994359)
1383 if (want_meter_wheel_event)
1384 {
1385 TQObjectList clickListTmp(*clickList);
1386 TQObjectListIt it(clickListTmp);
1387
1388 TQMouseEvent fakeEvent(TQEvent::MouseButtonPress, e->pos(), e->globalPos(), button, e->state());
1389
1390 while (it != 0)
1391 {
1392 Meter* meter = (Meter*)(*it);
1393 // Check if meter is still in list
1394 if (clickList->containsRef(meter) && meter->click(&fakeEvent))
1395 {
1396 if (RichTextLabel* richText = dynamic_cast<RichTextLabel*>(meter))
1397 {
1398 pythonIface->meterClicked(this, richText->anchorAt(fakeEvent.x(), fakeEvent.y()),
1399 button);
1400 }
1401 else
1402 {
1403 pythonIface->meterClicked(this, meter, button);
1404 }
1405 }
1406 ++it;
1407 }
1408 }
1409
1410 pythonIface->widgetClicked(this, e->x(), e->y(), button);
1411 }
1412}
1413
1414void karamba::management_popup( void )
1415{
1416 kpop->popup(TQCursor::pos());
1417}
1418
1419void karamba::mousePressEvent( TQMouseEvent *e )
1420{
1421 //tqDebug("karamba::mousePressEvent");
1422 if( e->button() == TQt::RightButton && !want_right_button )
1423 {
1424 management_popup();
1425 }
1426 else
1427 {
1428 clickPos = e->pos();
1429 if( toggleLocked -> isChecked() )
1430 passClick( e );
1431 if( !(onTop || managed))
1432 KWin::lowerWindow( winId() );
1433 }
1434}
1435
1436void karamba::wheelEvent( TQWheelEvent *e )
1437{
1438 //tqDebug("karamba::wheelEvent");
1439 passWheelClick( e );
1440}
1441
1442void karamba::mouseReleaseEvent( TQMouseEvent *e )
1443{
1444 //tqDebug("karamba::mouseReleaseEvent");
1445 clickPos = e->pos();
1446}
1447
1448void karamba::mouseDoubleClickEvent( TQMouseEvent *e )
1449{
1450 //tqDebug("karamba::mouseDoubleClickEvent");
1451 if( !toggleLocked -> isChecked() )
1452 {
1453 passClick( e );
1454 }
1455}
1456
1457void karamba::keyPressEvent(TQKeyEvent *e)
1458{
1459 //tqDebug("karamba::keyPressEvent");
1460 keyPressed(e->text(), 0);
1461}
1462
1463void karamba::keyPressed(const TQString& s, const Meter* meter)
1464{
1465 if (pythonIface && pythonIface->isExtensionLoaded())
1466 pythonIface->keyPressed(this, meter, s);
1467}
1468
1469void karamba::mouseMoveEvent( TQMouseEvent *e )
1470{
1471 //tqDebug("karamba::mouseMoveEvent");
1472 if( e->state() != 0 && e->state() < 16 && !toggleLocked -> isChecked() )
1473 {
1474 move( e->globalPos() - clickPos );
1475 }
1476 else
1477 {
1478 // Change cursor over ClickArea
1479 TQObjectListIt it(*clickList);
1480 bool insideArea = false;
1481
1482 while (it != 0)
1483 {
1484 insideArea = ((Meter*)(*it)) -> insideActiveArea(e -> x(), e ->y());
1485 if (insideArea)
1486 {
1487 break;
1488 }
1489 ++it;
1490 }
1491
1492 if(insideArea)
1493 {
1494 if( cursor().shape() != PointingHandCursor )
1495 setCursor( PointingHandCursor );
1496 }
1497 else
1498 {
1499 if( cursor().shape() != ArrowCursor )
1500 setCursor( ArrowCursor );
1501 }
1502
1503 TQObjectListIt image_it( *imageList); // iterate over image sensors
1504 while ( image_it != 0 )
1505 {
1506 ((ImageLabel*) *image_it)->rolloverImage(e);
1507 ++image_it;
1508 }
1509 }
1510
1511 if (pythonIface && pythonIface->isExtensionLoaded())
1512 {
1513 int button = 0;
1514
1515 //Modified by Ryan Nickell (p0z3r@mail.com) 03/16/2004
1516 // This will work now, but only when you move at least
1517 // one pixel in any direction with your mouse.
1518 //if( e->button() == TQt::LeftButton )
1519 if( e->state() == TQt::LeftButton)
1520 button = 1;
1521 //else if( e->button() == TQt::MidButton )
1522 else if( e->state() == TQt::MidButton )
1523 button = 2;
1524 //else if( e->button() == TQt::RightButton )
1525 else if( e->state() == TQt::RightButton )
1526 button = 3;
1527
1528 pythonIface->widgetMouseMoved(this, e->x(), e->y(), button);
1529 }
1530}
1531
1532void karamba::closeEvent ( TQCloseEvent * qc)
1533{
1534 //tqDebug("karamba::closeEvent");
1535 qc->accept();
1536 // close(true);
1537 // delete this;
1538}
1539
1540void karamba::paintEvent ( TQPaintEvent *e)
1541{
1542 //kdDebug() << k_funcinfo << pm.size() << endl;
1543 if(pm.width() == 0)
1544 return;
1545 if( !(onTop || managed))
1546 {
1547 if( lowerTimer.elapsed() > 100 )
1548 {
1549 KWin::lowerWindow( winId() );
1550 lowerTimer.restart();
1551 }
1552 }
1553 TQRect rect = e->rect();
1554 bitBlt(this,rect.topLeft(),&pm,rect,TQt::CopyROP);
1555}
1556
1557void karamba::updateSensors()
1558{
1559 //tqDebug("karamba::updateSensors");
1560 TQObjectListIt it( *sensorList ); // iterate over meters
1561 while ( it != 0 )
1562 {
1563 ((Sensor*) *it)->update();
1564 ++it;
1565 }
1566 TQTimer::singleShot( 500, this, TQ_SLOT(step()) );
1567}
1568
1569void karamba::updateBackground(TDESharedPixmap* kpm)
1570{
1571 //kdDebug() << k_funcinfo << pm.size() << endl;
1572 // if pm width == 0 this is the first time we come here and we should start
1573 // the theme. This is because we need the background before starting.
1574 //if(pm.width() == 0)
1575 if( !themeStarted )
1576 {
1577 themeStarted = true;
1578 start();
1579 }
1580 background = TQPixmap(*kpm);
1581
1582 TQPixmap buffer = TQPixmap(size());
1583
1584 pm = TQPixmap(size());
1585 buffer.fill(TQt::black);
1586
1587 TQObjectListIt it( *imageList ); // iterate over meters
1588 p.begin(&buffer);
1589 bitBlt(&buffer,0,0,&background,0,TQt::CopyROP);
1590
1591 while ( it != 0 )
1592 {
1593 if (((ImageLabel*) *it)->background == 1)
1594 {
1595 ((ImageLabel*) *it)->mUpdate(&p, 1);
1596 }
1597 ++it;
1598 }
1599 p.end();
1600
1601 bitBlt(&pm,0,0,&buffer,0,TQt::CopyROP);
1602 background = pm;
1603
1604 TQPixmap buffer2 = TQPixmap(size());
1605
1606 pm = TQPixmap(size());
1607 buffer2.fill(TQt::black);
1608
1609 TQObjectListIt it2( *meterList ); // iterate over meters
1610 p.begin(&buffer2);
1611 bitBlt(&buffer2,0,0,&background,0,TQt::CopyROP);
1612
1613 while ( it2 != 0 )
1614 {
1615 ((Meter*) *it2)->mUpdate(&p);
1616 ++it2;
1617 }
1618 p.end();
1619
1620 bitBlt(&pm,0,0,&buffer2,0,TQt::CopyROP);
1621 if (systray != 0)
1622 {
1623 systray->updateBackgroundPixmap(buffer2);
1624 }
1625 repaint();
1626}
1627
1628void karamba::currentDesktopChanged( int i )
1629{
1630 //tqDebug("karamba::currentDesktopChanged");
1631 kroot->repaint( true );
1632 if (pythonIface && pythonIface->isExtensionLoaded())
1633 pythonIface->desktopChanged(this, i);
1634}
1635
1636void karamba::currentWallpaperChanged(int i )
1637{
1638 //tqDebug("karamba::currentWallpaperChanged");
1639 kroot->repaint( true );
1640 if (pythonIface && pythonIface->isExtensionLoaded())
1641 pythonIface->wallpaperChanged(this, i);
1642}
1643
1644void karamba::externalStep()
1645{
1646 //kdDebug() << k_funcinfo << pm.size() << endl;
1647 if (widgetUpdate)
1648 {
1649 TQPixmap buffer = TQPixmap(size());
1650
1651 pm = TQPixmap(size());
1652 buffer.fill(TQt::black);
1653
1654 TQObjectListIt it( *meterList ); // iterate over meters
1655 p.begin(&buffer);
1656 bitBlt(&buffer,0,0,&background,0,TQt::CopyROP);
1657
1658 while ( it != 0 )
1659 {
1660 ((Meter*) *it)->mUpdate(&p);
1661 ++it;
1662 }
1663 p.end();
1664
1665 bitBlt(&pm,0,0,&buffer,0,TQt::CopyROP);
1666 repaint();
1667 }
1668}
1669
1670void karamba::step()
1671{
1672 //kdDebug() << k_funcinfo << pm.size() << endl;
1673 if (widgetUpdate && haveUpdated)
1674 {
1675 pm = TQPixmap(size());
1676 TQPixmap buffer = TQPixmap(size());
1677 buffer.fill(TQt::black);
1678
1679 TQObjectListIt it( *meterList ); // iterate over meters
1680 p.begin(&buffer);
1681
1682 bitBlt(&buffer,0,0,&background,0,TQt::CopyROP);
1683
1684 while (it != 0)
1685 {
1686 ((Meter*) *it)->mUpdate(&p);
1687 ++it;
1688 }
1689 p.end();
1690
1691 bitBlt(&pm,0,0,&buffer,0,TQt::CopyROP);
1692 update();
1693 }
1694
1695 if (pythonIface && pythonIface->isExtensionLoaded())
1696 {
1697 if (!haveUpdated)
1698 pythonIface->initWidget(this);
1699 else
1700 pythonIface->widgetUpdated(this);
1701 }
1702
1703 haveUpdated = true;
1704}
1705
1706void karamba::widgetClosed()
1707{
1708 //tqDebug("karamba::widgetClosed");
1709 if (pythonIface && pythonIface->isExtensionLoaded())
1710 pythonIface->widgetClosed(this);
1711}
1712
1713void karamba::slotToggleLocked()
1714{
1715 //tqDebug("karamba::slotToggleLocked");
1716 if(toggleLocked->isChecked())
1717 {
1718 toggleLocked->setIconSet(SmallIconSet("system-lock-screen"));
1719 }
1720 else
1721 {
1722 toggleLocked->setIconSet(SmallIconSet("move"));
1723 }
1724}
1725
1726void karamba::slotToggleFastTransforms()
1727{
1728 //tqDebug("karamba::slotToggleFastTransforms");
1729 // bool fastTransforms = toggleFastTransforms -> isChecked();
1730 // if (toggleFastTransforms -> isChecked())
1731 // {
1732 // toggleFastTransforms -> setIconSet(SmallIconSet("ok"));
1733 // }
1734 // else
1735 // {
1736 // TQPixmap ok_disabled;
1737 // toggleFastTransforms -> setIconSet(ok_disabled);
1738 // }
1739 //config.setGroup("internal");
1740 //config.writeEntry("fastTransforms", toggleFastTransforms -> isChecked());
1741}
1742
1743
1744bool karamba::useSmoothTransforms()
1745{
1746 //tqDebug("karamba::useSmoothTransforms");
1747 return !toggleFastTransforms -> isChecked();
1748}
1749
1750void karamba::writeConfigData()
1751{
1752 //tqDebug("karamba::writeConfigData");
1753 config -> setGroup("internal");
1754 config -> writeEntry("lockedPosition", toggleLocked -> isChecked() );
1755 config -> writeEntry("fastTransforms", toggleFastTransforms -> isChecked() );
1756 config -> writeEntry("desktop", desktop );
1757 config -> setGroup("theme");
1758 // Widget Position
1759 config -> writeEntry("widgetPosX", x());
1760 config -> writeEntry("widgetPosY", y());
1761 // Widget Size
1762 config -> writeEntry("widgetWidth", width());
1763 config -> writeEntry("widgetHeight", height());
1764
1765 // write changes to DiskSensor
1766 config -> sync();
1767 //tqWarning("Config File ~/.superkaramba/%s.rc written.",
1768 // m_theme.name().ascii());
1769}
1770
1771void karamba::slotToggleConfigOption(TQString key, bool value)
1772{
1773 //tqDebug("karamba::slotToggleConfigOption");
1774 config -> setGroup("config menu");
1775 config -> writeEntry(key, value);
1776 passMenuOptionChanged(key, value);
1777}
1778
1779void karamba::addMenuConfigOption(TQString key, TQString name)
1780{
1781 //tqDebug("karamba::addMenuConfigOption");
1782 kpop -> setItemEnabled(THEMECONF, true);
1783
1784 SignalBridge* action = new SignalBridge(this, key, menuAccColl);
1785 TDEToggleAction* confItem = new TDEToggleAction (name, TDEShortcut::null(),
1786 action, TQ_SLOT(receive()),
1787 menuAccColl, key.ascii());
1788 confItem -> setName(key.ascii());
1789
1790 menuAccColl -> insert(confItem);
1791
1792 connect(action, TQ_SIGNAL( enabled(TQString, bool) ),
1793 this, TQ_SLOT( slotToggleConfigOption(TQString, bool) ));
1794
1795 config -> setGroup("config menu");
1796 confItem -> setChecked(config -> readBoolEntry(key));
1797
1798 confItem -> plug(themeConfMenu);
1799
1800 numberOfConfMenuItems++;
1801}
1802
1803bool karamba::setMenuConfigOption(TQString key, bool value)
1804{
1805 //tqDebug("karamba::setMenuConfigOption");
1806 TDEToggleAction* menuAction = ((TDEToggleAction*)menuAccColl -> action(key.ascii()));
1807 if (menuAction == NULL)
1808 {
1809 tqWarning("Menu action %s not found.", key.ascii());
1810 return false;
1811 }
1812 else
1813 {
1814 menuAction -> setChecked(value);
1815 return true;
1816 }
1817}
1818
1819bool karamba::readMenuConfigOption(TQString key)
1820{
1821 //tqDebug("karamba::readMenuConfigOption");
1822 TDEToggleAction* menuAction = ((TDEToggleAction*)menuAccColl -> action(key.ascii()));
1823 if (menuAction == NULL)
1824 {
1825 tqWarning("Menu action %s not found.", key.ascii());
1826 return false;
1827 }
1828 else
1829 {
1830 return menuAction -> isChecked();
1831 }
1832}
1833
1834void karamba::passMenuItemClicked(int id)
1835{
1836 //tqDebug("karamba::passMenuItemClicked");
1837 //Everything below is to call the python callback function
1838 if (pythonIface && pythonIface->isExtensionLoaded())
1839 {
1840 TDEPopupMenu* menu = 0;
1841 for(int i = 0; i < (int)menuList->count(); i++)
1842 {
1843 TDEPopupMenu* tmp;
1844 if(i==0)
1845 {
1846 tmp = (TDEPopupMenu*) menuList->first();
1847 }
1848 else
1849 {
1850 tmp = (TDEPopupMenu*) menuList->next();
1851 }
1852 if(tmp != 0)
1853 {
1854 if(tmp->isItemVisible(id))
1855 {
1856 menu = tmp;
1857 break;
1858 }
1859 }
1860 }
1861 pythonIface->menuItemClicked(this, menu, id);
1862 }
1863}
1864
1865void karamba::activeTaskChanged(Task* t)
1866{
1867 //tqDebug("karamba::activeTaskChanged");
1868 //Everything below is to call the python callback function
1869 if (pythonIface && pythonIface->isExtensionLoaded())
1870 pythonIface->activeTaskChanged(this, t);
1871}
1872
1873void karamba::taskAdded(Task* t)
1874{
1875 //tqDebug("karamba::taskAdded");
1876 //Everything below is to call the python callback function
1877 if (pythonIface && pythonIface->isExtensionLoaded())
1878 pythonIface->taskAdded(this, t);
1879}
1880
1881void karamba::taskRemoved(Task* t)
1882{
1883 //tqDebug("karamba::taskRemoved");
1884 //Everything below is to call the python callback function
1885 if (pythonIface && pythonIface->isExtensionLoaded())
1886 pythonIface->taskRemoved(this, t);
1887}
1888
1889void karamba::startupAdded(Startup* t)
1890{
1891 //tqDebug("karamba::startupAdded");
1892 //Everything below is to call the python callback function
1893 if (pythonIface && pythonIface->isExtensionLoaded())
1894 pythonIface->startupAdded(this, t);
1895}
1896
1897void karamba::startupRemoved(Startup* t)
1898{
1899 //tqDebug("karamba::startupRemoved");
1900 //Everything below is to call the python callback function
1901 if (pythonIface && pythonIface->isExtensionLoaded())
1902 pythonIface->startupRemoved(this, t);
1903}
1904
1905void karamba::processExited (TDEProcess* proc)
1906{
1907 //tqDebug("karamba::processExited");
1908 if (pythonIface && pythonIface->isExtensionLoaded())
1909 pythonIface->commandFinished(this, (int)proc->pid());
1910}
1911
1912void karamba::receivedStdout (TDEProcess *proc, char *buffer, int)
1913{
1914 //tqDebug("karamba::receivedStdout");
1915 //Everything below is to call the python callback function
1916 if (pythonIface && pythonIface->isExtensionLoaded())
1917 pythonIface->commandOutput(this, (int)proc->pid(), buffer);
1918}
1919
1920//For KDE session management
1921void karamba::saveProperties(TDEConfig* config)
1922{
1923 //tqDebug("karamba::saveProperties");
1924 config->setGroup("session");
1925 config->writeEntry("theme", m_theme.file());
1926 writeConfigData();
1927}
1928
1929//For KDE session management
1930void karamba::readProperties(TDEConfig* config)
1931{
1932 //tqDebug("karamba::readProperties");
1933 config->setGroup("session");
1934 TQString atheme = config->readEntry("theme");
1935}
1936
1937//Register types of events that can be dragged on our widget
1938void karamba::dragEnterEvent(TQDragEnterEvent* event)
1939{
1940 //tqDebug("karamba::dragEnterEvent");
1941 event->accept(TQTextDrag::canDecode(event));
1942}
1943
1944//Handle the drop part of a drag and drop event.
1945void karamba::dropEvent(TQDropEvent* event)
1946{
1947 //tqDebug("karamba::dropEvent");
1948 TQString text;
1949
1950 if ( TQTextDrag::decode(event, text) )
1951 {
1952 //Everything below is to call the python callback function
1953 if (pythonIface && pythonIface->isExtensionLoaded())
1954 {
1955 const TQPoint &p = event->pos();
1956 pythonIface->itemDropped(this, text, p.x(), p.y());
1957 }
1958 }
1959}
1960
1961void karamba::toDesktop(int id, int menuid)
1962{
1963 //tqDebug("karamba::toDesktop");
1964 int i;
1965
1966 desktop = id;
1967 for (i=0; ; i++)
1968 {
1969 int mid = toDesktopMenu->idAt(i);
1970 if (mid == -1)
1971 break;
1972
1973 toDesktopMenu->setItemChecked(mid, false);
1974 }
1975 toDesktopMenu->setItemChecked(menuid, true);
1976
1977 if (desktop)
1978 info->setDesktop( desktop);
1979 else
1980 info->setDesktop( NETWinInfo::OnAllDesktops );
1981}
1982
1983void karamba::systrayUpdated()
1984{
1985 //tqDebug("karamba::systrayUpdated");
1986 if (pythonIface && pythonIface->isExtensionLoaded())
1987 pythonIface->systrayUpdated(this);
1988}
1989
1990void karamba::toggleWidgetUpdate( bool b)
1991{
1992 //tqDebug("karamba::toggleWidgetUpdate");
1993 if (pythonIface && pythonIface->isExtensionLoaded())
1994 widgetUpdate = b;
1995}
1996
1997SignalBridge::SignalBridge(TQObject* parent, TQString name, TDEActionCollection* ac)
1998 : TQObject(parent, name.ascii()), collection(ac)
1999{
2000 setName(name.ascii());
2001}
2002
2003void SignalBridge::receive()
2004{
2005 emit enabled(name(), ((TDEToggleAction*)collection -> action(name())) ->
2006isChecked());
2007}
2008
2009DesktopChangeSlot::DesktopChangeSlot(TQObject *parent, int id)
2010 : TQObject(parent, "")
2011{
2012 desktopid = id;
2013}
2014
2015void DesktopChangeSlot::receive()
2016{
2017 karamba *k = (karamba *)parent();
2018
2019 // XXX - check type cast
2020
2021 k->toDesktop(desktopid, menuid);
2022}
2023
2024void DesktopChangeSlot::setMenuId(int id)
2025{
2026 menuid = id;
2027}
2028
2029int DesktopChangeSlot::menuId()
2030{
2031 return menuid;
2032}
2033
2034void karamba::showMenuExtension()
2035{
2036 kglobal = new TDEPopupMenu(this);
2037
2038 trayMenuToggleId = kglobal->insertItem(SmallIconSet("superkaramba"),
2039 i18n("Show System Tray Icon"), this,
2040 TQ_SLOT(slotToggleSystemTray()),
2041 CTRL+Key_S);
2042
2043 trayMenuThemeId = kglobal->insertItem(SmallIconSet("knewstuff"),
2044 i18n("&Manage Themes..."), this,
2045 TQ_SLOT(slotShowTheme()), CTRL+Key_M);
2046
2047 trayMenuQuitId = kglobal->insertItem(SmallIconSet("system-log-out"),
2048 i18n("&Quit SuperKaramba"), this,
2049 TQ_SLOT(slotQuit()), CTRL+Key_Q);
2050
2051 kglobal->polish();
2052
2053 trayMenuSeperatorId = kpop->insertSeparator();
2054 kpop->insertItem("SuperKaramba", kglobal);
2055}
2056
2057void karamba::hideMenuExtension()
2058{
2059 if(kglobal)
2060 {
2061 kpop->removeItem(trayMenuSeperatorId);
2062 kglobal->removeItem(trayMenuToggleId);
2063 kglobal->removeItem(trayMenuThemeId);
2064 kglobal->removeItem(trayMenuQuitId);
2065
2066 delete kglobal;
2067 kglobal = 0;
2068 }
2069}
2070
2071void karamba::slotToggleSystemTray()
2072{
2073 karambaApp->globalHideSysTray(false);
2074}
2075
2076void karamba::slotQuit()
2077{
2078 karambaApp->globalQuitSuperKaramba();
2079}
2080
2081void karamba::slotShowTheme()
2082{
2083 karambaApp->globalShowThemeDialog();
2084}
2085
2086void karamba::setAlwaysOnTop(bool stay)
2087{
2088 if(stay)
2089 {
2090 onTop = true;
2091 KWin::setState( winId(), NET::KeepAbove );
2092 }
2093 else
2094 {
2095 onTop = false;
2096 KWin::setState( winId(), NET::KeepBelow );
2097 }
2098}
2099
2100#include "karamba.moc"
ClickArea
Hans Karlsson.
Definition clickarea.h:41
ClickMap
Ralph M.
Definition clickmap.h:24
KarambaRootPixmap
Definition karambarootpixmap.h:23
LineParser
Definition lineparser.h:34
NoatunSensor
Definition noatunsensor.h:24
RssSensor
Ralph M.
Definition rsssensor.h:23
SensorParams
Hans Karlsson.
Definition sensorparams.h:32
SensorSensor
Hans Karlsson.
Definition sensorsensor.h:21
SignalBridge
SignalBridge is an ungulate that lives in the forests of wild Wisconsin.
Definition karamba.h:350
Startup
Represents a task which is in the process of starting.
Definition taskmanager.h:364
Task
A dynamic interface to a task (main window).
Definition taskmanager.h:50
TextField
Ralph M.
Definition textfield.h:22
TextFileSensor
Hans Karlsson.
Definition textfilesensor.h:37

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.9.8
This website is maintained by Timothy Pearson.