diff options
author | william <william.os4y@gmail.com> | 2015-03-14 21:34:39 +0100 |
---|---|---|
committer | william <william.os4y@gmail.com> | 2015-03-14 21:34:39 +0100 |
commit | 59bd42ae3da3da0181f6bbe53580fd741d17fae9 (patch) | |
tree | 258b5ac0db26d5553e1ed438cd993e0cab5ab38b /libLumina/LuminaUtils.cpp | |
parent | spelling error (diff) | |
parent | Add a new favoriting system to the Lumina Utils library. This should make thi... (diff) | |
download | lumina-59bd42ae3da3da0181f6bbe53580fd741d17fae9.tar.gz lumina-59bd42ae3da3da0181f6bbe53580fd741d17fae9.tar.bz2 lumina-59bd42ae3da3da0181f6bbe53580fd741d17fae9.zip |
Merge remote-tracking branch 'upstream/master' into deskEditor
Diffstat (limited to 'libLumina/LuminaUtils.cpp')
-rw-r--r-- | libLumina/LuminaUtils.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp index 9b8a1860..f7f5db74 100644 --- a/libLumina/LuminaUtils.cpp +++ b/libLumina/LuminaUtils.cpp @@ -144,6 +144,50 @@ void LUtils::LoadTranslation(QApplication *app, QString appname){ QTextCodec::setCodecForLocale( QTextCodec::codecForName(langEnc.toUtf8()) ); } +QStringList LUtils::listFavorites(){ + QStringList fav = LUtils::readFile(QDir::homePath()+"/.lumina/favorites/fav.list"); + return fav; +} + +bool LUtils::saveFavorites(QStringList list){ + return LUtils::writeFile(QDir::homePath()+"/.lumina/favorites/fav.list", list, true); +} + +bool LUtils::isFavorite(QString path){ + QStringList fav = LUtils::listFavorites(); + for(int i=0; i<fav.length(); i++){ + if(fav[i].endsWith("::::"+path)){ return true; } + } + return false; +} + +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"; } + //Assign a name if none given + if(name.isEmpty()){ name = info.fileName(); } + //Now add it to the list + QStringList fav = LUtils::listFavorites(); + bool found = false; + for(int i=0; i<fav.length(); i++){ + if(fav[i].endsWith("::::"+path)){ fav[i] = name+"::::"+type+"::::"+path; } + } + if(!found){ fav << name+"::::"+type+"::::"+path; } + return LUtils::saveFavorites(fav); +} + +void LUtils::removeFavorite(QString path){ + QStringList fav = LUtils::listFavorites(); + bool changed = false; + for(int i=0; i<fav.length(); i++){ + if(fav[i].endsWith("::::"+path)){ fav.removeAt(i); i--; changed=true;} + } + if(changed){ LUtils::saveFavorites(fav); } +} + void LUtils::LoadSystemDefaults(bool skipOS){ //Will create the Lumina configuration files based on the current system template (if any) QStringList sysDefaults; |