Date:2015-04-23 17:28:22 (8 years 7 months ago)
Author:Maarten ter Huurne
Commit:aa45ed9a74ba5818a8000a06a0ddf61c2a2f7c32
Message:Use const references to strings in Menu method arguments

This avoids unnecessary copying.

Removed sectionName argument to addLink(), since its only caller didn't
provide a value for it, meaning it always defaulted.
Files: src/menu.cpp (9 diffs)
src/menu.h (5 diffs)

Change Details

src/menu.cpp
108108    freeLinks();
109109}
110110
111void Menu::readSections(std::string parentDir)
111void Menu::readSections(std::string const& parentDir)
112112{
113113    DIR *dirp;
114114    struct dirent *dptr;
...... 
401401/*====================================
402402   LINKS MANAGEMENT
403403  ====================================*/
404void Menu::addActionLink(uint section, const string &title, Action action, const string &description, const string &icon) {
404void Menu::addActionLink(uint section, string const& title, Action action,
405        string const& description, string const& icon)
406{
405407    assert(section < sections.size());
406408
407409    Link *link = new Link(gmenu2x, action);
...... 
418420    links[section].push_back(link);
419421}
420422
421bool Menu::addLink(string path, string file, string sectionName) {
422    if (sectionName.empty()) {
423        sectionName = selSection();
424    }
423bool Menu::addLink(string const& path, string const& file)
424{
425    string const& sectionName = selSection();
425426
426427    string sectionDir = createSectionDir(sectionName);
427428    if (sectionDir.empty()) {
...... 
447448    }
448449    INFO("Adding link: '%s'\n", linkpath.c_str());
449450
450    if (path[path.length()-1]!='/') path += "/";
451    string dirPath = path;
452    if (dirPath.empty() || dirPath.back() != '/') dirPath += '/';
453
451454    //search for a manual
452455    pos = file.rfind(".");
453    string exename = path+file.substr(0,pos);
456    string exename = dirPath + file.substr(0, pos);
454457    string manual = "";
455458    if (fileExists(exename+".man.png")) {
456459        manual = exename+".man.png";
...... 
461464        FileLister fl;
462465        fl.setShowDirectories(false);
463466        fl.setFilter(".txt");
464        fl.browse(path);
467        fl.browse(dirPath);
465468        bool found = false;
466469        for (uint x=0; x<fl.size() && !found; x++) {
467470            string lcfilename = fl[x];
468471
469472            if (lcfilename.find("readme") != string::npos) {
470473                found = true;
471                manual = path+fl.getFiles()[x];
474                manual = dirPath + fl.getFiles()[x];
472475            }
473476        }
474477    }
475478
476479    INFO("Manual: '%s'\n", manual.c_str());
477480
478    string shorttitle=title, description="", exec=path+file, icon="";
481    string shorttitle=title, description="", exec=dirPath+file, icon="";
479482    if (fileExists(exename+".png")) icon = exename+".png";
480483
481484    //Reduce title lenght to fit the link width
...... 
642645}
643646
644647#ifdef HAVE_LIBOPK
645void Menu::openPackagesFromDir(std::string path)
648void Menu::openPackagesFromDir(std::string const& path)
646649{
647650    DEBUG("Opening packages from directory: %s\n", path.c_str());
648651    if (readPackages(path)) {
...... 
652655    }
653656}
654657
655void Menu::openPackage(std::string path, bool order)
658void Menu::openPackage(std::string const& path, bool order)
656659{
657660    /* First try to remove existing links of the same OPK
658661     * (needed for instance when an OPK is modified) */
...... 
748751/* Remove all links that correspond to the given path.
749752 * If "path" is a directory, it will remove all links that
750753 * correspond to an OPK present in the directory. */
751void Menu::removePackageLink(std::string path)
754void Menu::removePackageLink(std::string const& path)
752755{
753756    for (vector< vector<Link*> >::iterator section = links.begin();
754757                section < links.end(); section++) {
...... 
845848    closedir(dirp);
846849}
847850
848void Menu::renameSection(int index, const string &name) {
851void Menu::renameSection(int index, string const& name) {
849852    sections[index] = name;
850853}
src/menu.h
7878    void freeLinks();
7979
8080    // Load all the sections of the given "sections" directory.
81    void readSections(std::string parentDir);
81    void readSections(std::string const& parentDir);
8282
8383#ifdef HAVE_LIBOPK
8484    // Load all the .opk packages of the given directory
...... 
113113    virtual ~Menu();
114114
115115#ifdef HAVE_LIBOPK
116    void openPackage(std::string path, bool order = true);
117    void openPackagesFromDir(std::string path);
116    void openPackage(std::string const& path, bool order = true);
117    void openPackagesFromDir(std::string const& path);
118118#ifdef ENABLE_INOTIFY
119    void removePackageLink(std::string path);
119    void removePackageLink(std::string const& path);
120120#endif
121121#endif
122122
...... 
124124    const std::string &selSection();
125125    void setSectionIndex(int i);
126126
127    void addActionLink(uint section, const std::string &title,
128            Action action, const std::string &description="",
129            const std::string &icon="");
130    bool addLink(std::string path, std::string file, std::string sectionName="");
127    void addActionLink(uint section, std::string const& title,
128            Action action, std::string const& description="",
129            std::string const& icon="");
130    bool addLink(std::string const& path, std::string const& file);
131131
132132    /**
133133     * Looks up a section by name, adding it if it doesn't exist yet.
...... 
138138     * Looks up a section by name, adding it if it doesn't exist yet.
139139     * @return The index of the section.
140140     */
141    int sectionNamed(const std::string &sectionName) {
141    int sectionNamed(std::string const& sectionName) {
142142        return sectionNamed(sectionName.c_str());
143143    }
144144
...... 
162162    void setLinkIndex(int i);
163163
164164    const std::vector<std::string> &getSections() { return sections; }
165    void renameSection(int index, const std::string &name);
165    void renameSection(int index, std::string const& name);
166166};
167167
168168#endif // MENU_H

Archive Download the corresponding diff file



interactive