-rw-r--r-- | library/mimetype.cpp | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/library/mimetype.cpp b/library/mimetype.cpp index e2e0dab..92fe5e6 100644 --- a/library/mimetype.cpp +++ b/library/mimetype.cpp @@ -150,159 +150,157 @@ QString MimeType::description() const MimeTypeData* d = data(i); return d ? d->description() : QString::null; } QPixmap MimeType::pixmap() const { MimeTypeData* d = data(i); return d ? d->regIcon() : QPixmap(); } QString MimeType::extension() const { return extensions().first(); } QStringList MimeType::extensions() const { loadExtensions(); return *(*extFor).find(i); } QPixmap MimeType::bigPixmap() const { MimeTypeData* d = data(i); return d ? d->bigIcon() : QPixmap(); } 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; } 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); } } } void MimeType::clear() { delete d; d = 0; } 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; - if ( it != tokens.end() ) { + while ( it != tokens.end() ) { exts.remove(*it); if ( !newexts.contains(*it) ) newexts.append(*it); - while (it != tokens.end()) { (*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; } QString MimeType::appsFolderName() { return QPEApplication::qpeDir() + "apps"; } void MimeType::updateApplications() { clear(); AppLnkSet apps( appsFolderName() ); updateApplications(&apps); } void MimeType::updateApplications(AppLnkSet* folder) { for ( QListIterator<AppLnk> it( folder->children() ); it.current(); ++it ) { registerApp(*it.current()); } } |