📄 qpeapplication.cpp
字号:
/*! \fn void QPEApplication::linkChanged( const QString &linkFile ); This signal is emitted whenever an AppLnk or DocLnk is stored, removed or edited. \a linkFile contains the name of the link that is being modified.*//*! \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. \warning if you use the TimeString functions, you should use TimeString::connectChange() instead. \sa dateFormatChanged()*//*! \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. \warning if you use the TimeString functions, you should use TimeString::connectChange() instead. \sa clockChanged()*//*! \fn void QPEApplication::flush() \internal*//*! \fn void QPEApplication::reload() \internal*//*! \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 Note that messages received here may be processed by qpe application and emitted as signals, such as flush() and reload().*/void QPEApplication::processQCopFile(){#ifndef QTOPIA_DESKTOP#ifdef Q_OS_UNIX QString qcopfn(Global::tempDir()+ "qcop-msg-"); qcopfn += d->appName; // append command name#else QString qcopfn(Global::tempDir() + "qcop-msg-"); if (QApplication::winVersion() != Qt::WV_98) qcopfn += d->appName; // append command name else qcopfn += d->appName.lower(); // append command name#endif 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); } Global::truncateFile(f, 0);#ifndef Q_OS_WIN32 f.flush(); flock(f.handle(), LOCK_UN);#endif }#endif}#ifndef QT_NO_TRANSLATION#include "global_qtopiapaths.cpp"void QPEApplication::loadTranslations( const QStringList& qms ){ QStringList langs = Global::languageList(); QStringList qpepaths = global_qtopiapaths(); for (QStringList::ConstIterator qit = qpepaths.begin(); qit!=qpepaths.end(); ++qit) { for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { QString lang = *it; QTranslator * trans; QString tfn; for (QStringList::ConstIterator qmit = qms.begin(); qmit!=qms.end(); ++qmit) { trans = new QTranslator(qApp); tfn = *qit + "i18n/" + lang + "/" + *qmit + ".qm"; if ( trans->load( tfn )) qApp->installTranslator( trans ); else delete trans; } } }}#endifstatic void qtopiaMsgHandler(QtMsgType type, const char* msg){ switch ( type ) { case QtDebugMsg:#ifdef DEBUG fprintf( stderr, "Debug: %s\n", msg );#endif break; case QtWarningMsg: fprintf( stderr, "Warning: %s\n", msg ); break; case QtFatalMsg: fprintf( stderr, "Fatal: %s\n", msg ); abort(); }}#if defined (_WS_QWS_)extern bool qt_lineedit_password_visible_on_focus;#endif/*! 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( hack(argc), argv, t )#if defined(Q_WS_QWS) && !defined(QT_NO_COP), pidChannel(0)#endif#if defined(QTOPIA_TEST), hasPerfMonitor(0)#endif {#if defined (_WS_QWS_) // pdas and phones have uncertain input, so as long as line edit // has focus, should be able to see password text. qt_lineedit_password_visible_on_focus = TRUE;#endif #if defined(Q_WS_QWS) && defined(Q_OS_UNIX) QString dataDir(Global::tempDir()); if ( mkdir( dataDir.latin1(), 0700 ) ) { if ( errno != EEXIST ) { qFatal( QString("Cannot create Qtopia data directory: %1") .arg( dataDir ) ); } } struct stat buf; if ( lstat( dataDir.latin1(), &buf ) ) qFatal( QString( "stat failed for Qtopia data directory: %1" ) .arg( dataDir ) ); if ( !S_ISDIR( buf.st_mode ) ) qFatal( QString( "%1 is not a directory" ).arg( dataDir ) ); if ( buf.st_uid != getuid() ) qFatal( QString( "Qtopia data directory is not owned by user %1: %2" ) .arg( getuid() ).arg( dataDir ) ); if ( (buf.st_mode & 0677) != 0600 ) qFatal( QString( "Qtopia data directory has incorrect permissions: %1" ) .arg( dataDir ) );#endif qInstallMsgHandler(qtopiaMsgHandler);#ifdef QTOPIA_PHONE Config config( qtopia_internal_defaultButtonsFile(), Config::File ); config.setGroup( "Device" ); QString pi = config.readEntry( "PrimaryInput", "Keypad" ).lower(); // anything other than touchscreen means keypad modal editing gets enabled qt_modalEditingEnabled = pi != "touchscreen"; mousePreferred = !qt_modalEditingEnabled; qDebug( "Modal editing is %s", qt_modalEditingEnabled ? "ENABLED" : "DISABLED" );#endif QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. d = new QPEApplicationData;#ifdef Q_WS_QWS PluginLoaderIntern::init(); d->loadTextCodecs(); d->loadImageCodecs();#endif int dw = desktop()->width(); if ( dw < 200 ) { setFont( QFont( "helvetica", 8 ) );#ifdef Q_WS_QWS# ifdef QTOPIA_PHONE AppLnk::setSmallIconSize(16);# else AppLnk::setSmallIconSize(10);# endif AppLnk::setBigIconSize(28);#endif } else if ( dw > 600 ) { setFont( QFont( "helvetica", 12 ) );#ifdef Q_WS_QWS AppLnk::setSmallIconSize(24); AppLnk::setBigIconSize(48);#endif } else if ( dw > 400 ) { setFont( QFont( "helvetica", 12 ) );#ifndef Q_WS_QWS AppLnk::setSmallIconSize(16); AppLnk::setBigIconSize(32);#endif }#ifdef QTOPIA_PHONE setFont( QFont( "helvetica", 14, QFont::Normal ) );#endif QMimeSourceFactory::setDefaultFactory(new ResourceMimeFactory); connect(this, SIGNAL(lastWindowClosed()), this, SLOT(hideOrQuit()));#if defined(Q_WS_QWS) && !defined(QT_NO_COP) sysChannel = new QCopChannel( "QPE/System", this ); connect( sysChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(systemMessage(const QCString&,const QByteArray&)) ); #if 0 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&))); 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);#else initApp( argc, argv );#endif // #if 0#endif#if defined(Q_WS_QWS) FontDatabase::loadRenderers(); // load font factory plugins.#endif#ifndef QT_NO_TRANSLATION QStringList qms; qms << "qt"; qms << "libqpe"; qms << "libqtopia"; qms << "libqtopia2"; qms << d->appName; loadTranslations(qms);#endif applyStyle();#ifndef QTOPIA_DESKTOP if ( type() == GuiServer ) { setScreenSaverInterval(-1); setVolume();#ifdef Q_WS_QWS QWSServer::setScreenSaver(new QPEScreenSaver);#endif }#endif installEventFilter( this );#ifdef Q_WS_QWS QPEMenuToolFocusManager::initialize();#endif#ifdef QT_NO_QWS_CURSOR // if we have no cursor, probably don't want tooltips QToolTip::setEnabled( FALSE );#endif}#ifdef QTOPIA_INTERNAL_INITAPPvoid QPEApplication::initApp( int argc, char **argv ){ delete pidChannel; d->keep_running = TRUE; d->preloaded = FALSE; d->forceshow = FALSE;#ifdef Q_OS_UNIX QCString channel = QCString(argv[0]);#else QCString channel; if (QApplication::winVersion() != Qt::WV_98) channel += QString(argv[0]); // append command name else channel += QString(argv[0]).lower(); // append command name#endif channel.replace(QRegExp(".*/"),""); d->appName = channel; loadTranslations(QStringList()<<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; } }#ifdef QPE_LAZY_APPLICATION_SHUTDOWN if (!d->preloaded) { d->preloaded = TRUE; d->forceshow = TRUE; }#endif /* overide stored arguments */ setArgs(argc, argv);}#endifstruct InputMethodHintRec { InputMethodHintRec(QPEApplication::InputMethodHint h, const QString& p) : hint(h), param(p) {} QPEApplication::InputMethodHint hint; QString param;};static QPtrDict<InputMethodHintRec>* inputMethodDict=0;static void createInputMethodDict(){ if ( !inputMethodDict ) { inputMethodDict = new QPtrDict<InputMethodHintRec>; inputMethodDict->setAutoDelete(TRUE); }}/*! 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 ) { InputMethodHintRec* r = inputMethodDict->find(w); if ( r ) return r->hint; } return Normal;}/*! Returns the currently set hint parameter for widget \a w. \sa setInputMethodHint() InputMethodHint*/QString QPEApplication::inputMethodHintParam( QWidget* w ){ if ( inputMethodDict && w ) { InputMethodHintRec* r = inputMethodDict->find(w); if ( r ) return r->param; } return QString::null;}/*! \enum QPEApplication::InputMethodHint \value Normal the widget sometimes needs text input. \value AlwaysOff the widget never needs text input. \value AlwaysOn the widget always needs text input. \value Number the widget needs numeric input. \value PhoneNumber the widget needs phone-style numeric input. \value Words the widget needs word input. \value Text the widget needs non-word input. \value Named the widget needs special input, defined by param. Each input method may support a different range of special input types, but will default to Text if they do not know the type. By default, QLineEdit and QMultiLineEdit have the Words hint unless they have a QIntValidator, in which case they have the Number hint. This is appropriate for most cases, including the input of names (new names being added to the user's dictionary). All other widgets default to Normal mode. \sa inputMethodHint() setInputMethodHint()*//*! Hints to the system that widget \a w has use for the text input method specified by \a named. Such methods are input-method-specific and are defined by the files in $QPEDIR/etc/im/ for each input method. For example, the phone key input method includes support for the names input methods:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -