1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-26 07:59:42 +02:00

Enable support for multiple .desktop for one platform inside OPKs

This commit is contained in:
Paul Cercueil 2012-11-29 23:44:58 -03:00
parent 6629a63871
commit efdf766102
3 changed files with 54 additions and 47 deletions

View File

@ -57,7 +57,7 @@ static const char *tokens[] = { "%f", "%F", "%u", "%U", };
#ifdef HAVE_LIBOPK #ifdef HAVE_LIBOPK
LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_, LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
const char* linkfile, bool opk) const char* linkfile, struct ParserData *pdata)
#else #else
LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_, LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
const char* linkfile) const char* linkfile)
@ -80,45 +80,11 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
#endif #endif
#ifdef HAVE_LIBOPK #ifdef HAVE_LIBOPK
isOPK = opk; isOPK = !!pdata;
if (opk) { if (isOPK) {
string::size_type pos; string::size_type pos;
struct ParserData *pdata = opk_open(linkfile);
char *param; 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; opkFile = file;
pos = file.rfind('/'); pos = file.rfind('/');
@ -225,7 +191,6 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
dontleave = !strcmp(param, "true"); dontleave = !strcmp(param, "true");
edited = true; edited = true;
opk_close(pdata);
} }
#endif /* HAVE_LIBOPK */ #endif /* HAVE_LIBOPK */
@ -252,7 +217,7 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
setAliasFile( value ); setAliasFile( value );
} else } else
#ifdef HAVE_LIBOPK #ifdef HAVE_LIBOPK
if (!opk) { if (!isOPK) {
#endif #endif
if (name == "title") { if (name == "title") {
title = value; title = value;

View File

@ -63,7 +63,7 @@ public:
bool isOpk() { return isOPK; } bool isOpk() { return isOPK; }
LinkApp(GMenu2X *gmenu2x, Touchscreen &ts, InputManager &inputMgr, LinkApp(GMenu2X *gmenu2x, Touchscreen &ts, InputManager &inputMgr,
const char* linkfile, bool opk = false); const char* linkfile, struct ParserData *pdata = NULL);
#else #else
LinkApp(GMenu2X *gmenu2x, Touchscreen &ts, InputManager &inputMgr, LinkApp(GMenu2X *gmenu2x, Touchscreen &ts, InputManager &inputMgr,
const char* linkfile); const char* linkfile);

View File

@ -27,6 +27,10 @@
#include <fstream> #include <fstream>
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_LIBOPK
#include <opk.h>
#endif
#include "gmenu2x.h" #include "gmenu2x.h"
#include "linkapp.h" #include "linkapp.h"
#include "menu.h" #include "menu.h"
@ -446,9 +450,9 @@ void Menu::readPackages(std::string parentDir)
while ((dptr = readdir(dirp))) { while ((dptr = readdir(dirp))) {
char *c; char *c;
LinkApp *link;
std::string path; std::string path;
unsigned int i; unsigned int i;
struct ParserData *pdata;
if (dptr->d_type != DT_REG) if (dptr->d_type != DT_REG)
continue; continue;
@ -461,16 +465,54 @@ void Menu::readPackages(std::string parentDir)
continue; continue;
path = parentDir + '/' + dptr->d_name; 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()); pdata = opk_open(path.c_str());
for (i = 0; i < sections.size(); i++) { if (!pdata) {
if (sections[i] == link->getCategory()) { ERROR("Unable to open OPK %s\n", path.c_str());
links[i].push_back(link); 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; 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); closedir(dirp);