diff --git a/src/linkapp.cpp b/src/linkapp.cpp index 2f674e6..8d70c12 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -57,7 +57,7 @@ static const char *tokens[] = { "%f", "%F", "%u", "%U", }; #ifdef HAVE_LIBOPK LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_, - const char* linkfile, bool opk) + const char* linkfile, struct ParserData *pdata) #else LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_, const char* linkfile) @@ -80,45 +80,11 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_, #endif #ifdef HAVE_LIBOPK - isOPK = opk; - if (opk) { + isOPK = !!pdata; + if (isOPK) { string::size_type pos; - struct ParserData *pdata = opk_open(linkfile); char *param; - bool has_metadata = false; - - if (!pdata) { - ERROR("Unable to initialize libopk\n"); - return; - } - - for(;;) { - const char *str = opk_open_metadata(pdata); - if (!str) - break; - - /* Strip .desktop */ - string metadata(str); - 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) { - ERROR("%s does not contain any meta-data for this platform\n", linkfile); - opk_close(pdata); - return; - } - opkFile = file; pos = file.rfind('/'); @@ -225,7 +191,6 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_, dontleave = !strcmp(param, "true"); edited = true; - opk_close(pdata); } #endif /* HAVE_LIBOPK */ @@ -252,7 +217,7 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_, setAliasFile( value ); } else #ifdef HAVE_LIBOPK - if (!opk) { + if (!isOPK) { #endif if (name == "title") { title = value; diff --git a/src/linkapp.h b/src/linkapp.h index d2e98e9..7c87ddb 100644 --- a/src/linkapp.h +++ b/src/linkapp.h @@ -63,7 +63,7 @@ public: bool isOpk() { return isOPK; } LinkApp(GMenu2X *gmenu2x, Touchscreen &ts, InputManager &inputMgr, - const char* linkfile, bool opk = false); + const char* linkfile, struct ParserData *pdata = NULL); #else LinkApp(GMenu2X *gmenu2x, Touchscreen &ts, InputManager &inputMgr, const char* linkfile); diff --git a/src/menu.cpp b/src/menu.cpp index ff9c432..4737b2e 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -27,6 +27,10 @@ #include #include +#ifdef HAVE_LIBOPK +#include +#endif + #include "gmenu2x.h" #include "linkapp.h" #include "menu.h" @@ -446,9 +450,9 @@ void Menu::readPackages(std::string parentDir) while ((dptr = readdir(dirp))) { char *c; - LinkApp *link; std::string path; unsigned int i; + struct ParserData *pdata; if (dptr->d_type != DT_REG) continue; @@ -461,16 +465,54 @@ void Menu::readPackages(std::string parentDir) continue; path = parentDir + '/' + dptr->d_name; - link = new LinkApp(gmenu2x, ts, gmenu2x->input, path.c_str(), true); - 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); + pdata = opk_open(path.c_str()); + if (!pdata) { + 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 *str = opk_open_metadata(pdata); + if (!str) + break; + + /* Strip .desktop */ + string metadata(str); + 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(), pdata); + 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(pdata); } closedir(dirp);