aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core/libLumina/LuminaXDG.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/core/libLumina/LuminaXDG.cpp')
-rw-r--r--src-qt5/core/libLumina/LuminaXDG.cpp336
1 files changed, 0 insertions, 336 deletions
diff --git a/src-qt5/core/libLumina/LuminaXDG.cpp b/src-qt5/core/libLumina/LuminaXDG.cpp
index 96f77ff9..790b386e 100644
--- a/src-qt5/core/libLumina/LuminaXDG.cpp
+++ b/src-qt5/core/libLumina/LuminaXDG.cpp
@@ -586,287 +586,6 @@ bool LFileInfo::isAVFile(){
//==== LXDG Functions ====
-/*XDGDesktop *LXDG::loadDesktopFile(QString filePath, bool& ok, QObject *parent){
- //Create the outputs
- ok=false;
- XDGDesktop *DF = new XDGDesktop(parent);
- 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
-
- //Get the current localization code
- QString lang = QLocale::system().name(); //lang code
- QString slang = lang.section("_",0,0); //short lang code
-
- //Read in the File
- bool insection=false;
- bool inaction=false;
- QStringList file = LUtils::readFile(filePath);
- if(file.isEmpty()){ return DF; }
- //if(filePath.contains("pcbsd")){ qDebug() << "Check File:" << filePath << lang << slang; }
- XDGDesktopAction CDA; //current desktop action
- for(int i=0; i<file.length(); i++){
- QString line = file[i];
- //if(filePath.contains("pcbsd")){ qDebug() << " - Check Line:" << line << inaction << insection; }
- //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("[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();
- 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(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" && 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" && 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(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()) && 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" && 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; }
- else{ DF->type = XDGDesktop::BAD; } //Unknown type
- //hasType = true;
- }
- } //end reading file
- file.clear(); //done with contents of file
- //If there are OnlyShowIn desktops listed, add them to the name
- if( !DF->showInList.isEmpty() && !DF->showInList.contains("Lumina", Qt::CaseInsensitive) ){
- DF->name.append(" ("+DF->showInList.join(", ")+")");
- }
- //Quick fix for showing "wine" applications (which quite often don't list a category, or have other differences)
- if(DF->catList.isEmpty() && filePath.contains("/wine/")){
- DF->catList << "Wine"; //Internal Lumina category only (not in XDG specs as of 11/14/14)
- //Also add a fix for the location of Wine icons
- if( !DF->icon.isEmpty() ){
- QStringList sizes; sizes << "256x256" << "128x128" << "64x64" << "48x48" << "32x32" << "16x16";
- QString upath = QDir::homePath()+"/.local/share/icons/hicolor/%1/apps/%2.png";
- //qDebug() << "Wine App: Check icon" << upath;
- for(int i=0; i<sizes.length(); i++){
- if( QFile::exists(upath.arg(sizes[i],DF->icon)) ){
- DF->icon = upath.arg(sizes[i],DF->icon);
- //qDebug() << " - Found Icon:" << DF->icon;
- break;
- }
- }
- }
- }
- //Return the structure
- ok = true; //was able to open/read the file - validity determined later
- return DF;
-}*/
-
-/*bool LXDG::saveDesktopFile(XDGDesktop dFile, bool merge){
- qDebug() << "Save Desktop File:" << dFile.filePath << "Merge:" << 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 = "";
- if(!info.filter("Name=").isEmpty()){ tmp = info.filter("Name=").first().section("=",1,50); }
- clearName=(tmp!=dFile.name);
- tmp.clear();
- if(!info.filter("Comment=").isEmpty()){ tmp = info.filter("Comment=").first().section("=",1,50); }
- clearComment=(tmp!=dFile.comment);
- tmp.clear();
- if(!info.filter("GenericName=").isEmpty()){ 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<info.length(); i++){
- if(info[i]=="[Desktop Entry]"){
- insection = true;
- continue;
- }else if(info[i].startsWith("[")){
- if(insection){ insertloc = i; } //save this location for later insertions
- insection = false;
- continue;
- }
- if(!insection || info[i].isEmpty() || info[i].section("#",0,0).simplified().isEmpty()){ continue; }
- QString var = info[i].section("=",0,0);
- QString val = info[i].section("=",1,50).simplified();
- //NOTE: Clear the dFile variable as it is found/set in the file (to keep track of what has been used already)
- // For boolian values, set them to false
- // --LOCALIZED VALUES --
- if(var.startsWith("Name")){
- if(var.contains("[") && clearName){ info.removeAt(i); i--; continue;}
- else if(!var.contains("[")){ info[i] = var+"="+dFile.name; dFile.name.clear(); }
- }else if(var.startsWith("GenericName")){
- if(var.contains("[") && clearGName){ info.removeAt(i); i--; continue;}
- else if(!var.contains("[")){ info[i] = var+"="+dFile.genericName; dFile.genericName.clear(); }
- }else if(var.startsWith("Comment")){
- if(var.contains("[") && clearComment){ info.removeAt(i); i--; continue;}
- else if(!var.contains("[")){ info[i] = var+"="+dFile.comment; dFile.comment.clear(); }
-
- // --STRING/LIST VALUES--
- }else if(var=="Exec"){ info[i] = var+"="+dFile.exec; dFile.exec.clear(); }
- else if(var=="TryExec"){ info[i] = var+"="+dFile.tryexec; dFile.tryexec.clear(); }
- else if(var=="Path"){ info[i] = var+"="+dFile.path; dFile.path.clear(); }
- else if(var=="Icon"){ info[i] = var+"="+dFile.icon; dFile.icon.clear(); }
- else if(var=="StartupWMClass"){ info[i] = var+"="+dFile.startupWM; dFile.startupWM.clear(); }
- else if(var=="MimeType"){ info[i] = var+"="+dFile.mimeList.join(";"); dFile.mimeList.clear(); }
- else if(var=="Categories"){ info[i] = var+"="+dFile.catList.join(";"); dFile.catList.clear(); }
- else if(var=="Keywords"){ info[i] = var+"="+dFile.keyList.join(";"); dFile.keyList.clear(); }
- else if(var=="Actions"){ info[i] = var+"="+dFile.actionList.join(";"); dFile.actionList.clear(); }
- else if(var=="OnlyShowIn"){ info[i] = var+"="+dFile.showInList.join(";"); dFile.showInList.clear(); }
- else if(var=="NotShowIn"){ info[i] = var+"="+dFile.notShowInList.join(";"); dFile.notShowInList.clear(); }
- else if(var=="URL"){ info[i] = var+"="+dFile.url; dFile.url.clear(); }
-
- // --BOOLIAN VALUES--
- else if(var=="Hidden"){
- if(!autofile){ info.removeAt(i); i--; continue; }
- else{ info[i] = var+"="+(dFile.isHidden ? "true": "false"); dFile.isHidden=false;}
- }else if(var=="NoDisplay"){
- if(autofile){ info.removeAt(i); i--; continue; }
- else{ info[i] = var+"="+(dFile.isHidden ? "true": "false"); dFile.isHidden=false;}
- }else if(var=="Terminal"){
- info[i] = var+"="+(dFile.useTerminal ? "true": "false"); dFile.useTerminal=false;
- }else if(var=="StartupNotify"){
- info[i] = var+"="+(dFile.startupNotify ? "true": "false"); dFile.startupNotify=false;
- }
- // Remove any lines that have been un-set or removed from the file
- if(info[i].section("=",1,50).simplified().isEmpty()){ info.removeAt(i); i--; }
- }
-
- }else{
- //Just write a new file and overwrite any old one
- // (pre-set some values here which are always required)
- info << "[Desktop Entry]";
- info << "Version=1.0";
- if(dFile.type==XDGDesktop::APP){ info << "Type=Application"; }
- else if(dFile.type==XDGDesktop::LINK){ info << "Type=Link"; }
- else if(dFile.type==XDGDesktop::DIR){ info << "Type=Dir"; }
- }
-
- if(insertloc<0){ insertloc = info.size(); }//put it at the end
- //Now add in any items that did not exist in the original file
- if( !dFile.exec.isEmpty() ){ info.insert(insertloc,"Exec="+dFile.exec); }
- if( !dFile.tryexec.isEmpty() ){ info.insert(insertloc,"TryExec="+dFile.tryexec); }
- if( !dFile.path.isEmpty() ){ info.insert(insertloc,"Path="+dFile.path); }
- if( !dFile.icon.isEmpty() ){ info.insert(insertloc,"Icon="+dFile.icon); }
- if( !dFile.name.isEmpty() ){ info.insert(insertloc,"Name="+dFile.name); }
- if( !dFile.genericName.isEmpty() ){ info.insert(insertloc,"GenericName="+dFile.genericName); }
- if( !dFile.comment.isEmpty() ){ info.insert(insertloc,"Comment="+dFile.comment); }
- if( !dFile.startupWM.isEmpty() ){ info.insert(insertloc,"StartupWMClass="+dFile.startupWM); }
- if( !dFile.mimeList.isEmpty() ){ info.insert(insertloc,"MimeType="+dFile.mimeList.join(";")); }
- if( !dFile.catList.isEmpty() ){ info.insert(insertloc,"Categories="+dFile.catList.join(";")); }
- if( !dFile.keyList.isEmpty() ){ info.insert(insertloc,"Keywords="+dFile.keyList.join(";")); }
- if( !dFile.actionList.isEmpty() ){ info.insert(insertloc,"Actions="+dFile.actionList.join(";")); }
- if( !dFile.showInList.isEmpty() ){ info.insert(insertloc,"OnlyShowIn="+dFile.showInList.join(";")); }
- else if( !dFile.notShowInList.isEmpty() ){ info.insert(insertloc,"NotShowIn="+dFile.notShowInList.join(";")); }
- if( !dFile.url.isEmpty() ){ info.insert(insertloc,"URL="+dFile.url); }
- if( dFile.isHidden && autofile ){ info.insert(insertloc,"Hidden=true"); }
- else if(dFile.isHidden){ info.insert(insertloc,"NoDisplay=true"); }
- if( dFile.useTerminal){ info.insert(insertloc,"Terminal=true"); }
- if( dFile.startupNotify ){ info.insert(insertloc,"StartupNotify=true"); }
-
- //Now save the file
- return LUtils::writeFile(dFile.filePath, info, true);
-
-}*/
-
-/*bool LXDG::checkValidity(XDGDesktop dFile, bool showAll){
- bool ok=true;
- bool DEBUG = false;
- if(DEBUG){ qDebug() << "[LXDG] Check File validity:" << dFile.name << dFile.filePath; }
- switch (dFile.type){
- case XDGDesktop::BAD:
- ok=false;
- if(DEBUG){ qDebug() << " - Bad file type"; }
- break;
- case XDGDesktop::APP:
- if(!dFile.tryexec.isEmpty() && !LXDG::checkExec(dFile.tryexec)){ ok=false; if(DEBUG){ qDebug() << " - tryexec does not exist";} }
- else if(dFile.exec.isEmpty() || dFile.name.isEmpty()){ ok=false; if(DEBUG){ qDebug() << " - exec or name is empty";} }
- else if(!LXDG::checkExec(dFile.exec.section(" ",0,0,QString::SectionSkipEmpty)) ){ ok=false; if(DEBUG){ qDebug() << " - first exec binary does not exist";} }
- break;
- case XDGDesktop::LINK:
- ok = !dFile.url.isEmpty();
- if(DEBUG && !ok){ qDebug() << " - Link with missing URL"; }
- break;
- case XDGDesktop::DIR:
- ok = !dFile.path.isEmpty();
- if(DEBUG && !ok){ qDebug() << " - Dir with missing path"; }
- break;
- default:
- ok=false;
- if(DEBUG){ qDebug() << " - Unknown file type"; }
- }
- if(!showAll){
- if(!dFile.showInList.isEmpty()){ ok = dFile.showInList.contains("Lumina", Qt::CaseInsensitive); }
- else if(!dFile.notShowInList.isEmpty()){ ok = !dFile.notShowInList.contains("Lumina",Qt::CaseInsensitive); }
- else if(dFile.name.isEmpty()){ ok = false; }
- }
- return ok;
-}*/
-
bool LXDG::checkExec(QString exec){
//Return true(good) or false(bad)
if(exec.startsWith("/")){ return QFile::exists(exec); }
@@ -899,21 +618,6 @@ QStringList LXDG::systemApplicationDirs(){
return out;
}
-/*XDGDesktopList* LXDG::systemAppsList(){
- static XDGDesktopList *sysapps = 0;
- if(sysapps == 0){ qDebug() << "Generating new apps list"; sysapps = new XDGDesktopList(0,true); }//set this to automatically update as needed
- if(sysapps->lastCheck.isNull()){ sysapps->updateList(); } //catch the first time the class was used, and prompt for an update right now
- return sysapps;
-}*/
-
-/*QList<XDGDesktop*> LXDG::systemDesktopFiles(bool showAll, bool showHidden){
- //If this is going to be used regularly, it is better to use a custom instance of an XDGDesktopList() which self-updates instead.
- // Since this function will need to re-read the entire system app registry every time.
- XDGDesktopList sysapps;
- sysapps.updateList();
- return sysapps.apps(showAll, showHidden);
-}*/
-
QHash<QString,QList<XDGDesktop*> > LXDG::sortDesktopCats(QList<XDGDesktop*> apps){
//Sort the list of applications into their different categories (main categories only)
//Create the category lists
@@ -987,46 +691,6 @@ QList<XDGDesktop*> LXDG::sortDesktopNames(QList<XDGDesktop*> apps){
return out;
}
-/*QString LXDG::getDesktopExec(XDGDesktop app, QString ActionID){
- //Generate the executable line for the application
- QString out;
- QString exec = app.exec;
- if( !ActionID.isEmpty() ){
- //Go through and grab the proper exec for the listed action
- for(int i=0; i<app.actions.length(); i++){
- if(app.actions[i].ID == ActionID){
- exec = app.actions[i].exec;
- break;
- }
- }
- }
-
- if(exec.isEmpty()){ return ""; }
- else if(app.useTerminal){
- //Get the currently default terminal
- QString term = findDefaultAppForMime("application/terminal");
- if(!QFile::exists(term)){ term = "xterm -lc"; }
- else if(term.endsWith(".desktop")){
- bool ok = false;
- XDGDesktop DF = LXDG::loadDesktopFile(term, ok);
- if(ok){ term = LXDG::getDesktopExec(DF); }
- else{ term = "xterm -lc"; }
- }else if( !LUtils::isValidBinary(term)){ term = "xterm -lc"; }
- out = term+" -e "+exec; //-e is a nearly-universal flag for terminal emulators
- }else{
- out =exec;
- }
- //Now perform any of the XDG flag substitutions as appropriate (9/2014 standards)
- if(out.contains("%i") && !app.icon.isEmpty() ){ out.replace("%i", "--icon \'"+app.icon+"\'"); }
- if(out.contains("%c")){
- if(!app.name.isEmpty()){ out.replace("%c", "\'"+app.name+"\'"); }
- else if(!app.genericName.isEmpty()){ out.replace("%c", "\'"+app.genericName+"\'"); }
- else{ out.replace("%c", "\'"+app.filePath.section("/",-1).section(".desktop",0,0)+"\'"); }
- }
- if(out.contains("%k")){ out.replace("%k", "\'"+app.filePath+"\'"); }
- return out;
-}*/
-
void LXDG::setEnvironmentVars(){
//Set the default XDG environment variables if not already set
setenv("XDG_DATA_HOME",QString(QDir::homePath()+"/.local/share").toUtf8(), 0);
bgstack15