diff options
author | montellese <montellese@xbmc.org> | 2012-12-21 14:04:07 +0100 |
---|---|---|
committer | montellese <montellese@xbmc.org> | 2013-04-08 22:54:53 +0200 |
commit | 434de150b5868b54c0d08384c9d0ec3913e9cb30 (patch) | |
tree | a28a6e35514a9c4ff54899caa5c3e2101d028e9c | |
parent | af68086c80dc5dc89f9813764757910d8b3da3c9 (diff) |
CGUIDialogSmartPlaylistEditor: integrate group options
-rw-r--r-- | language/English/strings.po | 13 | ||||
-rw-r--r-- | xbmc/dialogs/GUIDialogSmartPlaylistEditor.cpp | 63 | ||||
-rw-r--r-- | xbmc/dialogs/GUIDialogSmartPlaylistEditor.h | 2 | ||||
-rw-r--r-- | xbmc/playlists/SmartPlayList.cpp | 120 | ||||
-rw-r--r-- | xbmc/playlists/SmartPlayList.h | 6 | ||||
-rw-r--r-- | xbmc/utils/DatabaseUtils.h | 1 |
6 files changed, 202 insertions, 3 deletions
diff --git a/language/English/strings.po b/language/English/strings.po index 8ccd55dc84..a571e4d316 100644 --- a/language/English/strings.po +++ b/language/English/strings.po @@ -9283,7 +9283,10 @@ msgctxt "#20417" msgid "Writer" msgstr "" -#empty string with id 20418 +#: xbmc/playlists/SmartPlayList.cpp +msgctxt "#20418" +msgid "Writers" +msgstr "" #: xbmc/settings/GUISettings.cpp msgctxt "#20419" @@ -9943,7 +9946,13 @@ msgctxt "#21457" msgid "Watched episode count" msgstr "" -#empty strings from id 21458 to 21459 +msgctxt "#21458" +msgid "Group by" +msgstr "" + +msgctxt "#21459" +msgid "mixed" +msgstr "" #: xbmc/settings/GUISettings.cpp msgctxt "#21460" diff --git a/xbmc/dialogs/GUIDialogSmartPlaylistEditor.cpp b/xbmc/dialogs/GUIDialogSmartPlaylistEditor.cpp index 3afb8823f1..451be19223 100644 --- a/xbmc/dialogs/GUIDialogSmartPlaylistEditor.cpp +++ b/xbmc/dialogs/GUIDialogSmartPlaylistEditor.cpp @@ -43,6 +43,8 @@ using namespace std; #define CONTROL_LIMIT 17 #define CONTROL_ORDER_FIELD 18 #define CONTROL_ORDER_DIRECTION 19 +#define CONTROL_GROUP_BY 23 +#define CONTROL_GROUP_MIXED 24 #define CONTROL_OK 20 #define CONTROL_CANCEL 21 @@ -118,6 +120,10 @@ bool CGUIDialogSmartPlaylistEditor::OnMessage(CGUIMessage& message) OnOrderDirection(); else if (iControl == CONTROL_TYPE) OnType(); + else if (iControl == CONTROL_GROUP_BY) + OnGroupBy(); + else if (iControl == CONTROL_GROUP_MIXED) + OnGroupMixed(); else return CGUIDialog::OnMessage(message); return true; @@ -241,6 +247,24 @@ void CGUIDialogSmartPlaylistEditor::OnOrderDirection() UpdateButtons(); } +void CGUIDialogSmartPlaylistEditor::OnGroupBy() +{ + CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), CONTROL_GROUP_BY); + OnMessage(msg); + m_playlist.SetGroup(CSmartPlaylistRule::TranslateGroup((Field)msg.GetParam1())); + + if (m_playlist.IsGroupMixed() && !CSmartPlaylistRule::CanGroupMix((Field)msg.GetParam1())) + m_playlist.SetGroupMixed(false); + + UpdateButtons(); +} + +void CGUIDialogSmartPlaylistEditor::OnGroupMixed() +{ + m_playlist.SetGroupMixed(!m_playlist.IsGroupMixed()); + UpdateButtons(); +} + void CGUIDialogSmartPlaylistEditor::UpdateButtons() { CONTROL_ENABLE(CONTROL_OK); // always enabled since we can have no rules -> match everything (as we do with default partymode playlists) @@ -304,6 +328,43 @@ void CGUIDialogSmartPlaylistEditor::UpdateButtons() CGUIMessage msg(GUI_MSG_ITEM_SELECT, GetID(), CONTROL_ORDER_FIELD, m_playlist.m_orderField); OnMessage(msg); } + + // setup groups + { + CGUIMessage msg(GUI_MSG_LABEL_RESET, GetID(), CONTROL_GROUP_BY); + OnMessage(msg); + } + vector<Field> groups = CSmartPlaylistRule::GetGroups(m_playlist.GetType()); + Field currentGroup = CSmartPlaylistRule::TranslateGroup(m_playlist.GetGroup()); + for (unsigned int i = 0; i < groups.size(); i++) + { + CGUIMessage msg(GUI_MSG_LABEL_ADD, GetID(), CONTROL_GROUP_BY, groups[i]); + msg.SetLabel(CSmartPlaylistRule::GetLocalizedGroup(groups[i])); + OnMessage(msg); + } + { + CGUIMessage msg(GUI_MSG_ITEM_SELECT, GetID(), CONTROL_GROUP_BY, currentGroup); + OnMessage(msg); + } + + if (m_playlist.IsGroupMixed()) + CONTROL_SELECT(CONTROL_GROUP_MIXED); + else + CONTROL_DESELECT(CONTROL_GROUP_MIXED); + + // disable the group controls if there's no group + // or only one group which can't be mixed + if (groups.size() == 0 || + (groups.size() == 1 && !CSmartPlaylistRule::CanGroupMix(groups[0]))) + { + CONTROL_DISABLE(CONTROL_GROUP_BY); + CONTROL_DISABLE(CONTROL_GROUP_MIXED); + } + else + { + CONTROL_ENABLE(CONTROL_GROUP_BY); + CONTROL_ENABLE_ON_CONDITION(CONTROL_GROUP_MIXED, CSmartPlaylistRule::CanGroupMix(currentGroup)); + } } void CGUIDialogSmartPlaylistEditor::UpdateRuleControlButtons() @@ -353,7 +414,6 @@ void CGUIDialogSmartPlaylistEditor::OnWindowLoaded() void CGUIDialogSmartPlaylistEditor::OnInitWindow() { m_cancelled = false; - UpdateButtons(); SendMessage(GUI_MSG_ITEM_SELECT, CONTROL_LIMIT, m_playlist.m_limit); @@ -401,6 +461,7 @@ void CGUIDialogSmartPlaylistEditor::OnInitWindow() SendMessage(GUI_MSG_ITEM_SELECT, CONTROL_TYPE, type); m_playlist.SetType(ConvertType(type)); + UpdateButtons(); CGUIDialog::OnInitWindow(); } diff --git a/xbmc/dialogs/GUIDialogSmartPlaylistEditor.h b/xbmc/dialogs/GUIDialogSmartPlaylistEditor.h index 98fa3ef72f..66fd1d70fb 100644 --- a/xbmc/dialogs/GUIDialogSmartPlaylistEditor.h +++ b/xbmc/dialogs/GUIDialogSmartPlaylistEditor.h @@ -51,6 +51,8 @@ protected: void OnType(); void OnOrder(); void OnOrderDirection(); + void OnGroupBy(); + void OnGroupMixed(); void OnOK(); void OnCancel(); void UpdateButtons(); diff --git a/xbmc/playlists/SmartPlayList.cpp b/xbmc/playlists/SmartPlayList.cpp index f07f17b4de..08205e3062 100644 --- a/xbmc/playlists/SmartPlayList.cpp +++ b/xbmc/playlists/SmartPlayList.cpp @@ -140,6 +140,31 @@ static const operatorField operators[] = { #define NUM_OPERATORS sizeof(operators) / sizeof(operatorField) +typedef struct +{ + std::string name; + Field field; + bool canMix; + int localizedString; +} group; + +static const group groups[] = { { "", FieldUnknown, false, 571 }, + { "none", FieldNone, false, 231 }, + { "sets", FieldSet, true, 20434 }, + { "genres", FieldGenre, false, 135 }, + { "years", FieldYear, false, 652 }, + { "actors", FieldActor, false, 344 }, + { "directors", FieldDirector, false, 20348 }, + { "writers", FieldWriter, false, 20418 }, + { "studios", FieldStudio, false, 20388 }, + { "countries", FieldCountry, false, 20451 }, + { "artists", FieldArtist, false, 133 }, + { "albums", FieldAlbum, false, 132 }, + { "tags", FieldTag, false, 20459 }, + }; + +#define NUM_GROUPS sizeof(groups) / sizeof(group) + CSmartPlaylistRule::CSmartPlaylistRule() { m_field = FieldNone; @@ -325,6 +350,28 @@ CStdString CSmartPlaylistRule::TranslateOperator(SEARCH_OPERATOR oper) return "contains"; } +Field CSmartPlaylistRule::TranslateGroup(const char *group) +{ + for (unsigned int i = 0; i < NUM_GROUPS; i++) + { + if (StringUtils::EqualsNoCase(group, groups[i].name)) + return groups[i].field; + } + + return FieldUnknown; +} + +CStdString CSmartPlaylistRule::TranslateGroup(Field group) +{ + for (unsigned int i = 0; i < NUM_GROUPS; i++) + { + if (group == groups[i].field) + return groups[i].name; + } + + return ""; +} + CStdString CSmartPlaylistRule::GetLocalizedField(Field field) { for (unsigned int i = 0; i < NUM_FIELDS; i++) @@ -619,6 +666,57 @@ std::vector<SortBy> CSmartPlaylistRule::GetOrders(const CStdString &type) return orders; } +std::vector<Field> CSmartPlaylistRule::GetGroups(const CStdString &type) +{ + vector<Field> groups; + groups.push_back(FieldUnknown); + + if (type == "artists") + groups.push_back(FieldGenre); + else if (type == "albums") + groups.push_back(FieldYear); + if (type == "movies") + { + groups.push_back(FieldNone); + groups.push_back(FieldSet); + groups.push_back(FieldGenre); + groups.push_back(FieldYear); + groups.push_back(FieldActor); + groups.push_back(FieldDirector); + groups.push_back(FieldWriter); + groups.push_back(FieldStudio); + groups.push_back(FieldCountry); + groups.push_back(FieldTag); + } + else if (type == "tvshows") + { + groups.push_back(FieldGenre); + groups.push_back(FieldYear); + groups.push_back(FieldActor); + groups.push_back(FieldDirector); + groups.push_back(FieldStudio); + groups.push_back(FieldTag); + } + else if (type == "episodes") + { + groups.push_back(FieldActor); + groups.push_back(FieldDirector); + groups.push_back(FieldWriter); + } + else if (type == "musicvideos") + { + groups.push_back(FieldArtist); + groups.push_back(FieldAlbum); + groups.push_back(FieldGenre); + groups.push_back(FieldYear); + groups.push_back(FieldDirector); + groups.push_back(FieldStudio); + groups.push_back(FieldTag); + } + + return groups; +} + CStdString CSmartPlaylistRule::GetLocalizedOperator(SEARCH_OPERATOR oper) { for (unsigned int i = 0; i < NUM_OPERATORS; i++) @@ -626,6 +724,28 @@ CStdString CSmartPlaylistRule::GetLocalizedOperator(SEARCH_OPERATOR oper) return g_localizeStrings.Get(16018); } +CStdString CSmartPlaylistRule::GetLocalizedGroup(Field group) +{ + for (unsigned int i = 0; i < NUM_GROUPS; i++) + { + if (group == groups[i].field) + return g_localizeStrings.Get(groups[i].localizedString); + } + + return g_localizeStrings.Get(groups[0].localizedString); +} + +bool CSmartPlaylistRule::CanGroupMix(Field group) +{ + for (unsigned int i = 0; i < NUM_GROUPS; i++) + { + if (group == groups[i].field) + return groups[i].canMix; + } + + return false; +} + CStdString CSmartPlaylistRule::GetLocalizedRule() const { CStdString rule; diff --git a/xbmc/playlists/SmartPlayList.h b/xbmc/playlists/SmartPlayList.h index 0aafe31e3c..4eb3a8fdab 100644 --- a/xbmc/playlists/SmartPlayList.h +++ b/xbmc/playlists/SmartPlayList.h @@ -86,11 +86,17 @@ public: static CStdString TranslateOrder(SortBy order); static CStdString GetField(Field field, const CStdString& strType); static CStdString TranslateOperator(SEARCH_OPERATOR oper); + static Field TranslateGroup(const char *group); + static CStdString TranslateGroup(Field group); static CStdString GetLocalizedField(Field field); static CStdString GetLocalizedOperator(SEARCH_OPERATOR oper); + static CStdString GetLocalizedGroup(Field group); + static bool CanGroupMix(Field group); + static std::vector<Field> GetFields(const CStdString &type); static std::vector<SortBy> GetOrders(const CStdString &type); + static std::vector<Field> GetGroups(const CStdString &type); static FIELD_TYPE GetFieldType(Field field); static bool IsFieldBrowseable(Field field); diff --git a/xbmc/utils/DatabaseUtils.h b/xbmc/utils/DatabaseUtils.h index e076c2276a..2127d5b067 100644 --- a/xbmc/utils/DatabaseUtils.h +++ b/xbmc/utils/DatabaseUtils.h @@ -35,6 +35,7 @@ namespace dbiplus typedef enum { // special fields used during sorting + FieldUnknown = -1, FieldNone = 0, FieldSort, // used to store the string to use for sorting FieldSortSpecial, // whether the item needs special handling (0 = no, 1 = sort on top, 2 = sort on bottom) |