mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-29 18:21:54 +02:00
Update GMenu2X to use the latest libopk v1.0 API
This commit is contained in:
parent
2cef732602
commit
c58b3a535e
@ -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, ¶m, __readFromOpk);
|
png_set_read_fn(png, ¶m, __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;
|
||||||
|
110
src/linkapp.cpp
110
src/linkapp.cpp
@ -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,45 +97,51 @@ 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;
|
}
|
||||||
|
|
||||||
|
char buf[lval + 1];
|
||||||
|
sprintf(buf, "%.*s", lval, val);
|
||||||
|
|
||||||
|
if (!strncmp(key, "Categories", lkey)) {
|
||||||
|
category = buf;
|
||||||
|
|
||||||
pos = category.find(';');
|
pos = category.find(';');
|
||||||
if (pos != category.npos)
|
if (pos != category.npos)
|
||||||
category = category.substr(0, pos);
|
category = category.substr(0, pos);
|
||||||
file += category + '/' + opkMount;
|
file += category + '/' + opkMount;
|
||||||
}
|
|
||||||
|
|
||||||
opkMount = (string) "/mnt/" + opkMount + '/';
|
} else if (!strncmp(key, "Name", lkey)) {
|
||||||
|
title = buf;
|
||||||
|
|
||||||
param = opk_read_param(pdata, "Name");
|
} else if (!strncmp(key, "Comment", lkey)) {
|
||||||
if (!param)
|
description = buf;
|
||||||
ERROR("Missing \"Name\" parameter\n");
|
|
||||||
else
|
|
||||||
title = param;
|
|
||||||
|
|
||||||
param = opk_read_param(pdata, "Comment");
|
#if defined(PLATFORM_A320) || defined(PLATFORM_GCW0)
|
||||||
if (param)
|
} else if (!strncmp(key, "Terminal", lkey)) {
|
||||||
description = param;
|
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
|
/* Read the icon from the OPK only
|
||||||
* if it doesn't exist on the skin */
|
* if it doesn't exist on the skin */
|
||||||
param = opk_read_param(pdata, "Icon");
|
this->icon = gmenu2x->sc.getSkinFilePath((string) buf + ".png");
|
||||||
if (param) {
|
|
||||||
this->icon = gmenu2x->sc.getSkinFilePath((string) param + ".png");
|
|
||||||
if (this->icon.empty())
|
if (this->icon.empty())
|
||||||
this->icon = (string) linkfile + '#' + param + ".png";
|
this->icon = (string) linkfile + '#' + buf + ".png";
|
||||||
iconPath = this->icon;
|
iconPath = this->icon;
|
||||||
updateSurfaces();
|
updateSurfaces();
|
||||||
}
|
|
||||||
|
|
||||||
param = opk_read_param(pdata, "Exec");
|
} else if (!strncmp(key, "Exec", lkey)) {
|
||||||
if (!param)
|
string tmp = buf;
|
||||||
ERROR("Missing \"Exec\" parameter\n");
|
|
||||||
else {
|
|
||||||
string tmp = param;
|
|
||||||
pos = tmp.find(' ');
|
pos = tmp.find(' ');
|
||||||
exec = tmp.substr(0, pos);
|
exec = tmp.substr(0, pos);
|
||||||
|
|
||||||
@ -150,18 +157,13 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(PLATFORM_A320) || defined(PLATFORM_GCW0)
|
|
||||||
param = opk_read_param(pdata, "Terminal");
|
|
||||||
if (param)
|
|
||||||
consoleApp = !strcmp(param, "true");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_LIBXDGMIME
|
#ifdef HAVE_LIBXDGMIME
|
||||||
param = opk_read_param(pdata, "MimeType");
|
if (!strncmp(key, "MimeType", lkey)) {
|
||||||
if (param) {
|
string mimetypes = buf;
|
||||||
string mimetypes = param;
|
|
||||||
|
|
||||||
while ((pos = mimetypes.find(';')) != mimetypes.npos) {
|
while ((pos = mimetypes.find(';')) != mimetypes.npos) {
|
||||||
int nb = 16;
|
int nb = 16;
|
||||||
@ -183,17 +185,13 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
|
|||||||
selectorfilter.erase(selectorfilter.end());
|
selectorfilter.erase(selectorfilter.end());
|
||||||
DEBUG("Compatible extensions: %s\n", selectorfilter.c_str());
|
DEBUG("Compatible extensions: %s\n", selectorfilter.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
#endif /* HAVE_LIBXDGMIME */
|
#endif /* HAVE_LIBXDGMIME */
|
||||||
|
}
|
||||||
|
|
||||||
param = opk_read_param(pdata, "X-OD-Manual");
|
opkMount = (string) "/mnt/" + opkMount + '/';
|
||||||
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';
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
20
src/menu.cpp
20
src/menu.cpp
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user