-rw-r--r-- | library/applnk.cpp | 2 | ||||
-rw-r--r-- | library/mimetype.cpp | 10 |
2 files changed, 8 insertions, 4 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp index 5f7da8e..e9d519e 100644 --- a/library/applnk.cpp +++ b/library/applnk.cpp @@ -1231,97 +1231,97 @@ 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. */ /*! \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; + QDict<void> reference(1021); QStringList subFilter = QStringList::split(";", mimefilter); QValueList<QRegExp> mimeFilters; for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it ) mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); findChildren(directory, mimeFilters, reference); const QList<DocLnk> &list = children(); for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { reference.remove( (*it)->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()); dl->setName(fi.baseName()); // #### 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 /* && dl->type() != "application/octet-stream" */ && !!dl->exec() ) 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; diff --git a/library/mimetype.cpp b/library/mimetype.cpp index 23de70b..ec45794 100644 --- a/library/mimetype.cpp +++ b/library/mimetype.cpp @@ -66,96 +66,97 @@ public: return bigicon; } private: void loadPixmaps() { if ( apps.count() ) { QString icon; for (AppLnk* lnk = apps.first(); icon.isNull() && lnk; lnk=apps.next()) { QStringList icons = lnk->mimeTypeIcons(); if ( icons.count() ) { QStringList types = lnk->mimeTypes(); for (QStringList::ConstIterator t=types.begin(),i=icons.begin(); t!=types.end() && i!=icons.end(); ++i,++t) { if ( *t == id ) { icon = *i; break; } } } } if ( icon.isNull() ) { AppLnk* lnk = apps.first(); regicon = lnk->pixmap(); bigicon = lnk->bigPixmap(); } else { QImage unscaledIcon = Resource::loadImage( icon ); regicon.convertFromImage( unscaledIcon.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); bigicon.convertFromImage( unscaledIcon.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ) ); } } } QPixmap regicon; QPixmap bigicon; QString desc; }; class MimeType::Private : public QDict<MimeTypeData> { public: Private() {} ~Private() {} // ... }; MimeType::Private* MimeType::d=0; static QMap<QString,QString> *typeFor = 0; static QMap<QString,QStringList> *extFor = 0; +static bool appsUpdated = FALSE; MimeType::Private& MimeType::data() { if ( !d ) { d = new Private; d->setAutoDelete(TRUE); static bool setCleanup = FALSE; if ( !setCleanup ) { qAddPostRoutine( cleanupMime ); setCleanup = TRUE; } } return *d; } /*! \class MimeType mimetype.h \brief The MimeType class provides MIME type information. A MimeType object is a light-weight value which provides information about a MIME type. \ingroup qtopiaemb */ /*! Constructs a MimeType. Normally, \a ext_or_id is a MIME type, but if \a ext_or_id starts with / or contains no /, it is interpretted as a filename and the extension (eg. .txt) is used as the MIME type. */ MimeType::MimeType( const QString& ext_or_id ) { init(ext_or_id); } /*! Constructs a MimeType from the type() of \a lnk. */ MimeType::MimeType( const DocLnk& lnk ) { init(lnk.type()); } /*! Returns the MIME type identifier. @@ -226,141 +227,144 @@ const AppLnk* MimeType::application() const { MimeTypeData* d = data(i); return d ? d->apps.first() : 0; } static QString serviceBinding(const QString& service) { // Copied from qtopiaservices QString svrc = service; for (int i=0; i<(int)svrc.length(); i++) if ( svrc[i]=='/' ) svrc[i] = '-'; return "Service-"+svrc; } /*! \internal */ void MimeType::registerApp( const AppLnk& lnk ) { QStringList list = lnk.mimeTypes(); for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) { MimeTypeData* cur = data()[*it]; AppLnk* l = new AppLnk(lnk); if ( !cur ) { cur = new MimeTypeData( *it ); data().insert( *it, cur ); cur->apps.append(l); } else if ( cur->apps.count() ) { Config binding(serviceBinding("Open/"+*it)); binding.setGroup("Service"); QString def = binding.readEntry("default"); if ( l->exec() == def ) cur->apps.prepend(l); else cur->apps.append(l); } else { cur->apps.append(l); } } } /*! \internal */ void MimeType::clear() { delete d; d = 0; + delete typeFor; typeFor = 0; + delete extFor ; extFor = 0; + appsUpdated = FALSE; } void MimeType::loadExtensions() { if ( !typeFor ) { extFor = new QMap<QString,QStringList>; typeFor = new QMap<QString,QString>; loadExtensions("/etc/mime.types"); loadExtensions(QPEApplication::qpeDir()+"etc/mime.types"); } } void MimeType::loadExtensions(const QString& filename) { QFile file(filename); if ( file.open(IO_ReadOnly) ) { QTextStream in(&file); QRegExp space("[ \t]+"); while (!in.atEnd()) { QStringList tokens = QStringList::split(space, in.readLine()); QStringList::ConstIterator it = tokens.begin(); if ( it != tokens.end() ) { QString id = *it; ++it; // new override old (though left overrides right) QStringList exts = (*extFor)[id]; QStringList newexts; while ( it != tokens.end() ) { exts.remove(*it); if ( !newexts.contains(*it) ) newexts.append(*it); (*typeFor)[*it] = id; ++it; } (*extFor)[id] = newexts + exts; } } } } void MimeType::init( const QString& ext_or_id ) { if ( ext_or_id[0] != '/' && ext_or_id.contains('/') ) { i = ext_or_id.lower(); } else { loadExtensions(); int dot = ext_or_id.findRev('.'); QString ext = dot >= 0 ? ext_or_id.mid(dot+1) : ext_or_id; i = (*typeFor)[ext.lower()]; if ( i.isNull() ) i = "application/octet-stream"; } - static bool appsUpdated = FALSE; + if ( !appsUpdated ) { - appsUpdated = TRUE; updateApplications(); } } MimeTypeData* MimeType::data(const QString& id) { MimeTypeData* d = data()[id]; if ( !d ) { int s = id.find('/'); QString idw = id.left(s)+"/*"; d = data()[idw]; } return d; } /*! Returns a Qtopia folder containing application definitions. */ QString MimeType::appsFolderName() { return QPEApplication::qpeDir() + "apps"; } /*! Reloads application definitions. */ void MimeType::updateApplications() { - clear(); +// clear(); + appsUpdated = true; AppLnkSet apps( appsFolderName() ); updateApplications(&apps); } void MimeType::updateApplications(AppLnkSet* folder) { for ( QListIterator<AppLnk> it( folder->children() ); it.current(); ++it ) { registerApp(*it.current()); } } |