From 7289bcfd67f45174232b3a79c0d46e54b839d8cc Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Sat, 10 Apr 2021 15:51:30 +0200 Subject: [PATCH] opkg_manager: vizualize available package updates --- data/locale/deutsch.locale | 2 +- data/locale/english.locale | 2 +- src/gui/opkg_manager.cpp | 106 +++++++++++++++++++++++++------------ src/gui/opkg_manager.h | 11 ++-- 4 files changed, 83 insertions(+), 38 deletions(-) diff --git a/data/locale/deutsch.locale b/data/locale/deutsch.locale index acccaeb01..9a1188782 100644 --- a/data/locale/deutsch.locale +++ b/data/locale/deutsch.locale @@ -2253,7 +2253,7 @@ opkg.install.local.package Installiere lokales Paket opkg.messagebox.reinstall %s erneut installieren? opkg.messagebox.remove %s entfernen? opkg.messagebox.size.error Nicht genügend freier Speicher für Paketinstallation verfügbar! -opkg.messagebox.updates.available Aktualisierung(en) verfügbar! +opkg.messagebox.updates.available Paket-Aktualisierung(en) verfügbar! opkg.success.install Installation erfolgreich!\nNeustart von Neutrino kann erforderlich sein. Jetzt neu starten? opkg.title Paketverwaltung opkg.update.check Prüfe auf Updates ... diff --git a/data/locale/english.locale b/data/locale/english.locale index c3b3bc1be..3d7ee2f3e 100644 --- a/data/locale/english.locale +++ b/data/locale/english.locale @@ -2253,7 +2253,7 @@ opkg.install.local.package Install local package opkg.messagebox.reinstall Re-install %s? opkg.messagebox.remove Remove %s? opkg.messagebox.size.error Not enough free memory available for this package! -opkg.messagebox.updates.available Update(s) available! +opkg.messagebox.updates.available Package update(s) available! opkg.success.install Install successful!\n restart of Neutrino might be required. Restart now? opkg.title Package Management opkg.update.check Checking for updates ... diff --git a/src/gui/opkg_manager.cpp b/src/gui/opkg_manager.cpp index de869efeb..bef1741f8 100644 --- a/src/gui/opkg_manager.cpp +++ b/src/gui/opkg_manager.cpp @@ -1,11 +1,11 @@ -/* + /* Based up Neutrino-GUI - Tuxbox-Project Copyright (C) 2001 by Steffen Hehn 'McClean' OPKG-Manager Class for Neutrino-GUI Implementation: - Copyright (C) 2012-2018 T. Graf 'dbt' + Copyright (C) 2012-2020 T. Graf 'dbt' www.dbox2-tuning.net Adaptions: @@ -34,7 +34,7 @@ #endif #include "opkg_manager.h" -#include +#include "widget/termwindow.h" /* hack, so we don't have to change all code below */ #define CShellWindow CTermWindow @@ -42,14 +42,14 @@ #include #include -#include -#include +#include "widget/icons.h" +#include "widget/msgbox.h" -#include -#include -#include +#include "widget/progresswindow.h" +#include "widget/hintbox.h" +#include "widget/keyboard_input.h" #include -#include +#include "filebrowser.h" #include #include #include @@ -87,6 +87,8 @@ */ #define SYSTEM_UPDATE "system-update" +#define INFOBAR_TXT_FILE "/tmp/infobar.txt" + using namespace std; enum @@ -169,6 +171,10 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey) int ret = showMenu(); saveConfig(); CFileHelpers::removeDir(OPKG_TMP_DIR); + + if (!num_updates) + removeInfoBarTxt(); + return ret; } int selected = menu->getSelected() - menu_offset; @@ -235,7 +241,7 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey) */ *local_dir = fileBrowser.getCurrentDir(); - refreshMenu(); + refreshMenu(); } return res; } @@ -457,9 +463,55 @@ void COPKGManager::updateMenu() } } +bool COPKGManager::removeInfoBarTxt() +{ + if (file_exists(INFOBAR_TXT_FILE)) + { + //ensure remove infobar.txt with relevant content. + std::string txt = readFile(INFOBAR_TXT_FILE); + std::string update_text = g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_UPDATES_AVAILABLE); + std::size_t found = txt.find(update_text); + if (found != std::string::npos) + { + unlink(INFOBAR_TXT_FILE); + return true; + } + } + return false; +} + +void COPKGManager::initUpdateMessage(bool enable_message) +{ + std::string update_count = to_string(num_updates) + " "; + std::string update_text = g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_UPDATES_AVAILABLE); + std::string update_msg = update_count + update_text; + + dprintf(DEBUG_NORMAL,"\033[32m[COPKGManager] [%s - %d] %s...\033[0m\n", __func__, __LINE__, update_msg.c_str()); + + if (enable_message && !removeInfoBarTxt()) + DisplayInfoMessage(update_msg.c_str()); + + fstream f; + f.open(INFOBAR_TXT_FILE, ios::out); + f << update_msg << endl; + f.close(); +} + +void COPKGManager::setUpdateCheckResult(bool enable_message) +{ + std::lock_guard g(opk_mutex); + + checkUpdates(std::string(), enable_message); + if (num_updates) + initUpdateMessage(enable_message); + else + removeInfoBarTxt(); +} + + bool COPKGManager::checkUpdates(const std::string & package_name, bool show_progress) { - if (!hasOpkgSupport()) + if (!hasOpkgSupport() || file_exists("/run/opkg.lock")) return false; silent = !show_progress; @@ -497,11 +549,11 @@ bool COPKGManager::checkUpdates(const std::string & package_name, bool show_prog if (it->second.upgradable){ dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Update packages available for...%s\n", __func__, __LINE__, it->second.name.c_str()); - if (!package_name.empty() && package_name == it->second.name){ - ret = true; - }else - ret = true; - num_updates++; + if (!package_name.empty() && package_name == it->second.name) + num_updates = 1; + else + num_updates++; + ret = true; } i++; } @@ -544,6 +596,7 @@ int COPKGManager::doUpdate() DisplayErrorMessage(msg.c_str()); return r; } + return 0; } @@ -553,23 +606,10 @@ void COPKGManager::refreshMenu() { updateMenu(); } - -void COPKGManager::showUpdateCheckResult() -{ - checkUpdates(); - - if (num_updates) - { - std::string update_msg = to_string(num_updates) + " "; - update_msg += g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_UPDATES_AVAILABLE); - DisplayInfoMessage(update_msg.c_str()); - } -} - int COPKGManager::showMenu() { installed = false; - showUpdateCheckResult(); + setUpdateCheckResult(true); #if 0 getPkgData(OM_LIST); getPkgData(OM_LIST_UPGRADEABLE); @@ -625,7 +665,7 @@ int COPKGManager::showMenu() //handling after successful installation string exit_action = ""; if (!has_err && installed){ - /*! + /* Show a success message only if restart/reboot is required and user should decide what to do or not. NOTE: marker file should be generated by opkg package itself (eg. with preinstall scripts), so it's controlled by the package maintainer! @@ -706,7 +746,7 @@ string COPKGManager::getPkgDescription(std::string pkgName, std::string pkgDesc) if (infoPath.empty()) infoPath = getInfoDir(); if (infoPath.empty()) - return pkgDesc; + return pkgDesc; string infoFile = infoPath + "/" + pkgName + ".control"; if (file_exists(infoFile.c_str())) { @@ -917,7 +957,7 @@ int COPKGManager::execCmd(const char *cmdstr, int verbose_mode) sl1 = sigc::mem_fun(*this, &COPKGManager::showErr); shell.OnResultError.connect(sl1); #endif - shell.exec(); + shell.exec(); return res; } diff --git a/src/gui/opkg_manager.h b/src/gui/opkg_manager.h index cc693fa8c..eb7766e88 100644 --- a/src/gui/opkg_manager.h +++ b/src/gui/opkg_manager.h @@ -5,7 +5,7 @@ OPKG-Manager Class for Neutrino-GUI Implementation: - Copyright (C) 2012-2015 T. Graf 'dbt' + Copyright (C) 2012-2020 T. Graf 'dbt' www.dbox2-tuning.net Adaptions: @@ -36,6 +36,7 @@ #include #include #include +#include #define OPKG_MAX_FEEDS 10 @@ -107,7 +108,10 @@ class COPKGManager : public CMenuTarget std::string getBlankPkgName(const std::string& line); bool isInstalled(const std::string& pkg_name); bool isUpgradable(const std::string& pkg_name); - void showUpdateCheckResult(); + + void initUpdateMessage(bool enable_message = true); + bool removeInfoBarTxt(); + std::mutex opk_mutex; /*! * Gets an info from opkg command info or status from a package via keywords as std::string @@ -172,7 +176,8 @@ class COPKGManager : public CMenuTarget int exec(CMenuTarget* parent, const std::string & actionKey); static bool hasOpkgSupport(); - bool checkUpdates(const std::string & package_name = std::string(), bool show_progress = true); + bool checkUpdates(const std::string & package_name = std::string(), bool show_progress = false); + void setUpdateCheckResult(bool enable_message = true); bool installPackage(const std::string& pkg_name, std::string options = std::string(), bool force_configure = false); bool checkSize(const std::string& pkg_name); };