diff options
-rw-r--r-- | libLumina/LuminaXDG.cpp | 106 | ||||
-rw-r--r-- | libLumina/LuminaXDG.h | 10 |
2 files changed, 80 insertions, 36 deletions
diff --git a/libLumina/LuminaXDG.cpp b/libLumina/LuminaXDG.cpp index ed576f23..19a3fbae 100644 --- a/libLumina/LuminaXDG.cpp +++ b/libLumina/LuminaXDG.cpp @@ -6,6 +6,7 @@ //=========================================== #include "LuminaXDG.h" #include "LuminaOS.h" +#include "LuminaUtils.h" #include <QObject> #include <QMediaPlayer> @@ -16,33 +17,47 @@ static qint64 mimechecktime; XDGDesktop LXDG::loadDesktopFile(QString filePath, bool& ok){ //Create the outputs ok=false; - //following the specifications, Name and Type are the mandatory in any .desktop file - //bool hasName=false, hasType=false; XDGDesktop DF; DF.isHidden=false; DF.useTerminal=false; DF.startupNotify=false; DF.type = XDGDesktop::APP; DF.filePath = filePath; + DF.lastRead = QDateTime::currentDateTime(); DF.exec = DF.tryexec = ""; // just to make sure this is initialized //Check input file path validity - QFile file(filePath); - if(!file.exists()){ return DF; } //invalid file + //QFile file(filePath); + //if(!file.exists()){ return DF; } //invalid file //Get the current localization code QString lang = QLocale::system().name(); //lang code + QString slang = lang.section("_",0,0); //short lang code //Open the file - if(!file.open(QIODevice::Text | QIODevice::ReadOnly)){ - return DF; - } - QTextStream os(&file); + //if(!file.open(QIODevice::Text | QIODevice::ReadOnly)){ + //return DF; + //} + //QTextStream os(&file); //Read in the File bool insection=false; - while(!os.atEnd()){ - QString line = os.readLine(); - //Check that this is the entry portion of the file (not the action/other sections) + bool inaction=false; + QStringList file = LUtils::readFile(filePath); + if(file.isEmpty()){ return DF; } + XDGDesktopAction CDA; //current desktop action + for(int i=0; i<file.length(); i++){ + QString line = file[i]; + //Check if this is the end of a section + if(line.startsWith("[") && inaction){ + insection=false; inaction=false; + //Add the current Action structure to the main desktop structure if appropriate + if(!CDA.ID.isEmpty()){ DF.actions << CDA; CDA = XDGDesktopAction(); } + }else if(line.startsWith("[")){ insection=false; inaction = false; } + //Now check if this is the beginning of a section if(line=="[Desktop Entry]"){ insection=true; continue; } - else if(line.startsWith("[")){ insection=false; } - if(!insection || line.startsWith("#")){ continue; } + else if(line.startsWith("[Desktop Action ")){ + //Grab the ID of the action out of the label + CDA.ID = line.section("]",0,0).section("Desktop Action",1,1).simplified(); + inaction = true; + continue; + }else if(!insection || !inaction || line.startsWith("#")){ continue; } //Now parse out the file line = line.simplified(); QString var = line.section("=",0,0).simplified(); @@ -51,38 +66,57 @@ XDGDesktop LXDG::loadDesktopFile(QString filePath, bool& ok){ QString val = line.section("=",1,50).simplified(); //------------------- if(var=="Name"){ - if(DF.name.isEmpty() && loc.isEmpty()){ DF.name = val; } - else if(loc == lang){ DF.name = val; } + if(insection){ + if(DF.name.isEmpty() && loc.isEmpty()){ DF.name = val; } + else if(DF.name.isEmpty() && loc==slang){ DF.name = val; } //short locale code + else if(loc == lang){ DF.name = val; } + }else if(inaction){ + if(CDA.name.isEmpty() && loc.isEmpty()){ CDA.name = val; } + else if(CDA.name.isEmpty() && loc==slang){ CDA.name = val; } //short locale code + else if(loc == lang){ CDA.name = val; } + } //hasName = true; - }else if(var=="GenericName"){ + }else if(var=="GenericName" && insection){ if(DF.genericName.isEmpty() && loc.isEmpty()){ DF.genericName = val; } + else if(DF.genericName.isEmpty() && loc==slang){ DF.genericName = val; } //short locale code else if(loc == lang){ DF.genericName = val; } - }else if(var=="Comment"){ + }else if(var=="Comment" && insection){ if(DF.comment.isEmpty() && loc.isEmpty()){ DF.comment = val; } + else if(DF.comment.isEmpty() && loc==slang){ DF.comment = val; } //short locale code else if(loc == lang){ DF.comment = val; } }else if(var=="Icon"){ - if(DF.icon.isEmpty() && loc.isEmpty()){ DF.icon = val; } - else if(loc == lang){ DF.icon = val; } + if(insection){ + if(DF.icon.isEmpty() && loc.isEmpty()){ DF.icon = val; } + else if(DF.icon.isEmpty() && loc==slang){ DF.icon = val; } //short locale code + else if(loc == lang){ DF.icon = val; } + }else if(inaction){ + if(CDA.icon.isEmpty() && loc.isEmpty()){ CDA.icon = val; } + else if(CDA.icon.isEmpty() && loc==slang){ CDA.icon = val; } //short locale code + else if(loc == lang){ CDA.icon = val; } + } } - else if( (var=="TryExec") && (DF.tryexec.isEmpty()) ) { DF.tryexec = val; } - else if( (var=="Exec") && (DF.exec.isEmpty() ) ) { DF.exec = val; } // only take the first Exec command in the file - else if( (var=="Path") && (DF.path.isEmpty() ) ){ DF.path = val; } - else if(var=="NoDisplay" && !DF.isHidden){ DF.isHidden = (val.toLower()=="true"); } - else if(var=="Hidden" && !DF.isHidden){ DF.isHidden = (val.toLower()=="true"); } - else if(var=="Categories"){ DF.catList = val.split(";",QString::SkipEmptyParts); } - else if(var=="OnlyShowIn"){ DF.showInList = val.split(";",QString::SkipEmptyParts); } - else if(var=="NotShowIn"){ DF.notShowInList = val.split(";",QString::SkipEmptyParts); } - else if(var=="Terminal"){ DF.useTerminal= (val.toLower()=="true"); } - else if(var=="Actions"){ DF.actionList = val.split(";",QString::SkipEmptyParts); } - else if(var=="MimeType"){ DF.mimeList = val.split(";",QString::SkipEmptyParts); } - else if(var=="Keywords"){ + else if( (var=="TryExec") && (DF.tryexec.isEmpty()) && insection) { DF.tryexec = val; } + else if(var=="Exec"){ + if(insection && DF.exec.isEmpty() ){ DF.exec = val; } + else if(inaction && CDA.exec.isEmpty() ){ CDA.exec = val; } + } + else if( (var=="Path") && (DF.path.isEmpty() ) && insection){ DF.path = val; } + else if(var=="NoDisplay" && !DF.isHidden && insection){ DF.isHidden = (val.toLower()=="true"); } + else if(var=="Hidden" && !DF.isHidden && insection){ DF.isHidden = (val.toLower()=="true"); } + else if(var=="Categories" && insection){ DF.catList = val.split(";",QString::SkipEmptyParts); } + else if(var=="OnlyShowIn" && insection){ DF.showInList = val.split(";",QString::SkipEmptyParts); } + else if(var=="NotShowIn" && insection){ DF.notShowInList = val.split(";",QString::SkipEmptyParts); } + else if(var=="Terminal" && insection){ DF.useTerminal= (val.toLower()=="true"); } + else if(var=="Actions" && insection){ DF.actionList = val.split(";",QString::SkipEmptyParts); } + else if(var=="MimeType" && insection){ DF.mimeList = val.split(";",QString::SkipEmptyParts); } + else if(var=="Keywords" && insection){ if(DF.keyList.isEmpty() && loc.isEmpty()){ DF.keyList = val.split(";",QString::SkipEmptyParts); } else if(loc == lang){ DF.keyList = val.split(";",QString::SkipEmptyParts); } } - else if(var=="StartupNotify"){ DF.startupNotify = (val.toLower()=="true"); } - else if(var=="StartupWMClass"){ DF.startupWM = val; } - else if(var=="URL"){ DF.url = val;} - else if(var=="Type"){ + else if(var=="StartupNotify" && insection){ DF.startupNotify = (val.toLower()=="true"); } + else if(var=="StartupWMClass" && insection){ DF.startupWM = val; } + else if(var=="URL" && insection){ DF.url = val;} + else if(var=="Type" && insection){ if(val.toLower()=="application"){ DF.type = XDGDesktop::APP; } else if(val.toLower()=="link"){ DF.type = XDGDesktop::LINK; } else if(val.toLower()=="dir"){ DF.type = XDGDesktop::DIR; } @@ -90,7 +124,7 @@ XDGDesktop LXDG::loadDesktopFile(QString filePath, bool& ok){ //hasType = true; } } //end reading file - file.close(); + //file.close(); //If there are OnlyShowIn desktops listed, add them to the name if( !DF.showInList.isEmpty() && !DF.showInList.contains("Lumina", Qt::CaseInsensitive) ){ /*QStringList added; diff --git a/libLumina/LuminaXDG.h b/libLumina/LuminaXDG.h index 1361ba7c..879d905a 100644 --- a/libLumina/LuminaXDG.h +++ b/libLumina/LuminaXDG.h @@ -30,11 +30,20 @@ #include <QDateTime> #include <QDebug> +class 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 + QString name, icon, exec; +}; + class 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 XDGDesktopType type; //General variables QString name, genericName, comment, icon; @@ -44,6 +53,7 @@ public: QString exec, tryexec, path, startupWM; QStringList actionList, mimeList, catList, keyList; bool useTerminal, startupNotify; + QList<XDGDesktopAction> actions; //Type 2 (LINK) variables QString url; |