diff --git a/src/gui/miscsettings_menu.cpp b/src/gui/miscsettings_menu.cpp index 61068e443..99576e520 100644 --- a/src/gui/miscsettings_menu.cpp +++ b/src/gui/miscsettings_menu.cpp @@ -565,7 +565,7 @@ int CMiscMenue::showMiscSettingsMenuOnlineServices() CMenuForwarder *mf = NULL; // tmdb - tmdb_onoff = new CMenuOptionChooser(LOCALE_TMDB_ENABLED, &g_settings.tmdb_enabled, OPTIONS_OFF0_ON1_OPTIONS, OPTIONS_OFF0_ON1_OPTION_COUNT, check_tmdb_api_key()); + tmdb_onoff = new CMenuOptionChooser(LOCALE_TMDB_ENABLED, &g_settings.tmdb_enabled, OPTIONS_OFF0_ON1_OPTIONS, OPTIONS_OFF0_ON1_OPTION_COUNT, CApiKey::check_tmdb_api_key()); tmdb_onoff->setHint(NEUTRINO_ICON_HINT_SETTINGS, LOCALE_MENU_HINT_TMDB_ENABLED); ms_oservices->addItem(tmdb_onoff); @@ -580,7 +580,7 @@ int CMiscMenue::showMiscSettingsMenuOnlineServices() #endif // omdb - omdb_onoff = new CMenuOptionChooser(LOCALE_IMDB_ENABLED, &g_settings.omdb_enabled, OPTIONS_OFF0_ON1_OPTIONS, OPTIONS_OFF0_ON1_OPTION_COUNT, check_omdb_api_key()); + omdb_onoff = new CMenuOptionChooser(LOCALE_IMDB_ENABLED, &g_settings.omdb_enabled, OPTIONS_OFF0_ON1_OPTIONS, OPTIONS_OFF0_ON1_OPTION_COUNT, CApiKey::check_omdb_api_key()); // omdb_onoff->setHint(NEUTRINO_ICON_HINT_SETTINGS, LOCALE_MENU_HINT_IMDB_ENABLED); ms_oservices->addItem(omdb_onoff); @@ -595,7 +595,7 @@ int CMiscMenue::showMiscSettingsMenuOnlineServices() #endif // youtube - youtube_onoff = new CMenuOptionChooser(LOCALE_YOUTUBE_ENABLED, &g_settings.youtube_enabled, OPTIONS_OFF0_ON1_OPTIONS, OPTIONS_OFF0_ON1_OPTION_COUNT, check_youtube_dev_id()); + youtube_onoff = new CMenuOptionChooser(LOCALE_YOUTUBE_ENABLED, &g_settings.youtube_enabled, OPTIONS_OFF0_ON1_OPTIONS, OPTIONS_OFF0_ON1_OPTION_COUNT, CApiKey::check_youtube_dev_id()); youtube_onoff->setHint(NEUTRINO_ICON_HINT_SETTINGS, LOCALE_MENU_HINT_YOUTUBE_ENABLED); ms_oservices->addItem(youtube_onoff); @@ -610,7 +610,7 @@ int CMiscMenue::showMiscSettingsMenuOnlineServices() #endif //shoutcast - shoutcast_onoff = new CMenuOptionChooser(LOCALE_SHOUTCAST_ENABLED, &g_settings.shoutcast_enabled, OPTIONS_OFF0_ON1_OPTIONS, OPTIONS_OFF0_ON1_OPTION_COUNT, check_shoutcast_dev_id()); + shoutcast_onoff = new CMenuOptionChooser(LOCALE_SHOUTCAST_ENABLED, &g_settings.shoutcast_enabled, OPTIONS_OFF0_ON1_OPTIONS, OPTIONS_OFF0_ON1_OPTION_COUNT, CApiKey::check_shoutcast_dev_id()); shoutcast_onoff->setHint(NEUTRINO_ICON_HINT_SETTINGS, LOCALE_MENU_HINT_SHOUTCAST_ENABLED); ms_oservices->addItem(shoutcast_onoff); @@ -709,39 +709,39 @@ bool CMiscMenue::changeNotify(const neutrino_locale_t OptionName, void * /*data* #endif else if (ARE_LOCALES_EQUAL(OptionName, LOCALE_TMDB_API_KEY)) { - g_settings.tmdb_enabled = g_settings.tmdb_enabled && check_tmdb_api_key(); + g_settings.tmdb_enabled = g_settings.tmdb_enabled && CApiKey::check_tmdb_api_key(); if (g_settings.tmdb_enabled) tmdb_api_key_short = g_settings.tmdb_api_key.substr(0, 8) + "..."; else tmdb_api_key_short.clear(); - tmdb_onoff->setActive(check_tmdb_api_key()); + tmdb_onoff->setActive(CApiKey::check_tmdb_api_key()); } else if (ARE_LOCALES_EQUAL(OptionName, LOCALE_IMDB_API_KEY)) { - g_settings.omdb_enabled = g_settings.omdb_enabled && check_omdb_api_key(); + g_settings.omdb_enabled = g_settings.omdb_enabled && CApiKey::check_omdb_api_key(); if (g_settings.omdb_enabled) omdb_api_key_short = g_settings.omdb_api_key.substr(0, 8) + "..."; else omdb_api_key_short.clear(); - omdb_onoff->setActive(check_omdb_api_key()); + omdb_onoff->setActive(CApiKey::check_omdb_api_key()); } else if (ARE_LOCALES_EQUAL(OptionName, LOCALE_YOUTUBE_DEV_ID)) { - g_settings.youtube_enabled = g_settings.youtube_enabled && check_youtube_dev_id(); + g_settings.youtube_enabled = g_settings.youtube_enabled && CApiKey::check_youtube_dev_id(); if (g_settings.youtube_enabled) youtube_dev_id_short = g_settings.youtube_dev_id.substr(0, 8) + "..."; else youtube_dev_id_short.clear(); - youtube_onoff->setActive(check_youtube_dev_id()); + youtube_onoff->setActive(CApiKey::check_youtube_dev_id()); } else if (ARE_LOCALES_EQUAL(OptionName, LOCALE_SHOUTCAST_DEV_ID)) { - g_settings.shoutcast_enabled = g_settings.shoutcast_enabled && check_shoutcast_dev_id(); + g_settings.shoutcast_enabled = g_settings.shoutcast_enabled && CApiKey::check_shoutcast_dev_id(); if (g_settings.shoutcast_enabled) shoutcast_dev_id_short = g_settings.shoutcast_dev_id.substr(0, 8) + "..."; else shoutcast_dev_id_short.clear(); - shoutcast_onoff->setActive(check_shoutcast_dev_id()); + shoutcast_onoff->setActive(CApiKey::check_shoutcast_dev_id()); } return ret; } diff --git a/src/neutrino.cpp b/src/neutrino.cpp index a09e59fd0..ec6af118c 100644 --- a/src/neutrino.cpp +++ b/src/neutrino.cpp @@ -881,19 +881,19 @@ int CNeutrinoApp::loadSetup(const char * fname) std::string yt_api_key = YT_DEV_KEY; g_settings.youtube_dev_id = configfile.getString("youtube_dev_id", yt_api_key.empty() ? "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" : yt_api_key); g_settings.youtube_enabled = configfile.getInt32("youtube_enabled", 1); - g_settings.youtube_enabled = g_settings.youtube_enabled && check_youtube_dev_id(); + g_settings.youtube_enabled = g_settings.youtube_enabled && CApiKey::check_youtube_dev_id(); std::string tmdb_api_key = TMDB_DEV_KEY; g_settings.tmdb_api_key = configfile.getString("tmdb_api_key", tmdb_api_key.empty() ? "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" : tmdb_api_key); g_settings.tmdb_enabled = configfile.getInt32("tmdb_enabled", 1); - g_settings.tmdb_enabled = g_settings.tmdb_enabled && check_tmdb_api_key(); + g_settings.tmdb_enabled = g_settings.tmdb_enabled && CApiKey::check_tmdb_api_key(); std::string omdb_api_key = OMDB_API_KEY; g_settings.omdb_api_key = configfile.getString("omdb_api_key", omdb_api_key.empty() ? "XXXXXXXX" : omdb_api_key); g_settings.omdb_enabled = configfile.getInt32("omdb_enabled", 1); - g_settings.omdb_enabled = g_settings.omdb_enabled && check_omdb_api_key(); + g_settings.omdb_enabled = g_settings.omdb_enabled && CApiKey::check_omdb_api_key(); std::string sc_api_key = SHOUTCAST_DEV_KEY; g_settings.shoutcast_dev_id = configfile.getString("shoutcast_dev_id", sc_api_key.empty() ? "XXXXXXXXXXXXXXXX" : sc_api_key); g_settings.shoutcast_enabled = configfile.getInt32("shoutcast_enabled", 1); - g_settings.shoutcast_enabled = g_settings.shoutcast_enabled && check_shoutcast_dev_id(); + g_settings.shoutcast_enabled = g_settings.shoutcast_enabled && CApiKey::check_shoutcast_dev_id(); //Filebrowser g_settings.filebrowser_showrights = configfile.getInt32("filebrowser_showrights", 1); diff --git a/src/system/setting_helpers.h b/src/system/setting_helpers.h index b1ec025b8..a3d94effa 100644 --- a/src/system/setting_helpers.h +++ b/src/system/setting_helpers.h @@ -150,14 +150,17 @@ class CAutoModeNotifier : public CChangeObserver bool changeNotify(const neutrino_locale_t, void * data); }; -//do we need a class? -int check_api_key(const std::string& api_key_setting, const std::string& api_key_pattern) +class CApiKey { - return ((api_key_setting != api_key_pattern) && !api_key_setting.empty()); -} -inline int check_shoutcast_dev_id() { return check_api_key(g_settings.shoutcast_dev_id, "XXXXXXXXXXXXXXXX"); } -inline int check_youtube_dev_id() { return check_api_key(g_settings.youtube_dev_id, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } -inline int check_tmdb_api_key() { return check_api_key(g_settings.tmdb_api_key, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } -inline int check_omdb_api_key() { return check_api_key(g_settings.omdb_api_key, "XXXXXXXX"); } + public: + static int check_api_key(const std::string& api_key_setting, const std::string& api_key_pattern) + { + return ((api_key_setting != api_key_pattern) && !api_key_setting.empty()); + } + static int check_shoutcast_dev_id() { return CApiKey::check_api_key(g_settings.shoutcast_dev_id, "XXXXXXXXXXXXXXXX"); } + static int check_youtube_dev_id() { return CApiKey::check_api_key(g_settings.youtube_dev_id, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } + static int check_tmdb_api_key() { return CApiKey::check_api_key(g_settings.tmdb_api_key, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } + static int check_omdb_api_key() { return CApiKey::check_api_key(g_settings.omdb_api_key, "XXXXXXXX"); } +}; #endif