summaryrefslogtreecommitdiff
path: root/library/qpeapplication.cpp
Unidiff
Diffstat (limited to 'library/qpeapplication.cpp') (more/less context) (show whitespace changes)
-rw-r--r--library/qpeapplication.cpp142
1 files changed, 120 insertions, 22 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index d1a7cd2..b1b7ed4 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -48,12 +48,15 @@
48#include <qdragobject.h> 48#include <qdragobject.h>
49#include <qtextcodec.h> 49#include <qtextcodec.h>
50#include <qevent.h> 50#include <qevent.h>
51#include <qtooltip.h> 51#include <qtooltip.h>
52#include <qsignal.h> 52#include <qsignal.h>
53#include <qmainwindow.h> 53#include <qmainwindow.h>
54
55#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
56#define QTOPIA_INTERNAL_INITAPP
54#include "qpeapplication.h" 57#include "qpeapplication.h"
55#include "qpestyle.h" 58#include "qpestyle.h"
56#include "styleinterface.h" 59#include "styleinterface.h"
57#if QT_VERSION >= 300 60#if QT_VERSION >= 300
58#include <qstylefactory.h> 61#include <qstylefactory.h>
59#else 62#else
@@ -302,12 +305,22 @@ public:
302 return r; 305 return r;
303 } 306 }
304private: 307private:
305 mutable QImageDrag *resImage; 308 mutable QImageDrag *resImage;
306}; 309};
307 310
311static int& hack(int& i)
312{
313#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
314 // These should be created, but aren't in Qt 2.3.0
315 (void)new QUtf8Codec;
316 (void)new QUtf16Codec;
317#endif
318 return i;
319}
320
308static int muted = 0; 321static int muted = 0;
309static int micMuted = 0; 322static int micMuted = 0;
310 323
311static void setVolume( int t = 0, int percent = -1 ) 324static void setVolume( int t = 0, int percent = -1 )
312{ 325{
313 switch ( t ) { 326 switch ( t ) {
@@ -483,12 +496,41 @@ static void setTreble( int t = 0, int percent = -1 )
483 496
484/*! 497/*!
485 \fn void QPEApplication::reload() 498 \fn void QPEApplication::reload()
486 499
487*/ 500*/
488 501
502
503
504void QPEApplication::processQCopFile()
505{
506 QString qcopfn("/tmp/qcop-msg-");
507 qcopfn += d->appName; // append command name
508
509 QFile f(qcopfn);
510 if ( f.open(IO_ReadWrite) ) {
511#ifndef Q_OS_WIN32
512 flock(f.handle(), LOCK_EX);
513#endif
514 QDataStream ds(&f);
515 QCString channel, message;
516 QByteArray data;
517 while(!ds.atEnd()) {
518 ds >> channel >> message >> data;
519 d->enqueueQCop(channel,message,data);
520 }
521 ::ftruncate(f.handle(), 0);
522#ifndef Q_OS_WIN32
523 f.flush();
524 flock(f.handle(), LOCK_UN);
525#endif
526 }
527#endif
528}
529
530
489/*! 531/*!
490 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 532 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
491 533
492 This signal is emitted when a message is received on this 534 This signal is emitted when a message is received on this
493 application's QPE/Application/<i>appname</i> \link qcop.html 535 application's QPE/Application/<i>appname</i> \link qcop.html
494 QCop\endlink channel. 536 QCop\endlink channel.
@@ -520,13 +562,13 @@ static void setTreble( int t = 0, int percent = -1 )
520 a QApplication, passing \a argc, \a argv, and \a t. 562 a QApplication, passing \a argc, \a argv, and \a t.
521 563
522 For applications, \a t should be the default, GuiClient. Only 564 For applications, \a t should be the default, GuiClient. Only
523 the Qtopia server passes GuiServer. 565 the Qtopia server passes GuiServer.
524*/ 566*/
525QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 567QPEApplication::QPEApplication( int & argc, char **argv, Type t )
526 : QApplication( argc, argv, t ) 568 : QApplication( hack(argc), argv, t ), pidChannel( 0 )
527{ 569{
528 d = new QPEApplicationData; 570 d = new QPEApplicationData;
529 d->loadTextCodecs(); 571 d->loadTextCodecs();
530 d->loadImageCodecs(); 572 d->loadImageCodecs();
531 int dw = desktop() ->width(); 573 int dw = desktop() ->width();
532 574
@@ -548,25 +590,31 @@ QPEApplication::QPEApplication( int & argc, char **argv, Type t )
548 AppLnk::setBigIconSize( 32 ); 590 AppLnk::setBigIconSize( 32 );
549 } 591 }
550 592
551 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 593 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
552 594
553 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 595 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
596
597
598 sysChannel = new QCopChannel( "QPE/System", this );
599 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
600 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) );
601
602/* COde now in initapp */
603#if 0
554#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 604#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
555 605
556 QString qcopfn( "/tmp/qcop-msg-" ); 606 QString qcopfn( "/tmp/qcop-msg-" );
557 qcopfn += QString( argv[ 0 ] ); // append command name 607 qcopfn += QString( argv[ 0 ] ); // append command name
558 608
559 QFile f( qcopfn ); 609 QFile f( qcopfn );
560 if ( f.open( IO_ReadOnly ) ) { 610 if ( f.open( IO_ReadOnly ) ) {
561 flock( f.handle(), LOCK_EX ); 611 flock( f.handle(), LOCK_EX );
562 } 612 }
563 613
564 sysChannel = new QCopChannel( "QPE/System", this ); 614
565 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
566 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) );
567 615
568 QCString channel = QCString( argv[ 0 ] ); 616 QCString channel = QCString( argv[ 0 ] );
569 channel.replace( QRegExp( ".*/" ), "" ); 617 channel.replace( QRegExp( ".*/" ), "" );
570 d->appName = channel; 618 d->appName = channel;
571 channel = "QPE/Application/" + channel; 619 channel = "QPE/Application/" + channel;
572 pidChannel = new QCopChannel( channel, this ); 620 pidChannel = new QCopChannel( channel, this );
@@ -605,13 +653,15 @@ QPEApplication::QPEApplication( int & argc, char **argv, Type t )
605 } 653 }
606 654
607 /* overide stored arguments */ 655 /* overide stored arguments */
608 setArgs( argc, argv ); 656 setArgs( argc, argv );
609 657
610#endif 658#endif
611 659#else
660 initApp( argc, argv );
661#endif
612 // qwsSetDecoration( new QPEDecoration() ); 662 // qwsSetDecoration( new QPEDecoration() );
613 663
614#ifndef QT_NO_TRANSLATION 664#ifndef QT_NO_TRANSLATION
615 665
616 QStringList langs = Global::languageList(); 666 QStringList langs = Global::languageList();
617 for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) { 667 for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) {
@@ -627,13 +677,12 @@ QPEApplication::QPEApplication( int & argc, char **argv, Type t )
627 677
628 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 678 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
629 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 679 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
630 setFont( fn ); 680 setFont( fn );
631 } 681 }
632#endif 682#endif
633
634 } 683 }
635#endif 684#endif
636 685
637 applyStyle(); 686 applyStyle();
638 687
639 if ( type() == GuiServer ) { 688 if ( type() == GuiServer ) {
@@ -647,12 +696,57 @@ QPEApplication::QPEApplication( int & argc, char **argv, Type t )
647#ifdef QT_NO_QWS_CURSOR 696#ifdef QT_NO_QWS_CURSOR
648 // if we have no cursor, probably don't want tooltips 697 // if we have no cursor, probably don't want tooltips
649 QToolTip::setEnabled( FALSE ); 698 QToolTip::setEnabled( FALSE );
650#endif 699#endif
651} 700}
652 701
702
703#ifdef QTOPIA_INTERNAL_INITAPP
704void QPEApplication::initApp( int argc, char **argv )
705{
706 delete pidChannel;
707 d->keep_running = TRUE;
708 d->preloaded = FALSE;
709 d->forceshow = FALSE;
710
711 QCString channel = QCString(argv[0]);
712
713 channel.replace(QRegExp(".*/"),"");
714 d->appName = channel;
715
716 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6
717
718 channel = "QPE/Application/" + channel;
719 pidChannel = new QCopChannel( channel, this);
720 connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)),
721 this, SLOT(pidMessage(const QCString &, const QByteArray &)));
722
723 processQCopFile();
724 d->keep_running = d->qcopq.isEmpty();
725
726 for (int a=0; a<argc; a++) {
727 if ( qstrcmp(argv[a],"-preload")==0 ) {
728 argv[a] = argv[a+1];
729 a++;
730 d->preloaded = TRUE;
731 argc-=1;
732 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
733 argv[a] = argv[a+1];
734 a++;
735 d->preloaded = TRUE;
736 d->forceshow = TRUE;
737 argc-=1;
738 }
739 }
740
741 /* overide stored arguments */
742 setArgs(argc, argv);
743}
744#endif
745
746
653static QPtrDict<void>* inputMethodDict = 0; 747static QPtrDict<void>* inputMethodDict = 0;
654static void createInputMethodDict() 748static void createInputMethodDict()
655{ 749{
656 if ( !inputMethodDict ) 750 if ( !inputMethodDict )
657 inputMethodDict = new QPtrDict<void>; 751 inputMethodDict = new QPtrDict<void>;
658} 752}
@@ -1121,26 +1215,12 @@ void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data
1121 unsetenv( "TZ" ); 1215 unsetenv( "TZ" );
1122 else 1216 else
1123 setenv( "TZ", t.latin1(), 1 ); 1217 setenv( "TZ", t.latin1(), 1 );
1124 // emit the signal so everyone else knows... 1218 // emit the signal so everyone else knows...
1125 emit timeChanged(); 1219 emit timeChanged();
1126 } 1220 }
1127 else if ( msg == "execute(QString)" ) {
1128 if ( type() == GuiServer ) {
1129 QString t;
1130 stream >> t;
1131 Global::execute( t );
1132 }
1133 }
1134 else if ( msg == "execute(QString,QString)" ) {
1135 if ( type() == GuiServer ) {
1136 QString t, d;
1137 stream >> t >> d;
1138 Global::execute( t, d );
1139 }
1140 }
1141 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { 1221 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) {
1142 if ( type() == GuiServer ) { 1222 if ( type() == GuiServer ) {
1143 QDateTime when; 1223 QDateTime when;
1144 QCString channel, message; 1224 QCString channel, message;
1145 int data; 1225 int data;
1146 stream >> when >> channel >> message >> data; 1226 stream >> when >> channel >> message >> data;
@@ -1205,14 +1285,28 @@ void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data
1205 int t, v; 1285 int t, v;
1206 stream >> t >> v; 1286 stream >> t >> v;
1207 setTreble( t, v ); 1287 setTreble( t, v );
1208 } 1288 }
1209 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1289 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1210 setTreble(); 1290 setTreble();
1291 } else if ( msg == "getMarkedText()" ) {
1292 if ( type() == GuiServer ) {
1293 const ushort unicode = 'C'-'@';
1294 const int scan = Key_C;
1295 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE );
1296 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE );
1297 }
1298 } else if ( msg == "newChannel(QString)") {
1299 QString myChannel = "QPE/Application/" + d->appName;
1300 QString channel;
1301 stream >> channel;
1302 if (channel == myChannel) {
1303 processQCopFile();
1304 d->sendQCopQ();
1305 }
1211 } 1306 }
1212
1213 1307
1214 1308
1215#endif 1309#endif
1216} 1310}
1217 1311
1218/*! 1312/*!
@@ -1303,13 +1397,17 @@ void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data)
1303 stream >> doc; 1397 stream >> doc;
1304 QWidget *mw = mainWidget(); 1398 QWidget *mw = mainWidget();
1305 if ( !mw ) 1399 if ( !mw )
1306 mw = d->qpe_main_widget; 1400 mw = d->qpe_main_widget;
1307 if ( mw ) 1401 if ( mw )
1308 Global::setDocument( mw, doc ); 1402 Global::setDocument( mw, doc );
1309 } else { 1403 } else if ( msg == "QPEProcessQCop()" ) {
1404 processQCopFile();
1405 d->sendQCopQ();
1406 }
1407 {
1310 bool p = d->keep_running; 1408 bool p = d->keep_running;
1311 d->keep_running = FALSE; 1409 d->keep_running = FALSE;
1312 emit appMessage( msg, data); 1410 emit appMessage( msg, data);
1313 if ( d->keep_running ) { 1411 if ( d->keep_running ) {
1314 d->notbusysent = FALSE; 1412 d->notbusysent = FALSE;
1315 raiseAppropriateWindow(); 1413 raiseAppropriateWindow();