/
SmartPlayList.h
218 lines (175 loc) · 7.77 KB
/
SmartPlayList.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#pragma once
/*
* Copyright (C) 2005-2012 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include <set>
#include <vector>
#include "utils/SortUtils.h"
#include "utils/StdString.h"
#include "utils/XBMCTinyXML.h"
class CDatabase;
class CVariant;
class ISmartPlaylistRule
{
public:
virtual ~ISmartPlaylistRule() { }
virtual bool Load(TiXmlElement *element, const CStdString &encoding = "UTF-8") = 0;
virtual bool Load(const CVariant &obj) = 0;
virtual bool Save(TiXmlNode *parent) const = 0;
virtual bool Save(CVariant &obj) const = 0;
};
class CSmartPlaylistRule : public ISmartPlaylistRule
{
public:
CSmartPlaylistRule();
enum SEARCH_OPERATOR { OPERATOR_START = 0,
OPERATOR_CONTAINS,
OPERATOR_DOES_NOT_CONTAIN,
OPERATOR_EQUALS,
OPERATOR_DOES_NOT_EQUAL,
OPERATOR_STARTS_WITH,
OPERATOR_ENDS_WITH,
OPERATOR_GREATER_THAN,
OPERATOR_LESS_THAN,
OPERATOR_AFTER,
OPERATOR_BEFORE,
OPERATOR_IN_THE_LAST,
OPERATOR_NOT_IN_THE_LAST,
OPERATOR_TRUE,
OPERATOR_FALSE,
OPERATOR_BETWEEN,
OPERATOR_END
};
enum FIELD_TYPE { TEXT_FIELD = 0,
BROWSEABLE_FIELD,
NUMERIC_FIELD,
DATE_FIELD,
PLAYLIST_FIELD,
SECONDS_FIELD,
BOOLEAN_FIELD,
TEXTIN_FIELD
};
virtual bool Load(TiXmlElement *element, const CStdString &encoding = "UTF-8");
virtual bool Load(const CVariant &obj);
virtual bool Save(TiXmlNode *parent) const;
virtual bool Save(CVariant &obj) const;
CStdString GetWhereClause(const CDatabase &db, const CStdString& strType) const;
static Field TranslateField(const char *field);
static CStdString TranslateField(Field field);
static SortBy TranslateOrder(const char *order);
static CStdString TranslateOrder(SortBy order);
static CStdString GetField(Field field, const CStdString& strType);
static CStdString TranslateOperator(SEARCH_OPERATOR oper);
static CStdString GetLocalizedField(Field field);
static CStdString GetLocalizedOrder(SortBy order);
static CStdString GetLocalizedOperator(SEARCH_OPERATOR oper);
static std::vector<Field> GetFields(const CStdString &type);
static std::vector<SortBy> GetOrders(const CStdString &type);
static FIELD_TYPE GetFieldType(Field field);
CStdString GetLocalizedRule(const CStdString &type) const;
CStdString GetLocalizedParameter(const CStdString &type) const;
Field m_field;
SEARCH_OPERATOR m_operator;
std::vector<CStdString> m_parameter;
private:
static SEARCH_OPERATOR TranslateOperator(const char *oper);
CStdString GetVideoResolutionQuery(const CStdString ¶meter) const;
};
class CSmartPlaylistRuleCombination;
typedef std::vector<CSmartPlaylistRule> CSmartPlaylistRules;
typedef std::vector<CSmartPlaylistRuleCombination> CSmartPlaylistRuleCombinations;
class CSmartPlaylistRuleCombination : public ISmartPlaylistRule
{
public:
CSmartPlaylistRuleCombination();
typedef enum {
CombinationOr = 0,
CombinationAnd
} Combination;
virtual bool Load(TiXmlElement *element, const CStdString &encoding = "UTF-8") { return false; }
virtual bool Load(const CVariant &obj);
virtual bool Save(TiXmlNode *parent) const { return false; }
virtual bool Save(CVariant &obj) const;
CStdString GetWhereClause(const CDatabase &db, const CStdString& strType, std::set<CStdString> &referencedPlaylists) const;
std::string TranslateCombinationType() const;
Combination GetType() const { return m_type; }
void SetType(Combination combination) { m_type = combination; }
void AddRule(const CSmartPlaylistRule &rule);
void AddCombination(const CSmartPlaylistRuleCombination &rule);
private:
friend class CSmartPlaylist;
friend class CGUIDialogSmartPlaylistEditor;
friend class CGUIDialogMediaFilter;
Combination m_type;
CSmartPlaylistRuleCombinations m_combinations;
CSmartPlaylistRules m_rules;
};
class CSmartPlaylist
{
public:
CSmartPlaylist();
bool Load(const CStdString &path);
bool Load(const CVariant &obj);
bool LoadFromXml(const CStdString &xml);
bool LoadFromJson(const CStdString &json);
bool Save(const CStdString &path) const;
bool Save(CVariant &obj, bool full = true) const;
bool SaveAsJson(CStdString &json, bool full = true) const;
TiXmlElement *OpenAndReadName(const CStdString &path);
bool LoadFromXML(TiXmlElement *root, const CStdString &encoding = "UTF-8");
void Reset();
void SetName(const CStdString &name);
void SetType(const CStdString &type); // music, video, mixed
const CStdString& GetName() const { return m_playlistName; };
const CStdString& GetType() const { return m_playlistType; };
void SetMatchAllRules(bool matchAll) { m_ruleCombination.SetType(matchAll ? CSmartPlaylistRuleCombination::CombinationAnd : CSmartPlaylistRuleCombination::CombinationOr); }
bool GetMatchAllRules() const { return m_ruleCombination.GetType() == CSmartPlaylistRuleCombination::CombinationAnd; }
void SetLimit(unsigned int limit) { m_limit = limit; };
unsigned int GetLimit() const { return m_limit; };
void SetOrder(SortBy order) { m_orderField = order; };
SortBy GetOrder() const { return m_orderField; };
void SetOrderAscending(bool orderAscending) { m_orderAscending = orderAscending; };
bool GetOrderAscending() const { return m_orderAscending; };
/*! \brief get the where clause for a playlist
We handle playlists inside playlists separately in order to ensure we don't introduce infinite loops
by playlist A including playlist B which also (perhaps via other playlists) then includes playlistA.
\param db the database to use to format up results
\param referencedPlaylists a set of playlists to know when we reach a cycle
\param needWhere whether we need to prepend the where clause with "WHERE "
*/
CStdString GetWhereClause(const CDatabase &db, std::set<CStdString> &referencedPlaylists) const;
CStdString GetSaveLocation() const;
static void GetAvailableFields(const std::string &type, std::vector<std::string> &fieldList);
static void GetAvailableOperators(std::vector<std::string> &operatorList);
bool IsEmpty() const { return m_ruleCombination.m_rules.empty() && m_ruleCombination.m_combinations.empty(); }
private:
friend class CGUIDialogSmartPlaylistEditor;
friend class CGUIDialogMediaFilter;
TiXmlElement* readName();
TiXmlElement *readNameFromXml(const CStdString &xml);
bool load(TiXmlElement *root);
CSmartPlaylistRuleCombination m_ruleCombination;
CStdString m_playlistName;
CStdString m_playlistType;
// order information
unsigned int m_limit;
SortBy m_orderField;
bool m_orderAscending;
CXBMCTinyXML m_xmlDoc;
};