Diffstat (limited to 'core/settings/light-and-power/light.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/settings/light-and-power/light.cpp | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/core/settings/light-and-power/light.cpp b/core/settings/light-and-power/light.cpp new file mode 100644 index 0000000..24e1fab --- a/dev/null +++ b/core/settings/light-and-power/light.cpp | |||
@@ -0,0 +1,133 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include "settings.h" | ||
21 | |||
22 | #include <qpe/global.h> | ||
23 | #include <qpe/fontmanager.h> | ||
24 | #include <qpe/config.h> | ||
25 | #include <qpe/applnk.h> | ||
26 | #include <qpe/qpeapplication.h> | ||
27 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | ||
28 | #include <qpe/qcopenvelope_qws.h> | ||
29 | #endif | ||
30 | |||
31 | #include <qlabel.h> | ||
32 | #include <qcheckbox.h> | ||
33 | #include <qradiobutton.h> | ||
34 | #include <qtabwidget.h> | ||
35 | #include <qslider.h> | ||
36 | #include <qfile.h> | ||
37 | #include <qtextstream.h> | ||
38 | #include <qdatastream.h> | ||
39 | #include <qmessagebox.h> | ||
40 | #include <qcombobox.h> | ||
41 | #include <qspinbox.h> | ||
42 | #include <qlistbox.h> | ||
43 | #include <qdir.h> | ||
44 | #if QT_VERSION >= 300 | ||
45 | #include <qstylefactory.h> | ||
46 | #endif | ||
47 | |||
48 | extern int qpe_sysBrightnessSteps(); | ||
49 | |||
50 | LightSettings::LightSettings( QWidget* parent, const char* name, WFlags fl ) | ||
51 | : LightSettingsBase( parent, name, TRUE, fl ) | ||
52 | { | ||
53 | // Not supported | ||
54 | auto_brightness->hide(); | ||
55 | |||
56 | Config config( "qpe" ); | ||
57 | |||
58 | config.setGroup( "Screensaver" ); | ||
59 | |||
60 | int interval; | ||
61 | interval = config.readNumEntry( "Interval_Dim", 30 ); | ||
62 | interval_dim->setValue( interval ); | ||
63 | interval = config.readNumEntry( "Interval_LightOff", 20 ); | ||
64 | interval_lightoff->setValue( interval ); | ||
65 | interval = config.readNumEntry( "Interval", 60 ); | ||
66 | if ( interval > 3600 ) interval /= 1000; // compatibility (was millisecs) | ||
67 | interval_suspend->setValue( interval ); | ||
68 | |||
69 | screensaver_dim->setChecked( config.readNumEntry("Dim",1) != 0 ); | ||
70 | screensaver_lightoff->setChecked( config.readNumEntry("LightOff",1) != 0 ); | ||
71 | int maxbright = qpe_sysBrightnessSteps(); | ||
72 | initbright = config.readNumEntry("Brightness",255); | ||
73 | brightness->setMaxValue( maxbright ); | ||
74 | brightness->setTickInterval( QMAX(1,maxbright/16) ); | ||
75 | brightness->setLineStep( QMAX(1,maxbright/16) ); | ||
76 | brightness->setPageStep( QMAX(1,maxbright/16) ); | ||
77 | brightness->setValue( (maxbright*255 - initbright*maxbright)/255 ); | ||
78 | |||
79 | connect(brightness, SIGNAL(valueChanged(int)), this, SLOT(applyBrightness())); | ||
80 | } | ||
81 | |||
82 | LightSettings::~LightSettings() | ||
83 | { | ||
84 | } | ||
85 | |||
86 | static void set_fl(int bright) | ||
87 | { | ||
88 | QCopEnvelope e("QPE/System", "setBacklight(int)" ); | ||
89 | e << bright; | ||
90 | } | ||
91 | |||
92 | void LightSettings::reject() | ||
93 | { | ||
94 | set_fl(initbright); | ||
95 | |||
96 | QDialog::reject(); | ||
97 | } | ||
98 | |||
99 | void LightSettings::accept() | ||
100 | { | ||
101 | if ( qApp->focusWidget() ) | ||
102 | qApp->focusWidget()->clearFocus(); | ||
103 | |||
104 | applyBrightness(); | ||
105 | |||
106 | int i_dim = (screensaver_dim->isChecked() ? interval_dim->value() : 0); | ||
107 | int i_lightoff = (screensaver_lightoff->isChecked() ? interval_lightoff->value() : 0); | ||
108 | int i_suspend = interval_suspend->value(); | ||
109 | QCopEnvelope e("QPE/System", "setScreenSaverIntervals(int,int,int)" ); | ||
110 | e << i_dim << i_lightoff << i_suspend; | ||
111 | |||
112 | Config config( "qpe" ); | ||
113 | config.setGroup( "Screensaver" ); | ||
114 | config.writeEntry( "Dim", (int)screensaver_dim->isChecked() ); | ||
115 | config.writeEntry( "LightOff", (int)screensaver_lightoff->isChecked() ); | ||
116 | config.writeEntry( "Interval_Dim", interval_dim->value() ); | ||
117 | config.writeEntry( "Interval_LightOff", interval_lightoff->value() ); | ||
118 | config.writeEntry( "Interval", interval_suspend->value() ); | ||
119 | config.writeEntry( "Brightness", | ||
120 | (brightness->maxValue()-brightness->value())*255/brightness->maxValue() ); | ||
121 | config.write(); | ||
122 | |||
123 | QDialog::accept(); | ||
124 | } | ||
125 | |||
126 | void LightSettings::applyBrightness() | ||
127 | { | ||
128 | int bright = (brightness->maxValue()-brightness->value())*255 | ||
129 | / brightness->maxValue(); | ||
130 | set_fl(bright); | ||
131 | } | ||
132 | |||
133 | |||