Add kpowersave shortcut in kcontrol 'energy' feature

pull/2/head
Francois Andriot 11 years ago committed by Slávek Banko
parent e988e6ee41
commit 533941e5dd

@ -26,6 +26,7 @@
#include <tqlabel.h> #include <tqlabel.h>
#include <tqlayout.h> #include <tqlayout.h>
#include <tqwhatsthis.h> #include <tqwhatsthis.h>
#include <tqpushbutton.h>
#include <tdeconfig.h> #include <tdeconfig.h>
#include <kcursor.h> #include <kcursor.h>
@ -36,6 +37,7 @@
#include <krun.h> #include <krun.h>
#include <kstandarddirs.h> #include <kstandarddirs.h>
#include <kurllabel.h> #include <kurllabel.h>
#include <dcopref.h>
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
@ -140,6 +142,7 @@ KEnergy::KEnergy(TQWidget *parent, const char *name)
m_Suspend = DFLT_SUSPEND; m_Suspend = DFLT_SUSPEND;
m_Off = DFLT_OFF; m_Off = DFLT_OFF;
m_bDPMS = false; m_bDPMS = false;
m_bKPowersave = false;
m_bMaintainSanity = true; m_bMaintainSanity = true;
setQuickHelp( i18n("<h1>Display Power Control</h1> If your display supports" setQuickHelp( i18n("<h1>Display Power Control</h1> If your display supports"
@ -154,6 +157,13 @@ KEnergy::KEnergy(TQWidget *parent, const char *name)
#ifdef HAVE_DPMS #ifdef HAVE_DPMS
int dummy; int dummy;
m_bDPMS = DPMSQueryExtension(tqt_xdisplay(), &dummy, &dummy); m_bDPMS = DPMSQueryExtension(tqt_xdisplay(), &dummy, &dummy);
DCOPRef kpowersave("kpowersave", "KPowersaveIface");
DCOPReply managingDPMS = kpowersave.call("currentSchemeManagesDPMS()");
if (managingDPMS.isValid()) {
m_bKPowersave = managingDPMS;
m_bDPMS = !m_bKPowersave;
}
#endif #endif
TQVBoxLayout *top = new TQVBoxLayout(this, 0, KDialog::spacingHint()); TQVBoxLayout *top = new TQVBoxLayout(this, 0, KDialog::spacingHint());
@ -162,14 +172,24 @@ KEnergy::KEnergy(TQWidget *parent, const char *name)
TQLabel *lbl; TQLabel *lbl;
if (m_bDPMS) { if (m_bDPMS) {
m_pCBEnable= new TQCheckBox(i18n("&Enable display power management" ), this); TDEGlobal::locale()->insertCatalogue("kpowersave");
connect(m_pCBEnable, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotChangeEnable(bool))); // ### these i18n strings need to be synced with kpowersave !!
hbox->addWidget(m_pCBEnable); m_pCBEnable= new TQCheckBox(i18n("&Enable display power management" ), this);
connect(m_pCBEnable, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotChangeEnable(bool)));
hbox->addWidget(m_pCBEnable);
TQWhatsThis::add( m_pCBEnable, i18n("Check this option to enable the" TQWhatsThis::add( m_pCBEnable, i18n("Check this option to enable the"
" power saving features of your display.") ); " power saving features of your display.") );
// ###
} else if(m_bKPowersave) {
m_pCBEnable = new TQCheckBox(i18n("&Enable specific display power management"), this);
hbox->addWidget(m_pCBEnable);
m_bEnabled = false;
m_pCBEnable->setChecked(true);
m_pCBEnable->setEnabled(false);
} else { } else {
lbl = new TQLabel(i18n("Your display does not support power saving."), this); lbl = new TQLabel(i18n("Your display does not support power saving."), this);
hbox->addWidget(lbl); hbox->addWidget(lbl);
} }
KURLLabel *logo = new KURLLabel(this); KURLLabel *logo = new KURLLabel(this);
@ -183,6 +203,7 @@ connect(logo, TQT_SIGNAL(leftClickedURL(const TQString&)), TQT_SLOT(openURL(cons
hbox->addWidget(logo); hbox->addWidget(logo);
// Sliders // Sliders
if (!m_bKPowersave) {
m_pStandbySlider = new KIntNumInput(m_Standby, this); m_pStandbySlider = new KIntNumInput(m_Standby, this);
m_pStandbySlider->setLabel(i18n("&Standby after:")); m_pStandbySlider->setLabel(i18n("&Standby after:"));
m_pStandbySlider->setRange(0, 120, 10); m_pStandbySlider->setRange(0, 120, 10);
@ -218,6 +239,16 @@ connect(logo, TQT_SIGNAL(leftClickedURL(const TQString&)), TQT_SLOT(openURL(cons
" greatest level of power saving that can be achieved while the" " greatest level of power saving that can be achieved while the"
" display is still physically turned on.") ); " display is still physically turned on.") );
} else {
m_pStandbySlider = 0;
m_pSuspendSlider = 0;
m_pOffSlider = 0;
TQPushButton* btnKPowersave = new TQPushButton(this);
btnKPowersave->setText(i18n("Configure KPowersave..."));
connect(btnKPowersave, TQT_SIGNAL(clicked()), TQT_SLOT(slotLaunchKPowersave()));
top->addWidget(btnKPowersave);
}
top->addStretch(); top->addStretch();
if (m_bDPMS) if (m_bDPMS)
@ -270,7 +301,9 @@ void KEnergy::defaults()
void KEnergy::readSettings() void KEnergy::readSettings()
{ {
m_bEnabled = m_pConfig->readBoolEntry("displayEnergySaving", false); if (m_bDPMS) {
m_bEnabled = m_pConfig->readBoolEntry("displayEnergySaving", false);
}
m_Standby = m_pConfig->readNumEntry("displayStandby", DFLT_STANDBY); m_Standby = m_pConfig->readNumEntry("displayStandby", DFLT_STANDBY);
m_Suspend = m_pConfig->readNumEntry("displaySuspend", DFLT_SUSPEND); m_Suspend = m_pConfig->readNumEntry("displaySuspend", DFLT_SUSPEND);
m_Off = m_pConfig->readNumEntry("displayPowerOff", DFLT_OFF); m_Off = m_pConfig->readNumEntry("displayPowerOff", DFLT_OFF);
@ -298,19 +331,29 @@ void KEnergy::writeSettings()
} }
void KEnergy::slotLaunchKPowersave()
{
DCOPRef r("kpowersave", "KPowersaveIface");
r.send("openConfigureDialog()");
}
void KEnergy::showSettings() void KEnergy::showSettings()
{ {
m_bMaintainSanity = false; m_bMaintainSanity = false;
if (m_bDPMS) if (m_bDPMS) {
m_pCBEnable->setChecked(m_bEnabled); m_pCBEnable->setChecked(m_bEnabled);
}
m_pStandbySlider->setEnabled(m_bEnabled);
m_pStandbySlider->setValue(m_Standby); if (!m_bKPowersave) {
m_pSuspendSlider->setEnabled(m_bEnabled); m_pStandbySlider->setEnabled(m_bEnabled);
m_pSuspendSlider->setValue(m_Suspend); m_pStandbySlider->setValue(m_Standby);
m_pOffSlider->setEnabled(m_bEnabled); m_pSuspendSlider->setEnabled(m_bEnabled);
m_pOffSlider->setValue(m_Off); m_pSuspendSlider->setValue(m_Suspend);
m_pOffSlider->setEnabled(m_bEnabled);
m_pOffSlider->setValue(m_Off);
}
m_bMaintainSanity = true; m_bMaintainSanity = true;
} }

@ -44,6 +44,7 @@ private slots:
void slotChangeStandby(int); void slotChangeStandby(int);
void slotChangeSuspend(int); void slotChangeSuspend(int);
void slotChangeOff(int); void slotChangeOff(int);
void slotLaunchKPowersave();
void openURL(const TQString &); void openURL(const TQString &);
private: private:
@ -54,7 +55,7 @@ private:
static void applySettings(bool, int, int, int); static void applySettings(bool, int, int, int);
friend void init_energy(); friend void init_energy();
bool m_bChanged, m_bDPMS, m_bEnabled, m_bMaintainSanity; bool m_bChanged, m_bDPMS, m_bKPowersave, m_bEnabled, m_bMaintainSanity;
int m_Standby, m_Suspend, m_Off; int m_Standby, m_Suspend, m_Off;
int m_StandbyDesired, m_SuspendDesired, m_OffDesired; int m_StandbyDesired, m_SuspendDesired, m_OffDesired;

Loading…
Cancel
Save