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

@@ -371,17 +371,58 @@ class CHint : public CHintBox
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
* Text is UTF-8 encoded
* @param[in] Text
* @li expects type neutrino_locale_t or const char*
* @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
* @li optional: expects type bool, enable/disable backround paint, default = true
* @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 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