opkg_manager: add option for silent screen

Help to control some screen messages, avoids unintended or disturbing messages,  e.g.
on update checks at background.
This commit is contained in:
2020-01-10 21:01:18 +01:00
parent 7f2bba84a0
commit 04e840366a
2 changed files with 43 additions and 21 deletions

View File

@@ -146,6 +146,7 @@ void COPKGManager::init()
local_dir = &g_settings.update_dir_opkg; local_dir = &g_settings.update_dir_opkg;
v_bad_pattern = getBadPackagePatternList(); v_bad_pattern = getBadPackagePatternList();
CFileHelpers::createDir(OPKG_TMP_DIR); CFileHelpers::createDir(OPKG_TMP_DIR);
silent = false;
} }
COPKGManager::~COPKGManager() COPKGManager::~COPKGManager()
@@ -457,34 +458,37 @@ bool COPKGManager::checkUpdates(const std::string & package_name, bool show_prog
if (!hasOpkgSupport()) if (!hasOpkgSupport())
return false; return false;
silent = !show_progress;
doUpdate(); doUpdate();
bool ret = false; bool ret = false;
size_t i = 0; size_t i = 0;
CProgressWindow status; CProgressWindow *status = NULL;
if (show_progress){ if (show_progress){
status.showHeader(false); status = new CProgressWindow();
status.paint(); status->showHeader(false);
status.showStatusMessageUTF(g_Locale->getText(LOCALE_OPKG_UPDATE_READING_LISTS)); status->paint();
status.showStatus(25); /* after do_update, we have actually done the hardest work already */ status->showStatusMessageUTF(g_Locale->getText(LOCALE_OPKG_UPDATE_READING_LISTS));
status->showStatus(25); /* after do_update, we have actually done the hardest work already */
} }
getPkgData(OM_LIST); getPkgData(OM_LIST);
if (show_progress) if (show_progress)
status.showStatus(50); status->showStatus(50);
getPkgData(OM_LIST_UPGRADEABLE); getPkgData(OM_LIST_UPGRADEABLE);
if (show_progress) if (show_progress)
status.showStatus(75); status->showStatus(75);
for (map<string, struct pkg>::iterator it = pkg_map.begin(); it != pkg_map.end(); ++it){ for (map<string, struct pkg>::iterator it = pkg_map.begin(); it != pkg_map.end(); ++it){
dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Update check for...%s\n", __func__, __LINE__, it->second.name.c_str()); dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Update check for...%s\n", __func__, __LINE__, it->second.name.c_str());
if (show_progress){ if (show_progress){
/* showing the names only makes things *much* slower... /* showing the names only makes things *much* slower...
status.showStatusMessageUTF(it->second.name); status->showStatusMessageUTF(it->second.name);
*/ */
status.showStatus(75 + 25*i / pkg_map.size()); status->showStatus(75 + 25*i / pkg_map.size());
} }
if (it->second.upgradable){ if (it->second.upgradable){
@@ -499,28 +503,41 @@ bool COPKGManager::checkUpdates(const std::string & package_name, bool show_prog
} }
if (show_progress){ if (show_progress){
status.showGlobalStatus(100); status->showGlobalStatus(100);
status.showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_READY)); // UTF-8 status->showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_READY)); // UTF-8
status.hide(); status->hide();
} }
if (status) {
delete status; status = NULL;
}
#if 0 #if 0
pkg_map.clear(); pkg_map.clear();
#endif #endif
return ret; return ret;
} }
int COPKGManager::doUpdate() int COPKGManager::doUpdate()
{ {
CHintBox hintBox(LOCALE_MESSAGEBOX_INFO, LOCALE_OPKG_UPDATE_CHECK); CHintBox *hintBox = NULL;
hintBox.paint();
if (!silent ) {
hintBox = new CHintBox (LOCALE_MESSAGEBOX_INFO, LOCALE_OPKG_UPDATE_CHECK);
hintBox->paint();
}
int r = execCmd(pkg_types[OM_UPDATE], CShellWindow::QUIET); int r = execCmd(pkg_types[OM_UPDATE], CShellWindow::QUIET);
hintBox.hide();
if (hintBox){
hintBox->hide();
delete hintBox; hintBox = NULL;
}
if (r) { if (r) {
string msg = string(g_Locale->getText(LOCALE_OPKG_FAILURE_UPDATE)); string msg = string(g_Locale->getText(LOCALE_OPKG_FAILURE_UPDATE));
msg += '\n' + tmp_str; msg += '\n' + tmp_str;
DisplayErrorMessage(msg.c_str()); if (!silent)
DisplayErrorMessage(msg.c_str());
return r; return r;
} }
return 0; return 0;
@@ -984,7 +1001,8 @@ void COPKGManager::showErr(int* res)
{ {
string err = to_string(*res); string err = to_string(*res);
string errtest = err_list[1].id; string errtest = err_list[1].id;
DisplayErrorMessage(errtest.c_str()); if (!silent)
DisplayErrorMessage(errtest.c_str());
} }
void COPKGManager::showError(const char* local_msg, char* err_message, const string& additional_text) void COPKGManager::showError(const char* local_msg, char* err_message, const string& additional_text)
@@ -994,14 +1012,16 @@ void COPKGManager::showError(const char* local_msg, char* err_message, const str
msg += string(err_message) + ":\n"; msg += string(err_message) + ":\n";
if (!additional_text.empty()) if (!additional_text.empty())
msg += additional_text; msg += additional_text;
DisplayErrorMessage(msg.c_str()); if (!silent)
DisplayErrorMessage(msg.c_str());
} }
bool COPKGManager::installPackage(const string& pkg_name, string options, bool force_configure) bool COPKGManager::installPackage(const string& pkg_name, string options, bool force_configure)
{ {
//check package size...cancel installation if size check failed //check package size...cancel installation if size check failed
if (!checkSize(pkg_name)){ if (!checkSize(pkg_name)){
DisplayErrorMessage(g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_SIZE_ERROR)); if (!silent)
DisplayErrorMessage(g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_SIZE_ERROR));
} }
else{ else{
string opts = " " + options + " "; string opts = " " + options + " ";
@@ -1121,6 +1141,7 @@ void COPKGManager::saveConfig()
//finally save config file //finally save config file
if (!opkg_conf.saveConfig(OPKG_CONFIG_FILE, '\t')){ if (!opkg_conf.saveConfig(OPKG_CONFIG_FILE, '\t')){
dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] Error: error while saving opkg config file! -> %s\n", __func__, __LINE__, OPKG_CONFIG_FILE); dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] Error: error while saving opkg config file! -> %s\n", __func__, __LINE__, OPKG_CONFIG_FILE);
DisplayErrorMessage("Error while saving opkg config file!"); if (!silent)
DisplayErrorMessage("Error while saving opkg config file!");
} }
} }

View File

@@ -49,6 +49,7 @@ class COPKGManager : public CMenuTarget
void loadConfig(); void loadConfig();
struct pkg; struct pkg;
void init(); void init();
bool silent; // Controls some screen messages, eg, avoids unintended or disturbing messages on update checks at background.
//config //config
std::string config_src[OPKG_MAX_FEEDS]; std::string config_src[OPKG_MAX_FEEDS];
std::vector<std::string> config_dest; std::vector<std::string> config_dest;