mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-04 23:37:10 +02:00
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.
This commit is contained in:
parent
9ca019ef51
commit
aa45ed9a74
33
src/menu.cpp
33
src/menu.cpp
@ -108,7 +108,7 @@ Menu::~Menu() {
|
|||||||
freeLinks();
|
freeLinks();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::readSections(std::string parentDir)
|
void Menu::readSections(std::string const& parentDir)
|
||||||
{
|
{
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
struct dirent *dptr;
|
struct dirent *dptr;
|
||||||
@ -401,7 +401,9 @@ void Menu::setSectionIndex(int i) {
|
|||||||
/*====================================
|
/*====================================
|
||||||
LINKS MANAGEMENT
|
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());
|
assert(section < sections.size());
|
||||||
|
|
||||||
Link *link = new Link(gmenu2x, action);
|
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);
|
links[section].push_back(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Menu::addLink(string path, string file, string sectionName) {
|
bool Menu::addLink(string const& path, string const& file)
|
||||||
if (sectionName.empty()) {
|
{
|
||||||
sectionName = selSection();
|
string const& sectionName = selSection();
|
||||||
}
|
|
||||||
|
|
||||||
string sectionDir = createSectionDir(sectionName);
|
string sectionDir = createSectionDir(sectionName);
|
||||||
if (sectionDir.empty()) {
|
if (sectionDir.empty()) {
|
||||||
@ -447,10 +448,12 @@ bool Menu::addLink(string path, string file, string sectionName) {
|
|||||||
}
|
}
|
||||||
INFO("Adding link: '%s'\n", linkpath.c_str());
|
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
|
//search for a manual
|
||||||
pos = file.rfind(".");
|
pos = file.rfind(".");
|
||||||
string exename = path+file.substr(0,pos);
|
string exename = dirPath + file.substr(0, pos);
|
||||||
string manual = "";
|
string manual = "";
|
||||||
if (fileExists(exename+".man.png")) {
|
if (fileExists(exename+".man.png")) {
|
||||||
manual = exename+".man.png";
|
manual = exename+".man.png";
|
||||||
@ -461,21 +464,21 @@ bool Menu::addLink(string path, string file, string sectionName) {
|
|||||||
FileLister fl;
|
FileLister fl;
|
||||||
fl.setShowDirectories(false);
|
fl.setShowDirectories(false);
|
||||||
fl.setFilter(".txt");
|
fl.setFilter(".txt");
|
||||||
fl.browse(path);
|
fl.browse(dirPath);
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (uint x=0; x<fl.size() && !found; x++) {
|
for (uint x=0; x<fl.size() && !found; x++) {
|
||||||
string lcfilename = fl[x];
|
string lcfilename = fl[x];
|
||||||
|
|
||||||
if (lcfilename.find("readme") != string::npos) {
|
if (lcfilename.find("readme") != string::npos) {
|
||||||
found = true;
|
found = true;
|
||||||
manual = path+fl.getFiles()[x];
|
manual = dirPath + fl.getFiles()[x];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
INFO("Manual: '%s'\n", manual.c_str());
|
INFO("Manual: '%s'\n", manual.c_str());
|
||||||
|
|
||||||
string shorttitle=title, description="", exec=path+file, icon="";
|
string shorttitle=title, description="", exec=dirPath+file, icon="";
|
||||||
if (fileExists(exename+".png")) icon = exename+".png";
|
if (fileExists(exename+".png")) icon = exename+".png";
|
||||||
|
|
||||||
//Reduce title lenght to fit the link width
|
//Reduce title lenght to fit the link width
|
||||||
@ -642,7 +645,7 @@ void Menu::setLinkIndex(int i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBOPK
|
#ifdef HAVE_LIBOPK
|
||||||
void Menu::openPackagesFromDir(std::string path)
|
void Menu::openPackagesFromDir(std::string const& path)
|
||||||
{
|
{
|
||||||
DEBUG("Opening packages from directory: %s\n", path.c_str());
|
DEBUG("Opening packages from directory: %s\n", path.c_str());
|
||||||
if (readPackages(path)) {
|
if (readPackages(path)) {
|
||||||
@ -652,7 +655,7 @@ void Menu::openPackagesFromDir(std::string path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::openPackage(std::string path, bool order)
|
void Menu::openPackage(std::string const& path, bool order)
|
||||||
{
|
{
|
||||||
/* First try to remove existing links of the same OPK
|
/* First try to remove existing links of the same OPK
|
||||||
* (needed for instance when an OPK is modified) */
|
* (needed for instance when an OPK is modified) */
|
||||||
@ -748,7 +751,7 @@ bool Menu::readPackages(std::string const& parentDir)
|
|||||||
/* Remove all links that correspond to the given path.
|
/* Remove all links that correspond to the given path.
|
||||||
* If "path" is a directory, it will remove all links that
|
* If "path" is a directory, it will remove all links that
|
||||||
* correspond to an OPK present in the directory. */
|
* correspond to an OPK present in the directory. */
|
||||||
void Menu::removePackageLink(std::string path)
|
void Menu::removePackageLink(std::string const& path)
|
||||||
{
|
{
|
||||||
for (vector< vector<Link*> >::iterator section = links.begin();
|
for (vector< vector<Link*> >::iterator section = links.begin();
|
||||||
section < links.end(); section++) {
|
section < links.end(); section++) {
|
||||||
@ -845,6 +848,6 @@ void Menu::readLinksOfSection(
|
|||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::renameSection(int index, const string &name) {
|
void Menu::renameSection(int index, string const& name) {
|
||||||
sections[index] = name;
|
sections[index] = name;
|
||||||
}
|
}
|
||||||
|
20
src/menu.h
20
src/menu.h
@ -78,7 +78,7 @@ private:
|
|||||||
void freeLinks();
|
void freeLinks();
|
||||||
|
|
||||||
// Load all the sections of the given "sections" directory.
|
// Load all the sections of the given "sections" directory.
|
||||||
void readSections(std::string parentDir);
|
void readSections(std::string const& parentDir);
|
||||||
|
|
||||||
#ifdef HAVE_LIBOPK
|
#ifdef HAVE_LIBOPK
|
||||||
// Load all the .opk packages of the given directory
|
// Load all the .opk packages of the given directory
|
||||||
@ -113,10 +113,10 @@ public:
|
|||||||
virtual ~Menu();
|
virtual ~Menu();
|
||||||
|
|
||||||
#ifdef HAVE_LIBOPK
|
#ifdef HAVE_LIBOPK
|
||||||
void openPackage(std::string path, bool order = true);
|
void openPackage(std::string const& path, bool order = true);
|
||||||
void openPackagesFromDir(std::string path);
|
void openPackagesFromDir(std::string const& path);
|
||||||
#ifdef ENABLE_INOTIFY
|
#ifdef ENABLE_INOTIFY
|
||||||
void removePackageLink(std::string path);
|
void removePackageLink(std::string const& path);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -124,10 +124,10 @@ public:
|
|||||||
const std::string &selSection();
|
const std::string &selSection();
|
||||||
void setSectionIndex(int i);
|
void setSectionIndex(int i);
|
||||||
|
|
||||||
void addActionLink(uint section, const std::string &title,
|
void addActionLink(uint section, std::string const& title,
|
||||||
Action action, const std::string &description="",
|
Action action, std::string const& description="",
|
||||||
const std::string &icon="");
|
std::string const& icon="");
|
||||||
bool addLink(std::string path, std::string file, std::string sectionName="");
|
bool addLink(std::string const& path, std::string const& file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks up a section by name, adding it if it doesn't exist yet.
|
* 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.
|
* Looks up a section by name, adding it if it doesn't exist yet.
|
||||||
* @return The index of the section.
|
* @return The index of the section.
|
||||||
*/
|
*/
|
||||||
int sectionNamed(const std::string §ionName) {
|
int sectionNamed(std::string const& sectionName) {
|
||||||
return sectionNamed(sectionName.c_str());
|
return sectionNamed(sectionName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ public:
|
|||||||
void setLinkIndex(int i);
|
void setLinkIndex(int i);
|
||||||
|
|
||||||
const std::vector<std::string> &getSections() { return sections; }
|
const std::vector<std::string> &getSections() { return sections; }
|
||||||
void renameSection(int index, const std::string &name);
|
void renameSection(int index, std::string const& name);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MENU_H
|
#endif // MENU_H
|
||||||
|
Loading…
Reference in New Issue
Block a user