opkg_manager: add class with member to set an update status

This commit is contained in:
2022-01-07 09:23:19 +01:00
parent de9cca01b9
commit e393c87324
2 changed files with 47 additions and 3 deletions

View File

@@ -233,13 +233,17 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey)
if (parent)
parent->hide();
int r = execCmd(actionKey, CShellWindow::VERBOSE | CShellWindow::ACKNOWLEDGE_EVENT);
if (r) {
if (r)
{
/* errno is never set properly, the string is totally useless.
showError(g_Locale->getText(LOCALE_OPKG_FAILURE_UPGRADE), strerror(errno), actionKey);
*/
showError(g_Locale->getText(LOCALE_OPKG_FAILURE_UPGRADE), NULL, actionKey);
} else
}
else
{
installed = true;
}
refreshMenu();
/* I don't think ending up at the last package in the list is a good idea...
g_RCInput->postMsg((neutrino_msg_t) CRCInput::RC_up, 0);
@@ -551,11 +555,14 @@ void COPKGManager::initUpdateMessage(bool enable_message)
f.close();
}
void COPKGManager::setUpdateCheckResult(bool enable_message)
{
std::lock_guard<std::mutex> g(opk_mutex);
checkUpdates(std::string(), enable_message);
handleUpdateFlagFile();
if (num_updates)
initUpdateMessage(enable_message);
else
@@ -563,6 +570,21 @@ void COPKGManager::setUpdateCheckResult(bool enable_message)
}
void COPKGManager::handleUpdateFlagFile()
{
if (file_exists(HAS_PKG_UPDATE_FLAGFILE))
unlink(HAS_PKG_UPDATE_FLAGFILE);
if (num_updates)
{
fstream f;
f.open(HAS_PKG_UPDATE_FLAGFILE, ios::out);
f << num_updates << endl;
f.close();
}
}
bool COPKGManager::checkUpdates(const std::string & package_name, bool show_progress)
{
if (!hasOpkgSupport() || file_exists("/run/opkg.lock"))
@@ -676,6 +698,7 @@ int COPKGManager::showMenu()
//upgrade all installed packages
std::string upd_info = to_string(num_updates) + " " + g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_UPDATES_AVAILABLE);
upgrade_forwarder = new CMenuForwarder(LOCALE_OPKG_UPGRADE, true, upd_info.c_str() , this, pm_cmd[CMD_UPGRADE].c_str(), CRCInput::RC_red);
upgrade_forwarder->OnPaintItem.connect(sigc::bind(sigc::mem_fun(this, &COPKGManager::setUpdateStateIcon2Item), upgrade_forwarder));
upgrade_forwarder->setHint(NEUTRINO_ICON_HINT_SW_UPDATE, LOCALE_MENU_HINT_OPKG_UPGRADE);
menu->addItem(upgrade_forwarder);
@@ -1202,3 +1225,14 @@ bool COPKGManager::isUpgradable(const string& pkg_name)
return true;
return false;
}
void COPKGManagerExtra::setUpdateStateIcon2Item(CMenuItem *item)
{
if (!item)
return;
if (file_exists(HAS_PKG_UPDATE_FLAGFILE))
item->setInfoIconRight(NEUTRINO_ICON_MARKER_UPDATE_AVAILABLE);
else
item->setInfoIconRight(NEUTRINO_ICON_MARKER_DIALOG_OK);
}

View File

@@ -38,8 +38,16 @@
#include <mutex>
#define OPKG_MAX_FEEDS 10
#define HAS_PKG_UPDATE_FLAGFILE "/tmp/.has_pkg_updates"
class COPKGManager : public CMenuTarget
class COPKGManagerExtra
{
public:
// set update status to passed menu item
void setUpdateStateIcon2Item(CMenuItem* item);
};
class COPKGManager : public CMenuTarget, public COPKGManagerExtra
{
private:
struct pkg {
@@ -115,6 +123,7 @@ class COPKGManager : public CMenuTarget
bool isInstalled(const std::string& pkg_name);
bool isUpgradable(const std::string& pkg_name);
void handleUpdateFlagFile();
void initUpdateMessage(bool enable_message = true);
bool removeInfoBarTxt();
std::mutex opk_mutex;
@@ -195,4 +204,5 @@ class COPKGManager : public CMenuTarget
bool installPackage(const std::string& pkg_name, std::string options = std::string(), bool force_configure = false);
bool checkSize(const std::string& pkg_name);
};
#endif