changed: Add logic to properly handle subtitles for stacked files
[vuplus_xbmc] / xbmc / dbwrappers / DatabaseQuery.h
1 #pragma once
2 /*
3  *      Copyright (C) 2013 Team XBMC
4  *      http://xbmc.org
5  *
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)
9  *  any later version.
10  *
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.
15  *
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/>.
19  *
20  */
21
22 #include <set>
23 #include <vector>
24 #include <boost/shared_ptr.hpp>
25
26 #include "utils/StdString.h"
27
28 class CDatabase;
29 class CVariant;
30 class TiXmlNode;
31
32 class CDatabaseQueryRule
33 {
34 public:
35   CDatabaseQueryRule();
36   virtual ~CDatabaseQueryRule() { };
37
38   enum SEARCH_OPERATOR { OPERATOR_START = 0,
39                          OPERATOR_CONTAINS,
40                          OPERATOR_DOES_NOT_CONTAIN,
41                          OPERATOR_EQUALS,
42                          OPERATOR_DOES_NOT_EQUAL,
43                          OPERATOR_STARTS_WITH,
44                          OPERATOR_ENDS_WITH,
45                          OPERATOR_GREATER_THAN,
46                          OPERATOR_LESS_THAN,
47                          OPERATOR_AFTER,
48                          OPERATOR_BEFORE,
49                          OPERATOR_IN_THE_LAST,
50                          OPERATOR_NOT_IN_THE_LAST,
51                          OPERATOR_TRUE,
52                          OPERATOR_FALSE,
53                          OPERATOR_BETWEEN,
54                          OPERATOR_END
55                        };
56
57   enum FIELD_TYPE { TEXT_FIELD = 0,
58                     NUMERIC_FIELD,
59                     DATE_FIELD,
60                     PLAYLIST_FIELD,
61                     SECONDS_FIELD,
62                     BOOLEAN_FIELD,
63                     TEXTIN_FIELD
64                   };
65
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;
70
71   static CStdString           GetLocalizedOperator(SEARCH_OPERATOR oper);
72   static void                 GetAvailableOperators(std::vector<std::string> &operatorList);
73
74   CStdString                  GetParameter() const;
75   void                        SetParameter(const CStdString &value);
76   void                        SetParameter(const std::vector<CStdString> &values);
77
78   virtual CStdString          GetWhereClause(const CDatabase &db, const CStdString& strType) const;
79
80   int                         m_field;
81   SEARCH_OPERATOR             m_operator;
82   std::vector<CStdString>     m_parameter;
83
84 protected:
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 &param,
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 ""; }
95
96   static SEARCH_OPERATOR      TranslateOperator(const char *oper);
97   static CStdString           TranslateOperator(SEARCH_OPERATOR oper);
98 };
99
100 class CDatabaseQueryRuleCombination;
101
102 typedef std::vector< boost::shared_ptr<CDatabaseQueryRule> > CDatabaseQueryRules;
103 typedef std::vector< boost::shared_ptr<CDatabaseQueryRuleCombination> > CDatabaseQueryRuleCombinations;
104
105 class IDatabaseQueryRuleFactory
106 {
107 public:
108   virtual CDatabaseQueryRule *CreateRule() const=0;
109   virtual CDatabaseQueryRuleCombination *CreateCombination() const=0;
110 };
111
112 class CDatabaseQueryRuleCombination
113 {
114 public:
115   CDatabaseQueryRuleCombination();
116   virtual ~CDatabaseQueryRuleCombination() { };
117
118   typedef enum {
119     CombinationOr = 0,
120     CombinationAnd
121   } Combination;
122
123   void clear();
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;
128
129   CStdString GetWhereClause(const CDatabase &db, const CStdString& strType) const;
130   std::string TranslateCombinationType() const;
131
132   Combination GetType() const { return m_type; }
133   void SetType(Combination combination) { m_type = combination; }
134
135   bool empty() const { return m_combinations.empty() && m_rules.empty(); }
136
137 protected:
138   friend class CGUIDialogSmartPlaylistEditor;
139   friend class CGUIDialogMediaFilter;
140
141   Combination m_type;
142   CDatabaseQueryRuleCombinations m_combinations;
143   CDatabaseQueryRules m_rules;
144 };