diff -Nru jwm-menu-3.0.1ubuntu1/debian/bzr-builder.manifest jwm-menu-3.0.1ubuntu1/debian/bzr-builder.manifest --- jwm-menu-3.0.1ubuntu1/debian/bzr-builder.manifest 2018-09-28 13:30:45.000000000 +0000 +++ jwm-menu-3.0.1ubuntu1/debian/bzr-builder.manifest 2019-01-24 14:09:25.000000000 +0000 @@ -1,2 +1,2 @@ -# bzr-builder format 0.3 deb-version {debupstream}-117 -lp:jwm-menu revid:israeldahl@gmail.com-20180314191550-1xgndq5tc3x5cdlw +# bzr-builder format 0.3 deb-version {debupstream}-118 +lp:jwm-menu revid:israeldahl@gmail.com-20181126012938-nblcowsueespcrs6 diff -Nru jwm-menu-3.0.1ubuntu1/debian/changelog jwm-menu-3.0.1ubuntu1/debian/changelog --- jwm-menu-3.0.1ubuntu1/debian/changelog 2018-09-28 13:30:45.000000000 +0000 +++ jwm-menu-3.0.1ubuntu1/debian/changelog 2019-01-24 14:09:25.000000000 +0000 @@ -1,8 +1,8 @@ -jwm-menu (3.0.1ubuntu1-117~ubuntu18.10.1) cosmic; urgency=low +jwm-menu (3.0.1ubuntu1-118~ubuntu18.10.1) cosmic; urgency=low * Auto build. - -- Israel Dahl Fri, 28 Sep 2018 13:30:45 +0000 + -- Israel Dahl Thu, 24 Jan 2019 14:09:25 +0000 jwm-menu (3.0.1ubuntu1) UNRELEASED; urgency=medium * reworked package diff -Nru jwm-menu-3.0.1ubuntu1/src/common.cpp jwm-menu-3.0.1ubuntu1/src/common.cpp --- jwm-menu-3.0.1ubuntu1/src/common.cpp 2018-09-28 13:30:44.000000000 +0000 +++ jwm-menu-3.0.1ubuntu1/src/common.cpp 2019-01-24 14:09:25.000000000 +0000 @@ -1028,6 +1028,7 @@ if(thisXDG.compare("")!=0)thisXDG+= ":"; thisXDG += datahome; } + return delimiter_vector_from_string(thisXDG,":"); unsigned int numberOfPaths; std::string tempXDG = thisXDG; unsigned int tryer; @@ -1042,7 +1043,7 @@ for (unsigned int whichPath=1;whichPath<=numberOfPaths;whichPath++){ if (whichPath >=1){lastPath = whichPath - 1;} else {lastPath = 0;} - std::string::size_type firstPosition = thisXDG.find_first_of(':'); + std::string::size_type firstPosition = thisXDG.find(':'); std::string::size_type position = thisXDG.find(':'); for (unsigned int i=1;i<=whichPath;i++){position = thisXDG.find(':',position+1);} for (unsigned int j=1;j<=lastPath;j++){firstPosition = thisXDG.find(':',firstPosition+1);} diff -Nru jwm-menu-3.0.1ubuntu1/src/menuXDG-alt.cxx jwm-menu-3.0.1ubuntu1/src/menuXDG-alt.cxx --- jwm-menu-3.0.1ubuntu1/src/menuXDG-alt.cxx 2018-09-28 13:30:44.000000000 +0000 +++ jwm-menu-3.0.1ubuntu1/src/menuXDG-alt.cxx 2019-01-24 14:09:25.000000000 +0000 @@ -39,6 +39,7 @@ //////////////////////////////// Global Variables std::string MENU_CACHE_FILE; +std::string LANGUAGE; std::string MENU_TO_MERGE; bool RELOAD; bool USECOMMENTS; @@ -129,6 +130,7 @@ //////////////////////////////////////////////////////////////////MAIN int main(int argc, char* argv[]) { bool isCached=checkCache(); + if(isCached)outXML("CACHED!!!"); RELOAD=false; INCEPTION=false; MERGE_inception=false; @@ -188,19 +190,23 @@ MENU_CACHE_FILE=getCacheFile(); char datestring[256]; bool isCached = false; + if(!linuxcommon::test_file(MENU_CACHE_FILE.c_str())){return false;} std::vector uniqueDirs = linuxcommon::desktop_paths(); std::string testPATH ="/usr/share/applications"; for( std::vector::iterator iter = uniqueDirs.begin(); iter!=uniqueDirs.end(); - ++iter){ + ++iter) + { testPATH = *iter; - bool prevCach=isCached; + //bool prevCach=isCached; isCached=checkCacheDirStat(testPATH,statFilename); - + if(isCached)outXML("checkcache TRUE for:"+statFilename); + else + outXML("checkcache FALSE for:"+statFilename); //if( (prevCach != isCached ) && (isCached) ){ //isCached=false;} } - if(!linuxcommon::test_file(MENU_CACHE_FILE.c_str())){isCached=false;} + return isCached; } bool checkCacheDirStat(std::string dirname,std::string statFilename){ @@ -225,20 +231,20 @@ stat(dirname.c_str(), &stat_structure); timer_result = gmtime(&(stat_structure.st_mtime)); strftime(datestring, sizeof(datestring), nl_langinfo(D_T_FMT), timer_result); - if(linuxcommon::test_file(statFilename.c_str())){ + if(linuxcommon::test_file(statFilename.c_str())) + { //get previous date - std::string line; - std::string currentTime; - std::ifstream thisfile(statFilename.c_str(), std::ifstream::in); - if(thisfile.is_open()){ - while (getline(thisfile,line)){ - currentTime=line; - if(currentTime.compare(datestring)==0){ res=true;} - } - } - - } - if(statFilename.compare("")!=0){ + std::string line; + std::string currentTime; + std::ifstream thisfile(statFilename.c_str(), std::ifstream::in); + if(thisfile.is_open()) + { + while (getline(thisfile,line)) + { + currentTime=line; + if(currentTime.compare(datestring)==0){ res=true;} + } + } std::ofstream myfile; //outXML(statFilename); myfile.open (statFilename.c_str()); @@ -675,7 +681,7 @@ return false; } bool no_display(std::string filename) { - std::string result = linuxcommon::get_line_with_equal(filename,"NoDisplay="); + std::string result = linuxcommon::get_line_with_equal(filename,"NoDisplay"); if(result.compare("")==0){ return false; } @@ -694,7 +700,7 @@ if(desktop_session1==NULL){desktop_session1="JWM";} std::string desktop_session=desktop_session1; std::transform(desktop_session.begin(),desktop_session.end(),desktop_session.begin(),::tolower); - std::string result = linuxcommon::get_line_with_equal(filename,"NotShowIn="); + std::string result = linuxcommon::get_line_with_equal(filename,"NotShowIn"); unsigned int found = 0; if(result.compare("")==0){ return false; @@ -763,7 +769,7 @@ return false; } bool terminal(std::string filename) { - std::string result = linuxcommon::get_line_with_equal(filename,"Terminal="); + std::string result = linuxcommon::get_line_with_equal(filename,"Terminal "); if(result.compare("")==0){ //Only show in line doesn't exist return false; @@ -1187,7 +1193,7 @@ CHROME = "Chrome Apps"; std::string temp1,temp2; unsigned int found; - std::string catline = linuxcommon::get_line_with_equal(filename,"Categories="); + std::string catline = linuxcommon::get_line_with_equal(filename,"Categories"); /*unsigned int chromefind = filename.find("chrome"); if (chromefind < filename.length()){return CHROME;}*/ if (catline.compare("")==0){return OTH;} @@ -1238,7 +1244,7 @@ return ""; } std::string exec_line(std::string filename) { - std::string tmpExec=linuxcommon::get_line_with_equal(filename,"TryExec="); + std::string tmpExec=linuxcommon::get_line_with_equal(filename,"TryExec"); if(tmpExec.compare("")!=0){ if(!linuxcommon::test_exec(tmpExec)){ unsigned int finder=tmpExec.rfind("/"); @@ -1249,7 +1255,7 @@ if(tmpExec.compare("")==0){return "";} } } - std::string execline=linuxcommon::get_line_with_equal(filename,"Exec="); + std::string execline=linuxcommon::get_line_with_equal(filename,"Exec"); if(execline.compare("")==0){return execline;} execline=remove_percentage(execline); if(terminal(filename)){ @@ -1358,98 +1364,120 @@ std::string name="Comment"; return get_language_based_line(name,filename); } -std::string get_language_based_line(std::string name,std::string filename){ +std::string get_language_based_line(std::string name,std::string filename) +{ std::string tryGet,tempstr; std::string mylang; - const char* thisLang= getenv("LANGUAGE"); - if(thisLang==NULL){ - const char* myLANG = getenv("LANG"); - if(myLANG !=NULL){ - mylang=myLANG; - unsigned int found = mylang.find('.'); - if(found < mylang.length()){ - mylang = mylang.erase(found,std::string::npos); + if(LANGUAGE.compare("")==0) + { + const char* thisLang= getenv("LANGUAGE"); + if(thisLang==NULL) + { + const char* myLANG = getenv("LANG"); + if(myLANG !=NULL) + { + mylang=myLANG; + unsigned int found = mylang.find('.'); + if(found < mylang.length()) + { + mylang = mylang.erase(found,std::string::npos); + } + LANGUAGE=mylang; } + } + else + { + mylang=thisLang; + LANGUAGE=mylang; + } + } + tempstr=name; + tempstr+="["; + tempstr+=LANGUAGE; + tryGet=linuxcommon::get_line_with_equal(filename,tempstr); + if( (tryGet.compare("")==0) && (LANGUAGE.compare("")!=0) ) + { + unsigned int dash = LANGUAGE.find('_'); + if(dash::iterator it=DESKTOP_DIRS.begin();it!=DESKTOP_DIRS.end();++it){ dirToOpen=*it; + unsigned int founddirname = dirToOpen.rfind('/'); + if(founddirname != dirToOpen.length()-1){dirToOpen+="/";} dirToOpen+="applications/"; //outXML("Dir To Open:"+dirToOpen); dir = opendir(dirToOpen.c_str()); diff -Nru jwm-menu-3.0.1ubuntu1/src/menuXDG.cxx jwm-menu-3.0.1ubuntu1/src/menuXDG.cxx --- jwm-menu-3.0.1ubuntu1/src/menuXDG.cxx 2018-09-28 13:30:44.000000000 +0000 +++ jwm-menu-3.0.1ubuntu1/src/menuXDG.cxx 1970-01-01 00:00:00.000000000 +0000 @@ -1,2202 +0,0 @@ - -/* - * jwm-menu generator - * copyright Israel Dahl 2015 - * GPL3 license - * - * But whoso keepeth his word, - * in him verily is the love of God perfected: - * hereby know we that we are in him. - * - * 1John2:5 KJV Public Domain - * - */ - -/* -TODO -pugixml... -add global var vector for changed files. -Then check if is cached and then add in via pugixml the new entry. into the right place (how?) -This should cut regen time down significantly... -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../include/common.hpp" -#include "../include/pugixml.hpp" - -//global variables -std::string MENU_CACHE_FILE; -std::string MENU_TO_MERGE; -bool RELOAD; -bool USECOMMENTS; -// this variable helps me know how deep I am in the menu :D -bool INCEPTION; -bool MERGE_inception; -bool ONLY_UNALLOCATED; -int MERGEFILES; -int MERGEMENUS; -//pugi -pugi::xml_document doc; -pugi::xml_document cache; -//vector -std::vector MENU_NAMES; -std::vector MENU_NODES; -std::vector DESKTOP_DIRS; -std::vector MERGE_DIRS; -std::vector DIRECTORY_FILES; -std::vector CURRENT_CATEGORIES; -std::vector NOT_CATEGORIES; -std::vector NOTtheseFiles; -std::vector PATHS; -//list -std::list DESKTOP_FILES; -//modification time -struct tm *timer_result; -struct stat stat_structure; - -//functions -//string vectors -std::vector xdgmenufiles(); -std::vector theseChangedFiles(std::string dirToOpen); -std::vector changedFiles(); -std::vector categoryDirs(); -std::vector addMergeDirs(std::vector directoryFiles); -std::vector CheckVectorAndRemove(std::vector VectorToCheck, std::string thingToRemove); -//string list -std::list get_desktop_files(); -//c strings -std::string getStatFile(); -std::string getCacheFile(); -std::string getDDItem(std::string directory, std::string lineToGet); -std::string getDDName(std::string directory); -std::string chopTAG(std::string line); -std::string loop_desktopfiles(std::string categoryToGet,std::string dirToOpen); -std::string grep(std::string args, std::string filename); -std::string get_language_based_line(std::string name,std::string filename); -std::string get_name(std::string filename); -std::string get_comment(std::string filename); -std::string make_menu(); -std::string make_menu_xdg(std::string prefix); -std::string remove_percentage(std::string line); -std::string exec_line(std::string filename); -std::string icon_line(std::string filename); -std::string name_line(std::string filename); -std::string cat_line(std::string filename); -std::string makeXDGmenu(std::vector cats,std::vector dirs); -std::string whichMenu(std::string prefix); -std::string getCacheDir(); -//boolean -bool checkCache(); -bool checkCacheDirStat(std::string dirname,std::string statFilename); -bool load(std::string filename); -bool load(); -bool no_display(std::string filename); -bool not_showin(std::string filename); -bool only_show(std::string filename); -bool terminal(std::string filename); -bool updateMenu(); -bool useComments(); -bool matchesAnyRule(std::string filename, pugi::xml_node rule); -bool matchesALLRules(std::string filename, pugi::xml_node rule); -//void -void test(); -void outXML(std::string message); -void writeOut(std::string MSG); -void readCacheFile(); -void Included(pugi::xml_node SUB, pugi::xml_node RETURN); - -//bool -bool file_name(pugi::xml_node NODE, std::string filename); -bool make_submenu(pugi::xml_node SUB, pugi::xml_node RETURN); -bool make_menu_xdg(std::string infile,std::string outfile); -bool LayoutMaker(pugi::xml_node Layout,pugi::xml_node RETURN); -//TODO make pugixml menu -int main(int argc, char* argv[]) { - bool isCached=checkCache(); - RELOAD=false; - INCEPTION=false; - MERGE_inception=false; - ONLY_UNALLOCATED=false; - MERGEMENUS=0; - MERGEFILES=0; - PATHS=linuxcommon::split_paths("PATH","/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:"); - USECOMMENTS=useComments(); - MENU_CACHE_FILE=getCacheFile(); - std::string arg; - if(argc>0){ - if(argv[1]!=NULL){ - arg=argv[1]; - //outXML("ARG="+arg); - std::string argstring=""; - //writeOut(argstring); - if(arg.compare("--reload")==0){ - arg="jwm-"; - } - if(arg.compare("--test")==0){ - test(); - return 0; - } - //if(linuxcommon::test_file(arg)){ - - // } - RELOAD=true; - } - } - else{arg="jwm-";} - //outXML(MENU_CACHE_FILE); - if(!RELOAD && isCached && linuxcommon::test_file(MENU_CACHE_FILE.c_str())){ - //get cached file - readCacheFile(); - return 0; - } - else{ - std::string result = make_menu_xdg(arg); - writeOut("\n\n"+result+""); - } - return 0; -} -bool compare_nocase (const std::string& first, const std::string& second){ - unsigned int i=0; - while ( (itolower(second[i])) return false; - ++i; - } - return ( first.length() < second.length() ); -} -bool checkCacheDirStat(std::string dirname,std::string statFilename){ - if(dirname.compare("")==0)return true; - std::string uniqueFilename=dirname; - uniqueFilename=uniqueFilename.erase(0,1); - unsigned int found = uniqueFilename.find("/"); - if(found uniqueDirs = linuxcommon::desktop_paths(); - std::string testPATH ="/usr/share/applications"; - for( std::vector::iterator iter = uniqueDirs.begin(); - iter!=uniqueDirs.end(); - ++iter){ - testPATH = *iter; - bool prevCach=isCached; - isCached=checkCacheDirStat(testPATH,statFilename); - - //if( (prevCach != isCached ) && (isCached) ){ -//isCached=false;} - } - if(!linuxcommon::test_file(MENU_CACHE_FILE.c_str())){isCached=false;} - return isCached; -} -std::vector changedFiles(){ - std::vector tmpVec; - std::string testDirFile; - std::vector dirs = linuxcommon::desktop_paths(); - for( std::vector::iterator itr = dirs.begin(); - itr!=dirs.end(); - ++itr){ - testDirFile = *itr; - std::vector veryTMPvec = theseChangedFiles(testDirFile); - tmpVec=linuxcommon::join_string_vectors(tmpVec,veryTMPvec); - } - return linuxcommon::sort_array(tmpVec); -} -std::vector theseChangedFiles(std::string dirToOpen){ - DIR *dir = NULL; - struct dirent *entryPointer = NULL; - std::string result,tester,fullpath; - dir = opendir(dirToOpen.c_str()); - std::vector tmpVec; - if (dir!=NULL){ - while ((entryPointer=readdir(dir)) != NULL){ - if ((entryPointer->d_type == DT_REG)&&(entryPointer->d_name[0] != '.')){ - fullpath = entryPointer->d_name; - result=dirToOpen+fullpath; - tester=dirToOpen+fullpath; - unsigned period = result.rfind("."); - bool isDESKTOP = false; - if(result.compare("")!=0){ - if(period changed=changedFiles(); - std::string fileName=getCacheFile(); - if(!doc.load_file( fileName.c_str() )){ - if(!linuxcommon::test_file(fileName.c_str())){ - linuxcommon::echo_error("The file: "+fileName+" was not found."); - return false; - } - } - std::string result; - std::string NAME,ICON,EXEC,COMMENT,CAT; - for( std::vector::iterator it = changed.begin(); - it!=changed.end(); - ++it){ - result=*it; - if( (no_display(result)) || !(only_show(result)) || (not_showin(result)) ){ - //outXML(result); - } - else{ - NAME=name_line(result); - NAME=linuxcommon::quote_xml(NAME); - ICON=icon_line(result); - ICON=linuxcommon::quote_xml(ICON); - EXEC=exec_line(result); - EXEC=linuxcommon::quote_xml(EXEC); - CAT=cat_line(result); - EXEC=linuxcommon::quote_xml(EXEC); - if(USECOMMENTS){ - COMMENT=get_comment(result); - COMMENT==linuxcommon::quote_xml(COMMENT); - } - //JWM->Menu->label="cat" - } - } - return doc.save_file( fileName.c_str() ); -} -bool load(){ - std::string fileName=getCacheFile(); - return load(fileName); -} -bool load(std::string filename){ - if(filename.compare("")==0){ - outXML("file does not exist and cannot be loaded"); - return false; - } - if(!doc.load_file( filename.c_str() )){ - if(!linuxcommon::test_file(filename.c_str())){ - outXML("The file: "+filename+" was not found."); - return false; - } - } - return true; -} -void readCacheFile(){ - std::string Filename=getCacheFile(); - if(Filename.compare("")==0){return;} - std::string line; - std::string currentTime; - std::ifstream thisfile(Filename.c_str(), std::ifstream::in); - if(thisfile.is_open()){ - while (getline(thisfile,line)){ - std::cout<"< get_desktop_files(){ - std::list DESKTOPS; - DIR *dir = NULL; - struct dirent *entryPointer = NULL; - std::string dirToOpen,fullpath,result,tester; - //TODO loop in ALL directories!! - for( std::vector::iterator it=DESKTOP_DIRS.begin();it!=DESKTOP_DIRS.end();++it){ - dirToOpen=*it; - dirToOpen+="applications/"; - //outXML("Dir To Open:"+dirToOpen); - dir = opendir(dirToOpen.c_str()); - if (dir!=NULL){ - while ((entryPointer=readdir(dir)) != NULL){ - if ((entryPointer->d_type == DT_REG)&&(entryPointer->d_name[0] != '.')){ - fullpath = entryPointer->d_name; - result=dirToOpen+fullpath; - tester=dirToOpen+fullpath; - unsigned period = result.rfind("."); - bool isDESKTOP = false; - if(result.compare("")!=0){ - if(period DESKTOPS; - //dirent - DIR *dir = NULL; - struct dirent *entryPointer = NULL; - dir = opendir(dirToOpen.c_str()); - //int - if (dir!=NULL){ - while ((entryPointer=readdir(dir)) != NULL){ - if ((entryPointer->d_type == DT_REG)&&(entryPointer->d_name[0] != '.')){ - fullpath = entryPointer->d_name; - result=dirToOpen+fullpath; - tester=dirToOpen+fullpath; - unsigned period = result.rfind("."); - bool isDESKTOP = false; - if(result.compare("")!=0){ - if(period"+EXEC+"\n"; - } - else{MenuEntry="\t\t"+EXEC+"\n";} - //else{MenuEntry="\t\t"+EXEC+"\n";} - category=cat_line(result); - //outXML(category); - //outXML(result); - if( category.compare(categoryToGet)==0){DESKTOPS.push_back(MenuEntry);} - }//nodisplay/notshow//onlyshow - } //isDesktop - }//result !empty - }//dirent is file - }//dirent !NULL - }//directory !NULL - closedir(dir); - DESKTOPS.unique(); - DESKTOPS.sort(compare_nocase); - for( std::list::iterator it=DESKTOPS.begin();it!=DESKTOPS.end();++it){ - std::string tempentry=*it; - if(tempentry.compare("")!=0){returnCAT+=tempentry;} - } - // outXML(returnCAT); - return returnCAT; -} - -std::string make_menu(){ - std::string MenuEntry,NAME,ICON,EXEC,CATS,TERMIE,AV,DEV,ED,GAME,ART,NET,OFF,SCI,SET,SYS,ACC,OTH,WINE,CHROME,category,testPATH; - std::string dirToOpen = "/usr/share/applications/"; - std::string pathToGet = "/applications/"; - //"/.local/share/desktop-directories" - std::string fullpath, result, name, icon, exec, tester, cat; - ///Localization Directory files - //TODO use other menus if available - std::string DIR_EXT = ".directory"; - std::string INTRO = "jwm"; - std::string iconEQ = "Icon="; - std::string MENU; - std::string fallbackIcon = "applications-"; - //TODO xdg dirs - std::string DD = "/usr/share/desktop-directories"; - std::vector dirVector = categoryDirs(); - for( std::vector::iterator it = dirVector.begin(); - it!=dirVector.end(); - ++it){ - DD=*it; - //outXML(DD); - if (DD.compare("")==0){return "\txterm -e 'locate desktop-directories'\n";} - - //Accessories - std::string A_NAME,A_ICON; - std::string accessories_FILE = DD + "/" + INTRO + "-accessories" + DIR_EXT; - if(linuxcommon::test_file(accessories_FILE.c_str()) ){ - A_NAME = get_name(accessories_FILE); - A_ICON = linuxcommon::get_line_with_equal(accessories_FILE,iconEQ); - } - if(A_NAME.compare("")==0){A_NAME = "Accessories";} - if(A_ICON.compare("")==0){A_ICON = fallbackIcon + "accessories";} - - //Games - std::string games_FILE = DD + "/" + INTRO + "-games" + DIR_EXT; - std::string GAME_NAME,GAME_ICON; - if(linuxcommon::test_file(games_FILE.c_str()) ){ - GAME_NAME = get_name(games_FILE); - GAME_ICON = linuxcommon::get_line_with_equal(games_FILE,iconEQ); - } - if(GAME_NAME.compare("")==0){GAME_NAME = "Games";} - if(GAME_ICON.compare("")==0){GAME_ICON = fallbackIcon + "games";} - - //Graphics - std::string graphics_FILE = DD + "/" + INTRO + "-graphics" + DIR_EXT; - std::string G_NAME,G_ICON; - if(linuxcommon::test_file(graphics_FILE.c_str()) ){ - G_NAME = get_name(graphics_FILE); - G_ICON = linuxcommon::get_line_with_equal(graphics_FILE,iconEQ); - } - if(G_NAME.compare("")==0){G_NAME = "Graphics";} - if(G_ICON.compare("")==0){G_ICON = fallbackIcon + "graphics";} - - //AudioVideo - std::string multimedia_FILE = DD + "/" + INTRO + "-multimedia" + DIR_EXT; - std::string M_NAME, M_ICON; - if(linuxcommon::test_file(multimedia_FILE.c_str()) ){ - M_NAME = get_name(multimedia_FILE); - M_ICON = linuxcommon::get_line_with_equal(multimedia_FILE,iconEQ); - } - if(M_NAME.compare("")==0){M_NAME = "Multimedia";} - if(M_ICON.compare("")==0){M_ICON = fallbackIcon + "multimedia";} - - //Network - std::string network_FILE = DD + "/" + INTRO + "-network" + DIR_EXT; - std::string I_NAME,I_ICON; - if(linuxcommon::test_file(network_FILE.c_str()) ){ - I_NAME = get_name(network_FILE); - I_ICON = linuxcommon::get_line_with_equal(network_FILE,iconEQ); - } - if(I_NAME.compare("")==0){I_NAME = "Internet";} - if(I_ICON.compare("")==0){I_ICON = fallbackIcon + "internet";} - - //Office - std::string office_FILE = DD + "/" + INTRO + "-office" + DIR_EXT; - std::string O_NAME,O_ICON; - if( linuxcommon::test_file(office_FILE.c_str()) ){ - O_NAME = get_name(office_FILE); - O_ICON = linuxcommon::get_line_with_equal(office_FILE,iconEQ); - } - if(O_NAME.compare("")==0){O_NAME = "Office";} - if(O_ICON.compare("")==0){O_ICON = fallbackIcon + "office";} - - //Other? - std::string other_FILE = DD + "/" + INTRO + "-other" + DIR_EXT; - std::string OTHER_NAME,OTHER_ICON; - if(linuxcommon::test_file(other_FILE.c_str()) ){ - OTHER_NAME = get_name(other_FILE); - OTHER_ICON = linuxcommon::get_line_with_equal(other_FILE,iconEQ); - } - if(OTHER_NAME.compare("")==0){OTHER_NAME = "Other";} - if(OTHER_ICON.compare("")==0){OTHER_ICON = fallbackIcon + "other";} - - //System - std::string system_FILE = DD + "/" + INTRO + "-system" + DIR_EXT; - std::string SYS_NAME,SYS_ICON; - if(linuxcommon::test_file(system_FILE.c_str()) ){ - SYS_NAME = get_name(system_FILE); - SYS_ICON = linuxcommon::get_line_with_equal(system_FILE,iconEQ); - } - if(SYS_NAME.compare("")==0){SYS_NAME = "System";} - if(SYS_ICON.compare("")==0){SYS_ICON = fallbackIcon + "system";} - - //Settings - std::string settings_FILE = DD + "/" + INTRO + "-settings" + DIR_EXT; - std::string SETT_NAME,SETT_ICON; - if(linuxcommon::test_file(settings_FILE.c_str()) ){ - SETT_NAME = get_name(settings_FILE); - SETT_ICON = linuxcommon::get_line_with_equal(settings_FILE,iconEQ); - } - if(SETT_NAME.compare("")==0){SETT_NAME = "Settings";} - if(SETT_ICON.compare("")==0){SETT_ICON = "preferences-desktop";} - - //Development - std::string development_FILE = DD + "/" + INTRO + "-development" + DIR_EXT; - std::string D_NAME,D_ICON; - if(linuxcommon::test_file(development_FILE.c_str()) ){ - D_NAME = get_name(development_FILE); - D_ICON = linuxcommon::get_line_with_equal(development_FILE,iconEQ); - } - if(D_NAME.compare("")==0){D_NAME = "Development";} - if(D_ICON.compare("")==0){D_ICON = fallbackIcon + "development";} - - //Education - std::string education_FILE = DD + "/" + INTRO + "-education" + DIR_EXT; - std::string E_NAME,E_ICON; - if(linuxcommon::test_file(education_FILE.c_str()) ){ - E_NAME = get_name(education_FILE); - E_ICON = linuxcommon::get_line_with_equal(education_FILE,iconEQ); - } - if(E_NAME.compare("")==0){E_NAME = "Education";} - if(E_ICON.compare("")==0){E_ICON = fallbackIcon + "science";} - //Wine - std::string wine_NAME,wine_ICON; - std::string wine_FILE = DD + "/wine" + DIR_EXT; - if(linuxcommon::test_file(wine_FILE.c_str()) ){ - wine_NAME = get_name(wine_FILE); - wine_ICON = linuxcommon::get_line_with_equal(wine_FILE,iconEQ); - } - if(wine_NAME.compare("")==0){wine_NAME = "Wine";} - if(wine_ICON.compare("")==0){wine_ICON = fallbackIcon + "accessories";} - - //Chrome - std::string chrome_NAME,chrome_ICON; - std::string chrome_FILE = DD + "/chrome-apps" + DIR_EXT; - if(linuxcommon::test_file(chrome_FILE.c_str()) ){ - chrome_NAME = get_name(chrome_FILE); - chrome_ICON = linuxcommon::get_line_with_equal(chrome_FILE,iconEQ); - } - if(chrome_NAME.compare("")==0){chrome_NAME = "Chrome Apps";} - if(chrome_ICON.compare("")==0){chrome_ICON = fallbackIcon + "accessories";} - - std::vector uniqueDirs = linuxcommon::desktop_paths(); - unsigned int found = 0; - //initialize directory reading variables to NULL - DIR *dir = NULL; - for( std::vector::iterator it = uniqueDirs.begin(); - it!=uniqueDirs.end(); - ++it){ - //get the string equvalent for the integer representation if of the xdg path - // something like - /* - 1=/usr/share/ - 2=/usr/local/share - etc... - */ - testPATH = *it; - //make sure this isn't blank - if(testPATH.compare("")!=0){ - //look to see if we have a / at the end... remove it if we do... - found = testPATH.rfind('/'); - if (found == testPATH.length()-1){testPATH=testPATH.substr(0,testPATH.length()-1);} - //see if there is a pathToGet directory - dirToOpen = testPATH + pathToGet; - dir = opendir(dirToOpen.c_str()); - if (dir!=NULL){ - //outXML(dirToOpen); - AV+=loop_desktopfiles("AudioVideo",dirToOpen); - DEV+=loop_desktopfiles("Development",dirToOpen); - ED+=loop_desktopfiles("Education",dirToOpen); - GAME+=loop_desktopfiles("Game",dirToOpen); - ART+=loop_desktopfiles("Graphics",dirToOpen); - NET+=loop_desktopfiles("Network",dirToOpen); - OFF+=loop_desktopfiles("Office",dirToOpen); - SCI+=loop_desktopfiles("Science",dirToOpen); - SET+=loop_desktopfiles("Settings",dirToOpen); - SYS+=loop_desktopfiles("System",dirToOpen); - ACC+=loop_desktopfiles("Utility",dirToOpen); - } - closedir(dir); - }// testPath not empty - }//vector of directories - if(ACC.compare("")!=0){MENU+="\t\n"+ACC+"\n\t\n";} - if(ED.compare("")!=0){MENU+="\t\n"+ED+"\n\t\n";} - if(NET.compare("")!=0){MENU+="\t\n"+NET+"\n\t\n";} - if(OFF.compare("")!=0){MENU+="\t\n"+OFF+"\n\t\n";} - if(GAME.compare("")!=0){MENU+="\t\n"+GAME+"\n\t\n";} - if(ART.compare("")!=0){MENU+="\t\n"+ART+"\n\t";} - if(AV.compare("")!=0){MENU+="\t\n"+AV+"\n\t\n";} - if(DEV.compare("")!=0){MENU+="\t\n"+DEV+"\n\t\n";} - if(SCI.compare("")!=0){MENU+="\t\n"+SCI+"\n\t\n";} - if(SET.compare("")!=0){MENU+="\t\n"+SET+"\n\t\n";} - if(SYS.compare("")!=0){MENU+="\t\n"+SYS+"\n\t";} - }//desktop directory vector - return MENU; -}//make_menu -std::string remove_percentage(std::string line){ - if(line.compare("")==0){return line;} - unsigned int percentfind=0; - std::string tempstring; - percentfind=line.find(" %",0); - if(percentfind>line.length()){return line;} - unsigned int semifind=line.find(";",percentfind); - // #if 0 - bool andis=false; - bool semiis=false; - if(semifindtemp2.length()){return catline;} - std::string thisCAT=""; - for(unsigned int i = 0; i'); - std::string temp = line; - temp=temp.erase(0,tLen+1); - tLen=temp.find('<'); - temp=temp.erase(tLen,std::string::npos); - return temp; -} -std::string getDDName(std::string directory){ - std::vector uniqueDirs = linuxcommon::desktop_paths(); - std::string testPATH,line; - unsigned int found = 0; - DIR *dirent = NULL; - for( std::vector::iterator it = uniqueDirs.begin(); - it!=uniqueDirs.end(); - ++it){ - - testPATH = *it; - //make sure this isn't blank - if(testPATH.compare("")!=0){ - //look to see if we have a / at the end... remove it if we do... - found = testPATH.rfind('/'); - if (found == testPATH.length()-1){testPATH=testPATH.substr(0,testPATH.length()-1);} - std::string tempdirName=testPATH; - tempdirName+="/desktop-directories/"; - dirent = opendir(tempdirName.c_str()); - if (dirent!=NULL){ - tempdirName+=directory; - } - if(get_name(tempdirName).compare("")!=0){line=get_name(tempdirName);} - closedir(dirent); - - } - } - line=linuxcommon::quote_xml(line); - return line; -} -std::string getDDItem(std::string directory, std::string lineToGet){ - std::vector uniqueDirs = linuxcommon::desktop_paths(); - std::string testPATH,line; - unsigned int found = 0; - DIR *dirent = NULL; - for( std::vector::iterator it = uniqueDirs.begin(); - it!=uniqueDirs.end(); - ++it){ - - testPATH = *it; - //make sure this isn't blank - if(testPATH.compare("")!=0){ - //look to see if we have a / at the end... remove it if we do... - found = testPATH.rfind('/'); - if (found == testPATH.length()-1){testPATH=testPATH.substr(0,testPATH.length()-1);} - std::string tempdirName=testPATH; - tempdirName+="/desktop-directories/"; - dirent = opendir(tempdirName.c_str()); - if (dirent!=NULL){ - tempdirName+=directory; - if(linuxcommon::get_line_with_equal(tempdirName,lineToGet).compare("")!=0){line=linuxcommon::get_line_with_equal(tempdirName,lineToGet);} - } - } - } - line==linuxcommon::quote_xml(line); - return line; -} - -std::string makeXDGmenu(std::vector cats,std::vector dirs){ - std::string MENU,menuTest,this_ICON,this_NAME,this_Exec, desktopTest,testDirFile,testPATH; - std::string dirToOpen = "/usr/share/applications/"; - std::string pathToGet = "/applications/"; - std::string iconEQ = "Icon="; - std::string DESKTOPS; - for( std::vector::iterator itr = dirs.begin(); - itr!=dirs.end(); - ++itr){ - testDirFile = *itr; - if(getDDName(testDirFile).compare("")!=0){this_NAME = getDDName(testDirFile);} - if(getDDItem(testDirFile,iconEQ).compare("")!=0){this_ICON = getDDItem(testDirFile,iconEQ);} - for( std::vector::iterator it = cats.begin(); - it!=cats.end(); - ++it){ - - std::vector uniqueDirs = linuxcommon::desktop_paths(); - unsigned int found = 0; - unsigned int foundDesk = 0; - unsigned int foundMENU = 0; - //initialize directory reading variables to NULL - std::string CATS=*it; - DIR *dirent = NULL; - for( std::vector::iterator iter = uniqueDirs.begin(); - iter!=uniqueDirs.end(); - ++iter){ - testPATH = *iter; - //make sure this isn't blank - if(testPATH.compare("")!=0){ - //look to see if we have a / at the end... remove it if we do... - found = testPATH.rfind('/'); - if (found == testPATH.length()-1){testPATH=testPATH.substr(0,testPATH.length()-1);} - //see if there is a pathToGet directory - dirToOpen = testPATH + pathToGet; - dirent = opendir(dirToOpen.c_str()); - if (dirent!=NULL){ - //Does the menu file have icon and name? - if( (this_ICON.compare("")!=0)&&(this_NAME.compare("")!=0) ){ - std::string tempTEST; - //test the loop of the files for this category - desktopTest=loop_desktopfiles(CATS,dirToOpen); - //Is this entry already there? - foundMENU=MENU.find(desktopTest); - if( foundMENU>MENU.length() ){ - tempTEST=desktopTest; - std::string OLDdesktop=DESKTOPS; - DESKTOPS+=desktopTest; - //make sure we have something new here - if(DESKTOPS.length()>tempTEST.length()){ - //add it - DESKTOPS=OLDdesktop+"\t\n"+desktopTest; - } - } - } - } - } - }//desktop file path vector - unsigned int menuFind=0; - menuFind=MENU.find(this_NAME); - if(menuFind>MENU.length()){ - if(DESKTOPS.compare("")!=0){ - MENU+="\t\n"+DESKTOPS+"\t\n"; - } - } - DESKTOPS.clear(); - }//categories vector - }//dirs vector - return MENU; -} -////////////////////////////////////////////////////////////////////////////////////////////////////BOOL - - -bool no_display(std::string filename) { - std::string result = linuxcommon::get_line_with_equal(filename,"NoDisplay="); - if(result.compare("")==0){ - return false; - } - std::transform(result.begin(),result.end(),result.begin(),::tolower); - if (result.compare("true")==0){return true;} - else{return false;} - - return false; -} -bool useComments(){ - std::string jwmVersion = "jwm -v";// | grep JWM |sed 's/ by.*//' |sed 's/JWM v//'"; - std::string version = linuxcommon::term_out(jwmVersion); - version=linuxcommon::remove_cruft(version,"JWM v"); - - unsigned int found=0; - found=version.find(" by"); - if(found newTagVersionMajor){return true;} - if(majorVersion < newTagVersionMajor){return false;} - if(minorVersion >= newTagVersionMinor){ - if(revVersion>=revno){return true;} - } - return false; -} -bool only_show(std::string filename) { - const char* desktop = getenv("XDG_CURRENT_DESKTOP"); - if(desktop==NULL){desktop="JWM";} - const char* desktop_session = getenv("DESKTOP_SESSION"); - if(desktop_session==NULL){desktop_session="JWM";} - std::string result = linuxcommon::get_line_with_equal_after_header("Desktop Entry",filename,"OnlyShowIn="); - unsigned int found = 0; - if(result.compare("")==0){ - //Only show in line doesn't exist - return true; - } - //compare lower case words only - std::transform(result.begin(),result.end(),result.begin(),::tolower); - - std::string temp1,temp2; - temp2=result; - - for(unsigned int i = 0; iprefix.length() ){ - prefix+=apps; - menuNAME=prefix; - } - } - } - } - std::string testPATH; - std::string FALLBACKmenuNAME = "lxde-"+apps; - std::string jwmmenuNAME="jwm-"+apps; - std::vector MENUS=xdgmenufiles(); - bool arg,jwm,lxde; - arg=false; - jwm=false; - lxde=false; - std::string argM,jwmM,lxdeM; - for( std::vector::iterator it = MENUS.begin(); - it!=MENUS.end(); - ++it){ - testPATH = *it; - if(prefix.compare("")!=0){ - //outXML("prefix sent in"); - if(testPATH.find(FALLBACKmenuNAME) catty =linuxcommon::delimiter_vector_from_string(tempCat,";"); - for(std::vector::iterator itn=NOT_CATEGORIES.begin();itn!=NOT_CATEGORIES.end();++itn){ - std::string Cat=*itn; - outXML("DON'T USE::"+Cat); - if(linuxcommon::look_for_string_in_vector(catty,Cat)){ - outXML("DON'T USE::Found:"+Cat+" in:"+fname); - return false; - } - } - } - //outXML("Found filename="+fname); - std::string NAME=get_name(fname); - std::string EXEC=exec_line(fname); - std::string ICON=icon_line(fname); - std::string TOOLTIP=get_comment(fname); - if(EXEC.compare("")==0){return false;} - //outXML("NAME="+NAME+"\nEXEC="+EXEC+"\nICON="+ICON+"\nTOOLTIP="+TOOLTIP); - if(NAME.compare("")==0){NAME=EXEC;} - if(TOOLTIP.compare("")==0){TOOLTIP=EXEC;} - temp=NODE.append_child("Program"); - temp.append_child(pugi::node_pcdata).set_value(EXEC.c_str()); - pugi::xml_attribute ATTRI = temp.append_attribute("label"); - ATTRI.set_value(NAME.c_str()); - ATTRI = temp.append_attribute("icon"); - ATTRI.set_value(ICON.c_str()); - if(USECOMMENTS){ - ATTRI=temp.append_attribute("tooltip"); - ATTRI.set_value(TOOLTIP.c_str()); - } - return true; -} - -std::string dirFileFullPath(std::string fileName){ - //Find the name in the file! - std::string filename=linuxcommon::find_xdg_config_dir_subdir("menus"); - filename+=fileName; - if(linuxcommon::test_file(filename)){return filename;} - return ""; -} - -void Category(std::string Cat, pugi::xml_node RETURN){ - if(Cat.compare("")==0)return; - if(!RETURN)return; - outXML("void Category(std::string "+Cat+", pugi::xml_node RETURN)"); - int iter=0; - for( std::list::iterator it=DESKTOP_FILES.begin();it!=DESKTOP_FILES.end();++it){ - std::string tempentry=*it; - std::string tempCat=linuxcommon::get_line_with_equal(tempentry,"Categories"); - std::vector catty =linuxcommon::delimiter_vector_from_string(tempCat,";"); - - if(linuxcommon::look_for_string_in_vector(catty,Cat)){ - outXML("Category:"+tempCat+"\nFound:"+Cat); - if(!file_name(RETURN,tempentry)){ - //outXML("Failed to process:"+tempentry); - } - else{ - //outXML("found category:"+Cat+" in:"+tempentry); - //Remove desktop file from list?? - - it=DESKTOP_FILES.erase(it);//it); - } - } - iter++; - } -} -void Category(std::vector Cats, pugi::xml_node RETURN){ - if(Cats.empty())return; - if(!RETURN)return; - outXML("void Category(std::vector Cats, pugi::xml_node RETURN)"); - std::list::iterator it=DESKTOP_FILES.begin();//it!=DESKTOP_FILES.end();++it){ - while(it!=DESKTOP_FILES.end()){ - std::string tempentry=*it; - bool WORKEDout=false; - std::string tempCat=linuxcommon::get_line_with_equal(tempentry,"Categories"); - std::vector catty =linuxcommon::delimiter_vector_from_string(tempCat,";"); - for( std::vector::iterator itera=Cats.begin();itera!=Cats.end();++itera){ - std::string Cat=*itera; - if(linuxcommon::look_for_string_in_vector(catty,Cat)){ - if(!file_name(RETURN,tempentry)){outXML("Failed to process:"+tempentry);} - else{ - outXML("found category:"+Cat+" in:"+tempentry); - WORKEDout=true; - } - } - } - if(WORKEDout){it=DESKTOP_FILES.erase(it);} - else{++it;} - } - outXML("End of Category"); -} -void Excluded(pugi::xml_node SUB, pugi::xml_node RETURN){ - if(!SUB)return; - if(!RETURN)return; - std::vector NOTlist; - std::vector YESlist; - pugi::xml_node Layout; - for(Layout=SUB.first_child();Layout;Layout=Layout.next_sibling()){ - std::string namer=Layout.name(); - std::string val=Layout.text().as_string(); - if(namer.compare("Filename")==0){ - if(!file_name(RETURN,val)){ - //outXML("Skipping="+val); - } - } - if(namer.compare("Category")==0){ - Category(val,RETURN); - } - //these can hold category or filename - for(std::list::iterator it=DESKTOP_FILES.begin();it!=DESKTOP_FILES.end();++it){ - std::string tempentry=*it; - if(namer.compare("All")==0){ - YESlist.push_back(tempentry); - } - if(namer.compare("Not")==0){ - if(matchesAnyRule(tempentry,Layout)){ - NOTlist.push_back(tempentry); - } - else{YESlist.push_back(tempentry);} - } - if(namer.compare("And")==0){ - if(matchesALLRules(tempentry,Layout)){ - YESlist.push_back(tempentry); - } - else{NOTlist.push_back(tempentry);} - } - if(namer.compare("Or")==0){ - if(matchesAnyRule(tempentry,Layout)){ - YESlist.push_back(tempentry); - } - else{NOTlist.push_back(tempentry);} - } - } - } - //TODO check not list and Yes list to remove from Not list - for(std::vector::iterator it=NOTlist.begin();it!=NOTlist.end();++it){ - std::string fileName=*it; - if(linuxcommon::test_file(fileName)){ - pugi::xml_node tmp=RETURN.append_child("Program"); - std::string numero, icon,tooltip,exec; - exec=exec_line(fileName); - if(exec.compare("")!=0){ - numero=get_name(fileName); - icon=icon_line(fileName); - if(icon.compare("")==0){icon="application-default-icon";} - if(numero.compare("")==0){numero=exec;} - tmp.append_attribute("label")=numero.c_str(); - tmp.append_attribute("icon")=icon.c_str(); - if(USECOMMENTS){ - tooltip=get_comment(fileName); - if(tooltip.compare("")==0){tooltip=numero;} - tmp.append_attribute("tooltip")=tooltip.c_str(); - } - tmp.append_child(pugi::node_pcdata).set_value(exec.c_str()); - } - } - } -} -bool matchesAnyRule(std::string filename, pugi::xml_node rule){ - for(pugi::xml_node ruleNode=rule.first_child();ruleNode;ruleNode=ruleNode.next_sibling()){ - std::string Name=ruleNode.name(); - std::string Value=ruleNode.text().as_string(); - if(Name.compare("Category")){ - std::string cat=cat_line(filename); - if(cat.compare(Value)==0){return true;} - } - if(Name.compare("Filename")){if(filename.compare(Value)==0){return true;}} - - } - return false; -} -bool matchesALLRules(std::string filename, pugi::xml_node rule){ - for(pugi::xml_node ruleNode=rule.first_child();ruleNode;ruleNode=ruleNode.next_sibling()){ - std::string Name=ruleNode.name(); - std::string Value=ruleNode.text().as_string(); - if(Name.compare("Category")){ - std::string cat=cat_line(filename); - if(cat.compare(Value)!=0){return false;} - } - if(Name.compare("Filename")){ - if(filename.compare(Value)!=0){return false;} - } - } - return true; -} -void ANDProcessor(pugi::xml_node SUB, pugi::xml_node RETURN){ - outXML("ANDProcessor"); - if(!SUB)return; - if(!RETURN)return; - pugi::xml_node Layout; - std::vector theseCats; - for(Layout=SUB.first_child();Layout;Layout=Layout.next_sibling()){ - std::string namer=Layout.name(); - outXML("AND->"+namer); - std::string val=Layout.text().as_string(); - if(namer.compare("Filename")==0){ - if(!file_name(RETURN,val)){ - //outXML("Skipping="+val); - } - } - if(namer.compare("Not")==0){ - for(pugi::xml_node tmp=Layout.first_child();tmp;tmp=tmp.next_sibling()){ - std::string namer2=tmp.name(); - std::string val2=tmp.text().as_string(); - outXML("AND->"+namer+"->"+namer2+"="+val2); - if(namer2.compare("Filename")==0){ - NOTtheseFiles.push_back(val2); - } - if(namer2.compare("Category")==0){ - outXML("Not this Category:"+val2); - NOT_CATEGORIES.push_back(val2); - } - } - } - if(namer.compare("Category")==0){ - theseCats.push_back(val); - outXML("AND adding:"+val); - CURRENT_CATEGORIES.push_back(val); - //Category(val,RETURN); - } - } - Category(theseCats,RETURN); -} -void OrProcessor(pugi::xml_node SUB, pugi::xml_node RETURN){ - outXML("OrProcessor"); - if(!SUB)return; - if(!RETURN)return; - pugi::xml_node Layout; - std::vector theseCats; - for(Layout=SUB.first_child();Layout;Layout=Layout.next_sibling()){ - std::string namer=Layout.name(); - std::string val=Layout.text().as_string(); - if(namer.compare("Filename")==0){ - if(!file_name(RETURN,val)){ - //outXML("Skipping="+val); - } - } - if(namer.compare("Category")==0){ - theseCats.push_back(val); - outXML("OR adding:"+val); - CURRENT_CATEGORIES.push_back(val); - //Category(val,RETURN); - } - } - Category(theseCats,RETURN); -} - -void NOTProcessor(pugi::xml_node SUB){ - if(!SUB)return; - pugi::xml_node Layout; - std::vector theseCats; - for(Layout=SUB.first_child();Layout;Layout=Layout.next_sibling()){ - std::string namer=Layout.name(); - std::string val=Layout.text().as_string(); - if(namer.compare("Filename")==0){ - NOTtheseFiles.push_back(val); - } - if(namer.compare("Category")==0){ - outXML("Not this category:"+val); - NOT_CATEGORIES.push_back(val); - - } - } -} -std::vector CheckVectorAndRemove(std::vector VectorToCheck, std::string thingToRemove){ - std::vector TEMPvector=VectorToCheck; - std::vector::iterator it = find (TEMPvector.begin(), TEMPvector.end(), thingToRemove); - if (it != TEMPvector.end()){ - TEMPvector.erase(it); - return TEMPvector; - } - return TEMPvector; -} -void Included(pugi::xml_node SUB, pugi::xml_node RETURN){ - //outXML("Included"); - NOTtheseFiles.clear(); - if(!SUB)return; - if(!RETURN)return; - std::vector YESlist; - std::copy( YESlist.begin(), YESlist.end(), std::back_inserter( DESKTOP_FILES ) ); - pugi::xml_node Layout; - pugi::xml_node NAMEnode=SUB.parent(); - NAMEnode=NAMEnode.child("Name"); - std::string tmpCater=NAMEnode.name(); - std::vector theseFiles; - for(Layout=SUB.first_child();Layout;Layout=Layout.next_sibling()){ - std::string namer=Layout.name(); - std::string val=Layout.text().as_string(); - if(namer.compare("Or")==0){ - OrProcessor(Layout,RETURN); - } - if(namer.compare("Filename")==0){ - if(!file_name(RETURN,val)){ - //outXML("Skipping="+val); - } - } - if(namer.compare("Category")==0){ - outXML("Included:"+val); - CURRENT_CATEGORIES.push_back(val); - //theseCats.push_back(val); - } - //these can hold category or filename - if(namer.compare("And")==0){ - ANDProcessor(Layout,RETURN); - } - if(namer.compare("Not")==0){ - NOTProcessor(Layout); - } - - } - if(CURRENT_CATEGORIES.empty()){CURRENT_CATEGORIES.push_back(tmpCater);} - - if(!NOTtheseFiles.empty()){ - for(std::vector::iterator itn=NOTtheseFiles.begin();itn!=NOTtheseFiles.end();++itn){ - YESlist=CheckVectorAndRemove(YESlist,*itn); - } - } - //TODO check not list and Yes list to remove from yes list - for(std::vector::iterator it=YESlist.begin();it!=YESlist.end();++it){ - outXML("Yes List!"); - std::string fileName=*it; - std::string cat=cat_line(fileName); - std::vector tmpCAT=linuxcommon::delimiter_vector_from_string(cat,";"); - if(!NOT_CATEGORIES.empty()){ - for(std::vector::iterator itn=NOT_CATEGORIES.begin();itn!=NOT_CATEGORIES.end();++itn){ - if(!linuxcommon::look_for_string_in_vector(tmpCAT,*itn)){ - for(std::vector::iterator itera=CURRENT_CATEGORIES.begin();itera!=CURRENT_CATEGORIES.end();++itera){ - std::string category=*itera; - if(linuxcommon::look_for_string_in_vector(tmpCAT,category)){ - pugi::xml_node tmp=RETURN.append_child("Program"); - std::string numero, icon,tooltip,exec; - exec=exec_line(fileName); - if(exec.compare("")!=0){ - numero=get_name(fileName); - icon=icon_line(fileName); - if(icon.compare("")==0){icon="application-default-icon";} - if(numero.compare("")==0){numero=exec;} - tmp.append_attribute("label")=numero.c_str(); - tmp.append_attribute("icon")=icon.c_str(); - if(USECOMMENTS){ - tooltip=get_comment(fileName); - if(tooltip.compare("")==0){tooltip=numero;} - tmp.append_attribute("tooltip")=tooltip.c_str(); - } - tmp.append_child(pugi::node_pcdata).set_value(exec.c_str()); - } - } - } - } - } - } - } -} -bool make_submenu(pugi::xml_node SUB, pugi::xml_node RETURN){ - //outXML("make_submenu"); - if(!SUB)return false; - if(!RETURN)return false; - if(MERGE_inception){return false;} - pugi::xml_node OnlyUnallocated,Layout; - std::string DIR_FILE,NAME,ICON,TOOLTIP; - if(!INCEPTION)CURRENT_CATEGORIES.clear(); - NAME=SUB.child("Name").text().as_string(); - TOOLTIP=NAME; - ICON="application-default-icon"; - if(DIRECTORY_FILES.empty()){DIRECTORY_FILES=categoryDirs();} - if(SUB.child("Directory")){ - std::string fileNoPath=SUB.child("Directory").text().as_string(); - - DIR_FILE=linuxcommon::test_file_in_vector_path(fileNoPath,DIRECTORY_FILES); - //outXML("**********************"+fileNoPath+":"+DIR_FILE); - if(DIR_FILE.compare("")!=0){ - TOOLTIP=get_comment(DIR_FILE); - NAME=get_name(DIR_FILE); - ICON=icon_line(DIR_FILE); - } - } - RETURN=RETURN.append_child("Menu"); - RETURN.append_attribute("label")=NAME.c_str(); - RETURN.append_attribute("icon")=ICON.c_str(); - outXML("make_submenu:"+NAME); - if(SUB.child("Include")){ - Included(SUB.child("Include"),RETURN); - } - if(SUB.child("Separator")){RETURN.append_child("Separator");} - if(SUB.child("Filename")){ - std::string val=SUB.child("Filename").text().as_string(); - if(!file_name(RETURN,val)){ - //outXML("Skipping="+val); - } - } - - if(SUB.child("Layout")){ - if(!LayoutMaker(SUB.child("Layout"),RETURN)){return false;} - } - if(SUB.child("MergeFile")){ - //TODO - } - if(SUB.child("OnlyUnallocated")){ - //how do I do this for a middle Other?? - for( std::list::iterator it=DESKTOP_FILES.begin();it!=DESKTOP_FILES.end();++it){ - std::string tempentry=*it; - if(!file_name(RETURN,tempentry)){ - outXML("Failed to process:"+tempentry); - } - - } - } - RETURN=RETURN.parent(); - return true; -} -void test(){ - if(!make_menu_xdg("/etc/xdg/menus/xfce-applications.menu","/home/israeldahl/temp.xml")){ - outXML("FAILED!!!"); - menumaker(); - } -} -std::vector DefaultCategories(){ - std::string d1="Utility"; - std::string d2="Games"; - std::string d3="Graphics"; - std::string d4="AudioVideo"; - std::string d5="Settings"; - std::string d6="System"; - std::string d7="Other"; - std::vector DEFAULT; - DEFAULT.push_back(d1); - DEFAULT.push_back(d2); - DEFAULT.push_back(d3); - DEFAULT.push_back(d4); - DEFAULT.push_back(d5); - DEFAULT.push_back(d6); - DEFAULT.push_back(d7); - return DEFAULT; -} -void resetMergeTypes(){ - MERGEMENUS=0; - MERGEFILES=0; -} -bool Merge(pugi::xml_node MergeNode, pugi::xml_node RETURN){ - // if we don't have any more menu nodes, get out!!! - if(MENU_NODES.empty()){return false;} - /* We NEED to prevent getting lost in the dream world here... - * So, lets check for some crazy inception stuff - * - * doc (Our loaded Document) - * Menu (The main Menu XML element) - * Menu (A category Menu) - * Layout - * Merge (Uh oh... this is getting inception-y) - */ - //This should be doc->Menu->Layout->Merge - pugi::xml_node inceptionNode=MergeNode.parent().parent(); - if(inceptionNode!=doc.child("Menu")){ - MERGE_inception=true; - } - else{MERGE_inception=false;} - std::string mergetype=MergeNode.attribute("type").as_string(); - /* Find out what type of merge we are doing... - * - * from freedesktop.org: - * type="menus"|"files"|"all" - * menus - all sub-menus that are not explicitly mentioned should be inserted in alphabetical order of their visual caption at this point - * files - all desktop entries contained in this menu that are not explicitly mentioned should be inserted in alphabetical order of their visual caption at this point. - * all -a mix of all sub-menus and all desktop entries that are not explicitly mentioned should be inserted in alphabetical order of their visual caption at this point. - */ - - //outXML("Merge Menus type:"+mergetype); - - //If it is menus - if(mergetype.compare("menus")==0){ - MERGEMENUS=1; - //if we don't have merge files yet set it to -1 to avoid bring in ALL files just yet. - if(MERGEFILES==0){MERGEFILES=-1;} - } - if(mergetype.compare("files")==0){ - MERGEFILES=1; - // we can run merge files now after merge menus if merge type=menus exists as well - if(MERGEMENUS==0){MERGEMENUS=-1;} - } - if(mergetype.compare("all")==0){ - MERGEMENUS=1; - MERGEFILES=1; - } - if(MERGEMENUS==1){ - /* Menu - * Name <--- THIS = comp - * Layout - * Merge <-- THIS = MergeNode - */ - std::string comp=MergeNode.parent().parent().child("Name").text().as_string(); - bool EVERYTHING=false; - if(MergeNode.parent().parent()==doc.child("Menu")){ - EVERYTHING=true; - } - outXML("Merging Menus"); - std::vector::iterator iter = MENU_NODES.begin(); - std::string BAIL; - while(iter!=MENU_NODES.end()){ - NOT_CATEGORIES.clear(); - pugi::xml_node tmp=*iter; - std::string numero=tmp.child("Name").text().as_string(); - if(numero.compare(BAIL)==0){return false;} - if(EVERYTHING){ - BAIL=numero; - make_submenu(tmp,RETURN); - outXML("'EVERYTHING' Erasing:"+numero); - iter=MENU_NODES.erase(iter); - } - else{ - std::string category; - //outXML("Menu:"+numero); - if(comp.compare(numero)==0){ - outXML("Found menu!! = "+numero); - iter=MENU_NODES.erase(iter); - - return make_submenu(tmp,RETURN); - } - else{++iter;} - } - - } - if(EVERYTHING){ - CURRENT_CATEGORIES.clear(); - MENU_NODES.clear(); - return true; - } - } - else if((MERGEMENUS!=-1)&&(MERGEFILES==1)){ - outXML("Merging Files"); - for( std::list::iterator it=DESKTOP_FILES.begin();it!=DESKTOP_FILES.end();++it){ - std::string tempentry=*it; - if(!file_name(RETURN,tempentry)){outXML("Failed to process:"+tempentry);} - } - return false; - } - else{return false;} - return false; -} -bool LayoutMaker(pugi::xml_node Layout, pugi::xml_node RETURN){ - if(!Layout){return false;} - if(!RETURN){return false;} - outXML("bool LayoutMaker(pugi::xml_node Layout, pugi::xml_node RETURN)"); - MERGEFILES=0; - MERGEMENUS=0; - if(!Layout.child("Merge")){return false;} - INCEPTION=true; - NOT_CATEGORIES.clear(); - for(Layout=Layout.first_child();Layout;Layout=Layout.next_sibling()){ - std::string namer=Layout.name(); - std::string val=Layout.text().as_string(); - if(namer.compare("Separator")==0){RETURN.append_child("Separator");} - else if(namer.compare("Filename")==0){ - //outXML("Layout Filename"); - if(!file_name(RETURN,val)){ - //outXML("Skipping="+val); - } - } - if(namer.compare("Menuname")==0){ - //outXML("Menuname"); - int it=0; - for( std::vector::iterator iter = MENU_NAMES.begin(); - iter!=MENU_NAMES.end(); - ++iter){ - std::string testPATH = *iter; - //outXML("Menu Name="+testPATH+" Trying to find:"+val); - if(testPATH.compare(val)==0){ - outXML("Menuname found:"+testPATH); - if(MENU_NODES.empty()){return false;} - pugi::xml_node currentmenu_node=MENU_NODES[it]; - //RETURN=RETURN.parent(); - int count=0; - for(std::vector::iterator item=MENU_NODES.begin();item!=MENU_NODES.end();++item){ - if(count==it){ - //outXML("Erasing node..."); - MERGE_inception=false; - currentmenu_node=*item; - if(!make_submenu(currentmenu_node,RETURN)){outXML("Did not make Menuname Menu for:"+val);} - item=MENU_NODES.erase(item); - break; - } - count++; - } - //else{RETURN=RETURN.parent();} - - - //make_submenu - } - it++; - } - - /* [show_empty="true"|"false"] - * [inline="true"|"false"] - * [inline_limit="integer"] - * [inline_header="true"|"false"] - * [inline_alias="true"|"false"] - * - */ - } - if(namer.compare("Merge")==0){ - if(!Merge(Layout,RETURN)){outXML("Didn't work out");} - else{return true;} - } - } - INCEPTION=false; - CURRENT_CATEGORIES.clear(); - NOT_CATEGORIES.clear(); - return true; -} -bool make_menu_xdg(std::string infile,std::string outfile){ - //outXML("bool make_menu_xdg(std::string "+infile+",std::string "+outfile+")"); - if(!linuxcommon::test_file(infile)){return false;} - if(outfile.compare("")==0){return false;} - pugi::xml_node node,SUB,Layout,RETURN, DIRdirs, menuNameNode, APPdirs; - //outXML("LOAD:"+infile); - pugi::xml_parse_result result = doc.load_file(infile.c_str()); - if(!result){ - std::cout << ""<< std::endl; - return false; - } - node=doc.child("Menu"); - if(!node){return false;} - if(cache.load(outfile.c_str())){cache.reset();} - RETURN=cache.append_child("JWM"); - SUB=node; - std::vector WAITVector; - for(menuNameNode=node.child("Menu");menuNameNode;menuNameNode=menuNameNode.next_sibling()){ - std::string thisNAME=menuNameNode.child("Name").text().as_string(); - if(thisNAME.compare("")!=0){ - if(menuNameNode.child("OnlyUnallocated")){ - WAITVector.push_back(menuNameNode); - } - else{ - //outXML("Adding "+thisNAME+" menu to MENU_NODES"); - MENU_NAMES.push_back(thisNAME); - MENU_NODES.push_back(menuNameNode); - } - - } - } - if(!WAITVector.empty()){ - for(std::vector::iterator itn=WAITVector.begin();itn!=WAITVector.end();++itn){ - menuNameNode=*itn; - std::string thisNAME=menuNameNode.child("Name").text().as_string(); - //outXML("OnlyUnAllocated adding "+thisNAME+" to the end"); - if(thisNAME.compare("")!=0){ - MENU_NAMES.push_back(thisNAME); - MENU_NODES.push_back(menuNameNode); - } - } - } - if(node.child("DefaultAppDirs")){ - DESKTOP_DIRS=linuxcommon::desktop_paths(); - } - for(APPdirs=node.child("AppDir");APPdirs;APPdirs=APPdirs.next_sibling()){ - std::string tmp=APPdirs.text().as_string(); - if(tmp.compare("")!=0){DESKTOP_DIRS.push_back(tmp);} - } - for(pugi::xml_node mergerDir=node.child("MergeDir");mergerDir;mergerDir=APPdirs.next_sibling()){ - std::string tmp=mergerDir.text().as_string(); - if(tmp.compare("")!=0){ - if(!linuxcommon::test_file(tmp)){ - std::string path=linuxcommon::get_directory_from_filename(infile); - tmp=path+tmp; - } - MERGE_DIRS.push_back(tmp); - } - } - if(node.child("DefaultMergeDirs")){MERGE_DIRS=addMergeDirs(MERGE_DIRS);} - //TODO actually support merge directories - if(node.child("DefaultDirectoryDirs")){ - std::vector tmpVector=categoryDirs(); - DIRECTORY_FILES.insert( DIRECTORY_FILES.end(), tmpVector.begin(), tmpVector.end()); - } - - for(DIRdirs=node.child("DirectoryDir");DIRdirs;DIRdirs=DIRdirs.next_sibling()){ - std::string tmp=DIRdirs.text().as_string(); - if(tmp.compare("")!=0){DIRECTORY_FILES.push_back(tmp);} - } - - /* IF JWM ever supports naming the tray button here... - std::string MENU_NAME="Applications"; - pugi::xml_node temp=node.child("Directory"); - if(temp){ - std::string TEMPstring=temp.text().as_string(); - if(TEMPstring.compare("")!=0){MENU_NAME=get_name(TEMPstring);} - } - */ - DESKTOP_FILES=get_desktop_files(); - if(node.child("Include")){ - Included(node.child("Include"),RETURN); - } - if(node.child("Layout")){ - outXML("Main Layout"); - LayoutMaker(node.child("Layout"),RETURN); - } - else{ - if(!make_submenu(node,RETURN)){return false;} - } - if(!cache.save_file(outfile.c_str())){ - outXML("FAILED TO SAVE:"+outfile); - return false; - } - linuxcommon::print_file_to_stdout(outfile); - return true; -} -std::string make_menu_xdg(std::string prefix){ - - std::vector catarray; - std::string apps="applications.menu"; - std::string menu_filename,line,JWM_MENU; - std::vector confdirs_array=linuxcommon::split_paths("XDG_CONFIG_DIRS","/etc/xdg:/etc/xdg/xdg-torios"); - std::string testPATH,dirToUse; - //std::vector MENUS=xdgmenufiles(); - std::vector directoryFiles; - - //make sure this isn't blank - std::string nO=""; - std::string mO= ""; - std::string mC= ""; - std::string layoutO=""; - std::string dO=""; - std::string iO=""; - std::string aO=""; - std::string cO=""; - std::string NOT=""; - std::string NOTc=""; - std::string appdirs=""; - std::string dirdirs=""; - std::string mergedirs=""; - std::string testEntry; - bool Include,No; - //bool AppDirs=false; - //bool DirDirs=false; - Include=false; - No=false; - unsigned int baseMenu=0; - std::string BASENAME,tempCat, NAME,DIRECTORY,CATEGORY; - testPATH=whichMenu(prefix); - //outXML("Using MENU: "+testPATH); - if(testPATH.compare("")!=0){ - std::ifstream inputFileStrem (testPATH.c_str(), std::ifstream::in); - if(inputFileStrem.is_open()){ - while (getline(inputFileStrem,line)){ - unsigned int length =line.length(); - //RESET if we reach the end of a category - if( (line.find(mO)) < length ){ - baseMenu++; - } - if( (line.find(mergedirs)) tmpVector=categoryDirs(); - directoryFiles.insert( directoryFiles.end(), tmpVector.begin(), tmpVector.end() ); - } - if( (line.find(mC)) < length ){ - if(baseMenu>1){ - catarray=linuxcommon::sort_array(catarray); - directoryFiles=linuxcommon::sort_array(directoryFiles); - unsigned int finder=0; - testEntry=makeXDGmenu(catarray,directoryFiles); - finder=JWM_MENU.find(testEntry); - if(finder>JWM_MENU.length()){ - //outXML(JWM_MENU); - JWM_MENU+=testEntry; - } - NAME=""; - catarray.clear(); - directoryFiles.clear(); - - //Boolean reset - //AppDirs=false; - //DirDirs=false; - Include=false; - No=false; - } - } - if (NAME.compare("")==0){ - if( (line.find(nO)) < length ){ - if(BASENAME.compare("")==0){BASENAME=chopTAG(line);} - else{ - NAME=chopTAG(line); - if (NAME.compare("")!=0){ - //outXML("adding Category: " + NAME); - catarray.push_back(NAME); - } - } - } - } - else{ - //if( (line.find(appdirs)) xdgmenufiles(){ - //$XDG_CONFIG_DIRS/menus/${XDG_MENU_PREFIX}applications.menu - std::string dirToOpen = "/etc/xdg/menus/"; - std::string pathToGet = "/menus/"; - std::string testPATH,tester,result,fullpath; - std::vector MENUS; - std::vector uniqueDirs = linuxcommon::split_paths("XDG_CONFIG_DIRS","/etc/xdg:/etc/xdg/xdg-torios"); - unsigned int found = 0; - //initialize directory reading variables to NULL - DIR *dir = NULL; - struct dirent *entryPointer = NULL; - for( std::vector::iterator it = uniqueDirs.begin(); - it!=uniqueDirs.end(); - ++it){ - //get the string equvalent for the integer representation if of the xdg path - // something like - /* - 1=/usr/share/ - 2=/usr/local/share - etc... - */ - testPATH = *it; - //make sure this isn't blank - if(testPATH.compare("")!=0){ - //look to see if we have a / at the end... remove it if we do... - found = testPATH.rfind('/'); - if (found == testPATH.length()-1){testPATH=testPATH.substr(0,testPATH.length()-1);} - //see if there is a pathToGet directory - dirToOpen = testPATH + pathToGet; - dir = opendir(dirToOpen.c_str()); - if(dir!=NULL){ - while ((entryPointer=readdir(dir)) != NULL){ - if ((entryPointer->d_type == DT_REG)&&(entryPointer->d_name[0] != '.')){ - fullpath = entryPointer->d_name; - result=dirToOpen+fullpath; - tester=dirToOpen+fullpath; - unsigned period = result.rfind("."); - bool isMENU = false; - if(result.compare("")!=0){ - if(period addMergeDirs(std::vector directoryFiles){ - //outXML("std::vector addMergeDirs(std::vector directoryFiles)"); - std::string dirToOpen = "/etc/xdg/menus/applications-merged/"; - std::vector MENUS= linuxcommon::split_paths("XDG_CONFIG_DIRS","/etc/xdg:/etc/xdg/xdg-torios"); - DIR *dir = NULL; - struct dirent *entryPointer = NULL; - std::string result; - std::string fullpath="/menus/applications-merged/"; - for( std::vector::iterator it = MENUS.begin(); - it!=MENUS.end(); - ++it){ - - dirToOpen=*it; - dirToOpen+=fullpath; - dir = opendir(dirToOpen.c_str()); - if (dir!=NULL){ - while ((entryPointer=readdir(dir)) != NULL){ - if ((entryPointer->d_type == DT_REG)&&(entryPointer->d_name[0] != '.')){ - result=dirToOpen; - result += entryPointer->d_name; - unsigned period = result.rfind("."); - bool isMENU = false; - if(result.compare("")!=0){ - if(period categoryDirs(){ - //outXML("std::vector categoryDirs()"); - std::string DD="/desktop-directories/"; - std::string dirToOpen,testPATH; - const char* home=getenv("HOME"); - std::vector dirVector; - std::vector tmpVector; - std::vector returnVector; - unsigned int found=0; - std::string HOME; - if(home != NULL){ - HOME=home; - } - std::string getdirs=HOME; - if(HOME.compare("")!=0){ - getdirs+="/.local/share/"; - dirVector=linuxcommon::split_paths("XDG_DATA_HOME",getdirs.c_str()); - } - //get the data dirs - tmpVector=linuxcommon::split_paths("XDG_DATA_DIRS","/usr/share:/usr/local/share"); - //insert the data dirs on the data home (if it exists); - dirVector.insert(dirVector.end(),tmpVector.begin(),tmpVector.end()); - for( std::vector::iterator it = dirVector.begin(); - it!=dirVector.end(); - ++it){ - //the current string in the vector - testPATH = *it; - //make sure this isn't blank - if(testPATH.compare("")!=0){ - //look to see if we have a / at the end... remove it if we do... - found = testPATH.rfind('/'); - if (found == testPATH.length()-1){testPATH=testPATH.substr(0,testPATH.length()-1);} - //see if there is a pathToGet directory - dirToOpen = testPATH + DD; - //see if it has the desktop directories folder - if(linuxcommon::test_dir(dirToOpen)){returnVector.push_back(dirToOpen);} - } - } - return returnVector; -} -void writeOut(std::string MSG){ - std::cout<>"$LOGFILE" + printf "%s" "$input" 2>>"$LOGFILE" } #make a function to get the modification time