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

📄 applnk.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*!  \fn QStringList AppLnkSet::types() const  Returns the list of \link applnk.html#Types types\endlink in the set.    For applications, games and settings the type is \c Application;    for documents the type is the document's MIME type.  \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap()*//*!  \fn const QList<AppLnk>& AppLnkSet::children() const  Returns the members of the set.*//*!  Constructs an empty AppLnkSet.*/AppLnkSet::AppLnkSet() :    d(new AppLnkSetPrivate){}/*!  Constructs an AppLnkSet that contains AppLnk objects representing  all the files in the given \a directory (and any subdirectories  recursively).  \omit  The directories may contain ".directory" files which override  any AppLnk::type() values for AppLnk objects found in the directory.  This allows simple localization of application types.  \endomit*/AppLnkSet::AppLnkSet( const QString &directory ) :    d(new AppLnkSetPrivate){    QDir dir( directory );    mFile = directory;    findChildren(directory,QString::null,QString::null);}/*!  Detaches all AppLnk objects from the set. The set become empty and  the caller becomes responsible for deleting the AppLnk objects.*/void AppLnkSet::detachChildren(){    QListIterator<AppLnk> it( mApps );    for ( ; it.current(); ) {	AppLnk* a = *it;	++it;	a->mId = 0;    }    mApps.clear();}/*!  Destroys the set, deleting all the AppLnk objects it contains.  \sa detachChildren()*/AppLnkSet::~AppLnkSet(){    QListIterator<AppLnk> it( mApps );    for ( ; it.current(); ) {	AppLnk* a = *it;	++it;	a->mId = 0;	delete a;    }    delete d;}void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth){    depth++;    if ( depth > 10 )	return;    QDir dir( dr );    QString typNameLocal = typName;    if ( dir.exists( ".directory" ) ) {	Config config( dr + "/.directory", Config::File );	config.setGroup( "Desktop Entry" );	typNameLocal = config.readEntry( "Name", typNameLocal );	if ( !typ.isEmpty() ) {	    QString iconFile = config.readEntry( "Icon", "AppsIcon" );	    QPixmap bpm, pm;	    QImage standardIcon;	    QString key = "_QPE_Global_" + iconFile + "_small";	    if ( QPixmapCache::find(key, pm) ) {		d->typPix.insert(typ, new QPixmap(pm));	    } else {		QImage unscaledIcon;		bool oldFast = qpe_fast_findPixmap;		qpe_fast_findPixmap = TRUE;		// Small icon		if (smallSize <= 16)		    unscaledIcon = Resource::loadImage( iconFile + "_16" );		if (unscaledIcon.isNull())		    unscaledIcon = standardIcon = Resource::loadImage( iconFile );		QPixmap pm;		pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );		d->typPix.insert(typ, new QPixmap(pm));		QPixmapCache::insert(key, pm);		qpe_fast_findPixmap = oldFast;	    }	    key = "_QPE_Global_" + iconFile + "_big";	    if ( QPixmapCache::find(key, bpm) ) {		d->typPixBig.insert(typ, new QPixmap(bpm));	    } else {		QImage unscaledIcon;		bool oldFast = qpe_fast_findPixmap;		qpe_fast_findPixmap = TRUE;		// big icon		if (bigSize > 32)		    unscaledIcon = Resource::loadImage( iconFile + "_48" );		if (unscaledIcon.isNull()) {		    if (standardIcon.isNull())			unscaledIcon = Resource::loadImage( iconFile );		    else			unscaledIcon = standardIcon;		}		bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );		d->typPixBig.insert(typ, new QPixmap(bpm));		QPixmapCache::insert(key, bpm);		qpe_fast_findPixmap = oldFast;	    }	    d->typName.insert(typ, new QString(typNameLocal));	}    }    const QFileInfoList *list = dir.entryInfoList();    if ( list ) {	QFileInfo* fi;	bool cadded=FALSE;	for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {	    QString bn = fi->fileName();	    if ( bn[0] != '.' && bn != "CVS" ) {		if ( fi->isDir() ) {		    QString c = typ.isNull() ? bn : typ+"/"+bn;		    QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn;		    findChildren(fi->filePath(), c, d, depth );		} else {		    if ( fi->extension(FALSE) == "desktop" ) { // No tr			AppLnk* app = new AppLnk( fi->filePath() );#ifdef QT_NO_QWS_MULTIPROCESS			if ( !Global::isBuiltinCommand( app->exec() ) )			    delete app;			else#endif			{			    if ( !typ.isEmpty() ) {				if ( !cadded ) {				    typs.append(typ);				    cadded = TRUE;				}				app->setType(typ);			    }			    add(app);			}		    }		}	    }	}    }}/*!  Adds AppLnk \a f to the set. The set takes responsibility for  deleting \a f.  \sa remove()*/void AppLnkSet::add( AppLnk *f ){    if ( f->mId == 0 ) {	AppLnk::lastId++;	f->mId = AppLnk::lastId;	mApps.append( f );    } else {	qWarning("Attempt to add an AppLnk twice");    }}/*!  Removes AppLnk \a f to the set. The caller becomes responsible for  deleting \a f. Returns TRUE if \a f was in the set; otherwise  returns FALSE.  \sa add()*/bool AppLnkSet::remove( AppLnk *f ){    if ( mApps.removeRef( f ) ) {	f->mId = 0;	return TRUE;    }    return FALSE;}/*!  Returns the localized name for type \a t.    For applications, games and settings the type is \c Application;    for documents the type is the document's MIME type.*/QString AppLnkSet::typeName( const QString& t ) const{    QString *st = d->typName.find(t);    return st ? *st : QString::null;}/*!  Returns the small pixmap associated with type \a t.    For applications, games and settings the type is \c Application;    for documents the type is the document's MIME type.*/QPixmap AppLnkSet::typePixmap( const QString& t ) const{    QPixmap *pm = d->typPix.find(t);    return pm ? *pm : QPixmap();}/*!  Returns the large pixmap associated with type \a t.    For applications, games and settings the type is \c Application;    for documents the type is the document's MIME type.*/QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const{    QPixmap *pm = d->typPixBig.find(t);    return pm ? *pm : QPixmap();}/*!  Returns the AppLnk with the given \a id.*/const AppLnk *AppLnkSet::find( int id ) const{    QListIterator<AppLnk> it( children() );    for ( ; it.current(); ++it ) {	const AppLnk *app = it.current();	if ( app->id() == id )	    return app;    }    return 0;}/*!  Returns the AppLnk with the given \a exec attribute.*/const AppLnk *AppLnkSet::findExec( const QString& exec ) const{    QListIterator<AppLnk> it( children() );    for ( ; it.current(); ++it ) {	const AppLnk *app = it.current();	if ( app->exec() == exec )	    return app;    }    return 0;}/*!  \class DocLnkSet applnk.h  \brief The DocLnkSet class is a set of DocLnk objects.  \ingroup qtopiaemb*//*!  \fn const QList<DocLnk>& DocLnkSet::children() const  Returns the members of the set.*//*!  Constructs an empty DocLnkSet.  \sa appendFrom()*/DocLnkSet::DocLnkSet(){}/*!  Constructs a DocLnkSet that contains DocLnk objects representing all  the files in the \a directory (and any subdirectories, recursively).  If \a mimefilter is not null,  only documents with a MIME type matching \a mimefilter are selected.  The value may contain multiple wild-card patterns separated by ";",  such as \c{*o/mpeg;audio/x-wav}.  See also \link applnk.html#files-and-links Files and Links\endlink.*/DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) :    AppLnkSet(){    QDir dir( directory );    mFile = dir.dirName();    QDict<void> reference(1021);    QStringList subFilter = QStringList::split(";", mimefilter);    QValueList<QRegExp> mimeFilters;    for( QStringList::Iterator itList = subFilter.begin(); itList != subFilter.end(); ++ itList )	mimeFilters.append( QRegExp(*itList, FALSE, TRUE) );    findChildren(directory, mimeFilters, reference);    const QList<DocLnk> &list = children();    for ( QListIterator<DocLnk> itDoc( list ); itDoc.current(); ++itDoc ) {	reference.remove( (*itDoc)->file() );    }    for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) {	if ( dit.current() == (void*)2 ) {	    // Unreferenced, make an unwritten link	    DocLnk* dl = new DocLnk;	    QFileInfo fi( dit.currentKey() );	    dl->setFile(fi.filePath());	    QString tmp = fi.fileName();	    int pos = tmp.findRev( '.' );	    dl->setName( (pos == -1) ? tmp : tmp.left( pos ) );	    // #### default to current path?	    // dl->setCategories( ... );	    bool match = mimefilter.isNull();	    if ( !match )		for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it )		    if ( (*it).match(dl->type()) >= 0 )			match = TRUE;	    if ( match )		add(dl);	    else		delete dl;	}    }}// other becomes empty/*!  Transfers all DocLnk objects from \a other to this set. \a other becomes  empty.*/void DocLnkSet::appendFrom( DocLnkSet& other ){    if ( &other == this )	return;    QListIterator<AppLnk> it( other.mApps );    for ( ; it.current(); ) {	mApps.append(*it);	++it;    }    other.mApps.clear();}void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth){    depth++;    if ( depth > 10 )	return;    QDir dir( dr );    if ( dir.exists( ".Qtopia-ignore" ) )	return;    const QFileInfoList *list = dir.entryInfoList();    if ( list ) {	QFileInfo* fi;	for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {	    QString bn = fi->fileName();	    if ( bn[0] != '.' ) {		if ( fi->isDir()  ) {		    if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" )			findChildren(fi->filePath(), mimeFilters, reference, depth);		} else {		    if ( fi->extension(FALSE) == "desktop" ) { // No tr			DocLnk* dl = new DocLnk( fi->filePath() );			QFileInfo fi2(dl->file());			bool match = FALSE;			if ( !fi2.exists() ) {			    dir.remove( dl->file() );			}			if ( mimeFilters.count() == 0 ) {			    add( dl );			    match = TRUE;			} else {			    for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) {				if ( (*it).match(dl->type()) >= 0 ) {				    add(dl);				    match = TRUE;				}			    }			}			if ( !match )			    delete dl;		    } else {			if ( !reference.find(fi->fileName()) ){			    reference.insert(fi->filePath(), (void*)2);			}		    }		}	    }	}    }}/*!  \class DocLnk applnk.h  \brief The DocLnk class represents loaded document references.  \ingroup qtopiaemb*//*!  \fn DocLnk::DocLnk( const DocLnk &o )  Copies \a o.*//*!  Constructs a DocLnk from a valid .desktop \a file or a new .desktop  \a file for other files.*/DocLnk::DocLnk( const QString &file ) :    AppLnk( file.right(8) == ".desktop" ? file : QString::null ){    init(file);}/*!  Constructs a DocLnk from a valid .desktop \a file or a new .desktop  \a file for other files. If \a may_be_desktopfile is TRUE, then an  attempt is made to read \a file as a .desktop file; if that fails it  is read as a normal file.*/DocLnk::DocLnk( const QString &file, bool may_be_desktopfile ) :    AppLnk(may_be_desktopfile ? file : QString::null){    init(file);}void DocLnk::init(const QString &file){    if ( isValid() ) {#ifndef FORCED_DIR_STRUCTURE_WAY	if ( mType.isNull() )	    // try to infer it#endif	{	    int s0 = file.findRev('/');	    if ( s0 > 0 ) {		int s1 = file.findRev('/',s0-1);		if ( s1 > 0 ) {		    int s2 = file.findRev('/',s1-1);		    if ( s2 > 0 ) {			mType = file.mid(s2+1,s0-s2-1);		    }		}	    }	}    } else if ( QFile::exists(file) ) {	QString n = file;	n.replace(QRegExp(".*/"),"");	n.replace(QRegExp("\\..*"),"");	setName( n );	setFile( file );    }    MimeType mt(mType);    if( mt.application() )	mExec = mt.application()->exec();}/*!  Constructs an invalid DocLnk.*/DocLnk::DocLnk(){}/*!  Destroys the DocLnk. Just like AppLnk objects, a run-time error  occurs if the DocLnk is a member of a DocLnkSet (or AppLnkSet).*/DocLnk::~DocLnk(){}/*!  \reimp*/QString DocLnk::exec() const{    MimeType mt(type());    const AppLnk* app = mt.application();    if ( app )	return app->exec();    else	return QString::null;}/*!  \reimp*/void DocLnk::invoke(const QStringList& args) const{    MimeType mt(type());    const AppLnk* app = mt.application();    if ( app ) {	QStringList a = args;	if ( !mLinkFile.isNull() && QFile::exists( linkFile() ) )	    a.append(linkFile());	else	    a.append(file());	app->execute(a);    }}/*!    \fn bool AppLnk::fileKnown() const    Returns TRUE is the file associated with AppLnk is already    known. If FALSE, calling file() will generate a file name.*//*!    \fn bool AppLnk::linkFileKnown() const    Returns TRUE is the link file associated with AppLnk is already    known. If FALSE, calling linkFile() will generate a file name.*//*!    \fn void AppLnkSet::clear()    Deletes all AppLnks in the set.*/#include "applnk.moc"

⌨️ 快捷键说明

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