qBittorrent
RSS::AutoDownloader Class Referencefinal

#include <rss_autodownloader.h>

Inheritance diagram for RSS::AutoDownloader:
Collaboration diagram for RSS::AutoDownloader:

Public Types

enum class  RulesFileFormat { Legacy , JSON }
 

Signals

void processingStateChanged (bool enabled)
 
void ruleAdded (const QString &ruleName)
 
void ruleChanged (const QString &ruleName)
 
void ruleRenamed (const QString &ruleName, const QString &oldRuleName)
 
void ruleAboutToBeRemoved (const QString &ruleName)
 

Public Member Functions

bool isProcessingEnabled () const
 
void setProcessingEnabled (bool enabled)
 
QStringList smartEpisodeFilters () const
 
void setSmartEpisodeFilters (const QStringList &filters)
 
QRegularExpression smartEpisodeRegex () const
 
bool downloadRepacks () const
 
void setDownloadRepacks (bool enabled)
 
bool hasRule (const QString &ruleName) const
 
AutoDownloadRule ruleByName (const QString &ruleName) const
 
QList< AutoDownloadRulerules () const
 
void insertRule (const AutoDownloadRule &rule)
 
bool renameRule (const QString &ruleName, const QString &newRuleName)
 
void removeRule (const QString &ruleName)
 
QByteArray exportRules (RulesFileFormat format=RulesFileFormat::JSON) const
 
void importRules (const QByteArray &data, RulesFileFormat format=RulesFileFormat::JSON)
 

Static Public Member Functions

static AutoDownloaderinstance ()
 

Private Slots

void process ()
 
void handleTorrentDownloadFinished (const QString &url)
 
void handleTorrentDownloadFailed (const QString &url)
 
void handleNewArticle (const Article *article)
 

Private Member Functions

 AutoDownloader ()
 
 ~AutoDownloader () override
 
void timerEvent (QTimerEvent *event) override
 
void setRule_impl (const AutoDownloadRule &rule)
 
void resetProcessingQueue ()
 
void startProcessing ()
 
void addJobForArticle (const Article *article)
 
void processJob (const QSharedPointer< ProcessingJob > &job)
 
void load ()
 
void loadRules (const QByteArray &data)
 
void loadRulesLegacy ()
 
void store ()
 
void storeDeferred ()
 
QByteArray exportRulesToJSONFormat () const
 
void importRulesFromJSONFormat (const QByteArray &data)
 
QByteArray exportRulesToLegacyFormat () const
 
void importRulesFromLegacyFormat (const QByteArray &data)
 

Private Attributes

CachedSettingValue< bool > m_storeProcessingEnabled
 
SettingValue< QVariant > m_storeSmartEpisodeFilter
 
SettingValue< bool > m_storeDownloadRepacks
 
QTimer * m_processingTimer
 
QThread * m_ioThread
 
AsyncFileStoragem_fileStorage
 
QHash< QString, AutoDownloadRulem_rules
 
QList< QSharedPointer< ProcessingJob > > m_processingQueue
 
QHash< QString, QSharedPointer< ProcessingJob > > m_waitingJobs
 
bool m_dirty = false
 
QBasicTimer m_savingTimer
 
QRegularExpression m_smartEpisodeRegex
 

Static Private Attributes

static QPointer< AutoDownloaderm_instance = nullptr
 

Friends

class ::Application
 

Detailed Description

Definition at line 63 of file rss_autodownloader.h.

Member Enumeration Documentation

◆ RulesFileFormat

Enumerator
Legacy 
JSON 

Definition at line 74 of file rss_autodownloader.h.

75  {
76  Legacy,
77  JSON
78  };

Constructor & Destructor Documentation

◆ AutoDownloader()

AutoDownloader::AutoDownloader ( )
private

Definition at line 100 of file rss_autodownloader.cpp.

