opkg_manager: simplify generation of info, called with info button

This commit is contained in:
2023-03-07 10:34:01 +01:00
parent 60a0049f47
commit 84339d1e8c

View File

@@ -161,41 +161,42 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey)
return ret; return ret;
} }
int selected = menu->getSelected() - menu_offset; int selected = menu->getSelected()/* - menu_offset*/;
string pkg_name = menu->getItem(selected)->getName();
if (expert_mode && actionKey == "rc_blue") { if (expert_mode && actionKey == "rc_blue") {
if (selected < 0 || selected >= (int) pkg_vec.size() || !pkg_vec[selected]->installed) if (selected < 0 || selected >= (int) pkg_vec.size() || !pkg_vec[selected]->installed)
return menu_return::RETURN_NONE; return menu_return::RETURN_NONE;
char loc[200]; char loc[200];
snprintf(loc, sizeof(loc), g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_REMOVE), pkg_vec[selected]->name.c_str()); snprintf(loc, sizeof(loc), g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_REMOVE), pkg_name.c_str());
if (ShowMsg(LOCALE_OPKG_TITLE, loc, CMsgBox::mbrCancel, CMsgBox::mbYes | CMsgBox::mbCancel) != CMsgBox::mbrCancel) { if (ShowMsg(LOCALE_OPKG_TITLE, loc, CMsgBox::mbrCancel, CMsgBox::mbYes | CMsgBox::mbCancel) != CMsgBox::mbrCancel) {
if (parent) if (parent)
parent->hide(); parent->hide();
execCmd(pm_cmd[CMD_REMOVE] + pkg_vec[selected]->name, CShellWindow::VERBOSE | CShellWindow::ACKNOWLEDGE_EVENT); execCmd(pm_cmd[CMD_REMOVE] + pkg_name, CShellWindow::VERBOSE | CShellWindow::ACKNOWLEDGE_EVENT);
refreshMenu(); refreshMenu();
} }
return res; return res;
} }
if (actionKey == "rc_info") { if (actionKey == "rc_info") {
if (selected < 0 || selected >= (int) pkg_vec.size()){ for (size_t i = 0; i < pkg_vec.size(); i++)
DisplayInfoMessage("No information available! Please first select a package!"); {
return menu_return::RETURN_NONE; if (pkg_vec[i]->name == pkg_name)
} {
//show package info... string infostr = getPkgInfo(pkg_name, "", pkg_vec[i]->installed);
bool is_installed = pkg_vec[selected]->installed;
string infostr = getPkgInfo(pkg_vec[selected]->name, "", is_installed /*status or info*/);
//if available, generate a readable string for installation time //if available, generate a readable string for installation time
if (is_installed){ if (pkg_vec[i]->installed){
string tstr = getPkgInfo(pkg_vec[selected]->name, "Installed-Time", is_installed); string tstr = getPkgInfo(pkg_name, "Installed-Time", true);
stringstream sstr(tstr); stringstream sstr(tstr);
time_t tval; sstr >> tval; time_t tval; sstr >> tval;
string newstr = asctime(localtime(&tval)); string newstr = asctime(localtime(&tval));
infostr = str_replace(tstr, newstr, infostr); infostr = str_replace(tstr, newstr, infostr);
}
DisplayInfoMessage(infostr.c_str());
break;
}
} }
DisplayInfoMessage(infostr.c_str());
return res; return res;
} }
if (actionKey == "rc_yellow") { if (actionKey == "rc_yellow") {