hintbox: expand ShowHintS() with slot parameter

This allows to execute one ore more methods inside the ShowHintS() method.
This should simplify calls of CHint messages with or without hide delays
In the simplest or most cases, only one code line is necessary for this,
see examples inside test_menu.cpp or here:

Single methode:
old:
CHintBox *hintBox new CHintBox(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_SERVICEMENU_GETPLUGINS_HINT));
hintBox->paint();
g_Plugins->loadPlugins();
sleep(1);
hintBox->.hide();
delete hintbox;

new:
ShowHintS(LOCALE_SERVICEMENU_GETPLUGINS_HINT, 1, true, sigc::mem_fun(g_Plugins, &CPlugins::loadPlugins));

Multiple methods:
old:
	CHint *hint = new CHint("Restart Tuner");
	hint->paint();
	g_Zapit->setStandby(true);
	sleep(2);
	g_Zapit->setStandby(false);
	sleep(2);
	g_Zapit->Rezap();
	delete hint;

new:
	std::vector <hint_message_data_t> hints;
	hints.push_back({sigc::bind(sigc::mem_fun(g_Zapit, &CZapitClient::setStandby), true),"Stopping tuner...", NONEXISTANT_LOCALE, 2, true});
	hints.push_back({sigc::bind(sigc::mem_fun(g_Zapit, &CZapitClient::setStandby), false), "Start tuner...", NONEXISTANT_LOCALE, 2, true});
	hints.push_back({sigc::hide_return(sigc::mem_fun(g_Zapit, &CZapitClient::Rezap)), "Rezap...", NONEXISTANT_LOCALE, 2, true});
	ShowHintS(hints);

slots can be used with sigc::bind, sigc::hide_return (or what ever) too.
sample slot:
sigc::slot<void> sl = sigc::bind(sigc::mem_fun(this, &ClassName::method), parameter);

Note: Usage of namespace sigc are doing to simplify the lines,
      but this is a matter of discretion.

TODO: - timeoutbar should visualize a kind of busy mode.
      - implemetations
This commit is contained in:
2021-09-29 21:35:32 +02:00
parent b23fcc7c7c
commit b7e837d82b
3 changed files with 134 additions and 3 deletions

View File

