Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

wip

  • Loading branch information...
commit 311f235e1aa2335f1f79111f58d081d3845452a6 1 parent 4f8a436
Sascha Montellese authored
2  xbmc/dialogs/GUIDialogSmartPlaylistRule.cpp
View
@@ -412,7 +412,7 @@ void CGUIDialogSmartPlaylistRule::UpdateButtons()
type = CGUIEditControl::INPUT_TYPE_TEXT;
break;
case CSmartPlaylistRule::DATE_FIELD:
- if (m_rule.m_operator.operation == FilterOperationInTheLast)
+ if (m_rule.m_operator.GetOperation() == FilterOperationInTheLast)
type = CGUIEditControl::INPUT_TYPE_TEXT;
else
type = CGUIEditControl::INPUT_TYPE_DATE;
30 xbmc/filter/Filter.cpp
View
@@ -132,9 +132,7 @@ CFilter::CFilter()
void CFilter::Reset()
{
- m_ruleCombination.m_combinations.clear();
- m_ruleCombination.m_rules.clear();
- m_ruleCombination.SetType(CFilterRuleCombination::CombinationAnd);
+ m_ruleCombination.Reset();
m_type = MediaTypeSong;
}
@@ -171,6 +169,18 @@ bool CFilter::Save(CVariant &obj) const
return true;
}
+bool CFilter::Filter(const CDatabase &db, std::string &query) const
+{
+ set<string> referencedPlaylists;
+ return filter(db, referencedPlaylists, query);
+}
+
+bool CFilter::Filter(CFileItemList& items) const
+{
+ set<string> referencedPlaylists;
+ return filter(referencedPlaylists, items);
+}
+
void CFilter::GetAvailableFields(std::vector<std::string> &fieldList)
{
for (unsigned int index = 0; index < NUM_FIELDS; index++)
@@ -242,3 +252,17 @@ std::string CFilter::GetLocalizedOperator(const CFilterOperator &op)
}
return "";
}
+
+bool CFilter::filter(const CDatabase &db, std::set<std::string> &referencedPlaylists, std::string &query) const
+{
+ // TODO
+
+ return false;
+}
+
+bool CFilter::filter(std::set<std::string> &referencedPlaylists, CFileItemList& items) const
+{
+ // TODO
+
+ return false;
+}
16 xbmc/filter/Filter.h
View
@@ -19,6 +19,7 @@
*
*/
+#include <set>
#include <string>
#include <vector>
@@ -26,6 +27,9 @@
#include "FilterRuleCombination.h"
#include "utils/DatabaseUtils.h"
+class CDatabase;
+class CFileItemList;
+
class CFilter
{
public:
@@ -33,6 +37,7 @@ class CFilter
virtual ~CFilter() { }
virtual void Reset();
+ virtual bool IsEmpty() const { return m_ruleCombination.GetRules().empty() && m_ruleCombination.GetCombinations().empty(); }
virtual bool Load(const CVariant &obj);
virtual bool Save(CVariant &obj) const;
@@ -40,10 +45,14 @@ class CFilter
MediaType GetType() const { return m_type; }
virtual void SetType(MediaType type) { m_type = type; }
+ CFilterRuleCombination& GetRuleCombination() { return m_ruleCombination; }
+ const CFilterRuleCombination& GetRuleCombination() const { return m_ruleCombination; }
+
void SetMatchAllRules(bool matchAll) { m_ruleCombination.SetType(matchAll ? CFilterRuleCombination::CombinationAnd : CFilterRuleCombination::CombinationOr); }
bool GetMatchAllRules() const { return m_ruleCombination.GetType() == CFilterRuleCombination::CombinationAnd; }
-
- virtual bool IsEmpty() const { return m_ruleCombination.m_rules.empty() && m_ruleCombination.m_combinations.empty(); }
+
+ virtual bool Filter(const CDatabase &db, std::string &query) const;
+ virtual bool Filter(CFileItemList& items) const;
static void GetAvailableFields(std::vector<std::string> &fieldList);
static const std::string& TranslateField(Field field);
@@ -56,6 +65,9 @@ class CFilter
static std::string GetLocalizedOperator(const CFilterOperator &op);
protected:
+ virtual bool filter(const CDatabase &db, std::set<std::string> &referencedPlaylists, std::string &query) const;
+ virtual bool filter(std::set<std::string> &referencedPlaylists, CFileItemList& items) const;
+
CFilterRuleCombination m_ruleCombination;
MediaType m_type;
};
44 xbmc/filter/FilterRule.cpp
View
@@ -25,6 +25,31 @@
using namespace std;
+bool CFilterOperator::Load(const CVariant &obj)
+{
+ if (!obj.isObject() ||
+ !obj.isMember("operation") || !obj["operation"].isString())
+ return false;
+
+ *this = CFilter::TranslateOperator(obj["operation"].asString());
+ if (obj.isMember("negated") && obj["negated"].isBoolean())
+ m_negated = obj["negated"].asBoolean();
+
+ return true;
+}
+
+bool CFilterOperator::Save(CVariant &obj) const
+{
+ if (obj.isNull() || m_operation == FilterOperationNone)
+ return false;
+
+ obj["operation"] = CFilter::TranslateOperator(*this);
+ if (m_negated)
+ obj["negated"] = true;
+
+ return true;
+}
+
CFilterRule::CFilterRule()
: m_field(FieldNone), m_type(FilterFieldTypeNone), m_browseable(false)
{ }
@@ -32,14 +57,13 @@ CFilterRule::CFilterRule()
bool CFilterRule::Load(const CVariant &obj)
{
if (!obj.isObject() ||
- !obj.isMember("field") || !obj["field"].isString() ||
- !obj.isMember("operator") || !obj["operator"].isString())
+ !obj.isMember("field") || !obj["field"].isString() ||
+ !obj.isMember("operator") || !obj["operator"].isObject() ||
+ !m_operator.Load(obj["operator"]))
return false;
- m_field = CFilter::TranslateField(obj["field"].asString().c_str());
- m_operator = CFilter::TranslateOperator(obj["operator"].asString().c_str());
-
- if (m_operator.operation == FilterOperationTrue)
+ m_field = CFilter::TranslateField(obj["field"].asString().c_str());
+ if (m_operator.m_operation == FilterOperationTrue)
return true;
if (!obj.isMember("value") || (!obj["value"].isString() && !obj["value"].isArray()))
@@ -64,12 +88,12 @@ bool CFilterRule::Load(const CVariant &obj)
bool CFilterRule::Save(CVariant &obj) const
{
- if (obj.isNull() || (m_value.empty() && m_operator.operation != FilterOperationTrue))
+ if (obj.isNull() ||
+ (m_value.empty() && m_operator.m_operation != FilterOperationTrue) ||
+ !m_operator.Save(obj["operator"]))
return false;
- obj["field"] = CFilter::TranslateField(m_field);
- obj["operator"] = CFilter::TranslateOperator(m_operator);
-
+ obj["field"] = CFilter::TranslateField(m_field);
obj["value"] = CVariant(CVariant::VariantTypeArray);
for (vector<std::string>::const_iterator it = m_value.begin(); it != m_value.end(); it++)
obj["value"].push_back(*it);
37 xbmc/filter/FilterRule.h
View
@@ -54,21 +54,32 @@ class CFilterOperator
{
public:
CFilterOperator(FilterOperation op = FilterOperationNone, bool neg = false)
- : operation(op), negated(neg)
+ : m_operation(op), m_negated(neg)
{ }
- bool operator==(const CFilterOperator &other) const { return operation == other.operation && negated == other.negated; }
+ bool operator==(const CFilterOperator &other) const { return m_operation == other.m_operation && m_negated == other.m_negated; }
bool operator!=(const CFilterOperator &other) const { return !(*this == other); }
+
+ virtual bool Load(const CVariant &obj);
+ virtual bool Save(CVariant &obj) const;
+
+ FilterOperation GetOperation() const { return m_operation; }
+ void SetOperation(FilterOperation op) { m_operation = op; }
+ bool IsNegated() const { return m_negated; }
+ void Negate(bool negate) { m_negated = negate; }
- int ToInt() const { return (int)operation | (int)negated << 31; }
+ int ToInt() const { return (int)m_operation | (int)m_negated << 31; }
void FromInt(int op)
{
- operation = (FilterOperation)(op & 0x7FFFFFFF);
- negated = (bool)(op >> 31);
+ m_operation = (FilterOperation)(op & 0x7FFFFFFF);
+ m_negated = (bool)(op >> 31);
}
- FilterOperation operation;
- bool negated;
+private:
+ friend class CFilterRule;
+
+ FilterOperation m_operation;
+ bool m_negated;
};
class CFilterRule
@@ -80,10 +91,22 @@ class CFilterRule
virtual bool Load(const CVariant &obj);
virtual bool Save(CVariant &obj) const;
+ Field GetField() const { return m_field; }
+ void SetField(Field field) { m_field = field; }
+ FilterFieldType GetType() const { return m_type; }
+ void SetType(FilterFieldType type) { m_type = type; }
+ const CFilterOperator& GetOperator() const { return m_operator; }
+ CFilterOperator& GetOperator() { return m_operator; }
+ void SetOperator(const CFilterOperator& op) { m_operator = op; }
+ bool IsBrowseable() const { return m_browseable; }
+ void SetBrowseable(bool browseable) { m_browseable = browseable; }
+
std::string GetValue() const;
+ const std::vector<std::string>& GetValues() const { return m_value; }
void SetValue(const std::string &value);
void SetValue(const std::vector<std::string> &values);
+private:
Field m_field;
FilterFieldType m_type;
CFilterOperator m_operator;
7 xbmc/filter/FilterRuleCombination.cpp
View
@@ -28,6 +28,13 @@ CFilterRuleCombination::CFilterRuleCombination()
: m_type(CombinationAnd)
{ }
+void CFilterRuleCombination::Reset()
+{
+ m_type = CombinationAnd;
+ m_rules.clear();
+ m_combinations.clear();
+}
+
bool CFilterRuleCombination::Load(const CVariant &obj)
{
if (!obj.isObject() && !obj.isArray())
8 xbmc/filter/FilterRuleCombination.h
View
@@ -34,12 +34,15 @@ class CFilterRuleCombination
{
public:
CFilterRuleCombination();
+ virtual ~CFilterRuleCombination() { }
typedef enum {
CombinationOr = 0,
CombinationAnd
} Combination;
+ virtual void Reset();
+
virtual bool Load(const CVariant &obj);
virtual bool Save(CVariant &obj) const;
@@ -48,9 +51,14 @@ class CFilterRuleCombination
Combination GetType() const { return m_type; }
void SetType(Combination combination) { m_type = combination; }
+ const CFilterRules& GetRules() const { return m_rules; }
+ CFilterRules& GetRules() { return m_rules; }
void AddRule(const CFilterRule &rule);
+ const CFilterRuleCombinations& GetCombinations() const { return m_combinations; }
+ CFilterRuleCombinations& GetCombinations() { return m_combinations; }
void AddCombination(const CFilterRuleCombination &rule);
+private:
Combination m_type;
CFilterRuleCombinations m_combinations;
CFilterRules m_rules;
2  xbmc/filter/dialogs/GUIDialogMediaFilter.cpp
View
@@ -284,7 +284,7 @@ void CGUIDialogMediaFilter::CreateSettings()
if (filter.rule == NULL)
filter.data = new int(CHECK_ALL);
else
- filter.data = new int(filter.rule->m_operator.operation == FilterOperationTrue ? CHECK_YES : CHECK_NO);
+ filter.data = new int(filter.rule->m_operator.GetOperation() == FilterOperationTrue ? CHECK_YES : CHECK_NO);
vector<pair<int, int> > entries;
entries.push_back(pair<int, int>(CHECK_ALL, CHECK_LABEL_ALL));
66 xbmc/playlists/SmartPlayList.cpp
View
@@ -115,7 +115,7 @@ static const translateField fields[] = {
CSmartPlaylistRule::CSmartPlaylistRule()
{
m_field = FieldNone;
- m_operator.operation = FilterOperationContains;
+ m_operator.SetOperation(FilterOperationContains);
m_parameter.clear();
}
@@ -136,7 +136,7 @@ bool CSmartPlaylistRule::Load(TiXmlElement *element, const CStdString &encoding
m_field = TranslateField(field);
m_operator = TranslateOperator(oper);
- if (m_operator.operation == FilterOperationTrue)
+ if (m_operator.GetOperation() == FilterOperationTrue)
return true;
TiXmlNode *parameter = element->FirstChild();
@@ -191,7 +191,7 @@ bool CSmartPlaylistRule::Load(const CVariant &obj)
m_field = TranslateField(obj["field"].asString().c_str());
m_operator = TranslateOperator(obj["operator"].asString().c_str());
- if (m_operator.operation == FilterOperationTrue)
+ if (m_operator.GetOperation() == FilterOperationTrue)
return true;
if (!obj.isMember("value") || (!obj["value"].isString() && !obj["value"].isArray()))
@@ -216,7 +216,7 @@ bool CSmartPlaylistRule::Load(const CVariant &obj)
bool CSmartPlaylistRule::Save(TiXmlNode *parent) const
{
- if (parent == NULL || (m_parameter.empty() && m_operator.operation != FilterOperationTrue))
+ if (parent == NULL || (m_parameter.empty() && m_operator.GetOperation() != FilterOperationTrue))
return false;
TiXmlElement rule("rule");
@@ -238,7 +238,7 @@ bool CSmartPlaylistRule::Save(TiXmlNode *parent) const
bool CSmartPlaylistRule::Save(CVariant &obj) const
{
- if (obj.isNull() || (m_parameter.empty() && m_operator.operation != FilterOperationTrue))
+ if (obj.isNull() || (m_parameter.empty() && m_operator.GetOperation() != FilterOperationTrue))
return false;
obj["field"] = TranslateField(m_field);
@@ -278,8 +278,8 @@ CStdString CSmartPlaylistRule::TranslateOrder(SortBy order)
CFilterOperator CSmartPlaylistRule::TranslateOperator(const char *oper)
{
CFilterOperator op = CFilter::TranslateOperator(oper);
- if (op.operation == FilterOperationNone)
- op.operation = FilterOperationContains;
+ if (op.GetOperation() == FilterOperationNone)
+ op.SetOperation(FilterOperationContains);
return op;
}
@@ -629,10 +629,10 @@ CStdString CSmartPlaylistRule::GetVideoResolutionQuery(const CStdString &paramet
else if (iRes >= 540) { min = 721; max = 960; }
else { min = 0; max = 720; }
- switch (m_operator.operation)
+ switch (m_operator.GetOperation())
{
case FilterOperationEquals:
- if (!m_operator.negated)
+ if (!m_operator.IsNegated())
retVal.AppendFormat(">= %i and iVideoWidth <= %i)", min, max);
else
retVal.AppendFormat("< %i or iVideoWidth > %i)", min, max);
@@ -656,30 +656,30 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
if ((strType == "tvshows" || strType == "episodes") && m_field == FieldYear)
{ // special case for premiered which is a date rather than a year
// TODO: SMARTPLAYLISTS do we really need this, or should we just make this field the premiered date and request a date?
- if (op.operation == FilterOperationEquals)
- op.operation = FilterOperationContains;
+ if (op.GetOperation() == FilterOperationEquals)
+ op.SetOperation(FilterOperationContains);
}
CStdString operatorString, negate;
if (GetFieldType(m_field) == TEXTIN_FIELD)
{
- if (op.operation == FilterOperationEquals && op.negated)
+ if (op.GetOperation() == FilterOperationEquals && op.IsNegated())
negate = " NOT";
}
else
{
// the comparison piece
- switch (op.operation)
+ switch (op.GetOperation())
{
case FilterOperationContains:
operatorString = " LIKE '%%%s%%'";
- if (op.negated)
+ if (op.IsNegated())
negate = " NOT";
break;
case FilterOperationEquals:
operatorString = " LIKE '%s'";
- if (op.negated)
+ if (op.IsNegated())
negate = " NOT";
break;
@@ -694,9 +694,9 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
case FilterOperationAfter:
case FilterOperationGreaterThan:
case FilterOperationInTheLast:
- if (!op.negated)
+ if (!op.IsNegated())
operatorString = " > ";
- else if (op.operation == FilterOperationInTheLast)
+ else if (op.GetOperation() == FilterOperationInTheLast)
operatorString = " < ";
if (GetFieldType(m_field) == NUMERIC_FIELD || GetFieldType(m_field) == SECONDS_FIELD)
@@ -715,7 +715,7 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
break;
case FilterOperationTrue:
- if (!op.negated)
+ if (!op.IsNegated())
operatorString = " = 1";
else
{
@@ -730,7 +730,7 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
}
// boolean operators don't have any values in m_parameter, they work on the operator
- if (m_operator.operation == FilterOperationTrue)
+ if (m_operator.GetOperation() == FilterOperationTrue)
{
if (strType == "movies")
{
@@ -791,7 +791,7 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
if (GetFieldType(m_field) == DATE_FIELD)
{
- if (m_operator.operation == FilterOperationInTheLast)
+ if (m_operator.GetOperation() == FilterOperationInTheLast)
{ // translate time period
CDateTime date=CDateTime::GetCurrentDateTime();
CDateTimeSpan span;
@@ -819,8 +819,8 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
else if (m_field == FieldAlbumArtist)
query = table + ".idAlbum" + negate + " IN (SELECT idAlbum FROM album_artist, artist WHERE album_artist.idArtist = artist.idArtist AND artist.strArtist" + parameter + ")";
else if (m_field == FieldLastPlayed &&
- (m_operator.operation == FilterOperationLessThan || m_operator.operation == FilterOperationBefore ||
- (m_operator.operation == FilterOperationInTheLast && m_operator.negated)))
+ (m_operator.GetOperation() == FilterOperationLessThan || m_operator.GetOperation() == FilterOperationBefore ||
+ (m_operator.GetOperation() == FilterOperationInTheLast && m_operator.IsNegated())))
query = GetField(m_field, strType) + " is NULL or " + GetField(m_field, strType) + parameter;
}
else if (strType == "albums")
@@ -858,8 +858,8 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
else if (m_field == FieldCountry)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM countrylinkmovie JOIN country ON country.idCountry=countrylinkmovie.idCountry WHERE country.strCountry" + parameter + ")";
else if ((m_field == FieldLastPlayed || m_field == FieldDateAdded) &&
- (m_operator.operation == FilterOperationLessThan || m_operator.operation == FilterOperationBefore ||
- (m_operator.operation == FilterOperationInTheLast && m_operator.negated)))
+ (m_operator.GetOperation() == FilterOperationLessThan || m_operator.GetOperation() == FilterOperationBefore ||
+ (m_operator.GetOperation() == FilterOperationInTheLast && m_operator.IsNegated())))
query = GetField(m_field, strType) + " IS NULL OR " + GetField(m_field, strType) + parameter;
else if (m_field == FieldSet)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM setlinkmovie JOIN sets ON sets.idSet=setlinkmovie.idSet WHERE sets.strSet" + parameter + ")";
@@ -879,8 +879,8 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
else if (m_field == FieldDirector)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMVideo FROM directorlinkmusicvideo JOIN actors ON actors.idActor=directorlinkmusicvideo.idDirector WHERE actors.strActor" + parameter + ")";
else if ((m_field == FieldLastPlayed || m_field == FieldDateAdded) &&
- (m_operator.operation == FilterOperationLessThan || m_operator.operation == FilterOperationBefore ||
- (m_operator.operation == FilterOperationInTheLast && m_operator.negated)))
+ (m_operator.GetOperation() == FilterOperationLessThan || m_operator.GetOperation() == FilterOperationBefore ||
+ (m_operator.GetOperation() == FilterOperationInTheLast && m_operator.IsNegated())))
query = GetField(m_field, strType) + " IS NULL OR " + GetField(m_field, strType) + parameter;
}
else if (strType == "tvshows")
@@ -898,8 +898,8 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
else if (m_field == FieldMPAA)
query = GetField(FieldId, strType) + negate + " IN (SELECT idShow FROM tvshowview WHERE " + GetField(m_field, strType) + parameter + ")";
else if ((m_field == FieldLastPlayed || m_field == FieldDateAdded) &&
- (m_operator.operation == FilterOperationLessThan || m_operator.operation == FilterOperationBefore ||
- (m_operator.operation == FilterOperationInTheLast && m_operator.negated)))
+ (m_operator.GetOperation() == FilterOperationLessThan || m_operator.GetOperation() == FilterOperationBefore ||
+ (m_operator.GetOperation() == FilterOperationInTheLast && m_operator.IsNegated())))
query = GetField(m_field, strType) + " IS NULL OR " + GetField(m_field, strType) + parameter;
}
else if (strType == "episodes")
@@ -915,8 +915,8 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
else if (m_field == FieldWriter)
query = GetField(FieldId, strType) + negate + " IN (SELECT idEpisode FROM writerlinkepisode JOIN actors ON actors.idActor=writerlinkepisode.idWriter WHERE actors.strActor" + parameter + ")";
else if ((m_field == FieldLastPlayed || m_field == FieldDateAdded) &&
- (m_operator.operation == FilterOperationLessThan || m_operator.operation == FilterOperationBefore ||
- (m_operator.operation == FilterOperationInTheLast && m_operator.negated)))
+ (m_operator.GetOperation() == FilterOperationLessThan || m_operator.GetOperation() == FilterOperationBefore ||
+ (m_operator.GetOperation() == FilterOperationInTheLast && m_operator.IsNegated())))
query = GetField(m_field, strType) + " IS NULL OR " + GetField(m_field, strType) + parameter;
else if (m_field == FieldStudio)
query = GetField(FieldId, strType) + negate + " IN (SELECT idEpisode FROM episodeview WHERE strStudio" + parameter + ")";
@@ -939,8 +939,8 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
query = table + ".idFile" + negate + " IN (SELECT DISTINCT idFile FROM streamdetails WHERE fVideoAspect " + parameter + ")";
if (m_field == FieldPlaycount && strType != "songs" && strType != "albums")
{ // playcount IS stored as NULL OR number IN video db
- if ((m_operator.operation == FilterOperationEquals && it->Equals("0") == !m_operator.negated) ||
- (m_operator.operation == FilterOperationLessThan))
+ if ((m_operator.GetOperation() == FilterOperationEquals && it->Equals("0") == !m_operator.IsNegated()) ||
+ (m_operator.GetOperation() == FilterOperationLessThan))
{
CStdString field = GetField(FieldPlaycount, strType);
query = field + " IS NULL OR " + field + parameter;
@@ -1018,7 +1018,7 @@ CStdString CSmartPlaylistRuleCombination::GetWhereClause(const CDatabase &db, co
}
if (playlist.GetType().Equals(strType))
{
- if (it->m_operator.operation == FilterOperationEquals && it->m_operator.negated)
+ if (it->m_operator.GetOperation() == FilterOperationEquals && it->m_operator.IsNegated())
currentRule.Format("NOT (%s)", playlistQuery.c_str());
else
currentRule = playlistQuery;
Please sign in to comment.
Something went wrong with that request. Please try again.