summaryrefslogtreecommitdiff
path: root/library
authorsandman <sandman>2002-10-13 16:06:24 (UTC)
committer sandman <sandman>2002-10-13 16:06:24 (UTC)
commit92aabc976e4a8e58d7db0bba42cb8d0f3ebe8982 (patch) (unidiff)
treee16b9cd59d51c8f1e159d830cb5c18ec4cd9420a /library
parentcb816d85c54242f8958ff77fba334b43be0dcb3d (diff)
downloadopie-92aabc976e4a8e58d7db0bba42cb8d0f3ebe8982.zip
opie-92aabc976e4a8e58d7db0bba42cb8d0f3ebe8982.tar.gz
opie-92aabc976e4a8e58d7db0bba42cb8d0f3ebe8982.tar.bz2
reformated with astyle (this may not be everybodys prefered style, but IMHO
it's better than the mess before..)
Diffstat (limited to 'library') (more/less context) (show whitespace changes)
-rw-r--r--library/qpeapplication.cpp189
1 files changed, 133 insertions, 56 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index f65f3ab..2432b65 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -77,80 +77,96 @@
77#include "alarmserver.h" 77#include "alarmserver.h"
78#include "applnk.h" 78#include "applnk.h"
79#include "qpemenubar.h" 79#include "qpemenubar.h"
80#include "textcodecinterface.h" 80#include "textcodecinterface.h"
81#include "imagecodecinterface.h" 81#include "imagecodecinterface.h"
82 82
83#include <unistd.h> 83#include <unistd.h>
84#include <sys/file.h> 84#include <sys/file.h>
85#include <sys/ioctl.h> 85#include <sys/ioctl.h>
86#include <sys/soundcard.h> 86#include <sys/soundcard.h>
87 87
88 88
89class QPEApplicationData { 89class QPEApplicationData
90{
90public: 91public:
91 QPEApplicationData() : presstimer( 0 ), presswidget( 0 ), rightpressed( FALSE ), 92 QPEApplicationData() : presstimer( 0 ), presswidget( 0 ), rightpressed( FALSE ),
92 kbgrabber( 0 ), kbregrab( FALSE ), notbusysent( FALSE ), preloaded( FALSE ), 93 kbgrabber( 0 ), kbregrab( FALSE ), notbusysent( FALSE ), preloaded( FALSE ),
93 forceshow( FALSE ), nomaximize( FALSE ), qpe_main_widget( 0 ), 94 forceshow( FALSE ), nomaximize( FALSE ), qpe_main_widget( 0 ),
94 keep_running( TRUE ) 95 keep_running( TRUE )
95 { 96 {
96 qcopq.setAutoDelete( TRUE ); 97 qcopq.setAutoDelete( TRUE );
97 } 98 }
98 99
99 int presstimer; 100 int presstimer;
100 QWidget* presswidget; 101 QWidget* presswidget;
101 QPoint presspos; 102 QPoint presspos;
102 bool rightpressed : 1; // AEH why not use uint foobar :1; if it's tt style -zecke 103bool rightpressed :
104 1; // AEH why not use uint foobar :1; if it's tt style -zecke
103 int kbgrabber; 105 int kbgrabber;
104 bool kbregrab : 1; 106bool kbregrab :
105 bool notbusysent : 1; 107 1;
108bool notbusysent :
109 1;
106 QString appName; 110 QString appName;
107 struct QCopRec { 111 struct QCopRec
112 {
108 QCopRec( const QCString &ch, const QCString &msg, 113 QCopRec( const QCString &ch, const QCString &msg,
109 const QByteArray &d ) : 114 const QByteArray &d ) :
110 channel( ch ), message( msg ), data( d ) { } 115 channel( ch ), message( msg ), data( d )
116 { }
111 117
112 QCString channel; 118 QCString channel;
113 QCString message; 119 QCString message;
114 QByteArray data; 120 QByteArray data;
115 }; 121 };
116 bool preloaded : 1; 122bool preloaded :
117 bool forceshow : 1; 123 1;
118 bool nomaximize : 1; 124bool forceshow :
125 1;
126bool nomaximize :
127 1;
119 QWidget* qpe_main_widget; 128 QWidget* qpe_main_widget;
120 bool keep_running : 1; 129bool keep_running :
130 1;
121 QList<QCopRec> qcopq; 131 QList<QCopRec> qcopq;
122 132
123 void enqueueQCop( const QCString &ch, const QCString &msg, 133 void enqueueQCop( const QCString &ch, const QCString &msg,
124 const QByteArray &data ) 134 const QByteArray &data )
125 { 135 {
126 qcopq.append( new QCopRec( ch, msg, data ) ); 136 qcopq.append( new QCopRec( ch, msg, data ) );
127 } 137 }
128 void sendQCopQ() { 138 void sendQCopQ()
139 {
129 QCopRec * r; 140 QCopRec * r;
130#ifndef QT_NO_COP 141#ifndef QT_NO_COP
142
131 for ( QListIterator<QCopRec> it( qcopq ); ( r = it.current() ); ++it ) 143 for ( QListIterator<QCopRec> it( qcopq ); ( r = it.current() ); ++it )
132 QCopChannel::sendLocally( r->channel, r->message, r->data ); 144 QCopChannel::sendLocally( r->channel, r->message, r->data );
133#endif 145#endif
146
134 qcopq.clear(); 147 qcopq.clear();
135 } 148 }
136 static void show_mx(QWidget* mw, bool nomaximize) { 149 static void show_mx(QWidget* mw, bool nomaximize)
150 {
137 if ( mw->layout() && mw->inherits("QDialog") ) { 151 if ( mw->layout() && mw->inherits("QDialog") ) {
138 QPEApplication::showDialog((QDialog*)mw,nomaximize); 152 QPEApplication::showDialog((QDialog*)mw,nomaximize);
139 } else { 153 }
154 else {
140#ifdef Q_WS_QWS 155#ifdef Q_WS_QWS
141 if ( !nomaximize ) 156 if ( !nomaximize )
142 mw->showMaximized(); 157 mw->showMaximized();
143 else 158 else
144#endif 159#endif
160
145 mw->show(); 161 mw->show();
146 } 162 }
147 } 163 }
148 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 164 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
149 { 165 {
150 /* 166 /*
151 // This works but disable it for now until it is safe to apply 167 // This works but disable it for now until it is safe to apply
152 // What is does is scan the .desktop files of all the apps for 168 // What is does is scan the .desktop files of all the apps for
153 // the applnk that has the corresponding argv[0] as this program 169 // the applnk that has the corresponding argv[0] as this program
154 // then it uses the name stored in the .desktop file as the caption 170 // then it uses the name stored in the .desktop file as the caption
155 // for the main widget. This saves duplicating translations for 171 // for the main widget. This saves duplicating translations for
156 // the app name in the program and in the .desktop files. 172 // the app name in the program and in the .desktop files.
@@ -166,82 +182,88 @@ public:
166 } 182 }
167 */ 183 */
168 return FALSE; 184 return FALSE;
169 } 185 }
170 186
171 187
172 void show(QWidget* mw, bool nomax) 188 void show(QWidget* mw, bool nomax)
173 { 189 {
174 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 190 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
175 nomaximize = nomax; 191 nomaximize = nomax;
176 qpe_main_widget = mw; 192 qpe_main_widget = mw;
177#ifndef QT_NO_COP 193#ifndef QT_NO_COP
194
178 sendQCopQ(); 195 sendQCopQ();
179#endif 196#endif
197
180 if ( preloaded ) { 198 if ( preloaded ) {
181 if(forceshow) 199 if(forceshow)
182 show_mx(mw,nomax); 200 show_mx(mw,nomax);
183 } else if ( keep_running ) { 201 }
202 else if ( keep_running ) {
184 show_mx(mw,nomax); 203 show_mx(mw,nomax);
185 } 204 }
186 } 205 }
187 206
188 void loadTextCodecs() 207 void loadTextCodecs()
189 { 208 {
190 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; 209 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
191 QDir dir( path, "lib*.so" ); 210 QDir dir( path, "lib*.so" );
192 QStringList list = dir.entryList(); 211 QStringList list = dir.entryList();
193 QStringList::Iterator it; 212 QStringList::Iterator it;
194 for ( it = list.begin(); it != list.end(); ++it ) { 213 for ( it = list.begin(); it != list.end(); ++it ) {
195 TextCodecInterface *iface = 0; 214 TextCodecInterface *iface = 0;
196 QLibrary *lib = new QLibrary( path + "/" + *it ); 215 QLibrary *lib = new QLibrary( path + "/" + *it );
197 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 216 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
198 QValueList<int> mibs = iface->mibEnums(); 217 QValueList<int> mibs = iface->mibEnums();
199 for (QValueList<int>::ConstIterator i=mibs.begin(); i!=mibs.end(); ++i) { 218 for (QValueList<int>::ConstIterator i=mibs.begin(); i!=mibs.end(); ++i) {
200 (void)iface->createForMib(*i); 219 (void)iface->createForMib(*i);
201 // ### it exists now; need to remember if we can delete it 220 // ### it exists now; need to remember if we can delete it
202 } 221 }
203 } else { 222 }
223 else {
204 lib->unload(); 224 lib->unload();
205 delete lib; 225 delete lib;
206 } 226 }
207 } 227 }
208 } 228 }
209 229
210 void loadImageCodecs() 230 void loadImageCodecs()
211 { 231 {
212 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; 232 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
213 QDir dir( path, "lib*.so" ); 233 QDir dir( path, "lib*.so" );
214 QStringList list = dir.entryList(); 234 QStringList list = dir.entryList();
215 QStringList::Iterator it; 235 QStringList::Iterator it;
216 for ( it = list.begin(); it != list.end(); ++it ) { 236 for ( it = list.begin(); it != list.end(); ++it ) {
217 ImageCodecInterface *iface = 0; 237 ImageCodecInterface *iface = 0;
218 QLibrary *lib = new QLibrary( path + "/" + *it ); 238 QLibrary *lib = new QLibrary( path + "/" + *it );
219 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 239 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
220 QStringList formats = iface->keys(); 240 QStringList formats = iface->keys();
221 for (QStringList::ConstIterator i=formats.begin(); i!=formats.end(); ++i) { 241 for (QStringList::ConstIterator i=formats.begin(); i!=formats.end(); ++i) {
222 (void)iface->installIOHandler(*i); 242 (void)iface->installIOHandler(*i);
223 // ### it exists now; need to remember if we can delete it 243 // ### it exists now; need to remember if we can delete it
224 } 244 }
225 } else { 245 }
246 else {
226 lib->unload(); 247 lib->unload();
227 delete lib; 248 delete lib;
228 } 249 }
229 } 250 }
230 } 251 }
231 QString styleName; 252 QString styleName;
232 QString decorationName; 253 QString decorationName;
233}; 254};
234 255
235class ResourceMimeFactory : public QMimeSourceFactory { 256class ResourceMimeFactory : public QMimeSourceFactory
257{
236public: 258public:
237 ResourceMimeFactory() 259 ResourceMimeFactory()
238 { 260 {
239 setFilePath( Global::helpPath() ); 261 setFilePath( Global::helpPath() );
240 setExtensionType( "html", "text/html;charset=UTF-8" ); 262 setExtensionType( "html", "text/html;charset=UTF-8" );
241 } 263 }
242 264
243 const QMimeSource* data( const QString& abs_name ) const 265 const QMimeSource* data( const QString& abs_name ) const
244 { 266 {
245 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 267 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
246 if ( !r ) { 268 if ( !r ) {
247 int sl = abs_name.length(); 269 int sl = abs_name.length();
@@ -439,29 +461,31 @@ static void setMic( int t = 0, int percent = -1 )
439QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 461QPEApplication::QPEApplication( int & argc, char **argv, Type t )
440 : QApplication( argc, argv, t ) 462 : QApplication( argc, argv, t )
441{ 463{
442 d = new QPEApplicationData; 464 d = new QPEApplicationData;
443 d->loadTextCodecs(); 465 d->loadTextCodecs();
444 d->loadImageCodecs(); 466 d->loadImageCodecs();
445 int dw = desktop() ->width(); 467 int dw = desktop() ->width();
446 qWarning( "Width %d", dw ); 468 qWarning( "Width %d", dw );
447 if ( dw < 200 ) { 469 if ( dw < 200 ) {
448 setFont( QFont( "helvetica", 8 ) ); 470 setFont( QFont( "helvetica", 8 ) );
449 AppLnk::setSmallIconSize( 10 ); 471 AppLnk::setSmallIconSize( 10 );
450 AppLnk::setBigIconSize( 28 ); 472 AppLnk::setBigIconSize( 28 );
451 }else if ( dw > 600 ) { 473 }
474 else if ( dw > 600 ) {
452 setFont( QFont( "helvetica", 12 ) ); 475 setFont( QFont( "helvetica", 12 ) );
453 AppLnk::setSmallIconSize( 24 ); 476 AppLnk::setSmallIconSize( 24 );
454 AppLnk::setBigIconSize( 48 ); 477 AppLnk::setBigIconSize( 48 );
455 }else if ( dw > 200 ) { 478 }
479 else if ( dw > 200 ) {
456 setFont( QFont( "helvetica", 12 ) ); 480 setFont( QFont( "helvetica", 12 ) );
457 AppLnk::setSmallIconSize( 16 ); 481 AppLnk::setSmallIconSize( 16 );
458 AppLnk::setBigIconSize( 32 ); 482 AppLnk::setBigIconSize( 32 );
459 } 483 }
460 484
461 485
462 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 486 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
463 487
464 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 488 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
465#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 489#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
466 490
467 QString qcopfn( "/tmp/qcop-msg-" ); 491 QString qcopfn( "/tmp/qcop-msg-" );
@@ -538,29 +562,31 @@ QPEApplication::QPEApplication( int & argc, char **argv, Type t )
538 else 562 else
539 delete trans; 563 delete trans;
540 564
541 trans = new QTranslator( this ); 565 trans = new QTranslator( this );
542 tfn = qpeDir() + "/i18n/" + lang + "/" + d->appName + ".qm"; 566 tfn = qpeDir() + "/i18n/" + lang + "/" + d->appName + ".qm";
543 if ( trans->load( tfn ) ) 567 if ( trans->load( tfn ) )
544 installTranslator( trans ); 568 installTranslator( trans );
545 else 569 else
546 delete trans; 570 delete trans;
547 571
548 //###language/font hack; should look it up somewhere 572 //###language/font hack; should look it up somewhere
549#ifdef QWS 573#ifdef QWS
574
550 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 575 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
551 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 576 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
552 setFont( fn ); 577 setFont( fn );
553 } 578 }
554#endif 579#endif
580
555 } 581 }
556#endif 582#endif
557 583
558 applyStyle(); 584 applyStyle();
559 585
560 if ( type() == GuiServer ) { 586 if ( type() == GuiServer ) {
561 setVolume(); 587 setVolume();
562 } 588 }
563 589
564 installEventFilter( this ); 590 installEventFilter( this );
565 591
566 QPEMenuToolFocusManager::initialize(); 592 QPEMenuToolFocusManager::initialize();
@@ -612,51 +638,60 @@ void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
612 if ( mode == Normal ) { 638 if ( mode == Normal ) {
613 inputMethodDict->remove 639 inputMethodDict->remove
614 ( w ); 640 ( w );
615 } 641 }
616 else { 642 else {
617 inputMethodDict->insert( w, ( void* ) mode ); 643 inputMethodDict->insert( w, ( void* ) mode );
618 } 644 }
619} 645}
620 646
621class HackDialog : public QDialog 647class HackDialog : public QDialog
622{ 648{
623public: 649public:
624 void acceptIt() { accept(); } 650 void acceptIt()
625 void rejectIt() { reject(); } 651 {
652 accept();
653 }
654 void rejectIt()
655 {
656 reject();
657 }
626}; 658};
627 659
628 660
629void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) 661void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
630{ 662{
631 // specialised actions for certain widgets. May want to 663 // specialised actions for certain widgets. May want to
632 // add more stuff here. 664 // add more stuff here.
633 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) 665 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
634 && activePopupWidget() ->parentWidget() 666 && activePopupWidget() ->parentWidget()
635 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) 667 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
636 key = Qt::Key_Return; 668 key = Qt::Key_Return;
637 669
638 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) 670 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
639 key = Qt::Key_Return; 671 key = Qt::Key_Return;
640 672
641#ifdef QWS 673#ifdef QWS
674
642 ke->simpleData.keycode = key; 675 ke->simpleData.keycode = key;
643#endif 676#endif
644} 677}
645 678
646class HackWidget : public QWidget 679class HackWidget : public QWidget
647{ 680{
648public: 681public:
649 bool needsOk() 682 bool needsOk()
650 { return ( getWState() & WState_Reserved1 ); } 683 {
684 return ( getWState() & WState_Reserved1 );
685 }
651}; 686};
652 687
653/*! 688/*!
654 \internal 689 \internal
655*/ 690*/
656 691
657#ifdef QWS 692#ifdef QWS
658bool QPEApplication::qwsEventFilter( QWSEvent * e ) 693bool QPEApplication::qwsEventFilter( QWSEvent * e )
659{ 694{
660 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 695 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
661 if ( qApp->type() != QApplication::GuiServer ) { 696 if ( qApp->type() != QApplication::GuiServer ) {
662 QCopEnvelope e( "QPE/System", "notBusy(QString)" ); 697 QCopEnvelope e( "QPE/System", "notBusy(QString)" );
@@ -698,25 +733,26 @@ bool QPEApplication::qwsEventFilter( QWSEvent * e )
698 } 733 }
699 else if ( ( ( HackWidget * ) active ) ->needsOk() ) { 734 else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
700 QSignal s; 735 QSignal s;
701 s.connect( active, SLOT( accept() ) ); 736 s.connect( active, SLOT( accept() ) );
702 s.activate(); 737 s.activate();
703 } 738 }
704 else { 739 else {
705 // do the same as with the select key: Map to the default action of the widget: 740 // do the same as with the select key: Map to the default action of the widget:
706 mapToDefaultAction( ke, Qt::Key_Return ); 741 mapToDefaultAction( ke, Qt::Key_Return );
707 } 742 }
708 } 743 }
709 } 744 }
710 } else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 745 }
746 else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
711 // Use special "select" key to do whatever default action a widget has 747 // Use special "select" key to do whatever default action a widget has
712 mapToDefaultAction( ke, Qt::Key_Space ); 748 mapToDefaultAction( ke, Qt::Key_Space );
713 } 749 }
714 else if ( ke->simpleData.keycode == Qt::Key_Escape && 750 else if ( ke->simpleData.keycode == Qt::Key_Escape &&
715 ke->simpleData.is_press ) { 751 ke->simpleData.is_press ) {
716 // Escape key closes app if focus on toplevel 752 // Escape key closes app if focus on toplevel
717 QWidget * active = activeWindow(); 753 QWidget * active = activeWindow();
718 if ( active && active->testWFlags( WType_TopLevel ) && 754 if ( active && active->testWFlags( WType_TopLevel ) &&
719 ( int ) active->winId() == ke->simpleData.window && 755 ( int ) active->winId() == ke->simpleData.window &&
720 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { 756 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
721 if ( active->inherits( "QDialog" ) ) { 757 if ( active->inherits( "QDialog" ) ) {
722 HackDialog * d = ( HackDialog * ) active; 758 HackDialog * d = ( HackDialog * ) active;
@@ -842,28 +878,32 @@ int QPEApplication::defaultRotation()
842 878
843/*! 879/*!
844 \internal 880 \internal
845*/ 881*/
846void QPEApplication::setDefaultRotation( int r ) 882void QPEApplication::setDefaultRotation( int r )
847{ 883{
848 if ( qApp->type() == GuiServer ) { 884 if ( qApp->type() == GuiServer ) {
849 deforient = r; 885 deforient = r;
850 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 886 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 );
851 Config config("qpe"); 887 Config config("qpe");
852 config.setGroup( "Rotation" ); 888 config.setGroup( "Rotation" );
853 config.writeEntry( "Screen", getenv("QWS_DISPLAY") ); 889 config.writeEntry( "Screen", getenv("QWS_DISPLAY") );
854 } else { 890 }
891 else {
855#ifndef QT_NO_COP 892#ifndef QT_NO_COP
856 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); e << r; } 893 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" );
894 e << r;
895 }
857#endif 896#endif
897
858 } 898 }
859} 899}
860 900
861/*! 901/*!
862 \internal 902 \internal
863*/ 903*/
864void QPEApplication::applyStyle() 904void QPEApplication::applyStyle()
865{ 905{
866 Config config( "qpe" ); 906 Config config( "qpe" );
867 907
868 config.setGroup( "Appearance" ); 908 config.setGroup( "Appearance" );
869 909
@@ -901,145 +941,165 @@ void QPEApplication::applyStyle()
901 // Font 941 // Font
902 QString ff = config.readEntry( "FontFamily", font().family() ); 942 QString ff = config.readEntry( "FontFamily", font().family() );
903 int fs = config.readNumEntry( "FontSize", font().pointSize() ); 943 int fs = config.readNumEntry( "FontSize", font().pointSize() );
904 setFont( QFont(ff,fs) ); 944 setFont( QFont(ff,fs) );
905} 945}
906 946
907void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) 947void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data )
908{ 948{
909#ifdef Q_WS_QWS 949#ifdef Q_WS_QWS
910 QDataStream stream( data, IO_ReadOnly ); 950 QDataStream stream( data, IO_ReadOnly );
911 if ( msg == "applyStyle()" ) { 951 if ( msg == "applyStyle()" ) {
912 applyStyle(); 952 applyStyle();
913 } else if ( msg == "setDefaultRotation(int)" ) { 953 }
954 else if ( msg == "setDefaultRotation(int)" ) {
914 if ( type() == GuiServer ) { 955 if ( type() == GuiServer ) {
915 int r; 956 int r;
916 stream >> r; 957 stream >> r;
917 setDefaultRotation( r ); 958 setDefaultRotation( r );
918 } 959 }
919 } else if ( msg == "shutdown()" ) { 960 }
961 else if ( msg == "shutdown()" ) {
920 if ( type() == GuiServer ) 962 if ( type() == GuiServer )
921 shutdown(); 963 shutdown();
922 } else if ( msg == "quit()" ) { 964 }
965 else if ( msg == "quit()" ) {
923 if ( type() != GuiServer ) 966 if ( type() != GuiServer )
924 tryQuit(); 967 tryQuit();
925 } else if ( msg == "forceQuit()" ) { 968 }
969 else if ( msg == "forceQuit()" ) {
926 if ( type() != GuiServer ) 970 if ( type() != GuiServer )
927 quit(); 971 quit();
928 } else if ( msg == "restart()" ) { 972 }
973 else if ( msg == "restart()" ) {
929 if ( type() == GuiServer ) 974 if ( type() == GuiServer )
930 restart(); 975 restart();
931 } else if ( msg == "grabKeyboard(QString)" ) { 976 }
977 else if ( msg == "grabKeyboard(QString)" ) {
932 QString who; 978 QString who;
933 stream >> who; 979 stream >> who;
934 if ( who.isEmpty() ) 980 if ( who.isEmpty() )
935 d->kbgrabber = 0; 981 d->kbgrabber = 0;
936 else if ( who != d->appName ) 982 else if ( who != d->appName )
937 d->kbgrabber = 1; 983 d->kbgrabber = 1;
938 else 984 else
939 d->kbgrabber = 2; 985 d->kbgrabber = 2;
940 } else if ( msg == "language(QString)" ) { 986 }
987 else if ( msg == "language(QString)" ) {
941 if ( type() == GuiServer ) { 988 if ( type() == GuiServer ) {
942 QString l; 989 QString l;
943 stream >> l; 990 stream >> l;
944 QString cl = getenv( "LANG" ); 991 QString cl = getenv( "LANG" );
945 if ( cl != l ) { 992 if ( cl != l ) {
946 if ( l.isNull() ) 993 if ( l.isNull() )
947 unsetenv( "LANG" ); 994 unsetenv( "LANG" );
948 else 995 else
949 setenv( "LANG", l.latin1(), 1 ); 996 setenv( "LANG", l.latin1(), 1 );
950 restart(); 997 restart();
951 } 998 }
952 } 999 }
953 } else if ( msg == "timeChange(QString)" ) { 1000 }
1001 else if ( msg == "timeChange(QString)" ) {
954 QString t; 1002 QString t;
955 stream >> t; 1003 stream >> t;
956 if ( t.isNull() ) 1004 if ( t.isNull() )
957 unsetenv( "TZ" ); 1005 unsetenv( "TZ" );
958 else 1006 else
959 setenv( "TZ", t.latin1(), 1 ); 1007 setenv( "TZ", t.latin1(), 1 );
960 // emit the signal so everyone else knows... 1008 // emit the signal so everyone else knows...
961 emit timeChanged(); 1009 emit timeChanged();
962 } else if ( msg == "execute(QString)" ) { 1010 }
1011 else if ( msg == "execute(QString)" ) {
963 if ( type() == GuiServer ) { 1012 if ( type() == GuiServer ) {
964 QString t; 1013 QString t;
965 stream >> t; 1014 stream >> t;
966 Global::execute( t ); 1015 Global::execute( t );
967 } 1016 }
968 } else if ( msg == "execute(QString,QString)" ) { 1017 }
1018 else if ( msg == "execute(QString,QString)" ) {
969 if ( type() == GuiServer ) { 1019 if ( type() == GuiServer ) {
970 QString t, d; 1020 QString t, d;
971 stream >> t >> d; 1021 stream >> t >> d;
972 Global::execute( t, d ); 1022 Global::execute( t, d );
973 } 1023 }
974 } else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { 1024 }
1025 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) {
975 if ( type() == GuiServer ) { 1026 if ( type() == GuiServer ) {
976 QDateTime when; 1027 QDateTime when;
977 QCString channel, message; 1028 QCString channel, message;
978 int data; 1029 int data;
979 stream >> when >> channel >> message >> data; 1030 stream >> when >> channel >> message >> data;
980 AlarmServer::addAlarm( when, channel, message, data ); 1031 AlarmServer::addAlarm( when, channel, message, data );
981 } 1032 }
982 } else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { 1033 }
1034 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) {
983 if ( type() == GuiServer ) { 1035 if ( type() == GuiServer ) {
984 QDateTime when; 1036 QDateTime when;
985 QCString channel, message; 1037 QCString channel, message;
986 int data; 1038 int data;
987 stream >> when >> channel >> message >> data; 1039 stream >> when >> channel >> message >> data;
988 AlarmServer::deleteAlarm( when, channel, message, data ); 1040 AlarmServer::deleteAlarm( when, channel, message, data );
989 } 1041 }
990 } else if ( msg == "clockChange(bool)" ) { 1042 }
1043 else if ( msg == "clockChange(bool)" ) {
991 int tmp; 1044 int tmp;
992 stream >> tmp; 1045 stream >> tmp;
993 emit clockChanged( tmp ); 1046 emit clockChanged( tmp );
994 } else if ( msg == "weekChange(bool)" ) { 1047 }
1048 else if ( msg == "weekChange(bool)" ) {
995 int tmp; 1049 int tmp;
996 stream >> tmp; 1050 stream >> tmp;
997 emit weekChanged( tmp ); 1051 emit weekChanged( tmp );
998 } else if ( msg == "setDateFormat(DateFormat)" ) { 1052 }
1053 else if ( msg == "setDateFormat(DateFormat)" ) {
999 DateFormat tmp; 1054 DateFormat tmp;
1000 stream >> tmp; 1055 stream >> tmp;
1001 emit dateFormatChanged( tmp ); 1056 emit dateFormatChanged( tmp );
1002 } else if ( msg == "setVolume(int,int)" ) { 1057 }
1058 else if ( msg == "setVolume(int,int)" ) {
1003 int t, v; 1059 int t, v;
1004 stream >> t >> v; 1060 stream >> t >> v;
1005 setVolume( t, v ); 1061 setVolume( t, v );
1006 emit volumeChanged( muted ); 1062 emit volumeChanged( muted );
1007 } else if ( msg == "volumeChange(bool)" ) { 1063 }
1064 else if ( msg == "volumeChange(bool)" ) {
1008 stream >> muted; 1065 stream >> muted;
1009 setVolume(); 1066 setVolume();
1010 emit volumeChanged( muted ); 1067 emit volumeChanged( muted );
1011 } else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1068 }
1069 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1012 int t, v; 1070 int t, v;
1013 stream >> t >> v; 1071 stream >> t >> v;
1014 setMic( t, v ); 1072 setMic( t, v );
1015 emit micChanged( micMuted ); 1073 emit micChanged( micMuted );
1016 } else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1074 }
1075 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1017 stream >> micMuted; 1076 stream >> micMuted;
1018 setMic(); 1077 setMic();
1019 emit micChanged( micMuted ); 1078 emit micChanged( micMuted );
1020 } 1079 }
1021#endif 1080#endif
1022} 1081}
1023 1082
1024/*! 1083/*!
1025 \internal 1084 \internal
1026*/ 1085*/
1027bool QPEApplication::raiseAppropriateWindow() 1086bool QPEApplication::raiseAppropriateWindow()
1028{ 1087{
1029 bool r=FALSE; 1088 bool r=FALSE;
1030 // ########## raise()ing main window should raise and set active 1089 // ########## raise()ing main window should raise and set active
1031 // ########## it and then all childen. This belongs in Qt/Embedded 1090 // ########## it and then all childen. This belongs in Qt/Embedded
1032 QWidget *top = d->qpe_main_widget; 1091 QWidget *top = d->qpe_main_widget;
1033 if ( !top ) top =mainWidget(); 1092 if ( !top )
1093 top = mainWidget();
1034 if ( top && d->keep_running ) { 1094 if ( top && d->keep_running ) {
1035 if ( top->isVisible() ) 1095 if ( top->isVisible() )
1036 r = TRUE; 1096 r = TRUE;
1037 else if (d->preloaded) { 1097 else if (d->preloaded) {
1038 // We are preloaded and not visible.. pretend we just started.. 1098 // We are preloaded and not visible.. pretend we just started..
1039 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1099 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1040 e << d->appName; 1100 e << d->appName;
1041 } 1101 }
1042 1102
1043 d->show_mx(top,d->nomaximize); 1103 d->show_mx(top,d->nomaximize);
1044 top->raise(); 1104 top->raise();
1045 top->setActiveWindow(); 1105 top->setActiveWindow();
@@ -1056,69 +1116,79 @@ bool QPEApplication::raiseAppropriateWindow()
1056 } 1116 }
1057 r = FALSE; 1117 r = FALSE;
1058 } 1118 }
1059 return r; 1119 return r;
1060} 1120}
1061 1121
1062void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) 1122void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data)
1063{ 1123{
1064#ifdef Q_WS_QWS 1124#ifdef Q_WS_QWS
1065 1125
1066 if ( msg == "quit()" ) { 1126 if ( msg == "quit()" ) {
1067 tryQuit(); 1127 tryQuit();
1068 } else if ( msg == "quitIfInvisible()" ) { 1128 }
1129 else if ( msg == "quitIfInvisible()" ) {
1069 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) 1130 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() )
1070 quit(); 1131 quit();
1071 } else if ( msg == "close()" ) { 1132 }
1133 else if ( msg == "close()" ) {
1072 hideOrQuit(); 1134 hideOrQuit();
1073 } else if ( msg == "disablePreload()" ) { 1135 }
1136 else if ( msg == "disablePreload()" ) {
1074 d->preloaded = FALSE; 1137 d->preloaded = FALSE;
1075 d->keep_running = TRUE; 1138 d->keep_running = TRUE;
1076 /* so that quit will quit */ 1139 /* so that quit will quit */
1077 } else if ( msg == "enablePreload()" ) { 1140 }
1141 else if ( msg == "enablePreload()" ) {
1078 if (d->qpe_main_widget) 1142 if (d->qpe_main_widget)
1079 d->preloaded = TRUE; 1143 d->preloaded = TRUE;
1080 d->keep_running = TRUE; 1144 d->keep_running = TRUE;
1081 /* so next quit won't quit */ 1145 /* so next quit won't quit */
1082 } else if ( msg == "raise()" ) { 1146 }
1147 else if ( msg == "raise()" ) {
1083 d->keep_running = TRUE; 1148 d->keep_running = TRUE;
1084 d->notbusysent = FALSE; 1149 d->notbusysent = FALSE;
1085 raiseAppropriateWindow(); 1150 raiseAppropriateWindow();
1086 // Tell the system we're still chugging along... 1151 // Tell the system we're still chugging along...
1087 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1152 QCopEnvelope e("QPE/System", "appRaised(QString)");
1088 e << d->appName; 1153 e << d->appName;
1089 } else if ( msg == "flush()" ) { 1154 }
1155 else if ( msg == "flush()" ) {
1090 emit flush(); 1156 emit flush();
1091 // we need to tell the desktop 1157 // we need to tell the desktop
1092 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); 1158 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
1093 e << d->appName; 1159 e << d->appName;
1094 } else if ( msg == "reload()" ) { 1160 }
1161 else if ( msg == "reload()" ) {
1095 emit reload(); 1162 emit reload();
1096 } else if ( msg == "setDocument(QString)" ) { 1163 }
1164 else if ( msg == "setDocument(QString)" ) {
1097 d->keep_running = TRUE; 1165 d->keep_running = TRUE;
1098 QDataStream stream( data, IO_ReadOnly ); 1166 QDataStream stream( data, IO_ReadOnly );
1099 QString doc; 1167 QString doc;
1100 stream >> doc; 1168 stream >> doc;
1101 QWidget *mw = mainWidget(); 1169 QWidget *mw = mainWidget();
1102 if ( !mw ) 1170 if ( !mw )
1103 mw = d->qpe_main_widget; 1171 mw = d->qpe_main_widget;
1104 if ( mw ) 1172 if ( mw )
1105 Global::setDocument( mw, doc ); 1173 Global::setDocument( mw, doc );
1106 } else if ( msg == "nextView()" ) { 1174 }
1175 else if ( msg == "nextView()" ) {
1107 qDebug("got nextView()"); 1176 qDebug("got nextView()");
1108/* 1177/*
1109 if ( raiseAppropriateWindow() ) 1178 if ( raiseAppropriateWindow() )
1110*/ 1179*/
1111 emit appMessage( msg, data); 1180 emit appMessage( msg, data);
1112 } else { 1181 }
1182 else {
1113 emit appMessage( msg, data); 1183 emit appMessage( msg, data);
1114 } 1184 }
1115 1185
1116#endif 1186#endif
1117} 1187}
1118 1188
1119 1189
1120/*! 1190/*!
1121 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1191 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1122 consider passing TRUE for \a nomaximize rather than the default FALSE. 1192 consider passing TRUE for \a nomaximize rather than the default FALSE.
1123 1193
1124 \sa showMainDocumentWidget() 1194 \sa showMainDocumentWidget()
@@ -1399,25 +1469,26 @@ bool QPEApplication::eventFilter( QObject *o, QEvent *e )
1399 d->rightpressed = FALSE; 1469 d->rightpressed = FALSE;
1400 return TRUE; // don't send the real Left release 1470 return TRUE; // don't send the real Left release
1401 } 1471 }
1402 } 1472 }
1403 break; 1473 break;
1404 default: 1474 default:
1405 break; 1475 break;
1406 } 1476 }
1407 break; 1477 break;
1408 default: 1478 default:
1409 ; 1479 ;
1410 } 1480 }
1411 }else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1481 }
1482 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1412 QKeyEvent *ke = (QKeyEvent *)e; 1483 QKeyEvent *ke = (QKeyEvent *)e;
1413 if ( ke->key() == Key_Enter ) { 1484 if ( ke->key() == Key_Enter ) {
1414 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { 1485 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
1415 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', 1486 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
1416 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); 1487 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
1417 return TRUE; 1488 return TRUE;
1418 } 1489 }
1419 } 1490 }
1420 } 1491 }
1421 return FALSE; 1492 return FALSE;
1422} 1493}
1423 1494
@@ -1457,108 +1528,114 @@ bool QPEApplication::keyboardGrabbed() const
1457/*! 1528/*!
1458 Reverses the effect of grabKeyboard(). This is called automatically 1529 Reverses the effect of grabKeyboard(). This is called automatically
1459 on program exit. 1530 on program exit.
1460*/ 1531*/
1461void QPEApplication::ungrabKeyboard() 1532void QPEApplication::ungrabKeyboard()
1462{ 1533{
1463 QPEApplicationData * d = ( ( QPEApplication* ) qApp ) ->d; 1534 QPEApplicationData * d = ( ( QPEApplication* ) qApp ) ->d;
1464 if ( d->kbgrabber == 2 ) { 1535 if ( d->kbgrabber == 2 ) {
1465#ifndef QT_NO_COP 1536#ifndef QT_NO_COP
1466 QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" ); 1537 QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" );
1467 e << QString::null; 1538 e << QString::null;
1468#endif 1539#endif
1540
1469 d->kbregrab = FALSE; 1541 d->kbregrab = FALSE;
1470 d->kbgrabber = 0; 1542 d->kbgrabber = 0;
1471 } 1543 }
1472} 1544}
1473 1545
1474/*! 1546/*!
1475 Grabs the physical keyboard keys, e.g. the application's launching 1547 Grabs the physical keyboard keys, e.g. the application's launching
1476 keys. Instead of launching applications when these keys are pressed 1548 keys. Instead of launching applications when these keys are pressed
1477 the signals emitted are sent to this application instead. Some games 1549 the signals emitted are sent to this application instead. Some games
1478 programs take over the launch keys in this way to make interaction 1550 programs take over the launch keys in this way to make interaction
1479 easier. 1551 easier.
1480 1552
1481 \sa ungrabKeyboard() 1553 \sa ungrabKeyboard()
1482*/ 1554*/
1483void QPEApplication::grabKeyboard() 1555void QPEApplication::grabKeyboard()
1484{ 1556{
1485 QPEApplicationData * d = ( ( QPEApplication* ) qApp ) ->d; 1557 QPEApplicationData * d = ( ( QPEApplication* ) qApp ) ->d;
1486 if ( qApp->type() == QApplication::GuiServer ) 1558 if ( qApp->type() == QApplication::GuiServer )
1487 d->kbgrabber = 0; 1559 d->kbgrabber = 0;
1488 else { 1560 else {
1489#ifndef QT_NO_COP 1561#ifndef QT_NO_COP
1490 QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" ); 1562 QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" );
1491 e << d->appName; 1563 e << d->appName;
1492#endif 1564#endif
1565
1493 d->kbgrabber = 2; // me 1566 d->kbgrabber = 2; // me
1494 } 1567 }
1495} 1568}
1496 1569
1497/*! 1570/*!
1498 \reimp 1571 \reimp
1499*/ 1572*/
1500int QPEApplication::exec() 1573int QPEApplication::exec()
1501{ 1574{
1502#ifndef QT_NO_COP 1575#ifndef QT_NO_COP
1503 d->sendQCopQ(); 1576 d->sendQCopQ();
1504#endif 1577#endif
1578
1505 if ( d->keep_running ) 1579 if ( d->keep_running )
1506 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) 1580 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() )
1507 return QApplication::exec(); 1581 return QApplication::exec();
1508 1582
1509#ifndef QT_NO_COP 1583#ifndef QT_NO_COP
1584
1510 { 1585 {
1511 QCopEnvelope e( "QPE/System", "closing(QString)" ); 1586 QCopEnvelope e( "QPE/System", "closing(QString)" );
1512 e << d->appName; 1587 e << d->appName;
1513 } 1588 }
1514#endif 1589#endif
1515 processEvents(); 1590 processEvents();
1516 return 0; 1591 return 0;
1517} 1592}
1518 1593
1519/*! 1594/*!
1520 \internal 1595 \internal
1521 External request for application to quit. Quits if possible without 1596 External request for application to quit. Quits if possible without
1522 loosing state. 1597 loosing state.
1523*/ 1598*/
1524void QPEApplication::tryQuit() 1599void QPEApplication::tryQuit()
1525{ 1600{
1526 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 ) 1601 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 )
1527 return ; // Inside modal loop or konsole. Too hard to save state. 1602 return ; // Inside modal loop or konsole. Too hard to save state.
1528#ifndef QT_NO_COP 1603#ifndef QT_NO_COP
1604
1529 { 1605 {
1530 QCopEnvelope e( "QPE/System", "closing(QString)" ); 1606 QCopEnvelope e( "QPE/System", "closing(QString)" );
1531 e << d->appName; 1607 e << d->appName;
1532 } 1608 }
1533#endif 1609#endif
1534 processEvents(); 1610 processEvents();
1535 1611
1536 quit(); 1612 quit();
1537} 1613}
1538 1614
1539/*! 1615/*!
1540 \internal 1616 \internal
1541 User initiated quit. Makes the window 'Go Away'. If preloaded this means 1617 User initiated quit. Makes the window 'Go Away'. If preloaded this means
1542 hiding the window. If not it means quitting the application. 1618 hiding the window. If not it means quitting the application.
1543 As this is user initiated we don't need to check state. 1619 As this is user initiated we don't need to check state.
1544*/ 1620*/
1545void QPEApplication::hideOrQuit() 1621void QPEApplication::hideOrQuit()
1546{ 1622{
1547 processEvents(); 1623 processEvents();
1548 1624
1549 // If we are a preloaded application we don't actually quit, so emit 1625 // If we are a preloaded application we don't actually quit, so emit
1550 // a System message indicating we're quasi-closing. 1626 // a System message indicating we're quasi-closing.
1551 if ( d->preloaded && d->qpe_main_widget ) 1627 if ( d->preloaded && d->qpe_main_widget )
1552#ifndef QT_NO_COP 1628#ifndef QT_NO_COP
1629
1553 { 1630 {
1554 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); 1631 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
1555 e << d->appName; 1632 e << d->appName;
1556 d->qpe_main_widget->hide(); 1633 d->qpe_main_widget->hide();
1557 } 1634 }
1558#endif 1635#endif
1559 else 1636 else
1560 quit(); 1637 quit();
1561} 1638}
1562 1639
1563#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 1640#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
1564 1641