mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 16:31:11 +02:00
CShellWindow: use slots for ACKNOWLEDGE_EVENT mode results
This commit is contained in:
@@ -156,7 +156,8 @@ void CShellWindow::exec()
|
|||||||
|
|
||||||
//callback for line handler
|
//callback for line handler
|
||||||
std::string s_output = std::string((output));
|
std::string s_output = std::string((output));
|
||||||
OnShellOutputLoop(s_output);
|
OnShellOutputLoop(s_output, res, &ok);
|
||||||
|
dprintf(DEBUG_NORMAL, "[CShellWindow] [%s - %d] res=%d ok=%d\n", __func__, __LINE__, *res, ok);
|
||||||
if (lines.size() > lines_max)
|
if (lines.size() > lines_max)
|
||||||
lines.pop_front();
|
lines.pop_front();
|
||||||
txt = "";
|
txt = "";
|
||||||
@@ -200,12 +201,14 @@ void CShellWindow::exec()
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
int r = waitpid(pid, &s, 0);
|
int r = waitpid(pid, &s, 0);
|
||||||
|
|
||||||
if (res) {
|
if (res){
|
||||||
dprintf(DEBUG_NORMAL, "[CShellWindow] [%s - %d] res=%d, error[%d]: %s\n", __func__, __LINE__, *res, errno, strerror(errno));
|
//if res value was generated inside signal, then use foreign res from signal instead own res value
|
||||||
if (r == -1)
|
if (OnShellOutputLoop.empty()){
|
||||||
*res = errno;
|
if (r == -1)
|
||||||
else
|
*res = errno;
|
||||||
*res = WEXITSTATUS(s);
|
else
|
||||||
|
*res = WEXITSTATUS(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showResult();
|
showResult();
|
||||||
@@ -220,12 +223,14 @@ void CShellWindow::showResult()
|
|||||||
if (mode & ACKNOWLEDGE){
|
if (mode & ACKNOWLEDGE){
|
||||||
show_button = true;
|
show_button = true;
|
||||||
}
|
}
|
||||||
else if (mode & ACKNOWLEDGE_MSG){
|
else if (mode & ACKNOWLEDGE_EVENT){
|
||||||
if (*res != 0){
|
if (*res != 0){
|
||||||
DisplayErrorMessage("Please press button");
|
OnResultError(res);
|
||||||
|
if (OnResultError.empty())
|
||||||
|
DisplayErrorMessage("Error while execution of task. Please see window for details!");
|
||||||
show_button = true;
|
show_button = true;
|
||||||
}else{
|
}else{
|
||||||
DisplayInfoMessage("...ready. Please press OK");
|
OnResultOk(res);
|
||||||
exit = true;
|
exit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,7 +240,7 @@ void CShellWindow::showResult()
|
|||||||
int b_height = 35;
|
int b_height = 35;
|
||||||
int xpos = frameBuffer->getScreenWidth() - b_width;
|
int xpos = frameBuffer->getScreenWidth() - b_width;
|
||||||
int ypos = frameBuffer->getScreenHeight() - b_height;
|
int ypos = frameBuffer->getScreenHeight() - b_height;
|
||||||
CComponentsButton btn(xpos, ypos, b_width, b_height, LOCALE_MESSAGEBOX_OK, NEUTRINO_ICON_BUTTON_OKAY, NULL, true, true);
|
CComponentsButton btn(xpos, ypos, b_width, b_height, LOCALE_MESSAGEBOX_BACK, NEUTRINO_ICON_BUTTON_OKAY, NULL, true, true);
|
||||||
btn.paint();
|
btn.paint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -47,9 +47,9 @@ class CShellWindow : public sigc::trackable
|
|||||||
public:
|
public:
|
||||||
enum shellwindow_modes
|
enum shellwindow_modes
|
||||||
{
|
{
|
||||||
VERBOSE = 1,
|
VERBOSE = 1,
|
||||||
ACKNOWLEDGE = 2,
|
ACKNOWLEDGE = 2,
|
||||||
ACKNOWLEDGE_MSG = 4
|
ACKNOWLEDGE_EVENT = 4
|
||||||
};
|
};
|
||||||
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();
|
||||||
@@ -79,7 +79,36 @@ class CShellWindow : public sigc::trackable
|
|||||||
shell.exec();
|
shell.exec();
|
||||||
...other code...
|
...other code...
|
||||||
*/
|
*/
|
||||||
sigc::signal<void, std::string&> OnShellOutputLoop;
|
sigc::signal<void, std::string&, int*, bool*> OnShellOutputLoop;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
signal/event handler runs after task is finished.
|
||||||
|
NOTE: works only with ACKNOWLEDGE_EVENT mode
|
||||||
|
After executed task comes a default messages (see method showResult()), but with these slots it is possible to use other messages
|
||||||
|
or any desired action without any touching this class.
|
||||||
|
Example for implementation in foreign class let show an alternate message than default message:
|
||||||
|
...your code...
|
||||||
|
//assuming in your foreign class is declared a member function named YourMemberFunction() without return value and int* as parmeter This method should run
|
||||||
|
instead the default message.
|
||||||
|
|
||||||
|
//declare a slot with return value as 'void' and wihout any parameter
|
||||||
|
sigc::slot<void, int*> sl;
|
||||||
|
|
||||||
|
//fill the slot with your member function in your class with your action
|
||||||
|
sl = sigc::mem_fun(*this, &CYourClass::YourMemberFunction);
|
||||||
|
|
||||||
|
//create the CShellWindow object in verbose mode, important: parameter 'auto_exec' must be set to 'false', so it is possible to connect the slot before engages the exec() methode
|
||||||
|
CShellWindow shell(cmd, (verbose ? CShellWindow::VERBOSE : 0) | (acknowledge ? CShellWindow::ACKNOWLEDGE_MSG : 0), &res, false);
|
||||||
|
|
||||||
|
//connect slot
|
||||||
|
shell1.OnResultError.connect(sl);
|
||||||
|
|
||||||
|
//now exec...
|
||||||
|
shell.exec();
|
||||||
|
...other code...
|
||||||
|
*/
|
||||||
|
sigc::signal<void, int*> OnResultError;
|
||||||
|
sigc::signal<void, int*> OnResultOk;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user