101  : m_storeProcessingEnabled("RSS/AutoDownloader/EnableProcessing", false)
102  , m_storeSmartEpisodeFilter("RSS/AutoDownloader/SmartEpisodeFilter")
103  , m_storeDownloadRepacks("RSS/AutoDownloader/DownloadRepacks")
104  , m_processingTimer(new QTimer(this))
105  , m_ioThread(new QThread(this))
106 {
107  Q_ASSERT(!m_instance); // only one instance is allowed
108  m_instance = this;
109 
112  if (!m_fileStorage)
113  throw RuntimeError(tr("Directory for RSS AutoDownloader data is unavailable."));
114 
115  m_fileStorage->moveToThread(m_ioThread);
116  connect(m_ioThread, &QThread::finished, m_fileStorage, &AsyncFileStorage::deleteLater);
117  connect(m_fileStorage, &AsyncFileStorage::failed, [](const QString &fileName, const QString &errorString)
118  {
119  LogMsg(tr("Couldn't save RSS AutoDownloader data in %1. Error: %2")
120  .arg(fileName, errorString), Log::CRITICAL);
121  });
122 
123  m_ioThread->start();
124 
129 
130  // initialise the smart episode regex
131  const QString regex = computeSmartFilterRegex(smartEpisodeFilters());
132  m_smartEpisodeRegex = QRegularExpression(regex,
133  QRegularExpression::CaseInsensitiveOption
134  | QRegularExpression::ExtendedPatternSyntaxOption
135  | QRegularExpression::UseUnicodePropertiesOption);
136 
137  load();
138 
139  m_processingTimer->setSingleShot(true);
140  connect(m_processingTimer, &QTimer::timeout, this, &AutoDownloader::process);
141 
142  if (isProcessingEnabled())
143  startProcessing();
144 }
void failed(const QString &fileName, const QString &errorString)
static Session * instance()
Definition: session.cpp:997
void downloadFromUrlFinished(const QString &url)
void downloadFromUrlFailed(const QString &url, const QString &reason)
CachedSettingValue< bool > m_storeProcessingEnabled
bool isProcessingEnabled() const
AsyncFileStorage * m_fileStorage
SettingValue< bool > m_storeDownloadRepacks
static QPointer< AutoDownloader > m_instance
SettingValue< QVariant > m_storeSmartEpisodeFilter
void handleTorrentDownloadFinished(const QString &url)
QStringList smartEpisodeFilters() const
QRegularExpression m_smartEpisodeRegex
void handleTorrentDownloadFailed(const QString &url)
void LogMsg(const QString &message, const Log::MsgType &type)
Definition: logger.cpp:125
@ CRITICAL
Definition: logger.h:48
QString fileName(const QString &filePath)
Definition: fs.cpp:87
QString expandPathAbs(const QString &path)
Definition: fs.cpp:309
QString specialFolderLocation(const SpecialFolder folder)
Definition: profile.cpp:131
const QString ConfFolderName(QStringLiteral("rss"))
QString computeSmartFilterRegex(const QStringList &filters)

References computeSmartFilterRegex(), ConfFolderName(), Config, Log::CRITICAL, BitTorrent::Session::downloadFromUrlFailed(), BitTorrent::Session::downloadFromUrlFinished(), Utils::Fs::expandPathAbs(), AsyncFileStorage::failed(), Utils::Fs::fileName(), handleTorrentDownloadFailed(), handleTorrentDownloadFinished(), BitTorrent::Session::instance(), isProcessingEnabled(), load(), LogMsg(), m_fileStorage, m_instance, m_ioThread, m_processingTimer, m_smartEpisodeRegex, process(), smartEpisodeFilters(), specialFolderLocation(), and startProcessing().

Here is the call graph for this function:

◆ ~AutoDownloader()

AutoDownloader::~AutoDownloader ( )
overrideprivate

Definition at line 146 of file rss_autodownloader.cpp.

147 {
148  store();
149 
150  m_ioThread->quit();
151  m_ioThread->wait();
152 }

References m_ioThread, and store().

Here is the call graph for this function:

Member Function Documentation

◆ addJobForArticle()

void AutoDownloader::addJobForArticle ( const Article article)
private

Definition at line 363 of file rss_autodownloader.cpp.

364 {
365  const QString torrentURL = article->torrentUrl();
366  if (m_waitingJobs.contains(torrentURL)) return;
367 
368  QSharedPointer<ProcessingJob> job(new ProcessingJob);
369  job->feedURL = article->feed()->url();
370  job->articleData = article->data();
371  m_processingQueue.append(job);
372  if (!m_processingTimer->isActive())
373  m_processingTimer->start();
374 }
QString torrentUrl() const
QVariantHash data() const
Feed * feed() const
QList< QSharedPointer< ProcessingJob > > m_processingQueue
QHash< QString, QSharedPointer< ProcessingJob > > m_waitingJobs
QString url() const
Definition: rss_feed.cpp:154

