1
/***************************************************************************
2
* Copyright (C) 2008 by Joris Guisson and Ivan Vasic *
3
* joris.guisson@gmail.com *
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 of the License, or *
9
* (at your option) any later version. *
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 this program; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20
***************************************************************************/
27
#include <syndication/item.h>
40
Class to filter torrents from Feeds
46
Filter(const QString & name);
50
* Start matching items, must be called before the first call to match, when matching
51
* a list of Syndication::Item's.
55
/// Get the name of the filter
56
const QString & filterName() const {return name;}
59
const QString & filterID() const {return id;}
61
/// Set the name of the filter
62
void setFilterName(const QString & n) {name = n;}
65
* Check if an item matches the filter
66
* @param item The item
67
* @return true If a match is found, false otherwise
69
bool match(Syndication::ItemPtr item);
72
void addWordMatch(const QRegExp & exp);
74
/// Remove a word match
75
void removeWordMatch(const QRegExp & exp);
77
/// Get all word matches
78
QList<QRegExp> wordMatches() const {return word_matches;}
80
/// Clear the list of word matches
81
void clearWordMatches() {word_matches.clear();}
83
/// Is season and episode matching enabled
84
bool useSeasonAndEpisodeMatching() const {return use_season_and_episode_matching;}
86
/// Enable or disable season and episode matching
87
void setSeasonAndEpisodeMatching(bool on) {use_season_and_episode_matching = on;}
89
/// Do not download duplicate season and episode matches
90
bool noDuplicateSeasonAndEpisodeMatches() const {return no_duplicate_se_matches;}
92
/// Set whether or not to download duplicate season and episode matches
93
void setNoDuplicateSeasonAndEpisodeMatches(bool on) {no_duplicate_se_matches = on;}
95
/// Get the seasons to download represented in a string
96
QString seasonsToString() const {return seasons_string;}
98
/// Get the episodes to download represented in a string
99
QString episodesToString() const {return episodes_string;}
102
* Set the seasons from a string
103
* @param s The string
104
* @return true if string is properly formatted
106
bool setSeasons(const QString & s);
109
* Set the episodes from a string
110
* @param s The string
111
* @return true if string is properly formatted
113
bool setEpisodes(const QString & s);
115
/// Download the matching items or not
116
bool downloadMatching() const {return download_matching;}
118
/// Set the download matching or not
119
void setDownloadMatching(bool on) {download_matching = on;}
121
/// Download the non matching items or not
122
bool downloadNonMatching() const {return download_non_matching;}
124
/// Set the download non matching or not
125
void setDownloadNonMatching(bool on) {download_non_matching = on;}
128
const QString & group() const {return dest_group;}
131
void setGroup(const QString & g) {dest_group = g;}
133
/// Get the download location
134
const QString & downloadLocation() const {return download_location;}
136
/// Set the download location
137
void setDownloadLocation(const QString & dl) {download_location = dl;}
139
/// Open torrents silently or not
140
bool openSilently() const {return silent;}
142
/// Enable or disable open silently
143
void setOpenSilently(bool on) {silent = on;}
145
/// Are the word matches case sensitive
146
bool caseSensitive() const {return case_sensitive;}
148
/// Set case sensitivity of word matches
149
void setCaseSensitive(bool on) {case_sensitive = on;}
151
/// Return wether or not all word matches must match
152
bool allWordMatchesMustMatch() const {return all_word_matches_must_match;}
154
/// Set wether or not all word matches must match
155
void setAllWordMatchesMustMatch(bool on) {all_word_matches_must_match = on;}
158
void save(bt::BEncoder & enc);
161
bool load(bt::BDictNode* dict);
163
/// Wether or not the string matches are regular expressions
164
bool useRegularExpressions() const {return use_regular_expressions;}
166
/// Enable or disable regular expressions
167
void setUseRegularExpressions(bool on) {use_regular_expressions = on;}
169
/// Is a string a valid seasons or episode string
170
static bool validSeasonOrEpisodeString(const QString & s);
172
/// Get the season and episode of an item
173
static bool getSeasonAndEpisode(const QString & title,int & season,int & episode);
181
struct MatchedSeasonAndEpisode
186
bool operator == (const MatchedSeasonAndEpisode & se) const
188
return season == se.season && episode == se.episode;
192
static bool parseNumbersString(const QString & s,QList<Range> & numbers);
193
static bool stringToRange(const QString & s,Range & r);
195
bool match(const QString & title,QRegExp & exp);
200
QList<QRegExp> word_matches;
201
bool use_season_and_episode_matching;
202
bool no_duplicate_se_matches;
203
QList<Range> seasons;
204
QString seasons_string;
205
QList<Range> episodes;
206
QString episodes_string;
207
bool download_matching;
208
bool download_non_matching;
210
QString download_location;
213
bool all_word_matches_must_match;
214
bool use_regular_expressions;
216
QList<MatchedSeasonAndEpisode> se_matches;