karamba.h
00001 /* 00002 * Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se> 00003 * Copyright (C) 2004,2005 Luke Kenneth Casson Leighton <lkcl@lkcl.net> 00004 * Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org> 00005 * Copyright (c) 2005 Ryan Nickell <p0z3r@earthlink.net> 00006 * 00007 * This file is part of SuperKaramba. 00008 * 00009 * SuperKaramba is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * SuperKaramba is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with SuperKaramba; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 ****************************************************************************/ 00023 00024 #ifndef _KARAMBA_H_ 00025 #define _KARAMBA_H_ 00026 00027 #ifdef HAVE_CONFIG_H 00028 #include <config.h> 00029 #endif 00030 00031 #include <tqwidget.h> 00032 #include <kapplication.h> 00033 00034 #include <kwinmodule.h> 00035 #include <kwin.h> 00036 00037 #include <tqfile.h> 00038 #include <kfile.h> 00039 #include <tqfileinfo.h> 00040 #include <kaction.h> 00041 #include <tqtimer.h> 00042 #include <tqpixmap.h> 00043 #include <tqpainter.h> 00044 00045 //#include <krootpixmap.h> 00046 00047 #include <tqregexp.h> 00048 #include <tqlabel.h> 00049 #include <tqobjectlist.h> 00050 #include <tqstring.h> 00051 #include <tqstringlist.h> 00052 #include <ksharedpixmap.h> 00053 #include <tqvaluestack.h> 00054 #include <dcopclient.h> 00055 #include <kpopupmenu.h> 00056 #include <tqcursor.h> 00057 #include <netwm.h> 00058 #include <kiconloader.h> 00059 #include <kfiledialog.h> 00060 #include <tqmap.h> 00061 #include <kurl.h> 00062 #include <krun.h> 00063 #include <tqdatetime.h> 00064 #include <tqbitmap.h> 00065 #include <kconfig.h> 00066 #include <kprocess.h> 00067 #include <tqdragobject.h> 00068 00069 #include "karambarootpixmap.h" 00070 00071 #include "bar.h" 00072 #include "textlabel.h" 00073 #include "imagelabel.h" 00074 #include "graph.h" 00075 #include "input.h" 00076 00077 #include "clickarea.h" 00078 00079 #include "sensorparams.h" 00080 #include "memsensor.h" 00081 #include "datesensor.h" 00082 #include "uptimesensor.h" 00083 #include "memsensor.h" 00084 #include "cpusensor.h" 00085 #include "networksensor.h" 00086 #include "xmmssensor.h" 00087 #include "noatunsensor.h" 00088 #include "programsensor.h" 00089 #include "disksensor.h" 00090 #include "sensorsensor.h" 00091 #include "textfilesensor.h" 00092 00093 #include "clickmap.h" 00094 #include "rsssensor.h" 00095 //#include "clickable.h" 00096 #include "taskmanager.h" 00097 #include "showdesktop.h" 00098 #include "systemtray.h" 00099 #include "themefile.h" 00100 00109 class KarambaPython; 00110 class LineParser; 00111 00112 class karamba : public TQWidget 00113 { 00114 Q_OBJECT 00115 TQ_OBJECT 00116 00117 public: 00118 karamba(TQString fn, TQString name, bool reloading = false, 00119 int instance = -1, bool sub_theme = false); 00120 TQObjectList *menuList; 00121 00122 virtual ~karamba(); 00123 const ThemeFile& theme() const { return m_theme; }; 00124 00125 TQObjectList *meterList; 00126 TQObjectList *imageList; 00127 TQObjectList *clickList; 00128 void setSensor(const LineParser& lineParser, Meter* meter); 00129 TQString getSensor(Meter* meter); 00130 TQString findSensorFromMap(Sensor* sensor); 00131 void deleteMeterFromSensors(Meter* meter); 00132 Sensor* findSensorFromList(Meter* meter); 00133 KPopupMenu* keditpop; 00134 KPopupMenu *kpop; 00135 TQBitmap* widgetMask; 00136 KarambaRootPixmap *kroot; 00137 TaskManager taskManager; 00138 Systemtray* systray; 00139 KProcess* currProcess; 00140 bool useSmoothTransforms(); 00141 00142 void changeInterval(int interval); 00143 void setWidgetUpdate(bool wu) { widgetUpdate = wu; }; 00144 bool getWidgetUpdate() { return widgetUpdate; }; 00145 bool hasMeter(Meter* meter) { return meterList->containsRef(meter) > 0; }; 00146 char getTempUnit() { return tempUnit; }; 00147 void addMenuConfigOption(TQString key, TQString name); 00148 bool setMenuConfigOption(TQString key, bool value); 00149 bool readMenuConfigOption(TQString key); 00150 void writeConfigData(); 00151 TextField* getDefaultTextProps() { return defaultTextField; }; 00152 int instance() const { return m_instance; }; 00153 void setInstance(int instance) { m_instance = instance; }; 00154 void closeTheme(bool reloading = false); 00155 void keyPressed(const TQString& s, const Meter* meter); 00156 00157 int numberOfConfMenuItems; 00158 KConfig* config; 00159 TQString prettyName; 00160 bool m_sub_theme; 00161 bool isSubTheme() { return m_sub_theme; } 00162 00163 void toggleWidgetUpdate( bool ); 00164 00165 KWinModule* kWinModule; 00166 00167 TQString incomingData; 00168 TQString getIncomingData() { return incomingData; } 00169 void _setIncomingData(TQString data) { incomingData = data; } 00170 void setIncomingData(TQString theme, TQString data); 00171 00172 void themeNotify(TQString theme, TQString txt); 00173 void callTheme(TQString theme, TQString txt); 00174 00175 double getUpdateTime() { return update_time; } 00176 void setUpdateTime(double time) { update_time = time; } 00177 00178 void makeActive(); 00179 void makePassive(); 00180 00181 void showMenuExtension(); 00182 void hideMenuExtension(); 00183 00184 protected: 00185 void mousePressEvent( TQMouseEvent *); 00186 void wheelEvent( TQWheelEvent *); 00187 void mouseReleaseEvent( TQMouseEvent *); 00188 void mouseDoubleClickEvent( TQMouseEvent *); 00189 void mouseMoveEvent( TQMouseEvent *); 00190 void keyPressEvent ( TQKeyEvent * e ); 00191 void closeEvent ( TQCloseEvent *); 00192 void paintEvent ( TQPaintEvent *); 00193 void saveProperties(KConfig *); 00194 void readProperties(KConfig *); 00195 void dragEnterEvent(TQDragEnterEvent* event); 00196 void dropEvent(TQDropEvent* event); 00197 00198 private: 00199 bool widgetUpdate; 00200 bool repaintInProgress; 00201 //bool reloading; 00202 bool want_right_button; 00203 bool want_meter_wheel_event; 00204 00205 NETWinInfo* info; 00206 bool onTop; 00207 bool managed; 00208 bool fixedPosition; 00209 bool haveUpdated; 00210 char tempUnit; 00211 double update_time; 00212 int m_instance; 00213 00214 bool parseConfig(); 00215 00216 void passClick( TQMouseEvent* ); 00217 void passWheelClick( TQWheelEvent* ); 00218 void meterClicked(TQMouseEvent*, Meter*); 00219 00220 TQMap<TQString, Sensor*> sensorMap; 00221 TQObjectList *sensorList; 00222 TQObjectList *timeList; 00223 00224 TQTime lowerTimer; 00225 // use only the first occurance of KARAMBA in a config file 00226 bool foundKaramba; 00227 00228 KPopupMenu* themeConfMenu; 00229 KPopupMenu* toDesktopMenu; 00230 KPopupMenu* kglobal; 00231 00232 DCOPClient *client; 00233 TQCString appId; 00234 00235 TQPixmap pm; 00236 TQPixmap background; 00237 TQPainter p; 00238 00239 TQPoint clickPos; 00240 KActionCollection* accColl; 00241 KActionCollection* menuAccColl; 00242 KToggleAction *toggleLocked; 00243 // use highquality scale and rotate algorithms 00244 KToggleAction *toggleFastTransforms; 00245 00246 // Python module references 00247 KarambaPython* pythonIface; 00248 TextField *defaultTextField; 00249 00250 int desktop; 00251 ThemeFile m_theme; 00252 00253 int trayMenuSeperatorId; 00254 int trayMenuQuitId; 00255 int trayMenuToggleId; 00256 int trayMenuThemeId; 00257 void start(); 00258 00259 public slots: 00260 void step(); 00261 void externalStep(); 00262 void widgetClosed(); 00263 void updateSensors(); 00264 void currentDesktopChanged(int); 00265 void currentWallpaperChanged(int); 00266 void slotToggleConfigOption(TQString key, bool); 00267 void updateBackground(KSharedPixmap*); 00268 void passMenuOptionChanged(TQString key, bool); 00269 void passMenuItemClicked(int); 00270 void processExited (KProcess *proc); 00271 void receivedStdout (KProcess *proc, char *buffer, int buflen); 00272 void toDesktop(int desktopid, int menuid); 00273 const char *getPrettyName() { return prettyName.ascii(); } 00274 00275 // Systray 00276 void systrayUpdated(); 00277 00278 // Task Manager 00279 void startupAdded(Startup*); 00280 void startupRemoved(Startup*); 00281 00282 void taskAdded(Task*); 00283 void taskRemoved(Task*); 00284 void activeTaskChanged(Task*); 00285 void reloadConfig(); 00286 00287 void setAlwaysOnTop(bool stay); 00288 00293 void setWantRightButton(bool yesno) { want_right_button = yesno; } 00294 00295 void setWantMeterWheelEvent(bool yesno) { want_meter_wheel_event = yesno; } 00296 00300 void management_popup( void ); 00301 00302 private: 00303 bool m_reloading; 00304 bool themeStarted; 00305 TQTimer *m_sysTimer; 00306 int m_interval; 00307 00308 private slots: 00309 void initPythonInterface(); 00310 void killWidget(); 00311 void editConfig(); 00312 void editScript(); 00313 void slotToggleLocked(); 00314 void slotToggleFastTransforms(); 00315 void popupNotify(int); 00316 void slotFileChanged( const TQString & ); 00317 00318 void slotToggleSystemTray(); 00319 void slotQuit(); 00320 void slotShowTheme(); 00321 }; 00322 00323 /* 00324 * Slot to receive the event of moving the karamba object 00325 * to a new desktop. Generated by karamba::toDesktopMenu items 00326 */ 00327 class DesktopChangeSlot : public TQObject 00328 { 00329 Q_OBJECT 00330 TQ_OBJECT 00331 00332 public: 00333 DesktopChangeSlot(TQObject *parent, int desktop_id); 00334 /* Parent should be the karamba object 00335 * desktop id of 0 indicates all desktops */ 00336 void setMenuId(int id); 00337 int menuId(); 00338 00339 public slots: 00340 void receive(); 00341 00342 protected: 00343 int desktopid; 00344 int menuid; 00345 }; 00346 00348 class SignalBridge : public TQObject 00349 { 00350 Q_OBJECT 00351 TQ_OBJECT 00352 00353 public: 00354 SignalBridge(TQObject* parent, TQString, KActionCollection*); 00355 00356 signals: 00357 void enabled(TQString, bool); 00358 00359 public slots: 00360 void receive(); 00361 00362 private: 00363 KActionCollection* collection; 00364 }; 00365 00366 #endif // _KARAMBA_H_