References RSS::Article::data(), RSS::Article::feed(), m_processingQueue, m_processingTimer, m_waitingJobs, RSS::Article::torrentUrl(), and RSS::Feed::url().

Referenced by handleNewArticle(), and resetProcessingQueue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ downloadRepacks()

bool AutoDownloader::downloadRepacks ( ) const

Definition at line 316 of file rss_autodownloader.cpp.

317 {
318  return m_storeDownloadRepacks.get(true);
319 }
T get(const T &defaultValue={}) const
Definition: settingvalue.h:46

References SettingValue< T >::get(), and m_storeDownloadRepacks.

Referenced by OptionsDialog::loadOptions(), and AppController::preferencesAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exportRules()

QByteArray AutoDownloader::exportRules ( AutoDownloader::RulesFileFormat  format = RulesFileFormat::JSON) const

Definition at line 221 of file rss_autodownloader.cpp.

222 {
223  switch (format)
224  {
226  return exportRulesToLegacyFormat();
227  default:
228  return exportRulesToJSONFormat();
229  }
230 }
QByteArray exportRulesToJSONFormat() const
QByteArray exportRulesToLegacyFormat() const

References exportRulesToJSONFormat(), exportRulesToLegacyFormat(), and Legacy.

Referenced by AutomatedRssDownloader::on_exportBtn_clicked().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exportRulesToJSONFormat()

QByteArray AutoDownloader::exportRulesToJSONFormat ( ) const
private

Definition at line 244 of file rss_autodownloader.cpp.

245 {
246  QJsonObject jsonObj;
247  for (const auto &rule : asConst(rules()))
248  jsonObj.insert(rule.name(), rule.toJsonObject());
249 
250  return QJsonDocument(jsonObj).toJson();
251 }
QList< AutoDownloadRule > rules() const
constexpr std::add_const_t< T > & asConst(T &t) noexcept
Definition: global.h:42

References asConst(), and rules().

Referenced by exportRules().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exportRulesToLegacyFormat()

QByteArray AutoDownloader::exportRulesToLegacyFormat ( ) const
private

Definition at line 259 of file rss_autodownloader.cpp.

260 {
261  QVariantHash dict;
262  for (const auto &rule : asConst(rules()))
263  dict[rule.name()] = rule.toLegacyDict();
264 
265  QByteArray data;
266  QDataStream out(&data, QIODevice::WriteOnly);
267  out.setVersion(QDataStream::Qt_4_5);
268  out << dict;
269 
270  return data;
271 }

References asConst(), and rules().

Referenced by exportRules().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleNewArticle

void AutoDownloader::handleNewArticle ( const Article article)
privateslot

Definition at line 352 of file rss_autodownloader.cpp.

353 {
354  if (!article->isRead() && !article->torrentUrl().isEmpty())
355  addJobForArticle(article);
356 }
bool isRead() const
void addJobForArticle(const Article *article)

References addJobForArticle(), RSS::Article::isRead(), and RSS::Article::torrentUrl().

Referenced by setProcessingEnabled(), and startProcessing().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleTorrentDownloadFailed

void AutoDownloader::handleTorrentDownloadFailed ( const QString &  url)
privateslot

Definition at line 346 of file rss_autodownloader.cpp.

347 {
348  m_waitingJobs.remove(url);
349  // TODO: Re-schedule job here.
350 }

References m_waitingJobs.

Referenced by AutoDownloader().

Here is the caller graph for this function:

◆ handleTorrentDownloadFinished

void AutoDownloader::handleTorrentDownloadFinished ( const QString &  url)
privateslot

Definition at line 336 of file rss_autodownloader.cpp.

337 {
338  const auto job = m_waitingJobs.take(url);
339  if (!job) return;
340 
341  if (Feed *feed = Session::instance()->feedByURL(job->feedURL))
342  if (Article *article = feed->articleByGUID(job->articleData.value(Article::KeyId).toString()))
343  article->markAsRead();
344 }
Definition: rss_article.h:43
static const QString KeyId
Definition: rss_article.h:53
static Session * instance()

References RSS::Session::instance(), RSS::Article::KeyId, and m_waitingJobs.

Referenced by AutoDownloader().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasRule()

bool AutoDownloader::hasRule ( const QString &  ruleName) const

Definition at line 159 of file rss_autodownloader.cpp.

160 {
161  return m_rules.contains(ruleName);
162 }
QHash< QString, AutoDownloadRule > m_rules

