opkg_manager: show package, version and description separated

Origin commit data
------------------
Commit: ea07083651
Author: Thilo Graf <dbt@novatux.de>
Date: 2023-03-07 (Tue, 07 Mar 2023)
This commit is contained in:
2023-03-07 23:20:43 +01:00
committed by vanhofen
parent 5afe7b1dc8
commit 9d4aa75b96
2 changed files with 60 additions and 27 deletions

View File

@@ -497,7 +497,7 @@ void COPKGManager::updateMenu()
if (!isPermittedPackage(it->second.name)) if (!isPermittedPackage(it->second.name))
continue; continue;
it->second.forwarder->iconName_Info_right = ""; it->second.forwarder->iconName_Info_right = NEUTRINO_ICON_MARKER_DOWNLOAD_LATER;
it->second.forwarder->setActive(true); it->second.forwarder->setActive(true);
if (it->second.upgradable) { if (it->second.upgradable) {
it->second.forwarder->iconName_Info_right = NEUTRINO_ICON_MARKER_UPDATE_AVAILABLE; it->second.forwarder->iconName_Info_right = NEUTRINO_ICON_MARKER_UPDATE_AVAILABLE;
@@ -739,7 +739,7 @@ int COPKGManager::showMenu()
if (!isPermittedPackage(it->second.name)) if (!isPermittedPackage(it->second.name))
continue; continue;
it->second.forwarder = new CMenuForwarder(it->second.desc, true, NULL , this, it->second.name.c_str()); it->second.forwarder = new CMenuForwarder(it->second.name, true, it->second.version.c_str() , this, it->second.name.c_str());
it->second.forwarder->setHint("", it->second.desc); it->second.forwarder->setHint("", it->second.desc);
menu->addItem(it->second.forwarder); menu->addItem(it->second.forwarder);
pkg_vec.push_back(&it->second); pkg_vec.push_back(&it->second);
@@ -829,9 +829,16 @@ string COPKGManager::getInfoDir()
return ""; return "";
} }
string COPKGManager::getPkgDescription(std::string pkgName, std::string pkgDesc) string COPKGManager::getPkgDetails(std::string pkgName, std::string pkgKeyword, std::string pkgDesc)
{ {
if (pkgKeyword.empty())
{
dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] pkgKeyword for [%s] not defined, missing value in parameter pkgName\n", __func__, __LINE__, pkgName.c_str());
return "";
}
static string infoPath; static string infoPath;
string res = "";
if (infoPath.empty()) if (infoPath.empty())
infoPath = getInfoDir(); infoPath = getInfoDir();
if (infoPath.empty()) if (infoPath.empty())
@@ -853,40 +860,31 @@ string COPKGManager::getPkgDescription(std::string pkgName, std::string pkgDesc)
return pkgDesc; return pkgDesc;
} }
char buf[512]; char buf[512];
string package, version, description;
while (fgets(buf, sizeof(buf), fd)) { while (fgets(buf, sizeof(buf), fd)) {
if (buf[0] == ' ') if (buf[0] == ' ')
continue; continue;
string line(buf); string line(buf);
trim(line, " "); trim(line, " ");
string tmp; string tmp;
/* When pkgDesc is empty, return description only for CMD_INFO */ string key = pkgKeyword + ":";
if (!pkgDesc.empty()) { tmp = getKeyInfo(line, key, " ");
tmp = getKeyInfo(line, "Package:", " ");
if (!tmp.empty())
package = tmp;
tmp = getKeyInfo(line, "Version:", " ");
if (!tmp.empty())
version = tmp;
}
tmp = getKeyInfo(line, "Description:", " ");
if (!tmp.empty()) if (!tmp.empty())
description = tmp; res = tmp;
} }
fclose(fd); fclose(fd);
if (pkgDesc.empty()) return res;
return description;
string desc = package + " - " + version;
if (!description.empty())
desc += " - " + description;
return desc;
} }
return pkgDesc; return pkgDesc;
} }
string COPKGManager::getPkgDescription(std::string pkgName, std::string pkgDesc)
{
if (!pkgDesc.empty())
return pkgDesc;
return getPkgDetails(pkgName, "Description", pkgDesc);
}
void COPKGManager::getPkgData(const int pkg_content_id) void COPKGManager::getPkgData(const int pkg_content_id)
{ {
dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] executing %s\n", __func__, __LINE__, pm_cmd[pkg_content_id].c_str()); dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] executing %s\n", __func__, __LINE__, pm_cmd[pkg_content_id].c_str());
@@ -942,19 +940,55 @@ void COPKGManager::getPkgData(const int pkg_content_id)
pkg_map[name] = pkg(name, line, line); pkg_map[name] = pkg(name, line, line);
map<string, struct pkg>::iterator it = pkg_map.find(name); map<string, struct pkg>::iterator it = pkg_map.find(name);
if (it != pkg_map.end()) if (it != pkg_map.end())
it->second.desc = getPkgDescription(name, line); {
it->second.name = name;
it->second.version = "";
it->second.desc = "";
std::string str_tmp = line, del = " - ";
size_t pos1 = str_tmp.find(del);
if (pos1 == std::string::npos)
{
name = str_tmp;
}else
{
name = str_tmp.substr(0, pos1);
str_tmp.erase(0, pos1 + del.length());
size_t pos2 = str_tmp.find(del);
if (pos2 == std::string::npos)
{
it->second.version = str_tmp;
}
else
{
it->second.version = str_tmp.substr(0, pos2);
it->second.desc = str_tmp.substr(pos2 + del.length());
}
}
}
break; break;
} }
case CMD_LIST_INSTALLED: { case CMD_LIST_INSTALLED: {
map<string, struct pkg>::iterator it = pkg_map.find(name); map<string, struct pkg>::iterator it = pkg_map.find(name);
if (it != pkg_map.end()) if (it != pkg_map.end())
{
it->second.installed = true; it->second.installed = true;
std::string del = " - ";
std::size_t delpos = line.find(del);
it->second.version = line.substr(delpos + del.length());
}
break; break;
} }
case CMD_LIST_UPGRADEABLE: { case CMD_LIST_UPGRADEABLE: {
map<string, struct pkg>::iterator it = pkg_map.find(name); map<string, struct pkg>::iterator it = pkg_map.find(name);
if (it != pkg_map.end()) if (it != pkg_map.end())
{
it->second.upgradable = true; it->second.upgradable = true;
std::string del = " - ";
std::size_t delpos = line.find(del);
it->second.version = line.substr(delpos + del.length());
}
break; break;
} }
default: default:

View File

@@ -186,9 +186,8 @@ class COPKGManager : public CMenuTarget, public COPKGManagerExtra
void handleShellOutput(std::string* cur_line, int* res, bool* ok); void handleShellOutput(std::string* cur_line, int* res, bool* ok);
std::string getInfoDir(); std::string getInfoDir();
std::string getPkgDescription(std::string pkgName, std::string pkgDesc=""); std::string getPkgDetails(std::string pkgName, std::string pkgKeyword, std::string pkgDesc = "");
std::string getPkgDescription(std::string pkgName, std::string pkgDesc = "");
int num_updates; int num_updates;
public: public: