TDE frontend for power management
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.

1908 lines
58KB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Danny Kukawka *
  3. * <dkukawka@suse.de>, <danny.kukawka@web.de> *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of version 2 of the GNU General Public License *
  7. * as published by the Free Software Foundation. *
  8. * *
  9. * This program is distributed in the hope that it will be useful, *
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  12. * GNU General Public License for more details. *
  13. * *
  14. * You should have received a copy of the GNU General Public License *
  15. * along with this program; if not, write to the *
  16. * Free Software Foundation, Inc., *
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
  18. ***************************************************************************/
  19. /*! \file configuredialog.cpp
  20. * All here displayed file members of configureDialog.cpp are related to operations with the
  21. * configure dialog for tdepowersave
  22. * \brief In this file can be found all configure dialog related code.
  23. * \author Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
  24. * \date 2005
  25. */
  26. // KDE - Headers
  27. #include <kaudioplayer.h>
  28. #include <tdeconfig.h>
  29. #include <kiconloader.h>
  30. #include <tdelocale.h>
  31. #include <tdemessagebox.h>
  32. #include <kinputdialog.h>
  33. #include <tdeaccelmanager.h>
  34. // QT - Headers
  35. #include <tqcheckbox.h>
  36. #include <tqcombobox.h>
  37. #include <tqdialog.h>
  38. #include <tqgroupbox.h>
  39. #include <tqlabel.h>
  40. #include <tqlineedit.h>
  41. #include <tqlistbox.h>
  42. #include <tqpushbutton.h>
  43. #include <tqslider.h>
  44. #include <tqspinbox.h>
  45. #include <tqstringlist.h>
  46. #include <tqtabwidget.h>
  47. #include <tqtoolbox.h>
  48. #include <tqtooltip.h>
  49. #include <tqstring.h>
  50. #include "configuredialog.h"
  51. /*! This is the default constructor of the class ConfigureDialog. */
  52. ConfigureDialog::ConfigureDialog( TDEConfig *_config, HardwareInfo *_hwinfo, Settings *_settings,
  53. TQWidget *parent, const char *name)
  54. :configure_Dialog(parent, name, false, WDestructiveClose )
  55. {
  56. kdDebugFuncIn(trace);
  57. tdeconfig = _config;
  58. settings = _settings;
  59. hwinfo = _hwinfo;
  60. suspend = hwinfo->getSuspendSupport();
  61. TQString session = getenv("DESKTOP_SESSION");
  62. if(session.startsWith("gnome")) gnome_session = true;
  63. else gnome_session = false;
  64. initalised = false;
  65. general_changed = false;
  66. scheme_changed = false;
  67. displayed_WARN_autosuspend = false;
  68. // check if brightness is supporte
  69. if(hwinfo->supportBrightness()) {
  70. brightnessLevels = hwinfo->getMaxBrightnessLevel() -1;
  71. brightness_last = hwinfo->getCurrentBrightnessLevel();
  72. } else {
  73. brightnessLevels = -1;
  74. brightness_last = -1;
  75. }
  76. brightness_changed = false;
  77. currentScheme = -1;
  78. // get the correct available suspend types
  79. SuspendStates suspend = hwinfo->getSuspendSupport();
  80. if ( suspend.freeze && (suspend.freeze_allowed || suspend.freeze_allowed == -1)) {
  81. actions.append("Freeze");
  82. }
  83. if ( suspend.standby && (suspend.standby_allowed || suspend.standby_allowed == -1)) {
  84. actions.append("Standby");
  85. }
  86. if( suspend.suspend2ram && (suspend.suspend2ram_allowed || suspend.suspend2ram_allowed == -1)) {
  87. actions.append("Suspend");
  88. }
  89. if ( suspend.suspend2disk && (suspend.suspend2disk_allowed || suspend.suspend2disk_allowed == -1)) {
  90. actions.append("Hibernate");
  91. }
  92. if ( suspend.suspend_hybrid && (suspend.suspend_hybrid_allowed || suspend.suspend_hybrid_allowed == -1)) {
  93. actions.append("Hybrid Suspend");
  94. }
  95. setIcons();
  96. setTooltips();
  97. getSchemeList();
  98. setSchemeList();
  99. setGeneralSettings();
  100. setInactivityBox();
  101. selectScheme(settings->currentScheme);
  102. tL_valueBrightness->setFrameStyle(TQFrame::Panel | TQFrame::Sunken);
  103. tL_valueBrightness->setBackgroundMode(TQt::PaletteBase);
  104. tL_valueBrightness->setAlignment(TQt::AlignCenter);
  105. tL_valueBrightness->setFocusPolicy(TQ_NoFocus);
  106. // hide Lid item if this is not a laptop
  107. if (!hwinfo->isLaptop())
  108. cB_lockLid->hide();
  109. // hide CPU Freq page if not supported
  110. if (!hwinfo->supportCPUFreq()) {
  111. tB_scheme->setItemLabel( 4, tB_scheme->itemLabel(4) + i18n(" - not supported"));
  112. tB_scheme->setItemEnabled( 4, false);
  113. }
  114. if (!hwinfo->supportBrightness()) {
  115. tB_scheme->setItemLabel( 3, tB_scheme->itemLabel(3) + i18n(" - not supported"));
  116. tB_scheme->setItemEnabled( 3, false);
  117. }
  118. initalised = true;
  119. kdDebugFuncOut(trace);
  120. }
  121. /*! This is the default destructor of the class ConfigureDialog. */
  122. ConfigureDialog::~ConfigureDialog(){
  123. kdDebugFuncIn(trace);
  124. // no need to delete child widgets, TQt does it all for us
  125. }
  126. /* ---- START General setup SECTION ---- */
  127. /*!
  128. * This used to fill the TQListBox listBox_schemes and the scheme related TQComboBoxes
  129. * with the existing schemes.
  130. */
  131. void ConfigureDialog::setSchemeList(){
  132. kdDebugFuncIn(trace);
  133. listBox_schemes->clear();
  134. cB_acScheme->clear();
  135. cB_batteryScheme->clear();
  136. for ( TQStringList::Iterator it = schemes.begin(); it != schemes.end(); ++it ) {
  137. const char *_tmp = (*it).utf8();
  138. if((*it) == "Performance" || (*it) == i18n("Performance")) {
  139. listBox_schemes->insertItem(SmallIcon("scheme_power", TQIconSet::Automatic), i18n(_tmp));
  140. cB_acScheme->insertItem(i18n(_tmp));
  141. cB_batteryScheme->insertItem(i18n(_tmp));
  142. } else if((*it) == "Powersave" || (*it) == i18n("Powersave")) {
  143. listBox_schemes->insertItem(SmallIcon("scheme_powersave", TQIconSet::Automatic),
  144. i18n(_tmp));
  145. cB_acScheme->insertItem(i18n(_tmp));
  146. cB_batteryScheme->insertItem(i18n(_tmp));
  147. } else if((*it) == "Presentation" || (*it) == i18n("Presentation")){
  148. listBox_schemes->insertItem(SmallIcon("scheme_presentation", TQIconSet::Automatic),
  149. i18n(_tmp));
  150. cB_acScheme->insertItem(i18n(_tmp));
  151. cB_batteryScheme->insertItem(i18n(_tmp));
  152. } else if((*it) == "Acoustic" || (*it) == i18n("Acoustic")) {
  153. listBox_schemes->insertItem(SmallIcon("scheme_acoustic", TQIconSet::Automatic),
  154. i18n(_tmp));
  155. cB_acScheme->insertItem(i18n(_tmp));
  156. cB_batteryScheme->insertItem(i18n(_tmp));
  157. } else if((*it) == "AdvancedPowersave" || (*it) == i18n("Advanced Powersave")) {
  158. listBox_schemes->insertItem(SmallIcon("scheme_advanced_powersave",
  159. TQIconSet::Automatic), i18n("Advanced Powersave"));
  160. cB_acScheme->insertItem(i18n("Advanced Powersave"));
  161. cB_batteryScheme->insertItem(i18n("Advanced Powersave"));
  162. } else {
  163. listBox_schemes->insertItem(i18n(_tmp));
  164. cB_acScheme->insertItem(i18n(_tmp));
  165. cB_batteryScheme->insertItem(i18n(_tmp));
  166. }
  167. }
  168. TDEAcceleratorManager::manage(pB_newScheme);
  169. kdDebugFuncOut(trace);
  170. }
  171. /*!
  172. * This used to get the list of schemes in from the config
  173. */
  174. void ConfigureDialog::getSchemeList(){
  175. kdDebugFuncIn(trace);
  176. if (tdeconfig->hasGroup("General")) {
  177. tdeconfig->setGroup("General");
  178. schemes = tdeconfig->readListEntry("schemes", ',');
  179. }
  180. kdDebugFuncOut(trace);
  181. }
  182. /*!
  183. * This used to set the current scheme based on the name of the scheme
  184. * \param _scheme TQString with the name of the scheme
  185. */
  186. void ConfigureDialog::selectScheme (TQString _scheme){
  187. kdDebugFuncIn(trace);
  188. // select the current scheme in the listbox
  189. if(!_scheme.isEmpty()) {
  190. int pos = schemes.findIndex(_scheme);
  191. if(pos > -1) {
  192. listBox_schemes->setCurrentItem(pos);
  193. currentScheme = pos;
  194. } else {
  195. listBox_schemes->setCurrentItem(0);
  196. }
  197. } else {
  198. listBox_schemes->setCurrentItem(0);
  199. }
  200. kdDebugFuncOut(trace);
  201. }
  202. /*!
  203. * This used to set all needed Icons for the dialog.
  204. */
  205. void ConfigureDialog::setIcons(){
  206. kdDebugFuncIn(trace);
  207. /* set all Icons */
  208. this->setIcon(SmallIcon("tdepowersave", TQIconSet::Automatic));
  209. buttonApply->setIconSet(SmallIconSet("apply", TQIconSet::Automatic));
  210. buttonCancel->setIconSet(SmallIconSet("cancel", TQIconSet::Automatic));
  211. buttonOk->setIconSet(SmallIconSet("ok", TQIconSet::Automatic));
  212. buttonHelp->setIconSet(SmallIconSet("help", TQIconSet::Automatic));
  213. pB_editBlacklist->setIconSet(SmallIconSet("configure", TQIconSet::Automatic));
  214. pB_editBlacklistDimm->setIconSet(SmallIconSet("configure", TQIconSet::Automatic));
  215. pB_editAutosuspendGBlacklist->setIconSet(SmallIconSet("configure", TQIconSet::Automatic));
  216. pB_editAutodimmGBlacklist->setIconSet(SmallIconSet("configure", TQIconSet::Automatic));
  217. tB_scheme->setItemIconSet( 0 ,SmallIcon("tdescreensaver", TQIconSet::Automatic));
  218. tB_scheme->setItemIconSet( 1 ,SmallIcon("display", TQIconSet::Automatic));
  219. if(actions[0] == "Hibernate") {
  220. tB_scheme->setItemIconSet( 2 ,SmallIcon("suspend_to_disk", TQIconSet::Automatic));
  221. }
  222. else if(actions[0] == "Suspend") {
  223. tB_scheme->setItemIconSet( 2 ,SmallIcon("suspend_to_ram", TQIconSet::Automatic));
  224. }
  225. else if(actions[0] == "Freeze") {
  226. tB_scheme->setItemIconSet( 2 ,SmallIcon("suspend_to_ram", TQIconSet::Automatic));
  227. }
  228. else if(actions[0] == "Standby") {
  229. tB_scheme->setItemIconSet( 2 ,SmallIcon("stand_by", TQIconSet::Automatic));
  230. }
  231. tB_scheme->setItemIconSet( 3 ,SmallIcon("autodimm", TQIconSet::Automatic));
  232. tB_scheme->setItemIconSet( 4 ,SmallIcon("processor", TQIconSet::Automatic));
  233. tB_scheme->setItemIconSet( 5 ,SmallIcon("misc", TQIconSet::Automatic));
  234. tB_general->setItemIconSet( 0, SmallIcon( "scheme_powersave", TQIconSet::Automatic));
  235. tB_general->setItemIconSet( 1, SmallIcon( "button", TQIconSet::Automatic));
  236. tB_general->setItemIconSet( 2, SmallIcon( "scheme_power", TQIconSet::Automatic));
  237. tB_general->setItemIconSet( 3, SmallIcon( "system-lock-screen", TQIconSet::Automatic));
  238. tB_general->setItemIconSet( 4, SmallIcon( "misc", TQIconSet::Automatic));
  239. pB_configNotify->setIconSet(SmallIconSet("knotify", TQIconSet::Automatic));
  240. kdDebugFuncOut(trace);
  241. }
  242. /*!
  243. * This used to set all needed Tooltips for the dialog.
  244. */
  245. void ConfigureDialog::setTooltips(){
  246. kdDebugFuncIn(trace);
  247. // TQToolTip::setWakeUpDelay ( 1000 );
  248. TQToolTip::add(cB_specificSettings, i18n("This enables specific screen saver settings. \n"
  249. "Note: If selected, the global screen saver settings are \n"
  250. "overwritten while tdepowersave runs."));
  251. TQToolTip::add(cB_disable_Ss, i18n("This disables the screen saver. \n"
  252. "Note: If selected, the global screen saver settings are \n"
  253. "overwritten while tdepowersave runs."));
  254. TQToolTip::add(cB_blankScreen, i18n("This blanks the screen instead of using a specific screen saver. \n"
  255. "Note: This may work only with TDEScreensaver."));
  256. TQToolTip::add(cB_SpecificPM, i18n("This enables specific DPMS settings. \n"
  257. "Note: If selected, the global DPMS settings are \n"
  258. "overwritten while tdepowersave runs."));
  259. TQToolTip::add(cB_disablePM, i18n("This disables DPMS support."));
  260. TQToolTip::add(cB_lockSuspend, i18n("If selected, the screen is locked on suspend or standby."));
  261. TQToolTip::add(cB_lockLid, i18n("If selected, the screen is locked if the lid close event is triggered."));
  262. TQToolTip::add(cB_autoSuspend, i18n("Check this box to enable or disable automatic suspension of "
  263. "the computer."));
  264. TQToolTip::add(cB_autoInactivity, i18n("Activate this action if the user was inactive for the defined "
  265. "time \n(greater than 0 minutes). If empty, nothing happens."));
  266. tB_scheme->setItemToolTip ( 0, i18n("All scheme-related screen saver and DPMS settings."));
  267. tB_scheme->setItemToolTip ( 1, i18n("All scheme-related display brightness settings."));
  268. tB_scheme->setItemToolTip ( 2, i18n("All scheme-related automatic suspend settings."));
  269. TQToolTip::add(brightnessSlider, i18n("Here you can change the brightness of your display. \n"
  270. "Use the slider to change the brightness directly for \n"
  271. "testing. To reset back to previous level, please press \n"
  272. "the 'Reset' button. "));
  273. TQToolTip::add(pB_resetBrightness, i18n("Use this button to set back the slider and the "
  274. "display brightness."));
  275. kdDebugFuncOut(trace);
  276. }
  277. /*!
  278. * This function is used to get the real name of the predefined schemes.
  279. * This is a workaround for the case if Yast translated the name of the
  280. * scheme In this case is a new config section created and the old settings
  281. * would be lost.
  282. * \param s_scheme TQString with the 'current' name of the scheme
  283. * \return TQString with the english name of the scheme
  284. */
  285. TQString ConfigureDialog::getSchemeRealName(TQString s_scheme) {
  286. kdDebugFuncIn(trace);
  287. TQString ret = s_scheme;
  288. if( s_scheme == "Performance" || s_scheme == i18n("Performance"))
  289. ret = "Performance";
  290. else if( s_scheme == "Powersave" || s_scheme == i18n("Powersave"))
  291. ret = "Powersave";
  292. else if( s_scheme == "Presentation" || s_scheme == i18n("Presentation"))
  293. ret = "Presentation";
  294. else if( s_scheme == "Acoustic" || s_scheme == i18n("Acoustic"))
  295. ret = "Acoustic";
  296. kdDebugFuncOut(trace);
  297. return ret;
  298. }
  299. /*!
  300. * This function is used to read the settings from configfile and
  301. * set the values to the related dialog elements.
  302. * \param schemeID Integer value, represent the position of the
  303. * scheme in the TQListBox and within the pdaemon-list.
  304. */
  305. void ConfigureDialog::setConfigToDialog( int schemeID ){
  306. if (trace) kdDebug() << funcinfo << "IN , scheme: " << schemeID << endl;
  307. initalised = false;
  308. TQString s_scheme = getSchemeRealName(schemes[schemeID]);
  309. if (tdeconfig->hasGroup(s_scheme)){
  310. settings->load_general_settings();
  311. // set the delete scheme button enabled if needed
  312. if (!s_scheme.startsWith("Performance") && !s_scheme.startsWith("Powersave") &&
  313. !s_scheme.startsWith("Presentation") && !s_scheme.startsWith("Acoustic")) {
  314. if (!s_scheme.startsWith(settings->ac_scheme) ||
  315. !s_scheme.startsWith(settings->battery_scheme)) {
  316. // enable delete button
  317. pB_deleteScheme->setEnabled( true );
  318. TQToolTip::add(pB_deleteScheme, i18n("Press this button to delete the "
  319. "selected scheme."));
  320. } else {
  321. // disable button
  322. pB_deleteScheme->setEnabled( false );
  323. TQToolTip::add(pB_deleteScheme, i18n("You can't delete the current AC "
  324. "or battery scheme."));
  325. }
  326. } else {
  327. // disable button, can't delete these scheme, they are default
  328. pB_deleteScheme->setEnabled( false );
  329. TQToolTip::add(pB_deleteScheme, i18n("You can't delete this default scheme."));
  330. }
  331. tdeconfig->setGroup(s_scheme);
  332. }
  333. // no configuration found, set to default values ?!
  334. else {
  335. if(tdeconfig->hasGroup("default-scheme"))
  336. tdeconfig->setGroup("default-scheme");
  337. else {
  338. kdDebugFuncOut(trace);
  339. return;
  340. }
  341. }
  342. cB_disable_Ss_toggled(tdeconfig->readBoolEntry("disableSs",false));
  343. cB_blankScreen->setChecked(tdeconfig->readBoolEntry("blankSs",false));
  344. cB_specificSettings_toggled(tdeconfig->readBoolEntry("specSsSettings",false));
  345. int i_standby = tdeconfig->readNumEntry("standbyAfter", -1);
  346. if(i_standby >= 0) {
  347. sB_standby->setValue(i_standby);
  348. }
  349. else {
  350. // load value from default-scheme
  351. if(tdeconfig->hasGroup("default-scheme")){
  352. tdeconfig->setGroup("default-scheme");
  353. i_standby = tdeconfig->readNumEntry("standbyAfter", -1);
  354. if(i_standby >= 0) {
  355. sB_standby->setValue(i_standby);
  356. }
  357. else sB_standby->setValue(0);
  358. }
  359. else{
  360. sB_standby->setValue(0);
  361. }
  362. // reset group to selected scheme
  363. if (tdeconfig->hasGroup(s_scheme)) tdeconfig->setGroup(s_scheme);
  364. else tdeconfig->setGroup("default-scheme");
  365. }
  366. int i_suspend = tdeconfig->readNumEntry("suspendAfter", -1);
  367. if(i_suspend >= 0) {
  368. sB_suspend->setValue(i_suspend);
  369. }
  370. else {
  371. // load value from default-scheme
  372. if(tdeconfig->hasGroup("default-scheme")){
  373. tdeconfig->setGroup("default-scheme");
  374. i_standby = tdeconfig->readNumEntry("suspendAfter", -1);
  375. if(i_standby >= 0) {
  376. sB_standby->setValue(i_standby);
  377. }
  378. else sB_standby->setValue(0);
  379. }
  380. else{
  381. sB_standby->setValue(0);
  382. }
  383. // reset group to selected scheme
  384. if (tdeconfig->hasGroup(s_scheme)) tdeconfig->setGroup(s_scheme);
  385. else tdeconfig->setGroup("default-scheme");
  386. }
  387. int i_poweroff = tdeconfig->readNumEntry("powerOffAfter", -1);
  388. if(i_poweroff >= 0) {
  389. sB_powerOff->setValue(i_poweroff);
  390. }
  391. else {
  392. // load value from default-scheme
  393. if(tdeconfig->hasGroup("default-scheme")){
  394. tdeconfig->setGroup("default-scheme");
  395. i_standby = tdeconfig->readNumEntry("powerOffAfter", -1);
  396. if(i_poweroff >= 0) {
  397. sB_powerOff->setValue(i_poweroff);
  398. }
  399. else sB_powerOff->setValue(0);
  400. }
  401. else{
  402. sB_powerOff->setValue(0);
  403. }
  404. // reset group to selected scheme
  405. if (tdeconfig->hasGroup(s_scheme)) tdeconfig->setGroup(s_scheme);
  406. else tdeconfig->setGroup("default-scheme");
  407. }
  408. cB_SpecificPM_toggled(tdeconfig->readBoolEntry("specPMSettings",false));
  409. cB_disablePM_toggled(tdeconfig->readBoolEntry("disableDPMS",false));
  410. // set autosuspend related settings
  411. TQString _action = tdeconfig->readEntry("autoInactiveAction", "NULL");
  412. if( _action != "NULL") {
  413. int _index = actions.findIndex(_action);
  414. if( _index != -1) {
  415. cB_autoInactivity->setCurrentItem( _index );
  416. cB_autoInactivity_activated( _index );
  417. cB_Blacklist->setEnabled(true);
  418. }
  419. else {
  420. // set to empty element if not supported by current machine or
  421. // if the value is "_NONE_"
  422. cB_autoInactivity->setCurrentItem( 0 );
  423. cB_autoInactivity_activated( 0 );
  424. cB_Blacklist->setEnabled(false);
  425. }
  426. }
  427. else {
  428. // set to disabled (to reduce code), if a entry found set to enabled !
  429. cB_Blacklist->setEnabled(false);
  430. if(tdeconfig->hasGroup("default-scheme")){
  431. tdeconfig->setGroup("default-scheme");
  432. _action = tdeconfig->readEntry("autoInactiveAction", "NULL");
  433. if(_action != "NULL") {
  434. int _index = actions.findIndex(_action);
  435. if( _index != -1) {
  436. cB_autoInactivity->setCurrentItem( _index );
  437. tL_autoInactivity_After->setEnabled(true);
  438. cB_Blacklist->setEnabled(true);
  439. }
  440. else {
  441. cB_autoInactivity->setCurrentItem( 0 );
  442. }
  443. }
  444. else {
  445. cB_autoInactivity->setCurrentItem( 0 );
  446. }
  447. // reset group to selected scheme
  448. if (tdeconfig->hasGroup(s_scheme)) tdeconfig->setGroup(s_scheme);
  449. else tdeconfig->setGroup("default-scheme");
  450. }
  451. else{
  452. cB_autoInactivity->setCurrentItem( 0 );
  453. }
  454. }
  455. if( cB_autoInactivity->currentItem() == 0 ) {
  456. sB_autoInactivity->setEnabled(false);
  457. tL_autoInactivity_After->setEnabled(false);
  458. }
  459. int i_autoInactivityAfter = tdeconfig->readNumEntry("autoInactiveActionAfter", -1);
  460. if(i_autoInactivityAfter >= 0) {
  461. sB_autoInactivity->setValue(i_autoInactivityAfter);
  462. }
  463. else {
  464. // load value from default-scheme
  465. if(tdeconfig->hasGroup("default-scheme")){
  466. tdeconfig->setGroup("default-scheme");
  467. i_autoInactivityAfter = tdeconfig->readNumEntry("autoInactiveActionAfter", -1);
  468. if(i_autoInactivityAfter >= 0) {
  469. sB_autoInactivity->setValue(i_autoInactivityAfter);
  470. }
  471. else sB_autoInactivity->setValue(0);
  472. }
  473. else{
  474. sB_autoInactivity->setValue(0);
  475. }
  476. // reset group to selected scheme
  477. if (tdeconfig->hasGroup(s_scheme)) tdeconfig->setGroup(s_scheme);
  478. else tdeconfig->setGroup("default-scheme");
  479. }
  480. if (hwinfo->supportBrightness()) {
  481. // enable the widgets
  482. cB_Brightness->setEnabled(true);
  483. cB_Brightness_toggled(tdeconfig->readBoolEntry("enableBrightness",false));
  484. if (brightnessLevels > 33)
  485. brightnessSlider->setLineStep(3);
  486. else
  487. brightnessSlider->setLineStep(100/brightnessLevels);
  488. brightnessSlider->setPageStep(10);
  489. int i_brightnessPercent = tdeconfig->readNumEntry("brightnessPercent", -1);
  490. if(i_brightnessPercent >= 0) {
  491. brightnessSlider->setValue(i_brightnessPercent);
  492. tL_valueBrightness->setText(TQString::number(i_brightnessPercent) + " %");
  493. }
  494. else {
  495. brightnessSlider->setValue(100);
  496. tL_valueBrightness->setText(TQString::number(100)+ " %");
  497. }
  498. tL_brightness->setText(i18n("Your hardware supports to change the brightness. The "
  499. "values of the slider are in percent and mapped "
  500. "to the available brightness levels of your hardware."));
  501. }
  502. else {
  503. cB_Brightness->setEnabled(false);
  504. gB_Brightness->setEnabled(false);
  505. tL_brightness->setText(i18n("Your Hardware currently not support changing the brightness "
  506. "of your display."));
  507. }
  508. // no need to enable autodimm if not support change brightness
  509. if (hwinfo->supportBrightness()) {
  510. int i_autoDimmAfter = tdeconfig->readNumEntry("autoDimmAfter", -1);
  511. if(i_autoDimmAfter >= 0) {
  512. sB_autoDimmTime->setValue(i_autoDimmAfter);
  513. }
  514. else {
  515. // load value from default-scheme
  516. if(tdeconfig->hasGroup("default-scheme")){
  517. tdeconfig->setGroup("default-scheme");
  518. i_autoDimmAfter = tdeconfig->readNumEntry("autoDimmAfter", -1);
  519. if(i_autoDimmAfter >= 0) {
  520. sB_autoDimmTime->setValue(i_autoDimmAfter);
  521. }
  522. else sB_autoDimmTime->setValue(0);
  523. }
  524. else{
  525. sB_autoDimmTime->setValue(0);
  526. }
  527. // reset group to selected scheme
  528. if (tdeconfig->hasGroup(s_scheme)) tdeconfig->setGroup(s_scheme);
  529. else tdeconfig->setGroup("default-scheme");
  530. }
  531. int i_autoDimmTo = tdeconfig->readNumEntry("autoDimmTo", -1);
  532. if(i_autoDimmTo >= 0) {
  533. sB_autoDimmTo->setValue(i_autoDimmTo);
  534. }
  535. else {
  536. // load value from default-scheme
  537. if(tdeconfig->hasGroup("default-scheme")){
  538. tdeconfig->setGroup("default-scheme");
  539. i_autoDimmTo = tdeconfig->readNumEntry("autoDimmTo", -1);
  540. if(i_autoDimmAfter >= 0) {
  541. sB_autoDimmTo->setValue(i_autoDimmTo);
  542. }
  543. else sB_autoDimmTo->setValue(0);
  544. }
  545. else{
  546. sB_autoDimmTo->setValue(0);
  547. }
  548. // reset group to selected scheme
  549. if (tdeconfig->hasGroup(s_scheme)) tdeconfig->setGroup(s_scheme);
  550. else tdeconfig->setGroup("default-scheme");
  551. }
  552. }
  553. if (hwinfo->supportCPUFreq()) {
  554. TQString cpuFreqPolicy = tdeconfig->readEntry("cpuFreqPolicy");
  555. if (cpuFreqPolicy.isEmpty()) {
  556. // load value from default-scheme
  557. if(tdeconfig->hasGroup("default-scheme")){
  558. tdeconfig->setGroup("default-scheme");
  559. cpuFreqPolicy = tdeconfig->readEntry("cpuFreqPolicy");
  560. }
  561. if (cpuFreqPolicy.isEmpty()) {
  562. cpuFreqPolicy = "DYNAMIC";
  563. }
  564. // reset group to selected scheme
  565. if (tdeconfig->hasGroup(s_scheme)) tdeconfig->setGroup(s_scheme);
  566. else tdeconfig->setGroup("default-scheme");
  567. }
  568. if (cpuFreqPolicy.startsWith("PERFORMANCE")) {
  569. comboB_cpuFreq->setCurrentItem(0);
  570. } else if (cpuFreqPolicy.startsWith("DYNAMIC")) {
  571. comboB_cpuFreq->setCurrentItem(1);
  572. } else if (cpuFreqPolicy.startsWith("POWERSAVE")) {
  573. comboB_cpuFreq->setCurrentItem(2);
  574. } else {
  575. kdWarning() << "Could not read/map CPU Freq Policy, set to dynamic" << endl;
  576. comboB_cpuFreq->setCurrentItem(1);
  577. }
  578. }
  579. if (actions.count() < 1) {
  580. cB_autoSuspend->setEnabled(false);
  581. cB_autoSuspend->setChecked(false);
  582. }
  583. cB_disableNotifications->setChecked(tdeconfig->readBoolEntry("disableNotifications",false));
  584. cB_Blacklist_toggled(tdeconfig->readBoolEntry("autoInactiveSchemeBlacklistEnabled",false));
  585. cB_autoSuspend_toggled(tdeconfig->readBoolEntry("autoSuspend",false));
  586. cB_BlacklistDimm_toggled(tdeconfig->readBoolEntry("autoDimmSchemeBlacklistEnabled",false));
  587. cB_autoDimm_toggled(tdeconfig->readBoolEntry("autoDimm",false));
  588. initalised = true;
  589. scheme_changed = false;
  590. if(!general_changed) buttonApply->setEnabled(false);
  591. currentScheme = schemeID;
  592. kdDebugFuncOut(trace);
  593. }
  594. /*!
  595. * This is used to set the values from the section general in configfile to the
  596. * related items in the dialog.
  597. */
  598. void ConfigureDialog::setGeneralSettings() {
  599. kdDebugFuncIn(trace);
  600. tdeconfig->setGroup("General");
  601. cB_lockSuspend->setChecked(tdeconfig->readBoolEntry("lockOnSuspend",false));
  602. cB_lockLid->setChecked(tdeconfig->readBoolEntry("lockOnLidClose",false));
  603. cB_autostart->setChecked(tdeconfig->readBoolEntry("Autostart",false));
  604. cB_autostart_neverAsk->setChecked(tdeconfig->readBoolEntry("AutostartNeverAsk",false));
  605. TQString lockmethod = tdeconfig->readEntry("lockMethod", "NULL");
  606. if(comboB_lock->count() == 0 ){
  607. comboB_lock->insertItem(i18n("Select Automatically"),0);
  608. comboB_lock->insertItem(i18n("TDEScreensaver"),1);
  609. comboB_lock->insertItem(i18n("XScreensaver"),2);
  610. comboB_lock->insertItem(i18n("xlock"),3);
  611. if (gnome_session) comboB_lock->insertItem(i18n("GNOME Screensaver"),4);
  612. }
  613. if (lockmethod == "automatic") comboB_lock->setCurrentItem(0);
  614. else if (lockmethod == "tdescreensaver") comboB_lock->setCurrentItem(1);
  615. else if (lockmethod == "xscreensaver") comboB_lock->setCurrentItem(2);
  616. else if (lockmethod == "xlock") comboB_lock->setCurrentItem(3);
  617. else if (gnome_session && (lockmethod == "gnomescreensaver")) comboB_lock->setCurrentItem(4);
  618. else comboB_lock->setCurrentItem(0);
  619. if(cB_lockSuspend->isOn() || cB_lockLid->isOn() ) {
  620. tL_lockWith->setEnabled(true);
  621. comboB_lock->setEnabled(true);
  622. }
  623. else {
  624. tL_lockWith->setEnabled(false);
  625. comboB_lock->setEnabled(false);
  626. }
  627. // battery tab
  628. BatteryCollection* _primBats = hwinfo->getPrimaryBatteries();
  629. if (_primBats->getNumBatteries() > 0) {
  630. // set widgets in the tab
  631. sB_batWarning->setValue(tdeconfig->readNumEntry("batteryWarning",0));
  632. sB_batLow->setValue(tdeconfig->readNumEntry("batteryLow",0));
  633. sB_batCritical->setValue(tdeconfig->readNumEntry("batteryCritical",0));
  634. // hide them and enable only if needed
  635. sB_batWarnAction_value->hide();
  636. sB_batLowAction_value->hide();
  637. sB_batCritAction_value->hide();
  638. TQString _select;
  639. TQStringList _actions = tdeconfig->readListEntry("batteryAllowedActions", TQString());
  640. _select = tdeconfig->readEntry("batteryWarningAction", TQString());
  641. fillActionComboBox(cB_batWarning, _actions, _select);
  642. if (_select == "BRIGHTNESS" && hwinfo->supportBrightness()) {
  643. sB_batWarnAction_value->show();
  644. sB_batWarnAction_value->setValue(tdeconfig->readNumEntry( "batteryWarningActionValue",0));
  645. }
  646. _select = tdeconfig->readEntry("batteryLowAction", TQString());
  647. fillActionComboBox(cB_batLow, _actions, _select);
  648. if (_select == "BRIGHTNESS" && hwinfo->supportBrightness()) {
  649. sB_batLowAction_value->show();
  650. sB_batLowAction_value->setValue( tdeconfig->readNumEntry( "batteryLowActionValue",0));
  651. }
  652. _select = tdeconfig->readEntry("batteryCriticalAction", TQString());
  653. fillActionComboBox(cB_batCritical, _actions, _select);
  654. if (_select == "BRIGHTNESS" && hwinfo->supportBrightness()) {
  655. sB_batCritAction_value->show();
  656. sB_batCritAction_value->setValue(tdeconfig->readNumEntry("batteryCriticalActionValue",0));
  657. }
  658. } else {
  659. // disable tab
  660. tB_general->setItemLabel( 0, tB_general->itemLabel(0) + i18n(" - not supported"));
  661. tB_general->setItemEnabled( 0, false);
  662. }
  663. // buttons tab:
  664. TQStringList _actions = tdeconfig->readListEntry("buttonsAllowedActions", TQString());
  665. fillActionComboBox(cB_PowerButton, _actions, tdeconfig->readEntry("ActionOnPowerButton", TQString()));
  666. fillActionComboBox(cB_SuspendButton, _actions, tdeconfig->readEntry("ActionOnSuspendButton", TQString()));
  667. fillActionComboBox(cB_S2DiskButton, _actions, tdeconfig->readEntry("ActionOnS2DiskButton", TQString()));
  668. // avoid logout dialog for lidclose - this make no sense
  669. _actions.remove("LOGOUT_DIALOG");
  670. fillActionComboBox(cB_LidcloseButton, _actions, tdeconfig->readEntry("ActionOnLidClose", TQString()));
  671. // default scheme tab:
  672. TQString _ac_scheme = tdeconfig->readEntry( "ac_scheme", "Performance");
  673. TQString _bat_scheme = tdeconfig->readEntry( "battery_scheme", "Powersave");
  674. cB_acScheme->setCurrentItem(schemes.findIndex(_ac_scheme));
  675. cB_batteryScheme->setCurrentItem(schemes.findIndex(_bat_scheme));
  676. kdDebugFuncOut(trace);
  677. }
  678. /* ---- END General setup SECTION ---- */
  679. /* ---- START store settings SECTION ---- */
  680. /*!
  681. * This used to save changes in settings of the current scheme.
  682. */
  683. void ConfigureDialog::saveSchemeSettings() {
  684. kdDebugFuncIn(trace);
  685. TQString s_scheme = getSchemeRealName(schemes[currentScheme]);
  686. tdeconfig->setGroup(s_scheme);
  687. tdeconfig->writeEntry("specSsSettings",cB_specificSettings->isOn());
  688. tdeconfig->writeEntry("disableSs",cB_disable_Ss->isOn());
  689. tdeconfig->writeEntry("blankSs",cB_blankScreen->isOn());
  690. tdeconfig->writeEntry("specPMSettings",cB_SpecificPM->isOn());
  691. tdeconfig->writeEntry("disableDPMS",cB_disablePM->isOn());
  692. tdeconfig->writeEntry("standbyAfter",sB_standby->value());
  693. tdeconfig->writeEntry("suspendAfter",sB_suspend->value());
  694. tdeconfig->writeEntry("powerOffAfter",sB_powerOff->value());
  695. tdeconfig->writeEntry("disableNotifications",cB_disableNotifications->isOn());
  696. if(cB_autoInactivity->currentText() == " "){
  697. tdeconfig->writeEntry("autoInactiveAction", "_NONE_");
  698. }
  699. else{
  700. int _index = cB_autoInactivity->currentItem();
  701. if(_index > 0) {
  702. /*if(_index == (cB_autoInactivity->count()-1)) {
  703. tdeconfig->writeEntry("autoInactiveAction","shutdown");
  704. }
  705. else {
  706. tdeconfig->writeEntry("autoInactiveAction",actions[(_index)]);
  707. }*/
  708. tdeconfig->writeEntry("autoInactiveAction",actions[(_index)]);
  709. }
  710. tdeconfig->writeEntry("autoInactiveActionAfter",sB_autoInactivity->value());
  711. }
  712. tdeconfig->writeEntry("autoSuspend",cB_autoSuspend->isOn());
  713. tdeconfig->writeEntry("autoInactiveSchemeBlacklistEnabled",cB_Blacklist->isOn());
  714. tdeconfig->writeEntry("autoDimm",cB_autoDimm->isOn());
  715. tdeconfig->writeEntry("autoDimmAfter", sB_autoDimmTime->value());
  716. tdeconfig->writeEntry("autoDimmTo", sB_autoDimmTo->value());
  717. tdeconfig->writeEntry("autoDimmSchemeBlacklistEnabled",cB_BlacklistDimm->isOn());
  718. tdeconfig->writeEntry("enableBrightness",cB_Brightness->isOn());
  719. if(brightness_changed)
  720. tdeconfig->writeEntry("brightnessPercent",brightnessSlider->value());
  721. if(hwinfo->supportCPUFreq()) {
  722. switch( comboB_cpuFreq->currentItem()) {
  723. case 0:
  724. tdeconfig->writeEntry("cpuFreqPolicy", "PERFORMANCE");
  725. break;
  726. case 2:
  727. tdeconfig->writeEntry("cpuFreqPolicy", "POWERSAVE");
  728. break;
  729. case 1:
  730. default:
  731. tdeconfig->writeEntry("cpuFreqPolicy", "DYNAMIC");
  732. break;
  733. }
  734. }
  735. tdeconfig->sync();
  736. scheme_changed = false;
  737. if(!general_changed) buttonApply->setEnabled(false);
  738. kdDebugFuncOut(trace);
  739. }
  740. /*!
  741. * This used to save changes in settings of the current scheme.
  742. */
  743. void ConfigureDialog::saveGeneralSettings() {
  744. kdDebugFuncIn(trace);
  745. tdeconfig->setGroup("General");
  746. tdeconfig->writeEntry("lockOnSuspend",cB_lockSuspend->isOn());
  747. tdeconfig->writeEntry("lockOnLidClose",cB_lockLid->isOn());
  748. tdeconfig->writeEntry("Autostart",cB_autostart->isOn());
  749. tdeconfig->writeEntry("AutostartNeverAsk",cB_autostart_neverAsk->isOn());
  750. TQString selected_method = "";
  751. int _selected = comboB_lock->currentItem();
  752. if(_selected == 0) selected_method = "automatic";
  753. else if(_selected == 1) selected_method = "tdescreensaver";
  754. else if(_selected == 2) selected_method = "xscreensaver";
  755. else if(_selected == 3) selected_method = "xlock";
  756. else if(gnome_session && (_selected == 4)) selected_method = "gnomescreensaver";
  757. tdeconfig->writeEntry( "lockMethod", selected_method );
  758. tdeconfig->writeEntry("batteryWarning", sB_batWarning->value());
  759. tdeconfig->writeEntry("batteryLow", sB_batLow->value());
  760. tdeconfig->writeEntry("batteryCritical", sB_batCritical->value());
  761. // battery level tab
  762. TQString _action = mapDescriptionToAction(cB_batWarning->currentText());
  763. tdeconfig->writeEntry("batteryWarningAction", _action);
  764. if (_action == "BRIGHTNESS") {
  765. tdeconfig->writeEntry("batteryWarningActionValue", sB_batWarnAction_value->value());
  766. }
  767. _action = mapDescriptionToAction(cB_batLow->currentText());
  768. tdeconfig->writeEntry("batteryLowAction", _action);
  769. if (_action == "BRIGHTNESS") {
  770. tdeconfig->writeEntry("batteryLowActionValue", sB_batLowAction_value->value());
  771. }
  772. _action = mapDescriptionToAction(cB_batCritical->currentText());
  773. tdeconfig->writeEntry("batteryCriticalAction", _action);
  774. if (_action == "BRIGHTNESS") {
  775. tdeconfig->writeEntry("batteryCriticalActionValue", sB_batCritAction_value->value());
  776. }
  777. // button tab
  778. tdeconfig->writeEntry("ActionOnPowerButton", mapDescriptionToAction(cB_PowerButton->currentText()));
  779. tdeconfig->writeEntry("ActionOnLidClose", mapDescriptionToAction(cB_LidcloseButton->currentText()));
  780. tdeconfig->writeEntry("ActionOnSuspendButton", mapDescriptionToAction(cB_SuspendButton->currentText()));
  781. tdeconfig->writeEntry("ActionOnS2DiskButton", mapDescriptionToAction(cB_S2DiskButton->currentText()));
  782. // schemes tab
  783. tdeconfig->writeEntry("ac_scheme", getSchemeRealName(schemes[cB_acScheme->currentItem()]));
  784. tdeconfig->writeEntry("battery_scheme", getSchemeRealName(schemes[cB_batteryScheme->currentItem()]));
  785. tdeconfig->sync();
  786. general_changed = false;
  787. if(!scheme_changed) buttonApply->setEnabled(false);
  788. kdDebugFuncOut(trace);
  789. }
  790. /* ---- END store settings SECTION ---- */
  791. /* ---- START monitor changes SECTION ---- */
  792. /*!
  793. * SLOT: Called if a value within the Tab 'General Settings' is changed.
  794. */
  795. void ConfigureDialog::general_valueChanged(){
  796. kdDebugFuncIn(trace);
  797. if(initalised) {
  798. general_changed = true;
  799. buttonApply->setEnabled(true);
  800. // enable/disable the comboB_lock and tL_lockWith
  801. if(cB_lockSuspend->isOn() || cB_lockLid->isOn() ) {
  802. tL_lockWith->setEnabled(true);
  803. comboB_lock->setEnabled(true);
  804. }
  805. else {
  806. tL_lockWith->setEnabled(false);
  807. comboB_lock->setEnabled(false);
  808. }
  809. }
  810. kdDebugFuncOut(trace);
  811. }
  812. /*!
  813. * SLOT: Called if a value within the Tab 'Scheme Settings' is changed.
  814. */
  815. void ConfigureDialog::scheme_valueChanged(){
  816. kdDebugFuncIn(trace);
  817. if(initalised) {
  818. scheme_changed = true;
  819. buttonApply->setEnabled(true);
  820. }
  821. kdDebugFuncOut(trace);
  822. }
  823. /*!
  824. * SLOT: called if the current scheme in the TQListBox listBox_schemes is
  825. * changed/ a other scheme was selected.
  826. */
  827. void ConfigureDialog::listBox_schemes_currentChanged(){
  828. kdDebugFuncIn(trace);
  829. // store current settings if something changed
  830. if(initalised && scheme_changed ) {
  831. int res = KMessageBox::warningYesNo(this,
  832. i18n("There are unsaved changes in the active scheme.\n"
  833. "Apply the changes before jumping to the next scheme "
  834. "or discard the changes?"),
  835. i18n("Unsaved Changes"), KStdGuiItem::apply(),
  836. KStdGuiItem::discard());
  837. if (res == KMessageBox::Yes) {
  838. // Save changes
  839. saveSchemeSettings();
  840. }
  841. if (res == KMessageBox::No) {
  842. // discard changes and reset trigger
  843. scheme_changed = false;
  844. }
  845. }
  846. // set to new Item
  847. setConfigToDialog(listBox_schemes->currentItem());
  848. kdDebugFuncOut(trace);
  849. }
  850. /* ---- END monitor changes SECTION ---- */
  851. /* ---- START BUTTON SECTION ---- */
  852. /*!
  853. * SLOT: called if the 'Apply' button is clicked.
  854. */
  855. void ConfigureDialog::buttonApply_clicked(){
  856. kdDebugFuncIn(trace);
  857. if(initalised && scheme_changed ) {
  858. saveSchemeSettings();
  859. scheme_changed = false;
  860. }
  861. if(initalised && general_changed ) {
  862. saveGeneralSettings();
  863. general_changed = false;
  864. }
  865. kdDebugFuncOut(trace);
  866. }
  867. /*!
  868. * SLOT: called if the 'Cancel' button is clicked.
  869. */
  870. void ConfigureDialog::buttonCancel_clicked(){
  871. kdDebugFuncOut(trace);
  872. if (scheme_changed || general_changed) {
  873. int res = KMessageBox::warningYesNoCancel(this,
  874. i18n("There are unsaved changes.\nApply the changes "
  875. "before cancel or discard the changes?"),
  876. i18n("Unsaved Changes"), KStdGuiItem::apply(),
  877. KStdGuiItem::discard());
  878. if (res == KMessageBox::Yes) {
  879. buttonApply_clicked();
  880. }
  881. else if (res == KMessageBox::Cancel) return;
  882. }
  883. kdDebugFuncOut(trace);
  884. close();
  885. }
  886. /*!
  887. * SLOT: called if the 'OK' button is clicked.
  888. */
  889. void ConfigureDialog::buttonOk_clicked(){
  890. kdDebugFuncIn(trace);
  891. buttonApply_clicked();
  892. buttonApply->setEnabled(false);
  893. kdDebugFuncOut(trace);
  894. close();
  895. }
  896. /*!
  897. * SLOT: called if the 'Help' button is clicked.
  898. */
  899. void ConfigureDialog::buttonHelp_clicked(){
  900. kdDebugFuncIn(trace);
  901. emit openHelp();
  902. kdDebugFuncOut(trace);
  903. }
  904. /* ---- END BUTTON SECTION ---- */
  905. /* ---- START SCHEME ADD/DELETE SECTION ---- */
  906. /*!
  907. * SLOT: called if the 'New' scheme button is clicked.
  908. */
  909. void ConfigureDialog::pB_newScheme_clicked(){
  910. kdDebugFuncIn(trace);
  911. bool _ok = false;
  912. bool _end = false;
  913. TQString _new;
  914. TQString _text = i18n("Please insert a name for the new scheme:");
  915. TQString _error;
  916. getSchemeList();
  917. while (!_end) {
  918. _new = KInputDialog::getText( i18n("TDEPowersave Configuration"),
  919. _error + _text, TQString(), &_ok, this);
  920. if (!_ok ) {
  921. _end = true;
  922. } else {
  923. _error = TQString();
  924. if (!_new.isEmpty()) {
  925. if ( schemes.contains(_new))
  926. _error = i18n("Error: A scheme with this name already exist.\n");
  927. else
  928. _end = true;
  929. }
  930. }
  931. }
  932. if (!_new.isEmpty()) {
  933. // write append new scheme to list
  934. schemes.append(_new);
  935. tdeconfig->setGroup("General");
  936. tdeconfig->writeEntry("schemes", schemes, ",");
  937. tdeconfig->sync();
  938. // update GUI
  939. setSchemeList();
  940. selectScheme(_new);
  941. saveSchemeSettings();
  942. }
  943. kdDebugFuncOut(trace);
  944. }
  945. /*!
  946. * SLOT: called if the 'Delete' scheme button is clicked.
  947. */
  948. void ConfigureDialog::pB_deleteScheme_clicked(){
  949. kdDebugFuncIn(trace);
  950. if (pB_deleteScheme->isEnabled()) {
  951. int answer = KMessageBox::questionYesNo( this, i18n("Do you really want to delete the "
  952. "%1 scheme?").arg(schemes[currentScheme]),
  953. i18n("Confirm delete scheme"),
  954. i18n("Delete"), i18n("Cancel"));
  955. if (answer == KMessageBox::Yes) {
  956. // delete the scheme, we can be sure this is a userscheme
  957. TQString _s_tmp = getSchemeRealName(schemes[currentScheme]);
  958. if (tdeconfig->hasGroup(_s_tmp) && tdeconfig->deleteGroup(_s_tmp)) {
  959. schemes.remove(_s_tmp);
  960. tdeconfig->setGroup("General");
  961. tdeconfig->writeEntry("schemes", schemes, ",");
  962. tdeconfig->sync();
  963. // update GUI
  964. setSchemeList();
  965. selectScheme(settings->currentScheme);
  966. } else {
  967. // could not delete the scheme ... error case
  968. KMessageBox::queuedMessageBox(this, KMessageBox::Error,
  969. i18n("Could not delete the selected scheme."));
  970. }
  971. }
  972. }
  973. kdDebugFuncOut(trace);
  974. }
  975. /* ---- END SCHEME ADD/DELETE SECTION ---- */
  976. /* ---- START SCREENSAVER SECTION ---- */
  977. /*!
  978. * SLOT: called if TQCheckBox cB_specificSettings is toggled.
  979. * \param state boolean, true if toggled on
  980. * false if toggled off
  981. */
  982. void ConfigureDialog::cB_specificSettings_toggled(bool state){
  983. kdDebugFuncIn(trace);
  984. if(!initalised) cB_specificSettings->setChecked(state);
  985. /* set widgets visible/disabled */
  986. if(state){
  987. cB_disable_Ss->setEnabled(true);
  988. if(cB_disable_Ss->isOn()){
  989. cB_blankScreen->setEnabled(false);
  990. }
  991. else {
  992. cB_blankScreen->setEnabled(true);
  993. }
  994. }
  995. else {
  996. cB_disable_Ss->setEnabled(false);
  997. cB_blankScreen->setEnabled(false);
  998. }
  999. kdDebugFuncOut(trace);
  1000. }
  1001. /*!
  1002. * SLOT: called if TQCheckBox cB_disable_Ss is toggled.
  1003. * \param state boolean, true if toggled on
  1004. * false if toggled off
  1005. */
  1006. void ConfigureDialog::cB_disable_Ss_toggled(bool state){
  1007. kdDebugFuncIn(trace);
  1008. /* set widgets visible/disabled */
  1009. if(!initalised) cB_disable_Ss->setChecked(state);
  1010. cB_blankScreen->setEnabled(!state);
  1011. kdDebugFuncOut(trace);
  1012. }
  1013. /* ---- END SCREENSAVER SECTION ---- */
  1014. /* ---- START DPMS SECTION ---- */
  1015. /*!
  1016. * SLOT: called if TQCheckBox cB_SpecificPM is toggled.
  1017. * \param state boolean, true if toggled on
  1018. * false if toggled offtrue
  1019. */
  1020. void ConfigureDialog::cB_SpecificPM_toggled(bool state){
  1021. kdDebugFuncIn(trace);
  1022. if(!initalised) cB_SpecificPM->setChecked(state);
  1023. /* set widgets visible/disabled */
  1024. cB_disablePM->setEnabled(state);
  1025. if(cB_disablePM->isOn()) {
  1026. state = false;
  1027. }
  1028. tL_standbyAfter->setEnabled(state);
  1029. sB_standby->setEnabled(state);
  1030. tL_suspendAfter->setEnabled(state);
  1031. sB_suspend->setEnabled(state);
  1032. tL_powerOffAfter->setEnabled(state);
  1033. sB_powerOff->setEnabled(state);
  1034. kdDebugFuncOut(trace);
  1035. }
  1036. /*!
  1037. * SLOT: called if TQCheckBox cB_disablePM is toggled.
  1038. * \param state boolean, true if toggled on
  1039. * false if toggled off
  1040. */
  1041. void ConfigureDialog::cB_disablePM_toggled(bool state){
  1042. kdDebugFuncIn(trace);
  1043. if(!initalised) cB_disablePM->setChecked(state);
  1044. /* set widgets visible/disabled */
  1045. tL_standbyAfter->setEnabled(!state);
  1046. sB_standby->setEnabled(!state);
  1047. tL_suspendAfter->setEnabled(!state);
  1048. sB_suspend->setEnabled(!state);
  1049. tL_powerOffAfter->setEnabled(!state);
  1050. sB_powerOff->setEnabled(!state);
  1051. kdDebugFuncOut(trace);
  1052. }
  1053. /*!
  1054. * SLOT: called if the standby TQSpinBoxes for DPMS timout is changed.
  1055. */
  1056. void ConfigureDialog::sB_standby_valueChanged() {
  1057. kdDebugFuncIn(trace);
  1058. if (initalised) {
  1059. if (sB_standby->value() == 0 )
  1060. return;
  1061. if ( sB_standby->value() > sB_suspend->value()) {
  1062. sB_suspend->setValue(sB_standby->value());
  1063. }
  1064. }
  1065. kdDebugFuncOut(trace);
  1066. }
  1067. /*!
  1068. * SLOT: called if the suspend TQSpinBoxes for DPMS timout is changed.
  1069. */
  1070. void ConfigureDialog::sB_suspend_valueChanged() {
  1071. kdDebugFuncIn(trace);
  1072. if (initalised) {
  1073. if (sB_suspend->value() == 0 )
  1074. return;
  1075. if ( sB_suspend->value() < sB_standby->value()) {
  1076. sB_standby->setValue(sB_suspend->value());
  1077. }
  1078. if ( sB_suspend->value() > sB_powerOff->value()) {
  1079. sB_powerOff->setValue(sB_suspend->value());
  1080. }
  1081. }
  1082. kdDebugFuncOut(trace);
  1083. }
  1084. /*!
  1085. * SLOT: called if the powerOff TQSpinBoxes for DPMS timout is changed.
  1086. */
  1087. void ConfigureDialog::sB_powerOff_valueChanged() {
  1088. kdDebugFuncIn(trace);
  1089. if (initalised) {
  1090. if (sB_powerOff->value() == 0 )
  1091. return;
  1092. if ( sB_powerOff->value() < sB_suspend->value()) {
  1093. sB_suspend->setValue(sB_powerOff->value());
  1094. }
  1095. }
  1096. kdDebugFuncOut(trace);
  1097. }
  1098. /* ---- END DPMS SECTION ---- */
  1099. /* ---- START Inactivity SECTION ---- */
  1100. /*!
  1101. * This used to set the inactivity related combobox cB_autoInactivity .
  1102. */
  1103. void ConfigureDialog::setInactivityBox(){
  1104. kdDebugFuncIn(trace);
  1105. cB_autoInactivity->clear();
  1106. // add "nothing" at start of the list
  1107. actions.push_front(" ");
  1108. // add "Turn Off Computer" at end of the list
  1109. // TQString _to_i18n = i18n("Turn Off Computer");
  1110. // actions.append("Turn Off Computer");
  1111. for ( TQStringList::Iterator it = actions.begin(); it != actions.end(); ++it ) {
  1112. cB_autoInactivity->insertItem( i18n( (*it).utf8() ) );
  1113. }
  1114. kdDebugFuncOut(trace);
  1115. }
  1116. /*!
  1117. * This used to set the autosuspend related widgets.
  1118. */
  1119. void ConfigureDialog::cB_autoSuspend_toggled( bool toggled ) {
  1120. kdDebugFuncIn(trace);
  1121. if(cB_autoSuspend->isOn() != toggled) {
  1122. cB_autoSuspend->setChecked(toggled);
  1123. }
  1124. tL_autoInactivity_explain->setEnabled(toggled);
  1125. cB_autoInactivity->setEnabled(toggled);
  1126. if(cB_autoInactivity->currentItem() > 0) {
  1127. cB_autoInactivity->setEnabled(true);
  1128. tL_autoInactivity_After->setEnabled(true);
  1129. sB_autoInactivity->setEnabled(true);
  1130. cB_Blacklist->setEnabled(true);
  1131. cB_Blacklist_toggled(cB_Blacklist->isOn());
  1132. }
  1133. if(!toggled) {
  1134. cB_autoSuspend->setChecked(false);
  1135. tL_autoInactivity_After->setEnabled(false);
  1136. cB_autoInactivity->setEnabled(false);
  1137. sB_autoInactivity->setEnabled(false);
  1138. cB_Blacklist->setEnabled(false);
  1139. pB_editBlacklist->setEnabled(false);
  1140. }
  1141. scheme_changed = true;
  1142. buttonApply->setEnabled(true);
  1143. kdDebugFuncOut(trace);
  1144. }
  1145. /*!
  1146. * SLOT: called if a new item in cB_autoInactivity is selected.
  1147. * \param selectedItem Integer, contains the ID of the new item in the
  1148. * comboBox.
  1149. */
  1150. void ConfigureDialog::cB_autoInactivity_activated( int selectedItem ) {
  1151. kdDebugFuncIn(trace);
  1152. if( actions[selectedItem] != " " ) {
  1153. if(!displayed_WARN_autosuspend && initalised) {
  1154. TQString _msg = "<qt>" + i18n("<b>Note:</b> If you select this option, the computer "
  1155. "will suspend or standby if the current user is "
  1156. "inactive for the defined time even if somebody is "
  1157. "logged in remotely to the X server.<br><br> This "
  1158. "feature can also produce problems with some programs, "
  1159. "such as video players or cd burner. These programs can "
  1160. "be blacklisted by checking <b>Enable scheme-specific "
  1161. "blacklist</b> and click <b>Edit Blacklist...</b>. If "
  1162. "this does not help, report the problem or deactivate "
  1163. "autosuspend.<br><br> Really use this option?") +
  1164. "</qt>";
  1165. int tmp = KMessageBox::warningContinueCancel(this, _msg);
  1166. if (tmp == KMessageBox::Cancel) {
  1167. selectedItem = 0;
  1168. }
  1169. displayed_WARN_autosuspend = true;
  1170. }
  1171. sB_autoInactivity->setEnabled(true);
  1172. tL_autoInactivity_After->setEnabled(true);
  1173. cB_Blacklist->setEnabled(true);
  1174. if(cB_Blacklist->isChecked()) pB_editBlacklist->setEnabled(true);
  1175. }
  1176. else {
  1177. sB_autoInactivity->setEnabled(false);
  1178. tL_autoInactivity_After->setEnabled(false);
  1179. cB_Blacklist->setEnabled(false);
  1180. pB_editBlacklist->setEnabled(false);
  1181. }
  1182. cB_autoInactivity->setCurrentItem( selectedItem );
  1183. if(initalised) {
  1184. scheme_changed = true;
  1185. buttonApply->setEnabled(true);
  1186. }
  1187. kdDebugFuncOut(trace);
  1188. }
  1189. /*!
  1190. * SLOT: Called if the 'Enable scheme specific blacklist' is toggled.
  1191. * \param toggled boolean, true if toggled on
  1192. * false if toggled off
  1193. */
  1194. void ConfigureDialog::cB_Blacklist_toggled( bool toggled ){
  1195. kdDebugFuncIn(trace);
  1196. pB_editBlacklist->setEnabled(toggled);
  1197. if(initalised) {
  1198. buttonApply->setEnabled(true);
  1199. scheme_changed = true;
  1200. } else {
  1201. cB_Blacklist->setChecked(toggled);
  1202. }
  1203. kdDebugFuncOut(trace);
  1204. }
  1205. /*!
  1206. * SLOT: Called if the 'edit blacklist' button is toggled.
  1207. */
  1208. void ConfigureDialog::pB_editBlacklistSuspend_clicked(){
  1209. kdDebugFuncIn(trace);
  1210. TQString _top_text = "";
  1211. bool initialiseImport = false;
  1212. if(tabWidget->currentPageIndex() == 0 ) {
  1213. TQString s_scheme = getSchemeRealName(schemes[listBox_schemes->currentItem()]);
  1214. _top_text = listBox_schemes->currentText();
  1215. if (tdeconfig->hasGroup(s_scheme)){
  1216. tdeconfig->setGroup(s_scheme);
  1217. }
  1218. blacklist = tdeconfig->readListEntry("autoInactiveSchemeBlacklist", ',');
  1219. if( blacklist.empty()) {
  1220. TQString _msg = i18n("The blacklist of the selected scheme is empty. "
  1221. "Import the general blacklist?");
  1222. int tmp = KMessageBox::questionYesNo(this, _msg, TQString(), i18n("Import"), i18n("Do Not Import"));
  1223. if (tmp == KMessageBox::Yes) {
  1224. initialiseImport = true;
  1225. if(tdeconfig->hasGroup("General")){
  1226. tdeconfig->setGroup("General");
  1227. blacklist = tdeconfig->readListEntry("autoInactiveBlacklist", ',');
  1228. }
  1229. }
  1230. }
  1231. }
  1232. else {
  1233. if(tdeconfig->hasGroup("General")){
  1234. _top_text = i18n("General Autosuspend Blacklist");
  1235. tdeconfig->setGroup("General");
  1236. blacklist = tdeconfig->readListEntry("autoInactiveBlacklist", ',');
  1237. }
  1238. }
  1239. blacklistEDlgAS = new blacklistEditDialog(blacklist, _top_text, initialiseImport, this);
  1240. connect( blacklistEDlgAS, TQT_SIGNAL(config_finished(TQStringList)), this,
  1241. TQT_SLOT(saveSchemeSuspendBlacklist(TQStringList)));
  1242. blacklistEDlgAS->exec();
  1243. kdDebugFuncOut(trace);
  1244. }
  1245. /*!
  1246. * SLOT: Called if the signal config_finished(TQStringList) recieved
  1247. * and the autosuspend blacklist is edited.
  1248. * \param new_blacklist TQStringlist with the edited blacklisted processes
  1249. */
  1250. void ConfigureDialog::saveSchemeSuspendBlacklist( TQStringList new_blacklist){
  1251. kdDebugFuncIn(trace);
  1252. if(tabWidget->currentPageIndex() == 0 ) {
  1253. TQString s_scheme = getSchemeRealName(schemes[currentScheme]);
  1254. tdeconfig->setGroup(s_scheme);
  1255. tdeconfig->writeEntry("autoInactiveSchemeBlacklist", new_blacklist, ',');
  1256. }
  1257. else {
  1258. tdeconfig->setGroup("General");
  1259. tdeconfig->writeEntry("autoInactiveBlacklist", new_blacklist, ',');
  1260. }
  1261. tdeconfig->sync();
  1262. kdDebugFuncOut(trace);
  1263. }
  1264. /* ---- END Inactivity SECTION ---- */
  1265. /* ---- START Autodimm SECTION ---- */
  1266. /*!
  1267. * This used to set the autodimm related widgets.
  1268. */
  1269. void ConfigureDialog::cB_autoDimm_toggled( bool toggled ) {
  1270. kdDebugFuncIn(trace);
  1271. if(cB_autoDimm->isOn() != toggled)
  1272. cB_autoDimm->setChecked(toggled);
  1273. if (toggled)
  1274. tL_autoDimmExplain->setEnabled(toggled);
  1275. tL_autoDimmAfter->setEnabled(toggled);
  1276. sB_autoDimmTime->setEnabled(toggled);
  1277. tL_autoDimmTo->setEnabled(toggled);
  1278. sB_autoDimmTo->setEnabled(toggled);
  1279. if (sB_autoDimmTime->value() > 0)
  1280. cB_BlacklistDimm->setEnabled(toggled);
  1281. if (cB_BlacklistDimm->isOn())
  1282. pB_editBlacklistDimm->setEnabled(toggled);
  1283. if (toggled) {
  1284. if (sB_autoDimmTime->value() > 0) {
  1285. tL_autoDimmTo->setEnabled(true);
  1286. sB_autoDimmTo->setEnabled(true);
  1287. } else {
  1288. tL_autoDimmTo->setEnabled(false);
  1289. sB_autoDimmTo->setEnabled(false);
  1290. }
  1291. }
  1292. scheme_changed = true;
  1293. buttonApply->setEnabled(true);
  1294. kdDebugFuncOut(trace);
  1295. }
  1296. /*!
  1297. * SLOT: Called if the 'Enable scheme specific blacklist' is toggled.
  1298. * \param toggled boolean, true if toggled on
  1299. * false if toggled off
  1300. */
  1301. void ConfigureDialog::cB_BlacklistDimm_toggled( bool toggled ){
  1302. kdDebugFuncIn(trace);
  1303. pB_editBlacklistDimm->setEnabled(toggled);
  1304. if(initalised) {
  1305. buttonApply->setEnabled(true);
  1306. scheme_changed = true;
  1307. } else {
  1308. cB_BlacklistDimm->setChecked(toggled);
  1309. }
  1310. kdDebugFuncOut(trace);
  1311. }
  1312. /*!
  1313. * SLOT: Called if the 'edit blacklist' button for autodimm is toggled.
  1314. */
  1315. void ConfigureDialog::pB_editBlacklistDimm_clicked(){
  1316. kdDebugFuncIn(trace);
  1317. TQString _top_text = "";
  1318. bool initialiseImport = false;
  1319. if(tabWidget->currentPageIndex() == 0 ) {
  1320. TQString s_scheme = getSchemeRealName(schemes[listBox_schemes->currentItem()]);
  1321. _top_text = listBox_schemes->currentText();
  1322. if (tdeconfig->hasGroup(s_scheme)){
  1323. tdeconfig->setGroup(s_scheme);
  1324. }
  1325. blacklist = tdeconfig->readListEntry("autoDimmSchemeBlacklist", ',');
  1326. if( blacklist.empty()) {
  1327. TQString _msg = i18n("The blacklist of the selected scheme is empty. "
  1328. "Import the general blacklist?");
  1329. int tmp = KMessageBox::questionYesNo(this, _msg, TQString(), i18n("Import"), i18n("Do Not Import"));
  1330. if (tmp == KMessageBox::Yes) {
  1331. initialiseImport = true;
  1332. if(tdeconfig->hasGroup("General")){
  1333. tdeconfig->setGroup("General");
  1334. blacklist = tdeconfig->readListEntry("autoDimmBlacklist", ',');
  1335. }
  1336. }
  1337. }
  1338. }
  1339. else {
  1340. if(tdeconfig->hasGroup("General")){
  1341. _top_text = i18n("General Autodimm Blacklist");
  1342. tdeconfig->setGroup("General");
  1343. blacklist = tdeconfig->readListEntry("autoDimmBlacklist", ',');
  1344. }
  1345. }
  1346. blacklistEDlgAD = new blacklistEditDialog(blacklist, _top_text, initialiseImport, this);
  1347. connect( blacklistEDlgAD, TQT_SIGNAL(config_finished(TQStringList)), this,
  1348. TQT_SLOT(saveSchemeDimmBlacklist(TQStringList)));
  1349. blacklistEDlgAD->exec();
  1350. kdDebugFuncOut(trace);
  1351. }
  1352. /*!
  1353. * SLOT: Called if the signal config_finished(TQStringList) recieved
  1354. * and the autdimm blacklist is edited.
  1355. * \param new_blacklist TQStringlist with the edited blacklisted processes
  1356. */
  1357. void ConfigureDialog::saveSchemeDimmBlacklist( TQStringList new_blacklist){
  1358. kdDebugFuncIn(trace);
  1359. if(tabWidget->currentPageIndex() == 0 ) {
  1360. TQString s_scheme = getSchemeRealName(schemes[currentScheme]);
  1361. tdeconfig->setGroup(s_scheme);
  1362. tdeconfig->writeEntry("autoDimmSchemeBlacklist", new_blacklist, ',');
  1363. }
  1364. else {
  1365. tdeconfig->setGroup("General");
  1366. tdeconfig->writeEntry("autoDimmBlacklist", new_blacklist, ',');
  1367. }
  1368. tdeconfig->sync();
  1369. kdDebugFuncOut(trace);
  1370. }
  1371. /*!
  1372. * SLOT: Called if there \ref sB_autoDimmTime get changed
  1373. * \param value Integer with the new value
  1374. */
  1375. void ConfigureDialog::sB_autoDimmTime_valueChanged( int value ) {
  1376. kdDebugFuncIn(trace);
  1377. if (value > 0) {
  1378. if (!tL_autoDimmTo->isEnabled()) {
  1379. tL_autoDimmTo->setEnabled(true);
  1380. sB_autoDimmTo->setEnabled(true);
  1381. cB_BlacklistDimm->setEnabled(true);
  1382. if (cB_BlacklistDimm->isOn())
  1383. pB_editBlacklistDimm->setEnabled(true);
  1384. }
  1385. } else {
  1386. if (tL_autoDimmTo->isEnabled()) {
  1387. tL_autoDimmTo->setEnabled(false);
  1388. sB_autoDimmTo->setEnabled(false);
  1389. cB_BlacklistDimm->setEnabled(false);
  1390. pB_editBlacklistDimm->setEnabled(false);
  1391. }
  1392. }
  1393. kdDebugFuncOut(trace);
  1394. }
  1395. /* ---- END Autodimm SECTION ---- */
  1396. /* ---- START Brightness SECTION ---- */
  1397. /*! \b SLOT: to enable the brigthness related widgets */
  1398. void ConfigureDialog::cB_Brightness_toggled( bool toggled ) {
  1399. kdDebugFuncIn(trace);
  1400. gB_Brightness->setEnabled(toggled);
  1401. cB_Brightness->setChecked(toggled);
  1402. connect(brightnessSlider, TQT_SIGNAL(valueChanged (int)), this, TQT_SLOT(brightnessSlider_sliderMoved(int)));
  1403. kdDebugFuncOut(trace);
  1404. }
  1405. /*! \b SLOT: to change the brightness if the slider is changed */
  1406. void ConfigureDialog::brightnessSlider_sliderMoved( int new_value ) {
  1407. kdDebugFuncIn(trace);
  1408. if (cB_Brightness->isEnabled() && cB_Brightness->isChecked()) {
  1409. scheme_valueChanged();
  1410. tL_valueBrightness->setText(TQString::number(new_value) + " %");
  1411. hwinfo->setBrightness(-1, new_value);
  1412. pB_resetBrightness->setEnabled(true);
  1413. brightness_changed = true;
  1414. }
  1415. kdDebugFuncOut(trace);
  1416. }
  1417. /*! \b SLOT: to reset the brightness if the reset button clicked */
  1418. void ConfigureDialog::pB_resetBrightness_clicked( ) {
  1419. kdDebugFuncIn(trace);
  1420. hwinfo->setBrightness(brightness_last, -1);
  1421. brightnessSlider->setValue(brightness_last);
  1422. pB_resetBrightness->setEnabled(false);
  1423. brightness_changed = false;
  1424. kdDebugFuncOut(trace);
  1425. }
  1426. /* ---- END Brightness SECTION ---- */
  1427. /* ---- START battery level SECTION ---- */
  1428. /*!
  1429. * SLOT: called if the warning TQSpinBoxes for battery level is changed.
  1430. */
  1431. void ConfigureDialog::sB_batWarning_valueChanged() {
  1432. kdDebugFuncIn(trace);
  1433. if (initalised) {
  1434. if (sB_batWarning->value() == 0 )
  1435. sB_batWarning->setValue(1);
  1436. if ( sB_batWarning->value() <= sB_batLow->value()) {
  1437. sB_batLow->setValue(sB_batWarning->value()-1);
  1438. }
  1439. }
  1440. kdDebugFuncOut(trace);
  1441. }
  1442. /*!
  1443. * SLOT: called if the low TQSpinBoxes for battery level is changed.
  1444. */
  1445. void ConfigureDialog::sB_batLow_valueChanged() {
  1446. kdDebugFuncIn(trace);
  1447. if (initalised) {
  1448. if (sB_batLow->value() == 0 )
  1449. sB_batLow->setValue(1);
  1450. if ( sB_batLow->value() >= sB_batWarning->value()) {
  1451. sB_batWarning->setValue(sB_batLow->value()+1);
  1452. }
  1453. if ( sB_batLow->value() <= sB_batCritical->value()) {
  1454. sB_batCritical->setValue(sB_batLow->value()-1);
  1455. }
  1456. }
  1457. kdDebugFuncOut(trace);
  1458. }
  1459. /*!
  1460. * SLOT: called if the critical TQSpinBoxes for battery level is changed.
  1461. */
  1462. void ConfigureDialog::sB_batCritical_valueChanged() {
  1463. kdDebugFuncIn(trace);
  1464. if (initalised) {
  1465. if (sB_batCritical->value() == 0 )
  1466. sB_batCritical->setValue(1);
  1467. if ( sB_batCritical->value() >= sB_batLow->value()) {
  1468. sB_batLow->setValue(sB_batCritical->value()+1);
  1469. }
  1470. }
  1471. kdDebugFuncOut(trace);
  1472. }
  1473. /*!
  1474. * SLOT: called if the TQComboBox for the battery warning level action changed,
  1475. * used to hide/show the related TQSpinboxes if needed.
  1476. */
  1477. void ConfigureDialog::cB_batWarning_activated() {
  1478. kdDebugFuncIn(trace);
  1479. if ( mapDescriptionToAction(cB_batWarning->currentText()) == "BRIGHTNESS") {
  1480. sB_batWarnAction_value->show();
  1481. } else {
  1482. sB_batWarnAction_value->hide();
  1483. }
  1484. kdDebugFuncOut(trace);
  1485. }
  1486. //! called if the TQComboBox for the battery low level action changed
  1487. /*!
  1488. * used to hide/show the related TQSpinboxes if needed.
  1489. */
  1490. void ConfigureDialog::cB_batLow_activated() {
  1491. kdDebugFuncIn(trace);
  1492. if ( mapDescriptionToAction(cB_batLow->currentText()) == "BRIGHTNESS") {
  1493. sB_batLowAction_value->show();
  1494. } else {
  1495. sB_batLowAction_value->hide();
  1496. }
  1497. kdDebugFuncOut(trace);
  1498. }
  1499. /*!
  1500. * SLOT: called if the TQComboBox for the battery critical level action changed,
  1501. * used to hide/show the related TQSpinboxes if needed.
  1502. */
  1503. void ConfigureDialog::cB_batCritical_activated() {
  1504. kdDebugFuncIn(trace);
  1505. if ( mapDescriptionToAction(cB_batCritical->currentText()) == "BRIGHTNESS") {
  1506. sB_batCritAction_value->show();
  1507. } else {
  1508. sB_batCritAction_value->hide();
  1509. }
  1510. kdDebugFuncOut(trace);
  1511. }
  1512. /* ---- END battery level SECTION ---- */
  1513. /*! \b SLOT: to open the KNotify config dialog */
  1514. void ConfigureDialog::pB_configNotify_released( ) {
  1515. kdDebugFuncIn(trace);
  1516. emit openKNotify();
  1517. kdDebugFuncOut(trace);
  1518. }
  1519. /* ---- START helper functions SECTION ---- */
  1520. /*!
  1521. * Map the key from config for a action to a descriptive name.
  1522. * \param action TQString with the config key value
  1523. * \return TQString with the description
  1524. */
  1525. TQString ConfigureDialog::mapActionToDescription( TQString action ) {
  1526. kdDebugFuncIn(trace);
  1527. TQString ret;
  1528. if (action.startsWith("SHUTDOWN")) {
  1529. ret = i18n("Shutdown");
  1530. } else if (action.startsWith("LOGOUT_DIALOG")) {
  1531. ret = i18n("Logout Dialog");
  1532. } else if (action.startsWith("SUSPEND2DISK")) {
  1533. if (actions.contains("Hibernate"))
  1534. ret = i18n("Hibernate");
  1535. } else if (action.startsWith("SUSPEND_HYBRID")) {
  1536. if (actions.contains("Hybrid Suspend"))
  1537. ret = i18n("Hybrid Suspend");
  1538. } else if (action.startsWith("SUSPEND2RAM")) {
  1539. if (actions.contains("Suspend"))
  1540. ret = i18n("Suspend");
  1541. } else if (action.startsWith("FREEZE")) {
  1542. if (actions.contains("Freeze"))
  1543. ret = i18n("Freeze");
  1544. } else if (action.startsWith("CPUFREQ_POWERSAVE")) {
  1545. if (hwinfo->supportCPUFreq())
  1546. ret = i18n("CPU Powersave policy");
  1547. } else if (action.startsWith("CPUFREQ_DYNAMIC")) {
  1548. if (hwinfo->supportCPUFreq())
  1549. ret = i18n("CPU Dynamic policy");
  1550. } else if (action.startsWith("CPUFREQ_PERFORMANCE")) {
  1551. if (hwinfo->supportCPUFreq())
  1552. ret = i18n("CPU Performance policy");
  1553. } else if (action.startsWith("BRIGHTNESS")) {
  1554. if (hwinfo->supportBrightness())
  1555. ret = i18n("Set Brightness to");
  1556. }
  1557. kdDebugFuncOut(trace);
  1558. return ret;
  1559. }
  1560. /*!
  1561. * Map the action description (maybe translated) back to a TQString key for the config.
  1562. * \param description TQString with the description
  1563. * \return TQString with the config key value
  1564. */
  1565. TQString ConfigureDialog::mapDescriptionToAction( TQString description ) {
  1566. kdDebugFuncIn(trace);
  1567. TQString ret;
  1568. if (description.startsWith("Shutdown") || description.startsWith(i18n("Shutdown"))) {
  1569. ret = "SHUTDOWN";
  1570. } else if (description.startsWith("Logout Dialog") ||
  1571. description.startsWith(i18n("Logout Dialog"))) {
  1572. ret = "LOGOUT_DIALOG";
  1573. } else if (description.startsWith("Hibernate") ||
  1574. description.startsWith(i18n("Hibernate"))) {
  1575. ret = "SUSPEND2DISK";
  1576. } else if (description.startsWith("Hybrid Suspend") ||
  1577. description.startsWith(i18n("Hybrid Suspend"))) {
  1578. ret = "SUSPEND_HYBRID";
  1579. } else if (description.startsWith("Suspend") ||
  1580. description.startsWith(i18n("Suspend"))) {
  1581. ret = "SUSPEND2RAM";
  1582. } else if (description.startsWith("Freeze") ||
  1583. description.startsWith(i18n("Freeze"))) {
  1584. ret = "FREEZE";
  1585. } else if (description.startsWith("CPU Powersave policy") ||
  1586. description.startsWith(i18n("CPU Powersave policy"))) {
  1587. ret = "CPUFREQ_POWERSAVE";
  1588. } else if (description.startsWith("CPU Dynamic policy") ||
  1589. description.startsWith(i18n("CPU Dynamic policy"))) {
  1590. ret = "CPUFREQ_DYNAMIC";
  1591. } else if (description.startsWith("CPU Performance policy") ||
  1592. description.startsWith(i18n("CPU Performance policy"))) {
  1593. ret = "CPUFREQ_PERFORMANCE";
  1594. } else if (description.startsWith("Set Brightness to") ||
  1595. description.startsWith(i18n("Set Brightness to"))) {
  1596. ret = "BRIGHTNESS";
  1597. }
  1598. kdDebugFuncOut(trace);
  1599. return ret;
  1600. }
  1601. /*!
  1602. * Helper to fill a TQComboBox with their text and select the correct item
  1603. * \param _cb Pointer to the TQComboBox
  1604. * \param _actions TQStringList with the allowed actions
  1605. * \param _select TQString with the action to select
  1606. */
  1607. void ConfigureDialog::fillActionComboBox(TQComboBox *_cb, TQStringList _actions, TQString _select) {
  1608. kdDebugFuncIn(trace);
  1609. _cb->clear();
  1610. _cb->insertItem("");
  1611. for ( TQStringList::Iterator it = _actions.begin(); it != _actions.end(); ++it ) {
  1612. TQString _tmp = *it;
  1613. TQString _desc = mapActionToDescription( _tmp );
  1614. if (!_desc.isEmpty()) {
  1615. _cb->insertItem( _desc );
  1616. if (_tmp == _select) {
  1617. _cb->setCurrentItem(_cb->count()-1);
  1618. }
  1619. }
  1620. }
  1621. kdDebugFuncOut(trace);
  1622. }
  1623. /* ---- END helper functions SECTION ---- */
  1624. #include "configuredialog.moc"