References m_rules.

Referenced by insertRule(), and renameRule().

Here is the caller graph for this function:

◆ importRules()

void AutoDownloader::importRules ( const QByteArray &  data,
const AutoDownloader::RulesFileFormat  format = RulesFileFormat::JSON 
)

Definition at line 232 of file rss_autodownloader.cpp.

233 {
234  switch (format)
235  {
238  break;
239  default:
241  }
242 }
void importRulesFromLegacyFormat(const QByteArray &data)
void importRulesFromJSONFormat(const QByteArray &data)

References importRulesFromJSONFormat(), importRulesFromLegacyFormat(), and Legacy.

Referenced by AutomatedRssDownloader::on_importBtn_clicked().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ importRulesFromJSONFormat()

void AutoDownloader::importRulesFromJSONFormat ( const QByteArray &  data)
private

Definition at line 253 of file rss_autodownloader.cpp.

254 {
255  for (const auto &rule : asConst(rulesFromJSON(data)))
256  insertRule(rule);
257 }
void insertRule(const AutoDownloadRule &rule)
QVector< RSS::AutoDownloadRule > rulesFromJSON(const QByteArray &jsonData)

References asConst(), insertRule(), and anonymous_namespace{rss_autodownloader.cpp}::rulesFromJSON().

Referenced by importRules().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ importRulesFromLegacyFormat()

void AutoDownloader::importRulesFromLegacyFormat ( const QByteArray &  data)
private

Definition at line 273 of file rss_autodownloader.cpp.

274 {
275  QDataStream in(data);
276  in.setVersion(QDataStream::Qt_4_5);
277  QVariantHash dict;
278  in >> dict;
279  if (in.status() != QDataStream::Ok)
280  throw ParsingError(tr("Invalid data format"));
281 
282  for (const QVariant &val : asConst(dict))
284 }
static AutoDownloadRule fromLegacyDict(const QVariantHash &dict)

References asConst(), RSS::AutoDownloadRule::fromLegacyDict(), and insertRule().

Referenced by importRules().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ insertRule()

void AutoDownloader::insertRule ( const AutoDownloadRule rule)

Definition at line 174 of file rss_autodownloader.cpp.

175 {
176  if (!hasRule(rule.name()))
177  {
178  // Insert new rule
179  setRule_impl(rule);
180  m_dirty = true;
181  store();
182  emit ruleAdded(rule.name());
184  }
185  else if (ruleByName(rule.name()) != rule)
186  {
187  // Update existing rule
188  setRule_impl(rule);
189  m_dirty = true;
190  storeDeferred();
191  emit ruleChanged(rule.name());
193  }
194 }
void ruleChanged(const QString &ruleName)
bool hasRule(const QString &ruleName) const
void setRule_impl(const AutoDownloadRule &rule)
void ruleAdded(const QString &ruleName)
AutoDownloadRule ruleByName(const QString &ruleName) const

References hasRule(), m_dirty, RSS::AutoDownloadRule::name(), resetProcessingQueue(), ruleAdded(), ruleByName(), ruleChanged(), setRule_impl(), store(), and storeDeferred().

Referenced by AutomatedRssDownloader::handleFeedCheckStateChange(), importRulesFromJSONFormat(), importRulesFromLegacyFormat(), loadRulesLegacy(), AutomatedRssDownloader::on_addRuleBtn_clicked(), AutomatedRssDownloader::saveEditedRule(), and RSSController::setRuleAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ instance()

◆ isProcessingEnabled()

bool AutoDownloader::isProcessingEnabled ( ) const

Definition at line 475 of file rss_autodownloader.cpp.

476 {
478 }

References m_storeProcessingEnabled.

Referenced by AutoDownloader(), OptionsDialog::loadOptions(), AppController::preferencesAction(), and resetProcessingQueue().

Here is the caller graph for this function:

◆ load()

void AutoDownloader::load ( )
private

Definition at line 415 of file rss_autodownloader.cpp.

416 {
417  QFile rulesFile(m_fileStorage->storageDir().absoluteFilePath(RulesFileName));
418 
419  if (!rulesFile.exists())
420  loadRulesLegacy();
421  else if (rulesFile.open(QFile::ReadOnly))
422  loadRules(rulesFile.readAll());
423  else
424  LogMsg(tr("Couldn't read RSS AutoDownloader rules from %1. Error: %2")
425  .arg(rulesFile.fileName(), rulesFile.errorString()), Log::CRITICAL);
426 }
QDir storageDir() const
void loadRules(const QByteArray &data)
const QString RulesFileName(QStringLiteral("download_rules.json"))

