CShellWindow/COPKGManager: rework shell shell mode handling

Modes were handled with bool values inside manager and this is not really
enough. Now we use the real parameters for more flexibility.
This commit is contained in:
2015-05-28 10:27:59 +02:00
parent 8edbbaddc0
commit e1e8cb0142
4 changed files with 172 additions and 162 deletions

View File

@@ -41,7 +41,7 @@
#include <gui/widget/icons.h> #include <gui/widget/icons.h>
#include <gui/widget/messagebox.h> #include <gui/widget/messagebox.h>
#include <gui/widget/shellwindow.h>
#include <gui/widget/progresswindow.h> #include <gui/widget/progresswindow.h>
#include <gui/widget/keyboard_input.h> #include <gui/widget/keyboard_input.h>
#include <driver/screen_max.h> #include <driver/screen_max.h>
@@ -145,7 +145,7 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey)
if (ShowMsg(LOCALE_OPKG_TITLE, loc, CMessageBox::mbrCancel, CMessageBox::mbYes | CMessageBox::mbCancel) != CMessageBox::mbrCancel) { if (ShowMsg(LOCALE_OPKG_TITLE, loc, CMessageBox::mbrCancel, CMessageBox::mbYes | CMessageBox::mbCancel) != CMessageBox::mbrCancel) {
if (parent) if (parent)
parent->hide(); parent->hide();
execCmd(pkg_types[OM_REMOVE] + pkg_vec[selected]->name, true, true); execCmd(pkg_types[OM_REMOVE] + pkg_vec[selected]->name, CShellWindow::VERBOSE | CShellWindow::ACKNOWLEDGE_EVENT);
refreshMenu(); refreshMenu();
} }
return res; return res;
@@ -192,7 +192,7 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey)
if(actionKey == pkg_types[OM_UPGRADE]) { if(actionKey == pkg_types[OM_UPGRADE]) {
if (parent) if (parent)
parent->hide(); parent->hide();
int r = execCmd(actionKey, true, true); int r = execCmd(actionKey, CShellWindow::VERBOSE | CShellWindow::ACKNOWLEDGE_EVENT);
if (r) { if (r) {
showError(g_Locale->getText(LOCALE_OPKG_FAILURE_UPGRADE), strerror(errno), actionKey); showError(g_Locale->getText(LOCALE_OPKG_FAILURE_UPGRADE), strerror(errno), actionKey);
} else } else
@@ -425,9 +425,10 @@ bool COPKGManager::checkUpdates(const std::string & package_name, bool show_prog
int COPKGManager::doUpdate() int COPKGManager::doUpdate()
{ {
int r = execCmd(pkg_types[OM_UPDATE]); int r = execCmd(pkg_types[OM_UPDATE], CShellWindow::QUIET);
if (r == -1) { 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;
DisplayErrorMessage(msg.c_str()); DisplayErrorMessage(msg.c_str());
return r; return r;
} }
@@ -640,7 +641,7 @@ string COPKGManager::getBlankPkgName(const string& line)
string COPKGManager::getPkgInfo(const string& pkg_name, const string& pkg_key, bool current_status) string COPKGManager::getPkgInfo(const string& pkg_name, const string& pkg_key, bool current_status)
{ {
execCmd(pkg_types[current_status ? OM_STATUS : OM_INFO] + pkg_name, false, true); execCmd(pkg_types[current_status ? OM_STATUS : OM_INFO] + pkg_name, CShellWindow::QUIET);
dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] [data: %s]\n", __func__, __LINE__, tmp_str.c_str()); dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] [data: %s]\n", __func__, __LINE__, tmp_str.c_str());
if (pkg_key.empty()) if (pkg_key.empty())
@@ -668,7 +669,7 @@ string COPKGManager::getKeyInfo(const string& input, const std::string& key, con
return ""; return "";
} }
int COPKGManager::execCmd(const char *cmdstr, bool verbose, bool acknowledge) int COPKGManager::execCmd(const char *cmdstr, int verbose_mode)
{ {
fprintf(stderr, "execCmd(%s)\n", cmdstr); fprintf(stderr, "execCmd(%s)\n", cmdstr);
string cmd = string(cmdstr); string cmd = string(cmdstr);
@@ -678,7 +679,7 @@ int COPKGManager::execCmd(const char *cmdstr, bool verbose, bool acknowledge)
bool ok = true; bool ok = true;
//create CShellWindow object //create CShellWindow object
CShellWindow shell(cmd, (verbose ? CShellWindow::VERBOSE : 0) | (acknowledge ? CShellWindow::ACKNOWLEDGE_EVENT : 0), &res, false); CShellWindow shell(cmd, verbose_mode, &res, false);
//init slot for shell output handler with 3 args, no return value, and connect with loop handler inside of CShellWindow object //init slot for shell output handler with 3 args, no return value, and connect with loop handler inside of CShellWindow object
sigc::slot3<void, string*, int*, bool*> sl_shell; sigc::slot3<void, string*, int*, bool*> sl_shell;
@@ -798,7 +799,7 @@ bool COPKGManager::installPackage(const string& pkg_name, string options, bool f
else{ else{
string opts = " " + options + " "; string opts = " " + options + " ";
int r = execCmd(pkg_types[OM_INSTALL] + opts + pkg_name, true, true); int r = execCmd(pkg_types[OM_INSTALL] + opts + pkg_name, CShellWindow::VERBOSE | CShellWindow::ACKNOWLEDGE_EVENT);
if (r){ if (r){
switch(r){ switch(r){
case OM_OUT_OF_SPACE_ERR: case OM_OUT_OF_SPACE_ERR:
@@ -818,8 +819,8 @@ bool COPKGManager::installPackage(const string& pkg_name, string options, bool f
} }
}else{ }else{
if (force_configure) if (force_configure)
execCmd(pkg_types[OM_CONFIGURE] + getBlankPkgName(pkg_name), false, false); execCmd(pkg_types[OM_CONFIGURE] + getBlankPkgName(pkg_name), 0);
installed = true; installed = true; //TODO: catch real result
} }
} }

View File

@@ -32,6 +32,7 @@
#define __OPKG_MANAGER__ #define __OPKG_MANAGER__
#include <gui/widget/menue.h> #include <gui/widget/menue.h>
#include <gui/widget/shellwindow.h>
#include <driver/framebuffer.h> #include <driver/framebuffer.h>
#include <configfile.h> #include <configfile.h>
#include <string> #include <string>
@@ -97,9 +98,9 @@ class COPKGManager : public CMenuTarget
}; };
void showErr(int* res); void showErr(int* res);
int execCmd(const char* cmdstr, bool verbose = false, bool acknowledge = false); int execCmd(const char* cmdstr, int verbose_mode = 0);
int execCmd(std::string cmdstr, bool verbose = false, bool acknowledge = false) { int execCmd(std::string cmdstr, int verbose_mode = 0) {
return execCmd(cmdstr.c_str(), verbose, acknowledge); return execCmd(cmdstr.c_str(), verbose_mode);
}; };
void getPkgData(const int pkg_content_id); void getPkgData(const int pkg_content_id);
std::string getBlankPkgName(const std::string& line); std::string getBlankPkgName(const std::string& line);

View File

@@ -62,7 +62,7 @@ CShellWindow::CShellWindow(const std::string &Command, const int Mode, int *Res,
void CShellWindow::exec() void CShellWindow::exec()
{ {
std::string cmd; std::string cmd;
if (!(mode & VERBOSE)){ if (mode == 0){
cmd = "PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin ; export PATH ; " + command + " 2>/dev/null >&2"; cmd = "PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin ; export PATH ; " + command + " 2>/dev/null >&2";
int r = my_system(cmd.c_str()); int r = my_system(cmd.c_str());
if (res) { if (res) {
@@ -72,9 +72,8 @@ void CShellWindow::exec()
*res = WEXITSTATUS(r); *res = WEXITSTATUS(r);
dprintf(DEBUG_NORMAL, "[CShellWindow] [%s - %d] Error! system returns: %d command: %s\n", __func__, __LINE__, *res, cmd.c_str()); dprintf(DEBUG_NORMAL, "[CShellWindow] [%s - %d] Error! system returns: %d command: %s\n", __func__, __LINE__, *res, cmd.c_str());
} }
return;
} }
else {
pid_t pid = 0; pid_t pid = 0;
cmd = command + " 2>&1"; cmd = command + " 2>&1";
FILE *f = my_popen(pid, cmd.c_str(), "r"); FILE *f = my_popen(pid, cmd.c_str(), "r");
@@ -91,8 +90,10 @@ void CShellWindow::exec()
unsigned int lines_max = h_shell / font->getHeight(); unsigned int lines_max = h_shell / font->getHeight();
list<std::string> lines; list<std::string> lines;
CBox textBoxPosition(frameBuffer->getScreenX(), frameBuffer->getScreenX(), w_shell, h_shell); CBox textBoxPosition(frameBuffer->getScreenX(), frameBuffer->getScreenX(), w_shell, h_shell);
if (textBox == NULL){
textBox = new CTextBox(cmd.c_str(), font, CTextBox::BOTTOM, &textBoxPosition); textBox = new CTextBox(cmd.c_str(), font, CTextBox::BOTTOM, &textBoxPosition);
textBox->enableSaveScreen(false); textBox->enableSaveScreen(false);
}
struct pollfd fds; struct pollfd fds;
fds.fd = fileno(f); fds.fd = fileno(f);
fds.events = POLLIN | POLLHUP | POLLERR; fds.events = POLLIN | POLLHUP | POLLERR;
@@ -173,7 +174,7 @@ void CShellWindow::exec()
if (((lines_read == lines_max) && (lastPaint + 100000 < now)) || (lastPaint + 250000 < now)) { if (((lines_read == lines_max) && (lastPaint + 100000 < now)) || (lastPaint + 250000 < now)) {
textBox->setText(&txt, textBox->getWindowsPos().iWidth, false); textBox->setText(&txt, textBox->getWindowsPos().iWidth, false);
if (!textBox->isPainted()) if (!textBox->isPainted())
textBox->paint(); if (mode & VERBOSE) textBox->paint();
lines_read = 0; lines_read = 0;
lastPaint = now; lastPaint = now;
dirty = false; dirty = false;
@@ -189,14 +190,16 @@ void CShellWindow::exec()
if (!ok || (r < 1 && dirty && lastPaint + 250000 < now)) { if (!ok || (r < 1 && dirty && lastPaint + 250000 < now)) {
textBox->setText(&txt, textBox->getWindowsPos().iWidth, false); textBox->setText(&txt, textBox->getWindowsPos().iWidth, false);
if (!textBox->isPainted()) if (!textBox->isPainted())
textBox->paint(); if (mode & VERBOSE) textBox->paint();
lastPaint = now; lastPaint = now;
dirty = false; dirty = false;
} }
} while(ok); } while(ok);
if (mode & VERBOSE) {
txt += "\n...ready"; txt += "\n...ready";
textBox->setText(&txt, textBox->getWindowsPos().iWidth, false); textBox->setText(&txt, textBox->getWindowsPos().iWidth, false);
}
fclose(f); fclose(f);
int s; int s;
@@ -214,6 +217,7 @@ void CShellWindow::exec()
} }
showResult(); showResult();
}
} }
void CShellWindow::showResult() void CShellWindow::showResult()
@@ -233,10 +237,11 @@ void CShellWindow::showResult()
show_button = true; show_button = true;
}else{ }else{
OnResultOk(res); OnResultOk(res);
exit = true; exit = true; //TODO: evaluate plausible statement
} }
} }
if ((mode & VERBOSE)){
if (show_button){ if (show_button){
int b_width = 150; int b_width = 150;
int b_height = 35; int b_height = 35;
@@ -256,9 +261,9 @@ void CShellWindow::showResult()
g_RCInput->getMsgAbsoluteTimeout(&msg, &data, &timeoutEnd); g_RCInput->getMsgAbsoluteTimeout(&msg, &data, &timeoutEnd);
while (msg != CRCInput::RC_ok && msg != CRCInput::RC_home && msg != CRCInput::RC_timeout); while (msg != CRCInput::RC_ok && msg != CRCInput::RC_home && msg != CRCInput::RC_timeout);
} }
textBox->hide(); textBox->hide();
} }
}
} }
CShellWindow::~CShellWindow() CShellWindow::~CShellWindow()

View File

@@ -45,11 +45,14 @@ class CShellWindow : public sigc::trackable
void showResult(); void showResult();
public: public:
//shell window modes for handled shell output. //NOTE: mode 0 use only system calls, with unhandled return values and no handled shell output
enum shellwindow_modes enum shellwindow_modes
{ {
VERBOSE = 1, /*SYSTEM = 0, */
ACKNOWLEDGE = 2, QUIET = 1, // no window
ACKNOWLEDGE_EVENT = 4 VERBOSE = 2, // show window
ACKNOWLEDGE = 4, // show result button inside window after execution, no message box NOTE: only in VERBOSE mode
ACKNOWLEDGE_EVENT = 8 // same like ACKNOWLEDGE but shows a default error message box or a slot handled action instead default error message box
}; };
CShellWindow(const std::string &Command, const int Mode = 0, int* Res = NULL, bool auto_exec = true); CShellWindow(const std::string &Command, const int Mode = 0, int* Res = NULL, bool auto_exec = true);
~CShellWindow(); ~CShellWindow();