@@ -1010,7 +1010,7 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
DisplayInfoMessage("Info Test!"); DisplayInfoMessage("Info Test!");
return menu_return::RETURN_REPAINT; return menu_return::RETURN_REPAINT;
} }
else if (actionKey == "short_hint"){ else if (actionKey == "short_hint with sleep and CHint instance"){
CHint *hint = new CHint("Info Test!"); CHint *hint = new CHint("Info Test!");
// Set the message window outside of screen mid to demonstrate the hide behavior, // Set the message window outside of screen mid to demonstrate the hide behavior,
// so that the hide behavior will not be influenced by any other window or menu. // so that the hide behavior will not be influenced by any other window or menu.
@@ -1027,6 +1027,41 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
ShowHintS("Info Test...", 3, true); ShowHintS("Info Test...", 3, true);
return menu_return::RETURN_REPAINT; return menu_return::RETURN_REPAINT;
} }
else if (actionKey == "short_hint_timed_slot"){
ShowHintS("Info test with function...", sigc::mem_fun(*this, &CTestMenu::showRecords), 3);
return menu_return::RETURN_REPAINT;
}
else if (actionKey == "short_hint_struct"){
hint_message_data_t hint;
hint.text = "Info Test...";
hint.slot = sigc::mem_fun(*this, &CTestMenu::showRecords);
hint.timeout = 3;
ShowHintS(hint);
return menu_return::RETURN_REPAINT;
}
else if (actionKey=="restarttuner")
{
#if 0
// use with CHint instance
CHint *hint = new CHint("Restart Tuner");
hint->paint();
g_Zapit->setStandby(true);
sleep(2);
g_Zapit->setStandby(false);
sleep(2);
g_Zapit->Rezap();
delete hint;
#endif
// Use of ShowHintS with slot does the same like previous block,
// but with multiple messages and despite that with lesser effort.
std::vector <hint_message_data_t> hints;
hints.push_back({sigc::bind(sigc::mem_fun(g_Zapit, &CZapitClient::setStandby), true),"Stopping tuner...", NONEXISTANT_LOCALE, 2, true});
hints.push_back({sigc::bind(sigc::mem_fun(g_Zapit, &CZapitClient::setStandby), false), "Start tuner...", NONEXISTANT_LOCALE, 2, true});
hints.push_back({sigc::hide_return(sigc::mem_fun(g_Zapit, &CZapitClient::Rezap)), "Rezap...", NONEXISTANT_LOCALE, 2, true});
ShowHintS(hints);
return menu_return::RETURN_REPAINT;
}
else if (actionKey == "shellwindow"){ else if (actionKey == "shellwindow"){
sigc::slot3<void, std::string*, int *, bool *> sl_shell_output; sigc::slot3<void, std::string*, int *, bool *> sl_shell_output;
sl_shell_output = sigc::mem_fun(*this, &CTestMenu::handleShellOutput); sl_shell_output = sigc::mem_fun(*this, &CTestMenu::handleShellOutput);
@@ -1277,6 +1312,8 @@ void CTestMenu::showHWTests(CMenuWidget *widget)
#endif #endif
widget->addItem(new CMenuForwarder("HDD", true, NULL, this, "hdd")); widget->addItem(new CMenuForwarder("HDD", true, NULL, this, "hdd"));
widget->addItem(new CMenuForwarder("SD/MMC", true, NULL, this, "mmc")); widget->addItem(new CMenuForwarder("SD/MMC", true, NULL, this, "mmc"));
widget->addItem(new CMenuForwarder("Tuner Reset", true, NULL, this, "restarttuner"));
#if 0 //some parts DEPRECATED #if 0 //some parts DEPRECATED
for (unsigned i = 0; i < sizeof(test_pos)/sizeof(int); i++) { for (unsigned i = 0; i < sizeof(test_pos)/sizeof(int); i++) {
CServiceManager::getInstance()->InitSatPosition(test_pos[i], NULL, true); CServiceManager::getInstance()->InitSatPosition(test_pos[i], NULL, true);
@@ -1347,6 +1384,8 @@ void CTestMenu::showMsgTests(CMenuWidget *widget)
widget->addItem(new CMenuSeparator(CMenuSeparator::STRING | CMenuSeparator::LINE, "Short Hint")); widget->addItem(new CMenuSeparator(CMenuSeparator::STRING | CMenuSeparator::LINE, "Short Hint"));
widget->addItem(new CMenuForwarder("Short hint!", true, NULL, this, "short_hint")); widget->addItem(new CMenuForwarder("Short hint!", true, NULL, this, "short_hint"));
widget->addItem(new CMenuForwarder("Short hint with timeout!", true, NULL, this, "short_hint_timed")); widget->addItem(new CMenuForwarder("Short hint with timeout!", true, NULL, this, "short_hint_timed"));
widget->addItem(new CMenuForwarder("Short hint with timeout and function!", true, NULL, this, "short_hint_timed_slot"));
widget->addItem(new CMenuForwarder("Short hint with struct arg!", true, NULL, this, "short_hint_struct"));
} }
void CTestMenu::showSeparatorTypes(CMenuWidget *widget) void CTestMenu::showSeparatorTypes(CMenuWidget *widget)

View File

@@ -497,7 +497,6 @@ CHint::CHint(const neutrino_locale_t Text, bool show_background) : CHintBox("" ,
int ShowHintS(const char * const Text, int timeout, bool show_background) int ShowHintS(const char * const Text, int timeout, bool show_background)
{ {
int res = messages_return::none; int res = messages_return::none;
CHint hint(Text, show_background); CHint hint(Text, show_background);
hint.setTimeOut(timeout); hint.setTimeOut(timeout);
hint.paint(); hint.paint();
@@ -511,3 +510,55 @@ int ShowHintS(const neutrino_locale_t Text, int timeout, bool show_background)
{ {
return ShowHintS(g_Locale->getText(Text), timeout, show_background); return ShowHintS(g_Locale->getText(Text), timeout, show_background);
} }
int ShowHintS(const std::string& Text, int timeout, bool show_background)
{
return ShowHintS(Text.c_str(), timeout, show_background);
}
int ShowHintS(const char * const Text, const sigc::slot<void> &Slot, int timeout, bool show_background)
{
int res = messages_return::none;
sigc::signal<void> OnCall;
OnCall.connect(Slot);
CHint hint(Text, show_background);
hint.setTimeOut(timeout);
hint.paint();
OnCall();
res = hint.exec();
hint.hide();
return res;
}
int ShowHintS(const neutrino_locale_t Text, const sigc::slot<void> &Slot, int timeout, bool show_background)
{
return ShowHintS(g_Locale->getText(Text), Slot, timeout, show_background);
}
int ShowHintS(const std::string& Text, const sigc::slot<void> &Slot, int timeout, bool show_background)
{
return ShowHintS(Text.c_str(), Slot, timeout, show_background);
}
int ShowHintS(const hint_message_data_t &hint_data)
{
std::string text = !hint_data.text.empty() ? hint_data.text : g_Locale->getText(hint_data.text_locale);
return ShowHintS(text, hint_data.slot, hint_data.timeout, hint_data.show_background);
}
int ShowHintS(const std::vector<hint_message_data_t>& v_hint_data)
{
int ret = messages_return::none;
for(size_t i=0; i<v_hint_data.size(); i++)
{
std::string txt = !v_hint_data.at(i).text.empty() ? v_hint_data.at(i).text : g_Locale->getText(v_hint_data.at(i).text_locale);
ret = ShowHintS(txt,
v_hint_data.at(i).slot,
v_hint_data.at(i).timeout,
v_hint_data.at(i).show_background);
}
return ret;
}

View File

@@ -371,17 +371,58 @@ class CHint : public CHintBox
virtual ~CHint(){}; virtual ~CHint(){};
}; };
typedef struct hint_message_data_t
{
sigc::slot<void> slot;
std::string text;
neutrino_locale_t text_locale;
int timeout;
bool show_background;
// hint_message_data_t(): text(std::string()),
// text_locale(NONEXISTANT_LOCALE),
// timeout(HINTBOX_DEFAULT_TIMEOUT),
// show_background(true){}
} hint_message_data_struct_t;
/** /**
* Simplified methodes to show hintboxes without titlebar and footer * Simplified methodes to show hintboxes without titlebar and footer
* Text is UTF-8 encoded * Text is UTF-8 encoded
* @param[in] Text
* @li expects type neutrino_locale_t or const char*
* @param[in] timeout * @param[in] timeout
* @li optional: expects type int as seconds, default = HINTBOX_DEFAULT_TIMEOUT (get from settings) * @li optional: expects type int as seconds, default = HINTBOX_DEFAULT_TIMEOUT (get from settings)
* @param[in] show_background * @param[in] show_background
* @li optional: expects type bool, enable/disable backround paint, default = true * @li optional: expects type bool, enable/disable backround paint, default = true
* @see for possible text parameters take a look to CHintBox() * @see for possible text parameters take a look to CHintBox()
*/ */
int ShowHintS(const neutrino_locale_t Text, int timeout = HINTBOX_DEFAULT_TIMEOUT, bool show_background = true); int ShowHintS(const neutrino_locale_t Text, int timeout = HINTBOX_DEFAULT_TIMEOUT, bool show_background = true);
int ShowHintS(const char * const Text, int timeout = HINTBOX_DEFAULT_TIMEOUT, bool show_background = true); int ShowHintS(const char * const Text, int timeout = HINTBOX_DEFAULT_TIMEOUT, bool show_background = true);
int ShowHintS(const std::string &Text, int timeout = HINTBOX_DEFAULT_TIMEOUT, bool show_background = true);
/**
* Simplified methodes to show hintboxes without titlebar and footer with mounted function as slot for custom action
* Text is UTF-8 encoded
* @param[in] Text
* @li expects type neutrino_locale_t or const char*
* @param[in] Slot
* @li expects sigc::slot<void>
* @li example:
* @li sigc::slot<void> sl = sigc::mem_fun(g_Plugins, &CPlugins::loadPlugins);\n
* ShowHintS(LOCALE_SERVICEMENU_GETPLUGINS_HINT, 1, true, &sl);
* @li or use a function with parameter(s):
* sigc::slot<void> sl = sigc::bind(sigc::mem_fun(*this, &CMyClass::foo), arg1, arg2, arg3, arg4);\n
* ShowHintS(LOCALE_SERVICEMENU_GETPLUGINS_HINT, 1, true, &sl);
* @param[in] timeout
* @li optional: expects type int as seconds, default = HINTBOX_DEFAULT_TIMEOUT (get from settings)
* @param[in] show_background
* @li optional: expects type bool, enable/disable backround paint, default = true
*/
int ShowHintS(const neutrino_locale_t Text, const sigc::slot<void> &Slot, int timeout = HINTBOX_DEFAULT_TIMEOUT, bool show_background = true);
int ShowHintS(const char * const Text, const sigc::slot<void> &Slot, int timeout = HINTBOX_DEFAULT_TIMEOUT, bool show_background = true);
int ShowHintS(const std::string &Text, const sigc::slot<void> &Slot, int timeout = HINTBOX_DEFAULT_TIMEOUT, bool show_background = true);
int ShowHintS(const hint_message_data_t &hint_data);
int ShowHintS(const std::vector<hint_message_data_t> &v_hint_data);
#endif #endif