mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-30 00:41:17 +02:00
CShellWindow: clean up constructor/destructor
Most tasks of this class were dispersed in the constructor and destructor. Tasks are better placed in Members.
This commit is contained in:
@@ -41,15 +41,24 @@
|
|||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <system/helpers.h>
|
#include <system/helpers.h>
|
||||||
#include <gui/components/cc.h>
|
|
||||||
#include <gui/widget/messagebox.h>
|
#include <gui/widget/messagebox.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
CShellWindow::CShellWindow(const std::string &command, const int _mode, int *res) {
|
CShellWindow::CShellWindow(const std::string &Command, const int Mode, int *Res)
|
||||||
pid_t pid;
|
{
|
||||||
textBox = NULL;
|
textBox = NULL;
|
||||||
|
frameBuffer = CFrameBuffer::getInstance();
|
||||||
|
|
||||||
|
command = Command;
|
||||||
|
mode = Mode;
|
||||||
|
res = Res;
|
||||||
|
|
||||||
|
exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShellWindow::exec()
|
||||||
|
{
|
||||||
std::string cmd;
|
std::string cmd;
|
||||||
mode = _mode;
|
|
||||||
if (!(mode & VERBOSE)){
|
if (!(mode & VERBOSE)){
|
||||||
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 = system(cmd.c_str());
|
int r = system(cmd.c_str());
|
||||||
@@ -62,6 +71,7 @@ CShellWindow::CShellWindow(const std::string &command, const int _mode, int *res
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid_t pid;
|
||||||
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");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
@@ -70,7 +80,6 @@ CShellWindow::CShellWindow(const std::string &command, const int _mode, int *res
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Font *font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO];
|
Font *font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO];
|
||||||
frameBuffer = CFrameBuffer::getInstance();
|
|
||||||
unsigned int lines_max = frameBuffer->getScreenHeight() / font->getHeight();
|
unsigned int lines_max = frameBuffer->getScreenHeight() / font->getHeight();
|
||||||
list<std::string> lines;
|
list<std::string> lines;
|
||||||
CBox textBoxPosition(frameBuffer->getScreenX(), frameBuffer->getScreenY(), frameBuffer->getScreenWidth(), frameBuffer->getScreenHeight());
|
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
|
else
|
||||||
*res = WEXITSTATUS(s);
|
*res = WEXITSTATUS(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
CShellWindow::~CShellWindow()
|
void CShellWindow::showResult()
|
||||||
{
|
{
|
||||||
if (textBox){
|
if (textBox){
|
||||||
bool exit = false;
|
bool exit = false;
|
||||||
@@ -201,6 +212,9 @@ CShellWindow::~CShellWindow()
|
|||||||
btn.paint();
|
btn.paint();
|
||||||
}
|
}
|
||||||
else if (mode & ACKNOWLEDGE_MSG){
|
else if (mode & ACKNOWLEDGE_MSG){
|
||||||
|
if (*res == -1)
|
||||||
|
DisplayErrorMessage("Please press button");
|
||||||
|
else
|
||||||
DisplayInfoMessage("...ready. Please press OK");
|
DisplayInfoMessage("...ready. Please press OK");
|
||||||
exit = true;
|
exit = true;
|
||||||
}
|
}
|
||||||
@@ -215,9 +229,13 @@ CShellWindow::~CShellWindow()
|
|||||||
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);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (textBox) {
|
|
||||||
textBox->hide();
|
textBox->hide();
|
||||||
delete textBox;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CShellWindow::~CShellWindow()
|
||||||
|
{
|
||||||
|
if (textBox)
|
||||||
|
delete textBox;
|
||||||
|
}
|
||||||
|
@@ -42,12 +42,16 @@ class CShellWindow
|
|||||||
ACKNOWLEDGE = 2,
|
ACKNOWLEDGE = 2,
|
||||||
ACKNOWLEDGE_MSG = 4
|
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();
|
~CShellWindow();
|
||||||
private:
|
private:
|
||||||
int mode;
|
int mode;
|
||||||
|
std::string command;
|
||||||
|
int* res;
|
||||||
CFrameBuffer *frameBuffer;
|
CFrameBuffer *frameBuffer;
|
||||||
CTextBox *textBox;
|
CTextBox *textBox;
|
||||||
|
void exec();
|
||||||
|
void showResult();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user