//=========================================== // Lumina-DE source code // Copyright (c) 2013, Ken Moore // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== #include "LuminaXDG.h" #include "LuminaOS.h" #include #include static QStringList mimeglobs; static qint64 mimechecktime; //==== LXDG Functions ==== 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.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 //Get the current localization code QString lang = QLocale::system().name(); //lang code //Open the 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) if(line=="[Desktop Entry]"){ insection=true; continue; } else if(line.startsWith("[")){ insection=false; } if(!insection || line.startsWith("#")){ continue; } //Now parse out the file line = line.simplified(); QString var = line.section("=",0,0).simplified(); 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(var=="Name"){ if(DF.name.isEmpty() && loc.isEmpty()){ DF.name = val; } else if(loc == lang){ DF.name = val; } //hasName = true; }else if(var=="GenericName"){ if(DF.genericName.isEmpty() && loc.isEmpty()){ DF.genericName = val; } else if(loc == lang){ DF.genericName = val; } }else if(var=="Comment"){ if(DF.comment.isEmpty() && loc.isEmpty()){ DF.comment = val; } 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; } } 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"){ 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"){ 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; } else{ DF.type = XDGDesktop::BAD; } //Unknown type //hasType = true; } } //end reading file 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; //Need to be careful about case insensitivity here - the QList functions don't understand it for(int i=0; i