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