diff --git a/src/gui/personalize.cpp b/src/gui/personalize.cpp index 4d09a5513..7161a5c11 100644 --- a/src/gui/personalize.cpp +++ b/src/gui/personalize.cpp @@ -153,7 +153,7 @@ #include #include #include - +#include #include #include #include @@ -626,7 +626,7 @@ int CPersonalizeGui::ShowMenuOptions(const int& widget) //found observer item and if found, then define 'this' as observer for current option chooser and run changeNotify bool is_observer = isObserver(v_item[i].widget, v_item[i].menuItem) ? true : false; CChangeObserver* observer = is_observer ? this : NULL; - CMenuOptionChooser * opt = new CMenuOptionChooser(name, p_mode, PERSONALIZE_MODE_OPTIONS, PERSONALIZE_MODE_MAX, v_item[i].menuItem->active, observer); + CMenuOptionChooser * opt = new CMenuOptionChooser(name, p_mode, PERSONALIZE_MODE_OPTIONS, PERSONALIZE_MODE_MAX, v_item[i].menuItem->current_active, observer); if (is_observer) changeNotify(name, (void*)p_mode); @@ -830,20 +830,20 @@ void CPersonalizeGui::addIntroItems(CMenuWidget *widget) //overloaded version from 'addItem', first parameter is an id from widget collection 'v_widget' -void CPersonalizeGui::addItem(const int& widget_id, CMenuItem *menu_Item, const int *personalize_mode, const bool defaultselected, const int& item_mode, CMenuItem *observer_Item) +void CPersonalizeGui::addItem(const int& widget_id, CMenuItem *menu_Item, const int *personalize_mode, const bool defaultselected, const int& item_mode, CMenuItem *observer_Item, const menu_item_disable_cond_t& disable_condition) { - addItem(v_widget[widget_id], menu_Item, personalize_mode, defaultselected, item_mode, observer_Item); + addItem(v_widget[widget_id], menu_Item, personalize_mode, defaultselected, item_mode, observer_Item, disable_condition); } //adds a personalized menu item object to menu with personalizing parameters -void CPersonalizeGui::addItem(CMenuWidget *widget, CMenuItem *menu_Item, const int *personalize_mode, const bool defaultselected, const int& item_mode, CMenuItem *observer_Item) +void CPersonalizeGui::addItem(CMenuWidget *widget, CMenuItem *menu_Item, const int *personalize_mode, const bool defaultselected, const int& item_mode, CMenuItem *observer_Item, const menu_item_disable_cond_t& disable_condition) { if (observer_Item != NULL) addObservedItem(widget, observer_Item, menu_Item); - CMenuForwarder *fw = static_cast (menu_Item); + CMenuForwarder *fw = static_cast (menu_Item); - menu_item_t item = {widget, menu_Item, defaultselected, fw->getTextLocale(), (int*)personalize_mode, item_mode, observer_Item}; + menu_item_t item = {widget, menu_Item, defaultselected, fw->getTextLocale(), (int*)personalize_mode, item_mode, observer_Item, disable_condition}; if (item_mode == PERSONALIZE_SHOW_AS_ACCESS_OPTION) { @@ -871,10 +871,10 @@ void CPersonalizeGui::addSeparator(const int& widget_id, const neutrino_locale_t void CPersonalizeGui::addSeparator(CMenuWidget &widget, const neutrino_locale_t locale_text, const int& item_mode) { if (locale_text == NONEXISTANT_LOCALE) { - menu_item_t to_add_sep = {&widget, GenericMenuSeparatorLine, false, locale_text, NULL, item_mode, NULL}; + menu_item_t to_add_sep = {&widget, GenericMenuSeparatorLine, false, locale_text, NULL, item_mode, NULL, DCOND_MODE_NONE }; v_item.push_back(to_add_sep); } else { - menu_item_t to_add_sep = {&widget, new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, locale_text), false, locale_text, NULL, item_mode, NULL}; + menu_item_t to_add_sep = {&widget, new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, locale_text), false, locale_text, NULL, item_mode, NULL, DCOND_MODE_NONE }; v_item.push_back(to_add_sep); } } @@ -909,7 +909,7 @@ void CPersonalizeGui::addPersonalizedItems() //get current mode of personlize itself int in_pinmode = hasPinItems() ? PERSONALIZE_PROTECT_MODE_PIN_PROTECTED : PERSONALIZE_PROTECT_MODE_NOT_PROTECTED; - for (uint i = 0; i < v_item.size(); i++) + for (uint i = 0; i < v_item.size(); i++) { int i_mode = v_item[i].item_mode; @@ -939,6 +939,7 @@ void CPersonalizeGui::addPersonalizedItems() neutrino_msg_t d_key = fw->directKey; bool add_shortcut = false; + //get shortcut if (fw->active && (d_key == CRCInput::RC_nokey || CRCInput::isNumeric(d_key))) //if RC_nokey or RC_key is digi and item is active, allow to generate a shortcut, { @@ -965,6 +966,14 @@ void CPersonalizeGui::addPersonalizedItems() use_pin, fw->active, NULL, fw->getTarget(), fw->getActionKey(), d_key, NULL, lock_icon); v_item[i].menuItem->hintIcon = fw->hintIcon; v_item[i].menuItem->hint = fw->hint; + + //assign slot for items, causes disable/enable by condition eg: receiver mode + if (v_item[i].condition != DCOND_MODE_NONE ){ + sigc::slot0 sl = sigc::bind<0>(sigc::mem_fun1(v_item[i].menuItem, &CMenuForwarder::disableByCondition), v_item[i].condition); + v_item[i].menuItem->OnPaintItem.connect(sl); + v_item[i].default_selected = false; + } + //add item if it's set to visible or pin protected and allow to add an forwarder as next if (p_mode != PERSONALIZE_MODE_NOTVISIBLE || i_mode == PERSONALIZE_SHOW_AS_ACCESS_OPTION) { diff --git a/src/gui/personalize.h b/src/gui/personalize.h index fb84f80b5..0ffcb24f9 100644 --- a/src/gui/personalize.h +++ b/src/gui/personalize.h @@ -111,6 +111,7 @@ typedef struct menu_item_t int* personalize_mode; int item_mode; CMenuItem *observer_Item; + int condition; }menu_item_struct_t; typedef struct observ_menu_item_t @@ -242,8 +243,8 @@ class CPersonalizeGui : public CMenuTarget, public CChangeObserver, public CPINP int getItemsCount(CMenuWidget *widget); int getItemsCount(const int& widget_id); void setShortcut(const int& short_cut = 1) {shortcut = short_cut;}; - void addItem(CMenuWidget *widget, CMenuItem *menu_Item, const int *personalize_mode = NULL, const bool defaultselected = false, const int& item_mode = PERSONALIZE_SHOW_AS_ITEM_OPTION, CMenuItem *observer_Item = NULL); - void addItem(const int& widget_id, CMenuItem *menu_Item, const int *personalize_mode = NULL, const bool defaultselected = false, const int& item_mode = PERSONALIZE_SHOW_AS_ITEM_OPTION, CMenuItem *observer_Item = NULL); + void addItem(CMenuWidget *widget, CMenuItem *menu_Item, const int *personalize_mode = NULL, const bool defaultselected = false, const int& item_mode = PERSONALIZE_SHOW_AS_ITEM_OPTION, CMenuItem *observer_Item = NULL, const menu_item_disable_cond_t& disable_condition = DCOND_MODE_NONE ); + void addItem(const int& widget_id, CMenuItem *menu_Item, const int *personalize_mode = NULL, const bool defaultselected = false, const int& item_mode = PERSONALIZE_SHOW_AS_ITEM_OPTION, CMenuItem *observer_Item = NULL, const menu_item_disable_cond_t& disable_condition = DCOND_MODE_NONE ); void addIntroItems(CMenuWidget *widget); void addIntroItems(const int& widget_id); void addSeparator(CMenuWidget &menu, const neutrino_locale_t locale_text = NONEXISTANT_LOCALE, const int& item_mode = PERSONALIZE_SHOW_AS_ITEM_OPTION); diff --git a/src/gui/widget/menue.cpp b/src/gui/widget/menue.cpp index 0f116080a..eae54ebe1 100644 --- a/src/gui/widget/menue.cpp +++ b/src/gui/widget/menue.cpp @@ -59,7 +59,7 @@ CMenuForwarder * const GenericMenuNext = &CGenericMenuNext; CMenuItem::CMenuItem(bool Active, neutrino_msg_t DirectKey, const char * const IconName, const char * const IconName_Info_right, bool IsStatic) { - active = Active; + active = current_active = Active; directKey = DirectKey; isStatic = IsStatic; @@ -89,6 +89,7 @@ CMenuItem::CMenuItem(bool Active, neutrino_msg_t DirectKey, const char * const I selected_iconName = NULL; height = 0; actObserv = NULL; + parent_widget = NULL; } void CMenuItem::init(const int X, const int Y, const int DX, const int OFFX) @@ -104,7 +105,7 @@ void CMenuItem::init(const int X, const int Y, const int DX, const int OFFX) void CMenuItem::setActive(const bool Active) { - active = Active; + active = current_active = Active; /* used gets set by the addItem() function. This is for disabling machine-specific options by just not calling the addItem() function. Without this, the changeNotifiers would become machine-dependent. */ @@ -112,6 +113,48 @@ void CMenuItem::setActive(const bool Active) paint(); } +bool CMenuItem::initModeCondition(const int& stb_mode) +{ + if (CNeutrinoApp::getInstance()->getMode() == stb_mode){ + active = false; + marked = false; + if (parent_widget) + if (!isSelectable()) + parent_widget->initSelectable(); + return true; + } + printf("\033[33m[CMenuItem] [%s - %d] missmatching stb mode condition \033[0m\n", __func__, __LINE__, stb_mode); + return false; +} + +void CMenuItem::disableByCondition(const menu_item_disable_cond_t& condition) +{ + int stb_mode = CNeutrinoApp::getInstance()->getMode(); + + if (condition & DCOND_MODE_TS){ + if (stb_mode == CNeutrinoApp::mode_ts) + if (initModeCondition(stb_mode)) + return; + } + if (condition & DCOND_MODE_RADIO){ + if (stb_mode == CNeutrinoApp::mode_radio) + if (initModeCondition(stb_mode)) + return; + } + if (condition & DCOND_MODE_TV){ + if (stb_mode == CNeutrinoApp::mode_tv) + if (initModeCondition(stb_mode)) + return; + } + + active = current_active; + + if (parent_widget){ + if (!isSelectable()) + parent_widget->initSelectable(); + } +} + void CMenuItem::setMarked(const bool Marked) { marked = Marked; @@ -605,6 +648,7 @@ void CMenuWidget::addItem(CMenuItem* menuItem, const bool defaultselected) menuItem->isUsed(); items.push_back(menuItem); + menuItem->setParentWidget(this); } void CMenuWidget::resetWidget(bool delete_items) @@ -668,12 +712,7 @@ int CMenuWidget::exec(CMenuTarget* parent, const std::string &) neutrino_msg_data_t data; bool bAllowRepeatLR = false; CVFD::MODES oldLcdMode = CVFD::getInstance()->getMode(); - - int pos = 0; - if (selected > 0 && selected < (int)items.size()) - pos = selected; - else - selected = -1; + exit_pressed = false; frameBuffer->Lock(); @@ -693,21 +732,22 @@ int CMenuWidget::exec(CMenuTarget* parent, const std::string &) } } } - /* make sure we start with a selectable item... */ - while (pos < (int)items.size()) { - if (items[pos]->isSelectable()) - break; - pos++; - } + checkHints(); if(savescreen) { calcSize(); saveScreen(); } + + /* make sure we start with a selectable item... */ + initSelectable(); + paint(); frameBuffer->blit(); + int pos = selected; + int retval = menu_return::RETURN_REPAINT; uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings::TIMING_MENU]); @@ -1132,6 +1172,22 @@ void CMenuWidget::calcSize() setMenuPos(full_width); } +void CMenuWidget::initSelectable() +{ + int pos = 0; + if (selected > 0 && selected < (int)items.size()) + pos = selected; + else + selected = -1; + + while (pos < (int)items.size()) { + if (items[pos]->isSelectable()) + break; + pos++; + } + selected = pos; +} + void CMenuWidget::paint() { calcSize(); @@ -1218,16 +1274,16 @@ void CMenuWidget::paintItems() * different height and this might leave artifacts otherwise after changing pages */ frameBuffer->paintBoxRel(x,item_start_y, width,item_height, COL_MENUCONTENT_PLUS_0); } + int ypos=item_start_y; for (int count = 0; count < (int)items.size(); count++) { CMenuItem* item = items[count]; - + item->OnPaintItem(); if ((count >= page_start[current_page]) && (count < page_start[current_page + 1])) { item->init(x, ypos, width, iconOffset); - if (item->isSelectable() && selected == -1) selected = count; @@ -2124,7 +2180,8 @@ std::string CMenuForwarder::getOption(void) int CMenuForwarder::paint(bool selected) { - std::string option_name = getOption(); + std::string option_name = getOption(); + fb_pixel_t bgcol = 0; if (jumpTarget) bgcol = jumpTarget->getColor(); @@ -2137,7 +2194,7 @@ int CMenuForwarder::paint(bool selected) //caption paintItemCaption(selected, option_name.c_str(), bgcol); - + return y+ height; } diff --git a/src/gui/widget/menue.h b/src/gui/widget/menue.h index 3fb863451..1d55bfbab 100644 --- a/src/gui/widget/menue.h +++ b/src/gui/widget/menue.h @@ -56,7 +56,8 @@ extern "C" { #define NO_WIDGET_ID -1 typedef int mn_widget_id_t; - +typedef int menu_item_disable_cond_t; +class CMenuWidget; struct menu_return { enum @@ -69,6 +70,15 @@ struct menu_return }; }; +enum +{ + DCOND_MODE_NONE = 1, + + DCOND_MODE_TV = 2, + DCOND_MODE_RADIO = 4, + DCOND_MODE_TS = 8 +}/*menu_item_disable_cond_t*/; + class CChangeObserver { public: @@ -104,15 +114,16 @@ class CMenuTarget virtual fb_pixel_t getColor(void) { return 0; } }; -class CMenuItem +class CMenuItem : public CComponentsSignals { private: void setIconName(); + CMenuWidget* parent_widget; protected: int x, y, dx, offx, name_start_x, icon_frame_w; bool used; fb_pixel_t item_color, item_bgcolor; - + bool initModeCondition(const int& stb_mode); void initItemColors(const bool select_mode); lua_State *luaState; std::string luaAction; @@ -124,7 +135,7 @@ class CMenuItem CActivateObserver * actObserv; public: int height; - bool active; + bool active, current_active; bool marked; bool inert; bool isStatic; @@ -157,7 +168,7 @@ class CMenuItem } virtual int getYPosition(void) const { return y; } - virtual bool isSelectable(void) const { return active; } + virtual bool isSelectable(void) const { return (active && current_active); } virtual int exec(CMenuTarget* /*parent*/) { @@ -166,9 +177,9 @@ class CMenuItem virtual void setActive(const bool Active); virtual void setMarked(const bool Marked); virtual void setInert(const bool Inert); - + virtual void paintItemButton(const bool select_mode, int item_height, const char * const icon_Name = NEUTRINO_ICON_BUTTON_RIGHT); - + virtual void prepareItem(const bool select_mode, const int &item_height); virtual void setItemButton(const char * const icon_Name, const bool is_select_button = false); @@ -180,17 +191,20 @@ class CMenuItem virtual int isMenueOptionChooser(void) const{return 0;} void setHint(const char * const icon, const neutrino_locale_t text) { hintIcon = (icon && *icon) ? icon : NULL; hint = text; } void setHint(const char * const icon, const std::string text) { hintIcon = (icon && *icon) ? icon : NULL; hintText = text; } + void setLua(lua_State *_luaState, std::string &_luaAction, std::string &_luaId) { luaState = _luaState; luaAction = _luaAction; luaId = _luaId; }; virtual const char *getName(); virtual void setName(const std::string& text); virtual void setName(const neutrino_locale_t text); - + sigc::signal OnPaintItem; virtual const char *getDescription(); virtual void setDescription(const std::string& text); virtual void setDescription(const neutrino_locale_t text); virtual int getDescriptionHeight(void); void setActivateObserver(CActivateObserver * Observ) { actObserv = Observ; } void activateNotify(void); + virtual void disableByCondition(const menu_item_disable_cond_t& condition); + void setParentWidget(CMenuWidget* parent){parent_widget = parent;} }; class CMenuSeparator : public CMenuItem @@ -355,7 +369,7 @@ struct CMenuOptionChooserCompareItem: public std::binary_function setHint(NEUTRINO_ICON_HINT_TVMODE, LOCALE_MENU_HINT_TVMODE); - personalize.addItem(MENU_MAIN, tvswitch, &g_settings.personalize[SNeutrinoSettings::P_MAIN_TV_MODE], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ITEM_OPTION, tvradio_switch); //observed + personalize.addItem(MENU_MAIN, tvswitch, &g_settings.personalize[SNeutrinoSettings::P_MAIN_TV_MODE], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ITEM_OPTION, tvradio_switch, DCOND_MODE_TV | DCOND_MODE_TS); //observed //radio-mode CMenuForwarder *radioswitch = new CMenuForwarder(LOCALE_MAINMENU_RADIOMODE, true, NULL, this, "radio", CRCInput::RC_green); radioswitch->setHint(NEUTRINO_ICON_HINT_RADIOMODE, LOCALE_MENU_HINT_RADIOMODE); - personalize.addItem(MENU_MAIN, radioswitch, &g_settings.personalize[SNeutrinoSettings::P_MAIN_RADIO_MODE], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ITEM_OPTION, tvradio_switch); //observed + personalize.addItem(MENU_MAIN, radioswitch, &g_settings.personalize[SNeutrinoSettings::P_MAIN_RADIO_MODE], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ITEM_OPTION, tvradio_switch, DCOND_MODE_RADIO | DCOND_MODE_TS); //observed } //timer @@ -237,12 +237,12 @@ void CNeutrinoApp::InitMenuMain() // settings, also as pin protected option in personalize menu, as a result of parameter value CPersonalizeGui::PERSONALIZE_SHOW_AS_ACCESS_OPTION mf = new CMenuForwarder(LOCALE_MAINMENU_SETTINGS, true, NULL, &personalize.getWidget(MENU_SETTINGS)/**settings**/); mf->setHint(NEUTRINO_ICON_HINT_SETTINGS, LOCALE_MENU_HINT_SETTINGS); - personalize.addItem(MENU_MAIN, mf, &g_settings.personalize[SNeutrinoSettings::P_MAIN_SETTINGS], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ACCESS_OPTION); + personalize.addItem(MENU_MAIN, mf, &g_settings.personalize[SNeutrinoSettings::P_MAIN_SETTINGS], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ACCESS_OPTION, NULL, DCOND_MODE_TS); // service, also as pin protected option in personalize menu, as a result of parameter value CPersonalizeGui::PERSONALIZE_SHOW_AS_ACCESS_OPTION mf = new CMenuForwarder(LOCALE_MAINMENU_SERVICE, true, NULL, &personalize.getWidget(MENU_SERVICE)); mf->setHint(NEUTRINO_ICON_HINT_SERVICE, LOCALE_MENU_HINT_SERVICE); - personalize.addItem(MENU_MAIN, mf, &g_settings.personalize[SNeutrinoSettings::P_MAIN_SERVICE], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ACCESS_OPTION); + personalize.addItem(MENU_MAIN, mf, &g_settings.personalize[SNeutrinoSettings::P_MAIN_SERVICE], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ACCESS_OPTION, NULL, DCOND_MODE_TS); //separator personalize.addSeparator(MENU_MAIN);