summaryrefslogtreecommitdiff
path: root/core/settings/light-and-power/light.cpp
Unidiff
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.cpp57
1 files changed, 32 insertions, 25 deletions
diff --git a/core/settings/light-and-power/light.cpp b/core/settings/light-and-power/light.cpp
index c0ba60b..21377b7 100644
--- a/core/settings/light-and-power/light.cpp
+++ b/core/settings/light-and-power/light.cpp
@@ -17,151 +17,160 @@
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details. 18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .: 19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU 20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file; 21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the 22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc., 23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330, 24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include "settings.h" 29#include "light.h"
30 30
31#include <qpe/config.h> 31#include <qpe/config.h>
32#include <qpe/qpeapplication.h> 32#include <qpe/qpeapplication.h>
33#include <qpe/power.h> 33#include <qpe/power.h>
34#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 34#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
35#include <qpe/qcopenvelope_qws.h> 35#include <qpe/qcopenvelope_qws.h>
36#endif 36#endif
37 37
38#include <qcheckbox.h> 38#include <qcheckbox.h>
39#include <qtabwidget.h> 39#include <qtabwidget.h>
40#include <qslider.h> 40#include <qslider.h>
41#include <qtimer.h>
41#include <qspinbox.h> 42#include <qspinbox.h>
42#include <qpushbutton.h> 43#include <qpushbutton.h>
43 44
44#include <opie/odevice.h> 45#include <opie/odevice.h>
45 46
46#include "sensor.h" 47#include "sensor.h"
47 48
48using namespace Opie; 49using namespace Opie;
49 50
50LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) 51LightSettings::LightSettings( QWidget* parent, const char* name, WFlags )
51 : LightSettingsBase( parent, name, true, WStyle_ContextHelp ) 52 : LightSettingsBase( parent, name, false, WStyle_ContextHelp )
52{ 53{
53 m_res = ODevice::inst ( )-> displayBrightnessResolution ( ); 54 m_res = ODevice::inst ( )-> displayBrightnessResolution ( );
54 55
55 if ( !ODevice::inst ( )-> hasLightSensor ( )) { 56 if ( !ODevice::inst ( )-> hasLightSensor ( )) {
56 auto_brightness-> hide ( ); 57 auto_brightness-> hide ( );
57 CalibrateLightSensor-> hide ( ); 58 CalibrateLightSensor-> hide ( );
58 auto_brightness_ac_3-> hide ( ); 59 auto_brightness_ac_3-> hide ( );
59 CalibrateLightSensorAC-> hide ( ); 60 CalibrateLightSensorAC-> hide ( );
60 } 61 }
61 62
62 Config config ( "apm" ); 63 Config config ( "apm" );
63 config. setGroup ( "Battery" ); 64 config. setGroup ( "Battery" );
64 65
65 // battery spinboxes 66 // battery spinboxes
66 interval_dim-> setValue ( config. readNumEntry ( "Dim", 20 )); 67 interval_dim-> setValue ( config. readNumEntry ( "Dim", 30 ));
67 interval_lightoff-> setValue ( config. readNumEntry ( "LightOff", 30 )); 68 interval_lightoff-> setValue ( config. readNumEntry ( "LightOff", 20 ));
68 interval_suspend-> setValue ( config. readNumEntry ( "Suspend", 60 )); 69 interval_suspend-> setValue ( config. readNumEntry ( "Suspend", 60 ));
69 70
70 // battery check and slider 71 // battery check and slider
71 LcdOffOnly-> setChecked ( config. readBoolEntry ( "LcdOffOnly", false )); 72 LcdOffOnly-> setChecked ( config. readBoolEntry ( "LcdOffOnly", false ));
72 73
73 int bright = config. readNumEntry ( "Brightness", 255 ); 74 int bright = config. readNumEntry ( "Brightness", 127 );
74 brightness-> setMaxValue ( m_res - 1 ); 75 brightness-> setMaxValue ( m_res - 1 );
75 brightness-> setTickInterval ( QMAX( 1, m_res / 16 )); 76 brightness-> setTickInterval ( QMAX( 1, m_res / 16 ));
76 brightness-> setLineStep ( QMAX( 1, m_res / 16 )); 77 brightness-> setLineStep ( QMAX( 1, m_res / 16 ));
77 brightness-> setPageStep ( QMAX( 1, m_res / 16 )); 78 brightness-> setPageStep ( QMAX( 1, m_res / 16 ));
78 brightness-> setValue (( bright * ( m_res - 1 ) + 127 ) / 255 ); 79 brightness-> setValue (( bright * ( m_res - 1 ) + 127 ) / 255 );
79 80
80 // light sensor 81 // light sensor
81 auto_brightness-> setChecked ( config. readBoolEntry ( "LightSensor", false )); 82 auto_brightness-> setChecked ( config. readBoolEntry ( "LightSensor", false ));
82 m_sensordata = config. readListEntry ( "LightSensorData", ';' ); 83 m_sensordata = config. readListEntry ( "LightSensorData", ';' );
83 84
84 config. setGroup ( "AC" ); 85 config. setGroup ( "AC" );
85 86
86 // ac spinboxes 87 // ac spinboxes
87 interval_dim_ac_3-> setValue ( config. readNumEntry ( "Dim", 20 )); 88 interval_dim_ac_3-> setValue ( config. readNumEntry ( "Dim", 60 ));
88 interval_lightoff_ac_3-> setValue ( config. readNumEntry ( "LightOff", 30 )); 89 interval_lightoff_ac_3-> setValue ( config. readNumEntry ( "LightOff", 120 ));
89 interval_suspend_ac_3-> setValue ( config. readNumEntry ( "Suspend", 60 )); 90 interval_suspend_ac_3-> setValue ( config. readNumEntry ( "Suspend", 0 ));
90 91
91 // ac check and slider 92 // ac check and slider
92 LcdOffOnly_2_3-> setChecked ( config. readBoolEntry ( "LcdOffOnly", false )); 93 LcdOffOnly_2_3-> setChecked ( config. readBoolEntry ( "LcdOffOnly", false ));
93 94
94 bright = config. readNumEntry ( "Brightness", 255 ); 95 bright = config. readNumEntry ( "Brightness", 255 );
95 brightness_ac_3-> setMaxValue ( m_res - 1 ); 96 brightness_ac_3-> setMaxValue ( m_res - 1 );
96 brightness_ac_3-> setTickInterval ( QMAX( 1, m_res / 16 )); 97 brightness_ac_3-> setTickInterval ( QMAX( 1, m_res / 16 ));
97 brightness_ac_3-> setLineStep ( QMAX( 1, m_res / 16 )); 98 brightness_ac_3-> setLineStep ( QMAX( 1, m_res / 16 ));
98 brightness_ac_3-> setPageStep ( QMAX( 1, m_res / 16 )); 99 brightness_ac_3-> setPageStep ( QMAX( 1, m_res / 16 ));
99 brightness_ac_3-> setValue (( bright * ( m_res - 1 ) + 127 ) / 255 ); 100 brightness_ac_3-> setValue (( bright * ( m_res - 1 ) + 127 ) / 255 );
100 101
101 // light sensor 102 // light sensor
102 auto_brightness_ac_3-> setChecked ( config. readBoolEntry ( "LightSensor", false )); 103 auto_brightness_ac_3-> setChecked ( config. readBoolEntry ( "LightSensor", false ));
103 m_sensordata_ac = config. readListEntry ( "LightSensorData", ';' ); 104 m_sensordata_ac = config. readListEntry ( "LightSensorData", ';' );
104 105
105 // advanced settings 106 // advanced settings
106 config. setGroup ( "Warnings" ); 107 config. setGroup ( "Warnings" );
107 warnintervalBox-> setValue ( config. readNumEntry ( "checkinterval", 10000 ) / 1000 ); 108 warnintervalBox-> setValue ( config. readNumEntry ( "checkinterval", 10000 ) / 1000 );
108 lowSpinBox-> setValue ( config. readNumEntry ( "powerverylow", 10 ) ); 109 lowSpinBox-> setValue ( config. readNumEntry ( "powerverylow", 10 ) );
109 criticalSpinBox-> setValue ( config. readNumEntry ( "powercritical", 5 ) ); 110 criticalSpinBox-> setValue ( config. readNumEntry ( "powercritical", 5 ) );
110 111
112 m_resettimer = new QTimer ( this );
113 connect ( m_resettimer, SIGNAL( timeout ( )), this, SLOT( resetBacklight ( )));
114
111 if ( PowerStatusManager::readStatus ( ). acStatus ( ) != PowerStatus::Online ) { 115 if ( PowerStatusManager::readStatus ( ). acStatus ( ) != PowerStatus::Online ) {
112 connect ( brightness, SIGNAL( valueChanged ( int )), this, SLOT( setBacklight ( int )));
113 tabs-> setCurrentPage ( 0 ); 116 tabs-> setCurrentPage ( 0 );
114 } 117 }
115 else { 118 else {
116 connect ( brightness_ac_3, SIGNAL( valueChanged ( int )), this, SLOT( setBacklight ( int )));
117 tabs-> setCurrentPage ( 1 ); 119 tabs-> setCurrentPage ( 1 );
118 } 120 }
121
122 connect ( brightness, SIGNAL( valueChanged ( int )), this, SLOT( setBacklight ( int )));
123 connect ( brightness_ac_3, SIGNAL( valueChanged ( int )), this, SLOT( setBacklight ( int )));
119} 124}
120 125
121LightSettings::~LightSettings ( ) 126LightSettings::~LightSettings ( )
122{ 127{
123} 128}
124 129
125
126void LightSettings::calibrateSensor ( ) 130void LightSettings::calibrateSensor ( )
127{ 131{
128 Sensor *s = new Sensor ( m_sensordata, this ); 132 Sensor *s = new Sensor ( m_sensordata, this );
133 connect ( s, SIGNAL( viewBacklight ( int )), this, SLOT( setBacklight ( int )));
129 s-> showMaximized ( ); 134 s-> showMaximized ( );
130 s-> exec ( ); 135 s-> exec ( );
131 delete s; 136 delete s;
132} 137}
133 138
134void LightSettings::calibrateSensorAC ( ) 139void LightSettings::calibrateSensorAC ( )
135{ 140{
136 Sensor *s = new Sensor ( m_sensordata_ac, this ); 141 Sensor *s = new Sensor ( m_sensordata_ac, this );
142 connect ( s, SIGNAL( viewBacklight ( int )), this, SLOT( setBacklight ( int )));
137 s-> showMaximized ( ); 143 s-> showMaximized ( );
138 s-> exec ( ); 144 s-> exec ( );
139 delete s; 145 delete s;
140} 146}
141 147
142void LightSettings::setBacklight ( int bright ) 148void LightSettings::setBacklight ( int bright )
143{ 149{
144 bright = bright * 255 / ( m_res - 1 ); 150 if ( bright >= 0 )
151 bright = bright * 255 / ( m_res - 1 );
152
145 QCopEnvelope e ( "QPE/System", "setBacklight(int)" ); 153 QCopEnvelope e ( "QPE/System", "setBacklight(int)" );
146 e << bright; 154 e << bright;
155
156 if ( bright != -1 ) {
157 m_resettimer-> stop ( );
158 m_resettimer-> start ( 2000, true );
159 }
147} 160}
148 161
149void LightSettings::reject ( ) 162void LightSettings::resetBacklight ( )
150{ 163{
151 { 164 setBacklight ( -1 );
152 QCopEnvelope e ( "QPE/System", "setBacklight(int)" );
153 e << -1;
154 }
155 QDialog::reject ( );
156} 165}
157 166
158void LightSettings::accept ( ) 167void LightSettings::accept ( )
159{ 168{
160 Config config ( "apm" ); 169 Config config ( "apm" );
161 170
162 // bat 171 // bat
163 config. setGroup ( "Battery" ); 172 config. setGroup ( "Battery" );
164 config. writeEntry ( "LcdOffOnly", LcdOffOnly-> isChecked ( )); 173 config. writeEntry ( "LcdOffOnly", LcdOffOnly-> isChecked ( ));
165 config. writeEntry ( "Dim", interval_dim-> value ( )); 174 config. writeEntry ( "Dim", interval_dim-> value ( ));
166 config. writeEntry ( "LightOff", interval_lightoff-> value ( )); 175 config. writeEntry ( "LightOff", interval_lightoff-> value ( ));
167 config. writeEntry ( "Suspend", interval_suspend-> value ( )); 176 config. writeEntry ( "Suspend", interval_suspend-> value ( ));
@@ -191,25 +200,23 @@ void LightSettings::accept ( )
191 config. writeEntry ( "power_verylow", lowSpinBox-> value ( )); 200 config. writeEntry ( "power_verylow", lowSpinBox-> value ( ));
192 config. writeEntry ( "power_critical", criticalSpinBox-> value ( )); 201 config. writeEntry ( "power_critical", criticalSpinBox-> value ( ));
193 config. write ( ); 202 config. write ( );
194 203
195 // notify the launcher 204 // notify the launcher
196 { 205 {
197 QCopEnvelope e ( "QPE/System", "reloadPowerWarnSettings()" ); 206 QCopEnvelope e ( "QPE/System", "reloadPowerWarnSettings()" );
198 } 207 }
199 { 208 {
200 QCopEnvelope e ( "QPE/System", "setScreenSaverInterval(int)" ); 209 QCopEnvelope e ( "QPE/System", "setScreenSaverInterval(int)" );
201 e << -1; 210 e << -1;
202 } 211 }
203 { 212 LightSettingsBase::accept ( );
204 QCopEnvelope e ( "QPE/System", "setBacklight(int)" );
205 e << -1;
206 }
207
208 QDialog::accept ( );
209} 213}
210 214
211void LightSettings::done ( int r ) 215void LightSettings::done ( int r )
212{ 216{
213 QDialog::done ( r ); 217 m_resettimer-> stop ( );
218 resetBacklight ( );
219
220 LightSettingsBase::done ( r );
214 close ( ); 221 close ( );
215} 222}