⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qpeapplication.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	AppLnkSet apps( appsPath );	QList<AppLnk> appsList = apps.children();	for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {	    if ( (*it)->exec() == appName ) {		mw->setIcon( (*it)->pixmap() );		mw->setCaption( (*it)->name() );		return TRUE;	    }	}    */	return FALSE;    }    void show(QWidget* mw, bool nomax)    {	setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );	nomaximize = nomax;	qpe_main_widget = mw;	qcopQok = TRUE;#ifndef QT_NO_COP	sendQCopQ();#endif	if ( preloaded ) {	    if(forceshow)		show_mx(mw,nomax, appName);	} else if ( keep_running ) {	    show_mx(mw,nomax, appName);	}    }#ifdef Q_WS_QWS    void loadTextCodecs()    {	QStringList list = textPluginLoader.list();	QStringList::Iterator it;	for ( it = list.begin(); it != list.end(); ++it ) {	    TextCodecInterface *iface = 0;	    if ( textPluginLoader.queryInterface( *it, 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		}	    }	}    }    void loadImageCodecs()    {	QStringList list = imagePluginLoader.list();	QStringList::Iterator it;	for ( it = list.begin(); it != list.end(); ++it ) {	    ImageCodecInterface *iface = 0;	    if ( imagePluginLoader.queryInterface( *it, 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		}	    }	}    }#endif#ifdef Q_WS_QWS    PluginLoaderIntern styleLoader;    StyleInterface *styleIface;    QString styleName;    PluginLoaderIntern textPluginLoader;    PluginLoaderIntern imagePluginLoader;#endif    QString decorationName;    QString decorationTheme;#ifdef QTOPIA_PHONE    QGuardedPtr<ContextMenu> editMenu;    QStringList iconPath;#endif};class ResourceMimeFactory : public QMimeSourceFactory {public:    ResourceMimeFactory() : resImage(0)    {#ifdef Q_WS_QWS	setFilePath( Global::helpPath() );	setExtensionType("html","text/html;charset=UTF-8");#endif    }    ~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);#ifdef Q_WS_QWS		QImage img = Resource::loadImage(name);		if( img.isNull() )		    img = qtopia_internal_loadIconSet(name).pixmap( QIconSet::Small, TRUE ).convertToImage();		if ( !img.isNull() ) {		    ResourceMimeFactory *that = (ResourceMimeFactory*)this;		    delete that->resImage;		    that->resImage = new QImageDrag( img );		    r = resImage;		}#endif	    } while (!r && sl>0);	}	return r;    }private:    QImageDrag *resImage;};int qtopia_muted=0;#ifndef QTOPIA_DESKTOPstatic void setVolume(int t=0, int percent=-1){    switch (t) {	case 0: {	    Config cfg("Sound");	    cfg.setGroup("System");	    if ( percent < 0 ) {		percent = cfg.readNumEntry("Volume",50);		qtopia_muted = cfg.readBoolEntry("Muted",false);            }	    int fd = 0;#ifndef Q_OS_WIN32	    if ((fd = open("/dev/mixer", O_RDWR))>=0) { // Some devices require this, O_RDONLY doesn't always work		int vol = qtopia_muted ? 0 : percent;		// set both channels to same volume		vol |= vol << 8;		ioctl(fd, MIXER_WRITE(0), &vol);		::close(fd);	    }#else	    HWAVEOUT handle;      	    WAVEFORMATEX formatData;	    formatData.cbSize = sizeof(WAVEFORMATEX);	    formatData.wFormatTag = WAVE_FORMAT_PCM;	    formatData.nAvgBytesPerSec = 4 * 44000;	    formatData.nBlockAlign = 4;	    formatData.nChannels = 2;	    formatData.nSamplesPerSec = 44000;	    formatData.wBitsPerSample = 16;	    waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL);	    int vol = qtopia_muted ? 0 : percent;	    unsigned int volume = (vol << 24) | (vol << 8);	    if ( waveOutSetVolume( handle, volume ) )		qDebug( "set volume of audio device failed" );	    waveOutClose( handle );#endif	} break;    }}#endifstatic 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;}#ifdef Q_WS_QWSstatic bool forced_off = FALSE;static int curbl=-1;static int backlight(){    if ( curbl == -1 ) {	// Read from config	Config config( "qpe" );	config.setGroup( "Screensaver" );	curbl = config.readNumEntry("Brightness",255);    }    return curbl;}void qpe_setBrightness(int bright);static void setBacklight(int bright){    if ( bright == -3 ) {	// Forced on	forced_off = FALSE;	bright = -1;    }    if ( forced_off && bright != -2 )	return;    if ( bright == -2 ) {	// Toggle between off and on	bright = curbl ? 0 : -1;	forced_off = !bright;    }    if ( bright == -1 ) {	// Read from config	Config config( "qpe" );	config.setGroup( "Screensaver" );	bright = config.readNumEntry("Brightness",255);    }    qpe_setBrightness(bright);    curbl = bright;}void qpe_setBacklight(int bright) { setBacklight(bright); }#endifstatic bool dim_on = FALSE;static bool lightoff_on = FALSE;static bool networkedsuspend_on = FALSE;static bool poweredsuspend_on = FALSE;#ifdef QTOPIA_PHONEstatic int homescreen_level = -1;#endif#ifdef Q_WS_QWSstatic int disable_suspend = 100;#ifndef QTOPIA_PHONEstatic bool powerOnlineStopsSuspend(){    return !poweredsuspend_on && PowerStatusManager::readStatus().acStatus() == PowerStatus::Online;}static bool networkOnlineStopsSuspend(){    return !networkedsuspend_on && Network::networkOnline();}#endifclass QPEScreenSaver : public QWSScreenSaver{public:    QPEScreenSaver()    {    }    void restore()    {	setBacklight(-1);    }    bool save(int level)    {#ifdef QTOPIA_PHONE        if (disable_suspend > 2 && homescreen_level != -1 && homescreen_level <= level) {            if (homescreen_level == level) {#ifndef QT_NO_COP                QCopEnvelope showHome( "QPE/System", "showHomeScreen()" );                QCopEnvelope closeApps( "QPE/System", "close()" );                return TRUE;#endif                  } else                --level;         }#endif	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:#ifndef QTOPIA_PHONE	    if ( disable_suspend > 2 && !powerOnlineStopsSuspend() && !networkOnlineStopsSuspend() )	    {                   if (PowerStatusManager::APMEnabled()) {    		    QWSServer::processKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );		    return FALSE;                } else                    return TRUE;            }#else            //no need to suspend in Phone Edition -> do nothing 	    return TRUE;#endif	    break;	}	return FALSE;    }    static const int eventBlockLevel = -1;};#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[5];    i1 = ssi(i1, config, "Dim","Interval_Dim", 30); // No tr    i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20);#ifndef QTOPIA_PHONE    i3 = ssi(i3, config, "","Interval", 60); // No tr#else     // phone edition doesn't have 3rd screensaver level#endif    //qDebug("screen saver intervals: %d %d %d", i1, i2, i3);    v[0] = QMAX( 1000*i1, 100);    v[1] = QMAX( 1000*i2, 100);#ifndef QTOPIA_PHONE    v[2] = QMAX( 1000*i3, 100);#else    v[2] = 0;#endif    v[3] = 0;    v[4] = 0;   #ifdef QTOPIA_PHONE    config.setGroup( "HomeScreen" );    bool showhomescreen_on = config.readBoolEntry("ShowHomeScreen", FALSE);    if (showhomescreen_on) {        int showhomescreen_interval;        showhomescreen_interval = 1000*config.readNumEntry("Interval_HomeScreen", 30);        for (int level=0; level < 5; level++) {            if (v[level] && v[level] < showhomescreen_interval)                showhomescreen_interval -= v[level];            else if (!v[level]) {                v[level]=showhomescreen_interval;                homescreen_level = level;                break;              } else {                for (int i = 3; i >= level; i--) {                    v[i+1] = v[i];                }                v[level] = showhomescreen_interval;                v[level+1] = QMAX(v[level+1]-showhomescreen_interval, 100);                homescreen_level = level;                break;            }        }        //qDebug(QString("%1 %2 %3 %4").arg(v[0]).arg(v[1]).arg(v[2]).arg(v[3]));    } else        homescreen_level = -1;#endif    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 #ifdef QTOPIA_PHONE            && !showhomescreen_on#endif        ){	QWSServer::setScreenSaverInterval(0);    }else{#if QT_VERSION > 237	QWSServer::setScreenSaverIntervals(v, QPEScreenSaver::eventBlockLevel);#else	QWSServer::setScreenSaverIntervals(v);#endif    }#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.*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -