3 * Copyright (C) 2013 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
24 #include <boost/shared_ptr.hpp>
26 #include "utils/StdString.h"
32 class CDatabaseQueryRule
36 virtual ~CDatabaseQueryRule() { };
38 enum SEARCH_OPERATOR { OPERATOR_START = 0,
40 OPERATOR_DOES_NOT_CONTAIN,
42 OPERATOR_DOES_NOT_EQUAL,
45 OPERATOR_GREATER_THAN,
50 OPERATOR_NOT_IN_THE_LAST,
57 enum FIELD_TYPE { TEXT_FIELD = 0,
66 virtual bool Load(const TiXmlNode *node, const std::string &encoding = "UTF-8");
67 virtual bool Load(const CVariant &obj);
68 virtual bool Save(TiXmlNode *parent) const;
69 virtual bool Save(CVariant &obj) const;
71 static CStdString GetLocalizedOperator(SEARCH_OPERATOR oper);
72 static void GetAvailableOperators(std::vector<std::string> &operatorList);
74 CStdString GetParameter() const;
75 void SetParameter(const CStdString &value);
76 void SetParameter(const std::vector<CStdString> &values);
78 virtual CStdString GetWhereClause(const CDatabase &db, const CStdString& strType) const;
81 SEARCH_OPERATOR m_operator;
82 std::vector<CStdString> m_parameter;
85 virtual CStdString GetField(int field, const CStdString& type) const=0;
86 virtual FIELD_TYPE GetFieldType(int field) const=0;
87 virtual int TranslateField(const char *field) const=0;
88 virtual CStdString TranslateField(int field) const=0;
89 virtual CStdString FormatParameter(const CStdString &negate, const CStdString &oper, const CDatabase &db, const CStdString &type) const;
90 virtual CStdString FormatWhereClause(const CStdString &negate, const CStdString &oper, const CStdString ¶m,
91 const CDatabase &db, const CStdString &type) const;
92 virtual SEARCH_OPERATOR GetOperator(const CStdString &type) const { return m_operator; };
93 virtual CStdString GetOperatorString(SEARCH_OPERATOR op) const;
94 virtual CStdString GetBooleanQuery(const CStdString &negate, const CStdString &strType) const { return ""; }
96 static SEARCH_OPERATOR TranslateOperator(const char *oper);
97 static CStdString TranslateOperator(SEARCH_OPERATOR oper);
100 class CDatabaseQueryRuleCombination;
102 typedef std::vector< boost::shared_ptr<CDatabaseQueryRule> > CDatabaseQueryRules;
103 typedef std::vector< boost::shared_ptr<CDatabaseQueryRuleCombination> > CDatabaseQueryRuleCombinations;
105 class IDatabaseQueryRuleFactory
108 virtual CDatabaseQueryRule *CreateRule() const=0;
109 virtual CDatabaseQueryRuleCombination *CreateCombination() const=0;
112 class CDatabaseQueryRuleCombination
115 CDatabaseQueryRuleCombination();
116 virtual ~CDatabaseQueryRuleCombination() { };
124 virtual bool Load(const TiXmlNode *node, const std::string &encoding = "UTF-8") { return false; }
125 virtual bool Load(const CVariant &obj, const IDatabaseQueryRuleFactory *factory);
126 virtual bool Save(TiXmlNode *parent) const;
127 virtual bool Save(CVariant &obj) const;
129 CStdString GetWhereClause(const CDatabase &db, const CStdString& strType) const;
130 std::string TranslateCombinationType() const;
132 Combination GetType() const { return m_type; }
133 void SetType(Combination combination) { m_type = combination; }
135 bool empty() const { return m_combinations.empty() && m_rules.empty(); }
138 friend class CGUIDialogSmartPlaylistEditor;
139 friend class CGUIDialogMediaFilter;
142 CDatabaseQueryRuleCombinations m_combinations;
143 CDatabaseQueryRules m_rules;