References Log::CRITICAL, loadRules(), loadRulesLegacy(), LogMsg(), m_fileStorage, RulesFileName(), and AsyncFileStorage::storageDir().

Referenced by AutoDownloader().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadRules()

void AutoDownloader::loadRules ( const QByteArray &  data)
private

Definition at line 428 of file rss_autodownloader.cpp.

429 {
430  try
431  {
432  const auto rules = rulesFromJSON(data);
433  for (const auto &rule : rules)
434  setRule_impl(rule);
435  }
436  catch (const ParsingError &error)
437  {
438  LogMsg(tr("Couldn't load RSS AutoDownloader rules. Reason: %1")
439  .arg(error.message()), Log::CRITICAL);
440  }
441 }
QString message() const noexcept
Definition: exceptions.cpp:36

References Log::CRITICAL, LogMsg(), Exception::message(), rules(), anonymous_namespace{rss_autodownloader.cpp}::rulesFromJSON(), and setRule_impl().

Referenced by load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadRulesLegacy()

void AutoDownloader::loadRulesLegacy ( )
private

Definition at line 443 of file rss_autodownloader.cpp.

444 {
445  const SettingsPtr settings = Profile::instance()->applicationSettings(QStringLiteral("qBittorrent-rss"));
446  const QVariantHash rules = settings->value(QStringLiteral("download_rules")).toHash();
447  for (const QVariant &ruleVar : rules)
448  {
449  const auto rule = AutoDownloadRule::fromLegacyDict(ruleVar.toHash());
450  if (!rule.name().isEmpty())
451  insertRule(rule);
452  }
453 }
SettingsPtr applicationSettings(const QString &name) const
Definition: profile.cpp:109
static const Profile * instance()
Definition: profile.cpp:67
std::unique_ptr< QSettings > SettingsPtr
Definition: profile.h:44

References Profile::applicationSettings(), RSS::AutoDownloadRule::fromLegacyDict(), insertRule(), Profile::instance(), rules(), and anonymous_namespace{addnewtorrentdialog.cpp}::settings().

Referenced by load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process

void AutoDownloader::process ( )
privateslot

Definition at line 326 of file rss_autodownloader.cpp.

327 {
328  if (m_processingQueue.isEmpty()) return; // processing was disabled
329 
330  processJob(m_processingQueue.takeFirst());
331  if (!m_processingQueue.isEmpty())
332  // Schedule to process the next torrent (if any)
333  m_processingTimer->start();
334 }
void processJob(const QSharedPointer< ProcessingJob > &job)

References m_processingQueue, m_processingTimer, and processJob().

Referenced by AutoDownloader().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processingStateChanged

void RSS::AutoDownloader::processingStateChanged ( bool  enabled)
signal

Referenced by AutomatedRssDownloader::AutomatedRssDownloader(), and setProcessingEnabled().

Here is the caller graph for this function:

◆ processJob()

void AutoDownloader::processJob ( const QSharedPointer< ProcessingJob > &  job)
private

Definition at line 376 of file rss_autodownloader.cpp.

377 {
378  for (AutoDownloadRule &rule : m_rules)
379  {
380  if (!rule.isEnabled()) continue;
381  if (!rule.feedURLs().contains(job->feedURL)) continue;
382  if (!rule.accepts(job->articleData)) continue;
383 
384  m_dirty = true;
385  storeDeferred();
386 
388  params.savePath = rule.savePath();
389  params.category = rule.assignedCategory();
390  params.addPaused = rule.addPaused();
391  params.contentLayout = rule.torrentContentLayout();
392  if (!rule.savePath().isEmpty())
393  params.useAutoTMM = false;
394  const auto torrentURL = job->articleData.value(Article::KeyTorrentURL).toString();
395  BitTorrent::Session::instance()->addTorrent(torrentURL, params);
396 
397  if (BitTorrent::MagnetUri(torrentURL).isValid())
398  {
399  if (Feed *feed = Session::instance()->feedByURL(job->feedURL))
400  {
401  if (Article *article = feed->articleByGUID(job->articleData.value(Article::KeyId).toString()))
402  article->markAsRead();
403  }
404  }
405  else
406  {
407  // waiting for torrent file downloading
408  m_waitingJobs.insert(torrentURL, job);
409  }
410 
411  return;
412  }
413 }
bool addTorrent(const QString &source, const AddTorrentParams &params=AddTorrentParams())
Definition: session.cpp:2007
static const QString KeyTorrentURL
Definition: rss_article.h:58
std::optional< bool > useAutoTMM
std::optional< bool > addPaused
std::optional< BitTorrent::TorrentContentLayout > contentLayout

