author | zecke <zecke> | 2003-08-25 14:46:43 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-08-25 14:46:43 (UTC) |
commit | 292b097e7db25dd231381c5b09307a1fbe81a492 (patch) (side-by-side diff) | |
tree | b103c6c5e15e784dc07af55539672a72559da821 | |
parent | 5f292b6e4fc0f4ee8e4bced9a916f6bdce864b6b (diff) | |
download | opie-292b097e7db25dd231381c5b09307a1fbe81a492.zip opie-292b097e7db25dd231381c5b09307a1fbe81a492.tar.gz opie-292b097e7db25dd231381c5b09307a1fbe81a492.tar.bz2 |
-instead of defining for an board we define now what this
boards need
QPE_NEED_CALIBRATE
-launcher is the only one executin application
-allow processing of QCOPfiles after start ( qpeapplication )
-qcopenvelope no longer calls Global::execute
-rw-r--r-- | library/custom-ipaq.h | 1 | ||||
-rw-r--r-- | library/custom-ramses.h | 1 | ||||
-rw-r--r-- | library/custom-sharp.h | 1 | ||||
-rw-r--r-- | library/custom-simpad.h | 7 | ||||
-rw-r--r-- | library/global.cpp | 59 | ||||
-rw-r--r-- | library/inputmethodinterface.h | 19 | ||||
-rw-r--r-- | library/qcopenvelope_qws.cpp | 66 | ||||
-rw-r--r-- | library/qpeapplication.cpp | 152 | ||||
-rw-r--r-- | library/qpeapplication.h | 6 |
9 files changed, 183 insertions, 129 deletions
diff --git a/library/custom-ipaq.h b/library/custom-ipaq.h index 553b571..a9319fa 100644 --- a/library/custom-ipaq.h +++ b/library/custom-ipaq.h @@ -1,20 +1,21 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** 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. ** **********************************************************************/ +#define QPE_NEED_CALIBRATION
\ No newline at end of file diff --git a/library/custom-ramses.h b/library/custom-ramses.h index b841a66..9104931 100644 --- a/library/custom-ramses.h +++ b/library/custom-ramses.h @@ -1,68 +1,69 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** 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. ** **********************************************************************/ +#define QPE_NEED_CALIBRATION #define QPE_HAVE_TOGGLELIGHT #define QPE_STARTMENU #include <unistd.h> #include <stdio.h> #include <signal.h> #include <fcntl.h> #include <sys/ioctl.h> #define QPE_HAVE_MEMALERTER #define QPE_MEMALERTER_IMPL \ static void sig_handler(int sig) \ { \ switch (sig) { \ case SIGHUP: \ memstate = VeryLow; \ break; \ case SIGUSR1: \ memstate = Normal; \ break; \ case SIGUSR2: \ memstate = Low; \ break; \ } \ } \ static void initMemalerter() \ { \ struct sigaction sa; \ memset(&sa, '\0', sizeof sa); \ sa.sa_handler = sig_handler; \ sa.sa_flags = SA_RESTART; \ if (sigaction(SIGHUP, &sa, NULL) < 0) { \ return; \ } \ if (sigaction(SIGUSR1, &sa, NULL) < 0) { \ return; \ } \ if (sigaction(SIGUSR2, &sa, NULL) < 0) { \ return; \ } \ FILE *fo = fopen("/proc/sys/vm/freepg_signal_proc", "w"); \ \ if (!fo) \ return; \ fprintf(fo, "qpe\n"); \ fclose(fo); \ } diff --git a/library/custom-sharp.h b/library/custom-sharp.h index 3dab34f..3936875 100644 --- a/library/custom-sharp.h +++ b/library/custom-sharp.h @@ -1,97 +1,98 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** 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. ** **********************************************************************/ +#define QPE_NEED_CALIBRATION #define QPE_OWNAPM #define QPE_HAVE_TOGGLELIGHT #define QPE_NOCIBAUD #define QPE_STARTMENU #include <asm/sharp_apm.h> #ifndef APM_IOC_BATTERY_BACK_CHK #define APM_IOC_BATTERY_BACK_CHK _IO(APM_IOC_MAGIC, 32) #endif #ifndef APM_IOC_BATTERY_MAIN_CHK #define APM_IOC_BATTERY_MAIN_CHK _IO(APM_IOC_MAGIC, 33) #endif #include <unistd.h> #include <stdio.h> #include <signal.h> #include <fcntl.h> #include <sys/ioctl.h> #include <sys/ioctl.h> #include <asm/sharp_char.h> #define QPE_HAVE_MEMALERTER #define QPE_MEMALERTER_IMPL \ static void sig_handler(int sig) \ { \ switch (sig) { \ case SIGHUP: \ memstate = VeryLow; \ break; \ case SIGUSR1: \ memstate = Normal; \ break; \ case SIGUSR2: \ memstate = Low; \ break; \ } \ } \ static void initMemalerter() \ { \ struct sigaction sa; \ memset(&sa, '\0', sizeof sa); \ sa.sa_handler = sig_handler; \ sa.sa_flags = SA_RESTART; \ if (sigaction(SIGHUP, &sa, NULL) < 0) { \ return; \ } \ if (sigaction(SIGUSR1, &sa, NULL) < 0) { \ return; \ } \ if (sigaction(SIGUSR2, &sa, NULL) < 0) { \ return; \ } \ FILE *fo = fopen("/proc/sys/vm/freepg_signal_proc", "w"); \ \ if (!fo) \ return; \ fprintf(fo, "qpe\n"); \ fclose(fo); \ } #define QPE_INITIAL_NUMLOCK_STATE \ { \ bool numLock = FALSE; \ sharp_kbdctl_modifstat st; \ int dev = ::open("/dev/sharp_kbdctl", O_RDWR); \ if( dev >= 0 ) { \ memset(&st, 0, sizeof(st)); \ st.which = 3; \ int ret = ioctl(dev, SHARP_KBDCTL_GETMODIFSTAT, (char*)&st); \ if( !ret ) \ numLock = (bool)st.stat; \ ::close(dev); \ } \ return numLock; \ } diff --git a/library/custom-simpad.h b/library/custom-simpad.h new file mode 100644 index 0000000..3872dfd --- a/dev/null +++ b/library/custom-simpad.h @@ -0,0 +1,7 @@ +/* + * GPLv2 only zecke@handhelds.org + hOlgAr + */ + + +#define QPE_NEED_CALIBRATION
\ No newline at end of file diff --git a/library/global.cpp b/library/global.cpp index 189b830..5c89430 100644 --- a/library/global.cpp +++ b/library/global.cpp @@ -583,248 +583,203 @@ void Global::invoke(const QString &c) #ifdef QT_NO_QWS_MULTIPROCESS QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); #else QStrList slist; unsigned int j; for ( j = 0; j < list.count(); j++ ) slist.append( list[j].utf8() ); const char **args = new (const char *)[slist.count() + 1]; for ( j = 0; j < slist.count(); j++ ) args[j] = slist.at(j); args[j] = NULL; #if !defined(QT_NO_COP) // an attempt to show a wait... // more logic should be used, but this will be fine for the moment... QCopEnvelope ( "QPE/System", "busy()" ); #endif #ifdef HAVE_QUICKEXEC QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; qDebug("libfile = %s", libexe.latin1() ); if ( QFile::exists( libexe ) ) { qDebug("calling quickexec %s", libexe.latin1() ); quickexecv( libexe.utf8().data(), (const char **)args ); } else #endif { bool success = false; int pfd [2]; if ( ::pipe ( pfd ) < 0 ) pfd [0] = pfd [1] = -1; pid_t pid = ::fork ( ); if ( pid == 0 ) { // child for ( int fd = 3; fd < 100; fd++ ) { if ( fd != pfd [1] ) ::close ( fd ); } ::setpgid ( ::getpid ( ), ::getppid ( )); // Closing of fd[1] indicates that the execvp succeeded! if ( pfd [1] >= 0 ) ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); // Try bindir first, so that foo/bar works too ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); ::execvp ( args [0], (char * const *) args ); char resultByte = 1; if ( pfd [1] >= 0 ) ::write ( pfd [1], &resultByte, 1 ); ::_exit ( -1 ); } else if ( pid > 0 ) { success = true; if ( pfd [1] >= 0 ) ::close ( pfd [1] ); if ( pfd [0] >= 0 ) { while ( true ) { char resultByte; int n = ::read ( pfd [0], &resultByte, 1 ); if ( n == 1 ) { success = false; break; } if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR ))) continue; break; // success } ::close ( pfd [0] ); } } if ( success ) StartingAppList::add( list[0] ); else QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 ); } #endif //QT_NO_QWS_MULTIPROCESS } /*! Executes the application identfied by \a c, passing \a document if it isn't null. Note that a better approach might be to send a QCop message to the application's QPE/Application/\e{appname} channel. */ void Global::execute( const QString &c, const QString& document ) { - if ( qApp->type() != QApplication::GuiServer ) { // ask the server to do the work #if !defined(QT_NO_COP) - if ( document.isNull() ) { - QCopEnvelope e( "QPE/System", "execute(QString)" ); - e << c; - } else { - QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); - e << c << document; - } -#endif - return; - } - - // Attempt to execute the app using a builtin class for the app first - // else try and find it in the bin directory - if (builtin) { - for (int i = 0; builtin[i].file; i++) { - if ( builtin[i].file == c ) { - if ( running[i] ) { - if ( !document.isNull() && builtin[i].documentary ) - setDocument(running[i], document); - running[i]->raise(); - running[i]->show(); - running[i]->setActiveWindow(); - } else { - running[i] = builtin[i].func( builtin[i].maximized ); - } -#ifndef QT_NO_COP - QCopEnvelope e("QPE/System", "notBusy(QString)" ); - e << c; // that was quick ;-) -#endif - return; - } - } - } - - //Global::invoke(c, document); - - // Convert the command line in to a list of arguments - QStringList list = QStringList::split(QRegExp(" *"),c); - -#if !defined(QT_NO_COP) - QString ap=list[0]; - - qDebug("executing %s", ap.latin1() ); - - /* if need be, sending a qcop message will result in an invoke, see - preceeding function */ - invoke( ap ); - //{ QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } - if ( !document.isEmpty() ) { - QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" ); - env << document; + if ( document.isNull() ) { + QCopEnvelope e( "QPE/System", "execute(QString)" ); + e << c; + } else { + QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); + e << c << document; } #endif + return; } /*! Returns the string \a s with the characters '\', '"', and '$' quoted by a preceeding '\'. \sa stringQuote() */ QString Global::shellQuote(const QString& s) { QString r="\""; for (int i=0; i<(int)s.length(); i++) { char c = s[i].latin1(); switch (c) { case '\\': case '"': case '$': r+="\\"; } r += s[i]; } r += "\""; return r; } /*! Returns the string \a s with the characters '\' and '"' quoted by a preceeding '\'. \sa shellQuote() */ QString Global::stringQuote(const QString& s) { QString r="\""; for (int i=0; i<(int)s.length(); i++) { char c = s[i].latin1(); switch (c) { case '\\': case '"': r+="\\"; } r += s[i]; } r += "\""; return r; } /*! Finds all documents on the system's document directories which match the filter \a mimefilter, and appends the resulting DocLnk objects to \a folder. */ void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) { QString homedocs = QString(getenv("HOME")) + "/Documents"; DocLnkSet d(homedocs,mimefilter); folder->appendFrom(d); /** let's do intellegint way of searching these files * a) the user don't want to check mediums global * b) the user wants to check but use the global options for it * c) the user wants to check it but not this medium * d) the user wants to check and this medium as well * * In all cases we need to apply a different mimefilter to * the medium. * a) mimefilter.isEmpty() we need to apply the responding filter * either the global or the one on the medium * * b) mimefilter is set to an application we need to find out if the * mimetypes are included in the mime mask of the medium */ StorageInfo storage; const QList<FileSystem> &fs = storage.fileSystems(); QListIterator<FileSystem> it ( fs ); for ( ; it.current(); ++it ) { if ( (*it)->isRemovable() ) { // let's find out if we should search on it // this is a candidate look at the cf and see if we should search on it QString path = (*it)->path(); if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) continue; DocLnkSet ide( path, mimefilter ); folder->appendFrom(ide); } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { QString path = (*it)->path() + "/Documents"; DocLnkSet ide( path, mimefilter ); folder->appendFrom(ide); } } } QStringList Global::languageList() { QString lang = getenv("LANG"); QStringList langs; langs.append(lang); int i = lang.find("."); if ( i > 0 ) lang = lang.left( i ); i = lang.find( "_" ); diff --git a/library/inputmethodinterface.h b/library/inputmethodinterface.h index 88a121d..488f601 100644 --- a/library/inputmethodinterface.h +++ b/library/inputmethodinterface.h @@ -1,64 +1,75 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** 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. ** **********************************************************************/ #ifndef INPUTMETHODINTERFACE_H #define INPUTMETHODINTERFACE_H #include <qpe/qcom.h> #include <qnamespace.h> #include <qstring.h> #ifndef QT_NO_COMPONENT // {637A8A14-AF98-41DA-969A-2BD16ECDA8C7} # ifndef IID_InputMethod # define IID_InputMethod QUuid( 0x637a8a14, 0xaf98, 0x41da, 0x96, 0x9a, 0x2b, 0xd1, 0x6e, 0xcd, 0xa8, 0xc7) # endif #endif class QWidget; class QPixmap; class QObject; class QWSInputMethod; struct InputMethodInterface : public QUnknownInterface { virtual QWidget *inputMethod( QWidget *parent, Qt::WFlags f ) = 0; virtual void resetState() = 0; virtual QPixmap *icon() = 0; virtual QString name() = 0; virtual void onKeyPress( QObject *receiver, const char *slot ) = 0; }; -// {70F0991C-8282-4625-A279-BD9D7D959FF6} +// {70F0991C-8282-4625-A279-BD9D7D959FF6} #ifndef IID_ExtInputMethod #define IID_ExtInputMethod QUuid( 0x70f0991c, 0x8282, 0x4625, 0xa2, 0x79, 0xbd, 0x9d, 0x7d, 0x95, 0x9f, 0xf6) #endif struct ExtInputMethodInterface : public QUnknownInterface { - virtual QWSInputMethod *inputMethod() = 0; - virtual QPixmap *icon() = 0; + //identifying functions. virtual QString name() = 0; - virtual QWidget *widget( QWidget *parent, Qt::WFlags f )= 0; + virtual QPixmap *icon() = 0; + + // state managment. + virtual void resetState() = 0; + + virtual QWidget *keyboardWidget( QWidget *parent, Qt::WFlags f ) = 0; + // filenames, not menu names. + virtual QStringList compatible() = 0; + + virtual QWSInputMethod *inputMethod() = 0; + virtual QWidget *statusWidget( QWidget *parent, Qt::WFlags f )= 0; + + virtual void qcopReceive( const QCString &msg, const QByteArray &data )= 0; }; #endif diff --git a/library/qcopenvelope_qws.cpp b/library/qcopenvelope_qws.cpp index 81bb0f5..0aac32b 100644 --- a/library/qcopenvelope_qws.cpp +++ b/library/qcopenvelope_qws.cpp @@ -9,165 +9,139 @@ ** 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. ** **********************************************************************/ #ifndef QT_NO_COP #include "qcopenvelope_qws.h" #endif #include "global.h" #include <qbuffer.h> #include <qdatastream.h> #include <qfile.h> #include <unistd.h> #include <errno.h> #include <sys/file.h> #include <sys/types.h> #include <sys/stat.h> #include <time.h> #ifndef QT_NO_COP /*! \class QCopEnvelope qcopenvelope_qws.h \brief The QCopEnvelope class encapsulates and sends QCop messages over QCopChannels. QCop messages allow applications to communicate with each other. These messages are sent using QCopEnvelope, and received by connecting to a QCopChannel. To send a message, use the following protocol: \code QCopEnvelope e(channelname, messagename); e << parameter1 << parameter2 << ...; \endcode For messages without parameters, simply use: \code QCopEnvelope e(channelname, messagename); \endcode (Do not try to simplify this further as it may confuse some compilers.) The \c{channelname} of channels within Qtopia all start with "QPE/". The \c{messagename} is a function identifier followed by a list of types in parentheses. There is no whitespace in the message name. To receive a message, you will generally just use your application's predefined QPE/Application/\e{appname} channel (see QPEApplication::appMessage()), but you can make another channel and connect it to a slot like this: \code myChannel = new QCopChannel( "QPE/FooBar", this ); connect( myChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(fooBarMessage( const QCString &, const QByteArray &)) ); \endcode See also, the \link qcop.html list of Qtopia messages\endlink. */ /*! Constructs a QCopEnvelope that will write \a message to \a channel. If \a message has parameters, you must then use operator<<() to add these parameters to the envelope. */ QCopEnvelope::QCopEnvelope( const QCString& channel, const QCString& message ) : QDataStream(new QBuffer), ch(channel), msg(message) { device()->open(IO_WriteOnly); } /*! Writes the message and then destroys the QCopEnvelope. */ QCopEnvelope::~QCopEnvelope() { QByteArray data = ((QBuffer*)device())->buffer(); const int pref=16; if ( qstrncmp(ch.data(),"QPE/Application/",pref)==0 ) { QString qcopfn("/tmp/qcop-msg-"); qcopfn += ch.mid(pref); QFile qcopfile(qcopfn); if ( qcopfile.open(IO_WriteOnly | IO_Append) ) { +#ifndef Q_OS_WIN32 if(flock(qcopfile.handle(), LOCK_EX)) { - /* some error occured */ + /* some error occurred */ qWarning(QString("Failed to obtain file lock on %1 (%2)") .arg(qcopfn).arg( errno )); } - /* file locked, but might be stale (e.g. program for whatever - reason did not start). I modified more than 1 minute ago, - truncate the file */ - struct stat buf; - time_t t; - if (!fstat(qcopfile.handle(), &buf) && (time(&t) != (time_t)-1) ) { - // success on fstat, lets compare times - if (buf.st_ctime + 60 < t) { - qWarning("stale file " + qcopfn + " found. Truncating"); - ftruncate(qcopfile.handle(), 0); - qcopfile.reset(); - } +#endif + { + QDataStream ds(&qcopfile); + ds << ch << msg << data; + qcopfile.flush(); +#ifndef Q_OS_WIN32 + flock(qcopfile.handle(), LOCK_UN); +#endif + qcopfile.close(); } - if ( !QCopChannel::isRegistered(ch) ) { - int fsize = qcopfile.size(); - { - QDataStream ds(&qcopfile); - ds << ch << msg << data; - flock(qcopfile.handle(), LOCK_UN); - qcopfile.close(); - } - - if (fsize == 0) { - QString cmd = ch.mid(pref); - Global::execute(cmd); - } - - char c; - for (int i=0; (c=msg[i]); i++) { - if ( c == ' ' ) { - // Return-value required - // ###### wait for it - break; - } else if ( c == '(' ) { - // No return value - break; - } - } - goto end; - } // endif isRegisterd - flock(qcopfile.handle(), LOCK_UN); - qcopfile.close(); - qcopfile.remove(); + QByteArray b; + QDataStream stream(b, IO_WriteOnly); + stream << QString(ch.mid(pref)); + QCopChannel::send("QPE/Server", "processQCop(QString)", b); + delete device(); + return; } else { - qWarning(QString("Failed to obtain file lock on %1") + qWarning(QString("Failed to open file %1") .arg(qcopfn)); } // endif open } else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) { // If this is a message that should go along the SOAP channel, we move the // endpoint URL to the data section. QString endpoint = ch.mid(9); - + ch = "QPE/SOAP"; // Since byte arrays are explicitly shared, this is appended to the data variable.. *this << endpoint; } + QCopChannel::send(ch,msg,data); -end: delete device(); } #endif diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index d1a7cd2..b1b7ed4 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp @@ -1,149 +1,152 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** 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> + +#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> #endif #include "global.h" #include "resource.h" #if QT_VERSION <= 230 && defined(QT_NO_CODECS) #include "qutfcodec.h" #endif #include "config.h" #include "network.h" #ifdef QWS #include "fontmanager.h" #endif #include "alarmserver.h" #include "applnk.h" #include "qpemenubar.h" #include "textcodecinterface.h" #include "imagecodecinterface.h" #include <unistd.h> #include <sys/file.h> #include <sys/ioctl.h> #include <sys/soundcard.h> #include "qt_override_p.h" class QPEApplicationData { public: QPEApplicationData ( ) : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), keep_running( true ), qpe_main_widget( 0 ) { 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; 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; QList<QCopRec> qcopq; 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(); } static void show_mx(QWidget* mw, bool nomaximize) { @@ -212,537 +215,628 @@ public: else if ( keep_running ) { show_mx(mw, nomax); } } void loadTextCodecs() { QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; QDir dir( path, "lib*.so" ); QStringList list; if ( dir. exists ( )) list = dir.entryList(); QStringList::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { TextCodecInterface *iface = 0; QLibrary *lib = new QLibrary( path + "/" + *it ); if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { QValueList<int> mibs = iface->mibEnums(); for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { (void)iface->createForMib(*i); // ### it exists now; need to remember if we can delete it } } else { lib->unload(); delete lib; } } } void loadImageCodecs() { QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; QDir dir( path, "lib*.so" ); QStringList list; if ( dir. exists ( )) list = dir.entryList(); QStringList::Iterator it; 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 { const QMimeSource * r = QMimeSourceFactory::data( abs_name ); if ( !r ) { int sl = abs_name.length(); do { sl = abs_name.findRev( '/', sl - 1 ); QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; int dot = name.findRev( '.' ); if ( dot >= 0 ) name = name.left( dot ); QImage img = Resource::loadImage( name ); if ( !img.isNull() ) { delete resImage; resImage = new QImageDrag( img ); r = resImage; } } while ( !r && sl > 0 ); } return r; } private: mutable QImageDrag *resImage; }; +static int& hack(int& i) +{ +#if QT_VERSION <= 230 && defined(QT_NO_CODECS) + // These should be created, but aren't in Qt 2.3.0 + (void)new QUtf8Codec; + (void)new QUtf16Codec; +#endif + return i; +} + static int muted = 0; static int micMuted = 0; static void setVolume( int t = 0, int percent = -1 ) { switch ( t ) { case 0: { Config cfg( "qpe" ); cfg.setGroup( "Volume" ); if ( percent < 0 ) percent = cfg.readNumEntry( "VolumePercent", 50 ); int fd = 0; if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { int vol = muted ? 0 : percent; // set both channels to same volume vol |= vol << 8; ioctl( fd, MIXER_WRITE( 0 ), &vol ); ::close( fd ); } } break; } } static void setMic( int t = 0, int percent = -1 ) { switch ( t ) { case 0: { Config cfg( "qpe" ); cfg.setGroup( "Volume" ); if ( percent < 0 ) percent = cfg.readNumEntry( "Mic", 50 ); int fd = 0; int mic = micMuted ? 0 : percent; if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); ::close( fd ); } } break; } } static void setBass( int t = 0, int percent = -1 ) { switch ( t ) { case 0: { Config cfg( "qpe" ); cfg.setGroup( "Volume" ); if ( percent < 0 ) percent = cfg.readNumEntry( "BassPercent", 50 ); int fd = 0; int bass = percent; if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); ::close( fd ); } } break; } } static void setTreble( int t = 0, int percent = -1 ) { switch ( t ) { case 0: { Config cfg( "qpe" ); cfg.setGroup( "Volume" ); if ( percent < 0 ) percent = cfg.readNumEntry( "TreblePercent", 50 ); int fd = 0; int treble = percent; if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); ::close( fd ); } } break; } } /*! \class QPEApplication qpeapplication.h \brief The QPEApplication class implements various system services that are available to all Qtopia applications. Simply by using QPEApplication instead of QApplication, a standard Qt application becomes a Qtopia application. It automatically follows style changes, quits and raises, and in the case of \link docwidget.html document-oriented\endlink applications, changes the currently displayed document in response to the environment. To create a \link docwidget.html document-oriented\endlink application use showMainDocumentWidget(); to create a non-document-oriented application use showMainWidget(). The keepRunning() function indicates whether the application will continue running after it's processed the last \link qcop.html QCop\endlink message. This can be changed using setKeepRunning(). A variety of signals are emitted when certain events occur, for example, timeChanged(), clockChanged(), weekChanged(), dateFormatChanged() and volumeChanged(). If the application receives a \link qcop.html QCop\endlink message on the application's QPE/Application/\e{appname} channel, the appMessage() signal is emitted. There are also flush() and reload() signals, which are emitted when synching begins and ends respectively - upon these signals, the application should save and reload any data files that are involved in synching. Most of these signals will initially be received and unfiltered through the appMessage() signal. This class also provides a set of useful static functions. The qpeDir() and documentDir() functions return the respective paths. The grabKeyboard() and ungrabKeyboard() functions are used to control whether the application takes control of the device's physical buttons (e.g. application launch keys). The stylus' mode of operation is set with setStylusOperation() and retrieved with stylusOperation(). There are also setInputMethodHint() and inputMethodHint() functions. \ingroup qtopiaemb */ /*! \fn void QPEApplication::clientMoused() \internal */ /*! \fn void QPEApplication::timeChanged(); This signal is emitted when the time changes outside the normal passage of time, i.e. if the time is set backwards or forwards. */ /*! \fn void QPEApplication::clockChanged( bool ampm ); This signal is emitted when the user changes the clock's style. If \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, they want a 24-hour clock. */ /*! \fn void QPEApplication::volumeChanged( bool muted ) This signal is emitted whenever the mute state is changed. If \a muted is TRUE, then sound output has been muted. */ /*! \fn void QPEApplication::weekChanged( bool startOnMonday ) This signal is emitted if the week start day is changed. If \a startOnMonday is TRUE then the first day of the week is Monday; if \a startOnMonday is FALSE then the first day of the week is Sunday. */ /*! \fn void QPEApplication::dateFormatChanged(DateFormat) This signal is emitted whenever the date format is changed. */ /*! \fn void QPEApplication::flush() ### */ /*! \fn void QPEApplication::reload() */ + + +void QPEApplication::processQCopFile() +{ + QString qcopfn("/tmp/qcop-msg-"); + qcopfn += d->appName; // append command name + + QFile f(qcopfn); + if ( f.open(IO_ReadWrite) ) { +#ifndef Q_OS_WIN32 + flock(f.handle(), LOCK_EX); +#endif + QDataStream ds(&f); + QCString channel, message; + QByteArray data; + while(!ds.atEnd()) { + ds >> channel >> message >> data; + d->enqueueQCop(channel,message,data); + } + ::ftruncate(f.handle(), 0); +#ifndef Q_OS_WIN32 + f.flush(); + flock(f.handle(), LOCK_UN); +#endif + } +#endif +} + + /*! \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) This signal is emitted when a message is received on this application's QPE/Application/<i>appname</i> \link qcop.html QCop\endlink channel. The slot to which you connect this signal uses \a msg and \a data in the following way: \code void MyWidget::receive( const QCString& msg, const QByteArray& data ) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "someMessage(int,int,int)" ) { int a,b,c; stream >> a >> b >> c; ... } else if ( msg == "otherMessage(QString)" ) { ... } } \endcode \sa qcop.html Note that messages received here may be processed by qpe application and emitted as signals, such as flush() and reload(). */ /*! Constructs a QPEApplication just as you would construct a QApplication, passing \a argc, \a argv, and \a t. For applications, \a t should be the default, GuiClient. Only the Qtopia server passes GuiServer. */ QPEApplication::QPEApplication( int & argc, char **argv, Type t ) - : QApplication( argc, argv, t ) + : QApplication( hack(argc), argv, t ), pidChannel( 0 ) { d = new QPEApplicationData; d->loadTextCodecs(); d->loadImageCodecs(); int dw = desktop() ->width(); if ( dw < 200 ) { setFont( QFont( "vera", 8 ) ); AppLnk::setSmallIconSize( 10 ); AppLnk::setBigIconSize( 28 ); } #ifndef QT_QWS_SIMPAD else if ( dw > 600 ) { setFont( QFont( "vera", 16 ) ); AppLnk::setSmallIconSize( 24 ); AppLnk::setBigIconSize( 48 ); } #endif else if ( dw > 200 ) { setFont( QFont( "vera", 10 ) ); AppLnk::setSmallIconSize( 14 ); AppLnk::setBigIconSize( 32 ); } QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); + + + sysChannel = new QCopChannel( "QPE/System", this ); + connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), + this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) ); + +/* COde now in initapp */ +#if 0 #if defined(Q_WS_QWS) && !defined(QT_NO_COP) QString qcopfn( "/tmp/qcop-msg-" ); qcopfn += QString( argv[ 0 ] ); // append command name QFile f( qcopfn ); if ( f.open( IO_ReadOnly ) ) { flock( f.handle(), LOCK_EX ); } - sysChannel = new QCopChannel( "QPE/System", this ); - connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), - this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) ); + QCString channel = QCString( argv[ 0 ] ); channel.replace( QRegExp( ".*/" ), "" ); d->appName = channel; channel = "QPE/Application/" + channel; pidChannel = new QCopChannel( channel, this ); connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) ); if ( f.isOpen() ) { d->keep_running = FALSE; QDataStream ds( &f ); QCString channel, message; QByteArray data; while ( !ds.atEnd() ) { ds >> channel >> message >> data; d->enqueueQCop( channel, message, data ); } flock( f.handle(), LOCK_UN ); f.close(); f.remove(); } for ( int a = 0; a < argc; a++ ) { 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 ); #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 ) { 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 ); - } + if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { + QFont fn = FontManager::unicodeFont( FontManager::Proportional ); + setFont( fn ); + } #endif - - } + } #endif applyStyle(); if ( type() == GuiServer ) { setVolume(); } installEventFilter( this ); QPEMenuToolFocusManager::initialize(); #ifdef QT_NO_QWS_CURSOR // if we have no cursor, probably don't want tooltips QToolTip::setEnabled( FALSE ); #endif } + +#ifdef QTOPIA_INTERNAL_INITAPP +void QPEApplication::initApp( int argc, char **argv ) +{ + delete pidChannel; + d->keep_running = TRUE; + d->preloaded = FALSE; + d->forceshow = FALSE; + + QCString channel = QCString(argv[0]); + + channel.replace(QRegExp(".*/"),""); + d->appName = channel; + + qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 + + channel = "QPE/Application/" + channel; + pidChannel = new QCopChannel( channel, this); + connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)), + this, SLOT(pidMessage(const QCString &, const QByteArray &))); + + processQCopFile(); + d->keep_running = d->qcopq.isEmpty(); + + for (int a=0; a<argc; a++) { + 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); +} +#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. \sa setInputMethodHint() InputMethodHint */ QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) { if ( inputMethodDict && w ) return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); return Normal; } /*! \enum QPEApplication::InputMethodHint \value Normal the application sometimes needs text input (the default). \value AlwaysOff the application never needs text input. \value AlwaysOn the application always needs text input. */ /*! Hints to the system that widget \a w has use for text input methods as specified by \a mode. \sa inputMethodHint() InputMethodHint */ void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) { createInputMethodDict(); if ( mode == Normal ) { inputMethodDict->remove ( w ); } else { inputMethodDict->insert( w, ( void* ) mode ); } } class HackDialog : public QDialog { public: void acceptIt() { accept(); } void rejectIt() { reject(); } }; void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) { // specialised actions for certain widgets. May want to // add more stuff here. if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) && activePopupWidget() ->parentWidget() && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) key = Qt::Key_Return; if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) key = Qt::Key_Return; #ifdef QWS ke->simpleData.keycode = key; #endif } class HackWidget : public QWidget { public: bool needsOk() { return ( getWState() & WState_Reserved1 ); } }; /*! \internal */ #ifdef QWS bool QPEApplication::qwsEventFilter( QWSEvent * e ) { if ( !d->notbusysent && e->type == QWSEvent::Focus ) { @@ -1031,375 +1125,379 @@ void QPEApplication::applyStyle() if ( dec != d->decorationName ) { qwsSetDecoration( new QPEDecoration( dec ) ); d->decorationName = dec; } // Font QString ff = config.readEntry( "FontFamily", font().family() ); int fs = config.readNumEntry( "FontSize", font().pointSize() ); // don't set a custom font if ( nostyle & Opie::Force_Font ) { ff = "Vera"; fs = 10; } setFont ( QFont ( ff, fs ), true ); // revert to global blocking policy ... Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None; Opie::force_appearance &= ~nostyle; #endif } void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) { #ifdef Q_WS_QWS QDataStream stream( data, IO_ReadOnly ); if ( msg == "applyStyle()" ) { applyStyle(); } else if ( msg == "toggleApplicationMenu()" ) { QWidget *active = activeWindow ( ); if ( active ) { QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( ); bool oldactive = man-> isActive ( ); man-> setActive( !man-> isActive() ); if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" ); } } } else if ( msg == "setDefaultRotation(int)" ) { if ( type() == GuiServer ) { int r; stream >> r; setDefaultRotation( r ); } } else if ( msg == "setCurrentRotation(int)" ) { int r; stream >> r; setCurrentRotation( r ); } else if ( msg == "shutdown()" ) { if ( type() == GuiServer ) shutdown(); } else if ( msg == "quit()" ) { if ( type() != GuiServer ) tryQuit(); } else if ( msg == "forceQuit()" ) { if ( type() != GuiServer ) quit(); } else if ( msg == "restart()" ) { if ( type() == GuiServer ) restart(); } else if ( msg == "language(QString)" ) { if ( type() == GuiServer ) { QString l; stream >> l; QString cl = getenv( "LANG" ); if ( cl != l ) { if ( l.isNull() ) unsetenv( "LANG" ); else setenv( "LANG", l.latin1(), 1 ); restart(); } } } else if ( msg == "timeChange(QString)" ) { QString t; stream >> t; if ( t.isNull() ) unsetenv( "TZ" ); else setenv( "TZ", t.latin1(), 1 ); // emit the signal so everyone else knows... emit timeChanged(); } - else if ( msg == "execute(QString)" ) { - if ( type() == GuiServer ) { - QString t; - stream >> t; - Global::execute( t ); - } - } - else if ( msg == "execute(QString,QString)" ) { - if ( type() == GuiServer ) { - QString t, d; - stream >> t >> d; - Global::execute( t, d ); - } - } else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { if ( type() == GuiServer ) { QDateTime when; QCString channel, message; int data; stream >> when >> channel >> message >> data; AlarmServer::addAlarm( when, channel, message, data ); } } else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { if ( type() == GuiServer ) { QDateTime when; QCString channel, message; int data; stream >> when >> channel >> message >> data; AlarmServer::deleteAlarm( when, channel, message, data ); } } else if ( msg == "clockChange(bool)" ) { int tmp; stream >> tmp; emit clockChanged( tmp ); } else if ( msg == "weekChange(bool)" ) { int tmp; stream >> tmp; emit weekChanged( tmp ); } else if ( msg == "setDateFormat(DateFormat)" ) { DateFormat tmp; stream >> tmp; emit dateFormatChanged( tmp ); } else if ( msg == "setVolume(int,int)" ) { int t, v; stream >> t >> v; setVolume( t, v ); emit volumeChanged( muted ); } else if ( msg == "volumeChange(bool)" ) { stream >> muted; setVolume(); emit volumeChanged( muted ); } else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> int t, v; stream >> t >> v; setMic( t, v ); emit micChanged( micMuted ); } else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> stream >> micMuted; setMic(); emit micChanged( micMuted ); } else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> int t, v; stream >> t >> v; setBass( t, v ); } else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> setBass(); } else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> int t, v; stream >> t >> v; setTreble( t, v ); } else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> setTreble(); + } else if ( msg == "getMarkedText()" ) { + if ( type() == GuiServer ) { + const ushort unicode = 'C'-'@'; + const int scan = Key_C; + qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE ); + 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 } /*! \internal */ 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; } 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; } 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; d->keep_running = TRUE; /* so that quit will quit */ } else if ( msg == "enablePreload()" ) { if (d->qpe_main_widget) d->preloaded = TRUE; d->keep_running = TRUE; /* so next quit won't quit */ } else if ( msg == "raise()" ) { d->keep_running = TRUE; d->notbusysent = FALSE; raiseAppropriateWindow(); // Tell the system we're still chugging along... QCopEnvelope e("QPE/System", "appRaised(QString)"); e << d->appName; } else if ( msg == "flush()" ) { emit flush(); // we need to tell the desktop 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 { + } else if ( msg == "QPEProcessQCop()" ) { + processQCopFile(); + d->sendQCopQ(); + } + { 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 ) d->keep_running = p; } #endif } /*! Sets widget \a mw as the mainWidget() and shows it. For small windows, consider passing TRUE for \a nomaximize rather than the default FALSE. \sa showMainDocumentWidget() */ void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) { d->show(mw, nomaximize ); } /*! Sets widget \a mw as the mainWidget() and shows it. For small windows, consider passing TRUE for \a nomaximize rather than the default FALSE. This calls designates the application as a \link docwidget.html document-oriented\endlink application. The \a mw widget \e must have this slot: setDocument(const QString&). \sa showMainWidget() */ void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) { if ( mw && argc() == 2 ) Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); d->show(mw, nomaximize ); } /*! If an application is started via a \link qcop.html QCop\endlink message, the application will process the \link qcop.html QCop\endlink message and then quit. If the application calls this function while processing a \link qcop.html QCop\endlink message, after processing its outstanding \link qcop.html QCop\endlink messages the application will start 'properly' and show itself. \sa keepRunning() */ void QPEApplication::setKeepRunning() { if ( qApp && qApp->inherits( "QPEApplication" ) ) { QPEApplication * qpeApp = ( QPEApplication* ) qApp; qpeApp->d->keep_running = TRUE; } } /*! Returns TRUE if the application will quit after processing the current list of qcop messages; otherwise returns FALSE. \sa setKeepRunning() */ bool QPEApplication::keepRunning() const { return d->keep_running; } /*! \internal */ void QPEApplication::internalSetStyle( const QString &style ) { #if QT_VERSION >= 300 if ( style == "QPE" ) { setStyle( new QPEStyle ); } else { QStyle *s = QStyleFactory::create( style ); if ( s ) setStyle( s ); } diff --git a/library/qpeapplication.h b/library/qpeapplication.h index 65a6d33..770ea23 100644 --- a/library/qpeapplication.h +++ b/library/qpeapplication.h @@ -1,198 +1,204 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** 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. ** **********************************************************************/ #ifndef __QPE_APPLICATION_H__ #define __QPE_APPLICATION_H__ #include <stdlib.h> // for setenv() #include <qglobal.h> #include <qapplication.h> #include <qdialog.h> #include <qwsdisplay_qws.h> #if defined(_WS_QWS_) && !defined(Q_WS_QWS) #define Q_WS_QWS #endif #include "qpedecoration_qws.h" #include "timestring.h" class QCopChannel; class QPEApplicationData; class QWSEvent; class QWSKeyEvent; class QPEApplication : public QApplication { Q_OBJECT public: QPEApplication( int& argc, char **argv, Type=GuiClient ); ~QPEApplication(); static QString qpeDir(); static QString documentDir(); void applyStyle(); static int defaultRotation(); static void setDefaultRotation(int r); static void setCurrentRotation(int r); static void grabKeyboard(); static void ungrabKeyboard(); enum StylusMode { LeftOnly, RightOnHold // RightOnHoldLeftDelayed, etc. }; static void setStylusOperation( QWidget*, StylusMode ); static StylusMode stylusOperation( QWidget* ); enum InputMethodHint { Normal, AlwaysOff, AlwaysOn }; enum screenSaverHint { Disable = 0, DisableLightOff = 1, DisableSuspend = 2, Enable = 100 }; static void setInputMethodHint( QWidget *, InputMethodHint ); static InputMethodHint inputMethodHint( QWidget * ); void showMainWidget( QWidget*, bool nomax=FALSE ); void showMainDocumentWidget( QWidget*, bool nomax=FALSE ); static void showDialog( QDialog*, bool nomax=FALSE ); static int execDialog( QDialog*, bool nomax=FALSE ); + /* Merge setTempScreenSaverMode */ +#ifdef QTOPIA_INTERNAL_INITAPP + void initApp( int argv, char **argv ); +#endif static void setKeepRunning(); bool keepRunning() const; bool keyboardGrabbed() const; int exec(); signals: void clientMoused(); void timeChanged(); void clockChanged( bool pm ); void micChanged( bool muted ); void volumeChanged( bool muted ); void appMessage( const QCString& msg, const QByteArray& data); void weekChanged( bool startOnMonday ); void dateFormatChanged( DateFormat ); void flush(); void reload(); + /* linkChanged signal */ private slots: void systemMessage( const QCString &msg, const QByteArray &data ); void pidMessage( const QCString &msg, const QByteArray &data ); void removeSenderFromStylusDict(); void hideOrQuit(); protected: bool qwsEventFilter( QWSEvent * ); void internalSetStyle( const QString &style ); void prepareForTermination(bool willrestart); virtual void restart(); virtual void shutdown(); bool eventFilter( QObject *, QEvent * ); void timerEvent( QTimerEvent * ); bool raiseAppropriateWindow(); virtual void tryQuit(); #if QT_VERSION > 233 virtual void polish ( QWidget * ); // this is actually implemented in qt_override.cpp (!) #endif private: #ifndef QT_NO_TRANSLATION void installTranslation( const QString& baseName ); #endif void mapToDefaultAction( QWSKeyEvent *ke, int defKey ); + void processQCopFile(); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) QCopChannel *sysChannel; QCopChannel *pidChannel; #endif QPEApplicationData *d; bool reserved_sh; }; inline void QPEApplication::showDialog( QDialog* d, bool nomax ) { QSize sh = d->sizeHint(); int w = QMAX(sh.width(),d->width()); int h = QMAX(sh.height(),d->height()); if ( !nomax && ( w > qApp->desktop()->width()*3/4 || h > qApp->desktop()->height()*3/4 ) ) { d->showMaximized(); } else { d->resize(w,h); d->show(); } } inline int QPEApplication::execDialog( QDialog* d, bool nomax ) { showDialog(d,nomax); return d->exec(); } enum Transformation { Rot0, Rot90, Rot180, Rot270 }; /* from qgfxtransformed_qws.cpp */ inline int TransToDeg ( Transformation t ) { int d = static_cast<int>( t ); return d * 90; } inline Transformation DegToTrans ( int d ) { Transformation t = static_cast<Transformation>( d / 90 ); return t; } /* * Set current rotation of Opie, and rotation for newly started apps. * Differs from setDefaultRotation in that 1) it rotates currently running apps, * and 2) does not set deforient or save orientation to qpe.conf. */ inline void QPEApplication::setCurrentRotation( int r ) { // setTransformation has been introduced in Qt/Embedded 2.3.4 snapshots // for compatibility with the SharpROM use fallback to setDefaultTransformation() #if QT_VERSION > 233 Transformation e = DegToTrans( r ); setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); qApp->desktop()->qwsDisplay()->setTransformation( e ); #else setDefaultRotation( r ); #endif } #endif |