mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-26 02:00:37 +02:00
Split huge function readPackages into two functions
This commit is contained in:
parent
1337eb5ed8
commit
78ad051756
115
src/menu.cpp
115
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);
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user