From 933e53832eeb45c6f660dcf46bed5dc68aaf24c2 Mon Sep 17 00:00:00 2001 From: Darrell Anderson Date: Sun, 14 Jul 2013 19:31:37 -0500 Subject: Update references from kpowersave to tdepowersave. --- src/CMakeLists.txt | 18 +- src/Makefile.am | 28 +- src/config/kpowersaverc_default | 151 -- src/config/tdepowersaverc_default | 151 ++ src/configure.in.in | 2 +- src/configure_Dialog.ui | 4 +- src/configuredialog.cpp | 12 +- src/configuredialog.h | 4 +- src/countdowndialog.cpp | 6 +- src/dbusInterface.cpp | 4 +- src/dbusInterface.h | 10 +- src/detailed_Dialog.ui | 2 +- src/detaileddialog.cpp | 4 +- src/detaileddialog.h | 2 +- src/dummy.cpp | 2 +- src/eventsrc | 28 +- src/hardware.cpp | 4 +- src/hardware.h | 4 +- src/hardware_battery.cpp | 10 +- src/hardware_cpu.h | 2 +- src/hi16-app-kpowersave.png | Bin 922 -> 0 bytes src/hi16-app-tdepowersave.png | Bin 0 -> 922 bytes src/hi32-app-kpowersave.png | Bin 2300 -> 0 bytes src/hi32-app-tdepowersave.png | Bin 0 -> 2300 bytes src/hi48-app-kpowersave.png | Bin 3975 -> 0 bytes src/hi48-app-tdepowersave.png | Bin 0 -> 3975 bytes src/inactivity.h | 2 +- src/infodialog.cpp | 4 +- src/infodialog.h | 2 +- src/kpowersave-autostart.desktop | 68 - src/kpowersave.cpp | 2678 ------------------------------------ src/kpowersave.desktop | 68 - src/kpowersave.h | 465 ------- src/kpowersave.lsm | 14 - src/kpowersave_debug.h | 68 - src/logviewer.cpp | 2 +- src/logviewer.h | 2 +- src/main.cpp | 16 +- src/pics/CMakeLists.txt | 2 +- src/pics/Makefile.am | 4 +- src/screen.cpp | 2 +- src/settings.cpp | 6 +- src/settings.h | 70 +- src/suspenddialog.cpp | 4 +- src/tdepowersave-autostart.desktop | 68 + src/tdepowersave.cpp | 2678 ++++++++++++++++++++++++++++++++++++ src/tdepowersave.desktop | 68 + src/tdepowersave.h | 465 +++++++ src/tdepowersave.lsm | 14 + src/tdepowersave_debug.h | 68 + 50 files changed, 3643 insertions(+), 3643 deletions(-) delete mode 100644 src/config/kpowersaverc_default create mode 100644 src/config/tdepowersaverc_default delete mode 100644 src/hi16-app-kpowersave.png create mode 100644 src/hi16-app-tdepowersave.png delete mode 100644 src/hi32-app-kpowersave.png create mode 100644 src/hi32-app-tdepowersave.png delete mode 100644 src/hi48-app-kpowersave.png create mode 100644 src/hi48-app-tdepowersave.png delete mode 100644 src/kpowersave-autostart.desktop delete mode 100644 src/kpowersave.cpp delete mode 100644 src/kpowersave.desktop delete mode 100644 src/kpowersave.h delete mode 100644 src/kpowersave.lsm delete mode 100644 src/kpowersave_debug.h create mode 100644 src/tdepowersave-autostart.desktop create mode 100644 src/tdepowersave.cpp create mode 100644 src/tdepowersave.desktop create mode 100644 src/tdepowersave.h create mode 100644 src/tdepowersave.lsm create mode 100644 src/tdepowersave_debug.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 437deba..de98870 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,16 +27,16 @@ link_directories( ##### other data ################################ -tde_install_icons( kpowersave ) -install( FILES kpowersave.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} ) -install( FILES kpowersave-autostart.desktop DESTINATION ${AUTOSTART_INSTALL_DIR} ) -install( FILES eventsrc DESTINATION ${DATA_INSTALL_DIR}/kpowersave ) -install( FILES config/kpowersaverc_default RENAME kpowersaverc DESTINATION ${CONFIG_INSTALL_DIR} ) +tde_install_icons( tdepowersave ) +install( FILES tdepowersave.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} ) +install( FILES tdepowersave-autostart.desktop DESTINATION ${AUTOSTART_INSTALL_DIR} ) +install( FILES eventsrc DESTINATION ${DATA_INSTALL_DIR}/tdepowersave ) +install( FILES config/tdepowersaverc_default RENAME tdepowersaverc DESTINATION ${CONFIG_INSTALL_DIR} ) -##### kpowersave (tdeinit) ###################### +##### tdepowersave (tdeinit) ###################### -tde_add_tdeinit_executable( kpowersave AUTOMOC +tde_add_tdeinit_executable( tdepowersave AUTOMOC SOURCES dummy.cpp autodimm.cpp autosuspend.cpp blacklistedit_Dialog.ui blacklisteditdialog.cpp @@ -44,8 +44,8 @@ tde_add_tdeinit_executable( kpowersave AUTOMOC countdowndialog.cpp dbusInterface.cpp detailed_Dialog.ui detaileddialog.cpp hardware.cpp hardware_battery.cpp hardware_batteryCollection.cpp hardware_cpu.cpp - inactivity.cpp info_Dialog.ui infodialog.cpp kpowersave.cpp - kpowersave.skel log_viewer.ui logviewer.cpp main.cpp + inactivity.cpp info_Dialog.ui infodialog.cpp tdepowersave.cpp + tdepowersave.skel log_viewer.ui logviewer.cpp main.cpp screen.cpp settings.cpp suspenddialog.cpp suspend_Dialog.ui LINK ${DBUS_TQT_LIBRARIES} tdeio-shared ${HAL_LIBRARIES} diff --git a/src/Makefile.am b/src/Makefile.am index 4558d05..dbb26e3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,7 +19,7 @@ noinst_HEADERS = \ hardware_cpu.h \ inactivity.h \ infodialog.h \ - kpowersave.h \ + tdepowersave.h \ logviewer.h \ privileges.h \ screen.h \ @@ -30,7 +30,7 @@ noinst_HEADERS = \ # let automoc handle all of the meta source files (moc) METASOURCES = AUTO -KDE_ICON = kpowersave +KDE_ICON = tdepowersave ######################################################################### # APPLICATION SECTION @@ -40,10 +40,10 @@ KDE_ICON = kpowersave bin_PROGRAMS = lib_LTLIBRARIES = -tdeinit_LTLIBRARIES = kpowersave.la +tdeinit_LTLIBRARIES = tdepowersave.la # the application source, library search path, and link libraries -kpowersave_la_SOURCES = \ +tdepowersave_la_SOURCES = \ dummy.cpp \ autodimm.cpp \ autosuspend.cpp \ @@ -63,8 +63,8 @@ kpowersave_la_SOURCES = \ inactivity.cpp \ info_Dialog.ui \ infodialog.cpp \ - kpowersave.cpp \ - kpowersave.skel \ + tdepowersave.cpp \ + tdepowersave.skel \ log_viewer.ui \ logviewer.cpp \ main.cpp \ @@ -74,30 +74,30 @@ kpowersave_la_SOURCES = \ suspend_Dialog.ui -kpowersave_la_LDFLAGS = $(KDE_RPATH) $(all_libraries) -module -avoid-version -kpowersave_la_LIBADD = $(LIB_KIO) @PACKAGE_LIBS@ -ldbus-tqt-1 -lXss -lXext -lXtst +tdepowersave_la_LDFLAGS = $(KDE_RPATH) $(all_libraries) -module -avoid-version +tdepowersave_la_LIBADD = $(LIB_KIO) @PACKAGE_LIBS@ -ldbus-tqt-1 -lXss -lXext -lXtst # this is where the desktop file will go -xdg_apps_DATA = kpowersave.desktop +xdg_apps_DATA = tdepowersave.desktop # and for autostart autostartdir = $(prefix)/share/autostart -autostart_DATA = kpowersave-autostart.desktop +autostart_DATA = tdepowersave-autostart.desktop # this is where the shell's XML-GUI resource file goes -shellrcdir = $(kde_datadir)/kpowersave +shellrcdir = $(kde_datadir)/tdepowersave shellrc_DATA = eventsrc -# shellrc_DATA = kpowersaveui.rc +# shellrc_DATA = tdepowersaveui.rc # pics subdir SUBDIRS = pics messages: $(EXTRACTRC) *ui eventsrc >> rc.cpp - $(XGETTEXT) `find . -name \*.h -o -name \*.H -o -name \*.cpp -o -name \*.C` -o $(podir)/kpowersave.pot + $(XGETTEXT) `find . -name \*.h -o -name \*.H -o -name \*.cpp -o -name \*.C` -o $(podir)/tdepowersave.pot rm -f rc.cpp install-data-local: $(mkinstalldirs) $(DESTDIR)$(kde_confdir) - $(INSTALL_DATA) $(top_srcdir)/src/config/kpowersaverc_default $(DESTDIR)$(kde_confdir)/kpowersaverc + $(INSTALL_DATA) $(top_srcdir)/src/config/tdepowersaverc_default $(DESTDIR)$(kde_confdir)/tdepowersaverc diff --git a/src/config/kpowersaverc_default b/src/config/kpowersaverc_default deleted file mode 100644 index 61e6e05..0000000 --- a/src/config/kpowersaverc_default +++ /dev/null @@ -1,151 +0,0 @@ -[General] -lockOnSuspend=true -lockOnLidClose=true -ActionOnLidClose= -ActionOnLidCloseValue= -ActionOnPowerButton=SHUTDOWN -ActionOnPowerButtonValue= -ActionOnSleepButton=SUSPEND2RAM -ActionOnS2DiskButton=SUSPEND2DISK -buttonsAllowedActions=SHUTDOWN,LOGOUT_DIALOG,SUSPEND2DISK,SUSPEND2RAM -AutoSuspendCountdown=true -AutoSuspendCountdownTimeOut=30 -Autostart=true -AutostartNeverAsk=false -unmountExternalOnSuspend=false -callSetPowerSaveOnAC=true -lockMethod=automatic -timeToFakeKeyAfterLock=2500 -forceDpmsOffOnLidClose=true -psMsgAsPassivePopup=false -autoInactiveBlacklist=mplayer,gmplayer,kaffeine,xine,mencoder,cdrecord,cdrecord-dvd,cdrdao,growisofs,kdetv,xawtv,realplay.bin,wodim -autoDimmBlacklist=mplayer,gmplayer,kaffeine,xine,kdetv,xawtv,realplay.bin -schemes=Performance,Powersave,Presentation,Acoustic -ac_scheme=Performance -battery_scheme=Powersave -batteryWarning=12 -batteryWarningAction= -batteryWarningActionValue= -batteryLow=7 -batteryLowAction=BRIGHTNESS -batteryLowActionValue=1 -batteryCritical=2 -batteryCriticalAction=SHUTDOWN -batteryCriticalActionValue= -batteryAllowedActions=SHUTDOWN,SUSPEND2DISK,SUSPEND2RAM,CPUFREQ_POWERSAVE,CPUFREQ_PERFORMANCE,CPUFREQ_DYNAMIC,BRIGHTNESS - -[default-scheme] -specSsSettings=false -disableSs=false -blankSs=false -specPMSettings=false -standbyAfter=5 -suspendAfter=10 -powerOffAfter=15 -disableDPMS=false -autoSuspend=false -autoInactiveAction=_NONE_ -autoInactiveActionAfter=0 -autoInactiveSchemeBlacklistEnabled=false -autoInactiveSchemeBlacklist= -autoDimm=false -autoDimmAfter=0 -autoDimmTo=50 -autoDimmSchemeBlacklistEnabled=false -autoDimmSchemeBlacklist= -enableBrightness=true -brightnessPercent=100 -cpuFreqPolicy=DYNAMIC -cpuFreqPolicyPerformance=51 - -[Performance] -specSsSettings=false -specPMSettings=true -standbyAfter=10 -suspendAfter=20 -powerOffAfter=30 -disableDPMS=false -autoSuspend=false -autoInactiveAction=_NONE_ -autoInactiveActionAfter=0 -autoInactiveSchemeBlacklistEnabled=false -autoInactiveSchemeBlacklist= -autoDimm=false -autoDimmAfter=0 -autoDimmTo=50 -autoDimmSchemeBlacklistEnabled=false -autoDimmSchemeBlacklist= -enableBrightness=true -brightnessPercent=100 -cpuFreqPolicy=DYNAMIC -cpuFreqDynamicPerformance=75 - -[Powersave] -specSsSettings=true -disableSs=false -blankSs=true -specPMSettings=true -standbyAfter=2 -suspendAfter=3 -powerOffAfter=5 -disableDPMS=false -autoSuspend=false -autoInactiveAction=_NONE_ -autoInactiveActionAfter=0 -autoInactiveSchemeBlacklistEnabled=false -autoInactiveSchemeBlacklist= -autoDimm=true -autoDimmAfter=5 -autoDimmTo=15 -autoDimmSchemeBlacklistEnabled=No -autoDimmSchemeBlacklist= -enableBrightness=true -brightnessPercent=50 -cpuFreqPolicy=DYNAMIC -cpuFreqDynamicPerformance=25 - -[Presentation] -specSsSettings=true -disableSs=true -specPMSettings=true -standbyAfter=10 -suspendAfter=20 -powerOffAfter=30 -disableDPMS=true -autoSuspend=false -autoInactiveAction=_NONE_ -autoInactiveActionAfter=0 -autoInactiveSchemeBlacklistEnabled=false -autoInactiveSchemeBlacklist= -autoDimm=false -autoDimmAfter=0 -autoDimmTo=100 -autoDimmSchemeBlacklistEnabled=false -autoDimmSchemeBlacklist= -enableBrightness=true -brightnessPercent=100 -cpuFreqPolicy=DYNAMIC -cpuFreqDynamicPerformance=60 - -[Acoustic] -specSsSettings=true -disableSs=false -specPMSettings=true -standbyAfter=5 -suspendAfter=7 -powerOffAfter=10 -disableDPMS=false -autoSuspend=false -autoInactiveAction=_NONE_ -autoInactiveActionAfter=0 -autoInactiveSchemeBlacklistEnabled=false -autoInactiveSchemeBlacklist= -autoDimm=false -autoDimmAfter=0 -autoDimmTo=50 -autoDimmSchemeBlacklistEnabled=false -autoDimmSchemeBlacklist= -enableBrightness=true -brightnessPercent=100 -cpuFreqPolicy=DYNAMIC -cpuFreqDynamicPerformance=50 diff --git a/src/config/tdepowersaverc_default b/src/config/tdepowersaverc_default new file mode 100644 index 0000000..61e6e05 --- /dev/null +++ b/src/config/tdepowersaverc_default @@ -0,0 +1,151 @@ +[General] +lockOnSuspend=true +lockOnLidClose=true +ActionOnLidClose= +ActionOnLidCloseValue= +ActionOnPowerButton=SHUTDOWN +ActionOnPowerButtonValue= +ActionOnSleepButton=SUSPEND2RAM +ActionOnS2DiskButton=SUSPEND2DISK +buttonsAllowedActions=SHUTDOWN,LOGOUT_DIALOG,SUSPEND2DISK,SUSPEND2RAM +AutoSuspendCountdown=true +AutoSuspendCountdownTimeOut=30 +Autostart=true +AutostartNeverAsk=false +unmountExternalOnSuspend=false +callSetPowerSaveOnAC=true +lockMethod=automatic +timeToFakeKeyAfterLock=2500 +forceDpmsOffOnLidClose=true +psMsgAsPassivePopup=false +autoInactiveBlacklist=mplayer,gmplayer,kaffeine,xine,mencoder,cdrecord,cdrecord-dvd,cdrdao,growisofs,kdetv,xawtv,realplay.bin,wodim +autoDimmBlacklist=mplayer,gmplayer,kaffeine,xine,kdetv,xawtv,realplay.bin +schemes=Performance,Powersave,Presentation,Acoustic +ac_scheme=Performance +battery_scheme=Powersave +batteryWarning=12 +batteryWarningAction= +batteryWarningActionValue= +batteryLow=7 +batteryLowAction=BRIGHTNESS +batteryLowActionValue=1 +batteryCritical=2 +batteryCriticalAction=SHUTDOWN +batteryCriticalActionValue= +batteryAllowedActions=SHUTDOWN,SUSPEND2DISK,SUSPEND2RAM,CPUFREQ_POWERSAVE,CPUFREQ_PERFORMANCE,CPUFREQ_DYNAMIC,BRIGHTNESS + +[default-scheme] +specSsSettings=false +disableSs=false +blankSs=false +specPMSettings=false +standbyAfter=5 +suspendAfter=10 +powerOffAfter=15 +disableDPMS=false +autoSuspend=false +autoInactiveAction=_NONE_ +autoInactiveActionAfter=0 +autoInactiveSchemeBlacklistEnabled=false +autoInactiveSchemeBlacklist= +autoDimm=false +autoDimmAfter=0 +autoDimmTo=50 +autoDimmSchemeBlacklistEnabled=false +autoDimmSchemeBlacklist= +enableBrightness=true +brightnessPercent=100 +cpuFreqPolicy=DYNAMIC +cpuFreqPolicyPerformance=51 + +[Performance] +specSsSettings=false +specPMSettings=true +standbyAfter=10 +suspendAfter=20 +powerOffAfter=30 +disableDPMS=false +autoSuspend=false +autoInactiveAction=_NONE_ +autoInactiveActionAfter=0 +autoInactiveSchemeBlacklistEnabled=false +autoInactiveSchemeBlacklist= +autoDimm=false +autoDimmAfter=0 +autoDimmTo=50 +autoDimmSchemeBlacklistEnabled=false +autoDimmSchemeBlacklist= +enableBrightness=true +brightnessPercent=100 +cpuFreqPolicy=DYNAMIC +cpuFreqDynamicPerformance=75 + +[Powersave] +specSsSettings=true +disableSs=false +blankSs=true +specPMSettings=true +standbyAfter=2 +suspendAfter=3 +powerOffAfter=5 +disableDPMS=false +autoSuspend=false +autoInactiveAction=_NONE_ +autoInactiveActionAfter=0 +autoInactiveSchemeBlacklistEnabled=false +autoInactiveSchemeBlacklist= +autoDimm=true +autoDimmAfter=5 +autoDimmTo=15 +autoDimmSchemeBlacklistEnabled=No +autoDimmSchemeBlacklist= +enableBrightness=true +brightnessPercent=50 +cpuFreqPolicy=DYNAMIC +cpuFreqDynamicPerformance=25 + +[Presentation] +specSsSettings=true +disableSs=true +specPMSettings=true +standbyAfter=10 +suspendAfter=20 +powerOffAfter=30 +disableDPMS=true +autoSuspend=false +autoInactiveAction=_NONE_ +autoInactiveActionAfter=0 +autoInactiveSchemeBlacklistEnabled=false +autoInactiveSchemeBlacklist= +autoDimm=false +autoDimmAfter=0 +autoDimmTo=100 +autoDimmSchemeBlacklistEnabled=false +autoDimmSchemeBlacklist= +enableBrightness=true +brightnessPercent=100 +cpuFreqPolicy=DYNAMIC +cpuFreqDynamicPerformance=60 + +[Acoustic] +specSsSettings=true +disableSs=false +specPMSettings=true +standbyAfter=5 +suspendAfter=7 +powerOffAfter=10 +disableDPMS=false +autoSuspend=false +autoInactiveAction=_NONE_ +autoInactiveActionAfter=0 +autoInactiveSchemeBlacklistEnabled=false +autoInactiveSchemeBlacklist= +autoDimm=false +autoDimmAfter=0 +autoDimmTo=50 +autoDimmSchemeBlacklistEnabled=false +autoDimmSchemeBlacklist= +enableBrightness=true +brightnessPercent=100 +cpuFreqPolicy=DYNAMIC +cpuFreqDynamicPerformance=50 diff --git a/src/configure.in.in b/src/configure.in.in index 9f9bdd1..dfcd1b3 100644 --- a/src/configure.in.in +++ b/src/configure.in.in @@ -1,6 +1,6 @@ #MIN_CONFIG(3.0.0) -AM_INIT_AUTOMAKE(kpowersave, 0.1) +AM_INIT_AUTOMAKE(tdepowersave, 0.1) AC_C_BIGENDIAN AC_CHECK_KDEMAXPATHLEN diff --git a/src/configure_Dialog.ui b/src/configure_Dialog.ui index 2500a62..ba7bfa3 100644 --- a/src/configure_Dialog.ui +++ b/src/configure_Dialog.ui @@ -21,7 +21,7 @@ - KPowersave Settings + TDEPowersave Settings true @@ -1975,7 +1975,7 @@ cB_autostart - KPowersave starts automatically on login + TDEPowersave starts automatically on login diff --git a/src/configuredialog.cpp b/src/configuredialog.cpp index 93843ea..59f0fad 100644 --- a/src/configuredialog.cpp +++ b/src/configuredialog.cpp @@ -19,7 +19,7 @@ /*! \file configuredialog.cpp * All here displayed file members of configureDialog.cpp are related to operations with the - * configure dialog for kpowersave + * configure dialog for tdepowersave * \brief In this file can be found all configure dialog related code. * \author Danny Kukawka, , * \date 2005 @@ -226,7 +226,7 @@ void ConfigureDialog::setIcons(){ kdDebugFuncIn(trace); /* set all Icons */ - this->setIcon(SmallIcon("kpowersave", TQIconSet::Automatic)); + this->setIcon(SmallIcon("tdepowersave", TQIconSet::Automatic)); buttonApply->setIconSet(SmallIconSet("apply", TQIconSet::Automatic)); buttonCancel->setIconSet(SmallIconSet("cancel", TQIconSet::Automatic)); buttonOk->setIconSet(SmallIconSet("ok", TQIconSet::Automatic)); @@ -270,15 +270,15 @@ void ConfigureDialog::setTooltips(){ // TQToolTip::setWakeUpDelay ( 1000 ); TQToolTip::add(cB_specificSettings, i18n("This enables specific screen saver settings. \n" "Note: If selected, the global screen saver settings are \n" - "overwritten while kpowersave runs.")); + "overwritten while tdepowersave runs.")); TQToolTip::add(cB_disable_Ss, i18n("This disables the screen saver. \n" "Note: If selected, the global screen saver settings are \n" - "overwritten while kpowersave runs.")); + "overwritten while tdepowersave runs.")); TQToolTip::add(cB_blankScreen, i18n("This blanks the screen instead of using a specific screen saver. \n" "Note: This may work only with KScreensaver.")); TQToolTip::add(cB_SpecificPM, i18n("This enables specific DPMS settings. \n" "Note: If selected, the global DPMS settings are \n" - "overwritten while kpowersave runs.")); + "overwritten while tdepowersave runs.")); TQToolTip::add(cB_disablePM, i18n("This disables DPMS support.")); TQToolTip::add(cB_lockSuspend, i18n("If selected, the screen is locked on suspend or standby.")); TQToolTip::add(cB_lockLid, i18n("If selected, the screen is locked if the lid close event is triggered.")); @@ -1035,7 +1035,7 @@ void ConfigureDialog::pB_newScheme_clicked(){ getSchemeList(); while (!_end) { - _new = KInputDialog::getText( i18n("KPowersave Configuration"), + _new = KInputDialog::getText( i18n("TDEPowersave Configuration"), _error + _text, TQString(), &_ok, this); if (!_ok ) { _end = true; diff --git a/src/configuredialog.h b/src/configuredialog.h index 6deb9b4..837866d 100644 --- a/src/configuredialog.h +++ b/src/configuredialog.h @@ -58,9 +58,9 @@ private: //! pointer to instance of the blacklist edit dialog for Autodimm blacklistEditDialog* blacklistEDlgAD; - //! the pointer to the config of kpowersave, get from constructor + //! the pointer to the config of tdepowersave, get from constructor TDEConfig *tdeconfig; - //! pointer to the KPowersave settings, get from constructor + //! pointer to the TDEPowersave settings, get from constructor Settings *settings; //! pointer to hardware information and actions HardwareInfo *hwinfo; diff --git a/src/countdowndialog.cpp b/src/countdowndialog.cpp index a3d9ac0..0adf891 100644 --- a/src/countdowndialog.cpp +++ b/src/countdowndialog.cpp @@ -25,7 +25,7 @@ // own header #include "countdowndialog.h" -#include "kpowersave_debug.h" +#include "tdepowersave_debug.h" // KDE headers: #include @@ -52,7 +52,7 @@ countDownDialog::countDownDialog( int timeout, TQWidget *parent, const char *nam PROGRESS = new TQTimer(this); connect(PROGRESS, TQT_SIGNAL(timeout()), this, TQT_SLOT(updateProgress())); - this->setCaption(i18n("KPowersave")); + this->setCaption(i18n("TDEPowersave")); kdDebugFuncOut(trace); } @@ -82,7 +82,7 @@ void countDownDialog::setPixmap( TQString type ) } else if (type.startsWith("standby")) { pixmap = TDEGlobal::iconLoader()->loadIcon("stand_by", TDEIcon::NoGroup, TDEIcon::SizeLarge); } else { - pixmap = TDEGlobal::iconLoader()->loadIcon("kpowersave", TDEIcon::NoGroup, TDEIcon::SizeLarge); + pixmap = TDEGlobal::iconLoader()->loadIcon("tdepowersave", TDEIcon::NoGroup, TDEIcon::SizeLarge); } iconPixmap->setPixmap( pixmap ); } diff --git a/src/dbusInterface.cpp b/src/dbusInterface.cpp index 82cffd6..19e4bc3 100644 --- a/src/dbusInterface.cpp +++ b/src/dbusInterface.cpp @@ -488,7 +488,7 @@ out: /* ---> PolicyKit method call section :: END <--- */ /*! - * Use this TQT_SLOT to emit a reviced messages to the kpowersave. + * Use this TQT_SLOT to emit a reviced messages to the tdepowersave. * NOTE: Because of the filter function this need to be a public function. * Don't use this function in any other place than this class. * \param type enum with the type of the message @@ -515,7 +515,7 @@ void dbusInterface::emitMsgReceived( msg_type type, TQString message, TQString s /*! * This function is needed filter function for the D-Bus connection to filter - * all needed messages from the bus which are needful for KPowersave. + * all needed messages from the bus which are needful for TDEPowersave. * \param connection existing connection to the D-Bus daemon * \param message the recieved message from the D-Bus daemon * \param data void pointer (see dbus bindings for more information) diff --git a/src/dbusInterface.h b/src/dbusInterface.h index 3e9ca94..f5afbd3 100644 --- a/src/dbusInterface.h +++ b/src/dbusInterface.h @@ -48,8 +48,8 @@ #include #include -// kpowersave - Header -#include "kpowersave_debug.h" +// tdepowersave - Header +#include "tdepowersave_debug.h" #define CK_SERVICE "org.freedesktop.ConsoleKit" #define CK_MANAGER_IFACE "org.freedesktop.ConsoleKit.Manager" @@ -77,7 +77,7 @@ private: //! real connection to D-Bus DBusConnection *dbus_connection; - //! to store information if KPowersave is connected to D-Bus + //! to store information if TDEPowersave is connected to D-Bus /*! * This boolean represent information about the state of the connection to D-Bus * \li true: if connected @@ -87,7 +87,7 @@ private: //! if we could claim the org.freedesktop.Policy.Power interface /*! - * This boolean represent information if KPowersave could claim the + * This boolean represent information if TDEPowersave could claim the * org.freedesktop.Policy.Power interface from the D-Bus * \li true: if acquired * \li false: if not @@ -122,7 +122,7 @@ public: bool isPolicyPowerIfaceOwned(); // --- helper to get private members of the class --- // - //! to get information if KPowersave is connected to D-Bus + //! to get information if TDEPowersave is connected to D-Bus bool isConnectedToDBUS(); //! to get info about claim org.freedesktop.Policy.Power interface bool acquiredPolicyPowerInterface(); diff --git a/src/detailed_Dialog.ui b/src/detailed_Dialog.ui index cb2eac8..0dbabda 100644 --- a/src/detailed_Dialog.ui +++ b/src/detailed_Dialog.ui @@ -21,7 +21,7 @@ - kpowersave + tdepowersave true diff --git a/src/detaileddialog.cpp b/src/detaileddialog.cpp index 163ff15..6a24349 100644 --- a/src/detaileddialog.cpp +++ b/src/detaileddialog.cpp @@ -58,7 +58,7 @@ detaileddialog::detaileddialog( HardwareInfo *_hwinfo, TQPixmap *_pixmap, Settin int batteries = primaryBatteries->getNumBatteries(); numOfCPUs = cpuInfo->getCPUNum(); - this->setCaption(i18n("KPowersave Information Dialog")); + this->setCaption(i18n("TDEPowersave Information Dialog")); // use this as compromise with current translation process // TODO: remove them in the next translation round @@ -423,7 +423,7 @@ void detaileddialog::setInfos() { else if(config->currentScheme == "AdvancedPowersave") InfoPictogram->setPixmap(SmallIcon("scheme_advanced_powersave", 22)); else - InfoPictogram->setPixmap(SmallIcon("kpowersave", 22)); + InfoPictogram->setPixmap(SmallIcon("tdepowersave", 22)); if(hwinfo->isOnline()) { if (hwinfo->supportCPUFreq()) { diff --git a/src/detaileddialog.h b/src/detaileddialog.h index ae38394..5cc6d4e 100644 --- a/src/detaileddialog.h +++ b/src/detaileddialog.h @@ -85,7 +85,7 @@ private: //! pointer to class settinfs to get the current settings Settings *config; - //! pointer to the kpowersave class + //! pointer to the tdepowersave class TQPixmap *pixmap; //! the numbers of CPUs in the system diff --git a/src/dummy.cpp b/src/dummy.cpp index 244ccc4..6a3b72c 100644 --- a/src/dummy.cpp +++ b/src/dummy.cpp @@ -90,7 +90,7 @@ class dummy { dummy = i18n("Try loading the default configuration."); dummy = i18n("Maybe the global configuration file is empty or missing."); - // for kpowersave.cpp: + // for tdepowersave.cpp: dummy = i18n("Cannot connect to D-Bus. The D-Bus daemon may not be running."); dummy = i18n("Scheme switched to %1. \n Deactivate following devices: %2").arg("").arg(""); dummy = i18n("Scheme switched to %1. \n Activate following devices: %2").arg("").arg(""); diff --git a/src/eventsrc b/src/eventsrc index 88ccc0b..8da795e 100644 --- a/src/eventsrc +++ b/src/eventsrc @@ -1,18 +1,18 @@ [!Global!] -IconName=kpowersave -Comment=KPowersave -Comment[cs]=KPowersave -Comment[de]=KPowersave -Comment[es]=KPowersave -Comment[fr]=KPowersave -Comment[it]=KPowersave -Comment[ja]=KPowersave -Comment[pl]=KPowersave -Comment[pt]=KPowersave -Comment[pt_BR]=KPowersave -Comment[ru]=KPowersave -Comment[zh_CN]=KPowersave -Comment[zh_TW]=KPowersave +IconName=tdepowersave +Comment=TDEPowersave +Comment[cs]=TDEPowersave +Comment[de]=TDEPowersave +Comment[es]=TDEPowersave +Comment[fr]=TDEPowersave +Comment[it]=TDEPowersave +Comment[ja]=TDEPowersave +Comment[pl]=TDEPowersave +Comment[pt]=TDEPowersave +Comment[pt_BR]=TDEPowersave +Comment[ru]=TDEPowersave +Comment[zh_CN]=TDEPowersave +Comment[zh_TW]=TDEPowersave [plug_event] Name=PlugEvent diff --git a/src/hardware.cpp b/src/hardware.cpp index 766b30b..d296476 100644 --- a/src/hardware.cpp +++ b/src/hardware.cpp @@ -36,7 +36,7 @@ // include own header #include "hardware.h" -#include "kpowersave_debug.h" +#include "tdepowersave_debug.h" #include "privileges.h" /*! The default constructor of the class HardwareInfo */ @@ -325,7 +325,7 @@ void HardwareInfo::handleResumeSignal (int result) { } /*! - * This function checks the session for the running KPowersave instance + * This function checks the session for the running TDEPowersave instance * \return Boolean with result of operation * \retval true if the query/check could get finished * \retval false on every error diff --git a/src/hardware.h b/src/hardware.h index 3dd048b..a5c7d5e 100644 --- a/src/hardware.h +++ b/src/hardware.h @@ -233,7 +233,7 @@ private: //! if brightness get controled via keyevents in hardware /*! * This boolean represent information if the machine handle brightness button - * and keyevents in hardware. If so KPowersave should ignore key events. + * and keyevents in hardware. If so TDEPowersave should ignore key events. * \li true: if handled in hardware * \li false: else */ @@ -249,7 +249,7 @@ private: //! if the current desktop session is active /*! * This boolean represent information if the current desktop session in - * Which KPowersave runs is marked in ConsoleKit as active or not. + * Which TDEPowersave runs is marked in ConsoleKit as active or not. * \li true: if active * \li false: else */ diff --git a/src/hardware_battery.cpp b/src/hardware_battery.cpp index ee9f0b9..8ae333d 100644 --- a/src/hardware_battery.cpp +++ b/src/hardware_battery.cpp @@ -418,7 +418,7 @@ bool Battery::checkChargeLevelCurrent () { } // FIXME VERIFY CORRECTNESS - // what does kpowersave expect to see in charge_level_current (battery.charge_level.current)? + // what does tdepowersave expect to see in charge_level_current (battery.charge_level.current)? charge_level_current = bdevice->energy(); if (charge_level_current < 0) { //overflow? @@ -455,7 +455,7 @@ bool Battery::checkChargeLevelLastfull () { } // FIXME VERIFY CORRECTNESS - // what does kpowersave expect to see in charge_level_lastfull (battery.charge_level.last_full)? + // what does tdepowersave expect to see in charge_level_lastfull (battery.charge_level.last_full)? charge_level_lastfull = bdevice->maximumEnergy(); if (charge_level_lastfull < charge_level_current ) { //possible overflow? @@ -493,7 +493,7 @@ bool Battery::checkChargeLevelRate () { int _rate = present_rate; // FIXME VERIFY CORRECTNESS - // what does kpowersave expect to see in present_rate (battery.charge_level.rate)? + // what does tdepowersave expect to see in present_rate (battery.charge_level.rate)? present_rate = bdevice->dischargeRate(); if (present_rate < 0 ) present_rate = 0; @@ -532,7 +532,7 @@ bool Battery::checkChargeLevelUnit () { } // FIXME VERIFY CORRECTNESS - // what does kpowersave expect to see in charge_level_unit (battery.charge_level.unit)? + // what does tdepowersave expect to see in charge_level_unit (battery.charge_level.unit)? charge_level_unit = "wH"; //query was not successfull but this is optional kdWarning() << "Couldn't request charge_level.unit for udi: " << udi << endl; @@ -566,7 +566,7 @@ bool Battery::checkChargeLevelDesign () { } // FIXME VERIFY CORRECTNESS - // what does kpowersave expect to see in design_capacity (battery.charge_level.last_full)? + // what does tdepowersave expect to see in design_capacity (battery.charge_level.last_full)? design_capacity = bdevice->maximumDesignEnergy(); if (design_capacity < 0) { design_capacity = 0; diff --git a/src/hardware_cpu.h b/src/hardware_cpu.h index 7d9c94d..62069ac 100644 --- a/src/hardware_cpu.h +++ b/src/hardware_cpu.h @@ -47,7 +47,7 @@ #include // own headers -#include "kpowersave_debug.h" +#include "tdepowersave_debug.h" class CPUInfo : public TQObject{ diff --git a/src/hi16-app-kpowersave.png b/src/hi16-app-kpowersave.png deleted file mode 100644 index 9353f8c..0000000 Binary files a/src/hi16-app-kpowersave.png and /dev/null differ diff --git a/src/hi16-app-tdepowersave.png b/src/hi16-app-tdepowersave.png new file mode 100644 index 0000000..9353f8c Binary files /dev/null and b/src/hi16-app-tdepowersave.png differ diff --git a/src/hi32-app-kpowersave.png b/src/hi32-app-kpowersave.png deleted file mode 100644 index d500a9f..0000000 Binary files a/src/hi32-app-kpowersave.png and /dev/null differ diff --git a/src/hi32-app-tdepowersave.png b/src/hi32-app-tdepowersave.png new file mode 100644 index 0000000..d500a9f Binary files /dev/null and b/src/hi32-app-tdepowersave.png differ diff --git a/src/hi48-app-kpowersave.png b/src/hi48-app-kpowersave.png deleted file mode 100644 index 26e2b89..0000000 Binary files a/src/hi48-app-kpowersave.png and /dev/null differ diff --git a/src/hi48-app-tdepowersave.png b/src/hi48-app-tdepowersave.png new file mode 100644 index 0000000..26e2b89 Binary files /dev/null and b/src/hi48-app-tdepowersave.png differ diff --git a/src/inactivity.h b/src/inactivity.h index 206cfea..8e03fd3 100644 --- a/src/inactivity.h +++ b/src/inactivity.h @@ -43,7 +43,7 @@ #include // from project -#include "kpowersave_debug.h" +#include "tdepowersave_debug.h" /*! * \file inactivity.h diff --git a/src/infodialog.cpp b/src/infodialog.cpp index 1205ca0..9837acb 100644 --- a/src/infodialog.cpp +++ b/src/infodialog.cpp @@ -73,9 +73,9 @@ infoDialog::infoDialog( TDEConfig *config, TQString captionName, TQString messag msgText->setText(message); if (!captionName.isEmpty()) - this->setCaption(i18n("KPowersave") + " - " + captionName); + this->setCaption(i18n("TDEPowersave") + " - " + captionName); else - this->setCaption(i18n("KPowersave")); + this->setCaption(i18n("TDEPowersave")); if (dontShowAgainMsg.isEmpty()) { dontShowAgain->setHidden(true); diff --git a/src/infodialog.h b/src/infodialog.h index 305a1a1..85d13dc 100644 --- a/src/infodialog.h +++ b/src/infodialog.h @@ -54,7 +54,7 @@ public: private: - //! the pointer to the settings of kpowersave, get from constructor + //! the pointer to the settings of tdepowersave, get from constructor TDEConfig *settings; //! name of the entry in the settings diff --git a/src/kpowersave-autostart.desktop b/src/kpowersave-autostart.desktop deleted file mode 100644 index 96bc19f..0000000 --- a/src/kpowersave-autostart.desktop +++ /dev/null @@ -1,68 +0,0 @@ -[Desktop Entry] -Encoding=UTF-8 -Name=kpowersave -Name[xx]=xxkpowersavexx -Name[de]=KPowersave -Name[es]=KPowersave -Name[fr]=KPowersave -Name[it]=KPowersave -Name[ja]=KPowersave -Name[pt_BR]=KPowersave -Name[ru]=KPowersave -Name[sv]=KPowersave -Name[zh_CN]=KPowersave -Name[zh_TW]=KPowersave -GenericName=Battery Monitor -Exec=kpowersave -Icon=kpowersave -Type=Application -Comment=Battery monitor and general power management -Comment[bg]=Монитор за батерията и основно управление на енергията -GenericName[bg]=Монитор за батерията -Comment[cs]=Sledování stavu baterií a správa napájení -GenericName[cs]=Monitor baterie -GenericName[de]=Akkuüberwachung -Comment[de]=Akkuüberwachung und allgemeine Energieverwaltung -GenericName[el]=Παρακολούθηση Μπαταρίας -GenericName[es]=Monitor de carga de la batería -Comment[es]=Monitor de batería y gestión general de la energía -Comment[fi]=Akkumonitori ja yleinen virranhallinta -GenericName[fi]=Akkumonitori -Comment[fr]=Moniteur de batterie et gestion de l'alimentation -GenericName[fr]=Moniteur de batterie -GenericName[hu]=Akkumulátorfigyelő -Comment[it]=Monitor della batteria e gestione generale dell'alimentazione -GenericName[it]=Monitor della batteria -Comment[km]=កមមវធ<200b>តរតពនតយ<200b>ថម នង គរបគរង<200b>ថាមពល<200b>ទទៅ -GenericName[km]=កមមវធ<200b>តរតពនតយ<200b>ថម -Comment[nb]=Batteriovervåking og generell strømstyring -GenericName[nb]=Batteriovervåker -GenericName[nl]=Batterijmonitor -GenericName[ja]=バッテリモニタ -Comment[ja]=バッテリモニタと一般電源管理 -Name[pa]=ਕ-ਊਰਜਾ ਸਭਾਲ -GenericName[pa]=ਬਟਰੀ ਦਰਸ਼ਕ -Comment[pl]=Monitor stanu baterii i ogólne zarządzanie energią -GenericName[pl]=Monitor baterii -Comment[pt]=Monitor de bateria e gestor global de energia -GenericName[pt]=Monitor de Bateria -Comment[pt_BR]=Monitor de Bateria e Gerenciamento de Energia Geral -GenericName[pt_BR]=Monitor de Bateria -GenericName[ru]=Монитор Батареи -Comment[ru]=Монитор батареи и управление энергосбережением -GenericName[sv]=Batteriövervakare -GenericName[tr]=Pil durumu izleme ve güç yönetimi arayüzü -Comment[tr]=Pil durumu izleme ve güç yönetimi arayüzü -Comment[uk]=Монітор стану батареї і загальне керування живленням -GenericName[uk]=Монітор батарей -Comment[xx]=xxBattery monitor and general power managementxx -GenericName[zh_CN]=电池监视器 -Comment[zh_CN]=电池监视器和常规电源管理 -GenericName[zh_TW]=電池監視器 -Comment[zh_TW]=電池監視器和一般電源管理 -X-TDE-autostart-after=panel -X-TDE-StartupNotify=false -X-TDE-UniqueApplet=true -X-TDE-autostart-condition=kpowersaverc:General:Autostart:true -Categories=System;Applet; - diff --git a/src/kpowersave.cpp b/src/kpowersave.cpp deleted file mode 100644 index a248da5..0000000 --- a/src/kpowersave.cpp +++ /dev/null @@ -1,2678 +0,0 @@ - /************************************************************************** - * Copyright (C) 2004 by Thomas Renninger * - * and * - * 2004-2007 by Danny Kukawka * - * , * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of version 2 of the GNU General Public License * - * as published by the Free Software Foundation. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -// KDE headers: -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// other TQt headers: -#include -#include -#include -#include -#include -#include -#include - -// own headers: -#include "kpowersave.h" -#include "infodialog.h" - -/*! -* \file kpowersave.cpp -* \brief This file contains the main functionality of the kpowersave-applet.*/ - -/*! - * This is the default constructor of the class kpowersave. - */ -kpowersave::kpowersave( bool force_acpi_check, bool trace_func ) : KSystemTray(0, "kpowersave"), - DCOPObject("KPowersaveIface") { - trace = trace_func; - kdDebugFuncIn(trace); - - display = new screen(); - settings = new Settings(); - autoSuspend = new autosuspend(); - autoDimm = new autodimm(); - hwinfo = new HardwareInfo(); - suspend = hwinfo->getSuspendSupport(); - - yast2 = NULL; - - resume_result = 0; - - config = TDEGlobal::config(); - config->setGroup("General"); - if(!config->readBoolEntry("AlreadyStarted", false) || force_acpi_check){ - config->writeEntry("AlreadyStarted", true); - // check whether APM, ACPI, PMU, CPUFreq or Suspend2Disk/ram supported, otherwise end up - // and don't start kpowersave ever again until force_acpi_check == true. - if (!hwinfo->hasACPI() && !hwinfo->hasAPM() && !hwinfo->hasPMU() && - !hwinfo->supportCPUFreq() && !suspend.suspend2disk && !suspend.suspend2ram){ - config->writeEntry("Autostart", false); - config->sync(); - kdError() << "This machine does not support ACPI, APM, PMU, CPUFreq, Suspend2Disk nor " - << "Suspend2RAM. Please close KPowersave now." << endl; - exit(-1); - } - } - - // default init - if (hwinfo->getAcAdapter()) { - settings->load_scheme_settings( settings->ac_scheme); - } else { - settings->load_scheme_settings( settings->battery_scheme); - } - // set the battery warning levels - hwinfo->setPrimaryBatteriesWarningLevel(settings->batteryWarningLevel, - settings->batteryLowLevel, - settings->batteryCriticalLevel); - - // connect to signals for changes - connect(hwinfo, TQT_SIGNAL(generalDataChanged()), this, TQT_SLOT(update())); - connect(hwinfo, TQT_SIGNAL(primaryBatteryChanged()), this, TQT_SLOT(update())); - connect(hwinfo, TQT_SIGNAL(ACStatus(bool)), this, TQT_SLOT(handleACStatusChange (bool))); - connect(hwinfo, TQT_SIGNAL(resumed(int)), this, TQT_SLOT(forwardResumeSignal(int))); - - // connect to error mesages - connect(autoSuspend, TQT_SIGNAL(displayErrorMsg(TQString)), this, TQT_SLOT(showErrorMessage(TQString))); - - // connect to events - connect(hwinfo, TQT_SIGNAL(lidclosetStatus(bool)), this, TQT_SLOT(handleLidEvent(bool))); - connect(hwinfo, TQT_SIGNAL(powerButtonPressed()), this, TQT_SLOT (handlePowerButtonEvent())); - connect(hwinfo, TQT_SIGNAL(sleepButtonPressed()), this, TQT_SLOT (handleSleepButtonEvent())); - connect(hwinfo, TQT_SIGNAL(s2diskButtonPressed()), this, TQT_SLOT (handleS2DiskButtonEvent())); - connect(hwinfo, TQT_SIGNAL(batteryWARNState(int,int)), this, TQT_SLOT(notifyBatteryStatusChange (int,int))); - connect(hwinfo, TQT_SIGNAL(desktopSessionIsActive(bool)), this, TQT_SLOT (handleSessionState(bool))); - connect(autoSuspend, TQT_SIGNAL(inactivityTimeExpired()), this, TQT_SLOT(do_autosuspendWarn())); - connect(autoDimm, TQT_SIGNAL(inactivityTimeExpired()), this, TQT_SLOT(do_downDimm())); - connect(autoDimm, TQT_SIGNAL(UserIsActiveAgain()), this, TQT_SLOT(do_upDimm())); - - config->sync(); - - config_dialog_shown = false; - suspend_dialog_shown = false; - detailedIsShown = false; - icon_set_colored = false; - icon_BG_is_colored = false; - - calledSuspend = -1; - countWhiteIconPixel = 0; - - pixmap_name = "NONE"; - suspendType = "NULL"; - - BAT_WARN_ICON_Timer = new TQTimer(this); - connect(BAT_WARN_ICON_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_setIconBG())); - - AUTODIMM_Timer = new TQTimer(this); - - initMenu(); - update(); - updateCPUFreqMenu(); - setSchemeSettings(); - - kdDebugFuncOut(trace); -} - - -/*! This is the default destructor of class kpowersave. */ -kpowersave::~kpowersave(){ - kdDebugFuncIn(trace); - - delete hwinfo; - delete display; - delete settings; - delete autoSuspend; -#ifdef ENABLE_YAST_ENTRY - delete yast2; -#endif -} - -/*! - * use this function to initalise the main kicker menu - */ -void kpowersave::initMenu() { - kdDebugFuncIn(trace); - - CONFIGURE_ID = this->contextMenu()->insertItem(SmallIcon("configure", TQIconSet::Automatic), - i18n("Configure KPowersave..."), - this, TQT_SLOT(showConfigureDialog())); - CONFIGURE_EVENTS_ID = this->contextMenu()->insertItem(SmallIcon("knotify", TQIconSet::Automatic), - i18n("Configure Notifications..."), - this, TQT_SLOT(showConfigureNotificationsDialog())); -#ifdef ENABLE_YAST_ENTRY - YAST_MODULE_MENU_ID = this->contextMenu()->insertItem(SmallIcon("yast", TQIconSet::Automatic), - i18n("Start YaST2 Power Management Module..."), - this, TQT_SLOT(do_config())); -#endif - - SLEEP_SEPARATOR_MENU_ID = this->contextMenu()->insertSeparator(); - SUSPEND2DISK_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("suspend_to_disk", - TQIconSet::Automatic), - i18n("Suspend to Disk"), this, - TQT_SLOT(do_suspend2disk())); - SUSPEND2RAM_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("suspend_to_ram", - TQIconSet::Automatic), - i18n("Suspend to RAM"), this, - TQT_SLOT(do_suspend2ram())); - STANDBY_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("stand_by", TQIconSet::Automatic), - i18n("Standby"), this, TQT_SLOT(do_standby())); - - speed_menu = new TQPopupMenu(this, i18n("Set CPU Frequency Policy").ascii()); - speed_menu->insertItem(i18n("Performance"), PERFORMANCE); - speed_menu->insertItem(i18n("Dynamic"), DYNAMIC); - speed_menu->insertItem(i18n("Powersave"), POWERSAVE); - - CPUFRETQ_SEPARATOR_MENU_ID = contextMenu()->insertSeparator(); - - CPUFRETQ_MENU_ID = contextMenu()->insertItem(i18n("Set CPU Frequency Policy"), speed_menu); - connect(speed_menu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(do_setSpeedPolicy(int))); - connect(hwinfo, TQT_SIGNAL(currentCPUFreqPolicyChanged()), this, TQT_SLOT(updateCPUFreqMenu())); - - - SCHEME_SEPARATOR_MENU_ID = contextMenu()->insertSeparator(); - - scheme_menu = new TQPopupMenu(this, i18n("Set Active Scheme").ascii()); - SCHEME_MENU_ID = contextMenu()->insertItem(i18n("Set Active Scheme"), scheme_menu); - connect(scheme_menu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(do_setActiveScheme(int))); - - // menu entry for the autosuspend disable checkbox, disabled by default, only - // displayed if autosuspend for the current scheme is activated - AUTOSUSPEND_SEPARATOR_MENU_ID = contextMenu()->insertSeparator(); - AUTOSUSPEND_MENU_ID = this->contextMenu()->insertItem( i18n("Disable Actions on Inactivity"), - this,TQT_SLOT(do_setAutosuspend())); - this->contextMenu()->setItemVisible(AUTOSUSPEND_SEPARATOR_MENU_ID, false); - this->contextMenu()->setItemVisible(AUTOSUSPEND_MENU_ID, false); - - HELP_SEPARATOR_MENU_ID = contextMenu()->insertSeparator(); - - help_menu = new TQPopupMenu(this, i18n("&Help").ascii()); - - help_menu->insertItem( SmallIcon("help", TQIconSet::Automatic), i18n("&KPowersave Handbook"), - this, TQT_SLOT(slotHelp())); - help_menu->insertSeparator(); - help_menu->insertItem( i18n("&Report a bug ..."), this, TQT_SLOT(slotReportBug())); - help_menu->insertItem( SmallIcon("kpowersave", TQIconSet::Automatic), - i18n("&About KPowersave"), this, TQT_SLOT(slotAbout())); - - HELP_MENU = contextMenu()->insertItem(SmallIcon("help", TQIconSet::Automatic), - i18n("&Help"), help_menu); - - connect(this, TQT_SIGNAL(quitSelected()), this, TQT_SLOT(_quit())); - - kdDebugFuncOut(trace); -} - -void kpowersave::resizeEvent ( TQResizeEvent * ) -{ - // Honor Free Desktop specifications that allow for arbitrary system tray icon sizes - loadIcon(true); - drawIcon(); -} - -/*! - * This funtion load and manipulate the icons for the kickerapplet-section. - * The redraw interval depends on \ref icon_set_colored and \ref BAT_icon_BG_intervall. - */ -void kpowersave::redrawPixmap(){ - kdDebugFuncIn(trace); - - // if colored icon_background: normal redraw intervall is set off. - // Icon (only) redrawed every BAT_icon_BG_intervall - if (icon_set_colored) { - if (icon_state_changed) { - loadIcon(); - drawIcon(); - } - } - else { - loadIcon(); - drawIcon(); - } - - kdDebugFuncOut(trace); -} - -/*! - * Starts the configure dialog of kpowersave. - */ -void kpowersave::showConfigureDialog() { - kdDebugFuncIn(trace); - - if(!config_dialog_shown) { - if (settings->schemes.count() > 0){ - configDlg = new ConfigureDialog(config, hwinfo, settings); - configDlg->show(); - config_dialog_shown = true; - connect(configDlg, TQT_SIGNAL(destroyed()), this, TQT_SLOT(observeConfigDlg())); - connect(configDlg, TQT_SIGNAL(openHelp()), this, TQT_SLOT(slotHelp())); - connect(configDlg, TQT_SIGNAL(openKNotify()), this, TQT_SLOT(showConfigureNotificationsDialog())); - } - else { - KPassivePopup::message(i18n("WARNING"), i18n("Cannot find any schemes."), - SmallIcon("messagebox_warning", 20), this, - i18n("Warning").ascii(), 15000); - } - } else { - configDlg->setWindowState((configDlg->windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); - configDlg->setActiveWindow(); - } - - kdDebugFuncOut(trace); -} - -/*! - * Starts the notification configure dialog of kpowersave. - */ -void kpowersave::showConfigureNotificationsDialog() { - kdDebugFuncIn(trace); - - KNotifyDialog::configure(this); - - kdDebugFuncOut(trace); -} - -/*! - * Load the icons (from filesystem) for the kicker applet to \ref pixmap . - * To reduce the systemload the icons are only reloaded if \ref pixmap_name - * is changed. - */ -void kpowersave::loadIcon(bool forceReload){ - kdDebugFuncIn(trace); - - TQString pixmap_name_tmp = "NONE"; - - BatteryCollection *primary = hwinfo->getPrimaryBatteries(); - - if ( !hwinfo->isOnline() ) { - pixmap_name_tmp = TQString("ERROR"); - } - else if (hwinfo->getAcAdapter() || primary->getBatteryState() == BAT_NONE) { - icon_set_colored = false; - - if (primary->getBatteryState() == BAT_NONE || (primary->getRemainingPercent() < 0 || - primary->getRemainingPercent() >= 99)) - pixmap_name_tmp = TQString("laptoppower"); - else - pixmap_name_tmp = TQString("laptopcharge"); - } - else { - switch(primary->getBatteryState()) { - case BAT_CRIT: - case BAT_LOW: - if (icon_BG_is_colored) pixmap_name_tmp = TQString("laptopbattery"); - else pixmap_name_tmp = TQString("laptopbatteryRED"); - icon_BG_is_colored = !icon_BG_is_colored; - icon_set_colored = true; - break; - case BAT_WARN: - if (icon_BG_is_colored) pixmap_name_tmp = TQString("laptopbattery"); - else pixmap_name_tmp = TQString("laptopbatteryORANGE"); - icon_BG_is_colored = !icon_BG_is_colored; - icon_set_colored = true; - break; - default: - // if battery is discharging and not in warning, low or critical state - pixmap_name_tmp = TQString("laptopbattery"); - icon_set_colored = false; - icon_BG_is_colored = false; - } - - if (icon_set_colored){ - icon_state_changed = false; - BAT_WARN_ICON_Timer->start(BAT_icon_BG_intervall, true); - } - } - - // reload icon only if new icon selected - if ((pixmap_name_tmp != pixmap_name) || (forceReload)) { - pixmap_name = pixmap_name_tmp; - if (pixmap_name.startsWith("ERROR")) { - pixmap = SmallIcon("laptoppower", width(), TDEIcon::DisabledState); - } - else - pixmap = SmallIcon(pixmap_name, width()); - } - - kdDebugFuncOut(trace); -} - - -/*! - * This function draw the battery-capacity (colored field) to the icon. - * Here also counted the white pixel in the icon-files. Since the icons are - * the same and white pixel only in the rectangle of the icon, the white pixel - * stored in \ref countWhiteIconPixel only one time. - */ -void kpowersave::drawIcon(){ - kdDebugFuncIn(trace); - - BatteryCollection *primary = hwinfo->getPrimaryBatteries(); - - TQImage image = pixmap.convertToImage(); - int w = image.width(); - int h = image.height(); - int x, y; - countWhiteIconPixel = 0; - - if((pixmap_name.contains("laptopbattery") || pixmap_name.contains("charge")) && - countWhiteIconPixel == 0) { - for (x = 0; x < w; x++) - for (y = 0; y < h; y++) - if(TQColor(image.pixel(x, y)) == TQt::white) countWhiteIconPixel++; - } - - int c = (countWhiteIconPixel * primary->getRemainingPercent()) / 100; - - if (c > 0) { - uint ui; - TQRgb Rgb_set; - - if (hwinfo->getAcAdapter()) { - Rgb_set = tqRgb(0x00, 0xff, 0x00); //green - } - else { - switch(primary->getBatteryState()) { - case BAT_CRIT: - case BAT_LOW: - Rgb_set = tqRgb(0xff, 0x00, 0x00);//red - break; - case BAT_WARN: - Rgb_set = tqRgb(0xff, 0x55, 0x00); //orange - break; - default: - Rgb_set = tqRgb(0x00, 0xff, 0x00); //green - } - } - if (image.depth() <= 8) { - ui = image.numColors(); - image.setNumColors(ui + 1); - image.setColor(ui, Rgb_set); - } - ui = 0xff000000 | Rgb_set; - - for (y = h - 1; y >= 0; y--) { - for (x = 0; x < w ; x++) { - if(TQColor(image.pixel(x, y)) == TQt::white) { - image.setPixel(x, y, ui); - c--; - if (c <= 0) goto quit; - } - } - } - } -quit: - image = image.smoothScale(width(), height()); - fullIcon.convertFromImage(image); - setPixmap(fullIcon); - - kdDebugFuncOut(trace); -} - -/*! -* By this function we fill and update the Tooltip for the icon in the kicker applet. -* The content of the tooltip alway updated, if something change. -* \todo Check if the tooltip also updated if mouse \b is over the icon, if not we maybe -* should implement this.\n If it is possible we should update the tooltip permanently -* while the mouse cursor is over the widget -*/ -void kpowersave::updateTooltip(){ - kdDebugFuncIn(trace); - - BatteryCollection *primary = hwinfo->getPrimaryBatteries(); - int percent = primary->getRemainingPercent(); - int minutes = primary->getRemainingMinutes(); - int charging_state = primary->getChargingState(); - - TQString tmp, num3; - num3.setNum(minutes % 60); - num3 = num3.rightJustify(2, '0'); - - if ( !hwinfo->isOnline() ){ - tmp = i18n("No information about battery and AC status available"); - } - else if (hwinfo->getAcAdapter()) { - if (percent == 100) tmp = i18n("Plugged in -- fully charged"); - // assume that no battery is there - else { - if ((percent < 0 && minutes < 0) || primary->getBatteryState() == BAT_NONE) { - tmp = i18n("Plugged in"); - } - else if (minutes > 0){ - if (charging_state == CHARGING) - tmp = i18n("Plugged in -- %1% charged (%2:%3 h until full " - "charged)").arg(percent).arg(minutes / 60).arg(num3); - else - tmp = i18n("Plugged in -- %1% charged (%2:%3 remaining hours)") - .arg(percent).arg(minutes / 60).arg(num3); - } - else if (charging_state == CHARGING && hwinfo->hasAPM()) { - tmp = i18n("Plugged in -- %1% charged").arg(percent); - } - else{ - if (percent == -1) tmp = i18n("Plugged in -- no battery"); - else tmp = i18n("Plugged in -- %1% charged").arg(percent); - } - } - } else{ - if (minutes >= 0){ - tmp = i18n("Running on batteries -- %1% charged (%2:%3 hours remaining)") - .arg(percent).arg(minutes / 60).arg(num3); - } - else { - tmp = i18n("Running on batteries -- %1% charged").arg(percent); - } - } - // add string whether battery is charging, but only if < 100% to avoid - // stupid tooltip message on machines which always with 100% and on AC - // are charging, as e.g. Sony Vaio FS vgn-fs115b - if (charging_state == CHARGING && percent < 100) - tmp += i18n(" -- battery is charging"); - - TQToolTip::add(this, tmp); - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT to starts the Yast2-power-management module. This called by the menuentry - * with ID \ref YAST_MODULE_MENU_ID, named "Start YaST2 Power Management Module". - * It create a new TDEProcess and execute "/sbin/yast2 power-management" with tdesu. - */ -void kpowersave::do_config(){ - kdDebugFuncIn(trace); - - #ifdef ENABLE_YAST_ENTRY - delete yast2; - - yast2 = new TDEProcess; - *yast2 << "tdesu" << "--nonewdcop" << "/sbin/yast2" << "power-management"; - - connect(yast2, TQT_SIGNAL(processExited(TDEProcess *)), - TQT_SLOT(slotConfigProcessExited(TDEProcess *))); - if(!yast2->start(TDEProcess::NotifyOnExit)) - { - delete yast2; - yast2 = NULL; - } - - kdDebugFuncOut(trace); - #else - kdDebugFuncOut(trace); - return; - #endif -} - -/*! - * \b TQT_SLOT to open the KPowersave help - */ -void kpowersave::slotHelp() -{ - kapp->invokeHelp( "", "kpowersave" ); -} - -/*! - * \b TQT_SLOT to open the KPowersave About dialog - */ -void kpowersave::slotAbout() -{ - TDEAboutApplication a( this ); - a.exec(); -} - -/*! - * \b TQT_SLOT to open the website to report bugs - */ -void kpowersave::slotReportBug() -{ -#ifdef DISTRO_IS_SUSE - #ifdef DISTRO_IS_SLES_SLED - kapp->invokeBrowser("https://bugzilla.novell.com/"); - #else - kapp->invokeBrowser("http://en.opensuse.org/Submitting_Bug_Reports"); - #endif -#else - #ifdef DISTRO_IS_ALTLINUX - kapp->invokeBrowser("http://bugzilla.altlinux.org/"); - #else - #ifdef DISTRO_IS_UBUNTU - kapp->invokeBrowser("https://launchpad.net/distros/ubuntu/+bugs"); - #else - #ifdef DISTRO_IS_PARDUS - kapp->invokeBrowser("http://bugs.pardus.org.tr/"); - #else - kapp->invokeBrowser("http://sourceforge.net/tracker/?group_id=124576&atid=700009"); - #endif - #endif - #endif -#endif -} - -/*! - * \b TQT_SLOT to set the icon background on/off if battery is in critical, low or warning-state. Within - * this function we set \ref icon_state_changed to true and call \ref redrawPixmap() to redraw the - * kickerapplet icon and create a icon with blinking background. \n \n - * The slot called by the TQTimer \ref BAT_WARN_ICON_Timer . The interval of the timer is defined - * trough \ref BAT_icon_BG_intervall and starts here: \ref loadIcon() . - */ -void kpowersave::do_setIconBG(){ - kdDebugFuncIn(trace); - - if (icon_set_colored) icon_state_changed = true; - redrawPixmap(); - - kdDebugFuncOut(trace); -} -/*! - * \b TQT_SLOT to enable/disable the autosuspend. - */ -void kpowersave::do_setAutosuspend(){ - kdDebugFuncIn(trace); - - if(!contextMenu()->isItemChecked(AUTOSUSPEND_MENU_ID)) { - autoSuspend->stop(); - contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, true); - } - else { - if(settings->autoSuspend) { - contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, false); - setAutoSuspend(false); - } - else { - contextMenu()->setItemVisible(AUTOSUSPEND_MENU_ID, false); - contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, false); - contextMenu()->setItemVisible(AUTOSUSPEND_SEPARATOR_MENU_ID, false); - } - } - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT which called if the \ref configDlg is destroyed. We set within this SLOT - * \ref config_dialog_shown to false. - * TODO: check if we maybe should force here the current default scheme depending on the AC/battery state - */ -void kpowersave::observeConfigDlg(){ - kdDebugFuncIn(trace); - - // reload general settings - settings->load_general_settings(); - // set the battery warning levels - all other general settings don't need to - // get set, since we check the settings only on events. - hwinfo->setPrimaryBatteriesWarningLevel(settings->batteryWarningLevel, - settings->batteryLowLevel, - settings->batteryCriticalLevel); - - // reload the maybe changed scheme settings - settings->load_scheme_settings( settings->currentScheme ); - // set the scheme - setSchemeSettings(); - - config_dialog_shown=false; - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT which called from \ref do_config() if the 'tdesu yast2' TDEProcess exited. - * This function control the return value and display if needed a errormessage on failure. - */ -void kpowersave::slotConfigProcessExited(TDEProcess *proc){ - kdDebugFuncIn(trace); - - #ifdef ENABLE_YAST_ENTRY - if (proc->normalExit()){ - if (proc->exitStatus() != 0 && proc->exitStatus() != 16){ - KPassivePopup::message( i18n("WARNING"), - i18n("Could not start YaST Power Management Module. " - "Check if it is installed."), - SmallIcon("messagebox_warning", 20), this, - i18n("Warning"), 15000); - } - } - else{ - KPassivePopup::message( i18n("WARNING"), - i18n("Could not start YaST Power Management Module. " - "Check if it is installed."), - SmallIcon("messagebox_warning", 20), this, i18n("Warning"), 15000); - } - - kdDebugFuncOut(trace); - #else - kdDebugFuncOut(trace); - return; - #endif -} - -/*! - * \b TQT_SLOT to send the command for "suspend to disk" to HAL daemon. - * If there is a error while "suspend to disk" the user get e messagebox. - * This function need a running HAL daemon for "suspend to disk". - * \return boolean with the result of the operation - * \retval true if successful - * \retval false if command not supported or if powersaved not running - */ -bool kpowersave::do_suspend2disk(){ - kdDebugFuncIn(trace); - - if (suspend.suspend2disk) { - if (suspend.suspend2disk_allowed || suspend.suspend2disk_allowed == -1) { - calledSuspend = SUSPEND2DISK; - if (!handleMounts(true)) { - kdWarning() << "Could not umount ..." << endl; - calledSuspend = -1; - kdDebugFuncOut(trace); - return false; - } - - if(settings->lockOnSuspend) { - display->lockScreen( settings->lockmethod ); - } - - autoSuspend->stop(); - autoDimm->stop(); - notifySuspend(calledSuspend); - bool ret = hwinfo->suspend(SUSPEND2DISK); - - if (ret) { - kdDebugFuncOut(trace); - return true; - } else { - KPassivePopup::message( i18n("WARNING"),i18n("Suspend to disk failed"), - SmallIcon("messagebox_warning", 20), this, - i18n("Warning").ascii(), 15000); - kdDebugFuncOut(trace); - return false; - } - } else { - KPassivePopup::message( i18n("WARNING"), - i18n("Suspend to disk disabled by administrator."), - SmallIcon("messagebox_warning", 20), - this, i18n("Warning").ascii(), 15000); - this->contextMenu()->setItemEnabled(SUSPEND2DISK_MENU_ID, false); - kdDebugFuncOut(trace); - return false; - } - } else { - kdWarning() << "This machine does not provide suspend2disk via HAL" << endl; - kdDebugFuncOut(trace); - return false; - } -} - -/*! - * \b TQT_SLOT to send the command for "suspend to RAM" to the HAL daemon. - * If there is a error while "suspend to RAM" the user get e messagebox. - * This function need a running HAL daemon for "suspend to RAM". - * \return boolean with the result of the operation - * \retval true if successful - * \retval false if command not supported or if powersaved not running - */ -bool kpowersave::do_suspend2ram(){ - kdDebugFuncIn(trace); - - if (suspend.suspend2ram) { - if (suspend.suspend2ram_allowed || suspend.suspend2ram_allowed == -1) { - calledSuspend = SUSPEND2RAM; - if (!handleMounts(true)) { - kdWarning() << "Could not umount ..." << endl; - calledSuspend = -1; - kdDebugFuncOut(trace); - return false; - } - - if(settings->lockOnSuspend) { - display->lockScreen( settings->lockmethod ); - } - - autoSuspend->stop(); - autoDimm->stop(); - notifySuspend(calledSuspend); - bool ret = hwinfo->suspend(SUSPEND2RAM); - - if (ret) { - kdDebugFuncOut(trace); - return true; - } else { - KPassivePopup::message( i18n("WARNING"),i18n("Suspend to RAM failed"), - SmallIcon("messagebox_warning", 20), this, - i18n("Warning").ascii(), 15000); - kdDebugFuncOut(trace); - return false; - } - } else { - KPassivePopup::message( i18n("WARNING"), - i18n("Suspend to RAM disabled by administrator."), - SmallIcon("messagebox_warning", 20), this, - i18n("Warning").ascii(), 15000); - this->contextMenu()->setItemEnabled(SUSPEND2RAM_MENU_ID, false); - kdDebugFuncOut(trace); - return false; - } - } else { - kdWarning() << "This machine does not provide suspend2ram via HAL" << endl; - kdDebugFuncOut(trace); - return false; - } -} - -/*! - * \b TQT_SLOT to send the command for "stand-by" to the HAL daemon. - * If there is a error while "stand-by" the user get e messagebox. - * This function need a running HAL daemon for "stand-by". - * \return boolean with the result of the operation - * \retval true if successful - * \retval false if command not supported or if powersaved not running - */ -bool kpowersave::do_standby(){ - kdDebugFuncIn(trace); - - if (suspend.standby) { - if (suspend.standby_allowed || suspend.standby_allowed == -1) { - calledSuspend = STANDBY; - if (!handleMounts(true)) { - kdWarning() << "Could not umount ..." << endl; - calledSuspend = -1; - kdDebugFuncOut(trace); - return false; - } - - if(settings->lockOnSuspend) { - display->lockScreen( settings->lockmethod ); - } - - autoSuspend->stop(); - autoDimm->stop(); - notifySuspend(calledSuspend); - bool ret = hwinfo->suspend(STANDBY); - - if (ret) { - kdDebugFuncOut(trace); - return true; - } else { - KPassivePopup::message( i18n("WARNING"),i18n("Standby failed"), - SmallIcon("messagebox_warning", 20), this, - i18n("Warning").ascii(), 15000); - kdDebugFuncOut(trace); - return false; - } - } else { - KPassivePopup::message( i18n("WARNING"),i18n("Standby disabled by administrator."), - SmallIcon("messagebox_warning", 20), this, - i18n("Warning").ascii(), 15000); - this->contextMenu()->setItemEnabled(STANDBY_MENU_ID, false); - kdDebugFuncOut(trace); - return false; - } - } else { - kdWarning() << "This machine does not provide suspend2ram via HAL" << endl; - kdDebugFuncOut(trace); - return false; - } -} - -/*! - * \b TQT_SLOT to send check if we should display the warning dialog and display - * the dialog if needed or call directly autosuspend after the signal - * \ref autosuspend::inactivityTimeExpired was recieved. - */ -void kpowersave::do_autosuspendWarn() { - kdDebugFuncIn(trace); - - if (settings->autoSuspendCountdown && (settings->autoSuspendCountdownTimeout > 0)) { - // we have to display the warn dialog - if(!contextMenu()->isItemChecked(AUTOSUSPEND_MENU_ID)) { - TQString message; - - countdown = new countDownDialog(settings->autoSuspendCountdownTimeout); - - if(settings->autoInactiveAction == "Suspend to Disk") { - countdown->setPixmap("suspend2disk"); - } else if (settings->autoInactiveAction == "Suspend to RAM") { - countdown->setPixmap("suspend2ram"); - } else if (settings->autoInactiveAction == "Standby") { - countdown->setPixmap("standby"); - } else { - countdown->setPixmap("kpowersave"); - } - - // TODO: rework this after translation round for openSUSE 10.3 ! - message = i18n("Inactivity detected.") + " " + - i18n("To stop the %1 press the 'Cancel' button before the countdown " - "expire.").arg(i18n("Autosuspend")) + "\n\n" + - i18n("The computer autosuspend in: "); - - countdown->setMessageText(message); - - connect(countdown, TQT_SIGNAL(dialogClosed(bool)), this, TQT_SLOT(do_autosuspend(bool))); - countdown->showDialog(); - } - } else { - // call directly autosuspend - do_autosuspend(false); - } - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT to send the related suspend command for autosuspend - * \param chancel boolean with info if the autosuspend should get chanceld - * \return boolean with the result of the operation - * \retval true if successful - * \retval false if command not supported or on any other error - * \todo add check if the requested command is supported befor send and - * add message for this case to tell that maybe changed config! - */ -bool kpowersave::do_autosuspend(bool chancel) { - kdDebugFuncIn(trace); - - // TODO: check if this is really needed, it get called also on the suspend methodes - autoSuspend->stop(); - - if (!chancel) { - if(!settings->disableNotifications) { - KNotifyClient::event( this->winId(), "autosuspend_event", - i18n("System is going into suspend mode now")); - } - - if(settings->autoSuspend && !contextMenu()->isItemChecked(AUTOSUSPEND_MENU_ID)) { - if(settings->autoInactiveAction == "Suspend to Disk") { - return do_suspend2disk(); - } else if (settings->autoInactiveAction == "Suspend to RAM") { - return do_suspend2ram(); - } else if (settings->autoInactiveAction == "Standby") { - return do_standby(); - } else { - return false; - } - } else { - return false; - } - } else { - kdDebug() << "The autosuspend was chanceled (via the chancel dialog), start again." << endl; - setAutoSuspend(false); - return false; - } -} - -/*! - * \b TQT_SLOT to dimm the display down to the configured level if the signal - * \ref autodimm::inactivityTimeExpired was recieved. - * \param - * \return boolean with the result of the operation - * \retval true if successful - * \retval false else - */ -void kpowersave::do_downDimm() { - kdDebugFuncIn(trace); - - if (hwinfo->supportBrightness()) { - if (!AUTODIMM_Timer->isActive()) { - int dimmToLevel = (int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->autoDimmTo/100.0)); - - // check if we really need to dimm down - if (dimmToLevel < hwinfo->getCurrentBrightnessLevel()) { - int steps = hwinfo->getCurrentBrightnessLevel() - dimmToLevel; - int timePerStep = (1500 / steps); - - autoDimmDown = true; - - AUTODIMM_Timer = new TQTimer(this); - connect(AUTODIMM_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_dimm())); - AUTODIMM_Timer->start(timePerStep, false); - } else { - kdWarning() << "Don't dimm down, current level is already lower than requested Level" << endl; - } - } else { - // wait until the timer is stopped, try later! - TQTimer::singleShot(1500, this, TQT_SLOT(do_downDimm())); - } - } - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT to dimm the display up to the configured level if the signal - * \ref autodimm::UserIsActiveAgain was recieved. - * \param - * \return boolean with the result of the operation - * \retval true if successful - * \retval false else - */ -void kpowersave::do_upDimm() { - kdDebugFuncIn(trace); - - //NOTE we go back to the value of the scheme and not the last on, to reduce trouble with the scheme - - if (hwinfo->supportBrightness()) { - if (!AUTODIMM_Timer->isActive()) { - int dimmToLevel = (int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->brightnessValue/100.0)); - - // check if we really need to dimm up - if (dimmToLevel > hwinfo->getCurrentBrightnessLevel()) { - int steps = dimmToLevel - hwinfo->getCurrentBrightnessLevel(); - int timePerStep = (750 / steps); - - autoDimmDown = false; - - AUTODIMM_Timer = new TQTimer(this); - connect(AUTODIMM_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_dimm())); - AUTODIMM_Timer->start(timePerStep, false); - - // start autodimm again - setAutoDimm(false); - } else { - kdWarning() << "Don't dimm up, current level is already above requested Level" << endl; - } - } else { - // wait until the timer is stopped, try later! - TQTimer::singleShot(750, this, TQT_SLOT(do_downDimm())); - } - } - - kdDebugFuncOut(trace); -} - - -/*! - * \b TQT_SLOT to dimm the display down - * \return boolean with the result of the operation - * \retval true if successful - * \retval false else - */ -void kpowersave::do_dimm() { - kdDebugFuncIn(trace); - - int current = hwinfo->getCurrentBrightnessLevel(); - - if (autoDimmDown) { - // dimm the display down - if (current > 0 && - current > ((int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->autoDimmTo/100.0))-1)) { - hwinfo->setBrightness((current -1) , -1); - } else { - AUTODIMM_Timer->stop(); - - // start checking if the user get active again - // NOTE: we start this here because the X-Server detect brightness changes as - // User activity --> FUCKING STUPID PIECE OF SHIT - autoDimm->startCheckForActivity(); - } - } else { - // dimm the display up - if (current < ((int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->brightnessValue/100.0))-1)) { - hwinfo->setBrightness((current +1) , -1); - } else { - AUTODIMM_Timer->stop(); - } - } - - kdDebugFuncOut(trace); -} - -/*! - * Function handle umount/remount external storage media before/after - * suspend. - * \param suspend boolean with info if the machine go into suspend or not - * \return result of the operation - * \retval true if all was successful - * \retval false if not - */ -bool kpowersave::handleMounts( bool suspend ) { - if (trace) kdDebug() << funcinfo << "IN: " << "called suspend: " << suspend << endl; - - bool _ret = false; - TQString _errormsg; - - if (settings->unmountExternalOnSuspend) { - TQString _method; - DCOPRef dcop_ref = DCOPRef( "kded", "mediamanager" ); - - if (suspend) { - _method = "unmountAllSuspend()"; - } else { - _method = "remountAllResume()"; - } - DCOPReply reply = dcop_ref.call(_method.latin1()); - if ( reply.isValid() ) { - reply.get(_errormsg); - if (_errormsg.isEmpty()) { - kdDebugFuncOut(trace); - return true; - } else { - kdError() << "ERROR while umount/remount partitions: " << _errormsg << endl; - } - } else { - kdWarning() << "Could not umount external storage partitions." << endl; - } - - } else { - kdDebugFuncOut(trace); - return true; - } - - // this is only needed for suspend case and an error ... - // on resume a simple error msg should be enough - if (!_ret && suspend) { - // handle error case - TQString _msg; - TQString _e_msg; - TQString _suspend; - - if (!_errormsg.isEmpty()) { - _e_msg = _errormsg; - } else { - _e_msg = i18n("Could not call DCOP interface to umount external media."); - } - - // ugly: need qt-tags because mediamanager can return html formated strings !!! - _msg = "" + - i18n("Could not umount external media before suspend/standby. \n " - "(Reason: %1)\n \n Would you like to continue suspend/standby " - "anyway? \n(Warning: Continue suspend can cause data loss!)").arg(_e_msg) + - ""; - - _suspend = getSuspendString(calledSuspend); - - int answer = KMessageBox::questionYesNo( 0, _msg, - i18n("Error while prepare %1").arg(_suspend), - i18n("Suspend anyway"), i18n("Cancel suspend"), - "ignoreMountOnSuspend"); - - if (answer == KMessageBox::Yes) { - _ret = true; - } - } - - kdDebugFuncOut(trace); - return _ret; -} - -/*! - * Handle the event for the power button and call the related action. - */ -void kpowersave::handlePowerButtonEvent( ) { - kdDebugFuncIn(trace); - - /* Only go to suspend on button event if we already resumed successful. - This should solve problems if we get may a event for the powerbutton - if there machine was waked up via power button. */ - if (calledSuspend == -1) { - handleActionCall(settings->powerButtonAction, settings->powerButtonActionValue); - } - - kdDebugFuncOut(trace); -} - -/*! - * Handle the event for the suspend2ram/sleep button and call the related action. - */ -void kpowersave::handleSleepButtonEvent() { - kdDebugFuncIn(trace); - - // Only go to suspend on button event if we already resumed successful. - if (calledSuspend == -1) { - handleActionCall(settings->sleepButtonAction, -1); - } - - kdDebugFuncOut(trace); -} - -/*! - * Handle the event for the suspend2disk (hibernater) button and call the related action. - */ -void kpowersave::handleS2DiskButtonEvent(){ - kdDebugFuncIn(trace); - - // Only go to suspend on button event if we already resumed successful. - if (calledSuspend == -1) { - handleActionCall(settings->s2diskButtonAction, -1); - } - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT to handle the lidclose event. If the screen get locked - * depends on the user specific settings. - * \param closed boolean with info if the lid is closed or not - */ -void kpowersave::handleLidEvent( bool closed ){ - if (trace) kdDebug() << funcinfo << "IN: " << "Lid closed? " << closed << endl; - - if (closed) { - // get new general settings! This could maybe removed if we - // could be shure, that the settings are actuall - settings->load_general_settings(); - - // handle screen lock - if (settings->lidcloseAction < 0) { - if(settings->lockOnLidClose) { - if(!display->lockScreen( settings->lockmethod )) { - KPassivePopup::message( i18n("WARNING"), - i18n("Could not lock the screen. There may " - "be a problem with the selected \nlock " - "method or something else."), - SmallIcon("messagebox_warning", 20), this, - i18n("Warning").ascii(), 10000); - - } - } - if(settings->forceDpmsOffOnLidClose) { - display->forceDPMSOff(); - } - } else { - // handle lock action - if (hwinfo->currentSessionIsActive()) { - handleActionCall(settings->lidcloseAction, settings->lidcloseActionValue); - } else { - kdWarning() << "Session is not active, don't react on lidclose " - << "event with a action call (like e.g. Suspend)!" << endl; - } - } - - if(!settings->disableNotifications) - KNotifyClient::event( this->winId(), "lid_closed_event", i18n("The Lid was closed.")); - } else { - if(settings->forceDpmsOffOnLidClose) { - // reset the scheme settings to avoid problems related to call xset on lidclose - setSchemeSettings(); - } - - if (settings->lockOnLidClose) { - activateLoginScreen(); - } - - if(!settings->disableNotifications) - KNotifyClient::event( this->winId(), "lid_opened_event", i18n("The Lid was opened.")); - } - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT to show the login dialog if the desktop was locked before the suspend. - */ -void kpowersave::activateLoginScreen(){ - kdDebugFuncIn(trace); - - // get new general settings! This could maybe removed if we - // could be shure, that the settings are actuall - settings->load_general_settings(); - - if(settings->timeToFakeKeyAfterLock >= 0) { - TQTimer::singleShot(settings->timeToFakeKeyAfterLock, display, TQT_SLOT(fakeShiftKeyEvent())); - } - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT to set the current suspend type for later use. - */ -void kpowersave::setSuspendType( TQString suspendtype){ - kdDebugFuncIn(trace); - - suspendType = suspendtype; - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT which called if kpowersave is exited by the user. In this case the user - * is asked through a yes/no box if "KPowersave start automatically on log in" and the - * result is written to the KDE configfile. - */ -void kpowersave::_quit (){ - kdDebugFuncIn(trace); - - // set the KDE-Settings back to user default - if(getenv("TDE_FULL_SESSION")) { - // first try to call the KDE method via DCOP to reset, if not fall back - if (!display->resetKDEScreensaver()) { - settings->load_kde(); - // reset to KDE screensaver settings - display->blankOnlyScreen(false); - if(!settings->kde->enabled) display->setScreenSaver(false); - else display->setScreenSaver(true); - - if(!settings->kde->displayEnergySaving) display->setDPMS(false); - else display->setDPMS(true); - - display->has_DPMS = display->setDPMSTimeouts( settings->kde->displayStandby, - settings->kde->displaySuspend, - settings->kde->displayPowerOff); - } - } - - // set, if this is a GNOME session, XScreensaver settings back to user default - TQString session = getenv("DESKTOP_SESSION"); - if(session.startsWith("gnome")) { - display->resetXScreensaver(); - } - - if(!settings->autostartNeverAsk) { - TQString tmp1 = i18n ("Start KPowersave automatically when you log in?"); - int tmp2 = KMessageBox::questionYesNo ( 0, tmp1, i18n("Question"), - i18n("Start Automatically"), i18n("Do Not Start")); - config->setGroup("General"); - config->writeEntry ("Autostart", tmp2 == KMessageBox::Yes); - config->sync (); - } - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT called if the user select a 'CPU Frequency Policy' from the menu ( \ref CPUFRETQ_MENU_ID ). - */ -void kpowersave::do_setSpeedPolicy(int menu_id){ - if (trace) kdDebug() << funcinfo << "IN: " << "menu_id/set policy to: " << menu_id << endl; - - if(!hwinfo->setCPUFreq((cpufreq_type)menu_id, settings->cpuFreqDynamicPerformance)) { - KPassivePopup::message(i18n("WARNING"), - i18n("CPU Freq Policy %1 could not be set.").arg(speed_menu->text(menu_id)), - SmallIcon("messagebox_warning", 20), this, i18n("Warning").ascii(), 10000); - } else { - hwinfo->checkCurrentCPUFreqPolicy(); - update(); - } - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT called if the user select a scheme from the menu. If there is any errormessage - * while try to set the selected scheme, the user get a messagebox with info. - */ -void kpowersave::do_setActiveScheme( int i ){ - if (trace) kdDebug() << funcinfo << "IN: " << "set scheme to: " << i << endl; - - if(!settings->schemes[i].isEmpty() && (settings->schemes[i] != settings->currentScheme)) { - for (int x = 0; x < (int) scheme_menu->count(); x++){ - if (x == i) - scheme_menu->setItemChecked(x, true); - else - scheme_menu->setItemChecked(x, false); - } - settings->load_scheme_settings( settings->schemes[i]); - setSchemeSettings(); - notifySchemeSwitch(); - } else if (!settings->schemes[i]){ - KPassivePopup::message( i18n("WARNING"), - i18n("Scheme %1 could not be activated.").arg(scheme_menu->text(i)), - SmallIcon("messagebox_warning", 20), this, i18n("Warning").ascii(), 5000); - } - - kdDebugFuncOut(trace); -} - -/*! - * This function is invoked if something has to be updated. This including also menu entries. - * If the battery is in warning state (and powersave set pdaemon->send_battery_state_change_message) - * the function pop-up a messagebox. - */ -void kpowersave::update(){ - kdDebugFuncIn(trace); - - int redraw_pixmap = 0; - TQString justMins; - - /* need to redraw pixmap in toolbar */ - if (hwinfo->update_info_ac_changed){ - redraw_pixmap = 1; - } - if (!hwinfo->isOnline()){ - this->contextMenu()->setItemVisible(SUSPEND2DISK_MENU_ID, false); - this->contextMenu()->setItemVisible(SUSPEND2RAM_MENU_ID, false); - this->contextMenu()->setItemVisible(STANDBY_MENU_ID, false); - this->contextMenu()->setItemVisible(SLEEP_SEPARATOR_MENU_ID, false); - this->contextMenu()->setItemVisible(SCHEME_SEPARATOR_MENU_ID, false); - this->contextMenu()->setItemVisible(SCHEME_MENU_ID, false); - this->contextMenu()->setItemVisible(HELP_SEPARATOR_MENU_ID, false); - this->contextMenu()->setItemVisible(CONFIGURE_ID, false); - this->contextMenu()->setItemVisible(CONFIGURE_EVENTS_ID, false); - if (!pixmap_name.startsWith("ERROR")) { - // dirty !!! but this work for the moment - hwinfo->update_info_cpufreq_policy_changed = true; - suspend = hwinfo->getSuspendSupport(); - redraw_pixmap = 1; - } - } - else{ - if (pixmap_name.startsWith("ERROR")) { - redraw_pixmap = 1; - hwinfo->update_info_cpufreq_policy_changed = true; - suspend = hwinfo->getSuspendSupport(); - } - this->contextMenu()->setItemVisible(SUSPEND2DISK_MENU_ID, true); - this->contextMenu()->setItemVisible(SUSPEND2RAM_MENU_ID, true); - this->contextMenu()->setItemVisible(STANDBY_MENU_ID, true); - this->contextMenu()->setItemVisible(SLEEP_SEPARATOR_MENU_ID, true); - this->contextMenu()->setItemVisible(SCHEME_SEPARATOR_MENU_ID, true); - this->contextMenu()->setItemVisible(SCHEME_MENU_ID, true); - this->contextMenu()->setItemVisible(HELP_SEPARATOR_MENU_ID, true); - this->contextMenu()->setItemVisible(CONFIGURE_ID, true); - this->contextMenu()->setItemVisible(CONFIGURE_EVENTS_ID, true); - - if (suspend.suspend2disk && (suspend.suspend2disk_allowed || - suspend.suspend2disk_allowed == -1)) { - this->contextMenu()->setItemEnabled(SUSPEND2DISK_MENU_ID, true); - } else { - if (!suspend.suspend2disk) - this->contextMenu()->setItemVisible(SUSPEND2DISK_MENU_ID, false); - else - this->contextMenu()->setItemEnabled(SUSPEND2DISK_MENU_ID, false); - } - - if (suspend.suspend2ram && (suspend.suspend2ram_allowed || - suspend.suspend2ram_allowed == -1)) { - this->contextMenu()->setItemEnabled(SUSPEND2RAM_MENU_ID, true); - } else { - if (!suspend.suspend2ram) - this->contextMenu()->setItemVisible(SUSPEND2RAM_MENU_ID, false); - else - this->contextMenu()->setItemEnabled(SUSPEND2RAM_MENU_ID, false); - } - - if (suspend.standby && (suspend.standby_allowed || suspend.standby_allowed == -1)) { - this->contextMenu()->setItemEnabled(STANDBY_MENU_ID, true); - } else { - if (!suspend.standby) - this->contextMenu()->setItemVisible(STANDBY_MENU_ID, false); - else - this->contextMenu()->setItemEnabled(STANDBY_MENU_ID, false); - } - } - - if (hwinfo->update_info_cpufreq_policy_changed == true){ - updateCPUFreqMenu(); - } - - BatteryCollection *primary = hwinfo->getPrimaryBatteries(); - - if (hwinfo->update_info_primBattery_changed == true){ - justMins.setNum(primary->getRemainingMinutes() % 60); - justMins = justMins.rightJustify(2, '0'); - - redraw_pixmap = 1; - hwinfo->update_info_primBattery_changed = false; - } - - updateSchemeMenu(); - - if (redraw_pixmap){ - redrawPixmap(); - } - - kdDebugFuncOut(trace); -} - -/*! - * This function is involved if the CPUFreqMenu must be updated. - */ -void kpowersave::updateCPUFreqMenu(){ - kdDebugFuncIn(trace); - - if (hwinfo->supportCPUFreq() && hwinfo->isOnline() && hwinfo->isCpuFreqAllowed()) { - /* set CPU frequency menu entries *********/ - /* speed menu has id 3 in context menu */ - contextMenu()->setItemVisible(CPUFRETQ_MENU_ID, true); - contextMenu()->setItemEnabled(CPUFRETQ_MENU_ID, true); - contextMenu()->setItemVisible(CPUFRETQ_SEPARATOR_MENU_ID, true); - - switch (hwinfo->getCurrentCPUFreqPolicy()){ - case PERFORMANCE: - speed_menu->setItemChecked(PERFORMANCE, true); - speed_menu->setItemChecked(DYNAMIC, false); - speed_menu->setItemChecked(POWERSAVE, false); - break; - case DYNAMIC: - speed_menu->setItemChecked(PERFORMANCE, false); - speed_menu->setItemChecked(DYNAMIC, true); - speed_menu->setItemChecked(POWERSAVE, false); - break; - case POWERSAVE: - speed_menu->setItemChecked(PERFORMANCE, false); - speed_menu->setItemChecked(DYNAMIC, false); - speed_menu->setItemChecked(POWERSAVE, true); - break; - } - } else { - /* there never were policies */ - if (!speed_menu) { - return ; - } else if (hwinfo->supportCPUFreq() && (hwinfo->isCpuFreqAllowed() != 1)) { - contextMenu()->setItemEnabled(CPUFRETQ_MENU_ID, false); - contextMenu()->setItemVisible(CPUFRETQ_SEPARATOR_MENU_ID, true); - } else{ - /* there were CPU freq policies, but they are not accessible any more */ - /* delete speed_menu */ - contextMenu()->setItemVisible(CPUFRETQ_MENU_ID, false); - contextMenu()->setItemVisible(CPUFRETQ_SEPARATOR_MENU_ID, false); - } - } - - hwinfo->update_info_cpufreq_policy_changed = false; - - kdDebugFuncOut(trace); -} - -/*! - * The function used to update the scheme menu. A update is needed if - * if there is maybe new schemes or if the current scheme changed or switched - * By this way also set the settings for screensaver and other parameter - * related to the selected scheme. - */ -void kpowersave::updateSchemeMenu(){ - kdDebugFuncIn(trace); - - if (settings->schemes.count() == 0 || !hwinfo->isOnline()){ - /* there never were schemes */ - if (!scheme_menu) - return ; - else{ - /* there were schemes, but they are not accessible any more */ - /* delete scheme_menu */ - scheme_menu->clear(); - contextMenu()->setItemVisible(SCHEME_MENU_ID, false); - contextMenu()->setItemVisible(SCHEME_SEPARATOR_MENU_ID, false); - return ; - } - } - - /* redraw all scheme entries ... */ - scheme_menu->clear(); - // clear the list of real scheme names - org_schemenames.clear(); - - org_schemenames = settings->schemes; - - int x = 0; - for ( TQStringList::iterator it = org_schemenames.begin(); it != org_schemenames.end(); ++it ) { - - TQString _t = *it; - - if ( *it == settings->ac_scheme ){ - scheme_menu->insertItem( SmallIcon("scheme_power", TQIconSet::Automatic), - i18n( ((TQString)*it).ascii() ), x, x); - } - else{ - if ( *it == settings->battery_scheme ){ - scheme_menu->insertItem(SmallIcon("scheme_powersave", TQIconSet::Automatic), - i18n( (*it).ascii() ), x, x); - } - else{ - if ((TQString)*it == "Acoustic"){ - scheme_menu->insertItem(SmallIcon("scheme_acoustic", - TQIconSet::Automatic), - i18n("Acoustic"), x, x); - } - else if ((TQString)*it == "Presentation"){ - scheme_menu->insertItem(SmallIcon("scheme_presentation", - TQIconSet::Automatic), - i18n("Presentation"), x, x); - - } - else if((TQString)*it == "AdvancedPowersave") { - scheme_menu->insertItem(SmallIcon("scheme_advanced_powersave", - TQIconSet::Automatic), - i18n( "Advanced Powersave" ), x, x); - } - else { - scheme_menu->insertItem(i18n( (*it).ascii() ), x, x); - } - } - } - - if ( *it == settings->currentScheme ) { - scheme_menu->setItemChecked(x, true); - } - ++x; - } - - if (x == 0 && scheme_menu){ - // this should not happen, scheme_list should have been NULL before - // now we'd have an empty menu ... - } - else{ - contextMenu()->setItemVisible(SCHEME_MENU_ID, true); - contextMenu()->setItemVisible(SCHEME_SEPARATOR_MENU_ID, true); - } - - kdDebugFuncOut(trace); -} - - -/*! - * Reimplemented eventhandler for mouse enterEvent. This is called if the mouse cursor - * enters the widget. In this case if the user move the mouse cursor over the kpowersave - * trayicon. \n \n - * We use this event to update the Tooltip with all needed information. The time beetween - * the event and the automatically popup of the TQToolTip should be long enought to collect - * the needed values and add a updated Tooltip. - */ -void kpowersave::enterEvent( TQEvent */*qee*/ ){ - - updateTooltip(); - -} - -/*! - * Event handler for mouse wheel events. If the system supports changing display - * brightness and changing brightness is enabled in the current scheme settings, - * this will raise the brightness by one level for wheel up events and lower the - * brightness by one level for wheel down events. - */ -void kpowersave::wheelEvent (TQWheelEvent *qwe) -{ - kdDebugFuncIn(trace); - - if (!hwinfo->supportBrightness() && settings->brightness) - return; - - if (qwe->orientation () == Qt::Vertical) { - if (qwe->delta() > 0) { - do_brightnessUp(5); - } else { - do_brightnessDown(5); - } - } - - kdDebugFuncOut(trace); -} - -/*! - * Reimplemented eventhandler for mousePressEvents which is involved if the user click - * on the icon on the kickerapplet. This was written to guarantee that a click with the - * right and the left mousebutton activate the menu. In the future this can also used - * to popup maybe a other menu. - */ -void kpowersave::mousePressEvent(TQMouseEvent *qme){ - kdDebugFuncIn(trace); - - KSystemTray::mousePressEvent(qme); - if (hwinfo->isOnline()) { - if (qme->button() == Qt::RightButton){ - // TODO check if maybe some rechecks needed - this->contextMenu()->exec(TQCursor::pos()); - } else if (qme->button() == Qt::LeftButton) { - showDetailedDialog(); - } - } - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT called if the detaileddialog is closed. With this we prevent open - * the dialog twice, use this function to reset the used variables. - */ -void kpowersave::closedetaileddialog() { - detailedIsShown = false; -} - -/*! - * \b TQT_SLOT used to display messeges in kpowersave. This function - * block all messeges which we have in kpowersave! - */ -void kpowersave::showErrorMessage( TQString msg ){ - kdDebugFuncIn(trace); - - if(settings->psMsgAsPassivePopup) { - KPassivePopup::message("KPowersave", msg, SmallIcon("messagebox_warning", 20), - this, i18n("Warning").ascii(), 10000); - } else { - kapp->updateUserTimestamp(); - // KMessageBox::error( 0, msg); - KMessageBox::queuedMessageBox(0, KMessageBox::Error, msg); - } - - kdDebugFuncOut(trace); -} - - -/*! - * Use this function to set the SchemeSettings. This function currently set the - * e.g. the screensaver and dpms settings. Don't forget to call this function if - * a scheme is changed or if the settings changed. - */ -void kpowersave::setSchemeSettings(){ - kdDebugFuncIn(trace); - - // --> check if there is a scheme set, if not, use defaults - if ( settings->currentScheme.isEmpty()) { - if (hwinfo->getAcAdapter()) { - settings->load_scheme_settings( settings->ac_scheme); - } else { - settings->load_scheme_settings( settings->battery_scheme); - } - } - - // call setPowerSave() depending on AC state - if (settings->callSetPowerSaveOnAC) { - if (hwinfo->getAcAdapter()) - hwinfo->setPowerSave(false); - else - hwinfo->setPowerSave(true); - } - - // --> set autosuspend settings - if(settings->autoSuspend) { - setAutoSuspend(false); - } else { - this->contextMenu()->setItemVisible(AUTOSUSPEND_MENU_ID, false); - this->contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, false); - this->contextMenu()->setItemVisible(AUTOSUSPEND_SEPARATOR_MENU_ID, false); - autoSuspend->stop(); - } - - // --> set autodimm settings - if (settings->autoDimm) { - setAutoDimm(true); - } else { - autoDimm->stop(); - } - - // --> set screensaver - if(settings->specSsSettings){ - if(settings->disableSs) display->setScreenSaver(false); - else { - display->setScreenSaver(true); - if(settings->blankSs) display->blankOnlyScreen(true); - else { - display->blankOnlyScreen(false); - } - } - - } // TODO: check if this really work !!! - else if(getenv("TDE_FULL_SESSION")) { - // try to reset the complete screensaver settings. Ff this fail, use own methodes - if (!display->resetKDEScreensaver()) { - settings->load_kde(); - // Always disable blankOnly screensaver setting (default). KDE does - // not provide a GUI to configure it and most likely we are the - // only ones messing with it - display->blankOnlyScreen(false); - - // reset to global screensaver settings - if(!settings->kde->enabled) display->setScreenSaver(false); - else { - display->setScreenSaver(true); - // What should we do with settings->kde->lock ? - // Maybe nothing ?! - } - } - } else if ((getenv("DESKTOP_SESSION") != NULL) && !strcmp(getenv("DESKTOP_SESSION"), "gnome")) { - // use this to set XScreensaver back to default settings this should - // also cover the DPMS settings for GNOME/XScreensaver - display->resetXScreensaver(); - } - - // --> set DPMS settings - if(settings->specPMSettings){ - // set the new DPMS settings - if(settings->disableDPMS) { - display->setDPMS(false); - } - else { - display->setDPMS(true); - display->has_DPMS = display->setDPMSTimeouts( settings->standbyAfter, - settings->suspendAfter, - settings->powerOffAfter); - } - } - else if(getenv("TDE_FULL_SESSION")){ - // try to reset the KDE screensaver/DPMS settings (if there are also - // no special screensaver settings) otherwise fall back and set values from files - if (!settings->specSsSettings && !display->resetKDEScreensaver()) { - settings->load_kde(); - // reset to global screensaver settings - if(!settings->kde->displayEnergySaving) { - display->setDPMS(false); - } - else { - display->setDPMS(true); - display->has_DPMS = display->setDPMSTimeouts( settings->kde->displayStandby, - settings->kde->displaySuspend, - settings->kde->displayPowerOff); - } - } - } - - // --> set brightness settings - if(settings->brightness && hwinfo->supportBrightness()) { - // set to given values - hwinfo->setBrightness (-1, settings->brightnessValue); - } - - // --> set CPU Freq settings - if(hwinfo->supportCPUFreq()) { - hwinfo->setCPUFreq( settings->cpuFreqPolicy, settings->cpuFreqDynamicPerformance); - } - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT which called to set and start the autosuspend monitoring. - * \param resumed boolean value which represent information if machine - * currently back from suspend/standby - */ -void kpowersave::setAutoSuspend( bool resumed ){ - if (trace) kdDebug() << funcinfo << "IN: " << "resumed? " << resumed << endl; - - if(settings->autoInactiveActionAfter > 0 && settings->autoSuspend) { - int autoInactiveActionAfter = 0; - - if( settings->autoInactiveAction.startsWith("_NONE_")) { - autoSuspend->stop(); - return; - } - if (resumed) { - autoSuspend->stop(); - delete autoSuspend; - autoSuspend = new autosuspend(); - connect(autoSuspend, TQT_SIGNAL(inactivityTimeExpired()), this, - TQT_SLOT(do_autosuspendWarn())); - } - - if (settings->autoSuspendCountdown && (settings->autoSuspendCountdownTimeout > 0)) { - autoInactiveActionAfter = ((settings->autoInactiveActionAfter * 60) - - settings->autoSuspendCountdownTimeout); - } else { - autoInactiveActionAfter = settings->autoInactiveActionAfter * 60; - } - - if(settings->autoInactiveSBlistEnabled) { - autoSuspend->start( autoInactiveActionAfter, settings->autoInactiveSBlist ); - } - else { - autoSuspend->start( autoInactiveActionAfter, settings->autoInactiveGBlist ); - } - this->contextMenu()->setItemVisible(AUTOSUSPEND_SEPARATOR_MENU_ID, true); - this->contextMenu()->setItemVisible(AUTOSUSPEND_MENU_ID, true); - } - else { - // if autosuspend is not NULL: stop autosuspend - if (autoSuspend) { - autoSuspend->stop(); - } - - this->contextMenu()->setItemVisible(AUTOSUSPEND_MENU_ID, false); - this->contextMenu()->setItemVisible(AUTOSUSPEND_SEPARATOR_MENU_ID, false); - } - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT which called to set and start the autodimm monitoring. - * \param resumed boolean value which represent information if machine - * currently back from suspend/standby - */ -void kpowersave::setAutoDimm( bool resumed ){ - if (trace) kdDebug() << funcinfo << "IN: " << "resumed? " << resumed << endl; - - if(settings->autoDimmAfter > 0 && settings->autoDimm) { - if(settings->autoDimmTo < 0) { - autoDimm->stop(); - kdWarning() << "Not allowed or set level for dimm" << endl; - } else { - if (resumed) { - // setup again - autoDimm->stop(); - delete autoDimm; - autoDimm = new autodimm(); - connect(autoDimm, TQT_SIGNAL(inactivityTimeExpired()), this, TQT_SLOT(do_downDimm())); - connect(autoDimm, TQT_SIGNAL(UserIsActiveAgain()), this, TQT_SLOT(do_upDimm())); - } - - if (settings->autoDimmSBlistEnabled) { - autoDimm->start(settings->autoDimmAfter * 60, settings->autoDimmSBlist); - } else { - autoDimm->start(settings->autoDimmAfter * 60, settings->autoDimmGBlist); - } - } - } else { - if (autoDimm) - autoDimm->stop(); - } - - kdDebugFuncOut(trace); -} - -// -------- start KNotify functions ------------- // - -/*! - * \b TQT_SLOT called if a battery warning state reached and related signal recieved. - * Here we emit the related KNotify event, if not disabled. - * \param type integer with the type of the battery - * \param state integer represent the reached battery state - */ -void kpowersave::notifyBatteryStatusChange ( int type, int state ) { - if (trace) kdDebug() << funcinfo << "IN: " << "type: " << type << "state: " << state << endl; - - - if (type == BAT_PRIMARY) { - BatteryCollection *primary = hwinfo->getPrimaryBatteries(); - int min = primary->getRemainingMinutes(); - - if (primary->getChargingState() == CHARGING) { - kdDebug() << "kpowersave::notifyBatteryStatusChange: Battery is charging, ignore event" << endl; - return; - } - if (hwinfo->getAcAdapter()) { - // the machine is on AC, no need to inform about battery state, - // this is maybe only a race condition with not directly actuall - // charge state - kdDebug() << "kpowersave::notifyBatteryStatusChange: Machine is on AC, ignore event" << endl; - kdDebugFuncOut(trace); - return; - } - - switch (state) { - case BAT_WARN: - if (!settings->disableNotifications) - KNotifyClient::event(this->winId(), "battery_warning_event", - i18n("Battery state changed to WARNING -- remaining time: " - "%1 hours and %2 minutes.").arg(min/60).arg(min%60)); - // set/call related actions - handleActionCall(settings->batteryWarningLevelAction, - settings->batteryWarningLevelActionValue); - break; - case BAT_LOW: - if (!settings->disableNotifications) - KNotifyClient::event(this->winId(), "battery_low_event", - i18n("Battery state changed to LOW -- remaining time: " - "%1 hours and %2 minutes.").arg(min/60).arg(min%60)); - // set/call related actions - handleActionCall(settings->batteryLowLevelAction, - settings->batteryLowLevelActionValue); - break; - case BAT_CRIT: - // handle carefully: - if (settings->batteryCriticalLevelAction == GO_SHUTDOWN) { - if (!settings->disableNotifications) - KNotifyClient::event(this->winId(), "battery_critical_event", - i18n("Battery state changed to CRITICAL -- " - "remaining time: %1 hours and %2 minutes.\n" - "Shut down your system or plug in the power " - "cable immediately. Otherwise the machine\n" - "will go shutdown in 30 seconds") - .arg(min/ 60).arg(min%60)); - - TQTimer::singleShot(30000, this, TQT_SLOT(handleCriticalBatteryActionCall())); - } else { - if (!settings->disableNotifications) - KNotifyClient::event(this->winId(), "battery_critical_event", - i18n("Battery state changed to CRITICAL -- " - "remaining time: %1 hours and %2 minutes.\n" - "Shut down your system or plug in the power " - "cable immediately.") - .arg(min/ 60).arg(min%60)); - - handleActionCall(settings->batteryCriticalLevelAction, - settings->batteryCriticalLevelActionValue); - } - break; - default: - break; - } - } else { - // TODO: add some code later for the other batteries - } - - kdDebugFuncOut(trace); -} - - -/*! - * Function to call the action for battery critical event. This is ugly, but - * because of TQTimer::singleShot() can't take param ... - * NOTE: Use this only for SHUTDOWN atm - */ -void kpowersave::handleCriticalBatteryActionCall () { - kdDebugFuncIn(trace); - - handleActionCall(GO_SHUTDOWN, settings->batteryCriticalLevelActionValue, true, true); - - kdDebugFuncOut(trace); -} - -/*! - * Function to set a special action for a battery warning level. - * \param action integer with the type of the action from \ref action - * \param value integer value of the action as e.g. a brightness level - * \param checkAC bool if there should be a check for AC state befor call the action - */ -void kpowersave::handleActionCall ( action action, int value , bool checkAC, bool batWarnCall ) { - if (trace) kdDebug() << funcinfo << "IN: " << "action: " << action << "value: " << value - << "checkAC: " << checkAC << endl; - - if (hwinfo->currentSessionIsActive()) { - switch (action) { - case GO_SHUTDOWN: - // to be shure if we really need the shutdown - if ((checkAC && !hwinfo->getAcAdapter()) || !checkAC ) { - DCOPRef shutdown = DCOPRef( "ksmserver", "ksmserver" ); - shutdown.send("logout", 0, 2, 2); - } - break; - case LOGOUT_DIALOG: - { - DCOPRef shutdown = DCOPRef( "ksmserver", "ksmserver" ); - shutdown.send("logout", 1, 2, 2); - } - break; - case GO_SUSPEND2RAM: - TQTimer::singleShot(100, this, TQT_SLOT(do_suspend2ram())); - break; - case GO_SUSPEND2DISK: - TQTimer::singleShot(100, this, TQT_SLOT(do_suspend2disk())); - break; - case BRIGHTNESS: - hwinfo->setBrightness( -1, value ); - break; - case CPUFRETQ_POWERSAVE: - hwinfo->setCPUFreq( POWERSAVE ); - break; - case CPUFRETQ_DYNAMIC: - hwinfo->setCPUFreq( DYNAMIC, settings->cpuFreqDynamicPerformance ); - break; - case CPUFRETQ_PERFORMANCE: - hwinfo->setCPUFreq( PERFORMANCE ); - break; - case SWITCH_SCHEME: // not supported atm - case UNKNOWN_ACTION: - case NONE: - default: - kdError() << "Could not set the requested Action: " << action << endl; - break; - } - } else if (batWarnCall) { - if (!hwinfo->isPolicyPowerIfaceOwned()) { - switch (action) { - case GO_SHUTDOWN: - // to be shure if we really need the shutdown - if ((checkAC && !hwinfo->getAcAdapter()) || !checkAC ) { - DCOPRef shutdown = DCOPRef( "ksmserver", "ksmserver" ); - shutdown.send("logout", 0, 2, 2); - } - break; - default: - kdError() << "Could not call requested action, inactive session: " << action << endl; - break; - } - } - } else { - kdError() << "Could not set the requested action, session is inactiv: " << action << endl; - } - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT called if ac stated changed. Here we emit the related KNotify event. - * and switch to the AC/battery scheme depending on the state of AC - * \param acstate boolean represent the state of AC (true == AC plugged in ...) - */ -void kpowersave::handleACStatusChange ( bool acstate , bool notifyEvent ) { - if (trace) kdDebug() << funcinfo << "IN: " << "acstate: " << acstate << "notifyEvent: " << notifyEvent << endl; - - int index; - - if (hwinfo->currentSessionIsActive()) { - - // emit notify event - if(notifyEvent && !settings->disableNotifications) { - if (acstate) { - KNotifyClient::event(this->winId(), "plug_event", i18n("AC adapter plugged in")); - } else { - KNotifyClient::event(this->winId(), "unplug_event", i18n("AC adapter unplugged")); - } - } - - // handle switch to AC/battery default scheme - if (acstate) { - index = settings->schemes.findIndex(settings->ac_scheme); - } else { - index = settings->schemes.findIndex(settings->battery_scheme); - } - - if (index != -1) - do_setActiveScheme(index); - - // update applet - update(); - } - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT called if scheme switched. Here we emit the related KNotify events - * if they are not disabled. - */ -void kpowersave::notifySchemeSwitch() { - kdDebugFuncIn(trace); - - if(!settings->disableNotifications) { - TQString _scheme = settings->currentScheme; - TQString eventType; - - if( _scheme != "Performance" && _scheme != "Powersave" && _scheme != "Acoustic" && - _scheme != "Presentation" && _scheme != "AdvancedPowersave" ) - eventType = "scheme_Unknown"; - else - eventType = "scheme_" + _scheme; - - KNotifyClient::event( this->winId(), eventType, - i18n("Switched to scheme: %1").arg(i18n(_scheme.ascii())).ascii()); - } - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT called if the machine suspend. Here we emit the related KNotify events - * if they are not disabled. - */ -void kpowersave::notifySuspend( int suspendType ) { - kdDebugFuncIn(trace); - - if(!settings->disableNotifications) { - switch (suspendType) { - case SUSPEND2DISK: - KNotifyClient::event( this->winId(), "suspend2disk_event", - i18n("System is going into %1 now."). - arg(i18n("Suspend to Disk"))); - break; - case SUSPEND2RAM: - KNotifyClient::event( this->winId(), "suspend2ram_event", - i18n("System is going into %1 now."). - arg(i18n("Suspend to RAM"))); - break; - case STANDBY: - KNotifyClient::event( this->winId(), "standby_event", - i18n("System is going into %1 now."). - arg(i18n("Standby"))); - break; - default: - break; - } - } - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT called to independent handleResumeSignal() from event loop and - * to avoid problems with the QT3 D-Bus bindings - */ -void kpowersave::forwardResumeSignal( int result ) { - if (trace) kdDebug() << funcinfo << "IN: " << "result: " << result << endl; - - resume_result = result; - - TQTimer::singleShot(100, this, TQT_SLOT(handleResumeSignal())); - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT called if the machine suspend. Here we emit the related KNotify events - * if they are not disabled. - */ -void kpowersave::handleResumeSignal() { - kdDebugFuncIn(trace); - - // fake key to show the login dialog if we locked the screen - if(settings->lockOnSuspend) { - activateLoginScreen(); - } - - // reset autosuspend and autodimm - setAutoSuspend(true); - setAutoDimm(true); - - // reset the CPU Freq Policy ... for more see https://bugzilla.novell.com/show_bug.cgi?id=223164 - if(hwinfo->supportCPUFreq()) { - hwinfo->setCPUFreq( settings->cpuFreqPolicy, settings->cpuFreqDynamicPerformance ); - } - - if(!settings->disableNotifications) { - switch (calledSuspend) { - case SUSPEND2DISK: - KNotifyClient::event( this->winId(), "resume_from_suspend2disk_event", - i18n("System is resumed from %1.").arg( - i18n("Suspend to Disk"))); - break; - case SUSPEND2RAM: - KNotifyClient::event( this->winId(), "resume_from_suspend2ram_event", - i18n("System is resumed from %1.").arg( - i18n("Suspend to RAM"))); - break; - case STANDBY: - KNotifyClient::event( this->winId(), "resume_from_standby_event", - i18n("System is resumed from %1.").arg( - i18n("Standby"))); - break; - default: - kdError() << "called suspend type unknown" << endl; - break; - - } - } - - // handle result of the resume/suspend - // 1 is a valid return code; don't error out when it is received! - if ((resume_result == 0) || (resume_result == 1) || (resume_result == INT_MAX)) { - if ( resume_result == INT_MAX ) - kdWarning() << "Unknown if we successful resumed, look like a D-Bus timeout since " - << "elapsed time between suspend and resume is higher than 6 hours" << endl; - - // successful resumed ... remount only in this case - if (!handleMounts(false)) { - KPassivePopup::message( i18n("WARNING"), - i18n("Could not remount (all) external storage" - " media."), SmallIcon("messagebox_warning", 20), - this, i18n("Warning").ascii(), 15000); - } - } else { - kdError() << "Unknown error while suspend. Errorcode: " << resume_result << endl; - TQString msg; - - msg = i18n("An unknown error occurred while %1. The errorcode is: '%2'"). - arg(getSuspendString(calledSuspend)).arg(resume_result); - -#if defined(DISTRO_IS_SUSE) || defined(DISTRO_IS_SLES_SLED) || defined(DISTRO_IS_PARDUS) - // okay we know this system use pm-utils and log is under /var/log/pm-suspend.log - msg += "\n" + i18n("Do you want to have a look at the log file?"); - int answer = KMessageBox::questionYesNo(0, msg, i18n("Error while %1"). - arg(getSuspendString(calledSuspend))); - if (answer == KMessageBox::Yes) { - #if defined(DISTRO_IS_SLES_SLED) - switch (calledSuspend) { - case SUSPEND2DISK: - logview = new LogViewer ("/var/log/suspend2disk.log"); - logview->show(); - break; - case SUSPEND2RAM: - logview = new LogViewer ("/var/log/suspend2ram.log"); - logview->show(); - break; - case STANDBY: - logview = new LogViewer ("/var/log/standby.log"); - logview->show(); - break; - default: - break; - } - #else - logview = new LogViewer ("/var/log/pm-suspend.log"); - logview->show(); - #endif - } -#else - KMessageBox::error(0, msg, i18n("Error while %1").arg(getSuspendString(calledSuspend))); -#endif - } - // set back ... suspend is handled - calledSuspend = -1; - resume_result = 0; - - kdDebugFuncOut(trace); -} - -/*! - * \b TQT_SLOT called if the state of the current session change - * \param state boolean represent the state of the session - * TODO: fix scheme handling - * TODO: fix critical battery situations (see the todo file in the source) - */ -void kpowersave::handleSessionState (bool state) { - kdDebugFuncIn(trace); - - if (state) { - // session is active again - if (settings->autoSuspend) disableAutosuspend(false); - if (settings->autoDimm) setAutoDimm(false); - /* handle may missed/not set AC status changes while the - session was inactive and set them to the default schemes ?! */ - handleACStatusChange(hwinfo->getAcAdapter(), false); - - } else { - // session is now inactive - if (settings->autoSuspend) disableAutosuspend(true); - if (settings->autoDimm) autoDimm->stop(); - } - - kdDebugFuncOut(trace); -} - -// -------- end KNotify functions ------------- // -// ------------ helper functions -------------- // - -/*! - * Helper function to get a i18n name for a suspend type. - * \param type Integer value with the suspend type - * \return TQString with the translated name or NULL if it fail - */ -TQString kpowersave::getSuspendString (int type) { - kdDebugFuncIn(trace); - - switch (type) { - case SUSPEND2DISK: - return i18n("Suspend to Disk"); - break; - case SUSPEND2RAM: - return i18n("Suspend to RAM"); - break; - case STANDBY: - return i18n("Standby"); - break; - default: - return TQString(); - } - - kdDebugFuncOut(trace); -} - -// --------- end helper functions ------------- // -// ------------ DCOP functions ---------------- // - -/*! - * DCOP Interface funtion to lock the screen with the userdefined methode. - * \return boolean with the result of locking the screen - * \retval true if locking the screen was successful - * \retval false if locking the screen failed or the user don't wan't to lock - */ -bool kpowersave::lockScreen(){ - kdDebugFuncIn(trace); - - settings->load_general_settings(); - - return display->lockScreen( settings->lockmethod ); - - kdDebugFuncOut(trace); -} - -/*! - * DCOP Interface funtion to return the name of the current powersave scheme. - * \return TQString with the name of the current scheme - */ -TQString kpowersave::currentScheme (){ - kdDebugFuncIn(trace); - - if(hwinfo->isOnline()) { - return settings->currentScheme; - } else { - return "ERROR: D-Bus and/or HAL not running"; - } - - kdDebugFuncOut(trace); -} - -/*! - * DCOP Interface funtion to return the name of the current cpuFreqPolicy. - * \return TQString with the name of the current cpuFreqPolicy - */ -TQString kpowersave::currentCPUFreqPolicy() { - kdDebugFuncIn(trace); - - if(hwinfo->isOnline()) { - TQString _cpuFreq = ""; - switch (hwinfo->getCurrentCPUFreqPolicy()){ - case PERFORMANCE: - _cpuFreq = "PERFORMANCE"; - break; - case DYNAMIC: - _cpuFreq = "DYNAMIC"; - break; - case POWERSAVE: - _cpuFreq = "POWERSAVE"; - break; - default: - _cpuFreq = "UNKNOWN"; - break; - } - return _cpuFreq; - } else { - return "ERROR: HAL or/and DBus not running"; - } - - kdDebugFuncOut(trace); -} - -/*! - * DCOP Interface funtion to send a list with the allowed - * CPU Frequency states. - * \return TQStringList with the supported CPUFreq states - */ -TQStringList kpowersave::listCPUFreqPolicies() { - kdDebugFuncIn(trace); - - TQStringList ret_list; - if (hwinfo->isCpuFreqAllowed()) { - ret_list.append("PERFORMANCE"); - ret_list.append("DYNAMIC"); - ret_list.append("POWERSAVE"); - } - else { - ret_list.append("NOT SUPPORTED"); - } - - kdDebugFuncOut(trace); - return ret_list; -} - -/*! - * DCOP Interface funtion to set the current CPUFreq policy - * \param policy TQString with the policy to set, only values from - * list_CPUFreqPolicies are allowed (except "NOT SUPPORTED") - * \return boolean with the result of set the requested CPUFreq policy - * \retval true if successful set - * \retval false if not supported or any other failure - */ -bool kpowersave::do_setCPUFreqPolicy( TQString policy ) { - if (trace) kdDebug() << funcinfo << "IN: " << "policy: " << policy << endl; - - - bool ret = true; - /* - if (hwinfo->isCpuFreqAllowed() && hwinfo->isOnline()) { - if (policy == "PERFORMANCE") { - hwinfo->setCPUFreq(PERFORMANCE); - } else if (policy == "DYNAMIC") { - hwinfo->setCPUFreq(DYNAMIC, settings->cpuFreqDynamicPerformance); - } else if (policy == "POWERSAVE") { - hwinfo->setCPUFreq(POWERSAVE); - } else { - kdDebugFuncOut(trace); - ret = false; - } - } else { - ret = false; - } - */ - kdDebugFuncOut(trace); - return ret; -} - -/*! - * DCOP Interface funtion to send a list with the supported and enabled - * sleeping states. - * \return TQStringList with the supported spleeping states - */ -TQStringList kpowersave::allowed_sleepingStates(){ - kdDebugFuncIn(trace); - - TQStringList sleepList; - if(hwinfo->isOnline()) { - if (suspend.suspend2disk && (suspend.suspend2disk_allowed || - suspend.suspend2disk_allowed == -1)){ - sleepList.append("suspendToDisk"); - } - if (suspend.suspend2ram && (suspend.suspend2ram_allowed || - suspend.suspend2ram_allowed == -1)){ - sleepList.append("suspendToRAM"); - } - if (suspend.standby && (suspend.standby_allowed || suspend.standby_allowed == -1)){ - sleepList.append("standBy"); - } - if(sleepList.isEmpty()){ - sleepList.append("NO_SLEEPING_STATES_SUPPORTED"); - } - } - else { - sleepList.append("ERROR: D-Bus and/or HAL not running"); - } - - kdDebugFuncOut(trace); - return sleepList; -} - -/*! - * DCOP Interface funtion to send a list with the all schemes. - * \return TQStringList with all schemes - */ -TQStringList kpowersave::listSchemes(){ - kdDebugFuncIn(trace); - - TQStringList _schemeList; - if(hwinfo->isOnline()) { - if (settings->schemes.count() > 0){ - _schemeList = settings->schemes; - } - } - else { - _schemeList.append("ERROR: D-Bus and/or HAL not running"); - } - - kdDebugFuncOut(trace); - return _schemeList; -} - - -/*! - * DCOP Interface funtion to set the current scheme. - * \return boolean with the result of set the requested scheme - * \retval false if failed (e.g. scheme is not in the list) - * \retval true if scheme found and set - * \param _scheme TQString with the scheme to set, scheme should be - * named as list from list_schemes() - */ -bool kpowersave::do_setScheme( TQString /*_scheme*/ ) { - kdDebugFuncIn(trace); - -/* int index; - index = settings->schemes.findIndex(_scheme); - - if (index != -1) { - do_setActiveScheme(index); - kdDebugFuncOut(trace); - return true; - } - else { - kdDebugFuncOut(trace); - return false; - } -*/ - kdDebugFuncOut(trace); - return false; -} - -/*! - * DCOP Interface funtion to send the suspend to disk command to powersave. - * \return boolean with the result of calling do_suspend2disk() - * \retval true if successful - * \retval false if not supported or powersaved not running - */ -bool kpowersave::do_suspendToDisk(){ - kdDebugFuncIn(trace); - kdDebugFuncOut(trace); - return do_suspend2disk(); -} - -/*! - * DCOP Interface funtion to send the suspend to disk command to powersave. - * \return boolean with the result of calling do_suspend2ram() - * \retval true if successful - * \retval false if not supported or powersaved not running - */ -bool kpowersave::do_suspendToRAM(){ - kdDebugFuncIn(trace); - kdDebugFuncOut(trace); - return do_suspend2ram(); -} - -/*! - * DCOP Interface funtion to send the suspend to disk command to powersave. - * \return boolean with the result of calling do_standby() - * \retval true if successful - * \retval false if not supported or powersaved not running - */ -bool kpowersave::do_standBy(){ - kdDebugFuncIn(trace); - kdDebugFuncOut(trace); - return do_standby(); -} - -//! dcop function to set the brightness up -bool kpowersave::do_brightnessUp(int percentageStep) { - kdDebugFuncIn(trace); - - bool retval = false; - - if(hwinfo->isOnline()) { - retval = hwinfo->setBrightnessUp(percentageStep); - } - - kdDebugFuncOut(trace); - return retval; -} - -//! dcop function to set the brightness down -bool kpowersave::do_brightnessDown(int percentageStep) { - kdDebugFuncIn(trace); - - bool retval = false; - - if(hwinfo->isOnline()) { - retval = hwinfo->setBrightnessDown(percentageStep); - } - - kdDebugFuncOut(trace); - return retval; -} - - -/*! - * DCOP Interface funtion to stop/start the Autosuspend - * \param disable boolean which tell if the autosuspend should be stopped (true) - * or started (false). - */ -void kpowersave::disableAutosuspend( bool disable ){ - kdDebugFuncIn(trace); - - if(settings->autoSuspend && settings->autoInactiveActionAfter > 0) { - if (disable) { - if ( !contextMenu()->isItemChecked(AUTOSUSPEND_MENU_ID)) { - autoSuspend->stop(); - contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, true); - } - } - else { - contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, false); - setAutoSuspend(true); - } - } - - kdDebugFuncOut(trace); -} - -/*! - * DCOP Interface funtion to open/close the detailed dialog. - */ -void kpowersave::showDetailedDialog( ){ - kdDebugFuncIn(trace); - - if (detailedIsShown) { - detailedDlg->close(); - delete(detailedDlg); - closedetaileddialog(); - return; - } - - detailedDlg = new detaileddialog(hwinfo, &fullIcon, settings); - - if (detailedDlg) { - detailedDlg->show(); - detailedIsShown = true; - } - - connect(detailedDlg, TQT_SIGNAL(destroyed()), this, TQT_SLOT(closedetaileddialog())); - - kdDebugFuncOut(trace); -} - -/*! - * DCOP Interface funtion to open the configure dialog. - * \return boolean with the result of open the dialog - * \retval false if failed (e.g. D-Bus or HAL is not running) - * \retval true if correct opend - */ -bool kpowersave::openConfigureDialog (){ - kdDebugFuncIn(trace); - - if(hwinfo->isOnline()) { - showConfigureDialog(); - kdDebugFuncOut(trace); - return config_dialog_shown; - } else { - kdDebugFuncOut(trace); - return false; - } -} - -/*! - * DCOP Interface funtion to find out if the current - * scheme manages DPMS - * \return boolean - * \retval false if current scheme does not overwrite DPMS - * \retval true if current scheme does - */ -bool kpowersave::currentSchemeManagesDPMS () { - kdDebugFuncIn(trace); - - return settings->specPMSettings; - - kdDebugFuncOut(trace); -} - - -//! dcop funtion to get the current brightness level -int kpowersave::brightnessGet() { - kdDebugFuncIn(trace); - - int retval = -1; - - if (hwinfo->supportBrightness()) { - retval = (int)(((float)hwinfo->getCurrentBrightnessLevel() / (float)hwinfo->getMaxBrightnessLevel()-1) * 100.0); - } - - kdDebugFuncOut(trace); - - return retval; -} - -#include "kpowersave.moc" diff --git a/src/kpowersave.desktop b/src/kpowersave.desktop deleted file mode 100644 index 08021ab..0000000 --- a/src/kpowersave.desktop +++ /dev/null @@ -1,68 +0,0 @@ -[Desktop Entry] -Encoding=UTF-8 -Name=kpowersave -Name[xx]=xxkpowersavexx -Name[de]=KPowersave -Name[es]=KPowersave -Name[fr]=KPowersave -Name[it]=KPowersave -Name[ja]=KPowersave -Name[pt_BR]=KPowersave -Name[ru]=KPowersave -Name[sv]=KPowersave -Name[zh_CN]=KPowersave -Name[zh_TW]=KPowersave -GenericName=Battery Monitor -Exec=kpowersave --force-acpi-check -Icon=kpowersave -Type=Application -Comment=Battery monitor and general power management -Comment[bg]=Монитор за батерията и основно управление на енергията -GenericName[bg]=Монитор за батерията -Comment[cs]=Sledování stavu baterií a správa napájení -GenericName[cs]=Monitor baterie -GenericName[de]=Akkuüberwachung -Comment[de]=Akkuüberwachung und allgemeine Energieverwaltung -GenericName[el]=Παρακολούθηση Μπαταρίας -GenericName[es]=Monitor de carga de la batería -Comment[es]=Monitor de batería y gestión general de la energía -Comment[fi]=Akkumonitori ja yleinen virranhallinta -GenericName[fi]=Akkumonitori -Comment[fr]=Moniteur de batterie et gestion de l'alimentation -GenericName[fr]=Moniteur de batterie -GenericName[hu]=Akkumulátorfigyelő -Comment[it]=Monitor della batteria e gestione generale dell'alimentazione -GenericName[it]=Monitor della batteria -Comment[km]=កមមវធ<200b>តរតពនតយ<200b>ថម នង គរបគរង<200b>ថាមពល<200b>ទទៅ -GenericName[km]=កមមវធ<200b>តរតពនតយ<200b>ថម -Comment[nb]=Batteriovervåking og generell strømstyring -GenericName[nb]=Batteriovervåker -GenericName[nl]=Batterijmonitor -GenericName[ja]=バッテリモニタ -Comment[ja]=バッテリモニタと一般電源管理 -Name[pa]=ਕ-ਊਰਜਾ ਸਭਾਲ -GenericName[pa]=ਬਟਰੀ ਦਰਸ਼ਕ -Comment[pl]=Monitor stanu baterii i ogólne zarządzanie energią -GenericName[pl]=Monitor baterii -Comment[pt]=Monitor de bateria e gestor global de energia -GenericName[pt]=Monitor de Bateria -Comment[pt_BR]=Monitor de Bateria e Gerenciamento de Energia Geral -GenericName[pt_BR]=Monitor de Bateria -GenericName[ru]=Монитор Батареи -Comment[ru]=Монитор батареи и управление энергосбережением -GenericName[sv]=Batteriövervakare -GenericName[tr]=Pil durumu izleme ve güç yönetimi arayüzü -Comment[tr]=Pil durumu izleme ve güç yönetimi arayüzü -Comment[uk]=Монітор стану батареї і загальне керування живленням -GenericName[uk]=Монітор батарей -Comment[xx]=xxBattery monitor and general power managementxx -GenericName[zh_CN]=电池监视器 -Comment[zh_CN]=电池监视器和常规电源管理 -GenericName[zh_TW]=電池監視器 -Comment[zh_TW]=電池監視器和一般電源管理 -X-TDE-autostart-after=panel -X-TDE-StartupNotify=false -X-TDE-UniqueApplet=true -X-TDE-autostart-condition=kpowersaverc:General:Autostart:true -Categories=System;Applet; - diff --git a/src/kpowersave.h b/src/kpowersave.h deleted file mode 100644 index 0239844..0000000 --- a/src/kpowersave.h +++ /dev/null @@ -1,465 +0,0 @@ -/************************************************************************** -* Copyright (C) 2004 by Thomas Renninger * -* and * -* 2004-2007 by Danny Kukawka * -* , * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of version 2 of the GNU General Public License * -* as published by the Free Software Foundation. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License * -* along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -***************************************************************************/ - -#ifndef _KPOWERSAVE_H_ -#define _KPOWERSAVE_H_ - -// this is needed to avoid typedef clash with X11/Xmd.h (X11/Xproto.h) -#ifndef TQT_CLEAN_NAMESPACE -#define TQT_CLEAN_NAMESPACE -#endif - -// Global Header -#ifdef HAVE_CONFIG_H -#include -#endif - -// KDE - Header -#include -#include -#include - -// QT - Header -#include - -// kpowersave - Header -#include "autosuspend.h" -#include "autodimm.h" -#include "configuredialog.h" -#include "countdowndialog.h" -#include "detaileddialog.h" -#include "hardware.h" -#include "kpowersave_debug.h" -#include "logviewer.h" -#include "screen.h" -#include "settings.h" - - -/*! -* \file kpowersave.h -* \brief Headerfile for kpowersave.cpp and the class \ref kpowersave. -*/ - /*! - * \class kpowersave - * \brief The central class for the kpowersave-applet - * \author Danny Kukawka, , - * \author Thomas Renninger, - * \date 2004 - 2007 - */ - -class kpowersave : public KSystemTray, public DCOPObject -{ - Q_OBJECT -// - K_DCOP - -private: - - // permanent pointers - //! to configure kpowersave - TDEConfig *config; - //! instance of \ref screen - screen *display; - //! instance of \ref settings - Settings *settings; - //! pointer to class HardwareInfo object - HardwareInfo *hwinfo; - //! instance of \ref autosuspend - autosuspend *autoSuspend; - //! instance of \ref autodimm - autodimm * autoDimm; - - // temporary pointer, use them if needed - //! TDEProcess to start YaST-module for configuration - TDEProcess *yast2; - //! instance of \ref ConfigureDialog - /*! the implemtation and all related functions for the configure dialog*/ - ConfigureDialog *configDlg; - //! instance of \ref LogViewer - LogViewer *logview; - //! instance of \ref countDownDialog - countDownDialog *countdown; - - - //! struct wth information about suspend states and permissions - SuspendStates suspend; - //! enum with the last called suspend, this need to be reset if needed - int calledSuspend; - - //! instance of \ref detaileddialog - detaileddialog *detailedDlg; - - //! represent the state of opened \ref detailedDlg - /*! - * This boolean represent information about the detailedDlg. Use this to inform - * if the dialog is displayed. - * \li true: if dialog is displayed - * \li false: if not - */ - bool detailedIsShown; - //! represent the state of the configure dialog - /*! - * This boolean represent information about the configure dialog. Use this to inform - * if the dialog is displayed. - * \li true: if dialog is displayed - * \li false: if not - */ - bool config_dialog_shown; - - //! represent background status of the kickerapplet icon - /*! - * This boolean represent information about the background of the kickerapplet icon. - * \li true: if iconbackground is colored - * \li false: if iconbackground is not colored - */ - bool icon_BG_is_colored; - //! represent color status of the kickerapplet icon - /*! - * This boolean represent the state of the kickerapplet icon. It don't display - * information about the icon backgrund like \ref icon_BG_is_colored . It say - * only that the icon is in state to have a blinking background . - * \li true: if icon set to be colored - * \li false: if icon isn't set to be colored - */ - bool icon_set_colored; - //! represent the state of icon changing - /*! - * This boolean represent information about changing the icon background. It's used to - * change the intervall of redraw the kickerapplet icon. - * \li true: if the state of icon is changed - * \li false: if the state of icon isn't change - */ - bool icon_state_changed; - //! represent the state of the suspend/progress dialog - /*! - * This boolean represent information about the current state of - * visible of the suspend/progress dialog. - * \li true: if the dialog is shown - * \li false: if not - */ - bool suspend_dialog_shown; - - //! tell if the display should get dimmed down - /*! - * This boolean represent information if the display should get dimmed down - * within the \ref do_dimm() function or not. - * \li true: if the display should get dimmed down - * \li false: if the display should get dimmed up - */ - bool autoDimmDown; - - //! to temporary hold the resume result - int resume_result; - - //! a menu entry ID - /*! contains the ID of the menuentry for kpowersave configure Dialog */ - int CONFIGURE_ID; - - int CONFIGURE_EVENTS_ID; - - //! a menu entry ID - /*! contains the ID of the menuentry for YaST-configuration */ - int YAST_MODULE_MENU_ID; - //! a menu seperator ID - /*! contains the ID of the separator between YaST-entry and the sleep-states */ - int SLEEP_SEPARATOR_MENU_ID; - //! a menu entry ID - /*! contains the ID of the menuentry for suspend-to-disk */ - int SUSPEND2DISK_MENU_ID; - //! a menu entry ID - /*! contains the ID of the menuentry for suspend-to-ram */ - int SUSPEND2RAM_MENU_ID; - //! a menu entry ID - /*! contains the ID of the menuentry for stand-by */ - int STANDBY_MENU_ID; - //! a menu seperator ID - /*! contains the ID of the separator between sleep-states-entries and the cpufreq-submenu */ - int CPUFRETQ_SEPARATOR_MENU_ID; - //! a submenu ID - /*! contains the ID of the cpufreq sub menu*/ - int CPUFRETQ_MENU_ID; - //! a menu seperator ID - /*! contains the ID of the separator between cpufreq- and scheme-submenu*/ - int SCHEME_SEPARATOR_MENU_ID; - //! a submenu ID - /*! contains the ID of the scheme submenu*/ - int SCHEME_MENU_ID; - //! a menu seperator ID - /*! contains the ID of the separator between scheme-submenu and autosuspend*/ - int AUTOSUSPEND_SEPARATOR_MENU_ID; - //! a menu entry ID - /*! contains the ID of the menuentry for disable inactivity actions */ - int AUTOSUSPEND_MENU_ID; - //! a menu seperator ID - /*! contains the ID of the separator between autosuspend and Help*/ - int HELP_SEPARATOR_MENU_ID; - //! a menu ID - /*! contains the ID of the help menu*/ - int HELP_MENU; - - //! number of white pixel in the kickerapplet icon - /*! - * This integer value represent the number of white pixel in the icon for - * the kickerapplet. with this 'global' variable we don't need to count the - * white pixel on every redraw. - */ - int countWhiteIconPixel; - - //! TQTimer-interval for icon background - /*! - * Time intervall to set the colored background of the batteryicon on/off. - * The value is 1000 msec/ 1 sec. - */ - static const int BAT_icon_BG_intervall = 1000; - - //! type of current running suspend - /*! TQString store the name of the current running suspend*/ - TQString suspendType; - - //! current name of the pixmap - /*! - * Contains the current name of the icon/pixmap. The value must be a filename of a existing iconfile. - * \sa power_icon, no_battery_icon, charge_icon, battery, battery_RED or battery_ORANGE - */ - TQString pixmap_name; - - //! contains the 'real' schemenames - /*! - * This list store the real schemenames (not the i18n()-version) - * regarding to position in the scheme-menu - */ - TQStringList org_schemenames; - - //! a sub-menu of the kickerapplet - /*! TQPopupMenu for the cpufreq-entries. */ - TQPopupMenu *speed_menu; - //! a sub-menu of the kickerapplet - /*! TQPopupMenu for the scheme-entries. */ - TQPopupMenu *scheme_menu; - //! a sub-menu of the kickerapplet - /*! TQPopupMenu for the help-entries. */ - TQPopupMenu *help_menu; - - - //! icon-pixmap - /*! TQPixmap with the (pre-)loaded icon from \ref pixmap_name .*/ - TQPixmap pixmap; - //! icon-pixmap - /*! TQPixmap with the full draw applet Icon (to be used in other classes) .*/ - TQPixmap fullIcon; - - - //! Timer for the blinking Icon background - /*! - * This timer is used to let blink the background of a icon in kicker. - * The timerinterval is defined in \ref BAT_icon_BG_intervall . - */ - TQTimer *BAT_WARN_ICON_Timer; - //! Timer to dimm down/up the brightness - /*! - * This timer is used dimm the display up and down. The timerinterval - * depends on calculated timePerStep in the calling function. - */ - TQTimer *AUTODIMM_Timer; - - //! draw all icon related things for \ref redrawPixmap() - void drawIcon(); - //! to intialise the menu for the kickerapplet - void initMenu(); - //! load the icon for \ref redrawPixmap() - void loadIcon(bool forceReload = false); - //! draw/redraw the icon for the kickerapplet - void redrawPixmap(); - //! to set the screensaver settings - void setSchemeSettings(); - //! to update the Tooltip of the kickerapplet - void updateTooltip(); - - //! Eventhandler to catch mouse-press-events and react - void mousePressEvent( TQMouseEvent *qme ); - //! Event handler to catch mouse wheel events and react - void wheelEvent( TQWheelEvent *qwe ); - //! Eventhandler to catch mouse enter events and react - void enterEvent( TQEvent *qee); - - //! to handle mount/umount on resume/suspend - bool handleMounts ( bool suspend ); - - //! to get the i18n string for a suspend type - TQString getSuspendString (int type); - -private slots: - - //! send command for stand-by to the TDE hardware library - bool do_standby(); - //! send command for suspend_to_disk to the TDE hardware library - bool do_suspend2disk(); - //! send command for suspend_to_RAM to the TDE hardware library - bool do_suspend2ram(); - - //! show warning dialog or call autosuspend if signal \ref inactivity::inactivityTimeExpired() recieved - void do_autosuspendWarn(); - //! execute the autosuspend - bool do_autosuspend(bool chancel); - //! starts the Yast2-power-management module - void do_config(); - //! sets the new scheme with all settings - void do_setActiveScheme( int ); - //! called if icon background must be changed - void do_setIconBG(); - //! to set the autosuspend on/off over the menu - void do_setAutosuspend(); - //! sets the CPU Freq policy via the TDE hardware library - void do_setSpeedPolicy( int ); - //! called if there are problems with starting yast module - void slotConfigProcessExited( TDEProcess * ); - //! called to open the kpowersave help - void slotHelp(); - //! called to open the kpowersave About dialog - void slotAbout(); - //! called to open website to report bugs - void slotReportBug(); - //! called if the configure dialog is destroyed - void observeConfigDlg(); - //! called if user exit from kpowersave - void _quit(); - - //! called if the user get inactive and the display should get dimmed down - void do_downDimm(); - //! called if the user get active again and the display should get dimmed up - void do_upDimm(); - //! TQT_SLOT do do the dimmining for autodimm feature - void do_dimm(); - //! TQT_SLOT to set autodimm related stuff and start autodimm monitoring - void setAutoDimm( bool resumed ); - - //! to update the main menu of the kickerapplet - /*! this is bound to generalDataChanged singal in pdaemon */ - void update(); - //! to update the scheme-menu within the main menu - void updateSchemeMenu(); - //! to update the menu with the cpu frequency within the main menu - void updateCPUFreqMenu(); - - //! this set \ref suspendType from signal - void setSuspendType( TQString suspendtype ); - //! this set the autosuspend and start the monitoring - void setAutoSuspend( bool ); - - //! called for critical battery event SHUTDOWN - void handleCriticalBatteryActionCall(); - //! set for a battery status the related actions - void handleActionCall ( action action, int value, bool checkAC = false, bool batWarnCall = false ); - - //! this lock/reactivate the screen if a lidclosetStatus() signal is triggered - void handleLidEvent( bool closed ); - //! show the login dialog after locked the screen - void activateLoginScreen(); - - //! handle event for press power button and call action - void handlePowerButtonEvent(); - //! handle event for press s2ram/sleep button and call action - void handleSleepButtonEvent(); - //! handle event for press s2disk button and call action - void handleS2DiskButtonEvent(); - - //! handle changes of the session state - void handleSessionState (bool state); - - //! to show the kpowersave configure_dialog - void showConfigureDialog(); - //! to show the KNotify config dialog - void showConfigureNotificationsDialog(); - - //! this emit the KNotify event for a battery warning state state - void notifyBatteryStatusChange ( int type, int state ); - //! this emit the KNotify event for change AC status - void handleACStatusChange ( bool acstate, bool notifyEvent = true ); - //! this emit the KNotify events if scheme switched - void notifySchemeSwitch(); - //! this emit the KNotify events if the machine go to suspend/Standby - void notifySuspend( int ); - //! to independent handleResumeSignal from event loop - void forwardResumeSignal( int result ); - //! this emit the KNotify events if the machine resumed - void handleResumeSignal(); - - //! this show a blocking dialog from kpowersave with the given message - void showErrorMessage( TQString msg ); - - //! this is called when detailed dialog is closed - void closedetaileddialog(); - -public: - - //! default constructor - kpowersave( bool force_acpi_check = false, bool trace_func = false); - //! default destructor - virtual ~kpowersave(); - -k_dcop: - //! dcop function to lock the screen - bool lockScreen(); - //! dcop function to set a scheme - bool do_setScheme( TQString ); - //! dcop function to set CPU Freq policy - bool do_setCPUFreqPolicy( TQString ); - //! dcop function to send 'suspend to disk' command to powersaved - bool do_suspendToDisk(); - //! dcop function to send 'suspend to RAM' command to powersaved - bool do_suspendToRAM(); - //! dcop function to send 'standby' command to powersaved - bool do_standBy(); - //! dcop function to set the brightness down - bool do_brightnessDown(int percentageStep = -1); - //! dcop function to set the brightness up - bool do_brightnessUp(int percentageStep = -1); - - //! dcop function to disable/stop autosuspend - void disableAutosuspend( bool ); - - //! dcop function to show the detailed dialog - void showDetailedDialog(); - //! dcop function to open the configure dialog - bool openConfigureDialog(); - - //! dcop function to find out if kpowersave manages DPMS - bool currentSchemeManagesDPMS(); - //! dcop funtion to get the current brightness level - int brightnessGet(); - - //! dcop function to return the name of the current scheme - TQString currentScheme (); - //! dcop function to return the current cpufreqpolicy - TQString currentCPUFreqPolicy(); - - //! dcop function to return the supported sleeping states - TQStringList allowed_sleepingStates(); - //! dcop function to return the schemes - TQStringList listSchemes(); - //! dcop function to return the supported CPU - TQStringList listCPUFreqPolicies(); - -protected: - void resizeEvent ( TQResizeEvent * ); -}; - -#endif // _KPOWERSAVE_H_ diff --git a/src/kpowersave.lsm b/src/kpowersave.lsm deleted file mode 100644 index 7cf6dc8..0000000 --- a/src/kpowersave.lsm +++ /dev/null @@ -1,14 +0,0 @@ -Begin4 -Title: kpowersave -Version: R14.0.0 -Entered-date: 2010-05-10 -Description: Front end for power management for the Trinity Desktop Environment -Keywords: TDE Qt -Author: Thomas Renninger -Maintained-by: The Trinity Desktop Environment (TDE) http://www.trinitydesktop.org/ -Primary-site: http://git.trinitydesktop.org/cgit/ -Alternate-site: -Original-site: http://kde-apps.org/content/show.php?content=29295 -Platforms: Linux and other Unices running TDE -Copying-policy: GPL -End diff --git a/src/kpowersave_debug.h b/src/kpowersave_debug.h deleted file mode 100644 index 20f2c6b..0000000 --- a/src/kpowersave_debug.h +++ /dev/null @@ -1,68 +0,0 @@ -/************************************************************************** -* Copyright (C) * -* 2004-2007 by Danny Kukawka * -* , * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of version 2 of the GNU General Public License * -* as published by the Free Software Foundation. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License * -* along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -***************************************************************************/ - -#ifndef _KPOWERSAVE_DEBUG_H -#define _KPOWERSAVE_DEBUG_H - -// Global Header -#ifdef HAVE_CONFIG_H -#include -#endif - -// Default Header -#include -#include - -// QT - Header -#include - -// KDE Header -#include - -/*! -* \file kpowersave_debug.h -* \brief Headerfile for debug related defines/macros. Currently this file -* contains the myDebug(...) macro. -*/ - -// to store the value over the different classes -extern bool trace; - -/* - * macro to collect time and k_funcinfo information for kdDebug() - */ -#define funcinfo "[" << TQString(TQTime::currentTime().toString()).ascii() << \ - ":" << TQTime::currentTime().msec() << "]" << k_funcinfo - -/* - * macros to trace function entry and leave points - */ -#define kdDebugFuncIn(traceinfo) do { \ - if (traceinfo == true) \ - kdDebug() << funcinfo << "IN " << endl; \ -} while (0) - -#define kdDebugFuncOut(traceinfo) do { \ - if (traceinfo == true) \ - kdDebug() << funcinfo << "OUT " << endl; \ -} while (0) - - -#endif //_KPOWERSAVE_DEBUG_H diff --git a/src/logviewer.cpp b/src/logviewer.cpp index 7d5d7b2..bd2207a 100644 --- a/src/logviewer.cpp +++ b/src/logviewer.cpp @@ -41,7 +41,7 @@ LogViewer::LogViewer( TQString filename, TQWidget *parent, const char *name) :log_viewer(parent, name, false, WDestructiveClose ) { - this->setCaption(i18n("KPowersave Logfile Viewer: %1").arg(filename)); + this->setCaption(i18n("TDEPowersave Logfile Viewer: %1").arg(filename)); if (!TQFile::exists ( filename )) return; diff --git a/src/logviewer.h b/src/logviewer.h index 53b49b7..9bb6274 100644 --- a/src/logviewer.h +++ b/src/logviewer.h @@ -26,7 +26,7 @@ */ /*! * \class LogViewer -* \brief class for view logfiles in KPowersave related funtionality +* \brief class for view logfiles in TDEPowersave related funtionality * \author Danny Kukawka, , * \version 0.0.1 * \date 2007 diff --git a/src/main.cpp b/src/main.cpp index ca7ad52..d44b70c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,22 +19,22 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include "kpowersave.h" +#include "tdepowersave.h" #include #include #include #include #include -#include "kpowersave_debug.h" +#include "tdepowersave_debug.h" /*! * \file main.cpp - * \brief The file with the \ref kdemain class to start kpowersave. + * \brief The file with the \ref kdemain class to start tdepowersave. */ /*! * \class kdemain - * \brief The kpowersave kdemain class, which is the startpoint of KPowersave. + * \brief The tdepowersave kdemain class, which is the startpoint of TDEPowersave. * \author Thomas Renninger, * \author Danny Kukawka, , * \date 2004 - 2007 @@ -52,7 +52,7 @@ bool trace = false; extern "C" int kdemain(int argc, char **argv) { - TDEAboutData about("kpowersave", I18N_NOOP("KPowersave"), version, description, + TDEAboutData about("tdepowersave", I18N_NOOP("TDEPowersave"), version, description, TDEAboutData::License_GPL, I18N_NOOP("(c) 2004-2006, Danny Kukawka\n" "(c) 2004 Thomas Renninger")); @@ -76,16 +76,16 @@ int kdemain(int argc, char **argv) TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); if (!KUniqueApplication::start()) { - fprintf(stderr, "KPowersave is already running!\n"); + fprintf(stderr, "TDEPowersave is already running!\n"); exit(0); } KUniqueApplication app; app.disableSessionManagement(); - kpowersave *mainWin = 0; + tdepowersave *mainWin = 0; - mainWin = new kpowersave(args->isSet( "force-acpi-check" ), args->isSet( "dbg-trace" )); + mainWin = new tdepowersave(args->isSet( "force-acpi-check" ), args->isSet( "dbg-trace" )); app.setMainWidget( mainWin ); mainWin->show(); diff --git a/src/pics/CMakeLists.txt b/src/pics/CMakeLists.txt index 0e4a84c..9ce88be 100644 --- a/src/pics/CMakeLists.txt +++ b/src/pics/CMakeLists.txt @@ -9,4 +9,4 @@ # ################################################# -tde_install_icons( DESTINATION ${DATA_INSTALL_DIR}/kpowersave/icons ) +tde_install_icons( DESTINATION ${DATA_INSTALL_DIR}/tdepowersave/icons ) diff --git a/src/pics/Makefile.am b/src/pics/Makefile.am index c63aa20..213fe82 100644 --- a/src/pics/Makefile.am +++ b/src/pics/Makefile.am @@ -1,3 +1,3 @@ -kpowersaveiconsdir = $(kde_datadir)/kpowersave/icons -kpowersaveicons_ICON = AUTO +tdepowersaveiconsdir = $(kde_datadir)/tdepowersave/icons +tdepowersaveicons_ICON = AUTO diff --git a/src/screen.cpp b/src/screen.cpp index 092c4bd..6bbce76 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -29,7 +29,7 @@ // own headers #include "screen.h" -#include "kpowersave_debug.h" +#include "tdepowersave_debug.h" /* needed for lXext C library linkage */ extern "C" { diff --git a/src/settings.cpp b/src/settings.cpp index ea1aa4a..cf860e0 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -35,7 +35,7 @@ /*! This is the default constructor of the class Settings. */ Settings::Settings() { - tdeconfig = new TDEConfig("kpowersaverc", true ); + tdeconfig = new TDEConfig("tdepowersaverc", true ); kde = new KDE_Settings(); load_kde(); load_general_settings(); @@ -50,7 +50,7 @@ Settings::~Settings() /*! - * Loads the scheme settings from kpowersaverc and fills the related variables. + * Loads the scheme settings from tdepowersaverc and fills the related variables. * \param schemeName TQString with the name (realname not i18n() version) of the * scheme which setting should be load. If the scheme could not * be loaded, this function try to load "default-scheme" @@ -231,7 +231,7 @@ bool Settings::load_scheme_settings(TQString schemeName){ /*! - * Loads the general settings from kpowersaverc and fills the related variables. + * Loads the general settings from tdepowersaverc and fills the related variables. * \return the result of the load * \retval true if the settings could be loaded * \retval false if there was no group named 'General' diff --git a/src/settings.h b/src/settings.h index 9a083a0..0b7cba4 100644 --- a/src/settings.h +++ b/src/settings.h @@ -175,33 +175,33 @@ public: * \li false: if not lock the screen */ bool lockOnLidClose; - //! if kpowersave starts on login + //! if tdepowersave starts on login /*! - * This boolean tells if kpowersave should be start automatically on userlogin. + * This boolean tells if tdepowersave should be start automatically on userlogin. * The value could be changed trough the configuration dialog and if the user - * stop kpowersave. + * stop tdepowersave. * \li true: if autostart * \li false: if not start on login */ bool autostart; - //! if kpowersave ask for the user for autostart + //! if tdepowersave ask for the user for autostart /*! - * This boolean tells if kpowersave ask for autostart settings if user stop kpowersave. + * This boolean tells if tdepowersave ask for autostart settings if user stop tdepowersave. * \li true: if ask on stop * \li false: if never ask */ bool autostartNeverAsk; - //! if kpowersave should force DPMS shutdown for display for lidclose + //! if tdepowersave should force DPMS shutdown for display for lidclose /*! - * This boolean tells if kpowersave should force dpms shutdown for the display if a + * This boolean tells if tdepowersave should force dpms shutdown for the display if a * lidclose event was recieved * \li true: if shutdown display * \li false: if not */ bool forceDpmsOffOnLidClose; - //! if kpowersave should call SetPowerSave() on HAL + //! if tdepowersave should call SetPowerSave() on HAL /*! - * This boolean tells if kpowersave should call SetPowerSave on HAL depending + * This boolean tells if tdepowersave should call SetPowerSave on HAL depending * on the AC state. * \li true: if should call * \li false: if not @@ -210,7 +210,7 @@ public: //! time after resume to fake keyevent /*! - * This integere contains the time after wich kpowersave should fake a keyevent + * This integere contains the time after wich tdepowersave should fake a keyevent * to show the login dialog if the desktop was locked on suspend. Value is in msec. */ int timeToFakeKeyAfterLock; @@ -270,43 +270,43 @@ public: TQString currentScheme; // ---------- Screensaver/DPMS section ------------ // - //! if kpowersave use own screensaver settings + //! if tdepowersave use own screensaver settings /*! - * This boolean represent kpowersave userspecific screensaver settings. If kpowersave + * This boolean represent tdepowersave userspecific screensaver settings. If tdepowersave * use own screensaver settings the KDE or GNOME settings are overwritten. - * \li true: if kpowersave use own settings - * \li false: if kpowersave don't change any screensaver settings + * \li true: if tdepowersave use own settings + * \li false: if tdepowersave don't change any screensaver settings */ bool specSsSettings; - //! if kpowersave should disable the screensaver + //! if tdepowersave should disable the screensaver /*! - * This boolean tells if kpowersave should disable the screensaver. - * \li true: if kpowersave should disable the screensaver + * This boolean tells if tdepowersave should disable the screensaver. + * \li true: if tdepowersave should disable the screensaver * \li false: if not */ bool disableSs; - //! if kpowersave should blank only the screen + //! if tdepowersave should blank only the screen /*! - * This boolean tells if kpowersave should blank only the screen instead of + * This boolean tells if tdepowersave should blank only the screen instead of * using the global selected KDE or GNOME screensaver. - * \li true: if kpowersave should blank only the screen + * \li true: if tdepowersave should blank only the screen * \li false: if not and don't change anything */ bool blankSs; - //! if kpowersave use own DPMS settings + //! if tdepowersave use own DPMS settings /*! - * This boolean tells if kpowersave should use own userspecific settings for - * Display PowerManagement Settings. If this value is true kpowersave overwritte + * This boolean tells if tdepowersave should use own userspecific settings for + * Display PowerManagement Settings. If this value is true tdepowersave overwritte * the KDE or GNOME global settings. - * \li true: if kpowersave use own DPMS settings - * \li false: if kpowersave don't change DPMS settings + * \li true: if tdepowersave use own DPMS settings + * \li false: if tdepowersave don't change DPMS settings */ bool specPMSettings; - //! if kpowersave should disable DPMS + //! if tdepowersave should disable DPMS /*! - * This boolean tells if kpowersave should disable DPMS. If this is used, - * kpowersave overwrite the KDE or GNOME global settings. - * \li true: if kpowersave should disable dpms + * This boolean tells if tdepowersave should disable DPMS. If this is used, + * tdepowersave overwrite the KDE or GNOME global settings. + * \li true: if tdepowersave should disable dpms * \li false: if not */ bool disableDPMS; @@ -364,7 +364,7 @@ public: bool autoInactiveSBlistEnabled; //! time of user inactivity to execute a defined action /*! - * This integer represent the time in minutes after which kpowersave + * This integer represent the time in minutes after which tdepowersave * should execute a specific through \ref autoInactiveAction defined * action. */ @@ -390,9 +390,9 @@ public: TQStringList autoInactiveSBlist; // ------ Autosuspend countdown dialog section -------- // - //! if KPowersave should display a dialog with a warning for autosuspend + //! if TDEPowersave should display a dialog with a warning for autosuspend /*! - * This boolean tells if KPowersave should show a warning dialog + * This boolean tells if TDEPowersave should show a warning dialog * with a countdown before call the autosuspend. * \li true: if show dialog * \li false: if not @@ -425,7 +425,7 @@ public: bool autoDimmSBlistEnabled; //! time of user inactivity to dimm the display /*! - * This integer represent the time in minutes after which kpowersave + * This integer represent the time in minutes after which tdepowersave * should dimm the display to the level defined by \ref autoDimmTo . */ int autoDimmAfter; @@ -468,7 +468,7 @@ public: //! if umount/remount external volumes on suspend /*! - * This boolean tells if KPowersave should umount external partitions + * This boolean tells if TDEPowersave should umount external partitions * before suspend and remount them after resume. * \li true: if umount/remount * \li false: if not @@ -487,7 +487,7 @@ public: private: - //! configuration of kpowersave + //! configuration of tdepowersave TDEConfig *tdeconfig; //! to map a battery action string to the related type diff --git a/src/suspenddialog.cpp b/src/suspenddialog.cpp index 26469da..ff3b04d 100644 --- a/src/suspenddialog.cpp +++ b/src/suspenddialog.cpp @@ -41,7 +41,7 @@ suspendDialog::suspendDialog(TQWidget *parent, const char *name) :suspend_Dialog(parent, name, true, TQt::WStyle_StaysOnTop | TQt::WDestructiveClose ) { - this->setIcon(SmallIcon("kpowersave", TQIconSet::Automatic)); + this->setIcon(SmallIcon("tdepowersave", TQIconSet::Automatic)); } /*! This is the default destructor of the class. */ @@ -65,7 +65,7 @@ void suspendDialog::setPixmap( TQString type ) } else if (type.startsWith("standby")) { pixmap = TDEGlobal::iconLoader()->loadIcon("stand_by", TDEIcon::NoGroup, TDEIcon::SizeLarge); } else { - pixmap = TDEGlobal::iconLoader()->loadIcon("kpowersave", TDEIcon::NoGroup, TDEIcon::SizeLarge); + pixmap = TDEGlobal::iconLoader()->loadIcon("tdepowersave", TDEIcon::NoGroup, TDEIcon::SizeLarge); } setCaption(i18n("Preparing Suspend...")); iconPixmap->setPixmap( pixmap ); diff --git a/src/tdepowersave-autostart.desktop b/src/tdepowersave-autostart.desktop new file mode 100644 index 0000000..20cf6e0 --- /dev/null +++ b/src/tdepowersave-autostart.desktop @@ -0,0 +1,68 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=tdepowersave +Name[xx]=xxtdepowersavexx +Name[de]=TDEPowersave +Name[es]=TDEPowersave +Name[fr]=TDEPowersave +Name[it]=TDEPowersave +Name[ja]=TDEPowersave +Name[pt_BR]=TDEPowersave +Name[ru]=TDEPowersave +Name[sv]=TDEPowersave +Name[zh_CN]=TDEPowersave +Name[zh_TW]=TDEPowersave +GenericName=Battery Monitor +Exec=tdepowersave +Icon=tdepowersave +Type=Application +Comment=Battery monitor and general power management +Comment[bg]=Монитор за батерията и основно управление на енергията +GenericName[bg]=Монитор за батерията +Comment[cs]=Sledování stavu baterií a správa napájení +GenericName[cs]=Monitor baterie +GenericName[de]=Akkuüberwachung +Comment[de]=Akkuüberwachung und allgemeine Energieverwaltung +GenericName[el]=Παρακολούθηση Μπαταρίας +GenericName[es]=Monitor de carga de la batería +Comment[es]=Monitor de batería y gestión general de la energía +Comment[fi]=Akkumonitori ja yleinen virranhallinta +GenericName[fi]=Akkumonitori +Comment[fr]=Moniteur de batterie et gestion de l'alimentation +GenericName[fr]=Moniteur de batterie +GenericName[hu]=Akkumulátorfigyelő +Comment[it]=Monitor della batteria e gestione generale dell'alimentazione +GenericName[it]=Monitor della batteria +Comment[km]=កមមវធ<200b>តរតពនតយ<200b>ថម នង គរបគរង<200b>ថាមពល<200b>ទទៅ +GenericName[km]=កមមវធ<200b>តរតពនតយ<200b>ថម +Comment[nb]=Batteriovervåking og generell strømstyring +GenericName[nb]=Batteriovervåker +GenericName[nl]=Batterijmonitor +GenericName[ja]=バッテリモニタ +Comment[ja]=バッテリモニタと一般電源管理 +Name[pa]=ਕ-ਊਰਜਾ ਸਭਾਲ +GenericName[pa]=ਬਟਰੀ ਦਰਸ਼ਕ +Comment[pl]=Monitor stanu baterii i ogólne zarządzanie energią +GenericName[pl]=Monitor baterii +Comment[pt]=Monitor de bateria e gestor global de energia +GenericName[pt]=Monitor de Bateria +Comment[pt_BR]=Monitor de Bateria e Gerenciamento de Energia Geral +GenericName[pt_BR]=Monitor de Bateria +GenericName[ru]=Монитор Батареи +Comment[ru]=Монитор батареи и управление энергосбережением +GenericName[sv]=Batteriövervakare +GenericName[tr]=Pil durumu izleme ve güç yönetimi arayüzü +Comment[tr]=Pil durumu izleme ve güç yönetimi arayüzü +Comment[uk]=Монітор стану батареї і загальне керування живленням +GenericName[uk]=Монітор батарей +Comment[xx]=xxBattery monitor and general power managementxx +GenericName[zh_CN]=电池监视器 +Comment[zh_CN]=电池监视器和常规电源管理 +GenericName[zh_TW]=電池監視器 +Comment[zh_TW]=電池監視器和一般電源管理 +X-TDE-autostart-after=panel +X-TDE-StartupNotify=false +X-TDE-UniqueApplet=true +X-TDE-autostart-condition=tdepowersaverc:General:Autostart:true +Categories=System;Applet; + diff --git a/src/tdepowersave.cpp b/src/tdepowersave.cpp new file mode 100644 index 0000000..da3071a --- /dev/null +++ b/src/tdepowersave.cpp @@ -0,0 +1,2678 @@ + /************************************************************************** + * Copyright (C) 2004 by Thomas Renninger * + * and * + * 2004-2007 by Danny Kukawka * + * , * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of version 2 of the GNU General Public License * + * as published by the Free Software Foundation. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +// KDE headers: +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// other TQt headers: +#include +#include +#include +#include +#include +#include +#include + +// own headers: +#include "tdepowersave.h" +#include "infodialog.h" + +/*! +* \file tdepowersave.cpp +* \brief This file contains the main functionality of the tdepowersave-applet.*/ + +/*! + * This is the default constructor of the class tdepowersave. + */ +tdepowersave::tdepowersave( bool force_acpi_check, bool trace_func ) : KSystemTray(0, "tdepowersave"), + DCOPObject("tdepowersaveIface") { + trace = trace_func; + kdDebugFuncIn(trace); + + display = new screen(); + settings = new Settings(); + autoSuspend = new autosuspend(); + autoDimm = new autodimm(); + hwinfo = new HardwareInfo(); + suspend = hwinfo->getSuspendSupport(); + + yast2 = NULL; + + resume_result = 0; + + config = TDEGlobal::config(); + config->setGroup("General"); + if(!config->readBoolEntry("AlreadyStarted", false) || force_acpi_check){ + config->writeEntry("AlreadyStarted", true); + // check whether APM, ACPI, PMU, CPUFreq or Suspend2Disk/ram supported, otherwise end up + // and don't start tdepowersave ever again until force_acpi_check == true. + if (!hwinfo->hasACPI() && !hwinfo->hasAPM() && !hwinfo->hasPMU() && + !hwinfo->supportCPUFreq() && !suspend.suspend2disk && !suspend.suspend2ram){ + config->writeEntry("Autostart", false); + config->sync(); + kdError() << "This machine does not support ACPI, APM, PMU, CPUFreq, Suspend2Disk nor " + << "Suspend2RAM. Please close tdepowersave now." << endl; + exit(-1); + } + } + + // default init + if (hwinfo->getAcAdapter()) { + settings->load_scheme_settings( settings->ac_scheme); + } else { + settings->load_scheme_settings( settings->battery_scheme); + } + // set the battery warning levels + hwinfo->setPrimaryBatteriesWarningLevel(settings->batteryWarningLevel, + settings->batteryLowLevel, + settings->batteryCriticalLevel); + + // connect to signals for changes + connect(hwinfo, TQT_SIGNAL(generalDataChanged()), this, TQT_SLOT(update())); + connect(hwinfo, TQT_SIGNAL(primaryBatteryChanged()), this, TQT_SLOT(update())); + connect(hwinfo, TQT_SIGNAL(ACStatus(bool)), this, TQT_SLOT(handleACStatusChange (bool))); + connect(hwinfo, TQT_SIGNAL(resumed(int)), this, TQT_SLOT(forwardResumeSignal(int))); + + // connect to error mesages + connect(autoSuspend, TQT_SIGNAL(displayErrorMsg(TQString)), this, TQT_SLOT(showErrorMessage(TQString))); + + // connect to events + connect(hwinfo, TQT_SIGNAL(lidclosetStatus(bool)), this, TQT_SLOT(handleLidEvent(bool))); + connect(hwinfo, TQT_SIGNAL(powerButtonPressed()), this, TQT_SLOT (handlePowerButtonEvent())); + connect(hwinfo, TQT_SIGNAL(sleepButtonPressed()), this, TQT_SLOT (handleSleepButtonEvent())); + connect(hwinfo, TQT_SIGNAL(s2diskButtonPressed()), this, TQT_SLOT (handleS2DiskButtonEvent())); + connect(hwinfo, TQT_SIGNAL(batteryWARNState(int,int)), this, TQT_SLOT(notifyBatteryStatusChange (int,int))); + connect(hwinfo, TQT_SIGNAL(desktopSessionIsActive(bool)), this, TQT_SLOT (handleSessionState(bool))); + connect(autoSuspend, TQT_SIGNAL(inactivityTimeExpired()), this, TQT_SLOT(do_autosuspendWarn())); + connect(autoDimm, TQT_SIGNAL(inactivityTimeExpired()), this, TQT_SLOT(do_downDimm())); + connect(autoDimm, TQT_SIGNAL(UserIsActiveAgain()), this, TQT_SLOT(do_upDimm())); + + config->sync(); + + config_dialog_shown = false; + suspend_dialog_shown = false; + detailedIsShown = false; + icon_set_colored = false; + icon_BG_is_colored = false; + + calledSuspend = -1; + countWhiteIconPixel = 0; + + pixmap_name = "NONE"; + suspendType = "NULL"; + + BAT_WARN_ICON_Timer = new TQTimer(this); + connect(BAT_WARN_ICON_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_setIconBG())); + + AUTODIMM_Timer = new TQTimer(this); + + initMenu(); + update(); + updateCPUFreqMenu(); + setSchemeSettings(); + + kdDebugFuncOut(trace); +} + + +/*! This is the default destructor of class tdepowersave. */ +tdepowersave::~tdepowersave(){ + kdDebugFuncIn(trace); + + delete hwinfo; + delete display; + delete settings; + delete autoSuspend; +#ifdef ENABLE_YAST_ENTRY + delete yast2; +#endif +} + +/*! + * use this function to initalise the main kicker menu + */ +void tdepowersave::initMenu() { + kdDebugFuncIn(trace); + + CONFIGURE_ID = this->contextMenu()->insertItem(SmallIcon("configure", TQIconSet::Automatic), + i18n("Configure TDEPowersave..."), + this, TQT_SLOT(showConfigureDialog())); + CONFIGURE_EVENTS_ID = this->contextMenu()->insertItem(SmallIcon("knotify", TQIconSet::Automatic), + i18n("Configure Notifications..."), + this, TQT_SLOT(showConfigureNotificationsDialog())); +#ifdef ENABLE_YAST_ENTRY + YAST_MODULE_MENU_ID = this->contextMenu()->insertItem(SmallIcon("yast", TQIconSet::Automatic), + i18n("Start YaST2 Power Management Module..."), + this, TQT_SLOT(do_config())); +#endif + + SLEEP_SEPARATOR_MENU_ID = this->contextMenu()->insertSeparator(); + SUSPEND2DISK_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("suspend_to_disk", + TQIconSet::Automatic), + i18n("Suspend to Disk"), this, + TQT_SLOT(do_suspend2disk())); + SUSPEND2RAM_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("suspend_to_ram", + TQIconSet::Automatic), + i18n("Suspend to RAM"), this, + TQT_SLOT(do_suspend2ram())); + STANDBY_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("stand_by", TQIconSet::Automatic), + i18n("Standby"), this, TQT_SLOT(do_standby())); + + speed_menu = new TQPopupMenu(this, i18n("Set CPU Frequency Policy").ascii()); + speed_menu->insertItem(i18n("Performance"), PERFORMANCE); + speed_menu->insertItem(i18n("Dynamic"), DYNAMIC); + speed_menu->insertItem(i18n("Powersave"), POWERSAVE); + + CPUFRETQ_SEPARATOR_MENU_ID = contextMenu()->insertSeparator(); + + CPUFRETQ_MENU_ID = contextMenu()->insertItem(i18n("Set CPU Frequency Policy"), speed_menu); + connect(speed_menu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(do_setSpeedPolicy(int))); + connect(hwinfo, TQT_SIGNAL(currentCPUFreqPolicyChanged()), this, TQT_SLOT(updateCPUFreqMenu())); + + + SCHEME_SEPARATOR_MENU_ID = contextMenu()->insertSeparator(); + + scheme_menu = new TQPopupMenu(this, i18n("Set Active Scheme").ascii()); + SCHEME_MENU_ID = contextMenu()->insertItem(i18n("Set Active Scheme"), scheme_menu); + connect(scheme_menu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(do_setActiveScheme(int))); + + // menu entry for the autosuspend disable checkbox, disabled by default, only + // displayed if autosuspend for the current scheme is activated + AUTOSUSPEND_SEPARATOR_MENU_ID = contextMenu()->insertSeparator(); + AUTOSUSPEND_MENU_ID = this->contextMenu()->insertItem( i18n("Disable Actions on Inactivity"), + this,TQT_SLOT(do_setAutosuspend())); + this->contextMenu()->setItemVisible(AUTOSUSPEND_SEPARATOR_MENU_ID, false); + this->contextMenu()->setItemVisible(AUTOSUSPEND_MENU_ID, false); + + HELP_SEPARATOR_MENU_ID = contextMenu()->insertSeparator(); + + help_menu = new TQPopupMenu(this, i18n("&Help").ascii()); + + help_menu->insertItem( SmallIcon("help", TQIconSet::Automatic), i18n("&tdepowersave Handbook"), + this, TQT_SLOT(slotHelp())); + help_menu->insertSeparator(); + help_menu->insertItem( i18n("&Report a bug ..."), this, TQT_SLOT(slotReportBug())); + help_menu->insertItem( SmallIcon("tdepowersave", TQIconSet::Automatic), + i18n("&About tdepowersave"), this, TQT_SLOT(slotAbout())); + + HELP_MENU = contextMenu()->insertItem(SmallIcon("help", TQIconSet::Automatic), + i18n("&Help"), help_menu); + + connect(this, TQT_SIGNAL(quitSelected()), this, TQT_SLOT(_quit())); + + kdDebugFuncOut(trace); +} + +void tdepowersave::resizeEvent ( TQResizeEvent * ) +{ + // Honor Free Desktop specifications that allow for arbitrary system tray icon sizes + loadIcon(true); + drawIcon(); +} + +/*! + * This funtion load and manipulate the icons for the kickerapplet-section. + * The redraw interval depends on \ref icon_set_colored and \ref BAT_icon_BG_intervall. + */ +void tdepowersave::redrawPixmap(){ + kdDebugFuncIn(trace); + + // if colored icon_background: normal redraw intervall is set off. + // Icon (only) redrawed every BAT_icon_BG_intervall + if (icon_set_colored) { + if (icon_state_changed) { + loadIcon(); + drawIcon(); + } + } + else { + loadIcon(); + drawIcon(); + } + + kdDebugFuncOut(trace); +} + +/*! + * Starts the configure dialog of tdepowersave. + */ +void tdepowersave::showConfigureDialog() { + kdDebugFuncIn(trace); + + if(!config_dialog_shown) { + if (settings->schemes.count() > 0){ + configDlg = new ConfigureDialog(config, hwinfo, settings); + configDlg->show(); + config_dialog_shown = true; + connect(configDlg, TQT_SIGNAL(destroyed()), this, TQT_SLOT(observeConfigDlg())); + connect(configDlg, TQT_SIGNAL(openHelp()), this, TQT_SLOT(slotHelp())); + connect(configDlg, TQT_SIGNAL(openKNotify()), this, TQT_SLOT(showConfigureNotificationsDialog())); + } + else { + KPassivePopup::message(i18n("WARNING"), i18n("Cannot find any schemes."), + SmallIcon("messagebox_warning", 20), this, + i18n("Warning").ascii(), 15000); + } + } else { + configDlg->setWindowState((configDlg->windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); + configDlg->setActiveWindow(); + } + + kdDebugFuncOut(trace); +} + +/*! + * Starts the notification configure dialog of tdepowersave. + */ +void tdepowersave::showConfigureNotificationsDialog() { + kdDebugFuncIn(trace); + + KNotifyDialog::configure(this); + + kdDebugFuncOut(trace); +} + +/*! + * Load the icons (from filesystem) for the kicker applet to \ref pixmap . + * To reduce the systemload the icons are only reloaded if \ref pixmap_name + * is changed. + */ +void tdepowersave::loadIcon(bool forceReload){ + kdDebugFuncIn(trace); + + TQString pixmap_name_tmp = "NONE"; + + BatteryCollection *primary = hwinfo->getPrimaryBatteries(); + + if ( !hwinfo->isOnline() ) { + pixmap_name_tmp = TQString("ERROR"); + } + else if (hwinfo->getAcAdapter() || primary->getBatteryState() == BAT_NONE) { + icon_set_colored = false; + + if (primary->getBatteryState() == BAT_NONE || (primary->getRemainingPercent() < 0 || + primary->getRemainingPercent() >= 99)) + pixmap_name_tmp = TQString("laptoppower"); + else + pixmap_name_tmp = TQString("laptopcharge"); + } + else { + switch(primary->getBatteryState()) { + case BAT_CRIT: + case BAT_LOW: + if (icon_BG_is_colored) pixmap_name_tmp = TQString("laptopbattery"); + else pixmap_name_tmp = TQString("laptopbatteryRED"); + icon_BG_is_colored = !icon_BG_is_colored; + icon_set_colored = true; + break; + case BAT_WARN: + if (icon_BG_is_colored) pixmap_name_tmp = TQString("laptopbattery"); + else pixmap_name_tmp = TQString("laptopbatteryORANGE"); + icon_BG_is_colored = !icon_BG_is_colored; + icon_set_colored = true; + break; + default: + // if battery is discharging and not in warning, low or critical state + pixmap_name_tmp = TQString("laptopbattery"); + icon_set_colored = false; + icon_BG_is_colored = false; + } + + if (icon_set_colored){ + icon_state_changed = false; + BAT_WARN_ICON_Timer->start(BAT_icon_BG_intervall, true); + } + } + + // reload icon only if new icon selected + if ((pixmap_name_tmp != pixmap_name) || (forceReload)) { + pixmap_name = pixmap_name_tmp; + if (pixmap_name.startsWith("ERROR")) { + pixmap = SmallIcon("laptoppower", width(), TDEIcon::DisabledState); + } + else + pixmap = SmallIcon(pixmap_name, width()); + } + + kdDebugFuncOut(trace); +} + + +/*! + * This function draw the battery-capacity (colored field) to the icon. + * Here also counted the white pixel in the icon-files. Since the icons are + * the same and white pixel only in the rectangle of the icon, the white pixel + * stored in \ref countWhiteIconPixel only one time. + */ +void tdepowersave::drawIcon(){ + kdDebugFuncIn(trace); + + BatteryCollection *primary = hwinfo->getPrimaryBatteries(); + + TQImage image = pixmap.convertToImage(); + int w = image.width(); + int h = image.height(); + int x, y; + countWhiteIconPixel = 0; + + if((pixmap_name.contains("laptopbattery") || pixmap_name.contains("charge")) && + countWhiteIconPixel == 0) { + for (x = 0; x < w; x++) + for (y = 0; y < h; y++) + if(TQColor(image.pixel(x, y)) == TQt::white) countWhiteIconPixel++; + } + + int c = (countWhiteIconPixel * primary->getRemainingPercent()) / 100; + + if (c > 0) { + uint ui; + TQRgb Rgb_set; + + if (hwinfo->getAcAdapter()) { + Rgb_set = tqRgb(0x00, 0xff, 0x00); //green + } + else { + switch(primary->getBatteryState()) { + case BAT_CRIT: + case BAT_LOW: + Rgb_set = tqRgb(0xff, 0x00, 0x00);//red + break; + case BAT_WARN: + Rgb_set = tqRgb(0xff, 0x55, 0x00); //orange + break; + default: + Rgb_set = tqRgb(0x00, 0xff, 0x00); //green + } + } + if (image.depth() <= 8) { + ui = image.numColors(); + image.setNumColors(ui + 1); + image.setColor(ui, Rgb_set); + } + ui = 0xff000000 | Rgb_set; + + for (y = h - 1; y >= 0; y--) { + for (x = 0; x < w ; x++) { + if(TQColor(image.pixel(x, y)) == TQt::white) { + image.setPixel(x, y, ui); + c--; + if (c <= 0) goto quit; + } + } + } + } +quit: + image = image.smoothScale(width(), height()); + fullIcon.convertFromImage(image); + setPixmap(fullIcon); + + kdDebugFuncOut(trace); +} + +/*! +* By this function we fill and update the Tooltip for the icon in the kicker applet. +* The content of the tooltip alway updated, if something change. +* \todo Check if the tooltip also updated if mouse \b is over the icon, if not we maybe +* should implement this.\n If it is possible we should update the tooltip permanently +* while the mouse cursor is over the widget +*/ +void tdepowersave::updateTooltip(){ + kdDebugFuncIn(trace); + + BatteryCollection *primary = hwinfo->getPrimaryBatteries(); + int percent = primary->getRemainingPercent(); + int minutes = primary->getRemainingMinutes(); + int charging_state = primary->getChargingState(); + + TQString tmp, num3; + num3.setNum(minutes % 60); + num3 = num3.rightJustify(2, '0'); + + if ( !hwinfo->isOnline() ){ + tmp = i18n("No information about battery and AC status available"); + } + else if (hwinfo->getAcAdapter()) { + if (percent == 100) tmp = i18n("Plugged in -- fully charged"); + // assume that no battery is there + else { + if ((percent < 0 && minutes < 0) || primary->getBatteryState() == BAT_NONE) { + tmp = i18n("Plugged in"); + } + else if (minutes > 0){ + if (charging_state == CHARGING) + tmp = i18n("Plugged in -- %1% charged (%2:%3 h until full " + "charged)").arg(percent).arg(minutes / 60).arg(num3); + else + tmp = i18n("Plugged in -- %1% charged (%2:%3 remaining hours)") + .arg(percent).arg(minutes / 60).arg(num3); + } + else if (charging_state == CHARGING && hwinfo->hasAPM()) { + tmp = i18n("Plugged in -- %1% charged").arg(percent); + } + else{ + if (percent == -1) tmp = i18n("Plugged in -- no battery"); + else tmp = i18n("Plugged in -- %1% charged").arg(percent); + } + } + } else{ + if (minutes >= 0){ + tmp = i18n("Running on batteries -- %1% charged (%2:%3 hours remaining)") + .arg(percent).arg(minutes / 60).arg(num3); + } + else { + tmp = i18n("Running on batteries -- %1% charged").arg(percent); + } + } + // add string whether battery is charging, but only if < 100% to avoid + // stupid tooltip message on machines which always with 100% and on AC + // are charging, as e.g. Sony Vaio FS vgn-fs115b + if (charging_state == CHARGING && percent < 100) + tmp += i18n(" -- battery is charging"); + + TQToolTip::add(this, tmp); + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT to starts the Yast2-power-management module. This called by the menuentry + * with ID \ref YAST_MODULE_MENU_ID, named "Start YaST2 Power Management Module". + * It create a new TDEProcess and execute "/sbin/yast2 power-management" with tdesu. + */ +void tdepowersave::do_config(){ + kdDebugFuncIn(trace); + + #ifdef ENABLE_YAST_ENTRY + delete yast2; + + yast2 = new TDEProcess; + *yast2 << "tdesu" << "--nonewdcop" << "/sbin/yast2" << "power-management"; + + connect(yast2, TQT_SIGNAL(processExited(TDEProcess *)), + TQT_SLOT(slotConfigProcessExited(TDEProcess *))); + if(!yast2->start(TDEProcess::NotifyOnExit)) + { + delete yast2; + yast2 = NULL; + } + + kdDebugFuncOut(trace); + #else + kdDebugFuncOut(trace); + return; + #endif +} + +/*! + * \b TQT_SLOT to open the tdepowersave help + */ +void tdepowersave::slotHelp() +{ + kapp->invokeHelp( "", "tdepowersave" ); +} + +/*! + * \b TQT_SLOT to open the tdepowersave About dialog + */ +void tdepowersave::slotAbout() +{ + TDEAboutApplication a( this ); + a.exec(); +} + +/*! + * \b TQT_SLOT to open the website to report bugs + */ +void tdepowersave::slotReportBug() +{ +#ifdef DISTRO_IS_SUSE + #ifdef DISTRO_IS_SLES_SLED + kapp->invokeBrowser("https://bugzilla.novell.com/"); + #else + kapp->invokeBrowser("http://en.opensuse.org/Submitting_Bug_Reports"); + #endif +#else + #ifdef DISTRO_IS_ALTLINUX + kapp->invokeBrowser("http://bugzilla.altlinux.org/"); + #else + #ifdef DISTRO_IS_UBUNTU + kapp->invokeBrowser("https://launchpad.net/distros/ubuntu/+bugs"); + #else + #ifdef DISTRO_IS_PARDUS + kapp->invokeBrowser("http://bugs.pardus.org.tr/"); + #else + kapp->invokeBrowser("http://sourceforge.net/tracker/?group_id=124576&atid=700009"); + #endif + #endif + #endif +#endif +} + +/*! + * \b TQT_SLOT to set the icon background on/off if battery is in critical, low or warning-state. Within + * this function we set \ref icon_state_changed to true and call \ref redrawPixmap() to redraw the + * kickerapplet icon and create a icon with blinking background. \n \n + * The slot called by the TQTimer \ref BAT_WARN_ICON_Timer . The interval of the timer is defined + * trough \ref BAT_icon_BG_intervall and starts here: \ref loadIcon() . + */ +void tdepowersave::do_setIconBG(){ + kdDebugFuncIn(trace); + + if (icon_set_colored) icon_state_changed = true; + redrawPixmap(); + + kdDebugFuncOut(trace); +} +/*! + * \b TQT_SLOT to enable/disable the autosuspend. + */ +void tdepowersave::do_setAutosuspend(){ + kdDebugFuncIn(trace); + + if(!contextMenu()->isItemChecked(AUTOSUSPEND_MENU_ID)) { + autoSuspend->stop(); + contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, true); + } + else { + if(settings->autoSuspend) { + contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, false); + setAutoSuspend(false); + } + else { + contextMenu()->setItemVisible(AUTOSUSPEND_MENU_ID, false); + contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, false); + contextMenu()->setItemVisible(AUTOSUSPEND_SEPARATOR_MENU_ID, false); + } + } + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT which called if the \ref configDlg is destroyed. We set within this SLOT + * \ref config_dialog_shown to false. + * TODO: check if we maybe should force here the current default scheme depending on the AC/battery state + */ +void tdepowersave::observeConfigDlg(){ + kdDebugFuncIn(trace); + + // reload general settings + settings->load_general_settings(); + // set the battery warning levels - all other general settings don't need to + // get set, since we check the settings only on events. + hwinfo->setPrimaryBatteriesWarningLevel(settings->batteryWarningLevel, + settings->batteryLowLevel, + settings->batteryCriticalLevel); + + // reload the maybe changed scheme settings + settings->load_scheme_settings( settings->currentScheme ); + // set the scheme + setSchemeSettings(); + + config_dialog_shown=false; + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT which called from \ref do_config() if the 'tdesu yast2' TDEProcess exited. + * This function control the return value and display if needed a errormessage on failure. + */ +void tdepowersave::slotConfigProcessExited(TDEProcess *proc){ + kdDebugFuncIn(trace); + + #ifdef ENABLE_YAST_ENTRY + if (proc->normalExit()){ + if (proc->exitStatus() != 0 && proc->exitStatus() != 16){ + KPassivePopup::message( i18n("WARNING"), + i18n("Could not start YaST Power Management Module. " + "Check if it is installed."), + SmallIcon("messagebox_warning", 20), this, + i18n("Warning"), 15000); + } + } + else{ + KPassivePopup::message( i18n("WARNING"), + i18n("Could not start YaST Power Management Module. " + "Check if it is installed."), + SmallIcon("messagebox_warning", 20), this, i18n("Warning"), 15000); + } + + kdDebugFuncOut(trace); + #else + kdDebugFuncOut(trace); + return; + #endif +} + +/*! + * \b TQT_SLOT to send the command for "suspend to disk" to HAL daemon. + * If there is a error while "suspend to disk" the user get e messagebox. + * This function need a running HAL daemon for "suspend to disk". + * \return boolean with the result of the operation + * \retval true if successful + * \retval false if command not supported or if powersaved not running + */ +bool tdepowersave::do_suspend2disk(){ + kdDebugFuncIn(trace); + + if (suspend.suspend2disk) { + if (suspend.suspend2disk_allowed || suspend.suspend2disk_allowed == -1) { + calledSuspend = SUSPEND2DISK; + if (!handleMounts(true)) { + kdWarning() << "Could not umount ..." << endl; + calledSuspend = -1; + kdDebugFuncOut(trace); + return false; + } + + if(settings->lockOnSuspend) { + display->lockScreen( settings->lockmethod ); + } + + autoSuspend->stop(); + autoDimm->stop(); + notifySuspend(calledSuspend); + bool ret = hwinfo->suspend(SUSPEND2DISK); + + if (ret) { + kdDebugFuncOut(trace); + return true; + } else { + KPassivePopup::message( i18n("WARNING"),i18n("Suspend to disk failed"), + SmallIcon("messagebox_warning", 20), this, + i18n("Warning").ascii(), 15000); + kdDebugFuncOut(trace); + return false; + } + } else { + KPassivePopup::message( i18n("WARNING"), + i18n("Suspend to disk disabled by administrator."), + SmallIcon("messagebox_warning", 20), + this, i18n("Warning").ascii(), 15000); + this->contextMenu()->setItemEnabled(SUSPEND2DISK_MENU_ID, false); + kdDebugFuncOut(trace); + return false; + } + } else { + kdWarning() << "This machine does not provide suspend2disk via HAL" << endl; + kdDebugFuncOut(trace); + return false; + } +} + +/*! + * \b TQT_SLOT to send the command for "suspend to RAM" to the HAL daemon. + * If there is a error while "suspend to RAM" the user get e messagebox. + * This function need a running HAL daemon for "suspend to RAM". + * \return boolean with the result of the operation + * \retval true if successful + * \retval false if command not supported or if powersaved not running + */ +bool tdepowersave::do_suspend2ram(){ + kdDebugFuncIn(trace); + + if (suspend.suspend2ram) { + if (suspend.suspend2ram_allowed || suspend.suspend2ram_allowed == -1) { + calledSuspend = SUSPEND2RAM; + if (!handleMounts(true)) { + kdWarning() << "Could not umount ..." << endl; + calledSuspend = -1; + kdDebugFuncOut(trace); + return false; + } + + if(settings->lockOnSuspend) { + display->lockScreen( settings->lockmethod ); + } + + autoSuspend->stop(); + autoDimm->stop(); + notifySuspend(calledSuspend); + bool ret = hwinfo->suspend(SUSPEND2RAM); + + if (ret) { + kdDebugFuncOut(trace); + return true; + } else { + KPassivePopup::message( i18n("WARNING"),i18n("Suspend to RAM failed"), + SmallIcon("messagebox_warning", 20), this, + i18n("Warning").ascii(), 15000); + kdDebugFuncOut(trace); + return false; + } + } else { + KPassivePopup::message( i18n("WARNING"), + i18n("Suspend to RAM disabled by administrator."), + SmallIcon("messagebox_warning", 20), this, + i18n("Warning").ascii(), 15000); + this->contextMenu()->setItemEnabled(SUSPEND2RAM_MENU_ID, false); + kdDebugFuncOut(trace); + return false; + } + } else { + kdWarning() << "This machine does not provide suspend2ram via HAL" << endl; + kdDebugFuncOut(trace); + return false; + } +} + +/*! + * \b TQT_SLOT to send the command for "stand-by" to the HAL daemon. + * If there is a error while "stand-by" the user get e messagebox. + * This function need a running HAL daemon for "stand-by". + * \return boolean with the result of the operation + * \retval true if successful + * \retval false if command not supported or if powersaved not running + */ +bool tdepowersave::do_standby(){ + kdDebugFuncIn(trace); + + if (suspend.standby) { + if (suspend.standby_allowed || suspend.standby_allowed == -1) { + calledSuspend = STANDBY; + if (!handleMounts(true)) { + kdWarning() << "Could not umount ..." << endl; + calledSuspend = -1; + kdDebugFuncOut(trace); + return false; + } + + if(settings->lockOnSuspend) { + display->lockScreen( settings->lockmethod ); + } + + autoSuspend->stop(); + autoDimm->stop(); + notifySuspend(calledSuspend); + bool ret = hwinfo->suspend(STANDBY); + + if (ret) { + kdDebugFuncOut(trace); + return true; + } else { + KPassivePopup::message( i18n("WARNING"),i18n("Standby failed"), + SmallIcon("messagebox_warning", 20), this, + i18n("Warning").ascii(), 15000); + kdDebugFuncOut(trace); + return false; + } + } else { + KPassivePopup::message( i18n("WARNING"),i18n("Standby disabled by administrator."), + SmallIcon("messagebox_warning", 20), this, + i18n("Warning").ascii(), 15000); + this->contextMenu()->setItemEnabled(STANDBY_MENU_ID, false); + kdDebugFuncOut(trace); + return false; + } + } else { + kdWarning() << "This machine does not provide suspend2ram via HAL" << endl; + kdDebugFuncOut(trace); + return false; + } +} + +/*! + * \b TQT_SLOT to send check if we should display the warning dialog and display + * the dialog if needed or call directly autosuspend after the signal + * \ref autosuspend::inactivityTimeExpired was recieved. + */ +void tdepowersave::do_autosuspendWarn() { + kdDebugFuncIn(trace); + + if (settings->autoSuspendCountdown && (settings->autoSuspendCountdownTimeout > 0)) { + // we have to display the warn dialog + if(!contextMenu()->isItemChecked(AUTOSUSPEND_MENU_ID)) { + TQString message; + + countdown = new countDownDialog(settings->autoSuspendCountdownTimeout); + + if(settings->autoInactiveAction == "Suspend to Disk") { + countdown->setPixmap("suspend2disk"); + } else if (settings->autoInactiveAction == "Suspend to RAM") { + countdown->setPixmap("suspend2ram"); + } else if (settings->autoInactiveAction == "Standby") { + countdown->setPixmap("standby"); + } else { + countdown->setPixmap("tdepowersave"); + } + + // TODO: rework this after translation round for openSUSE 10.3 ! + message = i18n("Inactivity detected.") + " " + + i18n("To stop the %1 press the 'Cancel' button before the countdown " + "expire.").arg(i18n("Autosuspend")) + "\n\n" + + i18n("The computer autosuspend in: "); + + countdown->setMessageText(message); + + connect(countdown, TQT_SIGNAL(dialogClosed(bool)), this, TQT_SLOT(do_autosuspend(bool))); + countdown->showDialog(); + } + } else { + // call directly autosuspend + do_autosuspend(false); + } + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT to send the related suspend command for autosuspend + * \param chancel boolean with info if the autosuspend should get chanceld + * \return boolean with the result of the operation + * \retval true if successful + * \retval false if command not supported or on any other error + * \todo add check if the requested command is supported befor send and + * add message for this case to tell that maybe changed config! + */ +bool tdepowersave::do_autosuspend(bool chancel) { + kdDebugFuncIn(trace); + + // TODO: check if this is really needed, it get called also on the suspend methodes + autoSuspend->stop(); + + if (!chancel) { + if(!settings->disableNotifications) { + KNotifyClient::event( this->winId(), "autosuspend_event", + i18n("System is going into suspend mode now")); + } + + if(settings->autoSuspend && !contextMenu()->isItemChecked(AUTOSUSPEND_MENU_ID)) { + if(settings->autoInactiveAction == "Suspend to Disk") { + return do_suspend2disk(); + } else if (settings->autoInactiveAction == "Suspend to RAM") { + return do_suspend2ram(); + } else if (settings->autoInactiveAction == "Standby") { + return do_standby(); + } else { + return false; + } + } else { + return false; + } + } else { + kdDebug() << "The autosuspend was chanceled (via the chancel dialog), start again." << endl; + setAutoSuspend(false); + return false; + } +} + +/*! + * \b TQT_SLOT to dimm the display down to the configured level if the signal + * \ref autodimm::inactivityTimeExpired was recieved. + * \param + * \return boolean with the result of the operation + * \retval true if successful + * \retval false else + */ +void tdepowersave::do_downDimm() { + kdDebugFuncIn(trace); + + if (hwinfo->supportBrightness()) { + if (!AUTODIMM_Timer->isActive()) { + int dimmToLevel = (int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->autoDimmTo/100.0)); + + // check if we really need to dimm down + if (dimmToLevel < hwinfo->getCurrentBrightnessLevel()) { + int steps = hwinfo->getCurrentBrightnessLevel() - dimmToLevel; + int timePerStep = (1500 / steps); + + autoDimmDown = true; + + AUTODIMM_Timer = new TQTimer(this); + connect(AUTODIMM_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_dimm())); + AUTODIMM_Timer->start(timePerStep, false); + } else { + kdWarning() << "Don't dimm down, current level is already lower than requested Level" << endl; + } + } else { + // wait until the timer is stopped, try later! + TQTimer::singleShot(1500, this, TQT_SLOT(do_downDimm())); + } + } + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT to dimm the display up to the configured level if the signal + * \ref autodimm::UserIsActiveAgain was recieved. + * \param + * \return boolean with the result of the operation + * \retval true if successful + * \retval false else + */ +void tdepowersave::do_upDimm() { + kdDebugFuncIn(trace); + + //NOTE we go back to the value of the scheme and not the last on, to reduce trouble with the scheme + + if (hwinfo->supportBrightness()) { + if (!AUTODIMM_Timer->isActive()) { + int dimmToLevel = (int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->brightnessValue/100.0)); + + // check if we really need to dimm up + if (dimmToLevel > hwinfo->getCurrentBrightnessLevel()) { + int steps = dimmToLevel - hwinfo->getCurrentBrightnessLevel(); + int timePerStep = (750 / steps); + + autoDimmDown = false; + + AUTODIMM_Timer = new TQTimer(this); + connect(AUTODIMM_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_dimm())); + AUTODIMM_Timer->start(timePerStep, false); + + // start autodimm again + setAutoDimm(false); + } else { + kdWarning() << "Don't dimm up, current level is already above requested Level" << endl; + } + } else { + // wait until the timer is stopped, try later! + TQTimer::singleShot(750, this, TQT_SLOT(do_downDimm())); + } + } + + kdDebugFuncOut(trace); +} + + +/*! + * \b TQT_SLOT to dimm the display down + * \return boolean with the result of the operation + * \retval true if successful + * \retval false else + */ +void tdepowersave::do_dimm() { + kdDebugFuncIn(trace); + + int current = hwinfo->getCurrentBrightnessLevel(); + + if (autoDimmDown) { + // dimm the display down + if (current > 0 && + current > ((int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->autoDimmTo/100.0))-1)) { + hwinfo->setBrightness((current -1) , -1); + } else { + AUTODIMM_Timer->stop(); + + // start checking if the user get active again + // NOTE: we start this here because the X-Server detect brightness changes as + // User activity --> FUCKING STUPID PIECE OF SHIT + autoDimm->startCheckForActivity(); + } + } else { + // dimm the display up + if (current < ((int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->brightnessValue/100.0))-1)) { + hwinfo->setBrightness((current +1) , -1); + } else { + AUTODIMM_Timer->stop(); + } + } + + kdDebugFuncOut(trace); +} + +/*! + * Function handle umount/remount external storage media before/after + * suspend. + * \param suspend boolean with info if the machine go into suspend or not + * \return result of the operation + * \retval true if all was successful + * \retval false if not + */ +bool tdepowersave::handleMounts( bool suspend ) { + if (trace) kdDebug() << funcinfo << "IN: " << "called suspend: " << suspend << endl; + + bool _ret = false; + TQString _errormsg; + + if (settings->unmountExternalOnSuspend) { + TQString _method; + DCOPRef dcop_ref = DCOPRef( "kded", "mediamanager" ); + + if (suspend) { + _method = "unmountAllSuspend()"; + } else { + _method = "remountAllResume()"; + } + DCOPReply reply = dcop_ref.call(_method.latin1()); + if ( reply.isValid() ) { + reply.get(_errormsg); + if (_errormsg.isEmpty()) { + kdDebugFuncOut(trace); + return true; + } else { + kdError() << "ERROR while umount/remount partitions: " << _errormsg << endl; + } + } else { + kdWarning() << "Could not umount external storage partitions." << endl; + } + + } else { + kdDebugFuncOut(trace); + return true; + } + + // this is only needed for suspend case and an error ... + // on resume a simple error msg should be enough + if (!_ret && suspend) { + // handle error case + TQString _msg; + TQString _e_msg; + TQString _suspend; + + if (!_errormsg.isEmpty()) { + _e_msg = _errormsg; + } else { + _e_msg = i18n("Could not call DCOP interface to umount external media."); + } + + // ugly: need qt-tags because mediamanager can return html formated strings !!! + _msg = "" + + i18n("Could not umount external media before suspend/standby. \n " + "(Reason: %1)\n \n Would you like to continue suspend/standby " + "anyway? \n(Warning: Continue suspend can cause data loss!)").arg(_e_msg) + + ""; + + _suspend = getSuspendString(calledSuspend); + + int answer = KMessageBox::questionYesNo( 0, _msg, + i18n("Error while prepare %1").arg(_suspend), + i18n("Suspend anyway"), i18n("Cancel suspend"), + "ignoreMountOnSuspend"); + + if (answer == KMessageBox::Yes) { + _ret = true; + } + } + + kdDebugFuncOut(trace); + return _ret; +} + +/*! + * Handle the event for the power button and call the related action. + */ +void tdepowersave::handlePowerButtonEvent( ) { + kdDebugFuncIn(trace); + + /* Only go to suspend on button event if we already resumed successful. + This should solve problems if we get may a event for the powerbutton + if there machine was waked up via power button. */ + if (calledSuspend == -1) { + handleActionCall(settings->powerButtonAction, settings->powerButtonActionValue); + } + + kdDebugFuncOut(trace); +} + +/*! + * Handle the event for the suspend2ram/sleep button and call the related action. + */ +void tdepowersave::handleSleepButtonEvent() { + kdDebugFuncIn(trace); + + // Only go to suspend on button event if we already resumed successful. + if (calledSuspend == -1) { + handleActionCall(settings->sleepButtonAction, -1); + } + + kdDebugFuncOut(trace); +} + +/*! + * Handle the event for the suspend2disk (hibernater) button and call the related action. + */ +void tdepowersave::handleS2DiskButtonEvent(){ + kdDebugFuncIn(trace); + + // Only go to suspend on button event if we already resumed successful. + if (calledSuspend == -1) { + handleActionCall(settings->s2diskButtonAction, -1); + } + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT to handle the lidclose event. If the screen get locked + * depends on the user specific settings. + * \param closed boolean with info if the lid is closed or not + */ +void tdepowersave::handleLidEvent( bool closed ){ + if (trace) kdDebug() << funcinfo << "IN: " << "Lid closed? " << closed << endl; + + if (closed) { + // get new general settings! This could maybe removed if we + // could be shure, that the settings are actuall + settings->load_general_settings(); + + // handle screen lock + if (settings->lidcloseAction < 0) { + if(settings->lockOnLidClose) { + if(!display->lockScreen( settings->lockmethod )) { + KPassivePopup::message( i18n("WARNING"), + i18n("Could not lock the screen. There may " + "be a problem with the selected \nlock " + "method or something else."), + SmallIcon("messagebox_warning", 20), this, + i18n("Warning").ascii(), 10000); + + } + } + if(settings->forceDpmsOffOnLidClose) { + display->forceDPMSOff(); + } + } else { + // handle lock action + if (hwinfo->currentSessionIsActive()) { + handleActionCall(settings->lidcloseAction, settings->lidcloseActionValue); + } else { + kdWarning() << "Session is not active, don't react on lidclose " + << "event with a action call (like e.g. Suspend)!" << endl; + } + } + + if(!settings->disableNotifications) + KNotifyClient::event( this->winId(), "lid_closed_event", i18n("The Lid was closed.")); + } else { + if(settings->forceDpmsOffOnLidClose) { + // reset the scheme settings to avoid problems related to call xset on lidclose + setSchemeSettings(); + } + + if (settings->lockOnLidClose) { + activateLoginScreen(); + } + + if(!settings->disableNotifications) + KNotifyClient::event( this->winId(), "lid_opened_event", i18n("The Lid was opened.")); + } + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT to show the login dialog if the desktop was locked before the suspend. + */ +void tdepowersave::activateLoginScreen(){ + kdDebugFuncIn(trace); + + // get new general settings! This could maybe removed if we + // could be shure, that the settings are actuall + settings->load_general_settings(); + + if(settings->timeToFakeKeyAfterLock >= 0) { + TQTimer::singleShot(settings->timeToFakeKeyAfterLock, display, TQT_SLOT(fakeShiftKeyEvent())); + } + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT to set the current suspend type for later use. + */ +void tdepowersave::setSuspendType( TQString suspendtype){ + kdDebugFuncIn(trace); + + suspendType = suspendtype; + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT which called if tdepowersave is exited by the user. In this case the user + * is asked through a yes/no box if "tdepowersave start automatically on log in" and the + * result is written to the KDE configfile. + */ +void tdepowersave::_quit (){ + kdDebugFuncIn(trace); + + // set the KDE-Settings back to user default + if(getenv("TDE_FULL_SESSION")) { + // first try to call the KDE method via DCOP to reset, if not fall back + if (!display->resetKDEScreensaver()) { + settings->load_kde(); + // reset to KDE screensaver settings + display->blankOnlyScreen(false); + if(!settings->kde->enabled) display->setScreenSaver(false); + else display->setScreenSaver(true); + + if(!settings->kde->displayEnergySaving) display->setDPMS(false); + else display->setDPMS(true); + + display->has_DPMS = display->setDPMSTimeouts( settings->kde->displayStandby, + settings->kde->displaySuspend, + settings->kde->displayPowerOff); + } + } + + // set, if this is a GNOME session, XScreensaver settings back to user default + TQString session = getenv("DESKTOP_SESSION"); + if(session.startsWith("gnome")) { + display->resetXScreensaver(); + } + + if(!settings->autostartNeverAsk) { + TQString tmp1 = i18n ("Start tdepowersave automatically when you log in?"); + int tmp2 = KMessageBox::questionYesNo ( 0, tmp1, i18n("Question"), + i18n("Start Automatically"), i18n("Do Not Start")); + config->setGroup("General"); + config->writeEntry ("Autostart", tmp2 == KMessageBox::Yes); + config->sync (); + } + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT called if the user select a 'CPU Frequency Policy' from the menu ( \ref CPUFRETQ_MENU_ID ). + */ +void tdepowersave::do_setSpeedPolicy(int menu_id){ + if (trace) kdDebug() << funcinfo << "IN: " << "menu_id/set policy to: " << menu_id << endl; + + if(!hwinfo->setCPUFreq((cpufreq_type)menu_id, settings->cpuFreqDynamicPerformance)) { + KPassivePopup::message(i18n("WARNING"), + i18n("CPU Freq Policy %1 could not be set.").arg(speed_menu->text(menu_id)), + SmallIcon("messagebox_warning", 20), this, i18n("Warning").ascii(), 10000); + } else { + hwinfo->checkCurrentCPUFreqPolicy(); + update(); + } + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT called if the user select a scheme from the menu. If there is any errormessage + * while try to set the selected scheme, the user get a messagebox with info. + */ +void tdepowersave::do_setActiveScheme( int i ){ + if (trace) kdDebug() << funcinfo << "IN: " << "set scheme to: " << i << endl; + + if(!settings->schemes[i].isEmpty() && (settings->schemes[i] != settings->currentScheme)) { + for (int x = 0; x < (int) scheme_menu->count(); x++){ + if (x == i) + scheme_menu->setItemChecked(x, true); + else + scheme_menu->setItemChecked(x, false); + } + settings->load_scheme_settings( settings->schemes[i]); + setSchemeSettings(); + notifySchemeSwitch(); + } else if (!settings->schemes[i]){ + KPassivePopup::message( i18n("WARNING"), + i18n("Scheme %1 could not be activated.").arg(scheme_menu->text(i)), + SmallIcon("messagebox_warning", 20), this, i18n("Warning").ascii(), 5000); + } + + kdDebugFuncOut(trace); +} + +/*! + * This function is invoked if something has to be updated. This including also menu entries. + * If the battery is in warning state (and powersave set pdaemon->send_battery_state_change_message) + * the function pop-up a messagebox. + */ +void tdepowersave::update(){ + kdDebugFuncIn(trace); + + int redraw_pixmap = 0; + TQString justMins; + + /* need to redraw pixmap in toolbar */ + if (hwinfo->update_info_ac_changed){ + redraw_pixmap = 1; + } + if (!hwinfo->isOnline()){ + this->contextMenu()->setItemVisible(SUSPEND2DISK_MENU_ID, false); + this->contextMenu()->setItemVisible(SUSPEND2RAM_MENU_ID, false); + this->contextMenu()->setItemVisible(STANDBY_MENU_ID, false); + this->contextMenu()->setItemVisible(SLEEP_SEPARATOR_MENU_ID, false); + this->contextMenu()->setItemVisible(SCHEME_SEPARATOR_MENU_ID, false); + this->contextMenu()->setItemVisible(SCHEME_MENU_ID, false); + this->contextMenu()->setItemVisible(HELP_SEPARATOR_MENU_ID, false); + this->contextMenu()->setItemVisible(CONFIGURE_ID, false); + this->contextMenu()->setItemVisible(CONFIGURE_EVENTS_ID, false); + if (!pixmap_name.startsWith("ERROR")) { + // dirty !!! but this work for the moment + hwinfo->update_info_cpufreq_policy_changed = true; + suspend = hwinfo->getSuspendSupport(); + redraw_pixmap = 1; + } + } + else{ + if (pixmap_name.startsWith("ERROR")) { + redraw_pixmap = 1; + hwinfo->update_info_cpufreq_policy_changed = true; + suspend = hwinfo->getSuspendSupport(); + } + this->contextMenu()->setItemVisible(SUSPEND2DISK_MENU_ID, true); + this->contextMenu()->setItemVisible(SUSPEND2RAM_MENU_ID, true); + this->contextMenu()->setItemVisible(STANDBY_MENU_ID, true); + this->contextMenu()->setItemVisible(SLEEP_SEPARATOR_MENU_ID, true); + this->contextMenu()->setItemVisible(SCHEME_SEPARATOR_MENU_ID, true); + this->contextMenu()->setItemVisible(SCHEME_MENU_ID, true); + this->contextMenu()->setItemVisible(HELP_SEPARATOR_MENU_ID, true); + this->contextMenu()->setItemVisible(CONFIGURE_ID, true); + this->contextMenu()->setItemVisible(CONFIGURE_EVENTS_ID, true); + + if (suspend.suspend2disk && (suspend.suspend2disk_allowed || + suspend.suspend2disk_allowed == -1)) { + this->contextMenu()->setItemEnabled(SUSPEND2DISK_MENU_ID, true); + } else { + if (!suspend.suspend2disk) + this->contextMenu()->setItemVisible(SUSPEND2DISK_MENU_ID, false); + else + this->contextMenu()->setItemEnabled(SUSPEND2DISK_MENU_ID, false); + } + + if (suspend.suspend2ram && (suspend.suspend2ram_allowed || + suspend.suspend2ram_allowed == -1)) { + this->contextMenu()->setItemEnabled(SUSPEND2RAM_MENU_ID, true); + } else { + if (!suspend.suspend2ram) + this->contextMenu()->setItemVisible(SUSPEND2RAM_MENU_ID, false); + else + this->contextMenu()->setItemEnabled(SUSPEND2RAM_MENU_ID, false); + } + + if (suspend.standby && (suspend.standby_allowed || suspend.standby_allowed == -1)) { + this->contextMenu()->setItemEnabled(STANDBY_MENU_ID, true); + } else { + if (!suspend.standby) + this->contextMenu()->setItemVisible(STANDBY_MENU_ID, false); + else + this->contextMenu()->setItemEnabled(STANDBY_MENU_ID, false); + } + } + + if (hwinfo->update_info_cpufreq_policy_changed == true){ + updateCPUFreqMenu(); + } + + BatteryCollection *primary = hwinfo->getPrimaryBatteries(); + + if (hwinfo->update_info_primBattery_changed == true){ + justMins.setNum(primary->getRemainingMinutes() % 60); + justMins = justMins.rightJustify(2, '0'); + + redraw_pixmap = 1; + hwinfo->update_info_primBattery_changed = false; + } + + updateSchemeMenu(); + + if (redraw_pixmap){ + redrawPixmap(); + } + + kdDebugFuncOut(trace); +} + +/*! + * This function is involved if the CPUFreqMenu must be updated. + */ +void tdepowersave::updateCPUFreqMenu(){ + kdDebugFuncIn(trace); + + if (hwinfo->supportCPUFreq() && hwinfo->isOnline() && hwinfo->isCpuFreqAllowed()) { + /* set CPU frequency menu entries *********/ + /* speed menu has id 3 in context menu */ + contextMenu()->setItemVisible(CPUFRETQ_MENU_ID, true); + contextMenu()->setItemEnabled(CPUFRETQ_MENU_ID, true); + contextMenu()->setItemVisible(CPUFRETQ_SEPARATOR_MENU_ID, true); + + switch (hwinfo->getCurrentCPUFreqPolicy()){ + case PERFORMANCE: + speed_menu->setItemChecked(PERFORMANCE, true); + speed_menu->setItemChecked(DYNAMIC, false); + speed_menu->setItemChecked(POWERSAVE, false); + break; + case DYNAMIC: + speed_menu->setItemChecked(PERFORMANCE, false); + speed_menu->setItemChecked(DYNAMIC, true); + speed_menu->setItemChecked(POWERSAVE, false); + break; + case POWERSAVE: + speed_menu->setItemChecked(PERFORMANCE, false); + speed_menu->setItemChecked(DYNAMIC, false); + speed_menu->setItemChecked(POWERSAVE, true); + break; + } + } else { + /* there never were policies */ + if (!speed_menu) { + return ; + } else if (hwinfo->supportCPUFreq() && (hwinfo->isCpuFreqAllowed() != 1)) { + contextMenu()->setItemEnabled(CPUFRETQ_MENU_ID, false); + contextMenu()->setItemVisible(CPUFRETQ_SEPARATOR_MENU_ID, true); + } else{ + /* there were CPU freq policies, but they are not accessible any more */ + /* delete speed_menu */ + contextMenu()->setItemVisible(CPUFRETQ_MENU_ID, false); + contextMenu()->setItemVisible(CPUFRETQ_SEPARATOR_MENU_ID, false); + } + } + + hwinfo->update_info_cpufreq_policy_changed = false; + + kdDebugFuncOut(trace); +} + +/*! + * The function used to update the scheme menu. A update is needed if + * if there is maybe new schemes or if the current scheme changed or switched + * By this way also set the settings for screensaver and other parameter + * related to the selected scheme. + */ +void tdepowersave::updateSchemeMenu(){ + kdDebugFuncIn(trace); + + if (settings->schemes.count() == 0 || !hwinfo->isOnline()){ + /* there never were schemes */ + if (!scheme_menu) + return ; + else{ + /* there were schemes, but they are not accessible any more */ + /* delete scheme_menu */ + scheme_menu->clear(); + contextMenu()->setItemVisible(SCHEME_MENU_ID, false); + contextMenu()->setItemVisible(SCHEME_SEPARATOR_MENU_ID, false); + return ; + } + } + + /* redraw all scheme entries ... */ + scheme_menu->clear(); + // clear the list of real scheme names + org_schemenames.clear(); + + org_schemenames = settings->schemes; + + int x = 0; + for ( TQStringList::iterator it = org_schemenames.begin(); it != org_schemenames.end(); ++it ) { + + TQString _t = *it; + + if ( *it == settings->ac_scheme ){ + scheme_menu->insertItem( SmallIcon("scheme_power", TQIconSet::Automatic), + i18n( ((TQString)*it).ascii() ), x, x); + } + else{ + if ( *it == settings->battery_scheme ){ + scheme_menu->insertItem(SmallIcon("scheme_powersave", TQIconSet::Automatic), + i18n( (*it).ascii() ), x, x); + } + else{ + if ((TQString)*it == "Acoustic"){ + scheme_menu->insertItem(SmallIcon("scheme_acoustic", + TQIconSet::Automatic), + i18n("Acoustic"), x, x); + } + else if ((TQString)*it == "Presentation"){ + scheme_menu->insertItem(SmallIcon("scheme_presentation", + TQIconSet::Automatic), + i18n("Presentation"), x, x); + + } + else if((TQString)*it == "AdvancedPowersave") { + scheme_menu->insertItem(SmallIcon("scheme_advanced_powersave", + TQIconSet::Automatic), + i18n( "Advanced Powersave" ), x, x); + } + else { + scheme_menu->insertItem(i18n( (*it).ascii() ), x, x); + } + } + } + + if ( *it == settings->currentScheme ) { + scheme_menu->setItemChecked(x, true); + } + ++x; + } + + if (x == 0 && scheme_menu){ + // this should not happen, scheme_list should have been NULL before + // now we'd have an empty menu ... + } + else{ + contextMenu()->setItemVisible(SCHEME_MENU_ID, true); + contextMenu()->setItemVisible(SCHEME_SEPARATOR_MENU_ID, true); + } + + kdDebugFuncOut(trace); +} + + +/*! + * Reimplemented eventhandler for mouse enterEvent. This is called if the mouse cursor + * enters the widget. In this case if the user move the mouse cursor over the tdepowersave + * trayicon. \n \n + * We use this event to update the Tooltip with all needed information. The time beetween + * the event and the automatically popup of the TQToolTip should be long enought to collect + * the needed values and add a updated Tooltip. + */ +void tdepowersave::enterEvent( TQEvent */*qee*/ ){ + + updateTooltip(); + +} + +/*! + * Event handler for mouse wheel events. If the system supports changing display + * brightness and changing brightness is enabled in the current scheme settings, + * this will raise the brightness by one level for wheel up events and lower the + * brightness by one level for wheel down events. + */ +void tdepowersave::wheelEvent (TQWheelEvent *qwe) +{ + kdDebugFuncIn(trace); + + if (!hwinfo->supportBrightness() && settings->brightness) + return; + + if (qwe->orientation () == Qt::Vertical) { + if (qwe->delta() > 0) { + do_brightnessUp(5); + } else { + do_brightnessDown(5); + } + } + + kdDebugFuncOut(trace); +} + +/*! + * Reimplemented eventhandler for mousePressEvents which is involved if the user click + * on the icon on the kickerapplet. This was written to guarantee that a click with the + * right and the left mousebutton activate the menu. In the future this can also used + * to popup maybe a other menu. + */ +void tdepowersave::mousePressEvent(TQMouseEvent *qme){ + kdDebugFuncIn(trace); + + KSystemTray::mousePressEvent(qme); + if (hwinfo->isOnline()) { + if (qme->button() == Qt::RightButton){ + // TODO check if maybe some rechecks needed + this->contextMenu()->exec(TQCursor::pos()); + } else if (qme->button() == Qt::LeftButton) { + showDetailedDialog(); + } + } + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT called if the detaileddialog is closed. With this we prevent open + * the dialog twice, use this function to reset the used variables. + */ +void tdepowersave::closedetaileddialog() { + detailedIsShown = false; +} + +/*! + * \b TQT_SLOT used to display messeges in tdepowersave. This function + * block all messeges which we have in tdepowersave! + */ +void tdepowersave::showErrorMessage( TQString msg ){ + kdDebugFuncIn(trace); + + if(settings->psMsgAsPassivePopup) { + KPassivePopup::message("tdepowersave", msg, SmallIcon("messagebox_warning", 20), + this, i18n("Warning").ascii(), 10000); + } else { + kapp->updateUserTimestamp(); + // KMessageBox::error( 0, msg); + KMessageBox::queuedMessageBox(0, KMessageBox::Error, msg); + } + + kdDebugFuncOut(trace); +} + + +/*! + * Use this function to set the SchemeSettings. This function currently set the + * e.g. the screensaver and dpms settings. Don't forget to call this function if + * a scheme is changed or if the settings changed. + */ +void tdepowersave::setSchemeSettings(){ + kdDebugFuncIn(trace); + + // --> check if there is a scheme set, if not, use defaults + if ( settings->currentScheme.isEmpty()) { + if (hwinfo->getAcAdapter()) { + settings->load_scheme_settings( settings->ac_scheme); + } else { + settings->load_scheme_settings( settings->battery_scheme); + } + } + + // call setPowerSave() depending on AC state + if (settings->callSetPowerSaveOnAC) { + if (hwinfo->getAcAdapter()) + hwinfo->setPowerSave(false); + else + hwinfo->setPowerSave(true); + } + + // --> set autosuspend settings + if(settings->autoSuspend) { + setAutoSuspend(false); + } else { + this->contextMenu()->setItemVisible(AUTOSUSPEND_MENU_ID, false); + this->contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, false); + this->contextMenu()->setItemVisible(AUTOSUSPEND_SEPARATOR_MENU_ID, false); + autoSuspend->stop(); + } + + // --> set autodimm settings + if (settings->autoDimm) { + setAutoDimm(true); + } else { + autoDimm->stop(); + } + + // --> set screensaver + if(settings->specSsSettings){ + if(settings->disableSs) display->setScreenSaver(false); + else { + display->setScreenSaver(true); + if(settings->blankSs) display->blankOnlyScreen(true); + else { + display->blankOnlyScreen(false); + } + } + + } // TODO: check if this really work !!! + else if(getenv("TDE_FULL_SESSION")) { + // try to reset the complete screensaver settings. Ff this fail, use own methodes + if (!display->resetKDEScreensaver()) { + settings->load_kde(); + // Always disable blankOnly screensaver setting (default). KDE does + // not provide a GUI to configure it and most likely we are the + // only ones messing with it + display->blankOnlyScreen(false); + + // reset to global screensaver settings + if(!settings->kde->enabled) display->setScreenSaver(false); + else { + display->setScreenSaver(true); + // What should we do with settings->kde->lock ? + // Maybe nothing ?! + } + } + } else if ((getenv("DESKTOP_SESSION") != NULL) && !strcmp(getenv("DESKTOP_SESSION"), "gnome")) { + // use this to set XScreensaver back to default settings this should + // also cover the DPMS settings for GNOME/XScreensaver + display->resetXScreensaver(); + } + + // --> set DPMS settings + if(settings->specPMSettings){ + // set the new DPMS settings + if(settings->disableDPMS) { + display->setDPMS(false); + } + else { + display->setDPMS(true); + display->has_DPMS = display->setDPMSTimeouts( settings->standbyAfter, + settings->suspendAfter, + settings->powerOffAfter); + } + } + else if(getenv("TDE_FULL_SESSION")){ + // try to reset the KDE screensaver/DPMS settings (if there are also + // no special screensaver settings) otherwise fall back and set values from files + if (!settings->specSsSettings && !display->resetKDEScreensaver()) { + settings->load_kde(); + // reset to global screensaver settings + if(!settings->kde->displayEnergySaving) { + display->setDPMS(false); + } + else { + display->setDPMS(true); + display->has_DPMS = display->setDPMSTimeouts( settings->kde->displayStandby, + settings->kde->displaySuspend, + settings->kde->displayPowerOff); + } + } + } + + // --> set brightness settings + if(settings->brightness && hwinfo->supportBrightness()) { + // set to given values + hwinfo->setBrightness (-1, settings->brightnessValue); + } + + // --> set CPU Freq settings + if(hwinfo->supportCPUFreq()) { + hwinfo->setCPUFreq( settings->cpuFreqPolicy, settings->cpuFreqDynamicPerformance); + } + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT which called to set and start the autosuspend monitoring. + * \param resumed boolean value which represent information if machine + * currently back from suspend/standby + */ +void tdepowersave::setAutoSuspend( bool resumed ){ + if (trace) kdDebug() << funcinfo << "IN: " << "resumed? " << resumed << endl; + + if(settings->autoInactiveActionAfter > 0 && settings->autoSuspend) { + int autoInactiveActionAfter = 0; + + if( settings->autoInactiveAction.startsWith("_NONE_")) { + autoSuspend->stop(); + return; + } + if (resumed) { + autoSuspend->stop(); + delete autoSuspend; + autoSuspend = new autosuspend(); + connect(autoSuspend, TQT_SIGNAL(inactivityTimeExpired()), this, + TQT_SLOT(do_autosuspendWarn())); + } + + if (settings->autoSuspendCountdown && (settings->autoSuspendCountdownTimeout > 0)) { + autoInactiveActionAfter = ((settings->autoInactiveActionAfter * 60) - + settings->autoSuspendCountdownTimeout); + } else { + autoInactiveActionAfter = settings->autoInactiveActionAfter * 60; + } + + if(settings->autoInactiveSBlistEnabled) { + autoSuspend->start( autoInactiveActionAfter, settings->autoInactiveSBlist ); + } + else { + autoSuspend->start( autoInactiveActionAfter, settings->autoInactiveGBlist ); + } + this->contextMenu()->setItemVisible(AUTOSUSPEND_SEPARATOR_MENU_ID, true); + this->contextMenu()->setItemVisible(AUTOSUSPEND_MENU_ID, true); + } + else { + // if autosuspend is not NULL: stop autosuspend + if (autoSuspend) { + autoSuspend->stop(); + } + + this->contextMenu()->setItemVisible(AUTOSUSPEND_MENU_ID, false); + this->contextMenu()->setItemVisible(AUTOSUSPEND_SEPARATOR_MENU_ID, false); + } + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT which called to set and start the autodimm monitoring. + * \param resumed boolean value which represent information if machine + * currently back from suspend/standby + */ +void tdepowersave::setAutoDimm( bool resumed ){ + if (trace) kdDebug() << funcinfo << "IN: " << "resumed? " << resumed << endl; + + if(settings->autoDimmAfter > 0 && settings->autoDimm) { + if(settings->autoDimmTo < 0) { + autoDimm->stop(); + kdWarning() << "Not allowed or set level for dimm" << endl; + } else { + if (resumed) { + // setup again + autoDimm->stop(); + delete autoDimm; + autoDimm = new autodimm(); + connect(autoDimm, TQT_SIGNAL(inactivityTimeExpired()), this, TQT_SLOT(do_downDimm())); + connect(autoDimm, TQT_SIGNAL(UserIsActiveAgain()), this, TQT_SLOT(do_upDimm())); + } + + if (settings->autoDimmSBlistEnabled) { + autoDimm->start(settings->autoDimmAfter * 60, settings->autoDimmSBlist); + } else { + autoDimm->start(settings->autoDimmAfter * 60, settings->autoDimmGBlist); + } + } + } else { + if (autoDimm) + autoDimm->stop(); + } + + kdDebugFuncOut(trace); +} + +// -------- start KNotify functions ------------- // + +/*! + * \b TQT_SLOT called if a battery warning state reached and related signal recieved. + * Here we emit the related KNotify event, if not disabled. + * \param type integer with the type of the battery + * \param state integer represent the reached battery state + */ +void tdepowersave::notifyBatteryStatusChange ( int type, int state ) { + if (trace) kdDebug() << funcinfo << "IN: " << "type: " << type << "state: " << state << endl; + + + if (type == BAT_PRIMARY) { + BatteryCollection *primary = hwinfo->getPrimaryBatteries(); + int min = primary->getRemainingMinutes(); + + if (primary->getChargingState() == CHARGING) { + kdDebug() << "tdepowersave::notifyBatteryStatusChange: Battery is charging, ignore event" << endl; + return; + } + if (hwinfo->getAcAdapter()) { + // the machine is on AC, no need to inform about battery state, + // this is maybe only a race condition with not directly actuall + // charge state + kdDebug() << "tdepowersave::notifyBatteryStatusChange: Machine is on AC, ignore event" << endl; + kdDebugFuncOut(trace); + return; + } + + switch (state) { + case BAT_WARN: + if (!settings->disableNotifications) + KNotifyClient::event(this->winId(), "battery_warning_event", + i18n("Battery state changed to WARNING -- remaining time: " + "%1 hours and %2 minutes.").arg(min/60).arg(min%60)); + // set/call related actions + handleActionCall(settings->batteryWarningLevelAction, + settings->batteryWarningLevelActionValue); + break; + case BAT_LOW: + if (!settings->disableNotifications) + KNotifyClient::event(this->winId(), "battery_low_event", + i18n("Battery state changed to LOW -- remaining time: " + "%1 hours and %2 minutes.").arg(min/60).arg(min%60)); + // set/call related actions + handleActionCall(settings->batteryLowLevelAction, + settings->batteryLowLevelActionValue); + break; + case BAT_CRIT: + // handle carefully: + if (settings->batteryCriticalLevelAction == GO_SHUTDOWN) { + if (!settings->disableNotifications) + KNotifyClient::event(this->winId(), "battery_critical_event", + i18n("Battery state changed to CRITICAL -- " + "remaining time: %1 hours and %2 minutes.\n" + "Shut down your system or plug in the power " + "cable immediately. Otherwise the machine\n" + "will go shutdown in 30 seconds") + .arg(min/ 60).arg(min%60)); + + TQTimer::singleShot(30000, this, TQT_SLOT(handleCriticalBatteryActionCall())); + } else { + if (!settings->disableNotifications) + KNotifyClient::event(this->winId(), "battery_critical_event", + i18n("Battery state changed to CRITICAL -- " + "remaining time: %1 hours and %2 minutes.\n" + "Shut down your system or plug in the power " + "cable immediately.") + .arg(min/ 60).arg(min%60)); + + handleActionCall(settings->batteryCriticalLevelAction, + settings->batteryCriticalLevelActionValue); + } + break; + default: + break; + } + } else { + // TODO: add some code later for the other batteries + } + + kdDebugFuncOut(trace); +} + + +/*! + * Function to call the action for battery critical event. This is ugly, but + * because of TQTimer::singleShot() can't take param ... + * NOTE: Use this only for SHUTDOWN atm + */ +void tdepowersave::handleCriticalBatteryActionCall () { + kdDebugFuncIn(trace); + + handleActionCall(GO_SHUTDOWN, settings->batteryCriticalLevelActionValue, true, true); + + kdDebugFuncOut(trace); +} + +/*! + * Function to set a special action for a battery warning level. + * \param action integer with the type of the action from \ref action + * \param value integer value of the action as e.g. a brightness level + * \param checkAC bool if there should be a check for AC state befor call the action + */ +void tdepowersave::handleActionCall ( action action, int value , bool checkAC, bool batWarnCall ) { + if (trace) kdDebug() << funcinfo << "IN: " << "action: " << action << "value: " << value + << "checkAC: " << checkAC << endl; + + if (hwinfo->currentSessionIsActive()) { + switch (action) { + case GO_SHUTDOWN: + // to be shure if we really need the shutdown + if ((checkAC && !hwinfo->getAcAdapter()) || !checkAC ) { + DCOPRef shutdown = DCOPRef( "ksmserver", "ksmserver" ); + shutdown.send("logout", 0, 2, 2); + } + break; + case LOGOUT_DIALOG: + { + DCOPRef shutdown = DCOPRef( "ksmserver", "ksmserver" ); + shutdown.send("logout", 1, 2, 2); + } + break; + case GO_SUSPEND2RAM: + TQTimer::singleShot(100, this, TQT_SLOT(do_suspend2ram())); + break; + case GO_SUSPEND2DISK: + TQTimer::singleShot(100, this, TQT_SLOT(do_suspend2disk())); + break; + case BRIGHTNESS: + hwinfo->setBrightness( -1, value ); + break; + case CPUFRETQ_POWERSAVE: + hwinfo->setCPUFreq( POWERSAVE ); + break; + case CPUFRETQ_DYNAMIC: + hwinfo->setCPUFreq( DYNAMIC, settings->cpuFreqDynamicPerformance ); + break; + case CPUFRETQ_PERFORMANCE: + hwinfo->setCPUFreq( PERFORMANCE ); + break; + case SWITCH_SCHEME: // not supported atm + case UNKNOWN_ACTION: + case NONE: + default: + kdError() << "Could not set the requested Action: " << action << endl; + break; + } + } else if (batWarnCall) { + if (!hwinfo->isPolicyPowerIfaceOwned()) { + switch (action) { + case GO_SHUTDOWN: + // to be shure if we really need the shutdown + if ((checkAC && !hwinfo->getAcAdapter()) || !checkAC ) { + DCOPRef shutdown = DCOPRef( "ksmserver", "ksmserver" ); + shutdown.send("logout", 0, 2, 2); + } + break; + default: + kdError() << "Could not call requested action, inactive session: " << action << endl; + break; + } + } + } else { + kdError() << "Could not set the requested action, session is inactiv: " << action << endl; + } + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT called if ac stated changed. Here we emit the related KNotify event. + * and switch to the AC/battery scheme depending on the state of AC + * \param acstate boolean represent the state of AC (true == AC plugged in ...) + */ +void tdepowersave::handleACStatusChange ( bool acstate , bool notifyEvent ) { + if (trace) kdDebug() << funcinfo << "IN: " << "acstate: " << acstate << "notifyEvent: " << notifyEvent << endl; + + int index; + + if (hwinfo->currentSessionIsActive()) { + + // emit notify event + if(notifyEvent && !settings->disableNotifications) { + if (acstate) { + KNotifyClient::event(this->winId(), "plug_event", i18n("AC adapter plugged in")); + } else { + KNotifyClient::event(this->winId(), "unplug_event", i18n("AC adapter unplugged")); + } + } + + // handle switch to AC/battery default scheme + if (acstate) { + index = settings->schemes.findIndex(settings->ac_scheme); + } else { + index = settings->schemes.findIndex(settings->battery_scheme); + } + + if (index != -1) + do_setActiveScheme(index); + + // update applet + update(); + } + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT called if scheme switched. Here we emit the related KNotify events + * if they are not disabled. + */ +void tdepowersave::notifySchemeSwitch() { + kdDebugFuncIn(trace); + + if(!settings->disableNotifications) { + TQString _scheme = settings->currentScheme; + TQString eventType; + + if( _scheme != "Performance" && _scheme != "Powersave" && _scheme != "Acoustic" && + _scheme != "Presentation" && _scheme != "AdvancedPowersave" ) + eventType = "scheme_Unknown"; + else + eventType = "scheme_" + _scheme; + + KNotifyClient::event( this->winId(), eventType, + i18n("Switched to scheme: %1").arg(i18n(_scheme.ascii())).ascii()); + } + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT called if the machine suspend. Here we emit the related KNotify events + * if they are not disabled. + */ +void tdepowersave::notifySuspend( int suspendType ) { + kdDebugFuncIn(trace); + + if(!settings->disableNotifications) { + switch (suspendType) { + case SUSPEND2DISK: + KNotifyClient::event( this->winId(), "suspend2disk_event", + i18n("System is going into %1 now."). + arg(i18n("Suspend to Disk"))); + break; + case SUSPEND2RAM: + KNotifyClient::event( this->winId(), "suspend2ram_event", + i18n("System is going into %1 now."). + arg(i18n("Suspend to RAM"))); + break; + case STANDBY: + KNotifyClient::event( this->winId(), "standby_event", + i18n("System is going into %1 now."). + arg(i18n("Standby"))); + break; + default: + break; + } + } + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT called to independent handleResumeSignal() from event loop and + * to avoid problems with the QT3 D-Bus bindings + */ +void tdepowersave::forwardResumeSignal( int result ) { + if (trace) kdDebug() << funcinfo << "IN: " << "result: " << result << endl; + + resume_result = result; + + TQTimer::singleShot(100, this, TQT_SLOT(handleResumeSignal())); + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT called if the machine suspend. Here we emit the related KNotify events + * if they are not disabled. + */ +void tdepowersave::handleResumeSignal() { + kdDebugFuncIn(trace); + + // fake key to show the login dialog if we locked the screen + if(settings->lockOnSuspend) { + activateLoginScreen(); + } + + // reset autosuspend and autodimm + setAutoSuspend(true); + setAutoDimm(true); + + // reset the CPU Freq Policy ... for more see https://bugzilla.novell.com/show_bug.cgi?id=223164 + if(hwinfo->supportCPUFreq()) { + hwinfo->setCPUFreq( settings->cpuFreqPolicy, settings->cpuFreqDynamicPerformance ); + } + + if(!settings->disableNotifications) { + switch (calledSuspend) { + case SUSPEND2DISK: + KNotifyClient::event( this->winId(), "resume_from_suspend2disk_event", + i18n("System is resumed from %1.").arg( + i18n("Suspend to Disk"))); + break; + case SUSPEND2RAM: + KNotifyClient::event( this->winId(), "resume_from_suspend2ram_event", + i18n("System is resumed from %1.").arg( + i18n("Suspend to RAM"))); + break; + case STANDBY: + KNotifyClient::event( this->winId(), "resume_from_standby_event", + i18n("System is resumed from %1.").arg( + i18n("Standby"))); + break; + default: + kdError() << "called suspend type unknown" << endl; + break; + + } + } + + // handle result of the resume/suspend + // 1 is a valid return code; don't error out when it is received! + if ((resume_result == 0) || (resume_result == 1) || (resume_result == INT_MAX)) { + if ( resume_result == INT_MAX ) + kdWarning() << "Unknown if we successful resumed, look like a D-Bus timeout since " + << "elapsed time between suspend and resume is higher than 6 hours" << endl; + + // successful resumed ... remount only in this case + if (!handleMounts(false)) { + KPassivePopup::message( i18n("WARNING"), + i18n("Could not remount (all) external storage" + " media."), SmallIcon("messagebox_warning", 20), + this, i18n("Warning").ascii(), 15000); + } + } else { + kdError() << "Unknown error while suspend. Errorcode: " << resume_result << endl; + TQString msg; + + msg = i18n("An unknown error occurred while %1. The errorcode is: '%2'"). + arg(getSuspendString(calledSuspend)).arg(resume_result); + +#if defined(DISTRO_IS_SUSE) || defined(DISTRO_IS_SLES_SLED) || defined(DISTRO_IS_PARDUS) + // okay we know this system use pm-utils and log is under /var/log/pm-suspend.log + msg += "\n" + i18n("Do you want to have a look at the log file?"); + int answer = KMessageBox::questionYesNo(0, msg, i18n("Error while %1"). + arg(getSuspendString(calledSuspend))); + if (answer == KMessageBox::Yes) { + #if defined(DISTRO_IS_SLES_SLED) + switch (calledSuspend) { + case SUSPEND2DISK: + logview = new LogViewer ("/var/log/suspend2disk.log"); + logview->show(); + break; + case SUSPEND2RAM: + logview = new LogViewer ("/var/log/suspend2ram.log"); + logview->show(); + break; + case STANDBY: + logview = new LogViewer ("/var/log/standby.log"); + logview->show(); + break; + default: + break; + } + #else + logview = new LogViewer ("/var/log/pm-suspend.log"); + logview->show(); + #endif + } +#else + KMessageBox::error(0, msg, i18n("Error while %1").arg(getSuspendString(calledSuspend))); +#endif + } + // set back ... suspend is handled + calledSuspend = -1; + resume_result = 0; + + kdDebugFuncOut(trace); +} + +/*! + * \b TQT_SLOT called if the state of the current session change + * \param state boolean represent the state of the session + * TODO: fix scheme handling + * TODO: fix critical battery situations (see the todo file in the source) + */ +void tdepowersave::handleSessionState (bool state) { + kdDebugFuncIn(trace); + + if (state) { + // session is active again + if (settings->autoSuspend) disableAutosuspend(false); + if (settings->autoDimm) setAutoDimm(false); + /* handle may missed/not set AC status changes while the + session was inactive and set them to the default schemes ?! */ + handleACStatusChange(hwinfo->getAcAdapter(), false); + + } else { + // session is now inactive + if (settings->autoSuspend) disableAutosuspend(true); + if (settings->autoDimm) autoDimm->stop(); + } + + kdDebugFuncOut(trace); +} + +// -------- end KNotify functions ------------- // +// ------------ helper functions -------------- // + +/*! + * Helper function to get a i18n name for a suspend type. + * \param type Integer value with the suspend type + * \return TQString with the translated name or NULL if it fail + */ +TQString tdepowersave::getSuspendString (int type) { + kdDebugFuncIn(trace); + + switch (type) { + case SUSPEND2DISK: + return i18n("Suspend to Disk"); + break; + case SUSPEND2RAM: + return i18n("Suspend to RAM"); + break; + case STANDBY: + return i18n("Standby"); + break; + default: + return TQString(); + } + + kdDebugFuncOut(trace); +} + +// --------- end helper functions ------------- // +// ------------ DCOP functions ---------------- // + +/*! + * DCOP Interface funtion to lock the screen with the userdefined methode. + * \return boolean with the result of locking the screen + * \retval true if locking the screen was successful + * \retval false if locking the screen failed or the user don't wan't to lock + */ +bool tdepowersave::lockScreen(){ + kdDebugFuncIn(trace); + + settings->load_general_settings(); + + return display->lockScreen( settings->lockmethod ); + + kdDebugFuncOut(trace); +} + +/*! + * DCOP Interface funtion to return the name of the current powersave scheme. + * \return TQString with the name of the current scheme + */ +TQString tdepowersave::currentScheme (){ + kdDebugFuncIn(trace); + + if(hwinfo->isOnline()) { + return settings->currentScheme; + } else { + return "ERROR: D-Bus and/or HAL not running"; + } + + kdDebugFuncOut(trace); +} + +/*! + * DCOP Interface funtion to return the name of the current cpuFreqPolicy. + * \return TQString with the name of the current cpuFreqPolicy + */ +TQString tdepowersave::currentCPUFreqPolicy() { + kdDebugFuncIn(trace); + + if(hwinfo->isOnline()) { + TQString _cpuFreq = ""; + switch (hwinfo->getCurrentCPUFreqPolicy()){ + case PERFORMANCE: + _cpuFreq = "PERFORMANCE"; + break; + case DYNAMIC: + _cpuFreq = "DYNAMIC"; + break; + case POWERSAVE: + _cpuFreq = "POWERSAVE"; + break; + default: + _cpuFreq = "UNKNOWN"; + break; + } + return _cpuFreq; + } else { + return "ERROR: HAL or/and DBus not running"; + } + + kdDebugFuncOut(trace); +} + +/*! + * DCOP Interface funtion to send a list with the allowed + * CPU Frequency states. + * \return TQStringList with the supported CPUFreq states + */ +TQStringList tdepowersave::listCPUFreqPolicies() { + kdDebugFuncIn(trace); + + TQStringList ret_list; + if (hwinfo->isCpuFreqAllowed()) { + ret_list.append("PERFORMANCE"); + ret_list.append("DYNAMIC"); + ret_list.append("POWERSAVE"); + } + else { + ret_list.append("NOT SUPPORTED"); + } + + kdDebugFuncOut(trace); + return ret_list; +} + +/*! + * DCOP Interface funtion to set the current CPUFreq policy + * \param policy TQString with the policy to set, only values from + * list_CPUFreqPolicies are allowed (except "NOT SUPPORTED") + * \return boolean with the result of set the requested CPUFreq policy + * \retval true if successful set + * \retval false if not supported or any other failure + */ +bool tdepowersave::do_setCPUFreqPolicy( TQString policy ) { + if (trace) kdDebug() << funcinfo << "IN: " << "policy: " << policy << endl; + + + bool ret = true; + /* + if (hwinfo->isCpuFreqAllowed() && hwinfo->isOnline()) { + if (policy == "PERFORMANCE") { + hwinfo->setCPUFreq(PERFORMANCE); + } else if (policy == "DYNAMIC") { + hwinfo->setCPUFreq(DYNAMIC, settings->cpuFreqDynamicPerformance); + } else if (policy == "POWERSAVE") { + hwinfo->setCPUFreq(POWERSAVE); + } else { + kdDebugFuncOut(trace); + ret = false; + } + } else { + ret = false; + } + */ + kdDebugFuncOut(trace); + return ret; +} + +/*! + * DCOP Interface funtion to send a list with the supported and enabled + * sleeping states. + * \return TQStringList with the supported spleeping states + */ +TQStringList tdepowersave::allowed_sleepingStates(){ + kdDebugFuncIn(trace); + + TQStringList sleepList; + if(hwinfo->isOnline()) { + if (suspend.suspend2disk && (suspend.suspend2disk_allowed || + suspend.suspend2disk_allowed == -1)){ + sleepList.append("suspendToDisk"); + } + if (suspend.suspend2ram && (suspend.suspend2ram_allowed || + suspend.suspend2ram_allowed == -1)){ + sleepList.append("suspendToRAM"); + } + if (suspend.standby && (suspend.standby_allowed || suspend.standby_allowed == -1)){ + sleepList.append("standBy"); + } + if(sleepList.isEmpty()){ + sleepList.append("NO_SLEEPING_STATES_SUPPORTED"); + } + } + else { + sleepList.append("ERROR: D-Bus and/or HAL not running"); + } + + kdDebugFuncOut(trace); + return sleepList; +} + +/*! + * DCOP Interface funtion to send a list with the all schemes. + * \return TQStringList with all schemes + */ +TQStringList tdepowersave::listSchemes(){ + kdDebugFuncIn(trace); + + TQStringList _schemeList; + if(hwinfo->isOnline()) { + if (settings->schemes.count() > 0){ + _schemeList = settings->schemes; + } + } + else { + _schemeList.append("ERROR: D-Bus and/or HAL not running"); + } + + kdDebugFuncOut(trace); + return _schemeList; +} + + +/*! + * DCOP Interface funtion to set the current scheme. + * \return boolean with the result of set the requested scheme + * \retval false if failed (e.g. scheme is not in the list) + * \retval true if scheme found and set + * \param _scheme TQString with the scheme to set, scheme should be + * named as list from list_schemes() + */ +bool tdepowersave::do_setScheme( TQString /*_scheme*/ ) { + kdDebugFuncIn(trace); + +/* int index; + index = settings->schemes.findIndex(_scheme); + + if (index != -1) { + do_setActiveScheme(index); + kdDebugFuncOut(trace); + return true; + } + else { + kdDebugFuncOut(trace); + return false; + } +*/ + kdDebugFuncOut(trace); + return false; +} + +/*! + * DCOP Interface funtion to send the suspend to disk command to powersave. + * \return boolean with the result of calling do_suspend2disk() + * \retval true if successful + * \retval false if not supported or powersaved not running + */ +bool tdepowersave::do_suspendToDisk(){ + kdDebugFuncIn(trace); + kdDebugFuncOut(trace); + return do_suspend2disk(); +} + +/*! + * DCOP Interface funtion to send the suspend to disk command to powersave. + * \return boolean with the result of calling do_suspend2ram() + * \retval true if successful + * \retval false if not supported or powersaved not running + */ +bool tdepowersave::do_suspendToRAM(){ + kdDebugFuncIn(trace); + kdDebugFuncOut(trace); + return do_suspend2ram(); +} + +/*! + * DCOP Interface funtion to send the suspend to disk command to powersave. + * \return boolean with the result of calling do_standby() + * \retval true if successful + * \retval false if not supported or powersaved not running + */ +bool tdepowersave::do_standBy(){ + kdDebugFuncIn(trace); + kdDebugFuncOut(trace); + return do_standby(); +} + +//! dcop function to set the brightness up +bool tdepowersave::do_brightnessUp(int percentageStep) { + kdDebugFuncIn(trace); + + bool retval = false; + + if(hwinfo->isOnline()) { + retval = hwinfo->setBrightnessUp(percentageStep); + } + + kdDebugFuncOut(trace); + return retval; +} + +//! dcop function to set the brightness down +bool tdepowersave::do_brightnessDown(int percentageStep) { + kdDebugFuncIn(trace); + + bool retval = false; + + if(hwinfo->isOnline()) { + retval = hwinfo->setBrightnessDown(percentageStep); + } + + kdDebugFuncOut(trace); + return retval; +} + + +/*! + * DCOP Interface funtion to stop/start the Autosuspend + * \param disable boolean which tell if the autosuspend should be stopped (true) + * or started (false). + */ +void tdepowersave::disableAutosuspend( bool disable ){ + kdDebugFuncIn(trace); + + if(settings->autoSuspend && settings->autoInactiveActionAfter > 0) { + if (disable) { + if ( !contextMenu()->isItemChecked(AUTOSUSPEND_MENU_ID)) { + autoSuspend->stop(); + contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, true); + } + } + else { + contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, false); + setAutoSuspend(true); + } + } + + kdDebugFuncOut(trace); +} + +/*! + * DCOP Interface funtion to open/close the detailed dialog. + */ +void tdepowersave::showDetailedDialog( ){ + kdDebugFuncIn(trace); + + if (detailedIsShown) { + detailedDlg->close(); + delete(detailedDlg); + closedetaileddialog(); + return; + } + + detailedDlg = new detaileddialog(hwinfo, &fullIcon, settings); + + if (detailedDlg) { + detailedDlg->show(); + detailedIsShown = true; + } + + connect(detailedDlg, TQT_SIGNAL(destroyed()), this, TQT_SLOT(closedetaileddialog())); + + kdDebugFuncOut(trace); +} + +/*! + * DCOP Interface funtion to open the configure dialog. + * \return boolean with the result of open the dialog + * \retval false if failed (e.g. D-Bus or HAL is not running) + * \retval true if correct opend + */ +bool tdepowersave::openConfigureDialog (){ + kdDebugFuncIn(trace); + + if(hwinfo->isOnline()) { + showConfigureDialog(); + kdDebugFuncOut(trace); + return config_dialog_shown; + } else { + kdDebugFuncOut(trace); + return false; + } +} + +/*! + * DCOP Interface funtion to find out if the current + * scheme manages DPMS + * \return boolean + * \retval false if current scheme does not overwrite DPMS + * \retval true if current scheme does + */ +bool tdepowersave::currentSchemeManagesDPMS () { + kdDebugFuncIn(trace); + + return settings->specPMSettings; + + kdDebugFuncOut(trace); +} + + +//! dcop funtion to get the current brightness level +int tdepowersave::brightnessGet() { + kdDebugFuncIn(trace); + + int retval = -1; + + if (hwinfo->supportBrightness()) { + retval = (int)(((float)hwinfo->getCurrentBrightnessLevel() / (float)hwinfo->getMaxBrightnessLevel()-1) * 100.0); + } + + kdDebugFuncOut(trace); + + return retval; +} + +#include "tdepowersave.moc" diff --git a/src/tdepowersave.desktop b/src/tdepowersave.desktop new file mode 100644 index 0000000..61ad5b8 --- /dev/null +++ b/src/tdepowersave.desktop @@ -0,0 +1,68 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=tdepowersave +Name[xx]=xxtdepowersavexx +Name[de]=TDEPowersave +Name[es]=TDEPowersave +Name[fr]=TDEPowersave +Name[it]=TDEPowersave +Name[ja]=TDEPowersave +Name[pt_BR]=TDEPowersave +Name[ru]=TDEPowersave +Name[sv]=TDEPowersave +Name[zh_CN]=TDEPowersave +Name[zh_TW]=TDEPowersave +GenericName=Battery Monitor +Exec=tdepowersave --force-acpi-check +Icon=tdepowersave +Type=Application +Comment=Battery monitor and general power management +Comment[bg]=Монитор за батерията и основно управление на енергията +GenericName[bg]=Монитор за батерията +Comment[cs]=Sledování stavu baterií a správa napájení +GenericName[cs]=Monitor baterie +GenericName[de]=Akkuüberwachung +Comment[de]=Akkuüberwachung und allgemeine Energieverwaltung +GenericName[el]=Παρακολούθηση Μπαταρίας +GenericName[es]=Monitor de carga de la batería +Comment[es]=Monitor de batería y gestión general de la energía +Comment[fi]=Akkumonitori ja yleinen virranhallinta +GenericName[fi]=Akkumonitori +Comment[fr]=Moniteur de batterie et gestion de l'alimentation +GenericName[fr]=Moniteur de batterie +GenericName[hu]=Akkumulátorfigyelő +Comment[it]=Monitor della batteria e gestione generale dell'alimentazione +GenericName[it]=Monitor della batteria +Comment[km]=កមមវធ<200b>តរតពនតយ<200b>ថម នង គរបគរង<200b>ថាមពល<200b>ទទៅ +GenericName[km]=កមមវធ<200b>តរតពនតយ<200b>ថម +Comment[nb]=Batteriovervåking og generell strømstyring +GenericName[nb]=Batteriovervåker +GenericName[nl]=Batterijmonitor +GenericName[ja]=バッテリモニタ +Comment[ja]=バッテリモニタと一般電源管理 +Name[pa]=ਕ-ਊਰਜਾ ਸਭਾਲ +GenericName[pa]=ਬਟਰੀ ਦਰਸ਼ਕ +Comment[pl]=Monitor stanu baterii i ogólne zarządzanie energią +GenericName[pl]=Monitor baterii +Comment[pt]=Monitor de bateria e gestor global de energia +GenericName[pt]=Monitor de Bateria +Comment[pt_BR]=Monitor de Bateria e Gerenciamento de Energia Geral +GenericName[pt_BR]=Monitor de Bateria +GenericName[ru]=Монитор Батареи +Comment[ru]=Монитор батареи и управление энергосбережением +GenericName[sv]=Batteriövervakare +GenericName[tr]=Pil durumu izleme ve güç yönetimi arayüzü +Comment[tr]=Pil durumu izleme ve güç yönetimi arayüzü +Comment[uk]=Монітор стану батареї і загальне керування живленням +GenericName[uk]=Монітор батарей +Comment[xx]=xxBattery monitor and general power managementxx +GenericName[zh_CN]=电池监视器 +Comment[zh_CN]=电池监视器和常规电源管理 +GenericName[zh_TW]=電池監視器 +Comment[zh_TW]=電池監視器和一般電源管理 +X-TDE-autostart-after=panel +X-TDE-StartupNotify=false +X-TDE-UniqueApplet=true +X-TDE-autostart-condition=tdepowersaverc:General:Autostart:true +Categories=System;Applet; + diff --git a/src/tdepowersave.h b/src/tdepowersave.h new file mode 100644 index 0000000..0531561 --- /dev/null +++ b/src/tdepowersave.h @@ -0,0 +1,465 @@ +/************************************************************************** +* Copyright (C) 2004 by Thomas Renninger * +* and * +* 2004-2007 by Danny Kukawka * +* , * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of version 2 of the GNU General Public License * +* as published by the Free Software Foundation. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ + +#ifndef _TDEPOWERSAVE_H_ +#define _TDEPOWERSAVE_H_ + +// this is needed to avoid typedef clash with X11/Xmd.h (X11/Xproto.h) +#ifndef TQT_CLEAN_NAMESPACE +#define TQT_CLEAN_NAMESPACE +#endif + +// Global Header +#ifdef HAVE_CONFIG_H +#include +#endif + +// KDE - Header +#include +#include +#include + +// QT - Header +#include + +// tdepowersave - Header +#include "autosuspend.h" +#include "autodimm.h" +#include "configuredialog.h" +#include "countdowndialog.h" +#include "detaileddialog.h" +#include "hardware.h" +#include "tdepowersave_debug.h" +#include "logviewer.h" +#include "screen.h" +#include "settings.h" + + +/*! +* \file tdepowersave.h +* \brief Headerfile for tdepowersave.cpp and the class \ref tdepowersave. +*/ + /*! + * \class tdepowersave + * \brief The central class for the tdepowersave-applet + * \author Danny Kukawka, , + * \author Thomas Renninger, + * \date 2004 - 2007 + */ + +class tdepowersave : public KSystemTray, public DCOPObject +{ + Q_OBJECT +// + K_DCOP + +private: + + // permanent pointers + //! to configure tdepowersave + TDEConfig *config; + //! instance of \ref screen + screen *display; + //! instance of \ref settings + Settings *settings; + //! pointer to class HardwareInfo object + HardwareInfo *hwinfo; + //! instance of \ref autosuspend + autosuspend *autoSuspend; + //! instance of \ref autodimm + autodimm * autoDimm; + + // temporary pointer, use them if needed + //! TDEProcess to start YaST-module for configuration + TDEProcess *yast2; + //! instance of \ref ConfigureDialog + /*! the implemtation and all related functions for the configure dialog*/ + ConfigureDialog *configDlg; + //! instance of \ref LogViewer + LogViewer *logview; + //! instance of \ref countDownDialog + countDownDialog *countdown; + + + //! struct wth information about suspend states and permissions + SuspendStates suspend; + //! enum with the last called suspend, this need to be reset if needed + int calledSuspend; + + //! instance of \ref detaileddialog + detaileddialog *detailedDlg; + + //! represent the state of opened \ref detailedDlg + /*! + * This boolean represent information about the detailedDlg. Use this to inform + * if the dialog is displayed. + * \li true: if dialog is displayed + * \li false: if not + */ + bool detailedIsShown; + //! represent the state of the configure dialog + /*! + * This boolean represent information about the configure dialog. Use this to inform + * if the dialog is displayed. + * \li true: if dialog is displayed + * \li false: if not + */ + bool config_dialog_shown; + + //! represent background status of the kickerapplet icon + /*! + * This boolean represent information about the background of the kickerapplet icon. + * \li true: if iconbackground is colored + * \li false: if iconbackground is not colored + */ + bool icon_BG_is_colored; + //! represent color status of the kickerapplet icon + /*! + * This boolean represent the state of the kickerapplet icon. It don't display + * information about the icon backgrund like \ref icon_BG_is_colored . It say + * only that the icon is in state to have a blinking background . + * \li true: if icon set to be colored + * \li false: if icon isn't set to be colored + */ + bool icon_set_colored; + //! represent the state of icon changing + /*! + * This boolean represent information about changing the icon background. It's used to + * change the intervall of redraw the kickerapplet icon. + * \li true: if the state of icon is changed + * \li false: if the state of icon isn't change + */ + bool icon_state_changed; + //! represent the state of the suspend/progress dialog + /*! + * This boolean represent information about the current state of + * visible of the suspend/progress dialog. + * \li true: if the dialog is shown + * \li false: if not + */ + bool suspend_dialog_shown; + + //! tell if the display should get dimmed down + /*! + * This boolean represent information if the display should get dimmed down + * within the \ref do_dimm() function or not. + * \li true: if the display should get dimmed down + * \li false: if the display should get dimmed up + */ + bool autoDimmDown; + + //! to temporary hold the resume result + int resume_result; + + //! a menu entry ID + /*! contains the ID of the menuentry for tdepowersave configure Dialog */ + int CONFIGURE_ID; + + int CONFIGURE_EVENTS_ID; + + //! a menu entry ID + /*! contains the ID of the menuentry for YaST-configuration */ + int YAST_MODULE_MENU_ID; + //! a menu seperator ID + /*! contains the ID of the separator between YaST-entry and the sleep-states */ + int SLEEP_SEPARATOR_MENU_ID; + //! a menu entry ID + /*! contains the ID of the menuentry for suspend-to-disk */ + int SUSPEND2DISK_MENU_ID; + //! a menu entry ID + /*! contains the ID of the menuentry for suspend-to-ram */ + int SUSPEND2RAM_MENU_ID; + //! a menu entry ID + /*! contains the ID of the menuentry for stand-by */ + int STANDBY_MENU_ID; + //! a menu seperator ID + /*! contains the ID of the separator between sleep-states-entries and the cpufreq-submenu */ + int CPUFRETQ_SEPARATOR_MENU_ID; + //! a submenu ID + /*! contains the ID of the cpufreq sub menu*/ + int CPUFRETQ_MENU_ID; + //! a menu seperator ID + /*! contains the ID of the separator between cpufreq- and scheme-submenu*/ + int SCHEME_SEPARATOR_MENU_ID; + //! a submenu ID + /*! contains the ID of the scheme submenu*/ + int SCHEME_MENU_ID; + //! a menu seperator ID + /*! contains the ID of the separator between scheme-submenu and autosuspend*/ + int AUTOSUSPEND_SEPARATOR_MENU_ID; + //! a menu entry ID + /*! contains the ID of the menuentry for disable inactivity actions */ + int AUTOSUSPEND_MENU_ID; + //! a menu seperator ID + /*! contains the ID of the separator between autosuspend and Help*/ + int HELP_SEPARATOR_MENU_ID; + //! a menu ID + /*! contains the ID of the help menu*/ + int HELP_MENU; + + //! number of white pixel in the kickerapplet icon + /*! + * This integer value represent the number of white pixel in the icon for + * the kickerapplet. with this 'global' variable we don't need to count the + * white pixel on every redraw. + */ + int countWhiteIconPixel; + + //! TQTimer-interval for icon background + /*! + * Time intervall to set the colored background of the batteryicon on/off. + * The value is 1000 msec/ 1 sec. + */ + static const int BAT_icon_BG_intervall = 1000; + + //! type of current running suspend + /*! TQString store the name of the current running suspend*/ + TQString suspendType; + + //! current name of the pixmap + /*! + * Contains the current name of the icon/pixmap. The value must be a filename of a existing iconfile. + * \sa power_icon, no_battery_icon, charge_icon, battery, battery_RED or battery_ORANGE + */ + TQString pixmap_name; + + //! contains the 'real' schemenames + /*! + * This list store the real schemenames (not the i18n()-version) + * regarding to position in the scheme-menu + */ + TQStringList org_schemenames; + + //! a sub-menu of the kickerapplet + /*! TQPopupMenu for the cpufreq-entries. */ + TQPopupMenu *speed_menu; + //! a sub-menu of the kickerapplet + /*! TQPopupMenu for the scheme-entries. */ + TQPopupMenu *scheme_menu; + //! a sub-menu of the kickerapplet + /*! TQPopupMenu for the help-entries. */ + TQPopupMenu *help_menu; + + + //! icon-pixmap + /*! TQPixmap with the (pre-)loaded icon from \ref pixmap_name .*/ + TQPixmap pixmap; + //! icon-pixmap + /*! TQPixmap with the full draw applet Icon (to be used in other classes) .*/ + TQPixmap fullIcon; + + + //! Timer for the blinking Icon background + /*! + * This timer is used to let blink the background of a icon in kicker. + * The timerinterval is defined in \ref BAT_icon_BG_intervall . + */ + TQTimer *BAT_WARN_ICON_Timer; + //! Timer to dimm down/up the brightness + /*! + * This timer is used dimm the display up and down. The timerinterval + * depends on calculated timePerStep in the calling function. + */ + TQTimer *AUTODIMM_Timer; + + //! draw all icon related things for \ref redrawPixmap() + void drawIcon(); + //! to intialise the menu for the kickerapplet + void initMenu(); + //! load the icon for \ref redrawPixmap() + void loadIcon(bool forceReload = false); + //! draw/redraw the icon for the kickerapplet + void redrawPixmap(); + //! to set the screensaver settings + void setSchemeSettings(); + //! to update the Tooltip of the kickerapplet + void updateTooltip(); + + //! Eventhandler to catch mouse-press-events and react + void mousePressEvent( TQMouseEvent *qme ); + //! Event handler to catch mouse wheel events and react + void wheelEvent( TQWheelEvent *qwe ); + //! Eventhandler to catch mouse enter events and react + void enterEvent( TQEvent *qee); + + //! to handle mount/umount on resume/suspend + bool handleMounts ( bool suspend ); + + //! to get the i18n string for a suspend type + TQString getSuspendString (int type); + +private slots: + + //! send command for stand-by to the TDE hardware library + bool do_standby(); + //! send command for suspend_to_disk to the TDE hardware library + bool do_suspend2disk(); + //! send command for suspend_to_RAM to the TDE hardware library + bool do_suspend2ram(); + + //! show warning dialog or call autosuspend if signal \ref inactivity::inactivityTimeExpired() recieved + void do_autosuspendWarn(); + //! execute the autosuspend + bool do_autosuspend(bool chancel); + //! starts the Yast2-power-management module + void do_config(); + //! sets the new scheme with all settings + void do_setActiveScheme( int ); + //! called if icon background must be changed + void do_setIconBG(); + //! to set the autosuspend on/off over the menu + void do_setAutosuspend(); + //! sets the CPU Freq policy via the TDE hardware library + void do_setSpeedPolicy( int ); + //! called if there are problems with starting yast module + void slotConfigProcessExited( TDEProcess * ); + //! called to open the tdepowersave help + void slotHelp(); + //! called to open the tdepowersave About dialog + void slotAbout(); + //! called to open website to report bugs + void slotReportBug(); + //! called if the configure dialog is destroyed + void observeConfigDlg(); + //! called if user exit from tdepowersave + void _quit(); + + //! called if the user get inactive and the display should get dimmed down + void do_downDimm(); + //! called if the user get active again and the display should get dimmed up + void do_upDimm(); + //! TQT_SLOT do do the dimmining for autodimm feature + void do_dimm(); + //! TQT_SLOT to set autodimm related stuff and start autodimm monitoring + void setAutoDimm( bool resumed ); + + //! to update the main menu of the kickerapplet + /*! this is bound to generalDataChanged singal in pdaemon */ + void update(); + //! to update the scheme-menu within the main menu + void updateSchemeMenu(); + //! to update the menu with the cpu frequency within the main menu + void updateCPUFreqMenu(); + + //! this set \ref suspendType from signal + void setSuspendType( TQString suspendtype ); + //! this set the autosuspend and start the monitoring + void setAutoSuspend( bool ); + + //! called for critical battery event SHUTDOWN + void handleCriticalBatteryActionCall(); + //! set for a battery status the related actions + void handleActionCall ( action action, int value, bool checkAC = false, bool batWarnCall = false ); + + //! this lock/reactivate the screen if a lidclosetStatus() signal is triggered + void handleLidEvent( bool closed ); + //! show the login dialog after locked the screen + void activateLoginScreen(); + + //! handle event for press power button and call action + void handlePowerButtonEvent(); + //! handle event for press s2ram/sleep button and call action + void handleSleepButtonEvent(); + //! handle event for press s2disk button and call action + void handleS2DiskButtonEvent(); + + //! handle changes of the session state + void handleSessionState (bool state); + + //! to show the tdepowersave configure_dialog + void showConfigureDialog(); + //! to show the KNotify config dialog + void showConfigureNotificationsDialog(); + + //! this emit the KNotify event for a battery warning state state + void notifyBatteryStatusChange ( int type, int state ); + //! this emit the KNotify event for change AC status + void handleACStatusChange ( bool acstate, bool notifyEvent = true ); + //! this emit the KNotify events if scheme switched + void notifySchemeSwitch(); + //! this emit the KNotify events if the machine go to suspend/Standby + void notifySuspend( int ); + //! to independent handleResumeSignal from event loop + void forwardResumeSignal( int result ); + //! this emit the KNotify events if the machine resumed + void handleResumeSignal(); + + //! this show a blocking dialog from tdepowersave with the given message + void showErrorMessage( TQString msg ); + + //! this is called when detailed dialog is closed + void closedetaileddialog(); + +public: + + //! default constructor + tdepowersave( bool force_acpi_check = false, bool trace_func = false); + //! default destructor + virtual ~tdepowersave(); + +k_dcop: + //! dcop function to lock the screen + bool lockScreen(); + //! dcop function to set a scheme + bool do_setScheme( TQString ); + //! dcop function to set CPU Freq policy + bool do_setCPUFreqPolicy( TQString ); + //! dcop function to send 'suspend to disk' command to powersaved + bool do_suspendToDisk(); + //! dcop function to send 'suspend to RAM' command to powersaved + bool do_suspendToRAM(); + //! dcop function to send 'standby' command to powersaved + bool do_standBy(); + //! dcop function to set the brightness down + bool do_brightnessDown(int percentageStep = -1); + //! dcop function to set the brightness up + bool do_brightnessUp(int percentageStep = -1); + + //! dcop function to disable/stop autosuspend + void disableAutosuspend( bool ); + + //! dcop function to show the detailed dialog + void showDetailedDialog(); + //! dcop function to open the configure dialog + bool openConfigureDialog(); + + //! dcop function to find out if tdepowersave manages DPMS + bool currentSchemeManagesDPMS(); + //! dcop funtion to get the current brightness level + int brightnessGet(); + + //! dcop function to return the name of the current scheme + TQString currentScheme (); + //! dcop function to return the current cpufreqpolicy + TQString currentCPUFreqPolicy(); + + //! dcop function to return the supported sleeping states + TQStringList allowed_sleepingStates(); + //! dcop function to return the schemes + TQStringList listSchemes(); + //! dcop function to return the supported CPU + TQStringList listCPUFreqPolicies(); + +protected: + void resizeEvent ( TQResizeEvent * ); +}; + +#endif // _TDEPOWERSAVE_H_ diff --git a/src/tdepowersave.lsm b/src/tdepowersave.lsm new file mode 100644 index 0000000..3c08565 --- /dev/null +++ b/src/tdepowersave.lsm @@ -0,0 +1,14 @@ +Begin4 +Title: tdepowersave +Version: R14.0.0 +Entered-date: 2010-05-10 +Description: Front end for power management for the Trinity Desktop Environment +Keywords: TDE Qt +Author: Thomas Renninger +Maintained-by: The Trinity Desktop Environment (TDE) http://www.trinitydesktop.org/ +Primary-site: http://git.trinitydesktop.org/cgit/ +Alternate-site: +Original-site: http://kde-apps.org/content/show.php?content=29295 +Platforms: Linux and other Unices running TDE +Copying-policy: GPL +End diff --git a/src/tdepowersave_debug.h b/src/tdepowersave_debug.h new file mode 100644 index 0000000..9585a96 --- /dev/null +++ b/src/tdepowersave_debug.h @@ -0,0 +1,68 @@ +/************************************************************************** +* Copyright (C) * +* 2004-2007 by Danny Kukawka * +* , * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of version 2 of the GNU General Public License * +* as published by the Free Software Foundation. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ + +#ifndef _TDEPOWERSAVE_DEBUG_H +#define _TDEPOWERSAVE_DEBUG_H + +// Global Header +#ifdef HAVE_CONFIG_H +#include +#endif + +// Default Header +#include +#include + +// QT - Header +#include + +// KDE Header +#include + +/*! +* \file tdepowersave_debug.h +* \brief Headerfile for debug related defines/macros. Currently this file +* contains the myDebug(...) macro. +*/ + +// to store the value over the different classes +extern bool trace; + +/* + * macro to collect time and k_funcinfo information for kdDebug() + */ +#define funcinfo "[" << TQString(TQTime::currentTime().toString()).ascii() << \ + ":" << TQTime::currentTime().msec() << "]" << k_funcinfo + +/* + * macros to trace function entry and leave points + */ +#define kdDebugFuncIn(traceinfo) do { \ + if (traceinfo == true) \ + kdDebug() << funcinfo << "IN " << endl; \ +} while (0) + +#define kdDebugFuncOut(traceinfo) do { \ + if (traceinfo == true) \ + kdDebug() << funcinfo << "OUT " << endl; \ +} while (0) + + +#endif //_TDEPOWERSAVE_DEBUG_H -- cgit v1.2.1