diff options
author | Ken Moore <ken@pcbsd.org> | 2015-02-19 08:12:36 -0500 |
---|---|---|
committer | Ken Moore <ken@pcbsd.org> | 2015-02-19 08:12:36 -0500 |
commit | 193dd0a1f4e1fbd6b4a5a09cf712b66ad92db8e4 (patch) | |
tree | 5eb47a0862a75a902b3b4832259016b83d643ca1 | |
parent | Now tag 0.8.3-devel on the master branch (in preparation for the next version) (diff) | |
download | lumina-193dd0a1f4e1fbd6b4a5a09cf712b66ad92db8e4.tar.gz lumina-193dd0a1f4e1fbd6b4a5a09cf712b66ad92db8e4.tar.bz2 lumina-193dd0a1f4e1fbd6b4a5a09cf712b66ad92db8e4.zip |
Clean up the XGD mime-types detection routine quite a but. Now it should be much more accurate about special extensions and faster lookups for pre-found mimetypes.
-rw-r--r-- | libLumina/LuminaXDG.cpp | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/libLumina/LuminaXDG.cpp b/libLumina/LuminaXDG.cpp index cf49977a..22193786 100644 --- a/libLumina/LuminaXDG.cpp +++ b/libLumina/LuminaXDG.cpp @@ -377,26 +377,47 @@ QString LXDG::findAppMimeForFile(QString filename, bool multiple){ QString out; QString extension = filename.section(".",-1); if("."+extension == filename){ extension.clear(); } //hidden file without extension - int weight = 0; + //qDebug() << "MIME SEARCH:" << filename << extension; QStringList mimefull = LXDG::loadMimeFileGlobs2(); QStringList mimes; + //Just in case the extension/filename is a mimetype itself + if( mimefull.filter(":"+filename+":").length() == 1){ + return filename; + } + else if(mimefull.filter(":"+extension+":").length() == 1){ + return extension; + } + //Look for globs at the end of the filename if(!extension.isEmpty()){ mimes = mimefull.filter(":*."+extension); //If nothing found, try a case-insensitive search if(mimes.isEmpty()){ mimes = mimefull.filter(":*."+extension, Qt::CaseInsensitive); } + //Now ensure that the filter was accurate (*.<extention>.<something> will still be caught) + for(int i=0; i<mimes.length(); i++){ + if(!filename.endsWith( mimes[i].section(":*",-1) )){ mimes.removeAt(i); i--; } + } } - if(mimes.isEmpty()){ mimes = mimefull.filter(":"+filename.left(3)); } //look for the first 3 characters only (FIX WILDCARD DETECTION LATER) - mimes.sort(); + //Look for globs at the start of the filename + if(mimes.isEmpty()){ + mimes = mimefull.filter(":"+filename.left(2)); //look for the first 2 characters initially + //Note: This initial filter will only work if the wildcard (*) is not within the first 2 characters of the pattern + //Now ensure that the filter was accurate + for(int i=0; i<mimes.length(); i++){ + if(!filename.startsWith( mimes[i].section(":",3,50,QString::SectionSkipEmpty).section("*",0,0) )){ mimes.removeAt(i); i--; } + } + } + mimes.sort(); //this automatically puts them in weight order (100 on down) QStringList matches; + //qDebug() << "Mimes:" << mimes; for(int m=0; m<mimes.length(); m++){ QString mime = mimes[m].section(":",1,1,QString::SectionSkipEmpty); - if(mime.endsWith("/"+extension)){ matches.prepend(mime); } //exact match - else{ matches << mime; } - if(mimes[m].section(":",0,0,QString::SectionSkipEmpty).toInt() > weight ){ - out = mime; - } + matches << mime; } + //qDebug() << "Matches:" << matches; if(multiple){ out = matches.join("::::"); } + else if( !matches.isEmpty() ){ out = matches.first(); } + else{ out.clear(); } + //qDebug() << "Out:" << out; return out; } |