From 5bf04504e3670c0bf8e2b2f08c2b705175aaf67b Mon Sep 17 00:00:00 2001 From: vanhofen Date: Sat, 4 Dec 2021 23:22:35 +0100 Subject: [PATCH] usermenu-setup: formatting code using astyle; some manual code nicenings Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/0c50377eeeff7c4016ce600502aff7683f2a0d84 Author: vanhofen Date: 2021-12-04 (Sat, 04 Dec 2021) Origin message was: ------------------ - usermenu-setup: formatting code using astyle; some manual code nicenings --- src/gui/user_menue_setup.cpp | 91 +++++++++++++++++++++--------------- src/gui/user_menue_setup.h | 22 ++++----- 2 files changed, 64 insertions(+), 49 deletions(-) diff --git a/src/gui/user_menue_setup.cpp b/src/gui/user_menue_setup.cpp index 2aff54bbb..3c779f62d 100644 --- a/src/gui/user_menue_setup.cpp +++ b/src/gui/user_menue_setup.cpp @@ -55,6 +55,7 @@ static bool usermenu_show = true; static bool usermenu_show_cam = true; // FIXME -- use hwcaps? + struct keyvals { const int key; @@ -86,23 +87,23 @@ static keyvals usermenu_items[] = { SNeutrinoSettings::ITEM_CLOCK, LOCALE_CLOCK_SWITCH_ON, usermenu_show }, { SNeutrinoSettings::ITEM_GAMES, LOCALE_MAINMENU_GAMES, usermenu_show }, { SNeutrinoSettings::ITEM_SCRIPTS, LOCALE_MAINMENU_SCRIPTS, usermenu_show }, - { SNeutrinoSettings::ITEM_ECMINFO, LOCALE_ECMINFO_SHOW, usermenu_show }, //NI - { SNeutrinoSettings::ITEM_CAMD_RESET, LOCALE_CAMD_RESET, usermenu_show }, //NI - { SNeutrinoSettings::ITEM_INFOICONS, LOCALE_INFOICONS_SWITCH_ON, usermenu_show }, //NI + { SNeutrinoSettings::ITEM_ECMINFO, LOCALE_ECMINFO_SHOW, usermenu_show }, + { SNeutrinoSettings::ITEM_CAMD_RESET, LOCALE_CAMD_RESET, usermenu_show }, + { SNeutrinoSettings::ITEM_INFOICONS, LOCALE_INFOICONS_SWITCH_ON, usermenu_show }, { SNeutrinoSettings::ITEM_YOUTUBE, LOCALE_MOVIEPLAYER_YTPLAYBACK, usermenu_show }, { SNeutrinoSettings::ITEM_FILEPLAY_VIDEO, LOCALE_MOVIEPLAYER_FILEPLAYBACK_VIDEO, usermenu_show }, { SNeutrinoSettings::ITEM_TOOLS, LOCALE_MAINMENU_TOOLS, usermenu_show }, - { SNeutrinoSettings::ITEM_LUA, LOCALE_MAINMENU_LUA, usermenu_show }, - { SNeutrinoSettings::ITEM_TUNER_RESTART, LOCALE_SERVICEMENU_RESTART_TUNER, usermenu_show }, //NI + { SNeutrinoSettings::ITEM_LUA, LOCALE_MAINMENU_LUA, usermenu_show }, + { SNeutrinoSettings::ITEM_TUNER_RESTART, LOCALE_SERVICEMENU_RESTART_TUNER, usermenu_show }, { SNeutrinoSettings::ITEM_HDDMENU, LOCALE_HDD_SETTINGS, usermenu_show }, { SNeutrinoSettings::ITEM_AUDIOPLAY, LOCALE_AUDIOPLAYER_NAME, usermenu_show }, { SNeutrinoSettings::ITEM_INETPLAY, LOCALE_INETRADIO_NAME, usermenu_show }, { SNeutrinoSettings::ITEM_NETSETTINGS, LOCALE_MAINSETTINGS_NETWORK, usermenu_show }, { SNeutrinoSettings::ITEM_LCD4LINUX, LOCALE_LCD4L_SUPPORT, usermenu_show }, { SNeutrinoSettings::ITEM_SWUPDATE, LOCALE_SERVICEMENU_UPDATE, usermenu_show }, - { SNeutrinoSettings::ITEM_LIVESTREAM_RESOLUTION,LOCALE_LIVESTREAM_RESOLUTION, usermenu_show }, + { SNeutrinoSettings::ITEM_LIVESTREAM_RESOLUTION, LOCALE_LIVESTREAM_RESOLUTION, usermenu_show }, { SNeutrinoSettings::ITEM_ADZAP, LOCALE_USERMENU_ITEM_ADZAP, usermenu_show }, - { SNeutrinoSettings::ITEM_TESTMENU, LOCALE_TESTMENU, usermenu_show }, //NI + { SNeutrinoSettings::ITEM_TESTMENU, LOCALE_TESTMENU, usermenu_show }, { SNeutrinoSettings::ITEM_FILEPLAY_AUDIO, LOCALE_MOVIEPLAYER_FILEPLAYBACK_AUDIO, usermenu_show }, { SNeutrinoSettings::ITEM_TIMESHIFT, LOCALE_RECORDINGMENU_TIMESHIFT, usermenu_show }, { SNeutrinoSettings::ITEM_MAX, NONEXISTANT_LOCALE, usermenu_show } @@ -115,10 +116,11 @@ CUserMenuSetup::CUserMenuSetup(neutrino_locale_t menue_title, int menue_button) max_char = 24; width = 40; if (menue_button < (int) g_settings.usermenu.size()) - pref_name = g_settings.usermenu[button]->title; //set current button name as prefered name + pref_name = g_settings.usermenu[button]->title; // set current button name as prefered name forwarder = NULL; - for (int i = 0; usermenu_items[i].key != SNeutrinoSettings::ITEM_MAX; i++) { + for (int i = 0; usermenu_items[i].key != SNeutrinoSettings::ITEM_MAX; i++) + { const char *loc = g_Locale->getText(usermenu_items[i].value); if (usermenu_items[i].show) options.push_back(loc); @@ -127,10 +129,12 @@ CUserMenuSetup::CUserMenuSetup(neutrino_locale_t menue_title, int menue_button) } int number_of_plugins = g_Plugins->getNumberOfPlugins(); - for (int count = 0; count < number_of_plugins; count++) { + for (int count = 0; count < number_of_plugins; count++) + { const char *loc = g_Plugins->getName(count); const char *key = g_Plugins->getFileName(count); - if (loc && *loc && key && *key) { + if (loc && *loc && key && *key) + { options.push_back(loc); keys[loc] = key; vals[keys[loc]] = loc; @@ -143,12 +147,14 @@ CUserMenuSetup::~CUserMenuSetup() { } -int CUserMenuSetup::exec(CMenuTarget* parent, const std::string &actionKey) +int CUserMenuSetup::exec(CMenuTarget *parent, const std::string &actionKey) { - if (actionKey == ">d") { + if (actionKey == ">d") + { int selected = ums->getSelected(); - if (selected >= item_offset) { - if(parent) + if (selected >= item_offset) + { + if (parent) parent->hide(); ums->removeItem(selected); ums->hide(); @@ -157,10 +163,11 @@ int CUserMenuSetup::exec(CMenuTarget* parent, const std::string &actionKey) return menu_return::RETURN_NONE; } - if(parent) + if (parent) parent->hide(); - if (actionKey == ">a") { + if (actionKey == ">a") + { int selected = ums->getSelected(); CMenuOptionStringChooser *c = new CMenuOptionStringChooser(std::string(""), NULL, true, NULL, CRCInput::RC_nokey, NULL, true); c->setOptions(options); @@ -176,23 +183,25 @@ int CUserMenuSetup::exec(CMenuTarget* parent, const std::string &actionKey) int res = showSetup(); checkButtonName(); - - return res; + + return res; } static neutrino_locale_t locals[SNeutrinoSettings::ITEM_MAX]; neutrino_locale_t CUserMenuSetup::getLocale(unsigned int key) { - if(key >= SNeutrinoSettings::ITEM_MAX){ + if (key >= SNeutrinoSettings::ITEM_MAX) + { key = SNeutrinoSettings::ITEM_NONE; } static bool initialized = false; - if (!initialized) { + if (!initialized) + { initialized = true; for (int i = 0; i < SNeutrinoSettings::ITEM_MAX; i++) locals[i] = NONEXISTANT_LOCALE; - for (int i = 0; usermenu_items[i].key != SNeutrinoSettings::ITEM_MAX; i++) + for (int i = 0; usermenu_items[i].key != SNeutrinoSettings::ITEM_MAX; i++) locals[usermenu_items[i].key] = usermenu_items[i].value; } return locals[key]; @@ -207,11 +216,12 @@ int CUserMenuSetup::showSetup() int old_key = g_settings.usermenu[button]->key; CKeyboardInput name(LOCALE_USERMENU_NAME, &g_settings.usermenu[button]->title); - CMenuForwarder * mf = new CMenuForwarder(LOCALE_USERMENU_NAME, true, NULL, &name); + CMenuForwarder *mf = new CMenuForwarder(LOCALE_USERMENU_NAME, true, NULL, &name); ums->addItem(mf); - if (button >= SNeutrinoSettings::BUTTON_MAX) { + if (button >= SNeutrinoSettings::BUTTON_MAX) + { CKeyChooser *kc = new CKeyChooser(&g_settings.usermenu[button]->key, LOCALE_USERMENU_KEY_SELECT, NEUTRINO_ICON_SETTINGS); CMenuDForwarder *kf = new CMenuDForwarder(LOCALE_USERMENU_KEY, true, kc->getKeyName(), kc); ums->addItem(kf); @@ -221,7 +231,8 @@ int CUserMenuSetup::showSetup() std::vector items = ::split(g_settings.usermenu[button]->items, ','); item_offset = ums->getItemsCount(); - for (std::vector::iterator it = items.begin(); it != items.end(); ++it) { + for (std::vector::iterator it = items.begin(); it != items.end(); ++it) + { CMenuOptionStringChooser *c = new CMenuOptionStringChooser(std::string(""), NULL, true, NULL, CRCInput::RC_nokey, NULL, true); c->setTitle(LOCALE_USERMENU_ITEMS); c->setOptions(options); @@ -229,7 +240,8 @@ int CUserMenuSetup::showSetup() ums->addItem(c); } - const struct button_label footerButtons[2] = { + const struct button_label footerButtons[2] = + { { NEUTRINO_ICON_BUTTON_RED, LOCALE_BOUQUETEDITOR_DELETE }, { NEUTRINO_ICON_BUTTON_GREEN, LOCALE_BOUQUETEDITOR_ADD } }; @@ -243,8 +255,9 @@ int CUserMenuSetup::showSetup() const char *delim = ""; g_settings.usermenu[button]->items = ""; std::string none = to_string(SNeutrinoSettings::ITEM_NONE); - for (int count = item_offset; count < items_end; count++) { - std::string lk = keys[static_cast(ums->getItem(count))->getOptionValue()]; + for (int count = item_offset; count < items_end; count++) + { + std::string lk = keys[static_cast(ums->getItem(count))->getOptionValue()]; if (lk == none) continue; g_settings.usermenu[button]->items += delim + lk; @@ -259,28 +272,30 @@ int CUserMenuSetup::showSetup() return res; } -//check button name for details like empty string and show an user message on issue +// check button name for details like empty string and show an user message on issue void CUserMenuSetup::checkButtonName() { - //count of configured items + // count of configured items int used_items = getUsedItemsCount(); - //warn if no items defined and reset menu name, if empty + // warn if no items defined and reset menu name, if empty if (used_items == 0) { - if (!g_settings.usermenu[button]->title.empty()){ - // DisplayInfoMessage(g_Locale->getText(LOCALE_USERMENU_MSG_WARNING_NO_ITEMS)); + if (!g_settings.usermenu[button]->title.empty()) + { + //DisplayInfoMessage(g_Locale->getText(LOCALE_USERMENU_MSG_WARNING_NO_ITEMS)); g_settings.usermenu[button]->title = ""; } - //exit function + // exit function return; } #if 0 - //if found only 1 configured item, ensure that the caption of usermenu is the same like this - if (used_items == 1) { + // if found only 1 configured item, ensure that the caption of usermenu is the same like this + if (used_items == 1) + { bool dummy; - g_settings.usermenu[button]->title = CUserMenu::getUserMenuButtonName(button, dummy); + g_settings.usermenu[button]->title = CUserMenu::getUserMenuButtonName(button, dummy); } #endif @@ -294,7 +309,7 @@ void CUserMenuSetup::checkButtonName() } } -//get count of used items +// get count of used items int CUserMenuSetup::getUsedItemsCount() { return ::split(g_settings.usermenu[button]->items, ',').size(); diff --git a/src/gui/user_menue_setup.h b/src/gui/user_menue_setup.h index 0bdeebf47..1c964be6e 100644 --- a/src/gui/user_menue_setup.h +++ b/src/gui/user_menue_setup.h @@ -45,22 +45,22 @@ typedef struct usermenu_props_t neutrino_locale_t menue_title; const int menue_button; const neutrino_msg_t DirectKey; - const char* IconName; + const char *IconName; neutrino_locale_t def_name; -}usermenu_props_struct_t; +} usermenu_props_struct_t; #define USERMENU_ITEMS_COUNT SNeutrinoSettings::BUTTON_MAX const struct usermenu_props_t usermenu[USERMENU_ITEMS_COUNT] = { - {LOCALE_USERMENU_BUTTON_RED , SNeutrinoSettings::BUTTON_RED , CRCInput::RC_red ,NEUTRINO_ICON_BUTTON_RED ,LOCALE_USERMENU_TITLE_RED }, - {LOCALE_USERMENU_BUTTON_GREEN , SNeutrinoSettings::BUTTON_GREEN , CRCInput::RC_green ,NEUTRINO_ICON_BUTTON_GREEN ,LOCALE_USERMENU_TITLE_GREEN }, - {LOCALE_USERMENU_BUTTON_YELLOW , SNeutrinoSettings::BUTTON_YELLOW , CRCInput::RC_yellow ,NEUTRINO_ICON_BUTTON_YELLOW ,LOCALE_USERMENU_TITLE_YELLOW }, - {LOCALE_USERMENU_BUTTON_BLUE , SNeutrinoSettings::BUTTON_BLUE , CRCInput::RC_blue ,NEUTRINO_ICON_BUTTON_BLUE ,LOCALE_USERMENU_TITLE_BLUE } + {LOCALE_USERMENU_BUTTON_RED , SNeutrinoSettings::BUTTON_RED , CRCInput::RC_red , NEUTRINO_ICON_BUTTON_RED , LOCALE_USERMENU_TITLE_RED }, + {LOCALE_USERMENU_BUTTON_GREEN , SNeutrinoSettings::BUTTON_GREEN , CRCInput::RC_green , NEUTRINO_ICON_BUTTON_GREEN , LOCALE_USERMENU_TITLE_GREEN }, + {LOCALE_USERMENU_BUTTON_YELLOW , SNeutrinoSettings::BUTTON_YELLOW , CRCInput::RC_yellow , NEUTRINO_ICON_BUTTON_YELLOW , LOCALE_USERMENU_TITLE_YELLOW }, + {LOCALE_USERMENU_BUTTON_BLUE , SNeutrinoSettings::BUTTON_BLUE , CRCInput::RC_blue , NEUTRINO_ICON_BUTTON_BLUE , LOCALE_USERMENU_TITLE_BLUE } }; class CUserMenuSetup : public CMenuTarget -{ +{ private: int width; int max_char; @@ -69,10 +69,10 @@ class CUserMenuSetup : public CMenuTarget std::string pref_name; neutrino_locale_t local; CMenuForwarder *forwarder; - CMenuWidget * ums; + CMenuWidget *ums; std::vector options; - std::map keys; - std::map vals; + std::map keys; + std::map vals; int showSetup(); void checkButtonName(); @@ -82,7 +82,7 @@ class CUserMenuSetup : public CMenuTarget ~CUserMenuSetup(); void setCaller(CMenuForwarder *fw) { forwarder = fw ; } int getUsedItemsCount(); - int exec(CMenuTarget* parent, const std::string & actionKey); + int exec(CMenuTarget *parent, const std::string &actionKey); static neutrino_locale_t getLocale(unsigned int i); };