📄 qpeapplication.cpp
字号:
static bool powerOnlineStopsSuspend(){ return !poweredsuspend_on && PowerStatusManager::readStatus().acStatus() == PowerStatus::Online;}static bool networkOnlineStopsSuspend(){ return !networkedsuspend_on && Network::networkOnline();}class QPEScreenSaver : public QWSScreenSaver{public: QPEScreenSaver() { } void restore() { setBacklight(-1); } bool save(int level) { switch ( level ) { case 0: if ( disable_suspend > 0 && dim_on ) { if (backlight() > 1) setBacklight(1); // lowest non-off } return TRUE; break; case 1: if ( disable_suspend > 1 && lightoff_on ) { setBacklight(0); // off } return TRUE; break; case 2: if ( disable_suspend > 2 && !powerOnlineStopsSuspend() && !networkOnlineStopsSuspend() ) { QWSServer::processKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); return FALSE; } return TRUE; break; } return FALSE; }};#endifstatic int ssi(int interval, Config &config, const QString &enable, const QString& value, int def){ if ( !enable.isEmpty() && config.readNumEntry(enable,0) == 0 ) return 0; if ( interval < 0 ) { // Restore screen blanking and power saving state interval = config.readNumEntry( value, def ); } return interval;}static void setScreenSaverIntervals(int i1, int i2, int i3){ Config config( "qpe" ); config.setGroup( "Screensaver" ); int v[4]; i1 = ssi(i1, config, "Dim","Interval_Dim", 30); // No tr i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20); i3 = ssi(i3, config, "","Interval", 60); // No tr //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); v[0] = QMAX( 1000*i1, 100); v[1] = QMAX( 1000*i2, 100); v[2] = QMAX( 1000*i3, 100); v[3] = 0; dim_on = ( (i1 != 0) ? config.readNumEntry("Dim",1) : FALSE ); lightoff_on = ( (i2 != 0 ) ? config.readNumEntry("LightOff",1) : FALSE ); poweredsuspend_on = config.readNumEntry("Suspend",0); networkedsuspend_on = config.readNumEntry("NetworkedSuspend",1);#ifdef Q_WS_QWS if ( !i1 && !i2 && !i3 ) QWSServer::setScreenSaverInterval(0); else QWSServer::setScreenSaverIntervals(v);#endif}#ifndef QTOPIA_DESKTOPstatic void setScreenSaverInterval(int interval){ setScreenSaverIntervals(-1,-1,interval);}#endif/*! \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*//*! \enum QPEApplication::screenSaverHint \value Disable the screen should never blank \value DisableLightOff the screen should never blank and the backlight should never switch off \value DisableSuspend the screen should blank when the device goes into suspend mode \value Enable screen blanking and switching off the backlight are both enabled Currently, this is only used internally.*//*! \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. If the application offers the TimeMonitor service, it will get the QCop message that causes this signal even if it is not running, thus allowing it to update any alarms or other time-related records.*//*! \fn void QPEApplication::categoriesChanged(); This signal is emitted whenever a category is added, removed or edited. Note, on Qtopia 1.5.0, this signal is never emitted.*//*! \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}/*! 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{ 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 AppLnk::setSmallIconSize(10); 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 } 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#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; 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 << "libqpe"; qms << "libqtopia"; qms << d->appName; QStringList langs = Global::languageList(); 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(this); tfn = qpeDir() + "i18n/" + lang + "/" + *qmit + ".qm"; if ( trans->load( tfn )) installTranslator( trans ); else delete trans; } //###language/font hack; should look it up somewhere#ifdef Q_WS_QWS if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { QFont fn = FontManager::unicodeFont( FontManager::Proportional ); setFont( fn ); }#endif }#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; 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);}#endifstatic 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. \sa inputMethodHint() setInputMethodHint()*//*! 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -