1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-12-28 05:45:31 +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
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;

View File

@ -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);

View File

@ -27,6 +27,10 @@
#include <fstream>
#include <unistd.h>
#ifdef HAVE_LIBOPK
#include <opk.h>
#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);