You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2679 lines
80 KiB
2679 lines
80 KiB
15 years ago
|
/**************************************************************************
|
||
|
* Copyright (C) 2004 by Thomas Renninger *
|
||
|
* <trenn@suse.de> and *
|
||
|
* 2004-2007 by Danny Kukawka *
|
||
|
* <dkukawka@suse.de>, <danny.kukawka@web.de> *
|
||
|
* *
|
||
|
* 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:
|
||
12 years ago
|
#include <tdeaboutapplication.h>
|
||
|
#include <tdeapplication.h>
|
||
15 years ago
|
#include <kaudioplayer.h>
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <kiconloader.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
15 years ago
|
#include <knotifyclient.h>
|
||
|
#include <knotifydialog.h>
|
||
|
#include <kpassivepopup.h>
|
||
12 years ago
|
#include <tdepopupmenu.h>
|
||
15 years ago
|
|
||
14 years ago
|
// other TQt headers:
|
||
|
#include <tqcursor.h>
|
||
|
#include <tqevent.h>
|
||
|
#include <tqfile.h>
|
||
|
#include <tqimage.h>
|
||
|
#include <tqpixmap.h>
|
||
|
#include <tqtimer.h>
|
||
|
#include <tqtooltip.h>
|
||
15 years ago
|
|
||
|
// own headers:
|
||
12 years ago
|
#include "tdepowersave.h"
|
||
15 years ago
|
#include "infodialog.h"
|
||
|
|
||
15 years ago
|
/*!
|
||
12 years ago
|
* \file tdepowersave.cpp
|
||
|
* \brief This file contains the main functionality of the tdepowersave-applet.*/
|
||
15 years ago
|
|
||
15 years ago
|
/*!
|
||
12 years ago
|
* This is the default constructor of the class tdepowersave.
|
||
15 years ago
|
*/
|
||
12 years ago
|
tdepowersave::tdepowersave( bool force_acpi_check, bool trace_func ) : KSystemTray(0, "tdepowersave"),
|
||
|
DCOPObject("tdepowersaveIface") {
|
||
15 years ago
|
trace = trace_func;
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
15 years ago
|
|
||
|
display = new screen();
|
||
|
settings = new Settings();
|
||
|
autoSuspend = new autosuspend();
|
||
|
autoDimm = new autodimm();
|
||
|
hwinfo = new HardwareInfo();
|
||
|
suspend = hwinfo->getSuspendSupport();
|
||
15 years ago
|
|
||
15 years ago
|
yast2 = NULL;
|
||
|
|
||
|
resume_result = 0;
|
||
|
|
||
12 years ago
|
config = TDEGlobal::config();
|
||
15 years ago
|
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
|
||
12 years ago
|
// and don't start tdepowersave ever again until force_acpi_check == true.
|
||
15 years ago
|
if (!hwinfo->hasACPI() && !hwinfo->hasAPM() && !hwinfo->hasPMU() &&
|
||
15 years ago
|
!hwinfo->supportCPUFreq() && !suspend.suspend2disk && !suspend.suspend2ram){
|
||
|
config->writeEntry("Autostart", false);
|
||
|
config->sync();
|
||
|
kdError() << "This machine does not support ACPI, APM, PMU, CPUFreq, Suspend2Disk nor "
|
||
12 years ago
|
<< "Suspend2RAM. Please close tdepowersave now." << endl;
|
||
15 years ago
|
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
|
||
15 years ago
|
hwinfo->setPrimaryBatteriesWarningLevel(settings->batteryWarningLevel,
|
||
15 years ago
|
settings->batteryLowLevel,
|
||
|
settings->batteryCriticalLevel);
|
||
|
|
||
|
// connect to signals for changes
|
||
14 years ago
|
connect(hwinfo, TQT_SIGNAL(generalDataChanged()), this, TQT_SLOT(update()));
|
||
|
connect(hwinfo, TQT_SIGNAL(primaryBatteryChanged()), this, TQT_SLOT(update()));
|
||
13 years ago
|
connect(hwinfo, TQT_SIGNAL(ACStatus(bool)), this, TQT_SLOT(handleACStatusChange (bool)));
|
||
14 years ago
|
connect(hwinfo, TQT_SIGNAL(resumed(int)), this, TQT_SLOT(forwardResumeSignal(int)));
|
||
15 years ago
|
|
||
|
// connect to error mesages
|
||
14 years ago
|
connect(autoSuspend, TQT_SIGNAL(displayErrorMsg(TQString)), this, TQT_SLOT(showErrorMessage(TQString)));
|
||
15 years ago
|
|
||
|
// connect to events
|
||
13 years ago
|
connect(hwinfo, TQT_SIGNAL(lidclosetStatus(bool)), this, TQT_SLOT(handleLidEvent(bool)));
|
||
14 years ago
|
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()));
|
||
15 years ago
|
|
||
15 years ago
|
config->sync();
|
||
15 years ago
|
|
||
15 years ago
|
config_dialog_shown = false;
|
||
|
suspend_dialog_shown = false;
|
||
|
detailedIsShown = false;
|
||
|
icon_set_colored = false;
|
||
|
icon_BG_is_colored = false;
|
||
15 years ago
|
|
||
15 years ago
|
calledSuspend = -1;
|
||
|
countWhiteIconPixel = 0;
|
||
|
|
||
|
pixmap_name = "NONE";
|
||
|
suspendType = "NULL";
|
||
|
|
||
14 years ago
|
BAT_WARN_ICON_Timer = new TQTimer(this);
|
||
|
connect(BAT_WARN_ICON_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_setIconBG()));
|
||
15 years ago
|
|
||
14 years ago
|
AUTODIMM_Timer = new TQTimer(this);
|
||
15 years ago
|
|
||
|
initMenu();
|
||
|
update();
|
||
|
updateCPUFreqMenu();
|
||
|
setSchemeSettings();
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
|
||
12 years ago
|
/*! This is the default destructor of class tdepowersave. */
|
||
|
tdepowersave::~tdepowersave(){
|
||
15 years ago
|
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
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::initMenu() {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
14 years ago
|
CONFIGURE_ID = this->contextMenu()->insertItem(SmallIcon("configure", TQIconSet::Automatic),
|
||
12 years ago
|
i18n("Configure TDEPowersave..."),
|
||
14 years ago
|
this, TQT_SLOT(showConfigureDialog()));
|
||
|
CONFIGURE_EVENTS_ID = this->contextMenu()->insertItem(SmallIcon("knotify", TQIconSet::Automatic),
|
||
15 years ago
|
i18n("Configure Notifications..."),
|
||
14 years ago
|
this, TQT_SLOT(showConfigureNotificationsDialog()));
|
||
15 years ago
|
#ifdef ENABLE_YAST_ENTRY
|
||
14 years ago
|
YAST_MODULE_MENU_ID = this->contextMenu()->insertItem(SmallIcon("yast", TQIconSet::Automatic),
|
||
15 years ago
|
i18n("Start YaST2 Power Management Module..."),
|
||
14 years ago
|
this, TQT_SLOT(do_config()));
|
||
15 years ago
|
#endif
|
||
15 years ago
|
|
||
15 years ago
|
SLEEP_SEPARATOR_MENU_ID = this->contextMenu()->insertSeparator();
|
||
15 years ago
|
SUSPEND2DISK_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("suspend_to_disk",
|
||
14 years ago
|
TQIconSet::Automatic),
|
||
15 years ago
|
i18n("Suspend to Disk"), this,
|
||
14 years ago
|
TQT_SLOT(do_suspend2disk()));
|
||
15 years ago
|
SUSPEND2RAM_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("suspend_to_ram",
|
||
14 years ago
|
TQIconSet::Automatic),
|
||
15 years ago
|
i18n("Suspend to RAM"), this,
|
||
14 years ago
|
TQT_SLOT(do_suspend2ram()));
|
||
|
STANDBY_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("stand_by", TQIconSet::Automatic),
|
||
|
i18n("Standby"), this, TQT_SLOT(do_standby()));
|
||
15 years ago
|
|
||
14 years ago
|
speed_menu = new TQPopupMenu(this, i18n("Set CPU Frequency Policy").ascii());
|
||
15 years ago
|
speed_menu->insertItem(i18n("Performance"), PERFORMANCE);
|
||
|
speed_menu->insertItem(i18n("Dynamic"), DYNAMIC);
|
||
|
speed_menu->insertItem(i18n("Powersave"), POWERSAVE);
|
||
15 years ago
|
|
||
14 years ago
|
CPUFRETQ_SEPARATOR_MENU_ID = contextMenu()->insertSeparator();
|
||
15 years ago
|
|
||
14 years ago
|
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()));
|
||
15 years ago
|
|
||
|
|
||
|
SCHEME_SEPARATOR_MENU_ID = contextMenu()->insertSeparator();
|
||
15 years ago
|
|
||
14 years ago
|
scheme_menu = new TQPopupMenu(this, i18n("Set Active Scheme").ascii());
|
||
15 years ago
|
SCHEME_MENU_ID = contextMenu()->insertItem(i18n("Set Active Scheme"), scheme_menu);
|
||
14 years ago
|
connect(scheme_menu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(do_setActiveScheme(int)));
|
||
15 years ago
|
|
||
|
// menu entry for the autosuspend disable checkbox, disabled by default, only
|
||
15 years ago
|
// displayed if autosuspend for the current scheme is activated
|
||
|
AUTOSUSPEND_SEPARATOR_MENU_ID = contextMenu()->insertSeparator();
|
||
15 years ago
|
AUTOSUSPEND_MENU_ID = this->contextMenu()->insertItem( i18n("Disable Actions on Inactivity"),
|
||
14 years ago
|
this,TQT_SLOT(do_setAutosuspend()));
|
||
15 years ago
|
this->contextMenu()->setItemVisible(AUTOSUSPEND_SEPARATOR_MENU_ID, false);
|
||
|
this->contextMenu()->setItemVisible(AUTOSUSPEND_MENU_ID, false);
|
||
|
|
||
|
HELP_SEPARATOR_MENU_ID = contextMenu()->insertSeparator();
|
||
|
|
||
14 years ago
|
help_menu = new TQPopupMenu(this, i18n("&Help").ascii());
|
||
15 years ago
|
|
||
12 years ago
|
help_menu->insertItem( SmallIcon("help", TQIconSet::Automatic), i18n("&tdepowersave Handbook"),
|
||
14 years ago
|
this, TQT_SLOT(slotHelp()));
|
||
15 years ago
|
help_menu->insertSeparator();
|
||
14 years ago
|
help_menu->insertItem( i18n("&Report a bug ..."), this, TQT_SLOT(slotReportBug()));
|
||
12 years ago
|
help_menu->insertItem( SmallIcon("tdepowersave", TQIconSet::Automatic),
|
||
|
i18n("&About tdepowersave"), this, TQT_SLOT(slotAbout()));
|
||
15 years ago
|
|
||
14 years ago
|
HELP_MENU = contextMenu()->insertItem(SmallIcon("help", TQIconSet::Automatic),
|
||
15 years ago
|
i18n("&Help"), help_menu);
|
||
15 years ago
|
|
||
14 years ago
|
connect(this, TQT_SIGNAL(quitSelected()), this, TQT_SLOT(_quit()));
|
||
15 years ago
|
|
||
15 years ago
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
12 years ago
|
void tdepowersave::resizeEvent ( TQResizeEvent * )
|
||
15 years ago
|
{
|
||
|
// Honor Free Desktop specifications that allow for arbitrary system tray icon sizes
|
||
12 years ago
|
loadIcon(true);
|
||
15 years ago
|
drawIcon();
|
||
|
}
|
||
|
|
||
15 years ago
|
/*!
|
||
15 years ago
|
* This funtion load and manipulate the icons for the kickerapplet-section.
|
||
15 years ago
|
* The redraw interval depends on \ref icon_set_colored and \ref BAT_icon_BG_intervall.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::redrawPixmap(){
|
||
15 years ago
|
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);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
12 years ago
|
* Starts the configure dialog of tdepowersave.
|
||
15 years ago
|
*/
|
||
12 years ago
|
void tdepowersave::showConfigureDialog() {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
if(!config_dialog_shown) {
|
||
15 years ago
|
if (settings->schemes.count() > 0){
|
||
15 years ago
|
configDlg = new ConfigureDialog(config, hwinfo, settings);
|
||
|
configDlg->show();
|
||
|
config_dialog_shown = true;
|
||
14 years ago
|
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()));
|
||
15 years ago
|
}
|
||
|
else {
|
||
|
KPassivePopup::message(i18n("WARNING"), i18n("Cannot find any schemes."),
|
||
15 years ago
|
SmallIcon("messagebox_warning", 20), this,
|
||
14 years ago
|
i18n("Warning").ascii(), 15000);
|
||
15 years ago
|
}
|
||
|
} else {
|
||
13 years ago
|
configDlg->setWindowState((configDlg->windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
|
||
15 years ago
|
configDlg->setActiveWindow();
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
12 years ago
|
* Starts the notification configure dialog of tdepowersave.
|
||
15 years ago
|
*/
|
||
12 years ago
|
void tdepowersave::showConfigureNotificationsDialog() {
|
||
15 years ago
|
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.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::loadIcon(bool forceReload){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
14 years ago
|
TQString pixmap_name_tmp = "NONE";
|
||
15 years ago
|
|
||
|
BatteryCollection *primary = hwinfo->getPrimaryBatteries();
|
||
|
|
||
13 years ago
|
if ( !hwinfo->isOnline() ) {
|
||
14 years ago
|
pixmap_name_tmp = TQString("ERROR");
|
||
15 years ago
|
}
|
||
|
else if (hwinfo->getAcAdapter() || primary->getBatteryState() == BAT_NONE) {
|
||
|
icon_set_colored = false;
|
||
15 years ago
|
|
||
15 years ago
|
if (primary->getBatteryState() == BAT_NONE || (primary->getRemainingPercent() < 0 ||
|
||
|
primary->getRemainingPercent() >= 99))
|
||
14 years ago
|
pixmap_name_tmp = TQString("laptoppower");
|
||
15 years ago
|
else
|
||
14 years ago
|
pixmap_name_tmp = TQString("laptopcharge");
|
||
15 years ago
|
}
|
||
|
else {
|
||
|
switch(primary->getBatteryState()) {
|
||
|
case BAT_CRIT:
|
||
|
case BAT_LOW:
|
||
14 years ago
|
if (icon_BG_is_colored) pixmap_name_tmp = TQString("laptopbattery");
|
||
|
else pixmap_name_tmp = TQString("laptopbatteryRED");
|
||
15 years ago
|
icon_BG_is_colored = !icon_BG_is_colored;
|
||
|
icon_set_colored = true;
|
||
|
break;
|
||
|
case BAT_WARN:
|
||
14 years ago
|
if (icon_BG_is_colored) pixmap_name_tmp = TQString("laptopbattery");
|
||
|
else pixmap_name_tmp = TQString("laptopbatteryORANGE");
|
||
15 years ago
|
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
|
||
14 years ago
|
pixmap_name_tmp = TQString("laptopbattery");
|
||
15 years ago
|
icon_set_colored = false;
|
||
|
icon_BG_is_colored = false;
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
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
|
||
12 years ago
|
if ((pixmap_name_tmp != pixmap_name) || (forceReload)) {
|
||
15 years ago
|
pixmap_name = pixmap_name_tmp;
|
||
|
if (pixmap_name.startsWith("ERROR")) {
|
||
12 years ago
|
pixmap = SmallIcon("laptoppower", width(), TDEIcon::DisabledState);
|
||
15 years ago
|
}
|
||
15 years ago
|
else
|
||
15 years ago
|
pixmap = SmallIcon(pixmap_name, width());
|
||
15 years ago
|
}
|
||
15 years ago
|
|
||
15 years ago
|
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
|
||
15 years ago
|
* the same and white pixel only in the rectangle of the icon, the white pixel
|
||
15 years ago
|
* stored in \ref countWhiteIconPixel only one time.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::drawIcon(){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
BatteryCollection *primary = hwinfo->getPrimaryBatteries();
|
||
|
|
||
14 years ago
|
TQImage image = pixmap.convertToImage();
|
||
15 years ago
|
int w = image.width();
|
||
|
int h = image.height();
|
||
|
int x, y;
|
||
15 years ago
|
countWhiteIconPixel = 0;
|
||
15 years ago
|
|
||
13 years ago
|
if((pixmap_name.contains("laptopbattery") || pixmap_name.contains("charge")) &&
|
||
15 years ago
|
countWhiteIconPixel == 0) {
|
||
|
for (x = 0; x < w; x++)
|
||
|
for (y = 0; y < h; y++)
|
||
14 years ago
|
if(TQColor(image.pixel(x, y)) == TQt::white) countWhiteIconPixel++;
|
||
15 years ago
|
}
|
||
15 years ago
|
|
||
15 years ago
|
int c = (countWhiteIconPixel * primary->getRemainingPercent()) / 100;
|
||
15 years ago
|
|
||
15 years ago
|
if (c > 0) {
|
||
|
uint ui;
|
||
14 years ago
|
TQRgb Rgb_set;
|
||
15 years ago
|
|
||
15 years ago
|
if (hwinfo->getAcAdapter()) {
|
||
14 years ago
|
Rgb_set = tqRgb(0x00, 0xff, 0x00); //green
|
||
15 years ago
|
}
|
||
|
else {
|
||
|
switch(primary->getBatteryState()) {
|
||
|
case BAT_CRIT:
|
||
|
case BAT_LOW:
|
||
14 years ago
|
Rgb_set = tqRgb(0xff, 0x00, 0x00);//red
|
||
15 years ago
|
break;
|
||
|
case BAT_WARN:
|
||
14 years ago
|
Rgb_set = tqRgb(0xff, 0x55, 0x00); //orange
|
||
15 years ago
|
break;
|
||
|
default:
|
||
14 years ago
|
Rgb_set = tqRgb(0x00, 0xff, 0x00); //green
|
||
15 years ago
|
}
|
||
|
}
|
||
|
if (image.depth() <= 8) {
|
||
|
ui = image.numColors();
|
||
|
image.setNumColors(ui + 1);
|
||
|
image.setColor(ui, Rgb_set);
|
||
|
}
|
||
|
ui = 0xff000000 | Rgb_set;
|
||
15 years ago
|
|
||
15 years ago
|
for (y = h - 1; y >= 0; y--) {
|
||
|
for (x = 0; x < w ; x++) {
|
||
14 years ago
|
if(TQColor(image.pixel(x, y)) == TQt::white) {
|
||
15 years ago
|
image.setPixel(x, y, ui);
|
||
|
c--;
|
||
|
if (c <= 0) goto quit;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
quit:
|
||
15 years ago
|
image = image.smoothScale(width(), height());
|
||
15 years ago
|
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.
|
||
15 years ago
|
* \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
|
||
15 years ago
|
* while the mouse cursor is over the widget
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::updateTooltip(){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
BatteryCollection *primary = hwinfo->getPrimaryBatteries();
|
||
|
int percent = primary->getRemainingPercent();
|
||
|
int minutes = primary->getRemainingMinutes();
|
||
|
int charging_state = primary->getChargingState();
|
||
|
|
||
14 years ago
|
TQString tmp, num3;
|
||
15 years ago
|
num3.setNum(minutes % 60);
|
||
|
num3 = num3.rightJustify(2, '0');
|
||
|
|
||
13 years ago
|
if ( !hwinfo->isOnline() ){
|
||
15 years ago
|
tmp = i18n("No information about battery and AC status available");
|
||
15 years ago
|
}
|
||
15 years ago
|
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");
|
||
15 years ago
|
}
|
||
15 years ago
|
else if (minutes > 0){
|
||
|
if (charging_state == CHARGING)
|
||
|
tmp = i18n("Plugged in -- %1% charged (%2:%3 h until full "
|
||
13 years ago
|
"charged)").arg(percent).arg(minutes / 60).arg(num3);
|
||
15 years ago
|
else
|
||
|
tmp = i18n("Plugged in -- %1% charged (%2:%3 remaining hours)")
|
||
13 years ago
|
.arg(percent).arg(minutes / 60).arg(num3);
|
||
15 years ago
|
}
|
||
|
else if (charging_state == CHARGING && hwinfo->hasAPM()) {
|
||
13 years ago
|
tmp = i18n("Plugged in -- %1% charged").arg(percent);
|
||
15 years ago
|
}
|
||
|
else{
|
||
|
if (percent == -1) tmp = i18n("Plugged in -- no battery");
|
||
13 years ago
|
else tmp = i18n("Plugged in -- %1% charged").arg(percent);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
} else{
|
||
|
if (minutes >= 0){
|
||
|
tmp = i18n("Running on batteries -- %1% charged (%2:%3 hours remaining)")
|
||
13 years ago
|
.arg(percent).arg(minutes / 60).arg(num3);
|
||
15 years ago
|
}
|
||
|
else {
|
||
13 years ago
|
tmp = i18n("Running on batteries -- %1% charged").arg(percent);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
// add string whether battery is charging, but only if < 100% to avoid
|
||
15 years ago
|
// stupid tooltip message on machines which always with 100% and on AC
|
||
15 years ago
|
// are charging, as e.g. Sony Vaio FS vgn-fs115b
|
||
15 years ago
|
if (charging_state == CHARGING && percent < 100)
|
||
15 years ago
|
tmp += i18n(" -- battery is charging");
|
||
|
|
||
14 years ago
|
TQToolTip::add(this, tmp);
|
||
15 years ago
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to starts the Yast2-power-management module. This called by the menuentry
|
||
15 years ago
|
* with ID \ref YAST_MODULE_MENU_ID, named "Start YaST2 Power Management Module".
|
||
12 years ago
|
* It create a new TDEProcess and execute "/sbin/yast2 power-management" with tdesu.
|
||
15 years ago
|
*/
|
||
12 years ago
|
void tdepowersave::do_config(){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
15 years ago
|
|
||
15 years ago
|
#ifdef ENABLE_YAST_ENTRY
|
||
|
delete yast2;
|
||
15 years ago
|
|
||
12 years ago
|
yast2 = new TDEProcess;
|
||
13 years ago
|
*yast2 << "tdesu" << "--nonewdcop" << "/sbin/yast2" << "power-management";
|
||
15 years ago
|
|
||
12 years ago
|
connect(yast2, TQT_SIGNAL(processExited(TDEProcess *)),
|
||
|
TQT_SLOT(slotConfigProcessExited(TDEProcess *)));
|
||
|
if(!yast2->start(TDEProcess::NotifyOnExit))
|
||
15 years ago
|
{
|
||
|
delete yast2;
|
||
|
yast2 = NULL;
|
||
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
#else
|
||
|
kdDebugFuncOut(trace);
|
||
|
return;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
/*!
|
||
12 years ago
|
* \b TQT_SLOT to open the tdepowersave help
|
||
15 years ago
|
*/
|
||
12 years ago
|
void tdepowersave::slotHelp()
|
||
15 years ago
|
{
|
||
12 years ago
|
kapp->invokeHelp( "", "tdepowersave" );
|
||
15 years ago
|
}
|
||
|
|
||
|
/*!
|
||
12 years ago
|
* \b TQT_SLOT to open the tdepowersave About dialog
|
||
15 years ago
|
*/
|
||
12 years ago
|
void tdepowersave::slotAbout()
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEAboutApplication a( this );
|
||
15 years ago
|
a.exec();
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to open the website to report bugs
|
||
15 years ago
|
*/
|
||
12 years ago
|
void tdepowersave::slotReportBug()
|
||
15 years ago
|
{
|
||
|
#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
|
||
15 years ago
|
#else
|
||
15 years ago
|
#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
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to set the icon background on/off if battery is in critical, low or warning-state. Within
|
||
15 years ago
|
* this function we set \ref icon_state_changed to true and call \ref redrawPixmap() to redraw the
|
||
15 years ago
|
* kickerapplet icon and create a icon with blinking background. \n \n
|
||
14 years ago
|
* The slot called by the TQTimer \ref BAT_WARN_ICON_Timer . The interval of the timer is defined
|
||
15 years ago
|
* trough \ref BAT_icon_BG_intervall and starts here: \ref loadIcon() .
|
||
15 years ago
|
*/
|
||
12 years ago
|
void tdepowersave::do_setIconBG(){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
15 years ago
|
|
||
15 years ago
|
if (icon_set_colored) icon_state_changed = true;
|
||
|
redrawPixmap();
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to enable/disable the autosuspend.
|
||
15 years ago
|
*/
|
||
12 years ago
|
void tdepowersave::do_setAutosuspend(){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
if(!contextMenu()->isItemChecked(AUTOSUSPEND_MENU_ID)) {
|
||
|
autoSuspend->stop();
|
||
15 years ago
|
contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, true);
|
||
15 years ago
|
}
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT which called if the \ref configDlg is destroyed. We set within this SLOT
|
||
15 years ago
|
* \ref config_dialog_shown to false.
|
||
|
* TODO: check if we maybe should force here the current default scheme depending on the AC/battery state
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::observeConfigDlg(){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
15 years ago
|
|
||
15 years ago
|
// reload general settings
|
||
|
settings->load_general_settings();
|
||
15 years ago
|
// set the battery warning levels - all other general settings don't need to
|
||
15 years ago
|
// get set, since we check the settings only on events.
|
||
15 years ago
|
hwinfo->setPrimaryBatteriesWarningLevel(settings->batteryWarningLevel,
|
||
15 years ago
|
settings->batteryLowLevel,
|
||
|
settings->batteryCriticalLevel);
|
||
|
|
||
|
// reload the maybe changed scheme settings
|
||
|
settings->load_scheme_settings( settings->currentScheme );
|
||
|
// set the scheme
|
||
15 years ago
|
setSchemeSettings();
|
||
15 years ago
|
|
||
|
config_dialog_shown=false;
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
12 years ago
|
* \b TQT_SLOT which called from \ref do_config() if the 'tdesu yast2' TDEProcess exited.
|
||
15 years ago
|
* This function control the return value and display if needed a errormessage on failure.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::slotConfigProcessExited(TDEProcess *proc){
|
||
15 years ago
|
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."),
|
||
15 years ago
|
SmallIcon("messagebox_warning", 20), this,
|
||
15 years ago
|
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
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to send the command for "suspend to disk" to HAL daemon.
|
||
15 years ago
|
* 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
|
||
15 years ago
|
* \retval true if successful
|
||
15 years ago
|
* \retval false if command not supported or if powersaved not running
|
||
|
*/
|
||
12 years ago
|
bool tdepowersave::do_suspend2disk(){
|
||
15 years ago
|
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,
|
||
14 years ago
|
i18n("Warning").ascii(), 15000);
|
||
15 years ago
|
kdDebugFuncOut(trace);
|
||
|
return false;
|
||
|
}
|
||
|
} else {
|
||
|
KPassivePopup::message( i18n("WARNING"),
|
||
|
i18n("Suspend to disk disabled by administrator."),
|
||
15 years ago
|
SmallIcon("messagebox_warning", 20),
|
||
14 years ago
|
this, i18n("Warning").ascii(), 15000);
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to send the command for "suspend to RAM" to the HAL daemon.
|
||
15 years ago
|
* 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
|
||
15 years ago
|
* \retval true if successful
|
||
15 years ago
|
* \retval false if command not supported or if powersaved not running
|
||
|
*/
|
||
12 years ago
|
bool tdepowersave::do_suspend2ram(){
|
||
15 years ago
|
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,
|
||
14 years ago
|
i18n("Warning").ascii(), 15000);
|
||
15 years ago
|
kdDebugFuncOut(trace);
|
||
|
return false;
|
||
|
}
|
||
|
} else {
|
||
|
KPassivePopup::message( i18n("WARNING"),
|
||
|
i18n("Suspend to RAM disabled by administrator."),
|
||
15 years ago
|
SmallIcon("messagebox_warning", 20), this,
|
||
14 years ago
|
i18n("Warning").ascii(), 15000);
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to send the command for "stand-by" to the HAL daemon.
|
||
15 years ago
|
* 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
|
||
15 years ago
|
* \retval true if successful
|
||
15 years ago
|
* \retval false if command not supported or if powersaved not running
|
||
|
*/
|
||
12 years ago
|
bool tdepowersave::do_standby(){
|
||
15 years ago
|
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,
|
||
14 years ago
|
i18n("Warning").ascii(), 15000);
|
||
15 years ago
|
kdDebugFuncOut(trace);
|
||
|
return false;
|
||
|
}
|
||
|
} else {
|
||
|
KPassivePopup::message( i18n("WARNING"),i18n("Standby disabled by administrator."),
|
||
15 years ago
|
SmallIcon("messagebox_warning", 20), this,
|
||
14 years ago
|
i18n("Warning").ascii(), 15000);
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to send check if we should display the warning dialog and display
|
||
15 years ago
|
* the dialog if needed or call directly autosuspend after the signal
|
||
15 years ago
|
* \ref autosuspend::inactivityTimeExpired was recieved.
|
||
15 years ago
|
*/
|
||
12 years ago
|
void tdepowersave::do_autosuspendWarn() {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
if (settings->autoSuspendCountdown && (settings->autoSuspendCountdownTimeout > 0)) {
|
||
|
// we have to display the warn dialog
|
||
|
if(!contextMenu()->isItemChecked(AUTOSUSPEND_MENU_ID)) {
|
||
14 years ago
|
TQString message;
|
||
15 years ago
|
|
||
|
countdown = new countDownDialog(settings->autoSuspendCountdownTimeout);
|
||
15 years ago
|
|
||
15 years ago
|
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 {
|
||
12 years ago
|
countdown->setPixmap("tdepowersave");
|
||
15 years ago
|
}
|
||
15 years ago
|
|
||
15 years ago
|
// 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 "
|
||
13 years ago
|
"expire.").arg(i18n("Autosuspend")) + "\n\n" +
|
||
15 years ago
|
i18n("The computer autosuspend in: ");
|
||
|
|
||
|
countdown->setMessageText(message);
|
||
|
|
||
14 years ago
|
connect(countdown, TQT_SIGNAL(dialogClosed(bool)), this, TQT_SLOT(do_autosuspend(bool)));
|
||
15 years ago
|
countdown->showDialog();
|
||
15 years ago
|
}
|
||
15 years ago
|
} else {
|
||
|
// call directly autosuspend
|
||
|
do_autosuspend(false);
|
||
|
}
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to send the related suspend command for autosuspend
|
||
15 years ago
|
* \param chancel boolean with info if the autosuspend should get chanceld
|
||
|
* \return boolean with the result of the operation
|
||
15 years ago
|
* \retval true if successful
|
||
15 years ago
|
* \retval false if command not supported or on any other error
|
||
15 years ago
|
* \todo add check if the requested command is supported befor send and
|
||
15 years ago
|
* add message for this case to tell that maybe changed config!
|
||
|
*/
|
||
12 years ago
|
bool tdepowersave::do_autosuspend(bool chancel) {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
15 years ago
|
|
||
15 years ago
|
// TODO: check if this is really needed, it get called also on the suspend methodes
|
||
|
autoSuspend->stop();
|
||
|
|
||
15 years ago
|
if (!chancel) {
|
||
15 years ago
|
if(!settings->disableNotifications) {
|
||
15 years ago
|
KNotifyClient::event( this->winId(), "autosuspend_event",
|
||
15 years ago
|
i18n("System is going into suspend mode now"));
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to dimm the display down to the configured level if the signal
|
||
15 years ago
|
* \ref autodimm::inactivityTimeExpired was recieved.
|
||
|
* \param
|
||
15 years ago
|
* \return boolean with the result of the operation
|
||
15 years ago
|
* \retval true if successful
|
||
15 years ago
|
* \retval false else
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::do_downDimm() {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
if (hwinfo->supportBrightness()) {
|
||
|
if (!AUTODIMM_Timer->isActive()) {
|
||
|
int dimmToLevel = (int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->autoDimmTo/100.0));
|
||
15 years ago
|
|
||
|
// check if we really need to dimm down
|
||
15 years ago
|
if (dimmToLevel < hwinfo->getCurrentBrightnessLevel()) {
|
||
|
int steps = hwinfo->getCurrentBrightnessLevel() - dimmToLevel;
|
||
|
int timePerStep = (1500 / steps);
|
||
|
|
||
|
autoDimmDown = true;
|
||
15 years ago
|
|
||
14 years ago
|
AUTODIMM_Timer = new TQTimer(this);
|
||
|
connect(AUTODIMM_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_dimm()));
|
||
15 years ago
|
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!
|
||
14 years ago
|
TQTimer::singleShot(1500, this, TQT_SLOT(do_downDimm()));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to dimm the display up to the configured level if the signal
|
||
15 years ago
|
* \ref autodimm::UserIsActiveAgain was recieved.
|
||
|
* \param
|
||
15 years ago
|
* \return boolean with the result of the operation
|
||
15 years ago
|
* \retval true if successful
|
||
15 years ago
|
* \retval false else
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::do_upDimm() {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
15 years ago
|
|
||
15 years ago
|
//NOTE we go back to the value of the scheme and not the last on, to reduce trouble with the scheme
|
||
|
|
||
15 years ago
|
if (hwinfo->supportBrightness()) {
|
||
15 years ago
|
if (!AUTODIMM_Timer->isActive()) {
|
||
|
int dimmToLevel = (int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->brightnessValue/100.0));
|
||
15 years ago
|
|
||
15 years ago
|
// check if we really need to dimm up
|
||
|
if (dimmToLevel > hwinfo->getCurrentBrightnessLevel()) {
|
||
|
int steps = dimmToLevel - hwinfo->getCurrentBrightnessLevel();
|
||
|
int timePerStep = (750 / steps);
|
||
|
|
||
|
autoDimmDown = false;
|
||
15 years ago
|
|
||
14 years ago
|
AUTODIMM_Timer = new TQTimer(this);
|
||
|
connect(AUTODIMM_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_dimm()));
|
||
15 years ago
|
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!
|
||
14 years ago
|
TQTimer::singleShot(750, this, TQT_SLOT(do_downDimm()));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to dimm the display down
|
||
15 years ago
|
* \return boolean with the result of the operation
|
||
15 years ago
|
* \retval true if successful
|
||
15 years ago
|
* \retval false else
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::do_dimm() {
|
||
15 years ago
|
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);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
15 years ago
|
* Function handle umount/remount external storage media before/after
|
||
15 years ago
|
* 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
|
||
|
*/
|
||
12 years ago
|
bool tdepowersave::handleMounts( bool suspend ) {
|
||
15 years ago
|
if (trace) kdDebug() << funcinfo << "IN: " << "called suspend: " << suspend << endl;
|
||
|
|
||
|
bool _ret = false;
|
||
14 years ago
|
TQString _errormsg;
|
||
15 years ago
|
|
||
|
if (settings->unmountExternalOnSuspend) {
|
||
14 years ago
|
TQString _method;
|
||
15 years ago
|
DCOPRef dcop_ref = DCOPRef( "kded", "mediamanager" );
|
||
15 years ago
|
|
||
15 years ago
|
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;
|
||
|
}
|
||
15 years ago
|
|
||
|
// this is only needed for suspend case and an error ...
|
||
15 years ago
|
// on resume a simple error msg should be enough
|
||
|
if (!_ret && suspend) {
|
||
|
// handle error case
|
||
14 years ago
|
TQString _msg;
|
||
|
TQString _e_msg;
|
||
|
TQString _suspend;
|
||
15 years ago
|
|
||
|
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 !!!
|
||
15 years ago
|
_msg = "<qt>" +
|
||
15 years ago
|
i18n("Could not umount external media before suspend/standby. \n "
|
||
|
"(Reason: %1)\n \n Would you like to continue suspend/standby "
|
||
13 years ago
|
"anyway? \n(Warning: Continue suspend can cause data loss!)").arg(_e_msg) +
|
||
15 years ago
|
"</qt>";
|
||
|
|
||
|
_suspend = getSuspendString(calledSuspend);
|
||
|
|
||
15 years ago
|
int answer = KMessageBox::questionYesNo( 0, _msg,
|
||
13 years ago
|
i18n("Error while prepare %1").arg(_suspend),
|
||
15 years ago
|
i18n("Suspend anyway"), i18n("Cancel suspend"),
|
||
15 years ago
|
"ignoreMountOnSuspend");
|
||
|
|
||
|
if (answer == KMessageBox::Yes) {
|
||
|
_ret = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
return _ret;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
* Handle the event for the power button and call the related action.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::handlePowerButtonEvent( ) {
|
||
15 years ago
|
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);
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
* Handle the event for the suspend2ram/sleep button and call the related action.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::handleSleepButtonEvent() {
|
||
15 years ago
|
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.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::handleS2DiskButtonEvent(){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
// Only go to suspend on button event if we already resumed successful.
|
||
|
if (calledSuspend == -1) {
|
||
|
handleActionCall(settings->s2diskButtonAction, -1);
|
||
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to handle the lidclose event. If the screen get locked
|
||
15 years ago
|
* depends on the user specific settings.
|
||
|
* \param closed boolean with info if the lid is closed or not
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::handleLidEvent( bool closed ){
|
||
15 years ago
|
if (trace) kdDebug() << funcinfo << "IN: " << "Lid closed? " << closed << endl;
|
||
15 years ago
|
|
||
15 years ago
|
if (closed) {
|
||
15 years ago
|
// get new general settings! This could maybe removed if we
|
||
15 years ago
|
// could be shure, that the settings are actuall
|
||
|
settings->load_general_settings();
|
||
15 years ago
|
|
||
15 years ago
|
// 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 "
|
||
15 years ago
|
"be a problem with the selected \nlock "
|
||
15 years ago
|
"method or something else."),
|
||
|
SmallIcon("messagebox_warning", 20), this,
|
||
14 years ago
|
i18n("Warning").ascii(), 10000);
|
||
15 years ago
|
|
||
15 years ago
|
}
|
||
|
}
|
||
|
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();
|
||
15 years ago
|
}
|
||
15 years ago
|
|
||
|
if (settings->lockOnLidClose) {
|
||
|
activateLoginScreen();
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
if(!settings->disableNotifications)
|
||
|
KNotifyClient::event( this->winId(), "lid_opened_event", i18n("The Lid was opened."));
|
||
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to show the login dialog if the desktop was locked before the suspend.
|
||
15 years ago
|
*/
|
||
12 years ago
|
void tdepowersave::activateLoginScreen(){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
15 years ago
|
// get new general settings! This could maybe removed if we
|
||
15 years ago
|
// could be shure, that the settings are actuall
|
||
|
settings->load_general_settings();
|
||
15 years ago
|
|
||
15 years ago
|
if(settings->timeToFakeKeyAfterLock >= 0) {
|
||
14 years ago
|
TQTimer::singleShot(settings->timeToFakeKeyAfterLock, display, TQT_SLOT(fakeShiftKeyEvent()));
|
||
15 years ago
|
}
|
||
15 years ago
|
|
||
15 years ago
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT to set the current suspend type for later use.
|
||
15 years ago
|
*/
|
||
12 years ago
|
void tdepowersave::setSuspendType( TQString suspendtype){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
suspendType = suspendtype;
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
12 years ago
|
* \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
|
||
15 years ago
|
* result is written to the KDE configfile.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::_quit (){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
15 years ago
|
|
||
15 years ago
|
// set the KDE-Settings back to user default
|
||
13 years ago
|
if(getenv("TDE_FULL_SESSION")) {
|
||
15 years ago
|
// 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);
|
||
15 years ago
|
|
||
15 years ago
|
if(!settings->kde->displayEnergySaving) display->setDPMS(false);
|
||
|
else display->setDPMS(true);
|
||
15 years ago
|
|
||
15 years ago
|
display->has_DPMS = display->setDPMSTimeouts( settings->kde->displayStandby,
|
||
|
settings->kde->displaySuspend,
|
||
|
settings->kde->displayPowerOff);
|
||
|
}
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
// set, if this is a GNOME session, XScreensaver settings back to user default
|
||
14 years ago
|
TQString session = getenv("DESKTOP_SESSION");
|
||
15 years ago
|
if(session.startsWith("gnome")) {
|
||
|
display->resetXScreensaver();
|
||
|
}
|
||
15 years ago
|
|
||
|
if(!settings->autostartNeverAsk) {
|
||
12 years ago
|
TQString tmp1 = i18n ("Start tdepowersave automatically when you log in?");
|
||
15 years ago
|
int tmp2 = KMessageBox::questionYesNo ( 0, tmp1, i18n("Question"),
|
||
15 years ago
|
i18n("Start Automatically"), i18n("Do Not Start"));
|
||
|
config->setGroup("General");
|
||
|
config->writeEntry ("Autostart", tmp2 == KMessageBox::Yes);
|
||
|
config->sync ();
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT called if the user select a 'CPU Frequency Policy' from the menu ( \ref CPUFRETQ_MENU_ID ).
|
||
15 years ago
|
*/
|
||
12 years ago
|
void tdepowersave::do_setSpeedPolicy(int menu_id){
|
||
15 years ago
|
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"),
|
||
13 years ago
|
i18n("CPU Freq Policy %1 could not be set.").arg(speed_menu->text(menu_id)),
|
||
14 years ago
|
SmallIcon("messagebox_warning", 20), this, i18n("Warning").ascii(), 10000);
|
||
15 years ago
|
} else {
|
||
|
hwinfo->checkCurrentCPUFreqPolicy();
|
||
|
update();
|
||
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT called if the user select a scheme from the menu. If there is any errormessage
|
||
15 years ago
|
* while try to set the selected scheme, the user get a messagebox with info.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::do_setActiveScheme( int i ){
|
||
15 years ago
|
if (trace) kdDebug() << funcinfo << "IN: " << "set scheme to: " << i << endl;
|
||
|
|
||
14 years ago
|
if(!settings->schemes[i].isEmpty() && (settings->schemes[i] != settings->currentScheme)) {
|
||
15 years ago
|
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"),
|
||
13 years ago
|
i18n("Scheme %1 could not be activated.").arg(scheme_menu->text(i)),
|
||
14 years ago
|
SmallIcon("messagebox_warning", 20), this, i18n("Warning").ascii(), 5000);
|
||
15 years ago
|
}
|
||
15 years ago
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
* This function is invoked if something has to be updated. This including also menu entries.
|
||
15 years ago
|
* If the battery is in warning state (and powersave set pdaemon->send_battery_state_change_message)
|
||
15 years ago
|
* the function pop-up a messagebox.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::update(){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
15 years ago
|
|
||
15 years ago
|
int redraw_pixmap = 0;
|
||
14 years ago
|
TQString justMins;
|
||
15 years ago
|
|
||
15 years ago
|
/* 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);
|
||
15 years ago
|
|
||
|
if (suspend.suspend2disk && (suspend.suspend2disk_allowed ||
|
||
15 years ago
|
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);
|
||
|
}
|
||
|
|
||
15 years ago
|
if (suspend.suspend2ram && (suspend.suspend2ram_allowed ||
|
||
15 years ago
|
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 {
|
||
15 years ago
|
if (!suspend.standby)
|
||
15 years ago
|
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');
|
||
15 years ago
|
|
||
15 years ago
|
redraw_pixmap = 1;
|
||
|
hwinfo->update_info_primBattery_changed = false;
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
updateSchemeMenu();
|
||
|
|
||
|
if (redraw_pixmap){
|
||
|
redrawPixmap();
|
||
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
* This function is involved if the CPUFreqMenu must be updated.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::updateCPUFreqMenu(){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
if (hwinfo->supportCPUFreq() && hwinfo->isOnline() && hwinfo->isCpuFreqAllowed()) {
|
||
|
/* set CPU frequency menu entries *********/
|
||
|
/* speed menu has id 3 in context menu */
|
||
14 years ago
|
contextMenu()->setItemVisible(CPUFRETQ_MENU_ID, true);
|
||
|
contextMenu()->setItemEnabled(CPUFRETQ_MENU_ID, true);
|
||
|
contextMenu()->setItemVisible(CPUFRETQ_SEPARATOR_MENU_ID, true);
|
||
15 years ago
|
|
||
15 years ago
|
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)) {
|
||
14 years ago
|
contextMenu()->setItemEnabled(CPUFRETQ_MENU_ID, false);
|
||
|
contextMenu()->setItemVisible(CPUFRETQ_SEPARATOR_MENU_ID, true);
|
||
15 years ago
|
} else{
|
||
|
/* there were CPU freq policies, but they are not accessible any more */
|
||
|
/* delete speed_menu */
|
||
14 years ago
|
contextMenu()->setItemVisible(CPUFRETQ_MENU_ID, false);
|
||
|
contextMenu()->setItemVisible(CPUFRETQ_SEPARATOR_MENU_ID, false);
|
||
15 years ago
|
}
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
hwinfo->update_info_cpufreq_policy_changed = false;
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
15 years ago
|
* The function used to update the scheme menu. A update is needed if
|
||
15 years ago
|
* if there is maybe new schemes or if the current scheme changed or switched
|
||
15 years ago
|
* By this way also set the settings for screensaver and other parameter
|
||
15 years ago
|
* related to the selected scheme.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::updateSchemeMenu(){
|
||
15 years ago
|
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;
|
||
14 years ago
|
for ( TQStringList::iterator it = org_schemenames.begin(); it != org_schemenames.end(); ++it ) {
|
||
15 years ago
|
|
||
14 years ago
|
TQString _t = *it;
|
||
15 years ago
|
|
||
|
if ( *it == settings->ac_scheme ){
|
||
14 years ago
|
scheme_menu->insertItem( SmallIcon("scheme_power", TQIconSet::Automatic),
|
||
|
i18n( ((TQString)*it).ascii() ), x, x);
|
||
15 years ago
|
}
|
||
|
else{
|
||
|
if ( *it == settings->battery_scheme ){
|
||
14 years ago
|
scheme_menu->insertItem(SmallIcon("scheme_powersave", TQIconSet::Automatic),
|
||
14 years ago
|
i18n( (*it).ascii() ), x, x);
|
||
15 years ago
|
}
|
||
|
else{
|
||
14 years ago
|
if ((TQString)*it == "Acoustic"){
|
||
15 years ago
|
scheme_menu->insertItem(SmallIcon("scheme_acoustic",
|
||
14 years ago
|
TQIconSet::Automatic),
|
||
15 years ago
|
i18n("Acoustic"), x, x);
|
||
|
}
|
||
14 years ago
|
else if ((TQString)*it == "Presentation"){
|
||
15 years ago
|
scheme_menu->insertItem(SmallIcon("scheme_presentation",
|
||
14 years ago
|
TQIconSet::Automatic),
|
||
15 years ago
|
i18n("Presentation"), x, x);
|
||
15 years ago
|
|
||
15 years ago
|
}
|
||
14 years ago
|
else if((TQString)*it == "AdvancedPowersave") {
|
||
15 years ago
|
scheme_menu->insertItem(SmallIcon("scheme_advanced_powersave",
|
||
14 years ago
|
TQIconSet::Automatic),
|
||
15 years ago
|
i18n( "Advanced Powersave" ), x, x);
|
||
|
}
|
||
|
else {
|
||
14 years ago
|
scheme_menu->insertItem(i18n( (*it).ascii() ), x, x);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ( *it == settings->currentScheme ) {
|
||
|
scheme_menu->setItemChecked(x, true);
|
||
|
}
|
||
|
++x;
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
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);
|
||
|
}
|
||
|
|
||
|
|
||
|
/*!
|
||
15 years ago
|
* Reimplemented eventhandler for mouse enterEvent. This is called if the mouse cursor
|
||
12 years ago
|
* enters the widget. In this case if the user move the mouse cursor over the tdepowersave
|
||
15 years ago
|
* trayicon. \n \n
|
||
|
* We use this event to update the Tooltip with all needed information. The time beetween
|
||
14 years ago
|
* the event and the automatically popup of the TQToolTip should be long enought to collect
|
||
15 years ago
|
* the needed values and add a updated Tooltip.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::enterEvent( TQEvent */*qee*/ ){
|
||
15 years ago
|
|
||
|
updateTooltip();
|
||
|
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
* Event handler for mouse wheel events. If the system supports changing display
|
||
|
* brightness and changing brightness is enabled in the current scheme settings,
|
||
15 years ago
|
* this will raise the brightness by one level for wheel up events and lower the
|
||
15 years ago
|
* brightness by one level for wheel down events.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::wheelEvent (TQWheelEvent *qwe)
|
||
15 years ago
|
{
|
||
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
if (!hwinfo->supportBrightness() && settings->brightness)
|
||
|
return;
|
||
|
|
||
14 years ago
|
if (qwe->orientation () == Qt::Vertical) {
|
||
15 years ago
|
if (qwe->delta() > 0) {
|
||
|
do_brightnessUp(5);
|
||
|
} else {
|
||
|
do_brightnessDown(5);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
15 years ago
|
* 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.
|
||
15 years ago
|
*/
|
||
12 years ago
|
void tdepowersave::mousePressEvent(TQMouseEvent *qme){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
KSystemTray::mousePressEvent(qme);
|
||
|
if (hwinfo->isOnline()) {
|
||
14 years ago
|
if (qme->button() == Qt::RightButton){
|
||
15 years ago
|
// TODO check if maybe some rechecks needed
|
||
14 years ago
|
this->contextMenu()->exec(TQCursor::pos());
|
||
|
} else if (qme->button() == Qt::LeftButton) {
|
||
15 years ago
|
showDetailedDialog();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT called if the detaileddialog is closed. With this we prevent open
|
||
15 years ago
|
* the dialog twice, use this function to reset the used variables.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::closedetaileddialog() {
|
||
15 years ago
|
detailedIsShown = false;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
12 years ago
|
* \b TQT_SLOT used to display messeges in tdepowersave. This function
|
||
|
* block all messeges which we have in tdepowersave!
|
||
15 years ago
|
*/
|
||
12 years ago
|
void tdepowersave::showErrorMessage( TQString msg ){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
if(settings->psMsgAsPassivePopup) {
|
||
12 years ago
|
KPassivePopup::message("tdepowersave", msg, SmallIcon("messagebox_warning", 20),
|
||
14 years ago
|
this, i18n("Warning").ascii(), 10000);
|
||
15 years ago
|
} else {
|
||
|
kapp->updateUserTimestamp();
|
||
|
// KMessageBox::error( 0, msg);
|
||
|
KMessageBox::queuedMessageBox(0, KMessageBox::Error, msg);
|
||
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
|
||
|
/*!
|
||
15 years ago
|
* Use this function to set the SchemeSettings. This function currently set the
|
||
15 years ago
|
* e.g. the screensaver and dpms settings. Don't forget to call this function if
|
||
|
* a scheme is changed or if the settings changed.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::setSchemeSettings(){
|
||
15 years ago
|
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);
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
// --> 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);
|
||
|
}
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
} // TODO: check if this really work !!!
|
||
13 years ago
|
else if(getenv("TDE_FULL_SESSION")) {
|
||
15 years ago
|
// 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 ?!
|
||
15 years ago
|
}
|
||
15 years ago
|
}
|
||
|
} 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();
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
// --> 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);
|
||
|
}
|
||
|
}
|
||
13 years ago
|
else if(getenv("TDE_FULL_SESSION")){
|
||
15 years ago
|
// try to reset the KDE screensaver/DPMS settings (if there are also
|
||
15 years ago
|
// 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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
// --> 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);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT which called to set and start the autosuspend monitoring.
|
||
15 years ago
|
* \param resumed boolean value which represent information if machine
|
||
15 years ago
|
* currently back from suspend/standby
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::setAutoSuspend( bool resumed ){
|
||
15 years ago
|
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();
|
||
14 years ago
|
connect(autoSuspend, TQT_SIGNAL(inactivityTimeExpired()), this,
|
||
|
TQT_SLOT(do_autosuspendWarn()));
|
||
15 years ago
|
}
|
||
15 years ago
|
|
||
15 years ago
|
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);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT which called to set and start the autodimm monitoring.
|
||
15 years ago
|
* \param resumed boolean value which represent information if machine
|
||
15 years ago
|
* currently back from suspend/standby
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::setAutoDimm( bool resumed ){
|
||
15 years ago
|
if (trace) kdDebug() << funcinfo << "IN: " << "resumed? " << resumed << endl;
|
||
|
|
||
15 years ago
|
if(settings->autoDimmAfter > 0 && settings->autoDimm) {
|
||
15 years ago
|
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();
|
||
14 years ago
|
connect(autoDimm, TQT_SIGNAL(inactivityTimeExpired()), this, TQT_SLOT(do_downDimm()));
|
||
|
connect(autoDimm, TQT_SIGNAL(UserIsActiveAgain()), this, TQT_SLOT(do_upDimm()));
|
||
15 years ago
|
}
|
||
|
|
||
|
if (settings->autoDimmSBlistEnabled) {
|
||
|
autoDimm->start(settings->autoDimmAfter * 60, settings->autoDimmSBlist);
|
||
|
} else {
|
||
|
autoDimm->start(settings->autoDimmAfter * 60, settings->autoDimmGBlist);
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
if (autoDimm)
|
||
|
autoDimm->stop();
|
||
15 years ago
|
}
|
||
15 years ago
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
// -------- start KNotify functions ------------- //
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT called if a battery warning state reached and related signal recieved.
|
||
15 years ago
|
* 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
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::notifyBatteryStatusChange ( int type, int state ) {
|
||
15 years ago
|
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) {
|
||
12 years ago
|
kdDebug() << "tdepowersave::notifyBatteryStatusChange: Battery is charging, ignore event" << endl;
|
||
15 years ago
|
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
|
||
12 years ago
|
kdDebug() << "tdepowersave::notifyBatteryStatusChange: Machine is on AC, ignore event" << endl;
|
||
15 years ago
|
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: "
|
||
13 years ago
|
"%1 hours and %2 minutes.").arg(min/60).arg(min%60));
|
||
15 years ago
|
// 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: "
|
||
13 years ago
|
"%1 hours and %2 minutes.").arg(min/60).arg(min%60));
|
||
15 years ago
|
// 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")
|
||
13 years ago
|
.arg(min/ 60).arg(min%60));
|
||
15 years ago
|
|
||
14 years ago
|
TQTimer::singleShot(30000, this, TQT_SLOT(handleCriticalBatteryActionCall()));
|
||
15 years ago
|
} 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.")
|
||
13 years ago
|
.arg(min/ 60).arg(min%60));
|
||
15 years ago
|
|
||
|
handleActionCall(settings->batteryCriticalLevelAction,
|
||
|
settings->batteryCriticalLevelActionValue);
|
||
|
}
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
15 years ago
|
}
|
||
15 years ago
|
} 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
|
||
14 years ago
|
* because of TQTimer::singleShot() can't take param ...
|
||
15 years ago
|
* NOTE: Use this only for SHUTDOWN atm
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::handleCriticalBatteryActionCall () {
|
||
15 years ago
|
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
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::handleActionCall ( action action, int value , bool checkAC, bool batWarnCall ) {
|
||
15 years ago
|
if (trace) kdDebug() << funcinfo << "IN: " << "action: " << action << "value: " << value
|
||
15 years ago
|
<< "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:
|
||
14 years ago
|
TQTimer::singleShot(100, this, TQT_SLOT(do_suspend2ram()));
|
||
15 years ago
|
break;
|
||
|
case GO_SUSPEND2DISK:
|
||
14 years ago
|
TQTimer::singleShot(100, this, TQT_SLOT(do_suspend2disk()));
|
||
15 years ago
|
break;
|
||
|
case BRIGHTNESS:
|
||
|
hwinfo->setBrightness( -1, value );
|
||
|
break;
|
||
14 years ago
|
case CPUFRETQ_POWERSAVE:
|
||
15 years ago
|
hwinfo->setCPUFreq( POWERSAVE );
|
||
|
break;
|
||
14 years ago
|
case CPUFRETQ_DYNAMIC:
|
||
15 years ago
|
hwinfo->setCPUFreq( DYNAMIC, settings->cpuFreqDynamicPerformance );
|
||
|
break;
|
||
14 years ago
|
case CPUFRETQ_PERFORMANCE:
|
||
15 years ago
|
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);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT called if ac stated changed. Here we emit the related KNotify event.
|
||
15 years ago
|
* 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 ...)
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::handleACStatusChange ( bool acstate , bool notifyEvent ) {
|
||
15 years ago
|
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"));
|
||
|
}
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
// handle switch to AC/battery default scheme
|
||
|
if (acstate) {
|
||
13 years ago
|
index = settings->schemes.findIndex(settings->ac_scheme);
|
||
15 years ago
|
} else {
|
||
13 years ago
|
index = settings->schemes.findIndex(settings->battery_scheme);
|
||
15 years ago
|
}
|
||
15 years ago
|
|
||
15 years ago
|
if (index != -1)
|
||
|
do_setActiveScheme(index);
|
||
15 years ago
|
|
||
15 years ago
|
// update applet
|
||
|
update();
|
||
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT called if scheme switched. Here we emit the related KNotify events
|
||
15 years ago
|
* if they are not disabled.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::notifySchemeSwitch() {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
if(!settings->disableNotifications) {
|
||
14 years ago
|
TQString _scheme = settings->currentScheme;
|
||
|
TQString eventType;
|
||
15 years ago
|
|
||
|
if( _scheme != "Performance" && _scheme != "Powersave" && _scheme != "Acoustic" &&
|
||
|
_scheme != "Presentation" && _scheme != "AdvancedPowersave" )
|
||
|
eventType = "scheme_Unknown";
|
||
|
else
|
||
|
eventType = "scheme_" + _scheme;
|
||
|
|
||
15 years ago
|
KNotifyClient::event( this->winId(), eventType,
|
||
13 years ago
|
i18n("Switched to scheme: %1").arg(i18n(_scheme.ascii())).ascii());
|
||
15 years ago
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT called if the machine suspend. Here we emit the related KNotify events
|
||
15 years ago
|
* if they are not disabled.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::notifySuspend( int suspendType ) {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
if(!settings->disableNotifications) {
|
||
|
switch (suspendType) {
|
||
|
case SUSPEND2DISK:
|
||
15 years ago
|
KNotifyClient::event( this->winId(), "suspend2disk_event",
|
||
15 years ago
|
i18n("System is going into %1 now.").
|
||
|
arg(i18n("Suspend to Disk")));
|
||
|
break;
|
||
|
case SUSPEND2RAM:
|
||
15 years ago
|
KNotifyClient::event( this->winId(), "suspend2ram_event",
|
||
15 years ago
|
i18n("System is going into %1 now.").
|
||
|
arg(i18n("Suspend to RAM")));
|
||
|
break;
|
||
|
case STANDBY:
|
||
15 years ago
|
KNotifyClient::event( this->winId(), "standby_event",
|
||
15 years ago
|
i18n("System is going into %1 now.").
|
||
|
arg(i18n("Standby")));
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT called to independent handleResumeSignal() from event loop and
|
||
15 years ago
|
* to avoid problems with the QT3 D-Bus bindings
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::forwardResumeSignal( int result ) {
|
||
15 years ago
|
if (trace) kdDebug() << funcinfo << "IN: " << "result: " << result << endl;
|
||
15 years ago
|
|
||
15 years ago
|
resume_result = result;
|
||
|
|
||
14 years ago
|
TQTimer::singleShot(100, this, TQT_SLOT(handleResumeSignal()));
|
||
15 years ago
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT called if the machine suspend. Here we emit the related KNotify events
|
||
15 years ago
|
* if they are not disabled.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::handleResumeSignal() {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
// fake key to show the login dialog if we locked the screen
|
||
|
if(settings->lockOnSuspend) {
|
||
|
activateLoginScreen();
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
// 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:
|
||
15 years ago
|
KNotifyClient::event( this->winId(), "resume_from_suspend2disk_event",
|
||
13 years ago
|
i18n("System is resumed from %1.").arg(
|
||
15 years ago
|
i18n("Suspend to Disk")));
|
||
|
break;
|
||
|
case SUSPEND2RAM:
|
||
15 years ago
|
KNotifyClient::event( this->winId(), "resume_from_suspend2ram_event",
|
||
13 years ago
|
i18n("System is resumed from %1.").arg(
|
||
15 years ago
|
i18n("Suspend to RAM")));
|
||
|
break;
|
||
|
case STANDBY:
|
||
15 years ago
|
KNotifyClient::event( this->winId(), "resume_from_standby_event",
|
||
13 years ago
|
i18n("System is resumed from %1.").arg(
|
||
15 years ago
|
i18n("Standby")));
|
||
|
break;
|
||
|
default:
|
||
|
kdError() << "called suspend type unknown" << endl;
|
||
|
break;
|
||
15 years ago
|
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// handle result of the resume/suspend
|
||
15 years ago
|
// 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)) {
|
||
15 years ago
|
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)) {
|
||
15 years ago
|
KPassivePopup::message( i18n("WARNING"),
|
||
15 years ago
|
i18n("Could not remount (all) external storage"
|
||
15 years ago
|
" media."), SmallIcon("messagebox_warning", 20),
|
||
14 years ago
|
this, i18n("Warning").ascii(), 15000);
|
||
15 years ago
|
}
|
||
|
} else {
|
||
15 years ago
|
kdError() << "Unknown error while suspend. Errorcode: " << resume_result << endl;
|
||
14 years ago
|
TQString msg;
|
||
15 years ago
|
|
||
15 years ago
|
msg = i18n("An unknown error occurred while %1. The errorcode is: '%2'").
|
||
13 years ago
|
arg(getSuspendString(calledSuspend)).arg(resume_result);
|
||
15 years ago
|
|
||
|
#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;
|
||
15 years ago
|
}
|
||
15 years ago
|
#else
|
||
|
logview = new LogViewer ("/var/log/pm-suspend.log");
|
||
|
logview->show();
|
||
|
#endif
|
||
|
}
|
||
|
#else
|
||
13 years ago
|
KMessageBox::error(0, msg, i18n("Error while %1").arg(getSuspendString(calledSuspend)));
|
||
15 years ago
|
#endif
|
||
|
}
|
||
|
// set back ... suspend is handled
|
||
|
calledSuspend = -1;
|
||
|
resume_result = 0;
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
14 years ago
|
* \b TQT_SLOT called if the state of the current session change
|
||
15 years ago
|
* \param state boolean represent the state of the session
|
||
15 years ago
|
* TODO: fix scheme handling
|
||
15 years ago
|
* TODO: fix critical battery situations (see the todo file in the source)
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::handleSessionState (bool state) {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
if (state) {
|
||
|
// session is active again
|
||
|
if (settings->autoSuspend) disableAutosuspend(false);
|
||
|
if (settings->autoDimm) setAutoDimm(false);
|
||
15 years ago
|
/* handle may missed/not set AC status changes while the
|
||
15 years ago
|
session was inactive and set them to the default schemes ?! */
|
||
|
handleACStatusChange(hwinfo->getAcAdapter(), false);
|
||
15 years ago
|
|
||
15 years ago
|
} else {
|
||
|
// session is now inactive
|
||
|
if (settings->autoSuspend) disableAutosuspend(true);
|
||
|
if (settings->autoDimm) autoDimm->stop();
|
||
15 years ago
|
}
|
||
15 years ago
|
|
||
|
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
|
||
14 years ago
|
* \return TQString with the translated name or NULL if it fail
|
||
15 years ago
|
*/
|
||
12 years ago
|
TQString tdepowersave::getSuspendString (int type) {
|
||
15 years ago
|
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:
|
||
14 years ago
|
return TQString();
|
||
15 years ago
|
}
|
||
|
|
||
|
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
|
||
|
*/
|
||
12 years ago
|
bool tdepowersave::lockScreen(){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
15 years ago
|
|
||
15 years ago
|
settings->load_general_settings();
|
||
15 years ago
|
|
||
15 years ago
|
return display->lockScreen( settings->lockmethod );
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
* DCOP Interface funtion to return the name of the current powersave scheme.
|
||
14 years ago
|
* \return TQString with the name of the current scheme
|
||
15 years ago
|
*/
|
||
12 years ago
|
TQString tdepowersave::currentScheme (){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
15 years ago
|
|
||
15 years ago
|
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.
|
||
14 years ago
|
* \return TQString with the name of the current cpuFreqPolicy
|
||
15 years ago
|
*/
|
||
12 years ago
|
TQString tdepowersave::currentCPUFreqPolicy() {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
if(hwinfo->isOnline()) {
|
||
14 years ago
|
TQString _cpuFreq = "";
|
||
15 years ago
|
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";
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
15 years ago
|
* DCOP Interface funtion to send a list with the allowed
|
||
15 years ago
|
* CPU Frequency states.
|
||
14 years ago
|
* \return TQStringList with the supported CPUFreq states
|
||
15 years ago
|
*/
|
||
12 years ago
|
TQStringList tdepowersave::listCPUFreqPolicies() {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
14 years ago
|
TQStringList ret_list;
|
||
15 years ago
|
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
|
||
14 years ago
|
* \param policy TQString with the policy to set, only values from
|
||
15 years ago
|
* list_CPUFreqPolicies are allowed (except "NOT SUPPORTED")
|
||
|
* \return boolean with the result of set the requested CPUFreq policy
|
||
15 years ago
|
* \retval true if successful set
|
||
15 years ago
|
* \retval false if not supported or any other failure
|
||
|
*/
|
||
12 years ago
|
bool tdepowersave::do_setCPUFreqPolicy( TQString policy ) {
|
||
15 years ago
|
if (trace) kdDebug() << funcinfo << "IN: " << "policy: " << policy << endl;
|
||
|
|
||
15 years ago
|
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
15 years ago
|
* DCOP Interface funtion to send a list with the supported and enabled
|
||
15 years ago
|
* sleeping states.
|
||
14 years ago
|
* \return TQStringList with the supported spleeping states
|
||
15 years ago
|
*/
|
||
12 years ago
|
TQStringList tdepowersave::allowed_sleepingStates(){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
15 years ago
|
|
||
14 years ago
|
TQStringList sleepList;
|
||
15 years ago
|
if(hwinfo->isOnline()) {
|
||
15 years ago
|
if (suspend.suspend2disk && (suspend.suspend2disk_allowed ||
|
||
|
suspend.suspend2disk_allowed == -1)){
|
||
15 years ago
|
sleepList.append("suspendToDisk");
|
||
|
}
|
||
15 years ago
|
if (suspend.suspend2ram && (suspend.suspend2ram_allowed ||
|
||
|
suspend.suspend2ram_allowed == -1)){
|
||
15 years ago
|
sleepList.append("suspendToRAM");
|
||
|
}
|
||
15 years ago
|
if (suspend.standby && (suspend.standby_allowed || suspend.standby_allowed == -1)){
|
||
15 years ago
|
sleepList.append("standBy");
|
||
15 years ago
|
}
|
||
15 years ago
|
if(sleepList.isEmpty()){
|
||
|
sleepList.append("NO_SLEEPING_STATES_SUPPORTED");
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
sleepList.append("ERROR: D-Bus and/or HAL not running");
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
kdDebugFuncOut(trace);
|
||
|
return sleepList;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
* DCOP Interface funtion to send a list with the all schemes.
|
||
14 years ago
|
* \return TQStringList with all schemes
|
||
15 years ago
|
*/
|
||
12 years ago
|
TQStringList tdepowersave::listSchemes(){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
14 years ago
|
TQStringList _schemeList;
|
||
15 years ago
|
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
|
||
14 years ago
|
* \param _scheme TQString with the scheme to set, scheme should be
|
||
15 years ago
|
* named as list from list_schemes()
|
||
|
*/
|
||
12 years ago
|
bool tdepowersave::do_setScheme( TQString /*_scheme*/ ) {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
/* int index;
|
||
13 years ago
|
index = settings->schemes.findIndex(_scheme);
|
||
15 years ago
|
|
||
|
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
|
||
|
*/
|
||
12 years ago
|
bool tdepowersave::do_suspendToDisk(){
|
||
15 years ago
|
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
|
||
|
*/
|
||
12 years ago
|
bool tdepowersave::do_suspendToRAM(){
|
||
15 years ago
|
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
|
||
|
*/
|
||
12 years ago
|
bool tdepowersave::do_standBy(){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
kdDebugFuncOut(trace);
|
||
|
return do_standby();
|
||
|
}
|
||
|
|
||
|
//! dcop function to set the brightness up
|
||
12 years ago
|
bool tdepowersave::do_brightnessUp(int percentageStep) {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
15 years ago
|
|
||
15 years ago
|
bool retval = false;
|
||
15 years ago
|
|
||
15 years ago
|
if(hwinfo->isOnline()) {
|
||
|
retval = hwinfo->setBrightnessUp(percentageStep);
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
kdDebugFuncOut(trace);
|
||
|
return retval;
|
||
|
}
|
||
|
|
||
|
//! dcop function to set the brightness down
|
||
12 years ago
|
bool tdepowersave::do_brightnessDown(int percentageStep) {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
15 years ago
|
|
||
15 years ago
|
bool retval = false;
|
||
15 years ago
|
|
||
15 years ago
|
if(hwinfo->isOnline()) {
|
||
|
retval = hwinfo->setBrightnessDown(percentageStep);
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
kdDebugFuncOut(trace);
|
||
|
return retval;
|
||
|
}
|
||
|
|
||
|
|
||
|
/*!
|
||
15 years ago
|
* DCOP Interface funtion to stop/start the Autosuspend
|
||
15 years ago
|
* \param disable boolean which tell if the autosuspend should be stopped (true)
|
||
|
* or started (false).
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::disableAutosuspend( bool disable ){
|
||
15 years ago
|
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.
|
||
|
*/
|
||
12 years ago
|
void tdepowersave::showDetailedDialog( ){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
if (detailedIsShown) {
|
||
|
detailedDlg->close();
|
||
|
delete(detailedDlg);
|
||
|
closedetaileddialog();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
detailedDlg = new detaileddialog(hwinfo, &fullIcon, settings);
|
||
|
|
||
|
if (detailedDlg) {
|
||
|
detailedDlg->show();
|
||
|
detailedIsShown = true;
|
||
|
}
|
||
15 years ago
|
|
||
14 years ago
|
connect(detailedDlg, TQT_SIGNAL(destroyed()), this, TQT_SLOT(closedetaileddialog()));
|
||
15 years ago
|
|
||
|
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)
|
||
15 years ago
|
* \retval true if correct opend
|
||
15 years ago
|
*/
|
||
12 years ago
|
bool tdepowersave::openConfigureDialog (){
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
15 years ago
|
|
||
15 years ago
|
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
|
||
|
*/
|
||
12 years ago
|
bool tdepowersave::currentSchemeManagesDPMS () {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
return settings->specPMSettings;
|
||
15 years ago
|
|
||
15 years ago
|
kdDebugFuncOut(trace);
|
||
|
}
|
||
|
|
||
|
|
||
|
//! dcop funtion to get the current brightness level
|
||
12 years ago
|
int tdepowersave::brightnessGet() {
|
||
15 years ago
|
kdDebugFuncIn(trace);
|
||
|
|
||
|
int retval = -1;
|
||
|
|
||
|
if (hwinfo->supportBrightness()) {
|
||
|
retval = (int)(((float)hwinfo->getCurrentBrightnessLevel() / (float)hwinfo->getMaxBrightnessLevel()-1) * 100.0);
|
||
|
}
|
||
|
|
||
|
kdDebugFuncOut(trace);
|
||
15 years ago
|
|
||
15 years ago
|
return retval;
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "tdepowersave.moc"
|