summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-10-27 18:32:14 (UTC)
committer mickeyl <mickeyl>2004-10-27 18:32:14 (UTC)
commit7119f16d0439214b97b371ed4df66147a18e0c44 (patch) (unidiff)
tree2ac19d34b625e61f043fd2e77fff00d5b8bcb950
parent14aec3d5de39e1973693940d813d940f248df2d9 (diff)
downloadopie-7119f16d0439214b97b371ed4df66147a18e0c44.zip
opie-7119f16d0439214b97b371ed4df66147a18e0c44.tar.gz
opie-7119f16d0439214b97b371ed4df66147a18e0c44.tar.bz2
fix writing out the new system brightness
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/brightnessapplet/brightnessapplet.cpp16
-rw-r--r--noncore/applets/brightnessapplet/brightnessapplet.h2
-rw-r--r--noncore/applets/brightnessapplet/brightnessapplet.pro2
3 files changed, 13 insertions, 7 deletions
diff --git a/noncore/applets/brightnessapplet/brightnessapplet.cpp b/noncore/applets/brightnessapplet/brightnessapplet.cpp
index 1ade35e..5aaa27e 100644
--- a/noncore/applets/brightnessapplet/brightnessapplet.cpp
+++ b/noncore/applets/brightnessapplet/brightnessapplet.cpp
@@ -118,82 +118,93 @@ BrightnessAppletControl::BrightnessAppletControl( OTaskbarApplet* parent, const
118 slider->setPageStep(QMAX(1, maxbright / 16)); 118 slider->setPageStep(QMAX(1, maxbright / 16));
119 gl->addMultiCellWidget( slider, 0, 2, 0, 0 ); 119 gl->addMultiCellWidget( slider, 0, 2, 0, 0 );
120 120
121 QPixmap onPm( (const char **)light_on_xpm ); 121 QPixmap onPm( (const char **)light_on_xpm );
122 QLabel *l = new QLabel( this ); 122 QLabel *l = new QLabel( this );
123 l->setPixmap( onPm ); 123 l->setPixmap( onPm );
124 gl->addWidget( l, 0, 1 ); 124 gl->addWidget( l, 0, 1 );
125 125
126 QPixmap offPm( (const char **)light_off_xpm ); 126 QPixmap offPm( (const char **)light_off_xpm );
127 l = new QLabel( this ); 127 l = new QLabel( this );
128 l->setPixmap( offPm ); 128 l->setPixmap( offPm );
129 gl->addWidget( l, 2, 1 ); 129 gl->addWidget( l, 2, 1 );
130 130
131 setFixedHeight( 100 ); 131 setFixedHeight( 100 );
132 setFixedWidth( gl->sizeHint().width() ); 132 setFixedWidth( gl->sizeHint().width() );
133 setFocusPolicy(QWidget::NoFocus); 133 setFocusPolicy(QWidget::NoFocus);
134} 134}
135 135
136 136
137BrightnessAppletControl::~BrightnessAppletControl() 137BrightnessAppletControl::~BrightnessAppletControl()
138{ 138{
139} 139}
140 140
141 141
142void BrightnessAppletControl::hideEvent( QHideEvent* e )
143{
144 BrightnessApplet* applet = static_cast<BrightnessApplet*>( parent() );
145 applet->writeSystemBrightness( applet->calcBrightnessValue() );
146 QFrame::hideEvent( e );
147}
148
142BrightnessApplet::BrightnessApplet( QWidget *parent, const char *name ) 149BrightnessApplet::BrightnessApplet( QWidget *parent, const char *name )
143 :OTaskbarApplet( parent, name ) 150 :OTaskbarApplet( parent, name )
144{ 151{
145 setFixedHeight( AppLnk::smallIconSize() ); 152 setFixedHeight( AppLnk::smallIconSize() );
146 setFixedWidth( AppLnk::smallIconSize() ); 153 setFixedWidth( AppLnk::smallIconSize() );
147 _pixmap.convertFromImage( Resource::loadImage( "brightnessapplet/icon" ).smoothScale( height(), width() ) ); 154 _pixmap.convertFromImage( Resource::loadImage( "brightnessapplet/icon" ).smoothScale( height(), width() ) );
148 _control = new BrightnessAppletControl( this, "control" ); 155 _control = new BrightnessAppletControl( this, "control" );
149} 156}
150 157
151 158
152void BrightnessApplet::writeSystemBrightness(int brightness) 159void BrightnessApplet::writeSystemBrightness(int brightness)
153{ 160{
154 PowerStatus ps = PowerStatusManager::readStatus(); 161 PowerStatus ps = PowerStatusManager::readStatus();
155 162
156 Config cfg("qpe"); 163 Config cfg("qpe");
157 if (ps.acStatus() == PowerStatus::Online) { 164 if (ps.acStatus() == PowerStatus::Online) {
158 cfg.setGroup("AC"); 165 cfg.setGroup("AC");
159 } else { 166 } else {
160 cfg.setGroup("Battery"); 167 cfg.setGroup("Battery");
161 } 168 }
162 cfg.writeEntry("Brightness", brightness); 169 cfg.writeEntry("Brightness", brightness);
170 odebug << "writing brightness " << brightness << oendl;
171 cfg.write();
163} 172}
164 173
165 174
166int BrightnessApplet::readSystemBrightness(void) 175int BrightnessApplet::readSystemBrightness(void)
167{ 176{
168 PowerStatus ps = PowerStatusManager::readStatus(); 177 PowerStatus ps = PowerStatusManager::readStatus();
169 Config cfg("qpe"); 178 Config cfg("qpe");
170 179
171 if (ps.acStatus() == PowerStatus::Online) { 180 if (ps.acStatus() == PowerStatus::Online) {
172 cfg.setGroup("AC"); 181 cfg.setGroup("AC");
173 } else { 182 } else {
174 cfg.setGroup("Battery"); 183 cfg.setGroup("Battery");
175 } 184 }
185
186 odebug << "reading brightness " << cfg.readNumEntry("Brightness", 128) << oendl;
176 187
177 return cfg.readNumEntry("Brightness", 128); 188 return cfg.readNumEntry("Brightness", 128);
178} 189}
179 190
180 191
181BrightnessApplet::~BrightnessApplet() 192BrightnessApplet::~BrightnessApplet()
182{ 193{
183} 194}
184 195
185 196
186int BrightnessApplet::position() 197int BrightnessApplet::position()
187{ 198{
188 return 7; 199 return 7;
189} 200}
190 201
191 202
192void BrightnessApplet::paintEvent( QPaintEvent* ) 203void BrightnessApplet::paintEvent( QPaintEvent* )
193{ 204{
194 QPainter p(this); 205 QPainter p(this);
195 p.drawPixmap(0, 0, _pixmap ); 206 p.drawPixmap(0, 0, _pixmap );
196} 207}
197 208
198 209
199int BrightnessApplet::calcBrightnessValue() 210int BrightnessApplet::calcBrightnessValue()
@@ -202,34 +213,29 @@ int BrightnessApplet::calcBrightnessValue()
202 return (v * 255 + _control->slider->maxValue() / 2) / _control->slider->maxValue(); 213 return (v * 255 + _control->slider->maxValue() / 2) / _control->slider->maxValue();
203} 214}
204 215
205 216
206void BrightnessApplet::sliderMoved( int value ) 217void BrightnessApplet::sliderMoved( int value )
207{ 218{
208#ifndef QT_NO_COP 219#ifndef QT_NO_COP
209 QCopEnvelope e("QPE/System", "setBacklight(int)"); 220 QCopEnvelope e("QPE/System", "setBacklight(int)");
210 e << calcBrightnessValue(); 221 e << calcBrightnessValue();
211#else 222#else
212#error This Applet makes no sense without QCOP 223#error This Applet makes no sense without QCOP
213#endif // QT_NO_COP 224#endif // QT_NO_COP
214} 225}
215 226
216 227
217void BrightnessApplet::mousePressEvent( QMouseEvent* ) 228void BrightnessApplet::mousePressEvent( QMouseEvent* )
218{ 229{
219 if ( !_control->isVisible() ) 230 if ( !_control->isVisible() )
220 { 231 {
221 int v = 255 - readSystemBrightness(); 232 int v = 255 - readSystemBrightness();
222 popup( _control ); 233 popup( _control );
223 _control->slider->setValue((_control->slider->maxValue() * v + 128) / 255); 234 _control->slider->setValue((_control->slider->maxValue() * v + 128) / 255);
224 connect(_control->slider, SIGNAL(valueChanged(int)), this, SLOT(sliderMoved(int))); 235 connect(_control->slider, SIGNAL(valueChanged(int)), this, SLOT(sliderMoved(int)));
225 } 236 }
226 else
227 {
228 _control->hide();
229 writeSystemBrightness( calcBrightnessValue() );
230 }
231} 237}
232 238
233 239
234EXPORT_OPIE_APPLET_v1( BrightnessApplet ) 240EXPORT_OPIE_APPLET_v1( BrightnessApplet )
235 241
diff --git a/noncore/applets/brightnessapplet/brightnessapplet.h b/noncore/applets/brightnessapplet/brightnessapplet.h
index 8b88bd1..6d6d369 100644
--- a/noncore/applets/brightnessapplet/brightnessapplet.h
+++ b/noncore/applets/brightnessapplet/brightnessapplet.h
@@ -26,49 +26,49 @@
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#ifndef NETWORKAPPLET_H 31#ifndef NETWORKAPPLET_H
32#define NETWORKAPPLET_H 32#define NETWORKAPPLET_H
33 33
34#include <opie2/otaskbarapplet.h> 34#include <opie2/otaskbarapplet.h>
35#include <qframe.h> 35#include <qframe.h>
36#include <qstring.h> 36#include <qstring.h>
37#include <qtoolbutton.h> 37#include <qtoolbutton.h>
38#include <qlineedit.h> 38#include <qlineedit.h>
39#include <qpixmap.h> 39#include <qpixmap.h>
40 40
41class QShowEvent; 41class QShowEvent;
42class QHideEvent; 42class QHideEvent;
43class QSlider; 43class QSlider;
44 44
45class BrightnessAppletControl : public QFrame 45class BrightnessAppletControl : public QFrame
46{ 46{
47 public: 47 public:
48 BrightnessAppletControl( Opie::Ui::OTaskbarApplet* parent, const char* name = 0 ); 48 BrightnessAppletControl( Opie::Ui::OTaskbarApplet* parent, const char* name = 0 );
49 ~BrightnessAppletControl(); 49 ~BrightnessAppletControl();
50 50 virtual void hideEvent( QHideEvent* );
51 QSlider* slider; 51 QSlider* slider;
52}; 52};
53 53
54class BrightnessApplet : public Opie::Ui::OTaskbarApplet 54class BrightnessApplet : public Opie::Ui::OTaskbarApplet
55{ 55{
56 Q_OBJECT 56 Q_OBJECT
57 57
58 public: 58 public:
59 BrightnessApplet( QWidget* parent = 0, const char* name = 0 ); 59 BrightnessApplet( QWidget* parent = 0, const char* name = 0 );
60 ~BrightnessApplet(); 60 ~BrightnessApplet();
61 61
62 void writeSystemBrightness( int brightness ); 62 void writeSystemBrightness( int brightness );
63 int readSystemBrightness(); 63 int readSystemBrightness();
64 int calcBrightnessValue(); 64 int calcBrightnessValue();
65 65
66 static int position(); 66 static int position();
67 67
68 public slots: 68 public slots:
69 void sliderMoved( int value ); 69 void sliderMoved( int value );
70 70
71 protected: 71 protected:
72 virtual void paintEvent( QPaintEvent* ); 72 virtual void paintEvent( QPaintEvent* );
73 virtual void mousePressEvent( QMouseEvent* ); 73 virtual void mousePressEvent( QMouseEvent* );
74 74
diff --git a/noncore/applets/brightnessapplet/brightnessapplet.pro b/noncore/applets/brightnessapplet/brightnessapplet.pro
index 5044f38..8c65120 100644
--- a/noncore/applets/brightnessapplet/brightnessapplet.pro
+++ b/noncore/applets/brightnessapplet/brightnessapplet.pro
@@ -1,13 +1,13 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt plugin warn_on 2CONFIG += qt plugin warn_on
3HEADERS = brightnessapplet.h 3HEADERS = brightnessapplet.h
4SOURCES = brightnessapplet.cpp 4SOURCES = brightnessapplet.cpp
5TARGET = brightnessapplet 5TARGET = brightnessapplet
6DESTDIR = $(OPIEDIR)/plugins/applets 6DESTDIR = $(OPIEDIR)/plugins/applets
7INCLUDEPATH += $(OPIEDIR)/include 7INCLUDEPATH += $(OPIEDIR)/include
8DEPENDPATH += $(OPIEDIR)/include 8DEPENDPATH += $(OPIEDIR)/include
9LIBS += -lqpe -lopiecore2 -lopieui2 9LIBS += -lqpe -lopiecore2 -lopieui2
10VERSION = 0.1.0 10VERSION = 0.1.1
11 11
12 12
13include ( $(OPIEDIR)/include.pro ) 13include ( $(OPIEDIR)/include.pro )