1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-07-04 21:28:54 +03:00

Update GMenu2X to use the latest libopk v1.0 API

This commit is contained in:
Paul Cercueil 2013-05-26 19:06:53 -04:00
parent 2cef732602
commit c58b3a535e
4 changed files with 136 additions and 123 deletions

View File

@ -33,7 +33,7 @@ SDL_Surface *loadPNG(const std::string &path) {
png_infop info = NULL; png_infop info = NULL;
#ifdef HAVE_LIBOPK #ifdef HAVE_LIBOPK
std::string::size_type pos; std::string::size_type pos;
struct ParserData *pdata = NULL; struct OPK *opk = NULL;
void *buffer = NULL, *param; void *buffer = NULL, *param;
#endif #endif
@ -56,15 +56,24 @@ SDL_Surface *loadPNG(const std::string &path) {
#ifdef HAVE_LIBOPK #ifdef HAVE_LIBOPK
pos = path.find('#'); pos = path.find('#');
if (pos != path.npos) { if (pos != path.npos) {
int ret;
size_t length;
DEBUG("Registering specific callback for icon %s\n", path.c_str()); DEBUG("Registering specific callback for icon %s\n", path.c_str());
pdata = opk_open(path.substr(0, pos).c_str()); opk = opk_open(path.substr(0, pos).c_str());
if (!pdata) { if (!opk) {
ERROR("Unable to open OPK\n"); ERROR("Unable to open OPK\n");
goto cleanup; goto cleanup;
} }
buffer = opk_extract_file(pdata, path.substr(pos + 1).c_str()); ret = opk_extract_file(opk, path.substr(pos + 1).c_str(),
&buffer, &length);
if (ret < 0) {
ERROR("Unable to extract icon from OPK\n");
goto cleanup;
}
param = buffer; param = buffer;
png_set_read_fn(png, &param, __readFromOpk); png_set_read_fn(png, &param, __readFromOpk);
@ -156,8 +165,8 @@ cleanup:
#ifdef HAVE_LIBOPK #ifdef HAVE_LIBOPK
if (buffer) if (buffer)
free(buffer); free(buffer);
if (pdata) if (opk)
opk_close(pdata); opk_close(opk);
#endif #endif
return surface; return surface;

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, struct ParserData *pdata) const char* linkfile, struct OPK *opk)
#else #else
LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_, LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
const char* linkfile) const char* linkfile)
@ -82,11 +82,12 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
#endif #endif
#ifdef HAVE_LIBOPK #ifdef HAVE_LIBOPK
isOPK = !!pdata; isOPK = !!opk;
if (isOPK) { if (isOPK) {
string::size_type pos; string::size_type pos;
const char *key, *val;
char *param; size_t lkey, lval;
int ret;
opkFile = file; opkFile = file;
pos = file.rfind('/'); pos = file.rfind('/');
@ -96,104 +97,101 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
file = gmenu2x->getHome() + "/sections/"; file = gmenu2x->getHome() + "/sections/";
param = opk_read_param(pdata, "Categories"); while ((ret = opk_read_pair(opk, &key, &lkey, &val, &lval))) {
if (!param) if (ret < 0) {
ERROR("Missing \"Categories\" parameter\n"); ERROR("Unable to read meta-data\n");
else { break;
category = param; }
pos = category.find(';');
if (pos != category.npos) char buf[lval + 1];
category = category.substr(0, pos); sprintf(buf, "%.*s", lval, val);
file += category + '/' + opkMount;
if (!strncmp(key, "Categories", lkey)) {
category = buf;
pos = category.find(';');
if (pos != category.npos)
category = category.substr(0, pos);
file += category + '/' + opkMount;
} else if (!strncmp(key, "Name", lkey)) {
title = buf;
} else if (!strncmp(key, "Comment", lkey)) {
description = buf;
#if defined(PLATFORM_A320) || defined(PLATFORM_GCW0)
} else if (!strncmp(key, "Terminal", lkey)) {
consoleApp = !strncmp(val, "true", lval);
#endif
} else if (!strncmp(key, "X-OD-Manual", lkey)) {
manual = buf;
} else if (!strncmp(key, "X-OD-Daemon", lkey)) {
dontleave = !strncmp(val, "true", lval);
} else if (!strncmp(key, "Icon", lkey)) {
/* Read the icon from the OPK only
* if it doesn't exist on the skin */
this->icon = gmenu2x->sc.getSkinFilePath((string) buf + ".png");
if (this->icon.empty())
this->icon = (string) linkfile + '#' + buf + ".png";
iconPath = this->icon;
updateSurfaces();
} else if (!strncmp(key, "Exec", lkey)) {
string tmp = buf;
pos = tmp.find(' ');
exec = tmp.substr(0, pos);
if (pos != tmp.npos) {
unsigned int i;
params = tmp.substr(pos + 1);
for (i = 0; i < sizeof(tokens) / sizeof(tokens[0]); i++) {
if (params.find(tokens[i]) != params.npos) {
selectordir = CARD_ROOT;
break;
}
}
}
continue;
}
#ifdef HAVE_LIBXDGMIME
if (!strncmp(key, "MimeType", lkey)) {
string mimetypes = buf;
while ((pos = mimetypes.find(';')) != mimetypes.npos) {
int nb = 16;
char *extensions[nb];
string mimetype = mimetypes.substr(0, pos);
mimetypes = mimetypes.substr(pos + 1);
nb = xdg_mime_get_extensions_from_mime_type(
mimetype.c_str(), extensions, nb);
while (nb--) {
selectorfilter += (string) extensions[nb] + ',';
free(extensions[nb]);
}
}
/* Remove last comma */
if (!selectorfilter.empty()) {
selectorfilter.erase(selectorfilter.end());
DEBUG("Compatible extensions: %s\n", selectorfilter.c_str());
}
continue;
}
#endif /* HAVE_LIBXDGMIME */
} }
opkMount = (string) "/mnt/" + opkMount + '/'; opkMount = (string) "/mnt/" + opkMount + '/';
param = opk_read_param(pdata, "Name");
if (!param)
ERROR("Missing \"Name\" parameter\n");
else
title = param;
param = opk_read_param(pdata, "Comment");
if (param)
description = param;
/* Read the icon from the OPK only
* if it doesn't exist on the skin */
param = opk_read_param(pdata, "Icon");
if (param) {
this->icon = gmenu2x->sc.getSkinFilePath((string) param + ".png");
if (this->icon.empty())
this->icon = (string) linkfile + '#' + param + ".png";
iconPath = this->icon;
updateSurfaces();
}
param = opk_read_param(pdata, "Exec");
if (!param)
ERROR("Missing \"Exec\" parameter\n");
else {
string tmp = param;
pos = tmp.find(' ');
exec = tmp.substr(0, pos);
if (pos != tmp.npos) {
unsigned int i;
params = tmp.substr(pos + 1);
for (i = 0; i < sizeof(tokens) / sizeof(tokens[0]); i++) {
if (params.find(tokens[i]) != params.npos) {
selectordir = CARD_ROOT;
break;
}
}
}
}
#if defined(PLATFORM_A320) || defined(PLATFORM_GCW0)
param = opk_read_param(pdata, "Terminal");
if (param)
consoleApp = !strcmp(param, "true");
#endif
#ifdef HAVE_LIBXDGMIME
param = opk_read_param(pdata, "MimeType");
if (param) {
string mimetypes = param;
while ((pos = mimetypes.find(';')) != mimetypes.npos) {
int nb = 16;
char *extensions[nb];
string mimetype = mimetypes.substr(0, pos);
mimetypes = mimetypes.substr(pos + 1);
nb = xdg_mime_get_extensions_from_mime_type(
mimetype.c_str(), extensions, nb);
while (nb--) {
selectorfilter += (string) extensions[nb] + ',';
free(extensions[nb]);
}
}
/* Remove last comma */
if (!selectorfilter.empty()) {
selectorfilter.erase(selectorfilter.end());
DEBUG("Compatible extensions: %s\n", selectorfilter.c_str());
}
}
#endif /* HAVE_LIBXDGMIME */
param = opk_read_param(pdata, "X-OD-Manual");
if (param)
manual = param;
param = opk_read_param(pdata, "X-OD-Daemon");
if (param)
dontleave = !strcmp(param, "true");
edited = true; edited = true;
} }
#endif /* HAVE_LIBOPK */ #endif /* HAVE_LIBOPK */
@ -380,24 +378,26 @@ void LinkApp::showManual() {
#ifdef HAVE_LIBOPK #ifdef HAVE_LIBOPK
if (isOPK) { if (isOPK) {
vector<string> readme; vector<string> readme;
char *token, *buf, *ptr; char *token, *ptr;
struct ParserData *pdata; struct OPK *opk;
int err;
void *buf;
size_t len;
pdata = opk_open(opkFile.c_str()); opk = opk_open(opkFile.c_str());
if (!pdata) { if (!opk) {
WARNING("Unable to open OPK to read manual\n"); WARNING("Unable to open OPK to read manual\n");
return; return;
} }
buf = ptr = reinterpret_cast<char *>( err = opk_extract_file(opk, manual.c_str(), &buf, &len);
opk_extract_file(pdata, manual.c_str())); if (err < 0) {
opk_close(pdata);
if (!buf) {
WARNING("Unable to read manual from OPK\n"); WARNING("Unable to read manual from OPK\n");
return; return;
} }
opk_close(opk);
ptr = (char *) buf;
while((token = strchr(ptr, '\n'))) { while((token = strchr(ptr, '\n'))) {
*token = '\0'; *token = '\0';

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, struct ParserData *pdata = NULL); const char* linkfile, struct OPK *opk = 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

@ -452,7 +452,7 @@ void Menu::readPackages(std::string parentDir)
char *c; char *c;
std::string path; std::string path;
unsigned int i; unsigned int i;
struct ParserData *pdata; struct OPK *opk;
if (dptr->d_type != DT_REG) if (dptr->d_type != DT_REG)
continue; continue;
@ -472,8 +472,8 @@ void Menu::readPackages(std::string parentDir)
path = parentDir + '/' + dptr->d_name; path = parentDir + '/' + dptr->d_name;
pdata = opk_open(path.c_str()); opk = opk_open(path.c_str());
if (!pdata) { if (!opk) {
ERROR("Unable to open OPK %s\n", path.c_str()); ERROR("Unable to open OPK %s\n", path.c_str());
continue; continue;
} }
@ -484,12 +484,16 @@ void Menu::readPackages(std::string parentDir)
for (;;) { for (;;) {
string::size_type pos; string::size_type pos;
const char *str = opk_open_metadata(pdata); const char *name;
if (!str) int ret = opk_open_metadata(opk, &name);
if (ret < 0) {
ERROR("Error while loading meta-data\n");
break;
} else if (!ret)
break; break;
/* Strip .desktop */ /* Strip .desktop */
string metadata(str); string metadata(name);
pos = metadata.rfind('.'); pos = metadata.rfind('.');
metadata = metadata.substr(0, pos); metadata = metadata.substr(0, pos);
@ -506,7 +510,7 @@ void Menu::readPackages(std::string parentDir)
if (!has_metadata) if (!has_metadata)
break; break;
link = new LinkApp(gmenu2x, ts, gmenu2x->input, path.c_str(), pdata); link = new LinkApp(gmenu2x, ts, gmenu2x->input, path.c_str(), opk);
link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]); link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]);
addSection(link->getCategory()); addSection(link->getCategory());
@ -518,7 +522,7 @@ void Menu::readPackages(std::string parentDir)
} }
} }
opk_close(pdata); opk_close(opk);
} }
closedir(dirp); closedir(dirp);