Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qpeapplication.cpp

Go to the documentation of this file.
00001 #define QTOPIA_INTERNAL_LANGLIST
00002 
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <unistd.h>
00006 #include <sys/file.h>
00007 
00008 
00009 #include <qdir.h>
00010 #include <qdialog.h>
00011 #include <qdragobject.h>
00012 #include <qevent.h>
00013 #include <qlabel.h>
00014 #include <qlist.h>
00015 #include <qtextstream.h>
00016 #include <qtextcodec.h>
00017 #include <qpalette.h>
00018 #include <qptrdict.h>
00019 #include <qregexp.h>
00020 #include <qtimer.h>
00021 
00022 #include <qpe/custom.h>
00023 #include <qpe/alarmserver.h>
00024 #include <qpe/applnk.h>
00025 #include <qpe/qpemenubar.h>
00026 #include <qpe/textcodecinterface.h>
00027 #include <qpe/imagecodecinterface.h>
00028 #include <qpe/qlibrary.h>
00029 #include <qpe/qpestyle.h>
00030 #include <qpe/styleinterface.h>
00031 #include <qpe/global.h>
00032 #include <qpe/resource.h>
00033 #include <qpe/config.h>
00034 #include <qpe/network.h>
00035 
00036 #include <qpe/qpeapplication.h>
00037 #include <qpe/timestring.h>
00038 #include <qpe/qcopenvelope_qws.h>
00039 
00040 
00041 #include <X11/Xlib.h>
00042 #include <X11/Xutil.h>
00043 
00044 const int XKeyPress = KeyPress;
00045 const int XKeyRelease = KeyRelease;
00046 #undef KeyPress
00047 #undef KeyRelease
00048 
00049 namespace {
00050     struct QCopRec{
00051         QCopRec( const QCString& ch, const QCString& msg, const QByteArray& ar )
00052             : channel(ch), message(msg), data(ar) {
00053 
00054         }
00055         QCString channel;
00056         QCString message;
00057         QByteArray data;
00058     };
00059 };
00060 
00061 
00062 class QPEApplication::Private {
00063 public:
00064     Private();
00065     ~Private();
00066     void enqueueQCop( const QCString& ch, const QCString& msg,
00067                       const QByteArray& );
00068     void sendQCopQ();
00069     static void show_mx(QWidget* mw, bool nomaximize );
00070     void show( QWidget* mw, bool nomax );
00071     void loadTextCodecs();
00072     void loadImageCodecs();
00073 
00074     int kbgrabber;
00075     int presstimer;
00076 
00077     bool rightpressed  : 1;
00078     bool kbregrab      : 1;
00079     bool notbusysent   : 1;
00080     bool preloaded     : 1;
00081     bool forceshow     : 1;
00082     bool nomaximize    : 1;
00083     bool keep_running  : 1;
00084 
00085     QWidget* presswidget;
00086     QPoint presspos;
00087     QWidget* qpe_main_widget;
00088     QString appName;
00089     QString styleName;
00090     QString decorationName;
00091     Atom wm_delete_window;
00092     Atom wm_take_focus;
00093     Atom wm_context_help;
00094     Atom wm_context_accept;
00095     Atom wm_protocols;
00096 
00097 private:
00098     QList<QCopRec> qcopq;
00099 };
00100 QPEApplication::Private::~Private() {
00101 }
00102 QPEApplication::Private::Private()
00103     : kbgrabber(0 ), presstimer(0 ), rightpressed( FALSE ), kbregrab( FALSE ), notbusysent( FALSE ),
00104       preloaded( FALSE ), forceshow( FALSE ), nomaximize( FALSE ), keep_running( TRUE ),
00105       presswidget( 0 ), qpe_main_widget(0 ) {
00106 
00107     qcopq.setAutoDelete( TRUE );
00108 }
00109 void QPEApplication::Private::enqueueQCop( const QCString& chan, const QCString& msg,
00110                                            const QByteArray& ar ) {
00111     qcopq.append( new QCopRec(chan, msg, ar ) );
00112 }
00113 void QPEApplication::Private::sendQCopQ() {
00114     QCopRec* r;
00115     for ( r = qcopq.first(); r; r = qcopq.next() ) {
00116         QCopChannel::sendLocally( r->channel, r->message, r->data );
00117     }
00118     qcopq.clear();
00119 }
00120 void QPEApplication::Private::show_mx(QWidget* mw, bool nomaximize ) {
00121     if (mw->layout() && mw->inherits("QDialog") ) {
00122         QPEApplication::showDialog( (QDialog*)mw, nomaximize );
00123     }else {
00124         if (!nomaximize )
00125             mw->showMaximized();
00126         else
00127             mw->show();
00128     }
00129 }
00130 void QPEApplication::Private::show( QWidget* mw, bool nomax ) {
00131     nomaximize = nomax;
00132     qpe_main_widget = mw;
00133 
00134     sendQCopQ();
00135 
00136     if ( preloaded ) {
00137         if (forceshow )
00138             show_mx(mw, nomax );
00139     }else if ( keep_running )
00140         show_mx( mw, nomax );
00141 }
00142 void QPEApplication::Private::loadTextCodecs() {
00143     QString path = QPEApplication::qpeDir() + "plugins/textcodecs";
00144     QDir dir( path, "lib*.so" );
00145     QStringList list = dir.entryList();
00146     QStringList::Iterator it;
00147     for ( it = list.begin(); it != list.end(); ++it ) {
00148         TextCodecInterface *iface = 0;
00149         QLibrary *lib = new QLibrary( path + "/" + *it );
00150         if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
00151             QValueList<int> mibs = iface->mibEnums();
00152             for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
00153                 (void)iface->createForMib(*i);
00154                 // ### it exists now; need to remember if we can delete it
00155             }
00156         }
00157         else {
00158             lib->unload();
00159             delete lib;
00160         }
00161     }
00162 }
00163 void QPEApplication::Private::loadImageCodecs() {
00164     QString path = QPEApplication::qpeDir() + "plugins/imagecodecs";
00165     QDir dir( path, "lib*.so" );
00166     QStringList list = dir.entryList();
00167     QStringList::Iterator it;
00168     for ( it = list.begin(); it != list.end(); ++it ) {
00169         ImageCodecInterface *iface = 0;
00170         QLibrary *lib = new QLibrary( path + "/" + *it );
00171         if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
00172             QStringList formats = iface->keys();
00173             for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
00174                 (void)iface->installIOHandler(*i);
00175                 // ### it exists now; need to remember if we can delete it
00176             }
00177         }
00178         else {
00179             lib->unload();
00180             delete lib;
00181         }
00182     }
00183 }
00184 
00185 // The Help System hook
00186 namespace {
00187     class ResourceMimeFactory : public QMimeSourceFactory
00188     {
00189     public:
00190         ResourceMimeFactory();
00191         ~ResourceMimeFactory();
00192         const QMimeSource* data( const QString& abs_name )const;
00193     };
00194     ResourceMimeFactory::ResourceMimeFactory()
00195     {
00196         setFilePath( Global::helpPath() );
00197         setExtensionType( "html", "text/html;charset=UTF-8" );
00198     }
00199     ResourceMimeFactory::~ResourceMimeFactory() {
00200     }
00201 
00202     const QMimeSource* ResourceMimeFactory::data( const QString& abs_name ) const
00203     {
00204         const QMimeSource * r = QMimeSourceFactory::data( abs_name );
00205         if ( !r ) {
00206             int sl = abs_name.length();
00207             do {
00208                 sl = abs_name.findRev( '/', sl - 1 );
00209                 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
00210                 int dot = name.findRev( '.' );
00211                 if ( dot >= 0 )
00212                     name = name.left( dot );
00213                 QImage img = Resource::loadImage( name );
00214                 if ( !img.isNull() )
00215                     r = new QImageDrag( img );
00216             }
00217             while ( !r && sl > 0 );
00218         }
00219         return r;
00220     };
00221 };
00222 // QPEApplication
00223 QPEApplication::~QPEApplication() {
00224     qWarning("~QPEApplication");
00225     ungrabKeyboard();
00226     qWarning("UngrabKeyboard");
00227 
00228 //    delete m_sys;
00229 //    delete m_pid;
00230 
00231     delete d;
00232 }
00233 QPEApplication::QPEApplication(int &arg, char** argv, Type t)
00234     : QApplication( arg, argv, t ) {
00235     d = new Private;
00236     d->loadTextCodecs();
00237     d->loadImageCodecs();
00238 
00239     // Init X-Atom
00240     Atom *atoms[5];
00241     Atom atoms_re[5];
00242     char* names[5];
00243     int n = 0;
00244     atoms[n]   = &d->wm_delete_window;
00245     names[n++] = "WM_DELETE_WINDOW";
00246 
00247     atoms[n]   = &d->wm_take_focus;
00248     names[n++] = "WM_TAKE_FOCUS";
00249 
00250     atoms[n]   = &d->wm_context_help;
00251     names[n++] = "_NET_WM_CONTEXT_HELP";
00252 
00253     atoms[n]   = &d->wm_context_accept;
00254     names[n++] = "_NET_WM_CONTEXT_ACCEPT";
00255 
00256     atoms[n]   = &d->wm_protocols;
00257     names[n++] = "WM_PROTOCOLS";
00258 
00259     XInternAtoms( qt_xdisplay(), names, n, FALSE, atoms_re);
00260     // now copy the values over to the properties
00261     for (int i = 0; i < n; i++ )
00262         *atoms[i] = atoms_re[i];
00263     // done with X11 Stuff
00264 
00265     int dw = desktop()->width();
00266     if ( dw < 200 ) {
00267         setFont( QFont( "helvetica", 8 ) );
00268         AppLnk::setSmallIconSize( 10 );
00269         AppLnk::setBigIconSize( 28 );
00270     }else if ( dw > 600 ) {
00271         setFont( QFont( "helvetica", 12 ) );
00272         AppLnk::setSmallIconSize( 24 );
00273         AppLnk::setBigIconSize( 48 );
00274     }else if ( dw > 200 ) {
00275         setFont( QFont( "helvetica", 10 ) );
00276         AppLnk::setSmallIconSize( 16 );
00277         AppLnk::setBigIconSize( 32 );
00278     }
00279     QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
00280 
00281     connect( this, SIGNAL( lastWindowClosed() ), this, SLOT(hideOrQuit() ) );
00282 
00283     QString qcopfn( "/tmp/qcop-msg-" );
00284     qcopfn += QString( argv[0] ); // append command name to the QCOP name
00285     QFile file( qcopfn );
00286     if (file.open(IO_ReadOnly ) ) {
00287         flock( file.handle(), LOCK_EX );
00288     }
00289 
00290     /* Hmmm damn we need to make the parent 0l otherwise it get's deleted
00291      * past the QApplication
00292      */
00293     m_sys = new QCopChannel( "QPE/System", 0l);
00294     connect(m_sys, SIGNAL( received(const QCString&,const QByteArray&) ),
00295             this, SLOT(systemMessage(const QCString&,const QByteArray&) ) );
00296 
00297     // private channel QPE/Application/appname
00298     QCString channel = QCString( argv[0] );
00299     channel.replace( QRegExp( ".*/"), "" );
00300     d->appName = channel;
00301     channel = "QPE/Application/"+ channel;
00302     m_pid = new QCopChannel( channel, 0l );
00303     connect(m_pid, SIGNAL( received(const QCString&,const QByteArray&) ),
00304             this, SLOT( pidMessage(const QCString&,const QByteArray&) ) );
00305 
00306     // read the Pre QCOP Stuff  from the file
00307     if ( file.isOpen() ) {
00308         d->keep_running = FALSE;
00309         QDataStream ds( &file );
00310         QCString chanel, message;
00311         QByteArray data;
00312         while (!ds.atEnd() ) {
00313             ds >> chanel >> message >> data;
00314             d->enqueueQCop( chanel, message, data );
00315         }
00316         flock( file.handle(), LOCK_UN );
00317         file.close();
00318         file.remove();
00319     }
00320 
00321     // read in some stuff from the command line
00322     // we do not have setArgs so we need to take
00323     // care of that
00324     for ( int a = 0; a < arg; a++ ) {
00325         if ( qstrcmp( argv[a], "-preload" ) == 0 ) {
00326             d->preloaded = TRUE;
00327         }else if ( qstrcmp( argv[a ] ,  "-preload-show" ) == 0 ) {
00328             d->preloaded = TRUE;
00329             d->forceshow = TRUE;
00330         }
00331     }
00332     initTranslations();
00333     applyStyle();
00334 
00335     if ( type() == GuiServer )
00336         ;
00337 
00338     installEventFilter( this );
00339     QPEMenuToolFocusManager::initialize();
00340 }
00341 void QPEApplication::initTranslations() {
00342     // Translations add it
00343     QStringList langs = Global::languageList();
00344     for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) {
00345         QString lang = *it;
00346 
00347         QTranslator * trans;
00348         QString tfn;
00349 
00350         trans = new QTranslator( this );
00351         tfn = qpeDir() + "/i18n/" + lang + "/libqpe.qm";
00352         if ( trans->load( tfn ) )
00353             installTranslator( trans );
00354         else
00355             delete trans;
00356 
00357         trans = new QTranslator( this );
00358         tfn = qpeDir() + "/i18n/" + lang + "/" + d->appName + ".qm";
00359         if ( trans->load( tfn ) )
00360             installTranslator( trans );
00361         else
00362             delete trans;
00363     }
00364 }
00365 QString QPEApplication::qpeDir() {
00366     const char * base = getenv( "OPIEDIR" );
00367     if ( base )
00368         return QString( base ) + "/";
00369 
00370     return QString( "../" );
00371 }
00372 QString QPEApplication::documentDir() {
00373     const char* base = getenv( "HOME");
00374     if ( base )
00375         return QString( base ) + "/Documents";
00376 
00377     return QString( "../Documents" );
00378 }
00379 void QPEApplication::applyStyle() {
00380     Config config( "qpe" );
00381 
00382     config.setGroup( "Appearance" );
00383 
00384     // Widget style
00385     QString style = config.readEntry( "Style", "Light" );
00386     internalSetStyle( style );
00387 
00388     // Colors
00389     QColor bgcolor( config.readEntry( "Background", "#E5E1D5" ) );
00390     QColor btncolor( config.readEntry( "Button", "#D6CDBB" ) );
00391     QPalette pal( btncolor, bgcolor );
00392     QString color = config.readEntry( "Highlight", "#800000" );
00393     pal.setColor( QColorGroup::Highlight, QColor( color ) );
00394     color = config.readEntry( "HighlightedText", "#FFFFFF" );
00395     pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
00396     color = config.readEntry( "Text", "#000000" );
00397     pal.setColor( QColorGroup::Text, QColor( color ) );
00398     color = config.readEntry( "ButtonText", "#000000" );
00399     pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
00400     color = config.readEntry( "Base", "#FFFFFF" );
00401     pal.setColor( QColorGroup::Base, QColor( color ) );
00402 
00403     pal.setColor( QPalette::Disabled, QColorGroup::Text,
00404                   pal.color( QPalette::Active, QColorGroup::Background ).dark() );
00405 
00406     setPalette( pal, TRUE );
00407 
00408 
00409 
00410     // Font
00411     QString ff = config.readEntry( "FontFamily", font().family() );
00412     int fs = config.readNumEntry( "FontSize", font().pointSize() );
00413     setFont( QFont(ff, fs) );
00414 }
00415 int QPEApplication::defaultRotation() {
00416     return 0;
00417 }
00418 void QPEApplication::setDefaultRotation(int) {
00419 
00420 }
00421 void QPEApplication::grabKeyboard() {
00422     QPEApplication::Private * d = ( ( QPEApplication* ) qApp ) ->d;
00423     if ( qApp->type() == QApplication::GuiServer )
00424         d->kbgrabber = 0;
00425     else {
00426         QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" );
00427         e << d->appName;
00428 
00429         d->kbgrabber = 2; // me
00430     }
00431 }
00432 void QPEApplication::ungrabKeyboard() {
00433     QPEApplication::Private * d = ( ( QPEApplication* ) qApp ) ->d;
00434     if ( d->kbgrabber == 2 ) {
00435         QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" );
00436         e << QString::null;
00437 
00438         d->kbregrab = FALSE;
00439         d->kbgrabber = 0;
00440     }
00441 }
00442 void QPEApplication::showMainWidget( QWidget* wid, bool b) {
00443     d->show(wid, b );
00444 }
00445 void QPEApplication::showMainDocumentWidget( QWidget* mw, bool m) {
00446     if ( mw && argc() == 2 )
00447         Global::setDocument( mw, QString::fromUtf8(argv()[1] ) );
00448 
00449     d->show(mw, m );
00450 }
00451 void QPEApplication::showDialog( QDialog* d, bool nomax ) {
00452     showWidget( d, nomax );
00453 }
00454 int QPEApplication::execDialog( QDialog* d, bool nomax) {
00455     showDialog(d,nomax);
00456     return d->exec();
00457 }
00458 
00459 void QPEApplication::showWidget( QWidget* d,  bool nomax ) {
00460     QSize sh = d->sizeHint();
00461     int w = QMAX(sh.width(),d->width());
00462     int h = QMAX(sh.height(),d->height());
00463     if ( !nomax
00464          && ( w > qApp->desktop()->width()*3/4
00465               || h > qApp->desktop()->height()*3/4 ) )
00466     {
00467         d->showMaximized();
00468     } else {
00469         d->resize(w,h);
00470         d->show();
00471     }
00472 }
00473 
00474 void QPEApplication::setKeepRunning() {
00475     if ( qApp && qApp->inherits( "QPEApplication" ) ) {
00476         QPEApplication * qpeApp = ( QPEApplication* ) qApp;
00477         qpeApp->d->keep_running = TRUE;
00478     }
00479 }
00480 bool QPEApplication::keepRunning()const {
00481     return d->keep_running;
00482 }
00483 bool QPEApplication::keyboardGrabbed()const {
00484     return d->kbgrabber;
00485 }
00486 int QPEApplication::exec() {
00487     /* now send the QCOP stuff gotten from the file */
00488     d->sendQCopQ();
00489 
00490     if ( d->keep_running ) {
00491         qWarning("going to exec");
00492         int a = QApplication::exec();
00493         qWarning("left");
00494         return a;
00495     }
00496 
00497     {
00498         QCopEnvelope e( "QPE/System", "closing(QString)" );
00499         e << d->appName;
00500     }
00501     qWarning("processing events!");
00502     processEvents();
00503     return 0;
00504 }
00505 void QPEApplication::internalSetStyle( const QString& ) {
00506 
00507 }
00508 void QPEApplication::systemMessage( const QCString& chan, const QByteArray& ) {
00509     qWarning("QPEApplication::systemMessage( %s )", chan.data() );
00510 }
00511 void QPEApplication::pidMessage( const QCString& msg, const QByteArray& ) {
00512     if ( msg == "flush()" ) {
00513         emit flush();
00514         QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
00515         e << d->appName;
00516     }else if ( msg == "reload()" ) {
00517         emit reload();
00518     }
00519 
00520 }
00521 void QPEApplication::timerEvent( QTimerEvent* e ) {
00522     if ( e->timerId() == d->presstimer && d->presswidget ) {
00523         // Right pressed
00524         postEvent( d->presswidget,
00525                    new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
00526                                     RightButton, LeftButton ) );
00527         killTimer( d->presstimer );
00528         d->presstimer = 0;
00529     }
00530 }
00531 
00532 // InputMethods Hints
00533 namespace {
00534     static QPtrDict<void>* inputMethodDict = 0;
00535     static void createInputMethodDict(){
00536         if ( !inputMethodDict )
00537             inputMethodDict = new QPtrDict<void>;
00538     }
00539 
00540     static QPtrDict<void>* stylusDict = 0;
00541     static void createDict() {
00542         if ( !stylusDict )
00543             stylusDict = new QPtrDict<void>;
00544     }
00545 };
00546 
00547 void QPEApplication::setInputMethodHint( QWidget* w, InputMethodHint mode ) {
00548     createInputMethodDict();
00549     if ( mode == Normal ) {
00550         inputMethodDict->remove
00551             ( w );
00552     }else {
00553         inputMethodDict->insert( w, ( void* ) mode );
00554     }
00555 }
00556 QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget* w) {
00557     if ( inputMethodDict && w )
00558         return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
00559     return Normal;
00560 }
00561 
00562 
00563 void QPEApplication::removeSenderFromStylusDict() {
00564     stylusDict->remove( ( void* ) sender() );
00565     if ( d->presswidget == sender() )
00566         d->presswidget = 0;
00567 }
00568 void QPEApplication::setStylusOperation( QWidget* w, StylusMode mode) {
00569     createDict();
00570     if ( mode == LeftOnly ) {
00571         stylusDict->remove
00572             ( w );
00573         w->removeEventFilter( qApp );
00574     }else {
00575         stylusDict->insert( w, ( void* ) mode );
00576         connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) );
00577         w->installEventFilter( qApp );
00578     }
00579 }
00580 QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w) {
00581     if ( stylusDict )
00582         return ( StylusMode ) ( int ) stylusDict->find( w );
00583     return LeftOnly;
00584 }
00585 
00586 // eventFilter......
00587 bool QPEApplication::eventFilter( QObject* o, QEvent* e ) {
00588     /*
00589      * We want our WM to show Ok and a X button
00590      * on dialogs
00591      * our part is to set the _NET_WM_CONTEXT_ACCEPT
00592      * propery
00593      * and then wait for a client message -zecke
00594      * on show we will add the prop
00595      */
00596     if (o->inherits("QDialog") && e->type() == QEvent::Show ) {
00597         QDialog* dialog = (QDialog*)o;
00598         Atom wm_prot[45];
00599         int n = 0;
00600         wm_prot[n++] = d->wm_delete_window;
00601         wm_prot[n++] = d->wm_take_focus;
00602         wm_prot[n++] = d->wm_context_accept;
00603         if ( dialog->testWFlags( WStyle_ContextHelp ) )
00604             wm_prot[n++] = d->wm_context_help;
00605         XSetWMProtocols( qt_xdisplay(), dialog->winId(), wm_prot, n );
00606         return TRUE; // should be save
00607     }
00608     if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
00609         QMouseEvent * me = ( QMouseEvent* ) e;
00610         StylusMode mode = (StylusMode)(int)stylusDict->find(o);
00611         switch (mode) {
00612         case RightOnHold:
00613             switch ( me->type() ) {
00614             case QEvent::MouseButtonPress:
00615                 if ( me->button() == LeftButton ) {
00616                     d->presstimer = startTimer(500); // #### pref.
00617                     d->presswidget = (QWidget*)o;
00618                     d->presspos = me->pos();
00619                     d->rightpressed = FALSE;
00620                 }
00621                 break;
00622             case QEvent::MouseMove:
00623                 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
00624                     killTimer(d->presstimer);
00625                     d->presstimer = 0;
00626                 }
00627                 break;
00628             case QEvent::MouseButtonRelease:
00629                 if ( me->button() == LeftButton ) {
00630                     if ( d->presstimer ) {
00631                         killTimer(d->presstimer);
00632                         d->presstimer = 0;
00633                     }
00634                     if ( d->rightpressed && d->presswidget ) {
00635                         // Right released
00636                         postEvent( d->presswidget,
00637                                    new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
00638                                                     RightButton, LeftButton + RightButton ) );
00639                         // Left released, off-widget
00640                         postEvent( d->presswidget,
00641                                    new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
00642                                                     LeftButton, LeftButton ) );
00643                         postEvent( d->presswidget,
00644                                    new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
00645                                                     LeftButton, LeftButton ) );
00646                         d->rightpressed = FALSE;
00647                         return TRUE; // don't send the real Left release
00648                     }
00649                 }
00650                 break;
00651             default:
00652                 break;
00653             }
00654             break;
00655         default:
00656             ;
00657         }
00658     }
00659     else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
00660         QKeyEvent *ke = (QKeyEvent *)e;
00661         if ( ke->key() == Key_Enter ) {
00662             if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
00663                 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
00664                                              ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
00665                 return TRUE;
00666             }
00667         }
00668     }
00669     return FALSE;
00670 }
00671 
00672 // Quit stuff
00673 void QPEApplication::restart() {
00674 
00675 }
00676 void QPEApplication::shutdown() {
00677 
00678 }
00679 void QPEApplication::tryQuit() {
00680     qWarning("TryQuit!!");
00681     if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 )
00682         return ; // Inside modal loop or konsole. Too hard to save state.
00683     {
00684         QCopEnvelope e( "QPE/System", "closing(QString)" );
00685         e << d->appName;
00686     }
00687     processEvents();
00688 
00689     quit();
00690 }
00691 void QPEApplication::hideOrQuit() {
00692     qWarning("hide or close");
00693     processEvents();
00694     qWarning("past processing");
00695 
00696     // If we are a preloaded application we don't actually quit, so emit
00697     // a System message indicating we're quasi-closing.
00698     if ( d->preloaded && d->qpe_main_widget )
00699 
00700     {
00701         qWarning("hiding");
00702         QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
00703         e << d->appName;
00704         d->qpe_main_widget->hide();
00705     }
00706     else
00707         quit();
00708 }
00709 
00713 void QPEApplication::prepareForTermination( bool willrestart )
00714 {
00715         if ( willrestart ) {
00716                 // Draw a big wait icon, the image can be altered in later revisions
00717                 //  QWidget *d = QApplication::desktop();
00718                 QImage img = Resource::loadImage( "launcher/new_wait" );
00719                 QPixmap pix;
00720                 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) );
00721                 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize |
00722                                               QWidget::WStyle_NoBorder | QWidget::WStyle_Tool );
00723                 lblWait->setPixmap( pix );
00724                 lblWait->setAlignment( QWidget::AlignCenter );
00725                 lblWait->show();
00726                 lblWait->showMaximized();
00727         }
00728 #ifndef SINGLE_APP
00729         { QCopEnvelope envelope( "QPE/System", "forceQuit()" );
00730         }
00731         processEvents(); // ensure the message goes out.
00732         sleep( 1 ); // You have 1 second to comply.
00733 #endif
00734 }
00735 int QPEApplication::x11ClientMessage(QWidget* w, XEvent* event, bool b ) {
00736     qWarning("X11 ClientMessage %d %d", event->type,  ClientMessage);
00737     if ( event->type == ClientMessage ) {
00738         if ( (event->xclient.message_type == d->wm_protocols) &&
00739              (event->xclient.data.l[0] == d->wm_context_accept ) ) {
00740             qWarning("accepted!!!");
00741             /*
00742              * I'm not sure if we should use activeWidget
00743              * or activeModalWidget
00744              * a QDialog could be not modal too
00745              */
00746             if ( w->inherits("QDialog" ) ) {
00747                 qWarning("inherits QDialog!!!");
00748                 QDialog* dia = (QDialog*)w;
00749                 /*
00750                  * call it directly or via QTimer::singleShot?
00751                  */
00752                 QTimer::singleShot(0, dia, SLOT(accept() ) );
00753                  return 0;
00754             }
00755 
00756         }
00757     }
00758     return QApplication::x11ClientMessage(w, event, b );
00759 }
00760 
00761 #define KeyPress XKeyPress
00762 #define KeyRelease XKeyRelease
00763 
00764 #if defined(OPIE_NEW_MALLOC)
00765 #define likely(x) x
00766 
00767 // The libraries with the skiff package (and possibly others) have
00768 // completely useless implementations of builtin new and delete that
00769 // use about 50% of your CPU. Here we revert to the simple libc
00770 // functions.
00771 
00772 void* operator new[]( size_t size )
00773 {
00774         return malloc( size );
00775 }
00776 
00777 void* operator new( size_t size )
00778 {
00779         return malloc( size );
00780 }
00781 
00782 void operator delete[]( void* p )
00783 {
00784     if ( likely(p) )
00785         free( p );
00786 }
00787 
00788 void operator delete[]( void* p, size_t /*size*/ )
00789 {
00790     if ( likely(p) )
00791         free( p );
00792 }
00793 
00794 void operator delete( void* p )
00795 {
00796     if ( likely(p) )
00797         free( p );
00798 }
00799 
00800 void operator delete( void* p, size_t /*size*/ )
00801 {
00802     if ( likely(p) )
00803         free( p );
00804 }
00805 
00806 #endif

Generated on Sat Nov 5 16:16:39 2005 for OPIE by  doxygen 1.4.2