diff options
author | Ken Moore <ken@pcbsd.org> | 2016-09-21 17:08:34 -0400 |
---|---|---|
committer | Ken Moore <ken@pcbsd.org> | 2016-09-21 17:08:34 -0400 |
commit | e24b7b3f822a55aa8210ed21d50349147426f7a3 (patch) | |
tree | 329737f6f06f89d2337f2f15f089985dc11303e0 /src-qt5/core | |
parent | Add an "==" operator to the XDGDesktop class. Found a note in the QHash docs ... (diff) | |
download | lumina-e24b7b3f822a55aa8210ed21d50349147426f7a3.tar.gz lumina-e24b7b3f822a55aa8210ed21d50349147426f7a3.tar.bz2 lumina-e24b7b3f822a55aa8210ed21d50349147426f7a3.zip |
Fix the memory usage issue with Lumina and the application list on the system. It no longer grows with time that I can tell, but I am sure there is some additional cleanup and optimizations which can still be done later.
Diffstat (limited to 'src-qt5/core')
-rw-r--r-- | src-qt5/core/libLumina/LuminaXDG.cpp | 27 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LuminaXDG.h | 22 |
2 files changed, 21 insertions, 28 deletions
diff --git a/src-qt5/core/libLumina/LuminaXDG.cpp b/src-qt5/core/libLumina/LuminaXDG.cpp index e500ab7e..36b05676 100644 --- a/src-qt5/core/libLumina/LuminaXDG.cpp +++ b/src-qt5/core/libLumina/LuminaXDG.cpp @@ -48,7 +48,7 @@ void XDGDesktopList::updateList(){ bool firstrun = lastCheck.isNull() || oldkeys.isEmpty(); lastCheck = QDateTime::currentDateTime(); //Variables for internal loop use only (to prevent re-initializing variable on every iteration) - bool ok; QString path; QDir dir; QStringList apps; XDGDesktop dFile; + bool ok; QString path; QDir dir; QStringList apps; for(int i=0; i<appDirs.length(); i++){ if( !dir.cd(appDirs[i]) ){ continue; } //could not open dir for some reason apps = dir.entryList(QStringList() << "*.desktop",QDir::Files, QDir::Name); @@ -60,10 +60,10 @@ void XDGDesktopList::updateList(){ ok=true; }else{ ok=false; - if(files.contains(path)){ files.remove(path); } - dFile = LXDG::loadDesktopFile(path,ok); //will change the "ok" variable as needed - appschanged = true; //flag that something changed - needed to load a file - if(ok && !found.contains(dFile.name)){ + if(files.contains(path)){ appschanged = true; files.remove(path); } + XDGDesktop dFile = LXDG::loadDesktopFile(path,ok); //will change the "ok" variable as needed + if(ok){ + appschanged = true; //flag that something changed - needed to load a file if(!oldkeys.contains(path)){ newfiles << path; } //brand new file (not an update to a previously-read file) files.insert(path, dFile); found << dFile.name; @@ -79,6 +79,7 @@ void XDGDesktopList::updateList(){ } //Now go through and cleanup any old keys where the associated file does not exist anymore for(int i=0; i<oldkeys.length(); i++){ + //qDebug() << "Removing file from internal map:" << oldkeys[i]; files.remove(oldkeys[i]); } //If this class is automatically managing the lists, update the watched files/dirs and send out notifications @@ -89,7 +90,6 @@ void XDGDesktopList::updateList(){ if(appschanged){ emit appsUpdated(); } synctimer->start(); } - files.squeeze(); //make sure this class uses as little memory as possible (should not be needed - but just in case...) } QList<XDGDesktop> XDGDesktopList::apps(bool showAll, bool showHidden){ @@ -97,8 +97,8 @@ QList<XDGDesktop> XDGDesktopList::apps(bool showAll, bool showHidden){ QStringList keys = files.keys(); QList<XDGDesktop> out; for(int i=0; i<keys.length(); i++){ - if( LXDG::checkValidity(files[keys[i]], showAll) ){ - if( showHidden || !files[keys[i]].isHidden ){ + if( showHidden || !files[keys[i]].isHidden ){ //this is faster than the "checkValidity()" function below - so always filter here first + if( LXDG::checkValidity(files[keys[i]], showAll) ){ out << files[keys[i]]; } } @@ -239,7 +239,6 @@ XDGDesktop LXDG::loadDesktopFile(QString filePath, bool& ok){ QString loc = var.section("[",1,1).section("]",0,0).simplified(); // localization var = var.section("[",0,0).simplified(); //remove the localization QString val = line.section("=",1,50).simplified(); - //if(filePath.contains("pcbsd")){ qDebug() << " -- " << var << val << loc; } //------------------- if(var=="Name"){ if(insection){ @@ -300,17 +299,10 @@ XDGDesktop LXDG::loadDesktopFile(QString filePath, bool& ok){ //hasType = true; } } //end reading file - //file.close(); + file.clear(); //done with contents of file //If there are OnlyShowIn desktops listed, add them to the name if( !DF.showInList.isEmpty() && !DF.showInList.contains("Lumina", Qt::CaseInsensitive) ){ - /*QStringList added; - //Need to be careful about case insensitivity here - the QList functions don't understand it - for(int i=0; i<DF.showInList.length(); i++){ - if(DF.showInList[i].toLower()!="lumina"){ added << DF.showInList[i]; } - }*/ - //if(!added.isEmpty()){ DF.name.append(" ("+DF.showInList.join(", ")+")"); - //} } //Quick fix for showing "wine" applications (which quite often don't list a category, or have other differences) if(DF.catList.isEmpty() && filePath.contains("/wine/")){ @@ -330,7 +322,6 @@ XDGDesktop LXDG::loadDesktopFile(QString filePath, bool& ok){ } } //Return the structure - //if (hasName && hasType) ok = true; //without Name and Type, the structure cannot be a valid .desktop file ok = true; //was able to open/read the file - validity determined later return DF; } diff --git a/src-qt5/core/libLumina/LuminaXDG.h b/src-qt5/core/libLumina/LuminaXDG.h index 1720ebc5..5c012b9a 100644 --- a/src-qt5/core/libLumina/LuminaXDG.h +++ b/src-qt5/core/libLumina/LuminaXDG.h @@ -35,8 +35,8 @@ // ====================== // FreeDesktop Desktop Actions Framework (data structure) // ====================== -class XDGDesktopAction{ -public: +struct XDGDesktopAction{ +//public: //Admin variables QString ID; //The ID name for this action (should correspond to an entry in the "actionList" for the XDGDesktop below) //General Variables @@ -46,9 +46,10 @@ public: // ====================== // FreeDesktop Desktop Entry Framework (data structure) // ====================== -class XDGDesktop{ -public: +struct XDGDesktop{ +//public: enum XDGDesktopType { BAD, APP, LINK, DIR }; + //Admin variables QString filePath; //which file this structure contains the information for (absolute path) QDateTime lastRead; //when this structure was created from the file @@ -64,14 +65,15 @@ public: QList<XDGDesktopAction> actions; //Type 2 (LINK) variables QString url; - + //Constructor/destructor XDGDesktop(){} - ~XDGDesktop(){} - - friend bool operator==(const XDGDesktop lhs, const XDGDesktop rhs){ - return lhs.filePath == rhs.filePath && lhs.lastRead == rhs.lastRead; - } + ~XDGDesktop(){ + actions.clear(); + showInList.clear(); notShowInList.clear(); actionList.clear(); mimeList.clear(); catList.clear(); keyList.clear(); + name.clear(); genericName.clear(); comment.clear(); icon.clear(); + exec.clear(); tryexec.clear(); path.clear(); startupWM.clear(); url.clear(); + } }; // ======================== |