mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-27 15:32:59 +02:00
opkg_manager: vizualize available package updates
This commit is contained in:
@@ -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 <gui/widget/termwindow.h>
|
||||
#include "widget/termwindow.h"
|
||||
/* hack, so we don't have to change all code below */
|
||||
#define CShellWindow CTermWindow
|
||||
|
||||
@@ -42,14 +42,14 @@
|
||||
#include <neutrino.h>
|
||||
#include <neutrino_menue.h>
|
||||
|
||||
#include <gui/widget/icons.h>
|
||||
#include <gui/widget/msgbox.h>
|
||||
#include "widget/icons.h"
|
||||
#include "widget/msgbox.h"
|
||||
|
||||
#include <gui/widget/progresswindow.h>
|
||||
#include <gui/widget/hintbox.h>
|
||||
#include <gui/widget/keyboard_input.h>
|
||||
#include "widget/progresswindow.h"
|
||||
#include "widget/hintbox.h"
|
||||
#include "widget/keyboard_input.h"
|
||||
#include <driver/screen_max.h>
|
||||
#include <gui/filebrowser.h>
|
||||
#include "filebrowser.h"
|
||||
#include <system/debug.h>
|
||||
#include <system/helpers.h>
|
||||
#include <unistd.h>
|
||||
@@ -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<std::mutex> 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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user