qBittorrent
rss_autodownloadrule.h
Go to the documentation of this file.
1 /*
2  * Bittorrent Client using Qt and libtorrent.
3  * Copyright (C) 2017 Vladimir Golovnev <[email protected]>
4  * Copyright (C) 2010 Christophe Dumez <[email protected]>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (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 Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * In addition, as a special exception, the copyright holders give permission to
21  * link this program with the OpenSSL project's "OpenSSL" library (or with
22  * modified versions of it that use the same license as the "OpenSSL" library),
23  * and distribute the linked executables. You must obey the GNU General Public
24  * License in all respects for all of the code used other than "OpenSSL". If you
25  * modify file(s), you may extend this exception to your version of the file(s),
26  * but you are not obligated to do so. If you do not wish to do so, delete this
27  * exception statement from your version.
28  */
29 
30 #pragma once
31 
32 #include <optional>
33 
34 #include <QSharedDataPointer>
35 #include <QVariant>
36 
38 
39 class QDateTime;
40 class QJsonObject;
41 class QRegularExpression;
42 
43 namespace RSS
44 {
45  struct AutoDownloadRuleData;
46 
48  {
49  public:
50  explicit AutoDownloadRule(const QString &name = "");
51  AutoDownloadRule(const AutoDownloadRule &other);
53 
54  QString name() const;
55  void setName(const QString &name);
56 
57  bool isEnabled() const;
58  void setEnabled(bool enable);
59 
60  QString mustContain() const;
61  void setMustContain(const QString &tokens);
62  QString mustNotContain() const;
63  void setMustNotContain(const QString &tokens);
64  QStringList feedURLs() const;
65  void setFeedURLs(const QStringList &urls);
66  int ignoreDays() const;
67  void setIgnoreDays(int d);
68  QDateTime lastMatch() const;
69  void setLastMatch(const QDateTime &lastMatch);
70  bool useRegex() const;
71  void setUseRegex(bool enabled);
72  bool useSmartFilter() const;
73  void setUseSmartFilter(bool enabled);
74  QString episodeFilter() const;
75  void setEpisodeFilter(const QString &e);
76 
77  QStringList previouslyMatchedEpisodes() const;
79 
80  QString savePath() const;
81  void setSavePath(const QString &savePath);
82  std::optional<bool> addPaused() const;
83  void setAddPaused(std::optional<bool> addPaused);
84  std::optional<BitTorrent::TorrentContentLayout> torrentContentLayout() const;
85  void setTorrentContentLayout(std::optional<BitTorrent::TorrentContentLayout> contentLayout);
86  QString assignedCategory() const;
87  void setCategory(const QString &category);
88 
89  bool matches(const QVariantHash &articleData) const;
90  bool accepts(const QVariantHash &articleData);
91 
93  bool operator==(const AutoDownloadRule &other) const;
94  bool operator!=(const AutoDownloadRule &other) const;
95 
96  QJsonObject toJsonObject() const;
97  static AutoDownloadRule fromJsonObject(const QJsonObject &jsonObj, const QString &name = "");
98 
99  QVariantHash toLegacyDict() const;
100  static AutoDownloadRule fromLegacyDict(const QVariantHash &dict);
101 
102  private:
103  bool matchesMustContainExpression(const QString &articleTitle) const;
104  bool matchesMustNotContainExpression(const QString &articleTitle) const;
105  bool matchesEpisodeFilterExpression(const QString &articleTitle) const;
106  bool matchesSmartEpisodeFilter(const QString &articleTitle) const;
107  bool matchesExpression(const QString &articleTitle, const QString &expression) const;
108  QRegularExpression cachedRegex(const QString &expression, bool isRegex = true) const;
109 
110  QSharedDataPointer<AutoDownloadRuleData> m_dataPtr;
111  };
112 }
void setTorrentContentLayout(std::optional< BitTorrent::TorrentContentLayout > contentLayout)
void setEpisodeFilter(const QString &e)
QStringList previouslyMatchedEpisodes() const
std::optional< BitTorrent::TorrentContentLayout > torrentContentLayout() const
bool accepts(const QVariantHash &articleData)
void setPreviouslyMatchedEpisodes(const QStringList &previouslyMatchedEpisodes)
bool matchesEpisodeFilterExpression(const QString &articleTitle) const
bool matchesSmartEpisodeFilter(const QString &articleTitle) const
QJsonObject toJsonObject() const
void setLastMatch(const QDateTime &lastMatch)
bool operator==(const AutoDownloadRule &other) const
void setUseRegex(bool enabled)
void setMustContain(const QString &tokens)
static AutoDownloadRule fromJsonObject(const QJsonObject &jsonObj, const QString &name="")
QVariantHash toLegacyDict() const
void setSavePath(const QString &savePath)
AutoDownloadRule(const QString &name="")
QSharedDataPointer< AutoDownloadRuleData > m_dataPtr
std::optional< bool > addPaused() const
void setCategory(const QString &category)
AutoDownloadRule & operator=(const AutoDownloadRule &other)
void setUseSmartFilter(bool enabled)
static AutoDownloadRule fromLegacyDict(const QVariantHash &dict)
bool matchesMustNotContainExpression(const QString &articleTitle) const
void setFeedURLs(const QStringList &urls)
void setName(const QString &name)
QStringList feedURLs() const
bool matchesExpression(const QString &articleTitle, const QString &expression) const
bool operator!=(const AutoDownloadRule &other) const
bool matches(const QVariantHash &articleData) const
bool matchesMustContainExpression(const QString &articleTitle) const
QRegularExpression cachedRegex(const QString &expression, bool isRegex=true) const
void setMustNotContain(const QString &tokens)
void setAddPaused(std::optional< bool > addPaused)