Date: | 2015-04-23 17:28:22 (8 years 1 month 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 | ||
---|---|---|
108 | 108 | freeLinks(); |
109 | 109 | } |
110 | 110 | |
111 | void Menu::readSections(std::string parentDir) | |
111 | void Menu::readSections(std::string const& parentDir) | |
112 | 112 | { |
113 | 113 | DIR *dirp; |
114 | 114 | struct dirent *dptr; |
... | ... | |
401 | 401 | /*==================================== |
402 | 402 | LINKS MANAGEMENT |
403 | 403 | ====================================*/ |
404 | void Menu::addActionLink(uint section, const string &title, Action action, const string &description, const string &icon) { | |
404 | void Menu::addActionLink(uint section, string const& title, Action action, | |
405 | string const& description, string const& icon) | |
406 | { | |
405 | 407 | assert(section < sections.size()); |
406 | 408 | |
407 | 409 | Link *link = new Link(gmenu2x, action); |
... | ... | |
418 | 420 | links[section].push_back(link); |
419 | 421 | } |
420 | 422 | |
421 | bool Menu::addLink(string path, string file, string sectionName) { | |
422 | if (sectionName.empty()) { | |
423 | sectionName = selSection(); | |
424 | } | |
423 | bool Menu::addLink(string const& path, string const& file) | |
424 | { | |
425 | string const& sectionName = selSection(); | |
425 | 426 | |
426 | 427 | string sectionDir = createSectionDir(sectionName); |
427 | 428 | if (sectionDir.empty()) { |
... | ... | |
447 | 448 | } |
448 | 449 | INFO("Adding link: '%s'\n", linkpath.c_str()); |
449 | 450 | |
450 | if (path[path.length()-1]!='/') path += "/"; | |
451 | string dirPath = path; | |
452 | if (dirPath.empty() || dirPath.back() != '/') dirPath += '/'; | |
453 | ||
451 | 454 | //search for a manual |
452 | 455 | pos = file.rfind("."); |
453 | string exename = path+file.substr(0,pos); | |
456 | string exename = dirPath + file.substr(0, pos); | |
454 | 457 | string manual = ""; |
455 | 458 | if (fileExists(exename+".man.png")) { |
456 | 459 | manual = exename+".man.png"; |
... | ... | |
461 | 464 | FileLister fl; |
462 | 465 | fl.setShowDirectories(false); |
463 | 466 | fl.setFilter(".txt"); |
464 | fl.browse(path); | |
467 | fl.browse(dirPath); | |
465 | 468 | bool found = false; |
466 | 469 | for (uint x=0; x<fl.size() && !found; x++) { |
467 | 470 | string lcfilename = fl[x]; |
468 | 471 | |
469 | 472 | if (lcfilename.find("readme") != string::npos) { |
470 | 473 | found = true; |
471 | manual = path+fl.getFiles()[x]; | |
474 | manual = dirPath + fl.getFiles()[x]; | |
472 | 475 | } |
473 | 476 | } |
474 | 477 | } |
475 | 478 | |
476 | 479 | INFO("Manual: '%s'\n", manual.c_str()); |
477 | 480 | |
478 | string shorttitle=title, description="", exec=path+file, icon=""; | |
481 | string shorttitle=title, description="", exec=dirPath+file, icon=""; | |
479 | 482 | if (fileExists(exename+".png")) icon = exename+".png"; |
480 | 483 | |
481 | 484 | //Reduce title lenght to fit the link width |
... | ... | |
642 | 645 | } |
643 | 646 | |
644 | 647 | #ifdef HAVE_LIBOPK |
645 | void Menu::openPackagesFromDir(std::string path) | |
648 | void Menu::openPackagesFromDir(std::string const& path) | |
646 | 649 | { |
647 | 650 | DEBUG("Opening packages from directory: %s\n", path.c_str()); |
648 | 651 | if (readPackages(path)) { |
... | ... | |
652 | 655 | } |
653 | 656 | } |
654 | 657 | |
655 | void Menu::openPackage(std::string path, bool order) | |
658 | void Menu::openPackage(std::string const& path, bool order) | |
656 | 659 | { |
657 | 660 | /* First try to remove existing links of the same OPK |
658 | 661 | * (needed for instance when an OPK is modified) */ |
... | ... | |
748 | 751 | /* Remove all links that correspond to the given path. |
749 | 752 | * If "path" is a directory, it will remove all links that |
750 | 753 | * correspond to an OPK present in the directory. */ |
751 | void Menu::removePackageLink(std::string path) | |
754 | void Menu::removePackageLink(std::string const& path) | |
752 | 755 | { |
753 | 756 | for (vector< vector<Link*> >::iterator section = links.begin(); |
754 | 757 | section < links.end(); section++) { |
... | ... | |
845 | 848 | closedir(dirp); |
846 | 849 | } |
847 | 850 | |
848 | void Menu::renameSection(int index, const string &name) { | |
851 | void Menu::renameSection(int index, string const& name) { | |
849 | 852 | sections[index] = name; |
850 | 853 | } |
src/menu.h | ||
---|---|---|
78 | 78 | void freeLinks(); |
79 | 79 | |
80 | 80 | // Load all the sections of the given "sections" directory. |
81 | void readSections(std::string parentDir); | |
81 | void readSections(std::string const& parentDir); | |
82 | 82 | |
83 | 83 | #ifdef HAVE_LIBOPK |
84 | 84 | // Load all the .opk packages of the given directory |
... | ... | |
113 | 113 | virtual ~Menu(); |
114 | 114 | |
115 | 115 | #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); | |
118 | 118 | #ifdef ENABLE_INOTIFY |
119 | void removePackageLink(std::string path); | |
119 | void removePackageLink(std::string const& path); | |
120 | 120 | #endif |
121 | 121 | #endif |
122 | 122 | |
... | ... | |
124 | 124 | const std::string &selSection(); |
125 | 125 | void setSectionIndex(int i); |
126 | 126 | |
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); | |
131 | 131 | |
132 | 132 | /** |
133 | 133 | * Looks up a section by name, adding it if it doesn't exist yet. |
... | ... | |
138 | 138 | * Looks up a section by name, adding it if it doesn't exist yet. |
139 | 139 | * @return The index of the section. |
140 | 140 | */ |
141 | int sectionNamed(const std::string §ionName) { | |
141 | int sectionNamed(std::string const& sectionName) { | |
142 | 142 | return sectionNamed(sectionName.c_str()); |
143 | 143 | } |
144 | 144 | |
... | ... | |
162 | 162 | void setLinkIndex(int i); |
163 | 163 | |
164 | 164 | 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); | |
166 | 166 | }; |
167 | 167 | |
168 | 168 | #endif // MENU_H |
Branches:
install_locations
master
opkrun
packages