References BitTorrent::AddTorrentParams::addPaused, BitTorrent::Session::addTorrent(), BitTorrent::AddTorrentParams::category, BitTorrent::AddTorrentParams::contentLayout, BitTorrent::Session::instance(), RSS::Session::instance(), RSS::Article::KeyId, RSS::Article::KeyTorrentURL, m_dirty, m_rules, m_waitingJobs, BitTorrent::AddTorrentParams::savePath, storeDeferred(), and BitTorrent::AddTorrentParams::useAutoTMM.

Referenced by process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeRule()

void AutoDownloader::removeRule ( const QString &  ruleName)

Definition at line 210 of file rss_autodownloader.cpp.

211 {
212  if (m_rules.contains(ruleName))
213  {
214  emit ruleAboutToBeRemoved(ruleName);
215  m_rules.remove(ruleName);
216  m_dirty = true;
217  store();
218  }
219 }
void ruleAboutToBeRemoved(const QString &ruleName)

References m_dirty, m_rules, ruleAboutToBeRemoved(), and store().

Referenced by AutomatedRssDownloader::on_removeRuleBtn_clicked(), and RSSController::removeRuleAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ renameRule()

bool AutoDownloader::renameRule ( const QString &  ruleName,
const QString &  newRuleName 
)

Definition at line 196 of file rss_autodownloader.cpp.

197 {
198  if (!hasRule(ruleName)) return false;
199  if (hasRule(newRuleName)) return false;
200 
201  AutoDownloadRule rule = m_rules.take(ruleName);
202  rule.setName(newRuleName);
203  m_rules.insert(newRuleName, rule);
204  m_dirty = true;
205  store();
206  emit ruleRenamed(newRuleName, ruleName);
207  return true;
208 }
void setName(const QString &name)
void ruleRenamed(const QString &ruleName, const QString &oldRuleName)

References hasRule(), m_dirty, m_rules, ruleRenamed(), RSS::AutoDownloadRule::setName(), and store().

Referenced by RSSController::renameRuleAction(), and AutomatedRssDownloader::renameSelectedRule().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetProcessingQueue()

void AutoDownloader::resetProcessingQueue ( )
private

Definition at line 480 of file rss_autodownloader.cpp.

481 {
482  m_processingQueue.clear();
483  if (!isProcessingEnabled()) return;
484 
485  for (Article *article : asConst(Session::instance()->rootFolder()->articles()))
486  {
487  if (!article->isRead() && !article->torrentUrl().isEmpty())
488  addJobForArticle(article);
489  }
490 }

References addJobForArticle(), asConst(), RSS::Session::instance(), isProcessingEnabled(), and m_processingQueue.

Referenced by insertRule(), and startProcessing().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ruleAboutToBeRemoved

void RSS::AutoDownloader::ruleAboutToBeRemoved ( const QString &  ruleName)
signal

Referenced by AutomatedRssDownloader::AutomatedRssDownloader(), and removeRule().

Here is the caller graph for this function:

◆ ruleAdded

void RSS::AutoDownloader::ruleAdded ( const QString &  ruleName)
signal

Referenced by AutomatedRssDownloader::AutomatedRssDownloader(), and insertRule().

Here is the caller graph for this function:

◆ ruleByName()

AutoDownloadRule AutoDownloader::ruleByName ( const QString &  ruleName) const

◆ ruleChanged

void RSS::AutoDownloader::ruleChanged ( const QString &  ruleName)
signal

Referenced by AutomatedRssDownloader::AutomatedRssDownloader(), and insertRule().

Here is the caller graph for this function:

◆ ruleRenamed

void RSS::AutoDownloader::ruleRenamed ( const QString &  ruleName,
const QString &  oldRuleName 
)
signal

Referenced by AutomatedRssDownloader::AutomatedRssDownloader(), and renameRule().

Here is the caller graph for this function:

◆ rules()

QList< AutoDownloadRule > AutoDownloader::rules ( ) const

