diff options
-rw-r--r-- | libLumina/LuminaUtils.cpp | 48 | ||||
-rw-r--r-- | libLumina/LuminaUtils.h | 3 |
2 files changed, 44 insertions, 7 deletions
diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp index fd65ce03..c53edd27 100644 --- a/libLumina/LuminaUtils.cpp +++ b/libLumina/LuminaUtils.cpp @@ -1,6 +1,6 @@ //=========================================== // Lumina-DE source code -// Copyright (c) 2013, Ken Moore +// Copyright (c) 2013-2015, Ken Moore // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== @@ -16,6 +16,7 @@ #include <LuminaOS.h> #include <LuminaThemes.h> +#include <LuminaXDG.h> //============= // LUtils Functions @@ -145,7 +146,13 @@ void LUtils::LoadTranslation(QApplication *app, QString appname){ } QStringList LUtils::listFavorites(){ - QStringList fav = LUtils::readFile(QDir::homePath()+"/.lumina/favorites/fav.list"); + static QStringList fav; + static QDateTime lastRead; + QDateTime cur = QDateTime::currentDateTime(); + if(lastRead.isNull() || lastRead<QFileInfo(QDir::homePath()+"/.lumina/favorites/fav.list").lastModified()){ + fav = LUtils::readFile(QDir::homePath()+"/.lumina/favorites/fav.list"); + lastRead = cur; + } return fav; } @@ -164,9 +171,10 @@ bool LUtils::isFavorite(QString path){ bool LUtils::addFavorite(QString path, QString name){ //Generate the type of favorite this is QFileInfo info(path); - QString type = "file"; - if(info.isDir()){ type="dir"; } - else if(info.suffix()=="desktop"){ type="app"; } + QString type; + if(info.isDir()){ type="dir"; } + else if(info.suffix()=="desktop"){ type="app"; } + else{ type = LXDG::findAppMimeForFile(path); } //Assign a name if none given if(name.isEmpty()){ name = info.fileName(); } //Now add it to the list @@ -188,6 +196,34 @@ void LUtils::removeFavorite(QString path){ if(changed){ LUtils::saveFavorites(fav); } } +void LUtils::upgradeFavorites(int fromoldversionnumber){ + if(fromoldversionnumber <= 8004){ // < pre-0.8.4>, sym-links in the ~/.lumina/favorites dir} + //Include 0.8.4-devel versions in this upgrade (need to distinguish b/w devel and release versions later somehow) + QDir favdir(QDir::homePath()+"/.lumina/favorites"); + QFileInfoList symlinks = favdir.entryInfoList(QDir::Files | QDir::Dirs | QDir::System | QDir::NoDotAndDotDot); + QStringList favfile = LUtils::listFavorites(); //just in case some already exist + bool newentry = false; + for(int i=0; i<symlinks.length(); i++){ + if(!symlinks[i].isSymLink()){ continue; } //not a symlink + QString path = symlinks[i].symLinkTarget(); + QString name = symlinks[i].fileName(); //just use the name of the symlink from the old system + QString type; + if(symlinks[i].isDir()){ type = "dir"; } + else if(name.endsWith(".desktop")){ type = "app"; } + else{ type = LXDG::findAppMimeForFile(path); } + //Put the line into the file + favfile << name+"::::"+type+"::::"+path; + //Now remove the symlink - obsolete format + QFile::remove(symlinks[i].absoluteFilePath()); + newentry = true; + } + if(newentry){ + LUtils::saveFavorites(favfile); + } + } //end check for version <= 0.8.4 + +} + void LUtils::LoadSystemDefaults(bool skipOS){ //Will create the Lumina configuration files based on the current system template (if any) QStringList sysDefaults; @@ -342,4 +378,4 @@ void LUtils::LoadSystemDefaults(bool skipOS){ if(setTheme){ LTHEME::setCurrentSettings( themesettings[0], themesettings[1], themesettings[2], themesettings[3], themesettings[4]); } LUtils::writeFile(setdir+"/sessionsettings.conf", sesset, true); LUtils::writeFile(setdir+"/desktopsettings.conf", deskset, true); -}
\ No newline at end of file +} diff --git a/libLumina/LuminaUtils.h b/libLumina/LuminaUtils.h index d0c8b3ad..7af32d21 100644 --- a/libLumina/LuminaUtils.h +++ b/libLumina/LuminaUtils.h @@ -46,13 +46,14 @@ public: //Various functions for the favorites sub-system - // Formatting Note: "<name>::::[dir/file/app]::::<path>" + // Formatting Note: "<name>::::[dir/app/<mimetype>]::::<path>" // the <name> field might not be used for "app" flagged entries static QStringList listFavorites(); static bool saveFavorites(QStringList); static bool isFavorite(QString path); static bool addFavorite(QString path, QString name = ""); static void removeFavorite(QString path); + static void upgradeFavorites(int fromoldversionnumber); //Load the default setup for the system static void LoadSystemDefaults(bool skipOS = false); |