From 041ac95214f0548e5a3f8f70363d1bf927b50d59 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 12 May 2015 15:36:16 -0400 Subject: Large update to the XDG autostart spec - Add full write support in libLumina. This still needs to be tested/integrated into lumina-config for full access. --- libLumina/LuminaXDG.cpp | 170 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 165 insertions(+), 5 deletions(-) (limited to 'libLumina/LuminaXDG.cpp') diff --git a/libLumina/LuminaXDG.cpp b/libLumina/LuminaXDG.cpp index 85a90aa9..78e56823 100644 --- a/libLumina/LuminaXDG.cpp +++ b/libLumina/LuminaXDG.cpp @@ -17,7 +17,7 @@ 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; + //bool hasName=false, hasType=false; XDGDesktop DF; DF.isHidden=false; DF.useTerminal=false; @@ -53,7 +53,7 @@ XDGDesktop LXDG::loadDesktopFile(QString filePath, bool& ok){ if(var=="Name"){ if(DF.name.isEmpty() && loc.isEmpty()){ DF.name = val; } else if(loc == lang){ DF.name = val; } - hasName = true; + //hasName = true; }else if(var=="GenericName"){ if(DF.genericName.isEmpty() && loc.isEmpty()){ DF.genericName = val; } else if(loc == lang){ DF.genericName = val; } @@ -87,7 +87,7 @@ XDGDesktop LXDG::loadDesktopFile(QString filePath, bool& ok){ else if(val.toLower()=="link"){ DF.type = XDGDesktop::LINK; } else if(val.toLower()=="dir"){ DF.type = XDGDesktop::DIR; } else{ DF.type = XDGDesktop::BAD; } //Unknown type - hasType = true; + //hasType = true; } } //end reading file file.close(); @@ -109,10 +109,121 @@ XDGDesktop LXDG::loadDesktopFile(QString filePath, bool& ok){ DF.catList << "Wine"; //Internal Lumina category only (not in XDG specs as of 11/14/14) } //Return the structure - if (hasName && hasType) ok = true; //without Name and Type, the structure cannot be a valid .desktop file + //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; } +bool LXDG::saveDesktopFile(XDGDesktop dFile, bool merge){ + bool autofile = dFile.filePath.contains("/autostart/"); //use the "Hidden" field instead of the "NoDisplay" + int insertloc = -1; + QStringList info; + if(QFile::exists(dFile.filePath) && merge){ + //Load the existing file and merge in in any changes + info = LUtils::readFile(dFile.filePath); + //set a couple flags based on the contents before we start iterating through + // - determine if a translated field was changed (need to remove all the now-invalid translations) + bool clearName, clearComment, clearGName; + QString tmp = info.filter("Name=").first().section("=",1,50); + clearName=(tmp!=dFile.name); + tmp = info.filter("Comment=").first().section("=",1,50); + clearComment=(tmp!=dFile.comment); + tmp = info.filter("GenericName=").first().section("=",1,50); + clearGName=(tmp!=dFile.genericName); + //Now start iterating through the file and changing fields as necessary + bool insection = false; + for(int i=0; i