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

📄 applnk.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	    mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' );	    mLinkFile = file;	    mFile = config.readEntry("File", QString::null);	    if ( !mFile.isEmpty() && mFile[0] != '/' ) {		int slash = file.findRev('/');		if ( slash >= 0 ) {		    mFile = file.left(slash) + '/' + mFile;		}	    }	    d->mCatList = config.readListEntry("Categories", ';');	    if ( d->mCatList[0].toInt() < -1 ) {		// numeric cats in file! convert to text		Categories cat( 0 );		cat.load( categoryFileName() );		d->mCat.resize( d->mCatList.count() );		int i;		QStringList::ConstIterator it;		for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end();		      ++it, i++ ) {		    bool number;		    int id = (*it).toInt( &number );		    if ( !number ) {			// convert from text			id = cat.id( "Document View", *it ); // No tr			if ( id == 0 )			    id = cat.addCategory( "Document View", *it ); // No tr		    }		    d->mCat[i] = id;		}		d->updateCatListFromArray();	    }	}    }    mId = 0;}/*!  Returns a small pixmap associated with the application.  \sa bigPixmap() setIcon()*/const QPixmap& AppLnk::pixmap() const{    if ( mPixmap.isNull() ) {	AppLnk* that = (AppLnk*)this;	AppLnkPrivate::setPixmaps( that, TRUE );    }    return mPixmap;}/*!  Returns a large pixmap associated with the application.  \sa pixmap() setIcon()*/const QPixmap& AppLnk::bigPixmap() const{    if ( mBigPixmap.isNull() ) {	AppLnk* that = (AppLnk*)this;	AppLnkPrivate::setPixmaps( that, FALSE );    }    return mBigPixmap;}/*!  Returns the type of the AppLnk. For applications, games and  settings the type is \c Application; for documents the type is the  document's MIME type.*/QString AppLnk::type() const{    if ( mType.isNull() ) {	AppLnk* that = (AppLnk*)this;	QString f = file();	if ( !f.isNull() ) {	    MimeType mt(f);	    that->mType = mt.id();	    return that->mType;	}    }    return mType;}/*!  Returns the file associated with the AppLnk.  \sa exec() name()*/QString AppLnk::file() const{    if ( mFile.isNull() ) {	AppLnk* that = (AppLnk*)this;	QString ext = MimeType(mType).extension();	if ( !ext.isEmpty() )	    ext = "." + ext;	if ( !mLinkFile.isEmpty() ) {	    that->mFile =		mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop")		    ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile;	} else if ( mType.contains('/') ) {	    that->mFile =		QString(QDir::homeDirPath()+"/Documents/"+mType+"/"+safeFileName(that->mName));	    if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) {		int n=1;		QString nn;		while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext)			|| QFile::exists(nn+".desktop"))		    n++;		that->mFile = nn;	    }	    that->mLinkFile = that->mFile+".desktop";	    that->mFile += ext;	}	prepareDirectories(that->mFile);	if ( !that->mFile.isEmpty() ) {	    QFile f(that->mFile);	    if ( !f.open(IO_WriteOnly) )		that->mFile = QString::null;	    return that->mFile;	}    }    return mFile;}/*!  Returns the desktop file corresponding to this AppLnk.  \sa file() exec() name()*/QString AppLnk::linkFile() const{    if ( mLinkFile.isNull() ) {	AppLnk* that = (AppLnk*)this;	if ( type().contains('/') ) {#ifdef Q_WS_QWS	    StorageInfo storage;	    const FileSystem *fs = storage.fileSystemOf( that->mFile );	    if ( fs && fs->isRemovable() ) {		that->mLinkFile = fs->path();	    } else#else		qWarning("AppLnk::linkFile is using home as the root for windows");#endif	    {		that->mLinkFile = QDir::homeDirPath();	    }	    that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName);	    if ( QFile::exists(that->mLinkFile+".desktop") ) {		int n=1;		QString nn;		while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop"))		    n++;		that->mLinkFile = nn;	    }	    that->mLinkFile += ".desktop";	    storeLink();	}	return that->mLinkFile;    }    return mLinkFile;}/*!  Copies \a copy.*/AppLnk::AppLnk( const AppLnk &copy ){    mName = copy.mName;    mPixmap = copy.mPixmap;    mBigPixmap = copy.mBigPixmap;    mExec = copy.mExec;    mType = copy.mType;    mRotation = copy.mRotation;    mComment = copy.mComment;    mFile = copy.mFile;    mLinkFile = copy.mLinkFile;    mIconFile = copy.mIconFile;    mMimeTypes = copy.mMimeTypes;    mMimeTypeIcons = copy.mMimeTypeIcons;    mId = 0;    d = new AppLnkPrivate();    d->mCat = copy.d->mCat.copy();    d->mCatList = copy.d->mCatList;}/*!  Destroys the AppLnk. Note that if the AppLnk is currently a member  of an AppLnkSet, this will produce a run-time warning.  \sa AppLnkSet::add() AppLnkSet::remove()*/AppLnk::~AppLnk(){    if ( mId )	qWarning("Deleting AppLnk that is in an AppLnkSet");    if ( d )	delete d;}/*!  \overload  Executes the application associated with this AppLnk.  \sa exec()*/void AppLnk::execute() const{    execute(QStringList());}/*!  Executes the application associated with this AppLnk, with  \a args as arguments.  \sa exec()*/void AppLnk::execute(const QStringList& args) const{#ifdef Q_WS_QWS    if ( !mRotation.isEmpty() ) {	// ######## this will only work in the server	int rot = QPEApplication::defaultRotation();	rot = (rot+mRotation.toInt())%360;	QCString old = getenv("QWS_DISPLAY");        //preserve current display id for new applink        int displayID = 0;        QRegExp regExp( ":[0-9]+" );  // supports more than 10 displays        int length;        int match = regExp.match( old , 0, &length );        if ( match >= 0 ) {	    QString num = QString(old).mid( match+1, length-1 );	    displayID = num.toInt();        }#ifndef Q_OS_WIN32	setenv("QWS_DISPLAY", QString("Transformed:Rot%1:%2")                .arg(rot).arg(displayID), 1);	invoke(args);	setenv("QWS_DISPLAY", old.data(), 1);#else	QString	rotationEvn("QWS_DISPLAY=");	_putenv((rotationEvn + QString("Transformed:Rot%1:%2")                    .arg(rot).arg(displayID)).latin1());	invoke(args);	_putenv((rotationEvn + old.data()).latin1());#endif    } else	invoke(args);#endif}#ifdef Q_WS_QWS/*!  Invokes the application associated with this AppLnk, with  \a args as arguments. Rotation is not taken into account by  this function, so you should not call it directly.  \sa execute()*/void AppLnk::invoke(const QStringList& args) const{    Global::execute( exec(), args[0] );}/*!  Sets the Exec property to \a exec.  \sa exec() name()*/void AppLnk::setExec( const QString& exec ){    mExec = exec;}#endif/*!  Sets the Name property to \a docname.  \sa name()*/void AppLnk::setName( const QString& docname ){    mName = docname;}/*!  Sets the File property to \a filename.  \sa file() name()*/void AppLnk::setFile( const QString& filename ){    mFile = filename;}/*!  Sets the LinkFile property to \a filename.  \sa linkFile()*/void AppLnk::setLinkFile( const QString& filename ){    mLinkFile = filename;}/*!  Sets the Comment property to \a comment.  This text is displayed in the 'Details Dialog', for example if the  user uses the 'press-and-hold' gesture.  \sa comment()*/void AppLnk::setComment( const QString& comment ){    mComment = comment;}/*!  Sets the Type property to \a type.  For applications, games and settings the type should be \c  Application; for documents the type should be the document's MIME  type.  \sa type()*/void AppLnk::setType( const QString& type ){    mType = type;}/*!  \fn QString AppLnk::icon() const  Returns the Icon property.  \sa setIcon()*//*!  Sets the Icon property to \a iconname. This is the filename from  which the pixmap() and bigPixmap() are obtained.  \sa icon() setSmallIconSize() setBigIconSize()*/void AppLnk::setIcon( const QString& iconname ){    mIconFile = iconname;    AppLnkPrivate::setPixmaps( this, TRUE );    AppLnkPrivate::setPixmaps( this, FALSE );}/*!  Sets the Categories property to \a c.  See the CategoryWidget for more details.  \sa categories()*/void AppLnk::setCategories( const QArray<int>& c ){    d->mCat = c.copy();    d->updateCatListFromArray();}/*!  \fn QStringList AppLnk::mimeTypeIcons() const  Returns the MimeTypeIcons property of the AppLnk.*//*!  Attempts to ensure that the link file for this AppLnk exists,  including creating any required directories. Returns TRUE if  successful; otherwise returns FALSE.  You should not need to use this function.*/bool AppLnk::ensureLinkExists() const{    QString lf = linkFile();    return prepareDirectories(lf);}/*!  Commits the AppLnk to disk. Returns TRUE if the operation succeeded;  otherwise returns FALSE.  In addition, the "linkChanged(QString)" message is sent to the  "QPE/System" \link qcop.html QCop\endlink channel.*/bool AppLnk::writeLink() const{    // Only re-writes settable parts    QString lf = linkFile();    if ( !ensureLinkExists() )	return FALSE;    storeLink();    return TRUE;}/*!  \internal*/void AppLnk::storeLink() const{    Config config( mLinkFile, Config::File );    config.setGroup("Desktop Entry");    config.writeEntry("Name",mName);    if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile);    config.writeEntry("Type",type());    if ( !mComment.isNull() ) config.writeEntry("Comment",mComment);    QString f = file();    int i = 0;    while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] )	i++;    while ( i && f[i] != '/' )	i--;    // simple case where in the same directory    if ( mLinkFile.find( '/', i + 1 ) < 0 )	f = f.mid(i+1);    // ### could do relative ie ../../otherDocs/file.doc    config.writeEntry("File",f);    config.writeEntry( "Categories", d->mCatList, ';' );#ifndef QT_NO_COP    QCopEnvelope e("QPE/System", "linkChanged(QString)");    e << mLinkFile;#endif}/*!  Sets the property named \a key to \a value.  \sa property()*/void AppLnk::setProperty(const QString& key, const QString& value){    if ( ensureLinkExists() ) {	Config cfg(linkFile(), Config::File);	cfg.writeEntry(key,value);    }}/*!  Returns the property named \a key.  \sa setProperty()*/QString AppLnk::property(const QString& key) const{    QString lf = linkFile();    if ( !QFile::exists(lf) )	return QString::null;    Config cfg(lf, Config::File);    return cfg.readEntry(key);}bool AppLnk::isPreloaded() const {  // Preload information is stored in the Launcher config in v1.5.  Config cfg("Launcher");  cfg.setGroup("Preload");  QStringList apps = cfg.readListEntry("Apps",',');  if (apps.contains(exec()))    return true;  return false;}void AppLnk::setPreloaded(bool yesNo) {  // Preload information is stored in the Launcher config in v1.5.  Config cfg("Launcher");  cfg.setGroup("Preload");  QStringList apps = cfg.readListEntry("Apps", ',');  if (apps.contains(exec()) && !yesNo)    apps.remove(exec());  else if (yesNo && !apps.contains(exec()))    apps.append(exec());  cfg.writeEntry("Apps", apps, ',');}/*!  Deletes both the linkFile() and the file() associated with this AppLnk.  \sa removeLinkFile()*/void AppLnk::removeFiles(){    bool needmsg = FALSE;    if ( !mLinkFile.isNull() ) {	if ( !QFile::exists(linkFile()) || QFile::remove(linkFile()) ) {	    needmsg = TRUE;	} else {	    return; // failure	}    }    if ( !mFile.isNull() ) {	if ( !QFile::exists(file()) || QFile::remove(file()) ) {	    needmsg = TRUE;	} else {	    if ( !mLinkFile.isNull() )		writeLink();	    return; // failure	}    }#ifndef QT_NO_COP    if ( needmsg ) {	QCopEnvelope e("QPE/System", "linkChanged(QString)");	if ( !mLinkFile.isNull() )	    e << linkFile();	else	    e << file();    }#endif    // success}/*!  Deletes the linkFile(), leaving any file() untouched.    \sa removeFiles()*/void AppLnk::removeLinkFile(){    if ( isValid() && !mLinkFile.isNull() && QFile::remove(linkFile()) ) {#ifndef QT_NO_COP	QCopEnvelope e("QPE/System", "linkChanged(QString)");	e << linkFile();#endif    }}class AppLnkSetPrivate {public:    AppLnkSetPrivate()    {	typPix.setAutoDelete(TRUE);	typPixBig.setAutoDelete(TRUE);	typName.setAutoDelete(TRUE);    }    QDict<QPixmap> typPix;    QDict<QPixmap> typPixBig;    QDict<QString> typName;};/*!  \class AppLnkSet applnk.h  \brief The AppLnkSet class is a set of AppLnk objects.  \ingroup qtopiaemb*/

⌨️ 快捷键说明

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