author | zecke <zecke> | 2003-08-29 06:52:04 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-08-29 06:52:04 (UTC) |
commit | d8fadaf4f510803983d0b8b99994fd70e770ccab (patch) (side-by-side diff) | |
tree | 3921c576b3dbd0dc4fd3ccfe4d39204522bf57a6 /library/qpeapplication.cpp | |
parent | b9861471966f8bb0e3bea2db58a0d1289add1d4f (diff) | |
download | opie-d8fadaf4f510803983d0b8b99994fd70e770ccab.zip opie-d8fadaf4f510803983d0b8b99994fd70e770ccab.tar.gz opie-d8fadaf4f510803983d0b8b99994fd70e770ccab.tar.bz2 |
-IF the app is visible and has more than once topLevel widget
iterate over the list and activate the next one.
-Install translation in .qm
-Add an else again ( was lost in a merge )
-rw-r--r-- | library/qpeapplication.cpp | 142 |
1 files changed, 103 insertions, 39 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index 9286f9f..149e6bb 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp @@ -3,67 +3,66 @@ ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** -** $Id$ -** -**********************************************************************/ +*/ #define QTOPIA_INTERNAL_LANGLIST #include <stdlib.h> #include <unistd.h> #include <linux/limits.h> // needed for some toolchains (PATH_MAX) #include <qfile.h> #ifdef Q_WS_QWS #ifndef QT_NO_COP #if QT_VERSION <= 231 #define private public #define sendLocally processEvent #include "qcopenvelope_qws.h" #undef private #else #include "qcopenvelope_qws.h" #endif #endif #include <qwindowsystem_qws.h> #endif #include <qtextstream.h> #include <qpalette.h> #include <qbuffer.h> #include <qptrdict.h> #include <qregexp.h> #include <qdir.h> #include <qlabel.h> #include <qdialog.h> #include <qdragobject.h> #include <qtextcodec.h> #include <qevent.h> #include <qtooltip.h> #include <qsignal.h> #include <qmainwindow.h> +#include <qwidgetlist.h> #if defined(Q_WS_QWS) && !defined(QT_NO_COP) #define QTOPIA_INTERNAL_INITAPP #include "qpeapplication.h" #include "qpestyle.h" #include "styleinterface.h" #if QT_VERSION >= 300 #include <qstylefactory.h> #else #include <qplatinumstyle.h> #include <qwindowsstyle.h> #include <qmotifstyle.h> #include <qmotifplusstyle.h> #include "lightstyle.h" #include <qpe/qlibrary.h> @@ -104,46 +103,50 @@ public: { qcopq.setAutoDelete( TRUE ); } int presstimer; QWidget* presswidget; QPoint presspos; bool rightpressed : 1; bool kbgrabbed : 1; bool notbusysent : 1; bool preloaded : 1; bool forceshow : 1; bool nomaximize : 1; bool keep_running : 1; + QStringList langs; QString appName; struct QCopRec { QCopRec( const QCString &ch, const QCString &msg, const QByteArray &d ) : channel( ch ), message( msg ), data( d ) { } QCString channel; QCString message; QByteArray data; }; QWidget* qpe_main_widget; + QGuardedPtr<QWidget> lastWidget; QList<QCopRec> qcopq; + QString styleName; + QString decorationName; void enqueueQCop( const QCString &ch, const QCString &msg, const QByteArray &data ) { qcopq.append( new QCopRec( ch, msg, data ) ); } void sendQCopQ() { QCopRec * r; #ifndef QT_NO_COP for ( QListIterator<QCopRec> it( qcopq ); ( r = it.current() ); ++it ) QCopChannel::sendLocally( r->channel, r->message, r->data ); #endif qcopq.clear(); @@ -253,34 +256,32 @@ public: for ( it = list.begin(); it != list.end(); ++it ) { ImageCodecInterface *iface = 0; QLibrary *lib = new QLibrary( path + "/" + *it ); if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { QStringList formats = iface->keys(); for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { (void)iface->installIOHandler(*i); // ### it exists now; need to remember if we can delete it } } else { lib->unload(); delete lib; } } } - QString styleName; - QString decorationName; }; class ResourceMimeFactory : public QMimeSourceFactory { public: ResourceMimeFactory() : resImage( 0 ) { setFilePath( Global::helpPath() ); setExtensionType( "html", "text/html;charset=UTF-8" ); } ~ResourceMimeFactory() { delete resImage; } const QMimeSource* data( const QString& abs_name ) const { @@ -650,34 +651,34 @@ QPEApplication::QPEApplication( int & argc, char **argv, Type t ) d->forceshow = TRUE; argc -= 1; } } /* overide stored arguments */ setArgs( argc, argv ); #endif #else initApp( argc, argv ); #endif // qwsSetDecoration( new QPEDecoration() ); #ifndef QT_NO_TRANSLATION - QStringList langs = Global::languageList(); - for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) { + d->langs = Global::languageList(); + for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) { QString lang = *it; installTranslation( lang + "/libopie.qm"); installTranslation( lang + "/libqpe.qm" ); installTranslation( lang + "/" + d->appName + ".qm" ); //###language/font hack; should look it up somewhere #ifdef QWS if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { QFont fn = FontManager::unicodeFont( FontManager::Proportional ); setFont( fn ); } #endif } @@ -729,32 +730,36 @@ void QPEApplication::initApp( int argc, char **argv ) if ( qstrcmp(argv[a],"-preload")==0 ) { argv[a] = argv[a+1]; a++; d->preloaded = TRUE; argc-=1; } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { argv[a] = argv[a+1]; a++; d->preloaded = TRUE; d->forceshow = TRUE; argc-=1; } } /* overide stored arguments */ setArgs(argc, argv); + + /* install translation here */ + for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) + installTranslation( (*it) + "/" + d->appName + ".qm" ); } #endif static QPtrDict<void>* inputMethodDict = 0; static void createInputMethodDict() { if ( !inputMethodDict ) inputMethodDict = new QPtrDict<void>; } /*! Returns the currently set hint to the system as to whether widget \a w has any use for text input methods. @@ -1298,71 +1303,129 @@ void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE ); } } else if ( msg == "newChannel(QString)") { QString myChannel = "QPE/Application/" + d->appName; QString channel; stream >> channel; if (channel == myChannel) { processQCopFile(); d->sendQCopQ(); } } #endif } +#include <qmetaobject.h> + +QWidget *QPEApplication::nextWidget(QWidgetList* list, QWidget* _wid) { + QWidget *next = 0; + if ( list->isEmpty() || list->count() == 1 ) + next = _wid; + else{ + QWidget* wid; + uint idx = list->findRef( _wid ); + uint count = list->count(); + + /* one time through the list hacky we may not start with idx but end with it*/ + for (uint i = (idx + 1)%count; true; i=(i+1)%count ) { + wid = list->at(i); + if ( wid == _wid ) { + next = _wid; + break; + }else if ((( wid->inherits("QMainWindow") || + wid->inherits("QDialog") ) && + wid != qApp->desktop() && !wid->isHidden() ) || + ( wid == mainWidget() || wid == d->qpe_main_widget ) ){ + next = wid; + break; + } + } + } + + delete list; + return next; +} /*! \internal */ +// ########## raise()ing main window should raise and set active +// ########## it and then all childen. This belongs in Qt/Embedded +/* + * slightly change in behaviour to kill the need of modality in Opie + * If any of the topLevelWidgets !isFullyObscured we highlight the next + * top level window + * 1)If visible and not modal we iterate over the list of top level widgets + * 2)If modal we we make the modal and its parent toplevel widget visible if available + * 3)else make topLevel visible + * + * send qcop if necessary and save current visible widget if not modal + */ bool QPEApplication::raiseAppropriateWindow() { - bool r = FALSE; - // ########## raise()ing main window should raise and set active - // ########## it and then all childen. This belongs in Qt/Embedded - QWidget *top = d->qpe_main_widget; - if ( !top ) - top = mainWidget(); - if ( top && d->keep_running ) { - if ( top->isVisible() ) - r = TRUE; - else if (d->preloaded) { - // We are preloaded and not visible.. pretend we just started.. - QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); - e << d->appName; - } + bool r = FALSE; + + QWidget *top = d->qpe_main_widget ? d->qpe_main_widget : mainWidget(); + /* 1. */ + if ( ( top && (top->isVisible() ) || ( d->lastWidget && d->lastWidget->isVisible() ) ) && + !activeModalWidget() ) { + r = TRUE; + /*wid will be valid and topLevelWidgets will be deleted properly.. */ + QWidget *wid = nextWidget( topLevelWidgets(), + d->lastWidget ? (QWidget*)d->lastWidget : top ); + /* keep the size window got but not for root*/ + if ( top == wid ) + d->show_mx(top, d->nomaximize ); + else + wid->show(); + + wid->raise(); + wid->setActiveWindow(); + d->lastWidget = wid; + }else if ( activeModalWidget() ) { + QWidget* mod = activeModalWidget(); + /* get the parent of the modal and its topLevelWidget as background widget */ + QWidget* par = activeModalWidget()->parentWidget() ? activeModalWidget()->parentWidget()->topLevelWidget() : 0; + if (par ) { + if (par == top ) + d->show_mx(par, d->nomaximize ); + else + par->show(); + par->raise(); + par->setActiveWindow(); + } + mod->show(); + mod->raise(); + mod->setActiveWindow(); + }else if (top){ + d->show_mx(top, d->nomaximize ); + top->raise(); + top->setActiveWindow(); + d->lastWidget = top; + } - d->show_mx(top, d->nomaximize); - top->raise(); - top->setActiveWindow(); - } - QWidget *topm = activeModalWidget(); - if ( topm && topm != top ) { - topm->show(); - topm->raise(); - topm->setActiveWindow(); - // If we haven't already handled the fastAppShowing message - if (!top && d->preloaded) { - QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); - e << d->appName; - } - r = FALSE; - } - return r; + if (!r && d->preloaded ) { + QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); + e << d->appName; + } + + return r; } + void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) { #ifdef Q_WS_QWS if ( msg == "quit()" ) { tryQuit(); } else if ( msg == "quitIfInvisible()" ) { if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) quit(); } else if ( msg == "close()" ) { hideOrQuit(); } else if ( msg == "disablePreload()" ) { d->preloaded = FALSE; @@ -1389,36 +1452,37 @@ void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); e << d->appName; } else if ( msg == "reload()" ) { emit reload(); } else if ( msg == "setDocument(QString)" ) { d->keep_running = TRUE; QDataStream stream( data, IO_ReadOnly ); QString doc; stream >> doc; QWidget *mw = mainWidget(); if ( !mw ) mw = d->qpe_main_widget; if ( mw ) Global::setDocument( mw, doc ); + } else if ( msg == "QPEProcessQCop()" ) { processQCopFile(); d->sendQCopQ(); - } + }else { bool p = d->keep_running; d->keep_running = FALSE; emit appMessage( msg, data); if ( d->keep_running ) { d->notbusysent = FALSE; raiseAppropriateWindow(); if ( !p ) { // Tell the system we're still chugging along... #ifndef QT_NO_COP QCopEnvelope e("QPE/System", "appRaised(QString)"); e << d->appName; #endif } } if ( p ) |