From f01465bd4e0ae5020738dd444758555c55eece49 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 18 Aug 2016 11:05:42 -0400 Subject: Revamp how the system applications are parsed/updated. This now uses a new data class which provides for delta updates to the application list, allowing for later checks/updates to be performed a *lot* faster, in addition to providing information about which *new* application entries were discovered during the check in addition to the raw app list. As an added bonus, the new class-based nature of the routine will make it possible to embed the detection/update routines directly into the class rather than requiring some external class to monitor the system and request updates. Example Times: First run: same as old routine. Second run with one new app entry: new routine is ~1/4 of the time of the old routine (20ms vs 78ms on my test box) --- src-qt5/core/libLumina/LuminaXDG.cpp | 62 +++++++++++++++++++++++++++++++++++- src-qt5/core/libLumina/LuminaXDG.h | 20 +++++++++++- 2 files changed, 80 insertions(+), 2 deletions(-) (limited to 'src-qt5') diff --git a/src-qt5/core/libLumina/LuminaXDG.cpp b/src-qt5/core/libLumina/LuminaXDG.cpp index 8f6ada37..3e71fb5c 100644 --- a/src-qt5/core/libLumina/LuminaXDG.cpp +++ b/src-qt5/core/libLumina/LuminaXDG.cpp @@ -14,6 +14,57 @@ static QStringList mimeglobs; static qint64 mimechecktime; +//====XDGDesktopList Functions ==== +void XDGDesktopList::updateList(){ + //run the check routine + QStringList appDirs = LXDG::systemApplicationDirs(); //get all system directories + QStringList found, newfiles; //for avoiding duplicate apps (might be files with same name in different priority directories) + QStringList oldkeys = files.keys(); + QList out; + bool ok; //for internal loop use only (to prevent re-initializing variable on every iteration) + QString path; //for internal loop use (to prevent re-initializing variable on every iteration) + for(int i=0; iQFileInfo(path).lastModified()) ){ + //Re-use previous data for this file (nothing changed) + dFile = files[path]; + ok=true; + }else{ + ok=false; + dFile = LXDG::loadDesktopFile(dir.absoluteFilePath(apps[a]),ok); //will change the "ok" variable as needed + } + if(ok && !found.contains(dFile.name)){ + if(!files.contains(path)){ newfiles << path; } //brand new file (not an update to a previously-read file) + files.insert(path, dFile); + found << dFile.name; + oldkeys.removeAll(path); //make sure this key does not get cleaned up later + } + } //end loop over apps + } //end loop over appDirs + //Now go through and cleanup any old keys where the associated file does not exist anymore + for(int i=0; i XDGDesktopList::apps(bool showAll, bool showHidden){ + //showAll: include invalid files, showHidden: include NoShow/Hidden files + QStringList keys = files.keys(); + QList out; + for(int i=0; i LXDG::systemDesktopFiles(bool showAll, bool showHidden){ //Returns a list of all the unique *.desktop files that were found + /*qDebug() << "Read System Apps:"; + qDebug() << "Old Routine Start:" << QDateTime::currentDateTime().toString("hh.mm.ss.zzz"); QStringList appDirs = LXDG::systemApplicationDirs(); QStringList found; //for avoiding duplicate apps QList out; @@ -447,7 +500,14 @@ QList LXDG::systemDesktopFiles(bool showAll, bool showHidden){ } } } - return out; + qDebug() << " End:" << QDateTime::currentDateTime().toString("hh.mm.ss.zzz"); + //return out; */ + //qDebug() << "New Routine Start:" << QDateTime::currentDateTime().toString("hh.mm.ss.zzz"); + static XDGDesktopList sysappslist; + sysappslist.updateList(); + return sysappslist.apps(showAll, showHidden); + //qDebug() << " End:" << QDateTime::currentDateTime().toString("hh.mm.ss.zzz"); + //return out; } QHash > LXDG::sortDesktopCats(QList apps){ diff --git a/src-qt5/core/libLumina/LuminaXDG.h b/src-qt5/core/libLumina/LuminaXDG.h index 5a9b1441..644ec65a 100644 --- a/src-qt5/core/libLumina/LuminaXDG.h +++ b/src-qt5/core/libLumina/LuminaXDG.h @@ -69,6 +69,25 @@ public: ~XDGDesktop(){} }; +// ======================== +// Data Structure for keeping track of known system applications +// ======================== +class XDGDesktopList{ +public: + //Administration variables (not typically used directly) + QDateTime lastCheck; + QStringList newApps; //list of "new" apps found during the last check + QHash files; /// + + //Functions + XDGDesktopList(){} + ~XDGDesktopList(){} + //Main Interface functions + void updateList(); //run the check routine + QList apps(bool showAll, bool showHidden); //showAll: include invalid files, showHidden: include NoShow/Hidden files + +}; + // ======================== // File Information simplification class (combine QFileInfo with XDGDesktop) // Need some extra information not usually available by a QFileInfo @@ -165,4 +184,3 @@ public: }; #endif - -- cgit