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

LinkApp: Added support for reading OPK packages.

This commit is contained in:
Paul Cercueil 2012-10-07 21:50:07 +02:00
parent e3837fce68
commit 61d22e26e6
2 changed files with 119 additions and 29 deletions

View File

@ -41,11 +41,20 @@
#include <linux/vt.h> #include <linux/vt.h>
#endif #endif
#ifdef HAVE_LIBOPK
#include <opk.h>
#endif
using fastdelegate::MakeDelegate; using fastdelegate::MakeDelegate;
using namespace std; using namespace std;
#ifdef HAVE_LIBOPK
LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
const char* linkfile, bool opk)
#else
LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_, LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
const char* linkfile) const char* linkfile)
#endif
: Link(gmenu2x_, ts, MakeDelegate(this, &LinkApp::start)) : Link(gmenu2x_, ts, MakeDelegate(this, &LinkApp::start))
, inputMgr(inputMgr_) , inputMgr(inputMgr_)
{ {
@ -61,6 +70,66 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
consoleApp = false; consoleApp = false;
#endif #endif
#ifdef HAVE_LIBOPK
isOPK = opk;
if (opk) {
struct ParserData *pdata = openMetadata(linkfile);
char *param;
if (!pdata) {
ERROR("Unable to initialize libopk\n");
return;
}
file = linkfile;
param = readParam(pdata, "Name");
if (!param)
ERROR("Missing \"Name\" parameter\n");
else
title = param;
param = readParam(pdata, "Comment");
if (param)
description = param;
/* Read the icon from the OPK only
* if it doesn't exist on the skin */
param = readParam(pdata, "Icon");
if (param) {
this->icon = gmenu2x->sc.getSkinFilePath((string) param + ".png");
if (this->icon.empty())
this->icon = (string) linkfile + '#' + param + ".png";
iconSurface = gmenu2x->sc[this->icon];
}
if (iconPath.empty())
searchIcon();
param = readParam(pdata, "Exec");
if (!param)
ERROR("Missing \"Exec\" parameter\n");
else
exec = param;
#ifdef PLATFORM_DINGUX
param = readParam(pdata, "Terminal");
if (param)
consoleApp = !strcmp(param, "true");
#endif
param = readParam(pdata, "X-OD-Manual");
if (param)
manual = param;
param = readParam(pdata, "X-OD-Daemon");
if (param)
dontleave = !strcmp(param, "true");
edited = false;
closeMetadata(pdata);
}
#endif /* HAVE_LIBOPK */
string line; string line;
ifstream infile (linkfile, ios_base::in); ifstream infile (linkfile, ios_base::in);
while (getline(infile, line, '\n')) { while (getline(infile, line, '\n')) {
@ -71,23 +140,31 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
string::size_type position = line.find("="); string::size_type position = line.find("=");
string name = trim(line.substr(0,position)); string name = trim(line.substr(0,position));
string value = trim(line.substr(position+1)); string value = trim(line.substr(position+1));
if (name == "title") { #ifdef HAVE_LIBOPK
title = value; if (!opk) {
} else if (name == "description") { #endif
description = value; if (name == "title") {
} else if (name == "icon") { title = value;
setIcon(value); } else if (name == "description") {
} else if (name == "exec") { description = value;
exec = value; } else if (name == "icon") {
} else if (name == "params") { setIcon(value);
params = value; } else if (name == "exec") {
} else if (name == "manual") { exec = value;
manual = value; } else if (name == "params") {
} else if (name == "dontleave") { params = value;
if (value=="true") dontleave = true; } else if (name == "manual") {
manual = value;
} else if (name == "dontleave") {
if (value=="true") dontleave = true;
#ifdef PLATFORM_DINGUX #ifdef PLATFORM_DINGUX
} else if (name == "consoleapp") { } else if (name == "consoleapp") {
if (value == "true") consoleApp = true; if (value == "true") consoleApp = true;
#endif
} else if (name == "selectorfilter") {
setSelectorFilter( value );
#ifdef HAVE_LIBOPK
}
#endif #endif
} else if (name == "clock") { } else if (name == "clock") {
setClock( atoi(value.c_str()) ); setClock( atoi(value.c_str()) );
@ -95,8 +172,6 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
setSelectorDir( value ); setSelectorDir( value );
} else if (name == "selectorbrowser") { } else if (name == "selectorbrowser") {
if (value=="true") selectorbrowser = true; if (value=="true") selectorbrowser = true;
} else if (name == "selectorfilter") {
setSelectorFilter( value );
} else if (name == "selectorscreens") { } else if (name == "selectorscreens") {
setSelectorScreens( value ); setSelectorScreens( value );
} else if (name == "selectoraliases") { } else if (name == "selectoraliases") {
@ -162,22 +237,28 @@ bool LinkApp::save() {
ofstream f(file.c_str()); ofstream f(file.c_str());
if (f.is_open()) { if (f.is_open()) {
if (title!="" ) f << "title=" << title << endl; #ifdef HAVE_LIBOPK
if (description!="" ) f << "description=" << description << endl; if (!isOPK) {
if (icon!="" ) f << "icon=" << icon << endl; #endif
if (exec!="" ) f << "exec=" << exec << endl; if (title!="" ) f << "title=" << title << endl;
if (params!="" ) f << "params=" << params << endl; if (description!="" ) f << "description=" << description << endl;
if (manual!="" ) f << "manual=" << manual << endl; if (icon!="" ) f << "icon=" << icon << endl;
if (exec!="" ) f << "exec=" << exec << endl;
if (params!="" ) f << "params=" << params << endl;
if (manual!="" ) f << "manual=" << manual << endl;
if (dontleave ) f << "dontleave=true" << endl;
#ifdef PLATFORM_DINGUX
if (consoleApp ) f << "consoleapp=true" << endl;
#endif
if (selectorfilter!="" ) f << "selectorfilter=" << selectorfilter << endl;
#ifdef HAVE_LIBOPK
}
#endif
if (iclock!=0 ) f << "clock=" << iclock << endl; if (iclock!=0 ) f << "clock=" << iclock << endl;
if (selectordir!="" ) f << "selectordir=" << selectordir << endl; if (selectordir!="" ) f << "selectordir=" << selectordir << endl;
if (selectorbrowser ) f << "selectorbrowser=true" << endl; if (selectorbrowser ) f << "selectorbrowser=true" << endl;
if (selectorfilter!="" ) f << "selectorfilter=" << selectorfilter << endl;
if (selectorscreens!="") f << "selectorscreens=" << selectorscreens << endl; if (selectorscreens!="") f << "selectorscreens=" << selectorscreens << endl;
if (aliasfile!="" ) f << "selectoraliases=" << aliasfile << endl; if (aliasfile!="" ) f << "selectoraliases=" << aliasfile << endl;
if (dontleave ) f << "dontleave=true" << endl;
#ifdef PLATFORM_DINGUX
if (consoleApp ) f << "consoleapp=true" << endl;
#endif
f.close(); f.close();
sync(); sync();
return true; return true;

View File

@ -47,6 +47,9 @@ private:
std::string file; std::string file;
bool dontleave; bool dontleave;
#ifdef HAVE_LIBOPK
bool isOPK;
#endif
void start(); void start();
void launch( void launch(
@ -54,8 +57,14 @@ private:
const std::string &selectedDir = ""); const std::string &selectedDir = "");
public: public:
#ifdef HAVE_LIBOPK
LinkApp(GMenu2X *gmenu2x, Touchscreen &ts, InputManager &inputMgr,
const char* linkfile, bool opk = false);
#else
LinkApp(GMenu2X *gmenu2x, Touchscreen &ts, InputManager &inputMgr, LinkApp(GMenu2X *gmenu2x, Touchscreen &ts, InputManager &inputMgr,
const char* linkfile); const char* linkfile);
#endif
virtual const std::string &searchIcon(); virtual const std::string &searchIcon();
#ifdef PLATFORM_DINGUX #ifdef PLATFORM_DINGUX