diff -u'Nrpk~' menu-2.1.35~/install-menu/functions.cc menu-2.1.35/install-menu/functions.cc --- menu-2.1.35/install-menu/functions.cc~ 2007-10-10 14:33:44 +0400 +++ menu-2.1.35/install-menu/functions.cc 2007-10-10 14:42:57 +0400 @@ -597,4 +597,72 @@ ostream &substr::output(ostream &o, vect return o << s.substr( ps, sz ); } +ostream &locate_icon::output(ostream &o, vector &args, + map &menuentry) +{ + string path; + string str_sz = args[0]->soutput(menuentry); + string icon_name = args[1]->soutput(menuentry); + std::list paths; + std::list exts; + int icon_name_sz = icon_name.size(); + + if( str_sz.size() <= 0 ) + { + str_sz = "16"; + } + + if( icon_name_sz <= 0 ) + { + icon_name_sz = 15; + icon_name = "default_section"; + } + else if( icon_name.substr(0,1) == "/" ) + { + return o << icon_name; + } + + if( icon_name.substr(icon_name_sz-4,1) == "." ) + { + icon_name_sz = icon_name_sz-4; + icon_name = icon_name.substr(0, icon_name_sz); + } + + exts.push_back(".png"); + exts.push_back(".xpm"); + + paths.push_back(string("/usr/share/icons/Tango/") + str_sz +"x" + str_sz + "/apps/"); + paths.push_back(string("/usr/share/icons/TangoKDE/") + str_sz +"x" + str_sz + "/apps/"); + paths.push_back(string("/usr/share/icons/hicolor/") + str_sz +"x" + str_sz + "/apps/"); + paths.push_back(string("/usr/share/icons/default.kde/") + str_sz +"x" + str_sz + "/apps/"); + paths.push_back(string("/usr/share/icons/default.gnome/") + str_sz +"x" + str_sz + "/apps/"); + if( str_sz == "48" ) + paths.push_back("/usr/share/icons/large/"); + else if( str_sz == "32" ) + paths.push_back("/usr/share/icons/"); + else if( str_sz == "16" ) + paths.push_back("/usr/share/icons/mini/"); + paths.push_back("/usr/share/pixmaps/"); + + std::list::iterator it_ext; + for(it_ext = exts.begin(); it_ext != exts.end(); it_ext++) + { + std::list::iterator it_path; + for(it_path = paths.begin(); it_path != paths.end(); it_path++) + { + string xpath(*it_path + icon_name + *it_ext); + if( ::access(xpath.c_str(), F_OK) == 0 ) + { + path = xpath; + break; + } + } + } + + if( path.size() <= 0 ) + path = string("/usr/share/icons/hicolor/") + str_sz +"x" + str_sz + "/apps/default_section.png"; + + return o << path; +} + } diff -u'Nrpk~' menu-2.1.35~/install-menu/functions.h menu-2.1.35/install-menu/functions.h --- menu-2.1.35~/install-menu/functions.h 2007-10-09 18:33:14 +0400 +++ menu-2.1.35/install-menu/functions.h 2007-10-09 17:17:44 +0400 @@ -314,6 +314,10 @@ namespace functions { const char * getName() const {return "substr";} }; + struct locate_icon : public funcN<2> { + std::ostream &output(std::ostream &o, std::vector &, std::map &); + const char * getName() const { return "locate_icon"; } + }; } #endif diff -u'Nrpk~' menu-2.1.35~/install-menu/install-menu.cc menu-2.1.35/install-menu/install-menu.cc --- menu-2.1.35~/install-menu/install-menu.cc 2007-10-09 18:33:14 +0400 +++ menu-2.1.35/install-menu/install-menu.cc 2007-10-09 17:04:39 +0400 @@ -189,6 +189,7 @@ void add_functions() store_func(new functions::encode_translate); store_func(new functions::encode); store_func(new functions::substr); + store_func(new functions::locate_icon); } cat_str *get_eq_cat_str(parsestream &i)