summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-05-06 12:25:13 (UTC)
committer llornkcor <llornkcor>2002-05-06 12:25:13 (UTC)
commitc556c027c47921970b11f79aaa4429c2174b5c5b (patch) (unidiff)
treef9be4d90d54eb160aeb28bd7f6d8fb10c1c2db49
parent5549afd820c485db5ec70ad5bf1faed5821ab04a (diff)
downloadopie-c556c027c47921970b11f79aaa4429c2174b5c5b.zip
opie-c556c027c47921970b11f79aaa4429c2174b5c5b.tar.gz
opie-c556c027c47921970b11f79aaa4429c2174b5c5b.tar.bz2
added config file setting for showing mic level Sound.conf [System] ShowMic = TRUE will get you in!
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/volumeapplet/volume.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/core/applets/volumeapplet/volume.cpp b/core/applets/volumeapplet/volume.cpp
index 344f86f..e393f0f 100644
--- a/core/applets/volumeapplet/volume.cpp
+++ b/core/applets/volumeapplet/volume.cpp
@@ -1,379 +1,380 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21 21
22#include "volume.h" 22#include "volume.h"
23 23
24#include <qpe/resource.h> 24#include <qpe/resource.h>
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/config.h> 26#include <qpe/config.h>
27#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 27#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
28#include <qpe/qcopenvelope_qws.h> 28#include <qpe/qcopenvelope_qws.h>
29#endif 29#endif
30 30
31#include <qpainter.h> 31#include <qpainter.h>
32#include <qcheckbox.h> 32#include <qcheckbox.h>
33#include <qslider.h> 33#include <qslider.h>
34#include <qlayout.h> 34#include <qlayout.h>
35#include <qframe.h> 35#include <qframe.h>
36#include <qpixmap.h> 36#include <qpixmap.h>
37#include <qlabel.h> 37#include <qlabel.h>
38 38
39#include <qpushbutton.h> 39#include <qpushbutton.h>
40#include <qtimer.h> 40#include <qtimer.h>
41 41
42#define RATE_TIMER_INTERVAL 100 42#define RATE_TIMER_INTERVAL 100
43// Ten times per second is fine (RATE_TIMER_INTERVAL 100). A shorter time 43// Ten times per second is fine (RATE_TIMER_INTERVAL 100). A shorter time
44// results in "hanging" buttons on the iPAQ due to quite high CPU consumption. 44// results in "hanging" buttons on the iPAQ due to quite high CPU consumption.
45 45
46VolumeControl::VolumeControl( bool showMic, QWidget *parent, const char *name ) 46VolumeControl::VolumeControl( bool showMic, QWidget *parent, const char *name )
47 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) 47 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
48{ 48{
49 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 49 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
50 createView(showMic); 50 createView(showMic);
51} 51}
52 52
53void VolumeControl::createView(bool showMic) 53void VolumeControl::createView(bool showMic)
54{ 54{
55 Config cfg("Sound"); 55 Config cfg("Sound");
56 cfg.setGroup("System"); 56 cfg.setGroup("System");
57//showMic = TRUE; 57//showMic = TRUE;
58 QHBoxLayout *hboxLayout = new QHBoxLayout(this); 58 QHBoxLayout *hboxLayout = new QHBoxLayout(this);
59 hboxLayout->setMargin( 3 ); 59 hboxLayout->setMargin( 3 );
60 hboxLayout->setSpacing( 0); 60 hboxLayout->setSpacing( 0);
61 61
62 QVBoxLayout *vboxButtons = new QVBoxLayout(this); 62 QVBoxLayout *vboxButtons = new QVBoxLayout(this);
63 upButton = new QPushButton( this ); 63 upButton = new QPushButton( this );
64 upButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); 64 upButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
65 upButton->setPixmap( Resource::loadPixmap( "up" ) ); 65 upButton->setPixmap( Resource::loadPixmap( "up" ) );
66 downButton = new QPushButton( this ); 66 downButton = new QPushButton( this );
67 downButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); 67 downButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
68 downButton->setPixmap( Resource::loadPixmap( "down" ) ); 68 downButton->setPixmap( Resource::loadPixmap( "down" ) );
69 vboxButtons->setSpacing( 2 ); 69 vboxButtons->setSpacing( 2 );
70 70
71 vboxButtons->addWidget( upButton ); 71 vboxButtons->addWidget( upButton );
72 vboxButtons->addWidget( downButton ); 72 vboxButtons->addWidget( downButton );
73 73
74 QVBoxLayout *vbox = new QVBoxLayout( this ); 74 QVBoxLayout *vbox = new QVBoxLayout( this );
75 QHBoxLayout *hbox = NULL; 75 QHBoxLayout *hbox = NULL;
76 76
77 slider = new QSlider( this ); 77 slider = new QSlider( this );
78 slider->setRange( 0, 100 ); 78 slider->setRange( 0, 100 );
79 slider->setTickmarks( QSlider::Both ); 79 slider->setTickmarks( QSlider::Both );
80 slider->setTickInterval( 20 ); 80 slider->setTickInterval( 20 );
81 slider->setFocusPolicy( QWidget::NoFocus ); 81 slider->setFocusPolicy( QWidget::NoFocus );
82 slider->setValue(cfg.readNumEntry("Volume")); 82 slider->setValue(cfg.readNumEntry("Volume"));
83 83
84 QVBoxLayout *sbox = new QVBoxLayout(this); 84 QVBoxLayout *sbox = new QVBoxLayout(this);
85 sbox->setMargin( 3 ); 85 sbox->setMargin( 3 );
86 sbox->setSpacing( 3 ); 86 sbox->setSpacing( 3 );
87 sbox->addWidget( new QLabel("Vol", this) , 0, Qt::AlignVCenter | Qt::AlignHCenter ); 87 sbox->addWidget( new QLabel("Vol", this) , 0, Qt::AlignVCenter | Qt::AlignHCenter );
88 sbox->addWidget( slider, 0, Qt::AlignVCenter | Qt::AlignHCenter ); 88 sbox->addWidget( slider, 0, Qt::AlignVCenter | Qt::AlignHCenter );
89 89
90 if (showMic == TRUE) { 90 if (showMic == TRUE) {
91 mic = new QSlider(this); 91 mic = new QSlider(this);
92 mic->setRange( 0, 100 ); 92 mic->setRange( 0, 100 );
93 mic->setTickmarks( QSlider::Both ); 93 mic->setTickmarks( QSlider::Both );
94 mic->setTickInterval( 20 ); 94 mic->setTickInterval( 20 );
95 mic->setFocusPolicy( QWidget::NoFocus ); 95 mic->setFocusPolicy( QWidget::NoFocus );
96 mic->setValue(cfg.readNumEntry("Mic")); 96 mic->setValue(cfg.readNumEntry("Mic"));
97 97
98 QVBoxLayout *mbox = new QVBoxLayout(this); 98 QVBoxLayout *mbox = new QVBoxLayout(this);
99 mbox->setMargin( 3 ); 99 mbox->setMargin( 3 );
100 mbox->setSpacing( 3 ); 100 mbox->setSpacing( 3 );
101 mbox->addWidget( new QLabel("Mic", this) , 0, Qt::AlignVCenter | Qt::AlignHCenter ); 101 mbox->addWidget( new QLabel("Mic", this) , 0, Qt::AlignVCenter | Qt::AlignHCenter );
102 mbox->addWidget( mic, 0, Qt::AlignVCenter | Qt::AlignHCenter ); 102 mbox->addWidget( mic, 0, Qt::AlignVCenter | Qt::AlignHCenter );
103 103
104 hbox = new QHBoxLayout( this ); 104 hbox = new QHBoxLayout( this );
105 hbox->setMargin( 3 ); 105 hbox->setMargin( 3 );
106 hbox->setSpacing( 3 ); 106 hbox->setSpacing( 3 );
107 hbox->addLayout( sbox, 1); 107 hbox->addLayout( sbox, 1);
108 hbox->addLayout( mbox, 1); 108 hbox->addLayout( mbox, 1);
109 } 109 }
110 110
111 muteBox = new QCheckBox( tr("Mute"), this ); 111 muteBox = new QCheckBox( tr("Mute"), this );
112 muteBox->setFocusPolicy( QWidget::NoFocus ); 112 muteBox->setFocusPolicy( QWidget::NoFocus );
113 113
114 vbox->setMargin( 3 ); 114 vbox->setMargin( 3 );
115 vbox->setSpacing( 0 ); 115 vbox->setSpacing( 0 );
116 if (showMic == TRUE) 116 if (showMic == TRUE)
117 vbox->addLayout( hbox, 1 ); 117 vbox->addLayout( hbox, 1 );
118 else 118 else
119 vbox->addLayout( sbox, 1); 119 vbox->addLayout( sbox, 1);
120 vbox->addWidget( muteBox, 0, Qt::AlignVCenter | Qt::AlignHCenter ); 120 vbox->addWidget( muteBox, 0, Qt::AlignVCenter | Qt::AlignHCenter );
121 121
122 hboxLayout->addLayout( vboxButtons ); 122 hboxLayout->addLayout( vboxButtons );
123 hboxLayout->addLayout(vbox); 123 hboxLayout->addLayout(vbox);
124 124
125 setFixedHeight( 120 ); 125 setFixedHeight( 120 );
126 setFixedWidth( sizeHint().width() ); 126 setFixedWidth( sizeHint().width() );
127 setFocusPolicy(QWidget::NoFocus); 127 setFocusPolicy(QWidget::NoFocus);
128 connect( upButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) ); 128 connect( upButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) );
129 connect( upButton, SIGNAL( released() ), this, SLOT( ButtonChanged() ) ); 129 connect( upButton, SIGNAL( released() ), this, SLOT( ButtonChanged() ) );
130 connect( downButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) ); 130 connect( downButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) );
131 connect( downButton, SIGNAL( released() ), this, SLOT( ButtonChanged() ) ); 131 connect( downButton, SIGNAL( released() ), this, SLOT( ButtonChanged() ) );
132 132
133 rateTimer = new QTimer(this); 133 rateTimer = new QTimer(this);
134 connect( rateTimer, SIGNAL( timeout() ), this, SLOT( rateTimerDone() ) ); 134 connect( rateTimer, SIGNAL( timeout() ), this, SLOT( rateTimerDone() ) );
135} 135}
136 136
137void VolumeControl::keyPressEvent( QKeyEvent *e) 137void VolumeControl::keyPressEvent( QKeyEvent *e)
138{ 138{
139 switch(e->key()) 139 switch(e->key())
140 { 140 {
141 case Key_Up: 141 case Key_Up:
142 slider->subtractStep(); 142 slider->subtractStep();
143 break; 143 break;
144 case Key_Down: 144 case Key_Down:
145 slider->addStep(); 145 slider->addStep();
146 break; 146 break;
147 case Key_Space: 147 case Key_Space:
148 muteBox->toggle(); 148 muteBox->toggle();
149 break; 149 break;
150 case Key_Escape: 150 case Key_Escape:
151 close(); 151 close();
152 break; 152 break;
153 } 153 }
154} 154}
155 155
156void VolumeControl::ButtonChanged() 156void VolumeControl::ButtonChanged()
157{ 157{
158 if ( upButton->isDown() || downButton->isDown() ) 158 if ( upButton->isDown() || downButton->isDown() )
159 { 159 {
160 rateTimerDone(); // Call it one time manually, otherwise it wont get 160 rateTimerDone(); // Call it one time manually, otherwise it wont get
161 // called at all when a button is pressed for a time 161 // called at all when a button is pressed for a time
162 // shorter than RATE_TIMER_INTERVAL. 162 // shorter than RATE_TIMER_INTERVAL.
163 rateTimer->start( RATE_TIMER_INTERVAL, false ); 163 rateTimer->start( RATE_TIMER_INTERVAL, false );
164 } 164 }
165 else 165 else
166 rateTimer->stop(); 166 rateTimer->stop();
167} 167}
168 168
169void VolumeControl::rateTimerDone() 169void VolumeControl::rateTimerDone()
170{ 170{
171 if ( upButton->isDown() ) 171 if ( upButton->isDown() )
172 slider->setValue( slider->value() - 2 ); 172 slider->setValue( slider->value() - 2 );
173 else // downButton->isDown() 173 else // downButton->isDown()
174 slider->setValue( slider->value() + 2 ); 174 slider->setValue( slider->value() + 2 );
175} 175}
176 176
177//=========================================================================== 177//===========================================================================
178 178
179VolumeApplet::VolumeApplet( QWidget *parent, const char *name ) 179VolumeApplet::VolumeApplet( QWidget *parent, const char *name )
180 : QWidget( parent, name ) 180 : QWidget( parent, name )
181{ 181{
182 Config cfg("Sound"); 182 Config cfg("Sound");
183 cfg.setGroup("System"); 183 cfg.setGroup("System");
184 184
185 setFixedHeight( 18 ); 185 setFixedHeight( 18 );
186 setFixedWidth( 14 ); 186 setFixedWidth( 14 );
187 187
188 volumePixmap = Resource::loadPixmap( "volume" ); 188 volumePixmap = Resource::loadPixmap( "volume" );
189 189
190 volumePercent = cfg.readNumEntry("Volume",50); 190 volumePercent = cfg.readNumEntry("Volume",50);
191 micPercent = cfg.readNumEntry("Mic", 50); 191 micPercent = cfg.readNumEntry("Mic", 50);
192 muted = FALSE; // ### read from pref 192 muted = FALSE; // ### read from pref
193 micMuted = FALSE; // ### read from pref 193 micMuted = FALSE; // ### read from pref
194 194
195 advancedTimer = new QTimer(this); 195 advancedTimer = new QTimer(this);
196 196
197 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); 197 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
198 connect( qApp, SIGNAL( micChanged(bool) ), this, SLOT ( micChanged(bool) ) ); 198 connect( qApp, SIGNAL( micChanged(bool) ), this, SLOT ( micChanged(bool) ) );
199 connect( advancedTimer, SIGNAL( timeout() ),this, SLOT( advVolControl()) ); 199 connect( advancedTimer, SIGNAL( timeout() ),this, SLOT( advVolControl()) );
200 200
201 writeSystemVolume(); 201 writeSystemVolume();
202 writeSystemMic(); 202 writeSystemMic();
203} 203}
204 204
205VolumeApplet::~VolumeApplet() 205VolumeApplet::~VolumeApplet()
206{ 206{
207} 207}
208 208
209void VolumeApplet::keyPressEvent ( QKeyEvent * e ) 209void VolumeApplet::keyPressEvent ( QKeyEvent * e )
210{ 210{
211 QString s; 211 QString s;
212 s.setNum(e->key()); 212 s.setNum(e->key());
213 qWarning(s); 213 qWarning(s);
214} 214}
215void VolumeApplet::mousePressEvent( QMouseEvent * ) 215void VolumeApplet::mousePressEvent( QMouseEvent * )
216{ 216{
217 advancedTimer->start( 750, TRUE ); 217 advancedTimer->start( 750, TRUE );
218} 218}
219 219
220void VolumeApplet::mouseReleaseEvent( QMouseEvent * ) 220void VolumeApplet::mouseReleaseEvent( QMouseEvent * )
221{ 221{
222 showVolControl(FALSE); 222 showVolControl(FALSE);
223} 223}
224 224
225void VolumeApplet::advVolControl() 225void VolumeApplet::advVolControl()
226{ 226{
227 showVolControl(TRUE); 227 showVolControl(TRUE);
228} 228}
229 229
230void VolumeApplet::showVolControl(bool showMic) 230void VolumeApplet::showVolControl(bool showMic)
231{ 231{
232 Config cfg("Sound"); 232 Config cfg("Sound");
233 cfg.setGroup("System"); 233 cfg.setGroup("System");
234 volumePercent = cfg.readNumEntry("Volume",50); 234 volumePercent = cfg.readNumEntry("Volume",50);
235 micPercent = cfg.readNumEntry("Mic", 50); 235 micPercent = cfg.readNumEntry("Mic", 50);
236 236 QString show = cfg.readEntry("ShowMic", "FALSE");
237 if(show == "TRUE") showMic = TRUE;
237 // Create a small volume control window to adjust the volume with 238 // Create a small volume control window to adjust the volume with
238 VolumeControl *vc = new VolumeControl(showMic); 239 VolumeControl *vc = new VolumeControl(showMic);
239 vc->slider->setValue( 100 - volumePercent ); 240 vc->slider->setValue( 100 - volumePercent );
240 if (showMic) 241 if (showMic)
241 { 242 {
242 vc->mic->setValue( 100 - micPercent ); 243 vc->mic->setValue( 100 - micPercent );
243 connect( vc->mic, SIGNAL( valueChanged( int ) ), this, SLOT( micMoved( int ) ) ); 244 connect( vc->mic, SIGNAL( valueChanged( int ) ), this, SLOT( micMoved( int ) ) );
244 } 245 }
245 246
246 vc->muteBox->setChecked( muted ); 247 vc->muteBox->setChecked( muted );
247 connect( vc->slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) ); 248 connect( vc->slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) );
248 connect( vc->muteBox, SIGNAL( toggled( bool ) ), this, SLOT( mute( bool ) ) ); 249 connect( vc->muteBox, SIGNAL( toggled( bool ) ), this, SLOT( mute( bool ) ) );
249 QPoint curPos = mapToGlobal( rect().topLeft() ); 250 QPoint curPos = mapToGlobal( rect().topLeft() );
250 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 120 ); 251 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 120 );
251 vc->show(); 252 vc->show();
252 253
253 advancedTimer->stop(); 254 advancedTimer->stop();
254} 255}
255 256
256void VolumeApplet::volumeChanged( bool nowMuted ) 257void VolumeApplet::volumeChanged( bool nowMuted )
257{ 258{
258 int previousVolume = volumePercent; 259 int previousVolume = volumePercent;
259 260
260 if ( !nowMuted ) 261 if ( !nowMuted )
261 readSystemVolume(); 262 readSystemVolume();
262 263
263 // Handle case where muting it toggled 264 // Handle case where muting it toggled
264 if ( muted != nowMuted ) { 265 if ( muted != nowMuted ) {
265 muted = nowMuted; 266 muted = nowMuted;
266 repaint( TRUE ); 267 repaint( TRUE );
267 return; 268 return;
268 } 269 }
269 270
270 // Avoid over repainting 271 // Avoid over repainting
271 if ( previousVolume != volumePercent ) 272 if ( previousVolume != volumePercent )
272 repaint( 2, height() - 3, width() - 4, 2, FALSE ); 273 repaint( 2, height() - 3, width() - 4, 2, FALSE );
273} 274}
274 275
275void VolumeApplet::micChanged( bool nowMuted ) 276void VolumeApplet::micChanged( bool nowMuted )
276{ 277{
277 if (!nowMuted) 278 if (!nowMuted)
278 readSystemMic(); 279 readSystemMic();
279 micMuted = nowMuted; 280 micMuted = nowMuted;
280} 281}
281 282
282void VolumeApplet::mute( bool toggled ) 283void VolumeApplet::mute( bool toggled )
283{ 284{
284 muted = toggled; 285 muted = toggled;
285 286
286 // clear if removing mute 287 // clear if removing mute
287 repaint( !toggled ); 288 repaint( !toggled );
288 writeSystemVolume(); 289 writeSystemVolume();
289} 290}
290 291
291 292
292void VolumeApplet::sliderMoved( int percent ) 293void VolumeApplet::sliderMoved( int percent )
293{ 294{
294 setVolume( 100 - percent ); 295 setVolume( 100 - percent );
295} 296}
296 297
297void VolumeApplet::micMoved( int percent ) 298void VolumeApplet::micMoved( int percent )
298{ 299{
299 setMic( 100 - percent ); 300 setMic( 100 - percent );
300} 301}
301 302
302void VolumeApplet::readSystemVolume() 303void VolumeApplet::readSystemVolume()
303{ 304{
304 Config cfg("Sound"); 305 Config cfg("Sound");
305 cfg.setGroup("System"); 306 cfg.setGroup("System");
306 volumePercent = cfg.readNumEntry("Volume"); 307 volumePercent = cfg.readNumEntry("Volume");
307} 308}
308 309
309void VolumeApplet::readSystemMic() 310void VolumeApplet::readSystemMic()
310{ 311{
311 Config cfg("Sound"); 312 Config cfg("Sound");
312 cfg.setGroup("System"); 313 cfg.setGroup("System");
313 micPercent = cfg.readNumEntry("Mic"); 314 micPercent = cfg.readNumEntry("Mic");
314} 315}
315 316
316void VolumeApplet::setVolume( int percent ) 317void VolumeApplet::setVolume( int percent )
317{ 318{
318 // clamp volume percent to be between 0 and 100 319 // clamp volume percent to be between 0 and 100
319 volumePercent = (percent < 0) ? 0 : ((percent > 100) ? 100 : percent); 320 volumePercent = (percent < 0) ? 0 : ((percent > 100) ? 100 : percent);
320 // repaint just the little volume rectangle 321 // repaint just the little volume rectangle
321 repaint( 2, height() - 3, width() - 4, 2, FALSE ); 322 repaint( 2, height() - 3, width() - 4, 2, FALSE );
322 writeSystemVolume(); 323 writeSystemVolume();
323} 324}
324 325
325void VolumeApplet::setMic( int percent ) 326void VolumeApplet::setMic( int percent )
326{ 327{
327 // clamp volume percent to be between 0 and 100 328 // clamp volume percent to be between 0 and 100
328 micPercent = (percent < 0) ? 0 : ((percent > 100) ? 100 : percent); 329 micPercent = (percent < 0) ? 0 : ((percent > 100) ? 100 : percent);
329 writeSystemMic(); 330 writeSystemMic();
330} 331}
331 332
332void VolumeApplet::writeSystemVolume() 333void VolumeApplet::writeSystemVolume()
333{ 334{
334 { 335 {
335 Config cfg("Sound"); 336 Config cfg("Sound");
336 cfg.setGroup("System"); 337 cfg.setGroup("System");
337 cfg.writeEntry("Volume",volumePercent); 338 cfg.writeEntry("Volume",volumePercent);
338 } 339 }
339#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 340#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
340 // Send notification that the volume has changed 341 // Send notification that the volume has changed
341 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; 342 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
342#endif 343#endif
343} 344}
344 345
345void VolumeApplet::writeSystemMic() 346void VolumeApplet::writeSystemMic()
346{ 347{
347 { 348 {
348 Config cfg("Sound"); 349 Config cfg("Sound");
349 cfg.setGroup("System"); 350 cfg.setGroup("System");
350 cfg.writeEntry("Mic",micPercent); 351 cfg.writeEntry("Mic",micPercent);
351 } 352 }
352#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 353#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
353 // Send notification that the volume has changed 354 // Send notification that the volume has changed
354 QCopEnvelope( "QPE/System", "micChange(bool)" ) << micMuted; 355 QCopEnvelope( "QPE/System", "micChange(bool)" ) << micMuted;
355#endif 356#endif
356} 357}
357 358
358void VolumeApplet::paintEvent( QPaintEvent* ) 359void VolumeApplet::paintEvent( QPaintEvent* )
359{ 360{
360 QPainter p(this); 361 QPainter p(this);
361 362
362 if (volumePixmap.isNull()) 363 if (volumePixmap.isNull())
363 volumePixmap = Resource::loadPixmap( "volume" ); 364 volumePixmap = Resource::loadPixmap( "volume" );
364 p.drawPixmap( 0, 1, volumePixmap ); 365 p.drawPixmap( 0, 1, volumePixmap );
365 p.setPen( darkGray ); 366 p.setPen( darkGray );
366 p.drawRect( 1, height() - 4, width() - 2, 4 ); 367 p.drawRect( 1, height() - 4, width() - 2, 4 );
367 368
368 int pixelsWide = volumePercent * (width() - 4) / 100; 369 int pixelsWide = volumePercent * (width() - 4) / 100;
369 p.fillRect( 2, height() - 3, pixelsWide, 2, red ); 370 p.fillRect( 2, height() - 3, pixelsWide, 2, red );
370 p.fillRect( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray ); 371 p.fillRect( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray );
371 372
372 if ( muted ) { 373 if ( muted ) {
373 p.setPen( red ); 374 p.setPen( red );
374 p.drawLine( 1, 2, width() - 2, height() - 5 ); 375 p.drawLine( 1, 2, width() - 2, height() - 5 );
375 p.drawLine( 1, 3, width() - 2, height() - 4 ); 376 p.drawLine( 1, 3, width() - 2, height() - 4 );
376 p.drawLine( width() - 2, 2, 1, height() - 5 ); 377 p.drawLine( width() - 2, 2, 1, height() - 5 );
377 p.drawLine( width() - 2, 3, 1, height() - 4 ); 378 p.drawLine( width() - 2, 3, 1, height() - 4 );
378 } 379 }
379} 380}