summaryrefslogtreecommitdiff
authorjeremy <jeremy>2002-02-15 21:29:03 (UTC)
committer jeremy <jeremy>2002-02-15 21:29:03 (UTC)
commita176c76090a3ba74f350d2066d6762c9b9a7eb3b (patch) (unidiff)
treeb2dd448bd0fa8bd3d1e1730b44427f5c2f5f052f
parentb0768575b7bc1e4fe477d37a49cccc7e3d92bf85 (diff)
downloadopie-a176c76090a3ba74f350d2066d6762c9b9a7eb3b.zip
opie-a176c76090a3ba74f350d2066d6762c9b9a7eb3b.tar.gz
opie-a176c76090a3ba74f350d2066d6762c9b9a7eb3b.tar.bz2
Added checking for an empty keyRegisterList for increased performance :)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/desktop.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp
index ce99bad..a00fae2 100644
--- a/core/launcher/desktop.cpp
+++ b/core/launcher/desktop.cpp
@@ -95,238 +95,236 @@ bool Desktop::screenLocked()
95 */ 95 */
96class DesktopPowerAlerter : public QMessageBox 96class DesktopPowerAlerter : public QMessageBox
97{ 97{
98public: 98public:
99 DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) 99 DesktopPowerAlerter( QWidget *parent, const char *name = 0 )
100 : QMessageBox( tr("Battery Status"), "Low Battery", 100 : QMessageBox( tr("Battery Status"), "Low Battery",
101 QMessageBox::Critical, 101 QMessageBox::Critical,
102 QMessageBox::Ok | QMessageBox::Default, 102 QMessageBox::Ok | QMessageBox::Default,
103 QMessageBox::NoButton, QMessageBox::NoButton, 103 QMessageBox::NoButton, QMessageBox::NoButton,
104 parent, name, FALSE ) 104 parent, name, FALSE )
105 { 105 {
106 currentPriority = INT_MAX; 106 currentPriority = INT_MAX;
107 alertCount = 0; 107 alertCount = 0;
108 } 108 }
109 109
110 void alert( const QString &text, int priority ); 110 void alert( const QString &text, int priority );
111 void hideEvent( QHideEvent * ); 111 void hideEvent( QHideEvent * );
112private: 112private:
113 int currentPriority; 113 int currentPriority;
114 int alertCount; 114 int alertCount;
115}; 115};
116 116
117void DesktopPowerAlerter::alert( const QString &text, int priority ) 117void DesktopPowerAlerter::alert( const QString &text, int priority )
118{ 118{
119 alertCount++; 119 alertCount++;
120 if ( alertCount < priority ) 120 if ( alertCount < priority )
121 return; 121 return;
122 if ( priority > currentPriority ) 122 if ( priority > currentPriority )
123 return; 123 return;
124 currentPriority = priority; 124 currentPriority = priority;
125 setText( text ); 125 setText( text );
126 show(); 126 show();
127} 127}
128 128
129 129
130void DesktopPowerAlerter::hideEvent( QHideEvent *e ) 130void DesktopPowerAlerter::hideEvent( QHideEvent *e )
131{ 131{
132 QMessageBox::hideEvent( e ); 132 QMessageBox::hideEvent( e );
133 alertCount = 0; 133 alertCount = 0;
134 currentPriority = INT_MAX; 134 currentPriority = INT_MAX;
135} 135}
136 136
137 137
138 138
139DesktopApplication::DesktopApplication( int& argc, char **argv, Type t ) 139DesktopApplication::DesktopApplication( int& argc, char **argv, Type t )
140 : QPEApplication( argc, argv, t ) 140 : QPEApplication( argc, argv, t )
141{ 141{
142 142
143 QTimer *t = new QTimer( this ); 143 QTimer *t = new QTimer( this );
144 connect( t, SIGNAL(timeout()), this, SLOT(psTimeout()) ); 144 connect( t, SIGNAL(timeout()), this, SLOT(psTimeout()) );
145 t->start( 10000 ); 145 t->start( 10000 );
146 ps = new PowerStatus; 146 ps = new PowerStatus;
147 pa = new DesktopPowerAlerter( 0 ); 147 pa = new DesktopPowerAlerter( 0 );
148 148
149 channel = new QCopChannel( "QPE/Desktop", this ); 149 channel = new QCopChannel( "QPE/Desktop", this );
150 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 150 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
151 this, SLOT(receive(const QCString&, const QByteArray&)) ); 151 this, SLOT(receive(const QCString&, const QByteArray&)) );
152} 152}
153 153
154 154
155DesktopApplication::~DesktopApplication() 155DesktopApplication::~DesktopApplication()
156{ 156{
157 delete ps; 157 delete ps;
158 delete pa; 158 delete pa;
159} 159}
160 160
161void DesktopApplication::receive( const QCString &msg, const QByteArray &data ) 161void DesktopApplication::receive( const QCString &msg, const QByteArray &data )
162{ 162{
163 QDataStream stream( data, IO_ReadOnly ); 163 QDataStream stream( data, IO_ReadOnly );
164 if (msg == "keyRegister(int key, QString channel, QString message)") 164 if (msg == "keyRegister(int key, QString channel, QString message)")
165 { 165 {
166 int k; 166 int k;
167 QString c, m; 167 QString c, m;
168 168
169 stream >> k; 169 stream >> k;
170 stream >> c; 170 stream >> c;
171 stream >> m; 171 stream >> m;
172 172
173 qWarning("KeyRegisterRecieved: %i, %s, %s", k, (const char*)c, (const char *)m); 173 qWarning("KeyRegisterRecieved: %i, %s, %s", k, (const char*)c, (const char *)m);
174 keyRegisterList.append(QCopKeyRegister(k,c,m)); 174 keyRegisterList.append(QCopKeyRegister(k,c,m));
175 } 175 }
176} 176}
177 177
178enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown; 178enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown;
179 179
180#ifdef Q_WS_QWS 180#ifdef Q_WS_QWS
181bool DesktopApplication::qwsEventFilter( QWSEvent *e ) 181bool DesktopApplication::qwsEventFilter( QWSEvent *e )
182{ 182{
183 qpedesktop->checkMemory(); 183 qpedesktop->checkMemory();
184 184
185 if ( e->type == QWSEvent::Key ) { 185 if ( e->type == QWSEvent::Key ) {
186 QWSKeyEvent *ke = (QWSKeyEvent *)e; 186 QWSKeyEvent *ke = (QWSKeyEvent *)e;
187 if ( !loggedin && ke->simpleData.keycode != Key_F34 ) 187 if ( !loggedin && ke->simpleData.keycode != Key_F34 )
188 return TRUE; 188 return TRUE;
189 bool press = ke->simpleData.is_press; 189 bool press = ke->simpleData.is_press;
190 190
191 KeyRegisterList::Iterator it; 191 if (!keyRegisterList.isEmpty())
192 for( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it )
193 { 192 {
194 if ((*it).getKeyCode() == ke->simpleData.keycode) 193 KeyRegisterList::Iterator it;
195 QCopEnvelope((*it).getChannel().utf8(), (*it).getMessage().utf8()); 194 for( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it )
195 {
196 if ((*it).getKeyCode() == ke->simpleData.keycode)
197 QCopEnvelope((*it).getChannel().utf8(), (*it).getMessage().utf8());
198 }
196 } 199 }
197 200
198 if ( !keyboardGrabbed() ) { 201 if ( !keyboardGrabbed() ) {
199 if ( ke->simpleData.keycode == Key_F9 ) { 202 if ( ke->simpleData.keycode == Key_F9 ) {
200 if ( press ) emit datebook(); 203 if ( press ) emit datebook();
201 return TRUE; 204 return TRUE;
202 } 205 }
203 if ( ke->simpleData.keycode == Key_F10 ) { 206 if ( ke->simpleData.keycode == Key_F10 ) {
204 if ( !press && cardSendTimer ) { 207 if ( !press && cardSendTimer ) {
205 emit contacts(); 208 emit contacts();
206 delete cardSendTimer; 209 delete cardSendTimer;
207 } else if ( press ) { 210 } else if ( press ) {
208 cardSendTimer = new QTimer(); 211 cardSendTimer = new QTimer();
209 cardSendTimer->start( 2000, TRUE ); 212 cardSendTimer->start( 2000, TRUE );
210 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); 213 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) );
211 } 214 }
212 return TRUE; 215 return TRUE;
213 } 216 }
214 /* menu key now opens application menu/toolbar 217 /* menu key now opens application menu/toolbar
215 if ( ke->simpleData.keycode == Key_F11 ) { 218 if ( ke->simpleData.keycode == Key_F11 ) {
216 if ( press ) emit menu(); 219 if ( press ) emit menu();
217 return TRUE; 220 return TRUE;
218 } 221 }
219 */ 222 */
220 if ( ke->simpleData.keycode == Key_F12 ) { 223 if ( ke->simpleData.keycode == Key_F12 ) {
221 while( activePopupWidget() ) 224 while( activePopupWidget() )
222 activePopupWidget()->close(); 225 activePopupWidget()->close();
223 if ( press ) emit launch(); 226 if ( press ) emit launch();
224 return TRUE; 227 return TRUE;
225 } 228 }
226 if ( ke->simpleData.keycode == Key_F13 ) { 229 if ( ke->simpleData.keycode == Key_F13 ) {
227 if ( press ) emit email(); 230 if ( press ) emit email();
228 return TRUE; 231 return TRUE;
229 } 232 }
230 } 233 }
231 /* 234
232 if ( ke->simpleData.keycode == 4096 ) {
233 QCopEnvelope e("QPE/VMemo", "toggleRecord()");
234 return TRUE;
235 }
236 */
237 if ( ke->simpleData.keycode == Key_F34 ) { 235 if ( ke->simpleData.keycode == Key_F34 ) {
238 if ( press ) emit power(); 236 if ( press ) emit power();
239 return TRUE; 237 return TRUE;
240 } 238 }
241 if ( ke->simpleData.keycode == Key_F35 ) { 239 if ( ke->simpleData.keycode == Key_F35 ) {
242 if ( press ) emit backlight(); 240 if ( press ) emit backlight();
243 return TRUE; 241 return TRUE;
244 } 242 }
245 if ( ke->simpleData.keycode == Key_F32 ) { 243 if ( ke->simpleData.keycode == Key_F32 ) {
246 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); 244 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" );
247 return TRUE; 245 return TRUE;
248 } 246 }
249 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { 247 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) {
250 if ( press ) emit symbol(); 248 if ( press ) emit symbol();
251 return TRUE; 249 return TRUE;
252 } 250 }
253 if ( ke->simpleData.keycode == Key_NumLock ) { 251 if ( ke->simpleData.keycode == Key_NumLock ) {
254 if ( press ) emit numLockStateToggle(); 252 if ( press ) emit numLockStateToggle();
255 } 253 }
256 if ( ke->simpleData.keycode == Key_CapsLock ) { 254 if ( ke->simpleData.keycode == Key_CapsLock ) {
257 if ( press ) emit capsLockStateToggle(); 255 if ( press ) emit capsLockStateToggle();
258 } 256 }
259 if ( press ) 257 if ( press )
260 qpedesktop->keyClick(); 258 qpedesktop->keyClick();
261 } else { 259 } else {
262 if ( e->type == QWSEvent::Mouse ) { 260 if ( e->type == QWSEvent::Mouse ) {
263 QWSMouseEvent *me = (QWSMouseEvent *)e; 261 QWSMouseEvent *me = (QWSMouseEvent *)e;
264 static bool up = TRUE; 262 static bool up = TRUE;
265 if ( me->simpleData.state&LeftButton ) { 263 if ( me->simpleData.state&LeftButton ) {
266 if ( up ) { 264 if ( up ) {
267 up = FALSE; 265 up = FALSE;
268 qpedesktop->screenClick(); 266 qpedesktop->screenClick();
269 } 267 }
270 } else { 268 } else {
271 up = TRUE; 269 up = TRUE;
272 } 270 }
273 } 271 }
274 } 272 }
275 273
276 return QPEApplication::qwsEventFilter( e ); 274 return QPEApplication::qwsEventFilter( e );
277} 275}
278#endif 276#endif
279 277
280void DesktopApplication::psTimeout() 278void DesktopApplication::psTimeout()
281{ 279{
282 qpedesktop->checkMemory(); // in case no events are being generated 280 qpedesktop->checkMemory(); // in case no events are being generated
283 281
284 *ps = PowerStatusManager::readStatus(); 282 *ps = PowerStatusManager::readStatus();
285 283
286 if ( (ps->batteryStatus() == PowerStatus::VeryLow ) ) { 284 if ( (ps->batteryStatus() == PowerStatus::VeryLow ) ) {
287 pa->alert( tr( "Battery is running very low." ), 6 ); 285 pa->alert( tr( "Battery is running very low." ), 6 );
288 } 286 }
289 287
290 if ( ps->batteryStatus() == PowerStatus::Critical ) { 288 if ( ps->batteryStatus() == PowerStatus::Critical ) {
291 pa->alert( tr( "Battery level is critical!\n" 289 pa->alert( tr( "Battery level is critical!\n"
292 "Keep power off until power restored!" ), 1 ); 290 "Keep power off until power restored!" ), 1 );
293 } 291 }
294 292
295 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) { 293 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) {
296 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 ); 294 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 );
297 } 295 }
298} 296}
299 297
300 298
301void DesktopApplication::sendCard() 299void DesktopApplication::sendCard()
302{ 300{
303 delete cardSendTimer; 301 delete cardSendTimer;
304 cardSendTimer = 0; 302 cardSendTimer = 0;
305 QString card = getenv("HOME"); 303 QString card = getenv("HOME");
306 card += "/Applications/addressbook/businesscard.vcf"; 304 card += "/Applications/addressbook/businesscard.vcf";
307 305
308 if ( QFile::exists( card ) ) { 306 if ( QFile::exists( card ) ) {
309 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)"); 307 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)");
310 QString mimetype = "text/x-vCard"; 308 QString mimetype = "text/x-vCard";
311 e << tr("business card") << card << mimetype; 309 e << tr("business card") << card << mimetype;
312 } 310 }
313} 311}
314 312
315#if defined(QPE_HAVE_MEMALERTER) 313#if defined(QPE_HAVE_MEMALERTER)
316QPE_MEMALERTER_IMPL 314QPE_MEMALERTER_IMPL
317#endif 315#endif
318 316
319#if defined(CUSTOM_SOUND_IMPL) 317#if defined(CUSTOM_SOUND_IMPL)
320CUSTOM_SOUND_IMPL 318CUSTOM_SOUND_IMPL
321#endif 319#endif
322 320
323//=========================================================================== 321//===========================================================================
324 322
325Desktop::Desktop() : 323Desktop::Desktop() :
326 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), 324 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ),
327 qcopBridge( 0 ), 325 qcopBridge( 0 ),
328 transferServer( 0 ), 326 transferServer( 0 ),
329 packageSlave( 0 ) 327 packageSlave( 0 )
330{ 328{
331#ifdef CUSTOM_SOUND_INIT 329#ifdef CUSTOM_SOUND_INIT
332 CUSTOM_SOUND_INIT; 330 CUSTOM_SOUND_INIT;