From 5f8fd9b42e0ed6f8c17a91925ae4fff807359e08 Mon Sep 17 00:00:00 2001 From: thilo Date: Sat, 28 Jan 2012 15:28:13 +0000 Subject: [PATCH] *neutrino personalize: add observed option choosers in personalize menu Add new parameter 'observer_Item'. If you want to observe an item with another item (observer), then use this new prameter. Effect: While user sets an option of an observer item to 'visible' or 'pin-protected', the observed items are deactivated. git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-beta@2078 e54a6e83-5905-42d5-8d5c-058d10e6a962 --- src/gui/personalize.cpp | 136 +++++++++++++++++++++++++++++++++++----- src/gui/personalize.h | 30 ++++++--- 2 files changed, 140 insertions(+), 26 deletions(-) diff --git a/src/gui/personalize.cpp b/src/gui/personalize.cpp index 12880afee..7cec2bbb7 100644 --- a/src/gui/personalize.cpp +++ b/src/gui/personalize.cpp @@ -56,6 +56,8 @@ CMenuItem *menuItem = pointer to a menuitem object, can be forwarders, locked forwarders and separators...NO CHOOSERS! const int *personalize_mode = optional, default NULL, pointer to a specified personalize setting look at: PERSONALIZE_MODE, this regulates the personalize mode const bool item_mode = optional, default true, if you don't want to see this item in personalize menue, then set it to false + CMenuItem *observer_Item = optional, default NULL, if you want to observe this item with another item (observer), then use this prameter. + Effect: this observed item will be deactivated, if observer is set to 'visible' or 'pin-protected' Icon handling: If you define an icon in the item object, this will be shown in the personalized menu but not the personilazitions menue itself, otherwise a shortcut will be create @@ -203,14 +205,18 @@ CPersonalizeGui::CPersonalizeGui() shortcut = 1; show_usermenu = false; show_pin_setup = false; - pers_notifier = NULL; + user_menu_notifier = NULL; fkeyMenu = NULL; plMenu = NULL; + tmpW = NULL; + v_observ.clear(); + options_count = 0; } CPersonalizeGui::~CPersonalizeGui() { v_widget.clear(); + v_observ.clear(); } int CPersonalizeGui::exec(CMenuTarget* parent, const string & actionKey) @@ -310,7 +316,7 @@ int CPersonalizeGui::ShowPersonalizationMenu() delete fkeyMenu; delete plMenu; v_userMenuSetup.clear(); - delete pers_notifier; + delete user_menu_notifier; return res; } @@ -367,15 +373,15 @@ void CPersonalizeGui::ShowUserMenu(CMenuWidget* p_widget, vectoraddItem(new CMenuOptionChooser(usermenu[0].menue_title, &g_settings.personalize[SNeutrinoSettings::P_MAIN_RED_BUTTON], PERSONALIZE_ACTIVE_MODE_OPTIONS, PERSONALIZE_ACTIVE_MODE_MAX, true, pers_notifier));/*LOCALE_INFOVIEWER_EVENTLIST*/ + p_widget->addItem(new CMenuOptionChooser(usermenu[0].menue_title, &g_settings.personalize[SNeutrinoSettings::P_MAIN_RED_BUTTON], PERSONALIZE_ACTIVE_MODE_OPTIONS, PERSONALIZE_ACTIVE_MODE_MAX, true, user_menu_notifier));/*LOCALE_INFOVIEWER_EVENTLIST*/ //blue - p_widget->addItem(new CMenuOptionChooser(usermenu[3].menue_title, &g_settings.personalize[SNeutrinoSettings::P_MAIN_BLUE_BUTTON], PERSONALIZE_ACTIVE_MODE_OPTIONS, PERSONALIZE_ACTIVE_MODE_MAX, true, pers_notifier));/*LOCALE_INFOVIEWER_STREAMINFO*/ + p_widget->addItem(new CMenuOptionChooser(usermenu[3].menue_title, &g_settings.personalize[SNeutrinoSettings::P_MAIN_BLUE_BUTTON], PERSONALIZE_ACTIVE_MODE_OPTIONS, PERSONALIZE_ACTIVE_MODE_MAX, true, user_menu_notifier));/*LOCALE_INFOVIEWER_STREAMINFO*/ //add usermenu items p_widget->addItem(new CMenuSeparator(CMenuSeparator::ALIGN_RIGHT | CMenuSeparator::LINE | CMenuSeparator::STRING, LOCALE_USERMENU_NAME)); - pers_notifier->changeNotify(); + user_menu_notifier->changeNotify(); for (uint j = 0; jaddItem(v_umenu_fw[j]); @@ -413,9 +419,13 @@ void CPersonalizeGui::ShowMenuOptions(const int& widget) { string mn_name = v_widget[widget]->getName(); printf("[neutrino-personalize] exec %s...\n", __FUNCTION__); - + mn_widget_id_t w_index = widget+MN_WIDGET_ID_PERSONALIZE_MAIN; CMenuWidget* pm = new CMenuWidget(LOCALE_PERSONALIZE_HEAD, NEUTRINO_ICON_PERSONALIZE, width, w_index); + //reuqired in changeNotify() + options_count = 0; + tmpW = pm; + //************************* //subhead CMenuSeparator * pm_subhead = new CMenuSeparator(CMenuSeparator::ALIGN_LEFT | CMenuSeparator::SUB_HEAD | CMenuSeparator::STRING); @@ -435,10 +445,29 @@ void CPersonalizeGui::ShowMenuOptions(const int& widget) if (i_mode != PERSONALIZE_SHOW_NO) { + //add items to the options menu if (i_mode == PERSONALIZE_SHOW_AS_ITEM_OPTION) { if (v_item[i].personalize_mode != NULL) //option chooser - pm->addItem(new CMenuOptionChooser(v_item[i].locale_name, v_item[i].personalize_mode, PERSONALIZE_MODE_OPTIONS, PERSONALIZE_MODE_MAX, v_item[i].menuItem->active)); + { + //get locale name and personalize mode + neutrino_locale_t name = v_item[i].locale_name; + int* p_mode = v_item[i].personalize_mode; + + //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); + if (is_observer) + changeNotify(name, (void*)p_mode); + + //required for first view: check active mode of option chooser and disable if it's an observed item and item mode is set to 'not visible' + for (uint j = 0; j < v_observ.size(); j++) + if (opt->getOptionName()== g_Locale->getText(v_observ[j].to_observ_locale) && *p_mode == PERSONALIZE_MODE_NOTVISIBLE) + opt->setActive(false); + + pm->addItem(opt); //add option chooser + } else pm->addItem(v_item[i].menuItem); //separator } @@ -459,14 +488,76 @@ void CPersonalizeGui::ShowMenuOptions(const int& widget) pm->addItem(v_item[i].menuItem); } } + } - + options_count = pm->getItemsCount(); pm->exec (NULL, ""); pm->hide (); delete pm; } +//returns true, if found an observer item +bool CPersonalizeGui::isObserver(CMenuWidget* widget, CMenuItem *item) +{ + for (uint i = 0; i < v_observ.size(); i++) + { + if (v_observ[i].widget == widget) + { + CMenuForwarder* fw = static_cast (item); + if (fw->getTextLocale() == v_observ[i].observer_locale) + return true; + } + } + return false; +} + + +bool CPersonalizeGui::changeNotify(const neutrino_locale_t locale, void *data) +{ + int opt_val = *(int*) data; + + //exit if no options found + int opt_count = options_count; + if (opt_count == 0 && locale == NONEXISTANT_LOCALE) + return true; + + //if found an option and handle + for (int i = 0; i < opt_count; i++){ + + //get current item + CMenuItem* item = tmpW->getItem(i); + if (item->isMenueOptionChooser()) + { + //if found an optionchooser, then extract option name + CMenuOptionChooser* chooser = static_cast (item); + string opt_name = chooser->getOptionName(); + + for (uint j = 0; j < v_observ.size(); j++) + { + //if found the same option name for an observer item then... + if (locale == v_observ[j].observer_locale) + { + //...compare for observed item + if (opt_name == g_Locale->getText(v_observ[j].to_observ_locale)) + { + //and if found an observed item, then set properties + if (opt_val == PERSONALIZE_MODE_VISIBLE || opt_val == PERSONALIZE_MODE_PIN) + { + chooser->setActive(false); + chooser->setOptionValue(PERSONALIZE_MODE_NOTVISIBLE); + }else{ + chooser->setActive(true); + chooser->setOptionValue(PERSONALIZE_MODE_VISIBLE); + } + } + } + } + } + } + return true; +} + //shows a short help message void CPersonalizeGui::ShowHelpPersonalize() { @@ -539,6 +630,14 @@ int CPersonalizeGui::getWidgetId(CMenuWidget *widget) return -1; } +void CPersonalizeGui::addObservedItem(CMenuWidget *widget, CMenuItem* observer_Item, CMenuItem* to_observ_Item) +{ + CMenuForwarder *fw[2] = { static_cast (observer_Item), + static_cast (to_observ_Item)}; + observ_menu_item_t item = {widget, fw[0]->getTextLocale(), fw[1]->getTextLocale()}; + v_observ.push_back(item); +} + //adds non personalized menu intro items objects with separator, back button and separator line to menu without personalizing parameters void CPersonalizeGui::addIntroItems(const int& widget_id) @@ -555,17 +654,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) +void CPersonalizeGui::addItem(const int& widget_id, CMenuItem *menu_Item, const int *personalize_mode, const bool defaultselected, const int& item_mode, CMenuItem *observer_Item) { - addItem(v_widget[widget_id], menu_Item, personalize_mode, defaultselected, item_mode); + addItem(v_widget[widget_id], menu_Item, personalize_mode, defaultselected, item_mode, observer_Item); } //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) +void CPersonalizeGui::addItem(CMenuWidget *widget, CMenuItem *menu_Item, const int *personalize_mode, const bool defaultselected, const int& item_mode, CMenuItem *observer_Item) { + if (observer_Item != NULL) + addObservedItem(widget, observer_Item, menu_Item); + CMenuForwarder *fw = static_cast (menu_Item); - menu_item_t item = {widget, menu_Item, defaultselected, fw->getTextLocale(), (int*)personalize_mode, item_mode}; + menu_item_t item = {widget, menu_Item, defaultselected, fw->getTextLocale(), (int*)personalize_mode, item_mode, observer_Item}; if (item_mode == PERSONALIZE_SHOW_AS_ACCESS_OPTION) { @@ -592,8 +694,8 @@ void CPersonalizeGui::addSeparator(const int& widget_id, const neutrino_locale_t //expands with parameter within you can show or hide this item in personalize options void CPersonalizeGui::addSeparator(CMenuWidget &widget, const neutrino_locale_t locale_text, const int& item_mode) { - menu_item_t to_add_sep[2] = { {&widget, GenericMenuSeparatorLine, false, locale_text, NULL, item_mode}, - {&widget, new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, locale_text), false, locale_text, NULL, item_mode}}; + menu_item_t to_add_sep[2] = { {&widget, GenericMenuSeparatorLine, false, locale_text, NULL, item_mode, NULL}, + {&widget, new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, locale_text), false, locale_text, NULL, item_mode, NULL}}; if (locale_text == NONEXISTANT_LOCALE) v_item.push_back(to_add_sep[0]); @@ -776,13 +878,13 @@ void CPersonalizeGui::restoreSettings() //helper class to enable/disable some items in usermenu setup -CPersonalizeNotifier::CPersonalizeNotifier( CMenuItem* i1, CMenuItem* i2) +CUserMenuNotifier::CUserMenuNotifier( CMenuItem* i1, CMenuItem* i2) { toDisable[0]=i1; toDisable[1]=i2; } -bool CPersonalizeNotifier::changeNotify(const neutrino_locale_t, void *) +bool CUserMenuNotifier::changeNotify(const neutrino_locale_t, void *) { toDisable[0]->setActive(g_settings.personalize[SNeutrinoSettings::P_MAIN_RED_BUTTON]); toDisable[1]->setActive(g_settings.personalize[SNeutrinoSettings::P_MAIN_BLUE_BUTTON]); diff --git a/src/gui/personalize.h b/src/gui/personalize.h index c78ead1e4..6c9b79045 100644 --- a/src/gui/personalize.h +++ b/src/gui/personalize.h @@ -65,12 +65,12 @@ extern CPlugins * g_PluginList; /* neutrino.cpp */ //helper class to enable/disable some items in usermenu setup -class CPersonalizeNotifier : public CChangeObserver +class CUserMenuNotifier : public CChangeObserver { private: CMenuItem* toDisable[2]; public: - CPersonalizeNotifier( CMenuItem*, CMenuItem*); + CUserMenuNotifier( CMenuItem*, CMenuItem*); bool changeNotify(const neutrino_locale_t = NONEXISTANT_LOCALE, void *data = NULL); }; @@ -97,8 +97,16 @@ typedef struct menu_item_t neutrino_locale_t locale_name; int* personalize_mode; int item_mode; + CMenuItem *observer_Item; }menu_item_struct_t; +typedef struct observ_menu_item_t +{ + CMenuWidget *widget; + neutrino_locale_t observer_locale; + neutrino_locale_t to_observ_locale; +}observ_menu_item_struct_t; + typedef struct raw_item_t { CMenuItem* menuItem; @@ -114,14 +122,15 @@ typedef struct personalize_settings_t } personalize_settings_struct_t; -class CPersonalizeGui : public CMenuTarget +class CPersonalizeGui : public CMenuTarget, public CChangeObserver { private: - CPersonalizeNotifier *pers_notifier; + CUserMenuNotifier *user_menu_notifier; CMenuWidget* fkeyMenu; CMenuWidget* plMenu; + CMenuWidget* tmpW; - int width, widget_count, shortcut; + int width, widget_count, shortcut, options_count; bool show_usermenu, show_pin_setup; //stuff for settings handlers @@ -133,7 +142,8 @@ class CPersonalizeGui : public CMenuTarget std::vector v_item; std::vector v_widget; - + std::vector v_observ; + int ShowPersonalizationMenu(); void ShowMenuOptions(const int& menu); void ShowHelpPersonalize(); @@ -146,7 +156,9 @@ class CPersonalizeGui : public CMenuTarget bool hasPinItems(); neutrino_msg_t getShortcut(const int & shortcut_num, neutrino_msg_t alternate_rc_key = CRCInput::RC_nokey); - + void addObservedItem(CMenuWidget *widget, CMenuItem *observer_Item, CMenuItem *to_observ_Item); + bool changeNotify(const neutrino_locale_t locale= NONEXISTANT_LOCALE, void *data = NULL); + bool isObserver(CMenuWidget* widget, CMenuItem * item); public: //general options for personalized items enum PERSONALIZE_MODE @@ -211,8 +223,8 @@ class CPersonalizeGui : public CMenuTarget 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); - 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); + 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 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);