From 78ad051756dab9feee1e35245e4adbf1abea3330 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Wed, 10 Jul 2013 18:57:56 -0400 Subject: [PATCH] Split huge function readPackages into two functions --- src/menu.cpp | 115 ++++++++++++++++++++++++++------------------------- src/menu.h | 1 + 2 files changed, 59 insertions(+), 57 deletions(-) diff --git a/src/menu.cpp b/src/menu.cpp index e0ce881..d047465 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -214,7 +214,7 @@ bool Menu::addLink(string path, string file, string section) { string::size_type pos = title.rfind("."); if (pos!=string::npos && pos>0) { string ext = title.substr(pos, title.length()); - transform(ext.begin(), ext.end(), ext.begin(), (int(*)(int)) tolower); + transform(ext.begin(), ext.end(), ext.begin(), ::tolower); title = title.substr(0, pos); } @@ -438,6 +438,62 @@ void Menu::setLinkIndex(int i) { } #ifdef HAVE_LIBOPK +void Menu::openPackage(std::string path) +{ + struct OPK *opk = opk_open(path.c_str()); + if (!opk) { + ERROR("Unable to open OPK %s\n", path.c_str()); + return; + } + + for (;;) { + unsigned int i; + bool has_metadata = false; + LinkApp *link; + + for (;;) { + string::size_type pos; + const char *name; + int ret = opk_open_metadata(opk, &name); + if (ret < 0) { + ERROR("Error while loading meta-data\n"); + break; + } else if (!ret) + break; + + /* Strip .desktop */ + string metadata(name); + pos = metadata.rfind('.'); + metadata = metadata.substr(0, pos); + + /* Keep only the platform name */ + pos = metadata.rfind('.'); + metadata = metadata.substr(pos + 1); + + if (metadata.compare(PLATFORM) == 0) { + has_metadata = true; + break; + } + } + + if (!has_metadata) + break; + + link = new LinkApp(gmenu2x, ts, gmenu2x->input, path.c_str(), opk); + link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]); + + addSection(link->getCategory()); + for (i = 0; i < sections.size(); i++) { + if (sections[i] == link->getCategory()) { + links[i].push_back(link); + break; + } + } + } + + opk_close(opk); +} + void Menu::readPackages(std::string parentDir) { DIR *dirp; @@ -450,9 +506,6 @@ void Menu::readPackages(std::string parentDir) while ((dptr = readdir(dirp))) { char *c; - std::string path; - unsigned int i; - struct OPK *opk; if (dptr->d_type != DT_REG) continue; @@ -470,59 +523,7 @@ void Menu::readPackages(std::string parentDir) continue; } - path = parentDir + '/' + dptr->d_name; - - opk = opk_open(path.c_str()); - if (!opk) { - ERROR("Unable to open OPK %s\n", path.c_str()); - continue; - } - - for (;;) { - bool has_metadata = false; - LinkApp *link; - - for (;;) { - string::size_type pos; - const char *name; - int ret = opk_open_metadata(opk, &name); - if (ret < 0) { - ERROR("Error while loading meta-data\n"); - break; - } else if (!ret) - break; - - /* Strip .desktop */ - string metadata(name); - pos = metadata.rfind('.'); - metadata = metadata.substr(0, pos); - - /* Keep only the platform name */ - pos = metadata.rfind('.'); - metadata = metadata.substr(pos + 1); - - if (metadata.compare(PLATFORM) == 0) { - has_metadata = true; - break; - } - } - - if (!has_metadata) - break; - - link = new LinkApp(gmenu2x, ts, gmenu2x->input, path.c_str(), opk); - link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]); - - addSection(link->getCategory()); - for (i = 0; i < sections.size(); i++) { - if (sections[i] == link->getCategory()) { - links[i].push_back(link); - break; - } - } - } - - opk_close(opk); + openPackage(parentDir + '/' + dptr->d_name); } closedir(dirp); diff --git a/src/menu.h b/src/menu.h index 877f257..e0f9c04 100644 --- a/src/menu.h +++ b/src/menu.h @@ -52,6 +52,7 @@ private: #ifdef HAVE_LIBOPK // Load all the .opk packages of the given directory void readPackages(std::string parentDir); + void openPackage(std::string path); #endif // Load all the links on the given section directory.