diff --git a/src/menu.cpp b/src/menu.cpp index 3bdb93d..680a88a 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -108,7 +108,7 @@ Menu::~Menu() { freeLinks(); } -void Menu::readSections(std::string parentDir) +void Menu::readSections(std::string const& parentDir) { DIR *dirp; struct dirent *dptr; @@ -401,7 +401,9 @@ void Menu::setSectionIndex(int i) { /*==================================== LINKS MANAGEMENT ====================================*/ -void Menu::addActionLink(uint section, const string &title, Action action, const string &description, const string &icon) { +void Menu::addActionLink(uint section, string const& title, Action action, + string const& description, string const& icon) +{ assert(section < sections.size()); Link *link = new Link(gmenu2x, action); @@ -418,10 +420,9 @@ void Menu::addActionLink(uint section, const string &title, Action action, const links[section].push_back(link); } -bool Menu::addLink(string path, string file, string sectionName) { - if (sectionName.empty()) { - sectionName = selSection(); - } +bool Menu::addLink(string const& path, string const& file) +{ + string const& sectionName = selSection(); string sectionDir = createSectionDir(sectionName); if (sectionDir.empty()) { @@ -447,10 +448,12 @@ bool Menu::addLink(string path, string file, string sectionName) { } INFO("Adding link: '%s'\n", linkpath.c_str()); - if (path[path.length()-1]!='/') path += "/"; + string dirPath = path; + if (dirPath.empty() || dirPath.back() != '/') dirPath += '/'; + //search for a manual pos = file.rfind("."); - string exename = path+file.substr(0,pos); + string exename = dirPath + file.substr(0, pos); string manual = ""; if (fileExists(exename+".man.png")) { manual = exename+".man.png"; @@ -461,21 +464,21 @@ bool Menu::addLink(string path, string file, string sectionName) { FileLister fl; fl.setShowDirectories(false); fl.setFilter(".txt"); - fl.browse(path); + fl.browse(dirPath); bool found = false; for (uint x=0; x >::iterator section = links.begin(); section < links.end(); section++) { @@ -845,6 +848,6 @@ void Menu::readLinksOfSection( closedir(dirp); } -void Menu::renameSection(int index, const string &name) { +void Menu::renameSection(int index, string const& name) { sections[index] = name; } diff --git a/src/menu.h b/src/menu.h index cd94589..b84ad07 100644 --- a/src/menu.h +++ b/src/menu.h @@ -78,7 +78,7 @@ private: void freeLinks(); // Load all the sections of the given "sections" directory. - void readSections(std::string parentDir); + void readSections(std::string const& parentDir); #ifdef HAVE_LIBOPK // Load all the .opk packages of the given directory @@ -113,10 +113,10 @@ public: virtual ~Menu(); #ifdef HAVE_LIBOPK - void openPackage(std::string path, bool order = true); - void openPackagesFromDir(std::string path); + void openPackage(std::string const& path, bool order = true); + void openPackagesFromDir(std::string const& path); #ifdef ENABLE_INOTIFY - void removePackageLink(std::string path); + void removePackageLink(std::string const& path); #endif #endif @@ -124,10 +124,10 @@ public: const std::string &selSection(); void setSectionIndex(int i); - void addActionLink(uint section, const std::string &title, - Action action, const std::string &description="", - const std::string &icon=""); - bool addLink(std::string path, std::string file, std::string sectionName=""); + void addActionLink(uint section, std::string const& title, + Action action, std::string const& description="", + std::string const& icon=""); + bool addLink(std::string const& path, std::string const& file); /** * Looks up a section by name, adding it if it doesn't exist yet. @@ -138,7 +138,7 @@ public: * Looks up a section by name, adding it if it doesn't exist yet. * @return The index of the section. */ - int sectionNamed(const std::string §ionName) { + int sectionNamed(std::string const& sectionName) { return sectionNamed(sectionName.c_str()); } @@ -162,7 +162,7 @@ public: void setLinkIndex(int i); const std::vector &getSections() { return sections; } - void renameSection(int index, const std::string &name); + void renameSection(int index, std::string const& name); }; #endif // MENU_H