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;
v_bad_pattern = getBadPackagePatternList();
CFileHelpers::createDir(OPKG_TMP_DIR);
silent = false;
}
COPKGManager::~COPKGManager()
@@ -457,34 +458,37 @@ bool COPKGManager::checkUpdates(const std::string & package_name, bool show_prog
if (!hasOpkgSupport())
return false;
silent = !show_progress;
doUpdate();
bool ret = false;
size_t i = 0;
CProgressWindow status;
CProgressWindow *status = NULL;
if (show_progress){
status.showHeader(false);
status.paint();
status.showStatusMessageUTF(g_Locale->getText(LOCALE_OPKG_UPDATE_READING_LISTS));
status.showStatus(25); /* after do_update, we have actually done the hardest work already */
status = new CProgressWindow();
status->showHeader(false);
status->paint();
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);
if (show_progress)
status.showStatus(50);
status->showStatus(50);
getPkgData(OM_LIST_UPGRADEABLE);
if (show_progress)
status.showStatus(75);
status->showStatus(75);
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());
if (show_progress){
/* 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){
@@ -499,27 +503,40 @@ bool COPKGManager::checkUpdates(const std::string & package_name, bool show_prog
}
if (show_progress){
status.showGlobalStatus(100);
status.showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_READY)); // UTF-8
status.hide();
status->showGlobalStatus(100);
status->showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_READY)); // UTF-8
status->hide();
}
if (status) {
delete status; status = NULL;
}
#if 0
pkg_map.clear();
#endif
return ret;
}
int COPKGManager::doUpdate()
{
CHintBox hintBox(LOCALE_MESSAGEBOX_INFO, LOCALE_OPKG_UPDATE_CHECK);
hintBox.paint();
CHintBox *hintBox = NULL;
if (!silent ) {
hintBox = new CHintBox (LOCALE_MESSAGEBOX_INFO, LOCALE_OPKG_UPDATE_CHECK);
hintBox->paint();
}
int r = execCmd(pkg_types[OM_UPDATE], CShellWindow::QUIET);
hintBox.hide();
if (hintBox){
hintBox->hide();
delete hintBox; hintBox = NULL;
}
if (r) {
string msg = string(g_Locale->getText(LOCALE_OPKG_FAILURE_UPDATE));
msg += '\n' + tmp_str;
if (!silent)
DisplayErrorMessage(msg.c_str());
return r;
}
@@ -984,6 +1001,7 @@ void COPKGManager::showErr(int* res)
{
string err = to_string(*res);
string errtest = err_list[1].id;
if (!silent)
DisplayErrorMessage(errtest.c_str());
}
@@ -994,6 +1012,7 @@ void COPKGManager::showError(const char* local_msg, char* err_message, const str
msg += string(err_message) + ":\n";
if (!additional_text.empty())
msg += additional_text;
if (!silent)
DisplayErrorMessage(msg.c_str());
}
@@ -1001,6 +1020,7 @@ bool COPKGManager::installPackage(const string& pkg_name, string options, bool f
{
//check package size...cancel installation if size check failed
if (!checkSize(pkg_name)){
if (!silent)
DisplayErrorMessage(g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_SIZE_ERROR));
}
else{
@@ -1121,6 +1141,7 @@ void COPKGManager::saveConfig()
//finally save config file
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);
if (!silent)
DisplayErrorMessage("Error while saving opkg config file!");
}
}

View File

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