~ubuntu-branches/ubuntu/lucid/ktorrent/lucid

« back to all changes in this revision

Viewing changes to plugins/syndication/filter.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2009-02-16 18:37:14 UTC
  • mfrom: (1.1.25 upstream) (0.4.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090216183714-52tf47jrnmk4xkmp
Tags: 3.2+dfsg.1-2ubuntu1
* Merge with Debian, remaining changes: (LP: #296433)
  - Use Kubuntu's kde4.mk
  - Build-depend on libboost-serialization1.35-dev since unversioned -dev is
    in universe
  - Change plasma-applet-ktorrent to plasma-widget-ktorrent since we're
    supposed to call them widgets for the users

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2008 by Joris Guisson and Ivan Vasic                    *
 
3
 *   joris.guisson@gmail.com                                               *
 
4
 *   ivasic@gmail.com                                                      *
 
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 of the License, or     *
 
9
 *   (at your option) 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 this program; if not, write to the                         *
 
18
 *   Free Software Foundation, Inc.,                                       *
 
19
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
 
20
 ***************************************************************************/
 
21
#ifndef KTFILTER_H
 
22
#define KTFILTER_H
 
23
 
 
24
 
 
25
#include <QList>
 
26
#include <QRegExp>
 
27
#include <syndication/item.h>
 
28
 
 
29
namespace bt
 
30
{
 
31
        class BEncoder;
 
32
        class BDictNode;
 
33
}
 
34
 
 
35
namespace kt
 
36
{
 
37
        
 
38
 
 
39
        /**
 
40
                Class to filter torrents from Feeds
 
41
        */
 
42
        class Filter
 
43
        {
 
44
        public:
 
45
                Filter();
 
46
                Filter(const QString & name);
 
47
                virtual ~Filter();
 
48
                
 
49
                /**
 
50
                 * Start matching items, must be called before the first call to match, when matching
 
51
                 * a list of Syndication::Item's.
 
52
                 */
 
53
                void startMatching();
 
54
                
 
55
                /// Get the name of the filter
 
56
                const QString & filterName() const {return name;}
 
57
                
 
58
                /// Get the filter ID
 
59
                const QString & filterID() const {return id;}
 
60
                
 
61
                /// Set the name of the filter
 
62
                void setFilterName(const QString & n) {name = n;}
 
63
                
 
64
                /**
 
65
                 * Check if an item matches the filter
 
66
                 * @param item The item
 
67
                 * @return true If a match is found, false otherwise
 
68
                 */
 
69
                bool match(Syndication::ItemPtr item);
 
70
                
 
71
                /// Add a word match
 
72
                void addWordMatch(const QRegExp & exp);
 
73
                
 
74
                /// Remove a word match
 
75
                void removeWordMatch(const QRegExp & exp);
 
76
                
 
77
                /// Get all word matches
 
78
                QList<QRegExp> wordMatches() const {return word_matches;}
 
79
                
 
80
                /// Clear the list of word matches
 
81
                void clearWordMatches() {word_matches.clear();}
 
82
                
 
83
                /// Is season and episode matching enabled
 
84
                bool useSeasonAndEpisodeMatching() const {return use_season_and_episode_matching;}
 
85
                
 
86
                /// Enable or disable season and episode matching
 
87
                void setSeasonAndEpisodeMatching(bool on) {use_season_and_episode_matching = on;}
 
88
                
 
89
                /// Do not download duplicate season and episode matches
 
90
                bool noDuplicateSeasonAndEpisodeMatches() const {return no_duplicate_se_matches;}
 
91
                
 
92
                /// Set whether or not to download duplicate season and episode matches
 
93
                void setNoDuplicateSeasonAndEpisodeMatches(bool on) {no_duplicate_se_matches = on;}
 
94
                
 
95
                /// Get the seasons to download represented in a string
 
96
                QString seasonsToString() const {return seasons_string;}
 
97
                
 
98
                /// Get the episodes to download represented in a string
 
99
                QString episodesToString() const {return episodes_string;}
 
100
                
 
101
                /**
 
102
                 * Set the seasons from a string
 
103
                 * @param s The string
 
104
                 * @return true if string is properly formatted
 
105
                 */
 
106
                bool setSeasons(const QString & s);
 
107
                
 
108
                /**
 
109
                 * Set the episodes from a string
 
110
                 * @param s The string
 
111
                 * @return true if string is properly formatted
 
112
                 */
 
113
                bool setEpisodes(const QString & s);
 
114
                
 
115
                /// Download the matching items or not
 
116
                bool downloadMatching() const {return download_matching;}
 
117
                
 
118
                /// Set the download matching or not
 
119
                void setDownloadMatching(bool on) {download_matching = on;}
 
120
                
 
121
                /// Download the non matching items or not
 
122
                bool downloadNonMatching() const {return download_non_matching;}
 
123
                
 
124
                /// Set the download non matching or not
 
125
                void setDownloadNonMatching(bool on) {download_non_matching = on;}
 
126
                
 
127
                /// Get the group
 
128
                const QString & group() const {return dest_group;}
 
129
                
 
130
                /// Set the group 
 
131
                void setGroup(const QString & g) {dest_group = g;}
 
132
                
 
133
                /// Get the download location
 
134
                const QString & downloadLocation() const  {return download_location;}
 
135
                
 
136
                /// Set the download location
 
137
                void setDownloadLocation(const QString & dl) {download_location = dl;}
 
138
                
 
139
                /// Open torrents silently or not
 
140
                bool openSilently() const {return silent;}
 
141
                
 
142
                /// Enable or disable open silently
 
143
                void setOpenSilently(bool on) {silent = on;}
 
144
                
 
145
                /// Are the word matches case sensitive
 
146
                bool caseSensitive() const {return case_sensitive;}
 
147
                
 
148
                /// Set case sensitivity of word matches
 
149
                void setCaseSensitive(bool on) {case_sensitive = on;}
 
150
                
 
151
                /// Return wether or not all word matches must match
 
152
                bool allWordMatchesMustMatch() const {return all_word_matches_must_match;}
 
153
                
 
154
                /// Set wether or not all word matches must match
 
155
                void setAllWordMatchesMustMatch(bool on) {all_word_matches_must_match = on;}
 
156
                
 
157
                /// Save the filter
 
158
                void save(bt::BEncoder & enc);
 
159
                
 
160
                /// Load the filter
 
161
                bool load(bt::BDictNode* dict);
 
162
                
 
163
                /// Wether or not the string matches are regular expressions
 
164
                bool useRegularExpressions() const {return use_regular_expressions;}
 
165
                
 
166
                /// Enable or disable regular expressions
 
167
                void setUseRegularExpressions(bool on) {use_regular_expressions = on;}
 
168
                
 
169
                /// Is a string a valid seasons or episode string
 
170
                static bool validSeasonOrEpisodeString(const QString & s);
 
171
                
 
172
                /// Get the season and episode of an item
 
173
                static bool getSeasonAndEpisode(const QString & title,int & season,int & episode);
 
174
        private:
 
175
                struct Range
 
176
                {
 
177
                        int start;
 
178
                        int end;
 
179
                };
 
180
                
 
181
                struct MatchedSeasonAndEpisode
 
182
                {
 
183
                        int season;
 
184
                        int episode;
 
185
                        
 
186
                        bool operator == (const MatchedSeasonAndEpisode & se) const
 
187
                        {
 
188
                                return season == se.season && episode == se.episode;
 
189
                        }
 
190
                };
 
191
                
 
192
                static bool parseNumbersString(const QString & s,QList<Range> & numbers);
 
193
                static bool stringToRange(const QString & s,Range & r);
 
194
                
 
195
                bool match(const QString & title,QRegExp & exp);
 
196
                
 
197
        private:
 
198
                QString id;
 
199
                QString name;
 
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;
 
209
                QString dest_group;
 
210
                QString download_location;
 
211
                bool silent;
 
212
                bool case_sensitive;
 
213
                bool all_word_matches_must_match;
 
214
                bool use_regular_expressions;
 
215
                
 
216
                QList<MatchedSeasonAndEpisode> se_matches;
 
217
        };
 
218
 
 
219
}
 
220
 
 
221
#endif