diff --git a/data/locale/deutsch.locale b/data/locale/deutsch.locale index 7a7545314..74700bf24 100644 --- a/data/locale/deutsch.locale +++ b/data/locale/deutsch.locale @@ -1417,7 +1417,9 @@ moviebrowser.update_if_dest_empty_only Übernehmen nur wenn Ziel leer moviebrowser.use_dir Verzeichnis verwenden moviebrowser.use_movie_dir Wiedergabeverzeichnis verwenden moviebrowser.use_rec_dir Aufnahmeverzeichnis verwenden -moviebrowser.yt_concurrent_connections Gleichzeitige Verbindungen +moviebrowser.yt_concurrent_connections Gleichzeitige Verbindungen +moviebrowser.yt_history Frühere Suchen +moviebrowser.yt_max_history Max. Anzahl früherer Suchen moviebrowser.yt_error Fehler beim laden des Youtube Feed moviebrowser.yt_max_results Max. Anzahl der zu holenden Feeds moviebrowser.yt_most_discussed Am meisten diskutiert diff --git a/data/locale/english.locale b/data/locale/english.locale index a6b05c784..349246af0 100644 --- a/data/locale/english.locale +++ b/data/locale/english.locale @@ -1419,6 +1419,8 @@ moviebrowser.use_movie_dir Use movie directory moviebrowser.use_rec_dir Use record directory moviebrowser.yt_concurrent_connections Concurrent connections moviebrowser.yt_error Failed to load youtube feed +moviebrowser.yt_history Search history +moviebrowser.yt_max_history Max search history size moviebrowser.yt_max_results Max results to fetch moviebrowser.yt_most_discussed Most discussed moviebrowser.yt_most_popular Most popular diff --git a/src/gui/moviebrowser.cpp b/src/gui/moviebrowser.cpp index ea6d891f8..43bf819a2 100644 --- a/src/gui/moviebrowser.cpp +++ b/src/gui/moviebrowser.cpp @@ -778,6 +778,17 @@ bool CMovieBrowser::loadSettings(MB_SETTINGS* settings) settings->ytregion = configfile.getString("mb_ytregion", "default"); settings->ytsearch = configfile.getString("mb_ytsearch", ""); settings->ytvid = configfile.getString("mb_ytvid", ""); + settings->ytsearch_history_max = configfile.getInt32("mb_ytsearch_history_max", 10); + settings->ytsearch_history_size = configfile.getInt32("mb_ytsearch_history_size", 0); + if (settings->ytsearch_history_size > settings->ytsearch_history_max) + settings->ytsearch_history_size = settings->ytsearch_history_max; + settings->ytsearch_history.clear(); + for(int i = 0; i < settings->ytsearch_history_size; i++) { + std::string s = configfile.getString("mb_ytsearch_history_" + to_string(i)); + if (s != "") + settings->ytsearch_history.push_back(configfile.getString("mb_ytsearch_history_" + to_string(i), "")); + } + settings->ytsearch_history_size = settings->ytsearch_history.size(); return (result); } @@ -835,6 +846,15 @@ bool CMovieBrowser::saveSettings(MB_SETTINGS* settings) configfile.setString("mb_ytsearch", settings->ytsearch); configfile.setString("mb_ytvid", settings->ytvid); + settings->ytsearch_history_size = settings->ytsearch_history.size(); + if (settings->ytsearch_history_size > settings->ytsearch_history_max) + settings->ytsearch_history_size = settings->ytsearch_history_max; + configfile.setInt32("mb_ytsearch_history_max", settings->ytsearch_history_max); + configfile.setInt32("mb_ytsearch_history_size", settings->ytsearch_history_size); + std::list:: iterator it = settings->ytsearch_history.begin(); + for(int i = 0; i < settings->ytsearch_history_size; i++, ++it) + configfile.setString("mb_ytsearch_history_" + to_string(i), *it); + if (configfile.getModifiedFlag()) configfile.saveConfig(MOVIEBROWSER_SETTINGS_FILE); return (result); @@ -3639,6 +3659,55 @@ neutrino_locale_t CMovieBrowser::getFeedLocale(void) return ret; } +class CYTHistory : public CMenuTarget +{ + private: + int width; + int selected; + std::string *search; + MB_SETTINGS *settings; + public: + CYTHistory(MB_SETTINGS &_settings, std::string &_search); + int exec(CMenuTarget* parent, const std::string & actionKey); +}; + +CYTHistory::CYTHistory(MB_SETTINGS &_settings, std::string &_search) +{ + width = w_max (40, 10); + selected = -1; + settings = &_settings; + search = &_search; +} + +int CYTHistory::exec(CMenuTarget* parent, const std::string &actionKey) +{ + if (actionKey == "") { + if (parent) + parent->hide(); + CMenuWidget* m = new CMenuWidget(LOCALE_MOVIEBROWSER_YT_HISTORY, NEUTRINO_ICON_MOVIEPLAYER, width); + m->addKey(CRCInput::RC_spkr, this, "clear"); + m->setSelected(selected); + m->addItem(GenericMenuSeparator); + m->addItem(GenericMenuBack); + m->addItem(GenericMenuSeparatorLine); + std::list::iterator it = settings->ytsearch_history.begin(); + for (int i = 0; i < settings->ytsearch_history_size; i++, ++it) + m->addItem(new CMenuForwarderNonLocalized((*it).c_str(), true, NULL, this, (*it).c_str(), CRCInput::convertDigitToKey(i + 1))); + m->exec(NULL, ""); + m->hide(); + delete m; + return menu_return::RETURN_REPAINT; + } + if (actionKey == "clear") { + settings->ytsearch_history.clear(); + settings->ytsearch_history_size = 0; + return menu_return::RETURN_EXIT; + } + *search = actionKey; + g_RCInput->postMsg((neutrino_msg_t) CRCInput::RC_blue, 0); + return menu_return::RETURN_EXIT; +} + bool CMovieBrowser::showYTMenu() { m_pcWindow->paintBackground(); @@ -3663,18 +3732,23 @@ bool CMovieBrowser::showYTMenu() sprintf(cnt, "%d", cYTFeedParser::NEXT); mainMenu.addItem(new CMenuForwarder(LOCALE_MOVIEBROWSER_YT_NEXT_RESULTS, ytparser.HaveNext(), NULL, selector, cnt, CRCInput::RC_green, NEUTRINO_ICON_BUTTON_GREEN)); sprintf(cnt, "%d", cYTFeedParser::PREV); - mainMenu.addItem(new CMenuForwarder(LOCALE_MOVIEBROWSER_YT_PREV_RESULTS, ytparser.HavePrev(), NULL, selector, cnt, CRCInput::RC_yellow, NEUTRINO_ICON_BUTTON_YELLOW)); + mainMenu.addItem(new CMenuForwarder(LOCALE_MOVIEBROWSER_YT_PREV_RESULTS, ytparser.HavePrev(), NULL, selector, cnt, CRCInput::RC_nokey, "")); mainMenu.addItem(GenericMenuSeparatorLine); std::string search = m_settings.ytsearch; CStringInputSMS stringInput(LOCALE_MOVIEBROWSER_YT_SEARCH, &search, 20, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "abcdefghijklmnopqrstuvwxyz0123456789 -_/()<>=+.,:!?\\'"); - mainMenu.addItem(new CMenuForwarder(LOCALE_MOVIEBROWSER_YT_SEARCH, true, search, &stringInput, NULL, CRCInput::RC_nokey, "")); + mainMenu.addItem(new CMenuForwarder(LOCALE_MOVIEBROWSER_YT_SEARCH, true, search, &stringInput, NULL, CRCInput::RC_yellow, NEUTRINO_ICON_BUTTON_YELLOW)); sprintf(cnt, "%d", cYTFeedParser::SEARCH); mainMenu.addItem(new CMenuForwarder(LOCALE_EVENTFINDER_START_SEARCH, true, NULL, selector, cnt, CRCInput::RC_blue, NEUTRINO_ICON_BUTTON_BLUE)); + CYTHistory ytHistory(m_settings, search); + if (m_settings.ytsearch_history_size > 0) + mainMenu.addItem(new CMenuForwarder(LOCALE_MOVIEBROWSER_YT_HISTORY, true, NULL, &ytHistory, "", CRCInput::RC_0)); + mainMenu.addItem(GenericMenuSeparatorLine); mainMenu.addItem(new CMenuOptionNumberChooser(LOCALE_MOVIEBROWSER_YT_MAX_RESULTS, &m_settings.ytresults, true, 10, 50, NULL)); + mainMenu.addItem(new CMenuOptionNumberChooser(LOCALE_MOVIEBROWSER_YT_MAX_HISTORY, &m_settings.ytsearch_history_max, true, 10, 50, NULL)); char rstr[20]; sprintf(rstr, "%s", m_settings.ytregion.c_str()); @@ -3730,6 +3804,18 @@ bool CMovieBrowser::showYTMenu() reload = true; m_settings.ytsearch = search; m_settings.ytmode = newmode; + m_settings.ytsearch_history.push_front(search); + std::list::iterator it = m_settings.ytsearch_history.begin(); + it++; + while (it != m_settings.ytsearch_history.end()) { + if (*it == search) + it = m_settings.ytsearch_history.erase(it); + else + ++it; + } + m_settings.ytsearch_history_size = m_settings.ytsearch_history.size(); + if (m_settings.ytsearch_history_size > m_settings.ytsearch_history_max) + m_settings.ytsearch_history_size = m_settings.ytsearch_history_max; } } else if (m_settings.ytmode != newmode) { diff --git a/src/gui/moviebrowser.h b/src/gui/moviebrowser.h index 188eb95b5..2486bf0e5 100644 --- a/src/gui/moviebrowser.h +++ b/src/gui/moviebrowser.h @@ -73,6 +73,7 @@ #include #include +#include #include #include #include @@ -231,9 +232,12 @@ typedef struct int ytresults; int ytquality; int ytconcconn; + int ytsearch_history_size; + int ytsearch_history_max; std::string ytregion; std::string ytvid; std::string ytsearch; + std::list ytsearch_history; } MB_SETTINGS; // Priorities for Developmemt: P1: critical feature, P2: important feature, P3: for next release, P4: looks nice, lets see diff --git a/src/system/helpers.h b/src/system/helpers.h index 8bf4babfb..d9d4b6108 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -24,7 +24,8 @@ #include #include - +#include + int my_system(const char * cmd); int my_system(int argc, const char *arg, ...); /* argc is number of arguments including command */ @@ -64,4 +65,11 @@ class CFileHelpers }; +template std::string to_string(C i) +{ + std::stringstream s; + s << i; + return s.str(); +} + #endif diff --git a/src/system/locals.h b/src/system/locals.h index 50de8652c..1fd8f82cb 100644 --- a/src/system/locals.h +++ b/src/system/locals.h @@ -1446,6 +1446,8 @@ typedef enum LOCALE_MOVIEBROWSER_USE_REC_DIR, LOCALE_MOVIEBROWSER_YT_CONCURRENT_CONNECTIONS, LOCALE_MOVIEBROWSER_YT_ERROR, + LOCALE_MOVIEBROWSER_YT_HISTORY, + LOCALE_MOVIEBROWSER_YT_MAX_HISTORY, LOCALE_MOVIEBROWSER_YT_MAX_RESULTS, LOCALE_MOVIEBROWSER_YT_MOST_DISCUSSED, LOCALE_MOVIEBROWSER_YT_MOST_POPULAR, diff --git a/src/system/locals_intern.h b/src/system/locals_intern.h index 6b92fa3c9..18924eac2 100644 --- a/src/system/locals_intern.h +++ b/src/system/locals_intern.h @@ -1446,6 +1446,8 @@ const char * locale_real_names[] = "moviebrowser.use_rec_dir", "moviebrowser.yt_concurrent_connections", "moviebrowser.yt_error", + "moviebrowser.yt_history", + "moviebrowser.yt_max_history", "moviebrowser.yt_max_results", "moviebrowser.yt_most_discussed", "moviebrowser.yt_most_popular",