summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/desktop.cpp58
1 files changed, 32 insertions, 26 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp
index 7662e48..24dce73 100644
--- a/core/launcher/desktop.cpp
+++ b/core/launcher/desktop.cpp
@@ -101,200 +101,206 @@ class DesktopPowerAlerter : public QMessageBox
101public: 101public:
102 DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) 102 DesktopPowerAlerter( QWidget *parent, const char *name = 0 )
103 : QMessageBox( tr("Battery Status"), "Low Battery", 103 : QMessageBox( tr("Battery Status"), "Low Battery",
104 QMessageBox::Critical, 104 QMessageBox::Critical,
105 QMessageBox::Ok | QMessageBox::Default, 105 QMessageBox::Ok | QMessageBox::Default,
106 QMessageBox::NoButton, QMessageBox::NoButton, 106 QMessageBox::NoButton, QMessageBox::NoButton,
107 parent, name, FALSE ) 107 parent, name, FALSE )
108 { 108 {
109 currentPriority = INT_MAX; 109 currentPriority = INT_MAX;
110 alertCount = 0; 110 alertCount = 0;
111 } 111 }
112 112
113 void alert( const QString &text, int priority ); 113 void alert( const QString &text, int priority );
114 void hideEvent( QHideEvent * ); 114 void hideEvent( QHideEvent * );
115private: 115private:
116 int currentPriority; 116 int currentPriority;
117 int alertCount; 117 int alertCount;
118}; 118};
119 119
120void DesktopPowerAlerter::alert( const QString &text, int priority ) 120void DesktopPowerAlerter::alert( const QString &text, int priority )
121{ 121{
122 alertCount++; 122 alertCount++;
123 if ( alertCount < priority ) 123 if ( alertCount < priority )
124 return; 124 return;
125 if ( priority > currentPriority ) 125 if ( priority > currentPriority )
126 return; 126 return;
127 currentPriority = priority; 127 currentPriority = priority;
128 setText( text ); 128 setText( text );
129 show(); 129 show();
130} 130}
131 131
132 132
133void DesktopPowerAlerter::hideEvent( QHideEvent *e ) 133void DesktopPowerAlerter::hideEvent( QHideEvent *e )
134{ 134{
135 QMessageBox::hideEvent( e ); 135 QMessageBox::hideEvent( e );
136 alertCount = 0; 136 alertCount = 0;
137 currentPriority = INT_MAX; 137 currentPriority = INT_MAX;
138} 138}
139 139
140 140
141 141
142DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) 142DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType )
143 : QPEApplication( argc, argv, appType ) 143 : QPEApplication( argc, argv, appType )
144{ 144{
145 145
146 QTimer *t = new QTimer( this ); 146 QTimer *t = new QTimer( this );
147 connect( t, SIGNAL(timeout()), this, SLOT(psTimeout()) ); 147 connect( t, SIGNAL(timeout()), this, SLOT(psTimeout()) );
148 t->start( 10000 ); 148 t->start( 10000 );
149 ps = new PowerStatus; 149 ps = new PowerStatus;
150 pa = new DesktopPowerAlerter( 0 ); 150 pa = new DesktopPowerAlerter( 0 );
151 151
152 channel = new QCopChannel( "QPE/Desktop", this ); 152 channel = new QCopChannel( "QPE/Desktop", this );
153 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 153 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
154 this, SLOT(receive(const QCString&, const QByteArray&)) ); 154 this, SLOT(receive(const QCString&, const QByteArray&)) );
155} 155}
156 156
157 157
158DesktopApplication::~DesktopApplication() 158DesktopApplication::~DesktopApplication()
159{ 159{
160 delete ps; 160 delete ps;
161 delete pa; 161 delete pa;
162} 162}
163 163
164void DesktopApplication::receive( const QCString &msg, const QByteArray &data ) 164void DesktopApplication::receive( const QCString &msg, const QByteArray &data )
165{ 165{
166 QDataStream stream( data, IO_ReadOnly ); 166 QDataStream stream( data, IO_ReadOnly );
167 if (msg == "keyRegister(int key, QString channel, QString message)") 167 if (msg == "keyRegister(int key, QString channel, QString message)")
168 { 168 {
169 int k; 169 int k;
170 QString c, m; 170 QString c, m;
171 stream >> k; 171 stream >> k;
172 stream >> c; 172 stream >> c;
173 stream >> m; 173 stream >> m;
174 174
175 qWarning("KeyRegisterReceived: %i, %s, %s", k, (const char*)c, (const char *)m ); 175 qWarning("KeyRegisterReceived: %i, %s, %s", k, (const char*)c, (const char *)m );
176 keyRegisterList.append(QCopKeyRegister(k,c,m)); 176 keyRegisterList.append(QCopKeyRegister(k,c,m));
177 } 177 }
178 else if (msg == "suspend()"){ 178 else if (msg == "suspend()"){
179 emit power(); 179 emit power();
180 } 180 }
181 181
182} 182}
183 183
184enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown; 184enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown;
185 185
186#ifdef Q_WS_QWS 186#ifdef Q_WS_QWS
187bool DesktopApplication::qwsEventFilter( QWSEvent *e ) 187bool DesktopApplication::qwsEventFilter( QWSEvent *e )
188{ 188{
189 qpedesktop->checkMemory(); 189 qpedesktop->checkMemory();
190 190
191 if ( e->type == QWSEvent::Key ) { 191 if ( e->type == QWSEvent::Key ) {
192 QWSKeyEvent *ke = (QWSKeyEvent *)e; 192 QWSKeyEvent *ke = (QWSKeyEvent *)e;
193 if ( !loggedin && ke->simpleData.keycode != Key_F34 ) 193 if ( !loggedin && ke->simpleData.keycode != Key_F34 )
194 return TRUE; 194 return TRUE;
195 bool press = ke->simpleData.is_press; 195 bool press = ke->simpleData.is_press;
196 bool autoRepeat= ke->simpleData.is_auto_repeat; 196 bool autoRepeat= ke->simpleData.is_auto_repeat;
197 if (!keyRegisterList.isEmpty()) 197
198 { 198 /*
199 app that registers key/message to be sent back to the app, when it doesn't have focus,
200 when user presses key, unless keyboard has been requested from app.
201 will not send multiple repeats if user holds key
202 i.e. one shot
203
204 */
205 if (!keyRegisterList.isEmpty()) {
199 KeyRegisterList::Iterator it; 206 KeyRegisterList::Iterator it;
200 for( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) 207 for( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) {
201 { 208 if ((*it).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed()) {
202 if ((*it).getKeyCode() == ke->simpleData.keycode && !autoRepeat) { 209 if(press) qDebug("press"); else qDebug("release");
203 if(press) qDebug("press"); else qDebug("release"); 210 QCopEnvelope((*it).getChannel().utf8(), (*it).getMessage().utf8());
204 QCopEnvelope((*it).getChannel().utf8(), (*it).getMessage().utf8());
205 } 211 }
206 } 212 }
207 } 213 }
208 214
209 if ( !keyboardGrabbed() ) { 215 if ( !keyboardGrabbed() ) {
210 if ( ke->simpleData.keycode == Key_F9 ) { 216 if ( ke->simpleData.keycode == Key_F9 ) {
211 if ( press ) emit datebook(); 217 if ( press ) emit datebook();
212 return TRUE; 218 return TRUE;
213 } 219 }
214 if ( ke->simpleData.keycode == Key_F10 ) { 220 if ( ke->simpleData.keycode == Key_F10 ) {
215 if ( !press && cardSendTimer ) { 221 if ( !press && cardSendTimer ) {
216 emit contacts(); 222 emit contacts();
217 delete cardSendTimer; 223 delete cardSendTimer;
218 } else if ( press ) { 224 } else if ( press ) {
219 cardSendTimer = new QTimer(); 225 cardSendTimer = new QTimer();
220 cardSendTimer->start( 2000, TRUE ); 226 cardSendTimer->start( 2000, TRUE );
221 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); 227 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) );
222 } 228 }
223 return TRUE; 229 return TRUE;
224 } 230 }
225 /* menu key now opens application menu/toolbar 231 /* menu key now opens application menu/toolbar
226 if ( ke->simpleData.keycode == Key_F11 ) { 232 if ( ke->simpleData.keycode == Key_F11 ) {
227 if ( press ) emit menu(); 233 if ( press ) emit menu();
228 return TRUE; 234 return TRUE;
229 } 235 }
230 */ 236 */
231 if ( ke->simpleData.keycode == Key_F12 ) { 237 if ( ke->simpleData.keycode == Key_F12 ) {
232 while( activePopupWidget() ) 238 while( activePopupWidget() )
233 activePopupWidget()->close(); 239 activePopupWidget()->close();
234 if ( press ) emit launch(); 240 if ( press ) emit launch();
235 return TRUE; 241 return TRUE;
236 } 242 }
237 if ( ke->simpleData.keycode == Key_F13 ) { 243 if ( ke->simpleData.keycode == Key_F13 ) {
238 if ( press ) emit email(); 244 if ( press ) emit email();
239 return TRUE; 245 return TRUE;
240 } 246 }
241 } 247 }
242 248
243 if ( ke->simpleData.keycode == Key_F34 ) { 249 if ( ke->simpleData.keycode == Key_F34 ) {
244 if ( press ) emit power(); 250 if ( press ) emit power();
245 return TRUE; 251 return TRUE;
246 } 252 }
247// This was used for the iPAQ PowerButton 253// This was used for the iPAQ PowerButton
248// See main.cpp for new KeyboardFilter 254// See main.cpp for new KeyboardFilter
249// 255//
250// if ( ke->simpleData.keycode == Key_SysReq ) { 256// if ( ke->simpleData.keycode == Key_SysReq ) {
251// if ( press ) emit power(); 257// if ( press ) emit power();
252// return TRUE; 258// return TRUE;
253// } 259// }
254 if ( ke->simpleData.keycode == Key_F35 ) { 260 if ( ke->simpleData.keycode == Key_F35 ) {
255 if ( press ) emit backlight(); 261 if ( press ) emit backlight();
256 return TRUE; 262 return TRUE;
257 } 263 }
258 if ( ke->simpleData.keycode == Key_F32 ) { 264 if ( ke->simpleData.keycode == Key_F32 ) {
259 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); 265 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" );
260 return TRUE; 266 return TRUE;
261 } 267 }
262 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { 268 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) {
263 if ( press ) emit symbol(); 269 if ( press ) emit symbol();
264 return TRUE; 270 return TRUE;
265 } 271 }
266 if ( ke->simpleData.keycode == Key_NumLock ) { 272 if ( ke->simpleData.keycode == Key_NumLock ) {
267 if ( press ) emit numLockStateToggle(); 273 if ( press ) emit numLockStateToggle();
268 } 274 }
269 if ( ke->simpleData.keycode == Key_CapsLock ) { 275 if ( ke->simpleData.keycode == Key_CapsLock ) {
270 if ( press ) emit capsLockStateToggle(); 276 if ( press ) emit capsLockStateToggle();
271 } 277 }
272 if (( press && !autoRepeat ) || ( !press && autoRepeat )) 278 if (( press && !autoRepeat ) || ( !press && autoRepeat ))
273 qpedesktop->keyClick(); 279 qpedesktop->keyClick();
274 } else { 280 } else {
275 if ( e->type == QWSEvent::Mouse ) { 281 if ( e->type == QWSEvent::Mouse ) {
276 QWSMouseEvent *me = (QWSMouseEvent *)e; 282 QWSMouseEvent *me = (QWSMouseEvent *)e;
277 static bool up = TRUE; 283 static bool up = TRUE;
278 if ( me->simpleData.state&LeftButton ) { 284 if ( me->simpleData.state&LeftButton ) {
279 if ( up ) { 285 if ( up ) {
280 up = FALSE; 286 up = FALSE;
281 qpedesktop->screenClick(); 287 qpedesktop->screenClick();
282 } 288 }
283 } else { 289 } else {
284 up = TRUE; 290 up = TRUE;
285 } 291 }
286 } 292 }
287 } 293 }
288 294
289 return QPEApplication::qwsEventFilter( e ); 295 return QPEApplication::qwsEventFilter( e );
290} 296}
291#endif 297#endif
292 298
293void DesktopApplication::psTimeout() 299void DesktopApplication::psTimeout()
294{ 300{
295 qpedesktop->checkMemory(); // in case no events are being generated 301 qpedesktop->checkMemory(); // in case no events are being generated
296 302
297 *ps = PowerStatusManager::readStatus(); 303 *ps = PowerStatusManager::readStatus();
298 304
299 if ( (ps->batteryStatus() == PowerStatus::VeryLow ) ) { 305 if ( (ps->batteryStatus() == PowerStatus::VeryLow ) ) {
300 pa->alert( tr( "Battery is running very low." ), 6 ); 306 pa->alert( tr( "Battery is running very low." ), 6 );
@@ -657,128 +663,128 @@ void Desktop::styleChange( QStyle &s )
657} 663}
658 664
659void DesktopApplication::shutdown() 665void DesktopApplication::shutdown()
660{ 666{
661 if ( type() != GuiServer ) 667 if ( type() != GuiServer )
662 return; 668 return;
663 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); 669 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose );
664 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)), 670 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)),
665 this, SLOT(shutdown(ShutdownImpl::Type)) ); 671 this, SLOT(shutdown(ShutdownImpl::Type)) );
666 sd->showMaximized(); 672 sd->showMaximized();
667} 673}
668 674
669void DesktopApplication::shutdown( ShutdownImpl::Type t ) 675void DesktopApplication::shutdown( ShutdownImpl::Type t )
670{ 676{
671 switch ( t ) { 677 switch ( t ) {
672 case ShutdownImpl::ShutdownSystem: 678 case ShutdownImpl::ShutdownSystem:
673 execlp("shutdown", "shutdown", "-h", "now", (void*)0); 679 execlp("shutdown", "shutdown", "-h", "now", (void*)0);
674 break; 680 break;
675 case ShutdownImpl::RebootSystem: 681 case ShutdownImpl::RebootSystem:
676 execlp("shutdown", "shutdown", "-r", "now", (void*)0); 682 execlp("shutdown", "shutdown", "-r", "now", (void*)0);
677 break; 683 break;
678 case ShutdownImpl::RestartDesktop: 684 case ShutdownImpl::RestartDesktop:
679 restart(); 685 restart();
680 break; 686 break;
681 case ShutdownImpl::TerminateDesktop: 687 case ShutdownImpl::TerminateDesktop:
682 prepareForTermination(FALSE); 688 prepareForTermination(FALSE);
683 quit(); 689 quit();
684 break; 690 break;
685 } 691 }
686} 692}
687 693
688void DesktopApplication::restart() 694void DesktopApplication::restart()
689{ 695{
690 prepareForTermination(TRUE); 696 prepareForTermination(TRUE);
691 697
692#ifdef Q_WS_QWS 698#ifdef Q_WS_QWS
693 for ( int fd = 3; fd < 100; fd++ ) 699 for ( int fd = 3; fd < 100; fd++ )
694 close( fd ); 700 close( fd );
695#if defined(QT_DEMO_SINGLE_FLOPPY) 701#if defined(QT_DEMO_SINGLE_FLOPPY)
696 execl( "/sbin/init", "qpe", 0 ); 702 execl( "/sbin/init", "qpe", 0 );
697#elif defined(QT_QWS_CASSIOPEIA) 703#elif defined(QT_QWS_CASSIOPEIA)
698 execl( "/bin/sh", "sh", 0 ); 704 execl( "/bin/sh", "sh", 0 );
699#else 705#else
700 execl( (qpeDir()+"/bin/qpe").latin1(), "qpe", 0 ); 706 execl( (qpeDir()+"/bin/qpe").latin1(), "qpe", 0 );
701#endif 707#endif
702 exit(1); 708 exit(1);
703#endif 709#endif
704} 710}
705 711
706void Desktop::startTransferServer() 712void Desktop::startTransferServer()
707{ 713{
708 // start qcop bridge server 714 // start qcop bridge server
709 qcopBridge = new QCopBridge( 4243 ); 715 qcopBridge = new QCopBridge( 4243 );
710 if ( !qcopBridge->ok() ) { 716 if ( !qcopBridge->ok() ) {
711 delete qcopBridge; 717 delete qcopBridge;
712 qcopBridge = 0; 718 qcopBridge = 0;
713 } 719 }
714 // start transfer server 720 // start transfer server
715 transferServer = new TransferServer( 4242 ); 721 transferServer = new TransferServer( 4242 );
716 if ( !transferServer->ok() ) { 722 if ( !transferServer->ok() ) {
717 delete transferServer; 723 delete transferServer;
718 transferServer = 0; 724 transferServer = 0;
719 } 725 }
720 if ( !transferServer || !qcopBridge ) 726 if ( !transferServer || !qcopBridge )
721 startTimer( 2000 ); 727 startTimer( 2000 );
722} 728}
723 729
724void Desktop::timerEvent( QTimerEvent *e ) 730void Desktop::timerEvent( QTimerEvent *e )
725{ 731{
726 killTimer( e->timerId() ); 732 killTimer( e->timerId() );
727 startTransferServer(); 733 startTransferServer();
728} 734}
729 735
730void Desktop::terminateServers() 736void Desktop::terminateServers()
731{ 737{
732 delete transferServer; 738 delete transferServer;
733 delete qcopBridge; 739 delete qcopBridge;
734 transferServer = 0; 740 transferServer = 0;
735 qcopBridge = 0; 741 qcopBridge = 0;
736} 742}
737 743
738void Desktop::rereadVolumes() 744void Desktop::rereadVolumes()
739{ 745{
740 Config cfg("qpe"); 746 Config cfg("qpe");
741 cfg.setGroup("Volume"); 747 cfg.setGroup("Volume");
742 touchclick = cfg.readBoolEntry("TouchSound"); 748 touchclick = cfg.readBoolEntry("TouchSound");
743 keyclick = cfg.readBoolEntry("KeySound"); 749 keyclick = cfg.readBoolEntry("KeySound");
744 alarmsound = cfg.readBoolEntry("AlarmSound"); 750 alarmsound = cfg.readBoolEntry("AlarmSound");
745// Config cfg("Sound"); 751// Config cfg("Sound");
746// cfg.setGroup("System"); 752// cfg.setGroup("System");
747// touchclick = cfg.readBoolEntry("Touch"); 753// touchclick = cfg.readBoolEntry("Touch");
748// keyclick = cfg.readBoolEntry("Key"); 754// keyclick = cfg.readBoolEntry("Key");
749} 755}
750 756
751void Desktop::keyClick() 757void Desktop::keyClick()
752{ 758{
753 if ( keyclick ) 759 if ( keyclick )
754 ODevice::inst ( )-> keySound ( ); 760 ODevice::inst ( )-> keySound ( );
755} 761}
756 762
757void Desktop::screenClick() 763void Desktop::screenClick()
758{ 764{
759 if ( touchclick ) 765 if ( touchclick )
760 ODevice::inst ( )-> touchSound ( ); 766 ODevice::inst ( )-> touchSound ( );
761} 767}
762 768
763void Desktop::soundAlarm() 769void Desktop::soundAlarm()
764{ 770{
765 if ( qpedesktop-> alarmsound ) 771 if ( qpedesktop-> alarmsound )
766 ODevice::inst ( )-> alarmSound ( ); 772 ODevice::inst ( )-> alarmSound ( );
767} 773}
768 774
769bool Desktop::eventFilter( QObject *, QEvent *ev ) 775bool Desktop::eventFilter( QObject *, QEvent *ev )
770{ 776{
771 if ( ev-> type ( ) == QEvent::KeyPress ) { 777 if ( ev-> type ( ) == QEvent::KeyPress ) {
772 QKeyEvent *ke = (QKeyEvent *) ev; 778 QKeyEvent *ke = (QKeyEvent *) ev;
773 if ( ke-> key ( ) == Qt::Key_F11 ) { // menu key 779 if ( ke-> key ( ) == Qt::Key_F11 ) { // menu key
774 QWidget *active = qApp-> activeWindow ( ); 780 QWidget *active = qApp-> activeWindow ( );
775 781
776 if ( active && active-> isPopup ( )) 782 if ( active && active-> isPopup ( ))
777 active->close(); 783 active->close();
778 784
779 raiseMenu ( ); 785 raiseMenu ( );
780 return true; 786 return true;
781 } 787 }
782 } 788 }
783 return false; 789 return false;
784} 790}