Definition at line 169 of file rss_autodownloader.cpp.

170 {
171  return m_rules.values();
172 }

References m_rules.

Referenced by exportRulesToJSONFormat(), exportRulesToLegacyFormat(), loadRules(), loadRulesLegacy(), and RSSController::rulesAction().

Here is the caller graph for this function:

◆ setDownloadRepacks()

void AutoDownloader::setDownloadRepacks ( bool  enabled)

Definition at line 321 of file rss_autodownloader.cpp.

322 {
323  m_storeDownloadRepacks = enabled;
324 }

References m_storeDownloadRepacks.

Referenced by OptionsDialog::saveOptions(), and AppController::setPreferencesAction().

Here is the caller graph for this function:

◆ setProcessingEnabled()

void AutoDownloader::setProcessingEnabled ( bool  enabled)

Definition at line 498 of file rss_autodownloader.cpp.

499 {
500  if (m_storeProcessingEnabled != enabled)
501  {
502  m_storeProcessingEnabled = enabled;
503  if (enabled)
504  {
505  startProcessing();
506  }
507  else
508  {
509  m_processingQueue.clear();
510  disconnect(Session::instance()->rootFolder(), &Folder::newArticle, this, &AutoDownloader::handleNewArticle);
511  }
512 
513  emit processingStateChanged(enabled);
514  }
515 }
void processingStateChanged(bool enabled)
void handleNewArticle(const Article *article)
void newArticle(Article *article)

References handleNewArticle(), RSS::Session::instance(), m_processingQueue, m_storeProcessingEnabled, RSS::Item::newArticle(), processingStateChanged(), and startProcessing().

Referenced by OptionsDialog::saveOptions(), and AppController::setPreferencesAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRule_impl()

void AutoDownloader::setRule_impl ( const AutoDownloadRule rule)
private

Definition at line 358 of file rss_autodownloader.cpp.

359 {
360  m_rules.insert(rule.name(), rule);
361 }

References m_rules, and RSS::AutoDownloadRule::name().

Referenced by insertRule(), and loadRules().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSmartEpisodeFilters()

void AutoDownloader::setSmartEpisodeFilters ( const QStringList &  filters)

Definition at line 308 of file rss_autodownloader.cpp.

309 {
310  m_storeSmartEpisodeFilter = filters;
311 
312  const QString regex = computeSmartFilterRegex(filters);
313  m_smartEpisodeRegex.setPattern(regex);
314 }

References computeSmartFilterRegex(), m_smartEpisodeRegex, and m_storeSmartEpisodeFilter.

Referenced by OptionsDialog::saveOptions(), and AppController::setPreferencesAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ smartEpisodeFilters()

QStringList AutoDownloader::smartEpisodeFilters ( ) const

Definition at line 286 of file rss_autodownloader.cpp.

287 {
288  const QVariant filter = m_storeSmartEpisodeFilter.get();
289  if (filter.isNull())
290  {
291  const QStringList defaultFilters =
292  {
293  "s(\\d+)e(\\d+)", // Format 1: s01e01
294  "(\\d+)x(\\d+)", // Format 2: 01x01
295  "(\\d{4}[.\\-]\\d{1,2}[.\\-]\\d{1,2})", // Format 3: 2017.01.01
296  "(\\d{1,2}[.\\-]\\d{1,2}[.\\-]\\d{4})" // Format 4: 01.01.2017
297  };
298  return defaultFilters;
299  }
300  return filter.toStringList();
301 }

References SettingValue< T >::get(), and m_storeSmartEpisodeFilter.

Referenced by AutoDownloader(), OptionsDialog::loadOptions(), and AppController::preferencesAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ smartEpisodeRegex()

QRegularExpression AutoDownloader::smartEpisodeRegex ( ) const

Definition at line 303 of file rss_autodownloader.cpp.

304 {
305  return m_smartEpisodeRegex;
306 }

References m_smartEpisodeRegex.

Referenced by computeEpisodeName().

Here is the caller graph for this function:

◆ startProcessing()

void AutoDownloader::startProcessing ( )
private

Definition at line 492 of file rss_autodownloader.cpp.

493 {
495  connect(Session::instance()->rootFolder(), &Folder::newArticle, this, &AutoDownloader::handleNewArticle);
496 }

References handleNewArticle(), RSS::Session::instance(), RSS::Item::newArticle(), and resetProcessingQueue().

