From 4a60aa000dae379f57f5ba0e10f0b8164ee64aa0 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Tue, 9 Oct 2012 01:41:57 +0200 Subject: [PATCH] Load the OPK in the section defined by their "Categories" parameter --- src/linkapp.cpp | 13 ++++++++++++- src/linkapp.h | 4 +++- src/menu.cpp | 10 ++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/linkapp.cpp b/src/linkapp.cpp index d3a7c1d..00f07b2 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -88,9 +88,20 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_, pos = opkMount.rfind('.'); opkMount = opkMount.substr(0, pos); - file = gmenu2x->getHome() + "/sections/" + opkMount; + file = gmenu2x->getHome() + "/sections/"; opkMount = (string) "/mnt/" + opkMount + '/'; + param = opk_read_param(pdata, "Categories"); + if (!param) + ERROR("Missing \"Categories\" parameter\n"); + else { + category = param; + pos = category.find(';'); + if (pos != category.npos) + category = category.substr(0, pos); + file += category + '/' + opkMount; + } + param = opk_read_param(pdata, "Name"); if (!param) ERROR("Missing \"Name\" parameter\n"); diff --git a/src/linkapp.h b/src/linkapp.h index fb19755..096e657 100644 --- a/src/linkapp.h +++ b/src/linkapp.h @@ -49,7 +49,7 @@ private: bool dontleave; #ifdef HAVE_LIBOPK bool isOPK; - std::string opkMount, opkFile; + std::string opkMount, opkFile, category; #endif void start(); @@ -59,6 +59,8 @@ private: public: #ifdef HAVE_LIBOPK + const std::string &getCategory() { return category; } + LinkApp(GMenu2X *gmenu2x, Touchscreen &ts, InputManager &inputMgr, const char* linkfile, bool opk = false); #else diff --git a/src/menu.cpp b/src/menu.cpp index 45a7cd4..ff9c432 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -448,6 +448,7 @@ void Menu::readPackages(std::string parentDir) char *c; LinkApp *link; std::string path; + unsigned int i; if (dptr->d_type != DT_REG) continue; @@ -463,8 +464,13 @@ void Menu::readPackages(std::string parentDir) link = new LinkApp(gmenu2x, ts, gmenu2x->input, path.c_str(), true); link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]); - /* TODO: Read the category from the OPK. */ - links[0].push_back(link); + addSection(link->getCategory()); + for (i = 0; i < sections.size(); i++) { + if (sections[i] == link->getCategory()) { + links[i].push_back(link); + break; + } + } } closedir(dirp);