From dbfa0859cff33e6f979f7f565760c8f6b749a8da Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Sun, 5 Oct 2014 01:41:21 +0200 Subject: [PATCH] CShellWindow: clean up constructor/destructor Most tasks of this class were dispersed in the constructor and destructor. Tasks are better placed in Members. --- src/gui/widget/shellwindow.cpp | 40 ++++++++++++++++++++++++---------- src/gui/widget/shellwindow.h | 6 ++++- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/gui/widget/shellwindow.cpp b/src/gui/widget/shellwindow.cpp index fc9d53905..962870d03 100644 --- a/src/gui/widget/shellwindow.cpp +++ b/src/gui/widget/shellwindow.cpp @@ -41,15 +41,24 @@ #include #include #include -#include #include #include -CShellWindow::CShellWindow(const std::string &command, const int _mode, int *res) { - pid_t pid; - textBox = NULL; +CShellWindow::CShellWindow(const std::string &Command, const int Mode, int *Res) +{ + textBox = NULL; + frameBuffer = CFrameBuffer::getInstance(); + + command = Command; + mode = Mode; + res = Res; + + exec(); +} + +void CShellWindow::exec() +{ std::string cmd; - mode = _mode; if (!(mode & VERBOSE)){ cmd = "PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin ; export PATH ; " + command + " 2>/dev/null >&2"; int r = system(cmd.c_str()); @@ -62,6 +71,7 @@ CShellWindow::CShellWindow(const std::string &command, const int _mode, int *res return; } + pid_t pid; cmd = command + " 2>&1"; FILE *f = my_popen(pid, cmd.c_str(), "r"); if (!f) { @@ -70,7 +80,6 @@ CShellWindow::CShellWindow(const std::string &command, const int _mode, int *res return; } Font *font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]; - frameBuffer = CFrameBuffer::getInstance(); unsigned int lines_max = frameBuffer->getScreenHeight() / font->getHeight(); list lines; CBox textBoxPosition(frameBuffer->getScreenX(), frameBuffer->getScreenY(), frameBuffer->getScreenWidth(), frameBuffer->getScreenHeight()); @@ -185,9 +194,11 @@ CShellWindow::CShellWindow(const std::string &command, const int _mode, int *res else *res = WEXITSTATUS(s); } + + showResult(); } -CShellWindow::~CShellWindow() +void CShellWindow::showResult() { if (textBox){ bool exit = false; @@ -201,7 +212,10 @@ CShellWindow::~CShellWindow() btn.paint(); } else if (mode & ACKNOWLEDGE_MSG){ - DisplayInfoMessage("...ready. Please press OK"); + if (*res == -1) + DisplayErrorMessage("Please press button"); + else + DisplayInfoMessage("...ready. Please press OK"); exit = true; } @@ -215,9 +229,13 @@ CShellWindow::~CShellWindow() g_RCInput->getMsgAbsoluteTimeout(&msg, &data, &timeoutEnd); while (msg != CRCInput::RC_ok && msg != CRCInput::RC_home && msg != CRCInput::RC_timeout); } - } - if (textBox) { + textBox->hide(); - delete textBox; } } + +CShellWindow::~CShellWindow() +{ + if (textBox) + delete textBox; +} diff --git a/src/gui/widget/shellwindow.h b/src/gui/widget/shellwindow.h index ee6cb3953..130c7f8ce 100644 --- a/src/gui/widget/shellwindow.h +++ b/src/gui/widget/shellwindow.h @@ -42,12 +42,16 @@ class CShellWindow ACKNOWLEDGE = 2, ACKNOWLEDGE_MSG = 4 }; - CShellWindow(const std::string &cmd, const int mode = 0, int *res = NULL); + CShellWindow(const std::string &Command, const int Mode = 0, int* Res = NULL); ~CShellWindow(); private: int mode; + std::string command; + int* res; CFrameBuffer *frameBuffer; CTextBox *textBox; + void exec(); + void showResult(); }; #endif