aboutsummaryrefslogtreecommitdiff
path: root/libLumina
diff options
context:
space:
mode:
authorKen Moore <ken@pcbsd.org>2015-02-19 08:12:36 -0500
committerKen Moore <ken@pcbsd.org>2015-02-19 08:12:36 -0500
commit193dd0a1f4e1fbd6b4a5a09cf712b66ad92db8e4 (patch)
tree5eb47a0862a75a902b3b4832259016b83d643ca1 /libLumina
parentNow tag 0.8.3-devel on the master branch (in preparation for the next version) (diff)
downloadlumina-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.
Diffstat (limited to 'libLumina')
-rw-r--r--libLumina/LuminaXDG.cpp37
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;
}
bgstack15