added: Smartplaylists for tvshows and episodes. Needs decent testing + cleanup.
[xbmc:xbmc-antiquated.git] / xbmc / SmartPlaylist.h
1 #pragma once
2
3 #include "StdString.h"
4 #include "tinyXML/tinyxml.h"
5 #include <vector>
6
7 class CSmartPlaylistRule
8 {
9 public:
10   CSmartPlaylistRule();
11
12   enum DATABASE_FIELD { FIELD_NONE = 0,
13                         FIELD_GENRE = 1,
14                         SONG_ALBUM,
15                         SONG_ARTIST,
16                         SONG_ALBUM_ARTIST,
17                         FIELD_TITLE,
18                         FIELD_YEAR,
19                         FIELD_TIME,
20                         SONG_TRACKNUMBER,
21                         SONG_FILENAME,
22                         FIELD_PLAYCOUNT,
23                         SONG_LASTPLAYED,
24                         FIELD_RATING,
25                         SONG_COMMENT,
26                         FIELD_DATEADDED,
27                         VIDEO_PLOT,
28                         TVSHOW_STATUS,
29                         VIDEO_VOTES,
30                         VIDEO_DIRECTOR,
31                         VIDEO_ACTOR,
32                         TVSHOW_NUMEPISODES,
33                         TVSHOW_NUMWATCHED,
34                         EPISODE_WRITER,
35                         EPISODE_AIRDATE,
36                         EPISODE_EPISODE,
37                         EPISODE_SEASON,
38                         FIELD_PLAYLIST,
39                         FIELD_RANDOM
40                       };
41
42   enum SEARCH_OPERATOR { OPERATOR_START = 0,
43                          OPERATOR_CONTAINS,
44                          OPERATOR_DOES_NOT_CONTAIN,
45                          OPERATOR_EQUALS,
46                          OPERATOR_DOES_NOT_EQUAL,
47                          OPERATOR_STARTS_WITH,
48                          OPERATOR_ENDS_WITH,
49                          OPERATOR_GREATER_THAN,
50                          OPERATOR_LESS_THAN,
51                          OPERATOR_AFTER,
52                          OPERATOR_BEFORE,
53                          OPERATOR_IN_THE_LAST,
54                          OPERATOR_NOT_IN_THE_LAST,
55                          OPERATOR_END
56                        };
57
58   CStdString GetWhereClause(const CStdString& strType);
59   void TranslateStrings(const char *field, const char *oper, const char *parameter);
60   static DATABASE_FIELD TranslateField(const char *field);
61   static CStdString     TranslateField(DATABASE_FIELD field);
62   static CStdString     GetDatabaseField(DATABASE_FIELD field, const CStdString& strType);
63   static CStdString     TranslateOperator(SEARCH_OPERATOR oper);
64
65   static CStdString     GetLocalizedField(DATABASE_FIELD field);
66   static CStdString     GetLocalizedOperator(SEARCH_OPERATOR oper);
67   static std::vector<DATABASE_FIELD> GetFields(const CStdString &type);
68
69   CStdString            GetLocalizedRule();
70
71   TiXmlElement GetAsElement();
72
73   DATABASE_FIELD     m_field;
74   SEARCH_OPERATOR    m_operator;
75   CStdString         m_parameter;
76 private:
77   SEARCH_OPERATOR    TranslateOperator(const char *oper);
78 };
79
80 class CSmartPlaylist
81 {
82 public:
83   CSmartPlaylist();
84
85   bool Load(const CStdString &path);
86   bool Save(const CStdString &path);
87
88   TiXmlElement *OpenAndReadName(const CStdString &path);
89
90   void SetName(const CStdString &name);
91   void SetType(const CStdString &type); // music, video, mixed
92   const CStdString& GetName() const { return m_playlistName; };
93   const CStdString& GetType() const { return m_playlistType; };
94
95   void SetMatchAllRules(bool matchAll) { m_matchAllRules = matchAll; };
96   bool GetMatchAllRules() const { return m_matchAllRules; };
97
98   void SetLimit(unsigned int limit) { m_limit = limit; };
99   unsigned int GetLimit() const { return m_limit; };
100
101   void SetOrder(CSmartPlaylistRule::DATABASE_FIELD order) { m_orderField = order; };
102   CSmartPlaylistRule::DATABASE_FIELD GetOrder() const { return m_orderField; };
103
104   void SetOrderAscending(bool orderAscending) { m_orderAscending = orderAscending; };
105   bool GetOrderAscending() const { return m_orderAscending; };
106
107   void AddRule(const CSmartPlaylistRule &rule);
108   CStdString GetWhereClause(bool needWhere = true);
109   CStdString GetOrderClause();
110
111   const std::vector<CSmartPlaylistRule> &GetRules() const;
112
113 private:
114   friend class CGUIDialogSmartPlaylistEditor;
115
116   std::vector<CSmartPlaylistRule> m_playlistRules;
117   CStdString m_playlistName;
118   CStdString m_playlistType;
119   bool m_matchAllRules;
120   // order information
121   unsigned int m_limit;
122   CSmartPlaylistRule::DATABASE_FIELD m_orderField;
123   bool m_orderAscending;
124
125   TiXmlDocument m_xmlDoc;
126 };
127