Completely disable autosuspend functions if system does not support suspend

This relates to Bug 1615
pull/1/head
Timothy Pearson 11 years ago
parent f5d1ba39dc
commit ba6b20795d

@ -88,12 +88,15 @@ ConfigureDialog::ConfigureDialog( TDEConfig *_config, HardwareInfo *_hwinfo, Set
// get the correct available suspend types // get the correct available suspend types
SuspendStates suspend = hwinfo->getSuspendSupport(); SuspendStates suspend = hwinfo->getSuspendSupport();
if( suspend.suspend2ram && (suspend.suspend2ram_allowed || suspend.suspend2ram_allowed == -1)) if( suspend.suspend2ram && (suspend.suspend2ram_allowed || suspend.suspend2ram_allowed == -1)) {
actions.append("Suspend to RAM"); actions.append("Suspend to RAM");
if ( suspend.suspend2disk && (suspend.suspend2disk_allowed || suspend.suspend2disk_allowed == -1)) }
if ( suspend.suspend2disk && (suspend.suspend2disk_allowed || suspend.suspend2disk_allowed == -1)) {
actions.append("Suspend to Disk"); actions.append("Suspend to Disk");
if ( suspend.standby && (suspend.standby_allowed || suspend.standby_allowed == -1)) }
if ( suspend.standby && (suspend.standby_allowed || suspend.standby_allowed == -1)) {
actions.append("Standby"); actions.append("Standby");
}
setIcons(); setIcons();
setTooltips(); setTooltips();
@ -147,26 +150,26 @@ void ConfigureDialog::setSchemeList(){
for ( TQStringList::Iterator it = schemes.begin(); it != schemes.end(); ++it ) { for ( TQStringList::Iterator it = schemes.begin(); it != schemes.end(); ++it ) {
const char *_tmp = (*it).ascii(); const char *_tmp = (*it).ascii();
if(_tmp == "Performance" || _tmp == i18n("Performance")) { if((*it) == "Performance" || (*it) == i18n("Performance")) {
listBox_schemes->insertItem(SmallIcon("scheme_power", TQIconSet::Automatic), i18n(_tmp)); listBox_schemes->insertItem(SmallIcon("scheme_power", TQIconSet::Automatic), i18n(_tmp));
cB_acScheme->insertItem(i18n(_tmp)); cB_acScheme->insertItem(i18n(_tmp));
cB_batteryScheme->insertItem(i18n(_tmp)); cB_batteryScheme->insertItem(i18n(_tmp));
} else if(_tmp == "Powersave" || _tmp == i18n("Powersave")) { } else if((*it) == "Powersave" || (*it) == i18n("Powersave")) {
listBox_schemes->insertItem(SmallIcon("scheme_powersave", TQIconSet::Automatic), listBox_schemes->insertItem(SmallIcon("scheme_powersave", TQIconSet::Automatic),
i18n(_tmp)); i18n(_tmp));
cB_acScheme->insertItem(i18n(_tmp)); cB_acScheme->insertItem(i18n(_tmp));
cB_batteryScheme->insertItem(i18n(_tmp)); cB_batteryScheme->insertItem(i18n(_tmp));
} else if(_tmp == "Presentation" || _tmp == i18n("Presentation")){ } else if((*it) == "Presentation" || (*it) == i18n("Presentation")){
listBox_schemes->insertItem(SmallIcon("scheme_presentation", TQIconSet::Automatic), listBox_schemes->insertItem(SmallIcon("scheme_presentation", TQIconSet::Automatic),
i18n(_tmp)); i18n(_tmp));
cB_acScheme->insertItem(i18n(_tmp)); cB_acScheme->insertItem(i18n(_tmp));
cB_batteryScheme->insertItem(i18n(_tmp)); cB_batteryScheme->insertItem(i18n(_tmp));
} else if(_tmp == "Acoustic" || _tmp == i18n("Acoustic")) { } else if((*it) == "Acoustic" || (*it) == i18n("Acoustic")) {
listBox_schemes->insertItem(SmallIcon("scheme_acoustic", TQIconSet::Automatic), listBox_schemes->insertItem(SmallIcon("scheme_acoustic", TQIconSet::Automatic),
i18n(_tmp)); i18n(_tmp));
cB_acScheme->insertItem(i18n(_tmp)); cB_acScheme->insertItem(i18n(_tmp));
cB_batteryScheme->insertItem(i18n(_tmp)); cB_batteryScheme->insertItem(i18n(_tmp));
} else if(_tmp == "AdvancedPowersave" || _tmp == i18n("Advanced Powersave")) { } else if((*it) == "AdvancedPowersave" || (*it) == i18n("Advanced Powersave")) {
listBox_schemes->insertItem(SmallIcon("scheme_advanced_powersave", listBox_schemes->insertItem(SmallIcon("scheme_advanced_powersave",
TQIconSet::Automatic), i18n("Advanced Powersave")); TQIconSet::Automatic), i18n("Advanced Powersave"));
cB_acScheme->insertItem(i18n("Advanced Powersave")); cB_acScheme->insertItem(i18n("Advanced Powersave"));
@ -240,12 +243,15 @@ void ConfigureDialog::setIcons(){
tB_scheme->setItemIconSet( 0 ,SmallIcon("tdescreensaver", TQIconSet::Automatic)); tB_scheme->setItemIconSet( 0 ,SmallIcon("tdescreensaver", TQIconSet::Automatic));
tB_scheme->setItemIconSet( 1 ,SmallIcon("display", TQIconSet::Automatic)); tB_scheme->setItemIconSet( 1 ,SmallIcon("display", TQIconSet::Automatic));
if(actions[0] == "Suspend to Disk") if(actions[0] == "Suspend to Disk") {
tB_scheme->setItemIconSet( 2 ,SmallIcon("suspend_to_disk", TQIconSet::Automatic)); tB_scheme->setItemIconSet( 2 ,SmallIcon("suspend_to_disk", TQIconSet::Automatic));
else if(actions[0] == "Suspend to RAM") }
else if(actions[0] == "Suspend to RAM") {
tB_scheme->setItemIconSet( 2 ,SmallIcon("suspend_to_ram", TQIconSet::Automatic)); tB_scheme->setItemIconSet( 2 ,SmallIcon("suspend_to_ram", TQIconSet::Automatic));
else if(actions[0] == "Standby") }
else if(actions[0] == "Standby") {
tB_scheme->setItemIconSet( 2 ,SmallIcon("stand_by", TQIconSet::Automatic)); tB_scheme->setItemIconSet( 2 ,SmallIcon("stand_by", TQIconSet::Automatic));
}
tB_scheme->setItemIconSet( 3 ,SmallIcon("autodimm", TQIconSet::Automatic)); tB_scheme->setItemIconSet( 3 ,SmallIcon("autodimm", TQIconSet::Automatic));
tB_scheme->setItemIconSet( 4 ,SmallIcon("processor", TQIconSet::Automatic)); tB_scheme->setItemIconSet( 4 ,SmallIcon("processor", TQIconSet::Automatic));
@ -630,6 +636,11 @@ void ConfigureDialog::setConfigToDialog( int schemeID ){
} }
} }
if (actions.count() < 1) {
cB_autoSuspend->setEnabled(false);
cB_autoSuspend->setChecked(false);
}
cB_disableNotifications->setChecked(tdeconfig->readBoolEntry("disableNotifications",false)); cB_disableNotifications->setChecked(tdeconfig->readBoolEntry("disableNotifications",false));
cB_Blacklist_toggled(tdeconfig->readBoolEntry("autoInactiveSchemeBlacklistEnabled",false)); cB_Blacklist_toggled(tdeconfig->readBoolEntry("autoInactiveSchemeBlacklistEnabled",false));
@ -1283,8 +1294,9 @@ void ConfigureDialog::setInactivityBox(){
void ConfigureDialog::cB_autoSuspend_toggled( bool toggled ) { void ConfigureDialog::cB_autoSuspend_toggled( bool toggled ) {
kdDebugFuncIn(trace); kdDebugFuncIn(trace);
if(cB_autoSuspend->isOn() != toggled) if(cB_autoSuspend->isOn() != toggled) {
cB_autoSuspend->setChecked(toggled); cB_autoSuspend->setChecked(toggled);
}
tL_autoInactivity_explain->setEnabled(toggled); tL_autoInactivity_explain->setEnabled(toggled);
cB_autoInactivity->setEnabled(toggled); cB_autoInactivity->setEnabled(toggled);

@ -859,38 +859,61 @@ bool tdepowersave::do_standby(){
void tdepowersave::do_autosuspendWarn() { void tdepowersave::do_autosuspendWarn() {
kdDebugFuncIn(trace); kdDebugFuncIn(trace);
if (settings->autoSuspendCountdown && (settings->autoSuspendCountdownTimeout > 0)) { // Verify that the desired suspend action is allowed before displaying the dialog
// we have to display the warn dialog SuspendStates suspend = hwinfo->getSuspendSupport();
if(!contextMenu()->isItemChecked(AUTOSUSPEND_MENU_ID)) { bool allowed = false;
TQString message; if(settings->autoInactiveAction == "Suspend to Disk") {
if ( suspend.suspend2disk && (suspend.suspend2disk_allowed || suspend.suspend2disk_allowed == -1)) {
countdown = new countDownDialog(settings->autoSuspendCountdownTimeout); allowed = true;
}
}
else if (settings->autoInactiveAction == "Suspend to RAM") {
if( suspend.suspend2ram && (suspend.suspend2ram_allowed || suspend.suspend2ram_allowed == -1)) {
allowed = true;
}
}
else if (settings->autoInactiveAction == "Standby") {
if ( suspend.standby && (suspend.standby_allowed || suspend.standby_allowed == -1)) {
allowed = true;
}
}
if(settings->autoInactiveAction == "Suspend to Disk") { if (allowed) {
countdown->setPixmap("suspend2disk"); if (settings->autoSuspendCountdown && (settings->autoSuspendCountdownTimeout > 0)) {
} else if (settings->autoInactiveAction == "Suspend to RAM") { // we have to display the warn dialog
countdown->setPixmap("suspend2ram"); if(!contextMenu()->isItemChecked(AUTOSUSPEND_MENU_ID)) {
} else if (settings->autoInactiveAction == "Standby") { TQString message;
countdown->setPixmap("standby");
} else { countdown = new countDownDialog(settings->autoSuspendCountdownTimeout);
countdown->setPixmap("tdepowersave");
} if(settings->autoInactiveAction == "Suspend to Disk") {
countdown->setPixmap("suspend2disk");
} else if (settings->autoInactiveAction == "Suspend to RAM") {
countdown->setPixmap("suspend2ram");
} else if (settings->autoInactiveAction == "Standby") {
countdown->setPixmap("standby");
} else {
countdown->setPixmap("tdepowersave");
}
// TODO: rework this after translation round for openSUSE 10.3 ! // TODO: rework this after translation round for openSUSE 10.3 !
message = i18n("Inactivity detected.") + " " + message = i18n("Inactivity detected.") + " " +
i18n("To stop the %1 press the 'Cancel' button before the countdown " i18n("To stop the %1 press the 'Cancel' button before the countdown "
"expires.").arg(i18n("Autosuspend")) + "\n\n" + "expires.").arg(i18n("Autosuspend")) + "\n\n" +
i18n("The computer autosuspend in: "); i18n("The computer autosuspend in: ");
countdown->setMessageText(message); countdown->setMessageText(message);
connect(countdown, TQT_SIGNAL(dialogClosed(bool)), this, TQT_SLOT(do_autosuspend(bool))); connect(countdown, TQT_SIGNAL(dialogClosed(bool)), this, TQT_SLOT(do_autosuspend(bool)));
countdown->showDialog(); countdown->showDialog();
}
}
else {
// call directly autosuspend
do_autosuspend(false);
} }
} else {
// call directly autosuspend
do_autosuspend(false);
} }
kdDebugFuncOut(trace); kdDebugFuncOut(trace);
} }
@ -1701,7 +1724,8 @@ void tdepowersave::setSchemeSettings(){
// --> set autosuspend settings // --> set autosuspend settings
if(settings->autoSuspend) { if(settings->autoSuspend) {
setAutoSuspend(false); setAutoSuspend(false);
} else { }
else {
this->contextMenu()->setItemVisible(AUTOSUSPEND_MENU_ID, false); this->contextMenu()->setItemVisible(AUTOSUSPEND_MENU_ID, false);
this->contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, false); this->contextMenu()->setItemChecked(AUTOSUSPEND_MENU_ID, false);
this->contextMenu()->setItemVisible(AUTOSUSPEND_SEPARATOR_MENU_ID, false); this->contextMenu()->setItemVisible(AUTOSUSPEND_SEPARATOR_MENU_ID, false);
@ -1803,6 +1827,28 @@ void tdepowersave::setSchemeSettings(){
void tdepowersave::setAutoSuspend( bool resumed ){ void tdepowersave::setAutoSuspend( bool resumed ){
if (trace) kdDebug() << funcinfo << "IN: " << "resumed? " << resumed << endl; if (trace) kdDebug() << funcinfo << "IN: " << "resumed? " << resumed << endl;
// Verify that the desired suspend action is allowed before enabling autosuspend
SuspendStates suspend = hwinfo->getSuspendSupport();
bool allowed = false;
if(settings->autoInactiveAction == "Suspend to Disk") {
if ( suspend.suspend2disk && (suspend.suspend2disk_allowed || suspend.suspend2disk_allowed == -1)) {
allowed = true;
}
}
else if (settings->autoInactiveAction == "Suspend to RAM") {
if( suspend.suspend2ram && (suspend.suspend2ram_allowed || suspend.suspend2ram_allowed == -1)) {
allowed = true;
}
}
else if (settings->autoInactiveAction == "Standby") {
if ( suspend.standby && (suspend.standby_allowed || suspend.standby_allowed == -1)) {
allowed = true;
}
}
if (!allowed) {
settings->autoSuspend = false;
}
if(settings->autoInactiveActionAfter > 0 && settings->autoSuspend) { if(settings->autoInactiveActionAfter > 0 && settings->autoSuspend) {
int autoInactiveActionAfter = 0; int autoInactiveActionAfter = 0;
@ -1814,8 +1860,7 @@ void tdepowersave::setAutoSuspend( bool resumed ){
autoSuspend->stop(); autoSuspend->stop();
delete autoSuspend; delete autoSuspend;
autoSuspend = new autosuspend(); autoSuspend = new autosuspend();
connect(autoSuspend, TQT_SIGNAL(inactivityTimeExpired()), this, connect(autoSuspend, TQT_SIGNAL(inactivityTimeExpired()), this, TQT_SLOT(do_autosuspendWarn()));
TQT_SLOT(do_autosuspendWarn()));
} }
if (settings->autoSuspendCountdown && (settings->autoSuspendCountdownTimeout > 0)) { if (settings->autoSuspendCountdown && (settings->autoSuspendCountdownTimeout > 0)) {

Loading…
Cancel
Save