Referenced by AutoDownloader(), and setProcessingEnabled().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ store()

void AutoDownloader::store ( )
private

Definition at line 455 of file rss_autodownloader.cpp.

456 {
457  if (!m_dirty) return;
458 
459  m_dirty = false;
460  m_savingTimer.stop();
461 
462  QJsonObject jsonObj;
463  for (const auto &rule : asConst(m_rules))
464  jsonObj.insert(rule.name(), rule.toJsonObject());
465 
466  m_fileStorage->store(RulesFileName, QJsonDocument(jsonObj).toJson());
467 }
void store(const QString &fileName, const QByteArray &data)

References asConst(), m_dirty, m_fileStorage, m_rules, m_savingTimer, RulesFileName(), and AsyncFileStorage::store().

Referenced by insertRule(), removeRule(), renameRule(), timerEvent(), and ~AutoDownloader().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ storeDeferred()

void AutoDownloader::storeDeferred ( )
private

Definition at line 469 of file rss_autodownloader.cpp.

470 {
471  if (!m_savingTimer.isActive())
472  m_savingTimer.start(5 * 1000, this);
473 }

References m_savingTimer.

Referenced by insertRule(), and processJob().

Here is the caller graph for this function:

◆ timerEvent()

void AutoDownloader::timerEvent ( QTimerEvent *  event)
overrideprivate

Definition at line 517 of file rss_autodownloader.cpp.

518 {
519  Q_UNUSED(event);
520  store();
521 }

References store().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ ::Application

friend class ::Application
friend

Definition at line 68 of file rss_autodownloader.h.

Member Data Documentation

◆ m_dirty

bool RSS::AutoDownloader::m_dirty = false
private

Definition at line 145 of file rss_autodownloader.h.

Referenced by insertRule(), processJob(), removeRule(), renameRule(), and store().

◆ m_fileStorage

AsyncFileStorage* RSS::AutoDownloader::m_fileStorage
private

Definition at line 141 of file rss_autodownloader.h.

Referenced by AutoDownloader(), load(), and store().

◆ m_instance

QPointer< AutoDownloader > AutoDownloader::m_instance = nullptr
staticprivate

Definition at line 133 of file rss_autodownloader.h.

Referenced by AutoDownloader(), and instance().

◆ m_ioThread

QThread* RSS::AutoDownloader::m_ioThread
private

Definition at line 140 of file rss_autodownloader.h.

Referenced by AutoDownloader(), and ~AutoDownloader().

◆ m_processingQueue

QList<QSharedPointer<ProcessingJob> > RSS::AutoDownloader::m_processingQueue
private

◆ m_processingTimer

QTimer* RSS::AutoDownloader::m_processingTimer
private

Definition at line 139 of file rss_autodownloader.h.

Referenced by addJobForArticle(), AutoDownloader(), and process().

◆ m_rules

QHash<QString, AutoDownloadRule> RSS::AutoDownloader::m_rules
private

◆ m_savingTimer

QBasicTimer RSS::AutoDownloader::m_savingTimer
private

Definition at line 146 of file rss_autodownloader.h.

Referenced by store(), and storeDeferred().

◆ m_smartEpisodeRegex

QRegularExpression RSS::AutoDownloader::m_smartEpisodeRegex
private

Definition at line 147 of file rss_autodownloader.h.

Referenced by AutoDownloader(), setSmartEpisodeFilters(), and smartEpisodeRegex().

◆ m_storeDownloadRepacks

SettingValue<bool> RSS::AutoDownloader::m_storeDownloadRepacks
private

Definition at line 137 of file rss_autodownloader.h.

Referenced by downloadRepacks(), and setDownloadRepacks().

◆ m_storeProcessingEnabled

CachedSettingValue<bool> RSS::AutoDownloader::m_storeProcessingEnabled
private

Definition at line 135 of file rss_autodownloader.h.

Referenced by isProcessingEnabled(), and setProcessingEnabled().

◆ m_storeSmartEpisodeFilter

SettingValue<QVariant> RSS::AutoDownloader::m_storeSmartEpisodeFilter
private

Definition at line 136 of file rss_autodownloader.h.

Referenced by setSmartEpisodeFilters(), and smartEpisodeFilters().

◆ m_waitingJobs

QHash<QString, QSharedPointer<ProcessingJob> > RSS::AutoDownloader::m_waitingJobs
private

The documentation for this class was generated from the following files: