diff --git a/src/gui/osd_setup.cpp b/src/gui/osd_setup.cpp index 352afaf58..eb997466e 100644 --- a/src/gui/osd_setup.cpp +++ b/src/gui/osd_setup.cpp @@ -787,7 +787,7 @@ void COsdSetup::showOsdMenueColorSetup(CMenuWidget *menu_colors) { menu_colors->addIntroItems(LOCALE_COLORMENU_MENUCOLORS); - CMenuForwarder * mf = new CMenuDForwarder(LOCALE_COLORMENU_THEMESELECT, true, NULL, new CThemes(), NULL, CRCInput::RC_red); + CMenuForwarder * mf = new CMenuDForwarder(LOCALE_COLORMENU_THEMESELECT, true, NULL, CThemes::getInstance(), NULL, CRCInput::RC_red); mf->setHint("", LOCALE_MENU_HINT_THEME); menu_colors->addItem(mf); diff --git a/src/gui/themes.cpp b/src/gui/themes.cpp index a58a5afe8..49594ffd4 100644 --- a/src/gui/themes.cpp +++ b/src/gui/themes.cpp @@ -38,6 +38,7 @@ #include #include "widget/menue.h" #include +#include #include #include #include @@ -51,7 +52,7 @@ #include "themes.h" #define USERDIR "/var" THEMESDIR -#define FILE_PREFIX ".theme" +#define FILE_SUFFIX ".theme" static SNeutrinoTheme &t = g_settings.theme; CThemes::CThemes() : themefile('\t') @@ -61,15 +62,27 @@ CThemes::CThemes() hasThemeChanged = false; } +CThemes* CThemes::getInstance() +{ + static CThemes* th = NULL; + + if(!th) { + th = new CThemes(); + dprintf(DEBUG_DEBUG, "CThemes Instance created\n"); + } + return th; +} + int CThemes::exec(CMenuTarget* parent, const std::string & actionKey) { int res = menu_return::RETURN_REPAINT; if( !actionKey.empty() ) { - if (actionKey=="theme_neutrino") + if (actionKey=="default_theme") { - setupDefaultColors(); + if(!applyDefaultTheme()) + setupDefaultColors(); // fallback notifier = new CColorSetupNotifier(); notifier->changeNotify(NONEXISTANT_LOCALE, NULL); delete notifier; @@ -80,10 +93,10 @@ int CThemes::exec(CMenuTarget* parent, const std::string & actionKey) if ( strstr(themeFile.c_str(), "{U}") != 0 ) { themeFile.erase(0, 3); - readFile(((std::string)THEMESDIR_VAR + "/" + themeFile + FILE_PREFIX).c_str()); + readFile(((std::string)THEMESDIR_VAR + "/" + themeFile + FILE_SUFFIX).c_str()); } else - readFile(((std::string)THEMESDIR + "/" + themeFile + FILE_PREFIX).c_str()); + readFile(((std::string)THEMESDIR + "/" + themeFile + FILE_SUFFIX).c_str()); g_settings.theme_name = themeFile; } return res; @@ -157,7 +170,7 @@ int CThemes::Show() themes.addIntroItems(LOCALE_COLORTHEMEMENU_HEAD2); //set default theme - themes.addItem(new CMenuForwarder(LOCALE_COLORTHEMEMENU_NEUTRINO_THEME, true, NULL, this, "theme_neutrino", CRCInput::RC_red)); + themes.addItem(new CMenuForwarder(LOCALE_COLORTHEMEMENU_NEUTRINO_THEME, true, NULL, this, "default_theme", CRCInput::RC_red)); readThemes(themes); @@ -179,7 +192,7 @@ int CThemes::Show() int res = themes.exec(NULL, ""); if (!file_name.empty()) { - saveFile(((std::string)THEMESDIR_VAR + "/" + file_name + FILE_PREFIX).c_str()); + saveFile(((std::string)THEMESDIR_VAR + "/" + file_name + FILE_SUFFIX).c_str()); } if (hasThemeChanged) { @@ -231,6 +244,18 @@ void CThemes::saveFile(const char *themename) } } +bool CThemes::applyDefaultTheme() +{ + g_settings.theme_name = "Neutrino-3.0"; + std::string default_theme = THEMESDIR "/" + g_settings.theme_name + ".theme"; + if(themefile.loadConfig(default_theme)){ + getTheme(themefile); + return true; + } + dprintf(DEBUG_NORMAL, "[CThemes]\t[%s - %d], default neutrino theme [ %s ] not found\n", __func__, __LINE__, default_theme.c_str()); + return false; +} + // setup default Colors void CThemes::setupDefaultColors() { @@ -347,6 +372,9 @@ void CThemes::setTheme(CConfigFile &configfile) void CThemes::getTheme(CConfigFile &configfile) { + if (g_settings.theme_name.empty()) + applyDefaultTheme(); + t.menu_Head_alpha = configfile.getInt32( "menu_Head_alpha", 10 ); t.menu_Head_red = configfile.getInt32( "menu_Head_red", 0 ); t.menu_Head_green = configfile.getInt32( "menu_Head_green", 0 ); diff --git a/src/gui/themes.h b/src/gui/themes.h index 8919e3c29..4a6094fab 100644 --- a/src/gui/themes.h +++ b/src/gui/themes.h @@ -45,13 +45,15 @@ class CThemes : public CMenuTarget, CChangeObserver void readThemes(CMenuWidget &); void rememberOldTheme(bool remember); void move_userDir(); + bool applyDefaultTheme(); public: CThemes(); + static CThemes* getInstance(); void setupDefaultColors(); int exec(CMenuTarget* parent, const std::string & actionKey); - static void setTheme(CConfigFile &configfile); - static void getTheme(CConfigFile &configfile); + void setTheme(CConfigFile &configfile); + void getTheme(CConfigFile &configfile); }; #endif diff --git a/src/neutrino.cpp b/src/neutrino.cpp index 2803d8a91..c7db5e91d 100644 --- a/src/neutrino.cpp +++ b/src/neutrino.cpp @@ -363,8 +363,8 @@ int CNeutrinoApp::loadSetup(const char * fname) parentallocked = !access(NEUTRINO_PARENTALLOCKED_FILE, R_OK); //theme/color options - CThemes::getTheme(configfile); g_settings.theme_name = configfile.getString("theme_name",""); + CThemes::getInstance()->getTheme(configfile); //NI g_settings.inetradio_autostart = configfile.getInt32("inetradio_autostart" , 0); @@ -1234,8 +1234,8 @@ void CNeutrinoApp::saveSetup(const char * fname) } //theme/color options - configfile.getString( "theme_name",g_settings.theme_name ); - CThemes::setTheme(configfile); + CThemes::getInstance()->setTheme(configfile); + configfile.setString( "theme_name", g_settings.theme_name ); //NI configfile.setInt32("inetradio_autostart" , g_settings.inetradio_autostart);