Changeset b8c1be6


Ignore:
Timestamp:
07/16/14 06:56:13 (12 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, enter/10, releng/10.0.3, releng/10.1, releng/10.1.1, releng/10.1.2
Children:
bb5d187
Parents:
47e93bde
Message:

Speed up sequential mime-type checks by caching the contents of the globs2 DB. The minimum time for the cache to get updated is 30 seconds.

Location:
lumina/libLumina
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lumina/libLumina/LuminaXDG.cpp

    r2aaaec7 rb8c1be6  
    66//=========================================== 
    77#include "LuminaXDG.h" 
     8 
     9static QStringList mimeglobs; 
     10static qint64 mimechecktime; 
    811 
    912//==== LXDG Functions ==== 
     
    330333  mime.replace("/","-"); //translate to icon mime name 
    331334  ico = LXDG::findIcon(mime, "unknown"); //use the "unknown" mimetype icon as fallback   
    332   if(ico.isNull()){ ico = LXDG::findIcon("unknown",""); } 
     335  if(ico.isNull()){ ico = LXDG::findIcon("unknown",""); } //just in case 
    333336  return ico; 
    334337} 
     
    337340  QString out; 
    338341  int weight = 0; 
    339   QStringList dirs = LXDG::systemMimeDirs(); 
    340   for(int i=0; i<dirs.length(); i++){ 
    341     if(QFile::exists(dirs[i]+"/globs2")){ 
    342       QStringList mimes = LXDG::loadMimeFileGlobs2(dirs[i]+"/globs2"); 
    343       mimes = mimes.filter(":*."+extension); 
    344       for(int m=0; m<mimes.length(); m++){ 
    345           QString mime = mimes[m].section(":",1,1,QString::SectionSkipEmpty); 
    346           if(mimes[m].section(":",0,0,QString::SectionSkipEmpty).toInt() > weight ){ 
    347             out = mime; 
    348           } 
     342  QStringList mimes = LXDG::loadMimeFileGlobs2().filter(":*."+extension); 
     343  for(int m=0; m<mimes.length(); m++){ 
     344    QString mime = mimes[m].section(":",1,1,QString::SectionSkipEmpty); 
     345    if(mimes[m].section(":",0,0,QString::SectionSkipEmpty).toInt() > weight ){ 
     346      out = mime; 
     347    } 
     348  } 
     349  return out; 
     350} 
     351 
     352QStringList LXDG::loadMimeFileGlobs2(){ 
     353  //output format: <weight>:<mime type>:<file extension (*.something)> 
     354  if(mimeglobs.isEmpty() || (mimechecktime < (QDateTime::currentMSecsSinceEpoch()-30000)) ){ 
     355    qDebug() << "Loading globs2 mime DB files"; 
     356    mimeglobs.clear(); 
     357    mimechecktime = QDateTime::currentMSecsSinceEpoch(); //save the current time this was last checked 
     358    QStringList dirs = LXDG::systemMimeDirs(); 
     359    for(int i=0; i<dirs.length(); i++){ 
     360      if(QFile::exists(dirs[i]+"/globs2")){ 
     361        QFile file(dirs[i]+"/globs2"); 
     362        if(!file.exists()){ continue; } 
     363        if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ continue; } 
     364        QTextStream in(&file); 
     365        while(!in.atEnd()){ 
     366          QString line = in.readLine(); 
     367          if(!line.startsWith("#")){ 
     368            mimeglobs << line.simplified(); 
     369          } 
     370        } 
     371        file.close(); 
    349372      } 
    350     } 
    351   } 
    352   return out; 
    353 } 
    354  
    355 QStringList LXDG::loadMimeFileGlobs2(QString filePath){ 
    356   QStringList out; //format: <weight>:<mime type>:<file extension (*.something)> 
    357   QFile file(filePath); 
    358   if(!file.exists()){ return out; } 
    359   if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ return out; } 
    360   QTextStream in(&file); 
    361   while(!in.atEnd()){ 
    362     QString line = in.readLine(); 
    363     if(!line.startsWith("#")){ 
    364       out << line.simplified(); 
    365     } 
    366   } 
    367   file.close(); 
    368   return out; 
    369 } 
    370  
     373    }     
     374  } 
     375  return mimeglobs; 
     376} 
     377 
  • lumina/libLumina/LuminaXDG.h

    r2aaaec7 rb8c1be6  
    2626#include <QLocale> 
    2727#include <QTextStream> 
     28#include <QDateTime> 
    2829#include <QDebug> 
    2930 
     
    8182        //Find the mime-type of a particular file extension 
    8283        static QString findAppMimeForFile(QString extension); 
    83         //Load the "globs2" mime database file 
    84         static QStringList loadMimeFileGlobs2(QString filePath); 
     84        //Load all the "globs2" mime database files 
     85        static QStringList loadMimeFileGlobs2(); 
    8586}; 
    8687 
Note: See TracChangeset for help on using the changeset viewer.