From 70ce12372df93c74cf9376c0a0419b8fcdc5e21e Mon Sep 17 00:00:00 2001 From: Tim Delaney Date: Sun, 8 Jan 2017 11:46:01 +1100 Subject: [PATCH] Follow project coding style. Issue #2192. --HG-- branch : magao-dev --- src/base/rss/rssdownloadrule.cpp | 4 +- src/base/rss/rssfeed.cpp | 28 +- src/base/rss/rssfeed.h | 2 +- src/gui/rss/automatedrssdownloader.cpp | 979 +++++++++++++------------ src/gui/rss/automatedrssdownloader.h | 76 +- src/gui/rss/rss_imp.cpp | 132 ++-- src/gui/rss/rss_imp.h | 21 +- src/gui/torrentmodel.cpp | 24 +- 8 files changed, 632 insertions(+), 634 deletions(-) diff --git a/src/base/rss/rssdownloadrule.cpp b/src/base/rss/rssdownloadrule.cpp index 6d5bfc8ce..62a163ca8 100644 --- a/src/base/rss/rssdownloadrule.cpp +++ b/src/base/rss/rssdownloadrule.cpp @@ -110,7 +110,7 @@ bool DownloadRule::matches(const QString &articleTitle) const pos = reg.indexIn(articleTitle); if (pos != -1) { int epTheirs = reg.cap(1).toInt(); - if (epOursFirst <= epTheirs && epOursLast >= epTheirs) + if ((epOursFirst <= epTheirs) && (epOursLast >= epTheirs)) return true; } } @@ -300,7 +300,7 @@ QStringList DownloadRule::findMatchingArticles(const FeedPtr &feed) const ArticleHash::ConstIterator artIt = feedArticles.begin(); ArticleHash::ConstIterator artItend = feedArticles.end(); - for ( ; artIt != artItend ; ++artIt) { + for (; artIt != artItend; ++artIt) { const QString title = artIt.value()->title(); if (matches(title)) ret << title; diff --git a/src/base/rss/rssfeed.cpp b/src/base/rss/rssfeed.cpp index 28f46cc2e..91f9debe7 100644 --- a/src/base/rss/rssfeed.cpp +++ b/src/base/rss/rssfeed.cpp @@ -78,7 +78,7 @@ Feed::Feed(const QString &url, Manager *manager) // Download the RSS Feed icon Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(iconUrl(), true); - connect(handler, SIGNAL(downloadFinished(QString, QString)), this, SLOT(handleIconDownloadFinished(QString, QString))); + connect(handler, SIGNAL(downloadFinished(QString,QString)), this, SLOT(handleIconDownloadFinished(QString,QString))); // Load old RSS articles loadItemsFromDisk(); @@ -104,9 +104,8 @@ void Feed::saveItemsToDisk() ArticleHash::ConstIterator it = m_articles.begin(); ArticleHash::ConstIterator itend = m_articles.end(); - for ( ; it != itend; ++it) { + for (; it != itend; ++it) oldItems << it.value()->toHash(); - } qDebug("Saving %d old items for feed %s", oldItems.size(), qPrintable(displayName())); QHash allOldItems = qBTRSS.value("old_items", QHash()).toHash(); allOldItems[m_url] = oldItems; @@ -155,20 +154,18 @@ void Feed::addArticle(const ArticlePtr &article) } // Check if article was inserted at the end of the list and will break max_articles limit - if (Preferences::instance()->isRssDownloadingEnabled()) { + if (Preferences::instance()->isRssDownloadingEnabled()) if ((lbIndex < maxArticles) && !article->isRead()) downloadArticleTorrentIfMatching(article); - } } else { // m_articles.contains(article->guid()) // Try to download skipped articles if (Preferences::instance()->isRssDownloadingEnabled()) { ArticlePtr skipped = m_articles.value(article->guid(), ArticlePtr()); - if (skipped) { + if (skipped) if (!skipped->isRead()) downloadArticleTorrentIfMatching(skipped); - } } } } @@ -182,8 +179,8 @@ bool Feed::refresh() m_loading = true; // Download the RSS again Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(m_url); - connect(handler, SIGNAL(downloadFinished(QString, QByteArray)), this, SLOT(handleRssDownloadFinished(QString, QByteArray))); - connect(handler, SIGNAL(downloadFailed(QString, QString)), this, SLOT(handleRssDownloadFailed(QString, QString))); + connect(handler, SIGNAL(downloadFinished(QString,QByteArray)), this, SLOT(handleRssDownloadFinished(QString,QByteArray))); + connect(handler, SIGNAL(downloadFailed(QString,QString)), this, SLOT(handleRssDownloadFailed(QString,QString))); return true; } @@ -260,7 +257,7 @@ bool Feed::hasCustomIcon() const void Feed::setIconPath(const QString &path) { QString nativePath = Utils::Fs::fromNativePath(path); - if (nativePath == m_icon || nativePath.isEmpty() || !QFile::exists(nativePath)) return; + if ((nativePath == m_icon) || nativePath.isEmpty() || !QFile::exists(nativePath)) return; if (!m_icon.startsWith(":/") && QFile::exists(m_icon)) Utils::Fs::forceRemove(m_icon); @@ -282,9 +279,8 @@ void Feed::markAsRead() { ArticleHash::ConstIterator it = m_articles.begin(); ArticleHash::ConstIterator itend = m_articles.end(); - for ( ; it != itend; ++it) { + for (; it != itend; ++it) it.value()->markAsRead(); - } m_unreadCount = 0; m_manager->forwardFeedInfosChanged(m_url, displayName(), 0); } @@ -310,10 +306,9 @@ ArticleList Feed::unreadArticleListByDateDesc() const ArticleList::ConstIterator it = m_articlesByDate.begin(); ArticleList::ConstIterator itend = m_articlesByDate.end(); - for ( ; it != itend; ++it) { + for (; it != itend; ++it) if (!(*it)->isRead()) unreadNews << *it; - } return unreadNews; } @@ -407,10 +402,9 @@ void Feed::downloadArticleTorrentIfMatching(const ArticlePtr &article) void Feed::recheckRssItemsForDownload() { Q_ASSERT(Preferences::instance()->isRssDownloadingEnabled()); - foreach (const ArticlePtr &article, m_articlesByDate) { + foreach (const ArticlePtr &article, m_articlesByDate) if (!article->isRead()) downloadArticleTorrentIfMatching(article); - } } void Feed::handleNewArticle(const QVariantHash &articleData) @@ -426,7 +420,7 @@ void Feed::handleNewArticle(const QVariantHash &articleData) m_manager->forwardFeedInfosChanged(m_url, displayName(), m_unreadCount); // FIXME: We should forward the information here but this would seriously decrease // performance with current design. - //m_manager->forwardFeedContentChanged(m_url); + // m_manager->forwardFeedContentChanged(m_url); } void Feed::handleParsingFinished(const QString &error) diff --git a/src/base/rss/rssfeed.h b/src/base/rss/rssfeed.h index b457a04b4..1dfe0fcba 100644 --- a/src/base/rss/rssfeed.h +++ b/src/base/rss/rssfeed.h @@ -64,7 +64,7 @@ namespace Rss Q_OBJECT public: - Feed(const QString &url, Manager *manager); + Feed(const QString &url, Manager * manager); ~Feed(); bool refresh(); diff --git a/src/gui/rss/automatedrssdownloader.cpp b/src/gui/rss/automatedrssdownloader.cpp index 9a2483f6c..3abc02bbf 100644 --- a/src/gui/rss/automatedrssdownloader.cpp +++ b/src/gui/rss/automatedrssdownloader.cpp @@ -47,602 +47,607 @@ #include "ui_automatedrssdownloader.h" #include "automatedrssdownloader.h" -AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer& manager, QWidget *parent) : - QDialog(parent), - ui(new Ui::AutomatedRssDownloader), - m_manager(manager), m_editedRule(0) +AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer &manager, QWidget *parent) + : QDialog(parent), + ui(new Ui::AutomatedRssDownloader), + m_manager(manager), m_editedRule(0) { - ui->setupUi(this); - // Icons - ui->removeRuleBtn->setIcon(GuiIconProvider::instance()->getIcon("list-remove")); - ui->addRuleBtn->setIcon(GuiIconProvider::instance()->getIcon("list-add")); - - // Ui Settings - ui->listRules->setSortingEnabled(true); - ui->listRules->setSelectionMode(QAbstractItemView::ExtendedSelection); - ui->treeMatchingArticles->setSortingEnabled(true); - ui->hsplitter->setCollapsible(0, false); - ui->hsplitter->setCollapsible(1, false); - ui->hsplitter->setCollapsible(2, true); // Only the preview list is collapsible - bool ok; Q_UNUSED(ok); - ok = connect(ui->checkRegex, SIGNAL(toggled(bool)), SLOT(updateFieldsToolTips(bool))); - Q_ASSERT(ok); - ok = connect(ui->listRules, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRulesListMenu(const QPoint&))); - Q_ASSERT(ok); - m_ruleList = manager.toStrongRef()->downloadRules(); - m_editableRuleList = new Rss::DownloadRuleList; // Read rule list from disk - m_episodeValidator = new QRegExpValidator( - QRegExp("^(^[1-9]{1,1}\\d{0,3}x([1-9]{1,1}\\d{0,3}(-([1-9]{1,1}\\d{0,3})?)?;){1,}){1,1}", - Qt::CaseInsensitive), - ui->lineEFilter); - ui->lineEFilter->setValidator(m_episodeValidator); - QString tip = "

" + tr("Matches articles based on episode filter.") + "

" + tr("Example: ") + - "1x2;8-15;5;30-;" + tr(" will match 2, 5, 8 through 15, 30 and onward episodes of season one", "example X will match") + "

"; - tip += "

" + tr("Episode filter rules: ") + "

  • " + tr("Season number is a mandatory non-zero value") + "
  • " + - "
  • " + tr("Episode number is a mandatory non-zero value") + "
  • " + - "
  • " + tr("Filter must end with semicolon") + "
  • " + - "
  • " + tr("Three range types for episodes are supported: ") + "
  • " + "
    • " - "
    • " + tr("Single number: 1x25; matches episode 25 of season one") + "
    • " + - "
    • " + tr("Normal range: 1x25-40; matches episodes 25 through 40 of season one") + "
    • " + - "
    • " + tr("Infinite range: 1x25-; matches episodes 25 and upward of season one") + "
    • " + "
"; - ui->lineEFilter->setToolTip(tip); - initCategoryCombobox(); - loadFeedList(); - loadSettings(); - ok = connect(ui->listRules, SIGNAL(itemSelectionChanged()), SLOT(updateRuleDefinitionBox())); - Q_ASSERT(ok); - ok = connect(ui->listRules, SIGNAL(itemSelectionChanged()), SLOT(updateFeedList())); - Q_ASSERT(ok); - ok = connect(ui->listFeeds, SIGNAL(itemChanged(QListWidgetItem*)), SLOT(handleFeedCheckStateChange(QListWidgetItem*))); - Q_ASSERT(ok); - // Update matching articles when necessary - ok = connect(ui->lineContains, SIGNAL(textEdited(QString)), SLOT(updateMatchingArticles())); - Q_ASSERT(ok); - ok = connect(ui->lineContains, SIGNAL(textEdited(QString)), SLOT(updateMustLineValidity())); - Q_ASSERT(ok); - ok = connect(ui->lineNotContains, SIGNAL(textEdited(QString)), SLOT(updateMatchingArticles())); - Q_ASSERT(ok); - ok = connect(ui->lineNotContains, SIGNAL(textEdited(QString)), SLOT(updateMustNotLineValidity())); - Q_ASSERT(ok); - ok = connect(ui->checkRegex, SIGNAL(stateChanged(int)), SLOT(updateMatchingArticles())); - Q_ASSERT(ok); - ok = connect(ui->checkRegex, SIGNAL(stateChanged(int)), SLOT(updateMustLineValidity())); - Q_ASSERT(ok); - ok = connect(ui->checkRegex, SIGNAL(stateChanged(int)), SLOT(updateMustNotLineValidity())); - Q_ASSERT(ok); - ok = connect(this, SIGNAL(finished(int)), SLOT(onFinished(int))); - Q_ASSERT(ok); - ok = connect(ui->lineEFilter, SIGNAL(textEdited(QString)), SLOT(updateMatchingArticles())); - Q_ASSERT(ok); - editHotkey = new QShortcut(QKeySequence("F2"), ui->listRules, 0, 0, Qt::WidgetShortcut); - ok = connect(editHotkey, SIGNAL(activated()), SLOT(renameSelectedRule())); - Q_ASSERT(ok); - ok = connect(ui->listRules, SIGNAL(doubleClicked(QModelIndex)), SLOT(renameSelectedRule())); - Q_ASSERT(ok); - deleteHotkey = new QShortcut(QKeySequence::Delete, ui->listRules, 0, 0, Qt::WidgetShortcut); - ok = connect(deleteHotkey, SIGNAL(activated()), SLOT(on_removeRuleBtn_clicked())); - Q_ASSERT(ok); - updateRuleDefinitionBox(); - updateFeedList(); + ui->setupUi(this); + // Icons + ui->removeRuleBtn->setIcon(GuiIconProvider::instance()->getIcon("list-remove")); + ui->addRuleBtn->setIcon(GuiIconProvider::instance()->getIcon("list-add")); + + // Ui Settings + ui->listRules->setSortingEnabled(true); + ui->listRules->setSelectionMode(QAbstractItemView::ExtendedSelection); + ui->treeMatchingArticles->setSortingEnabled(true); + ui->hsplitter->setCollapsible(0, false); + ui->hsplitter->setCollapsible(1, false); + ui->hsplitter->setCollapsible(2, true); // Only the preview list is collapsible + bool ok; Q_UNUSED(ok); + ok = connect(ui->checkRegex, SIGNAL(toggled(bool)), SLOT(updateFieldsToolTips(bool))); + Q_ASSERT(ok); + ok = connect(ui->listRules, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRulesListMenu(const QPoint&))); + Q_ASSERT(ok); + m_ruleList = manager.toStrongRef()->downloadRules(); + m_editableRuleList = new Rss::DownloadRuleList; // Read rule list from disk + m_episodeValidator = new QRegExpValidator( + QRegExp("^(^[1-9]{1,1}\\d{0,3}x([1-9]{1,1}\\d{0,3}(-([1-9]{1,1}\\d{0,3})?)?;){1,}){1,1}", + Qt::CaseInsensitive), + ui->lineEFilter); + ui->lineEFilter->setValidator(m_episodeValidator); + QString tip = "

" + tr("Matches articles based on episode filter.") + "

" + tr("Example: ") + + "1x2;8-15;5;30-;" + tr(" will match 2, 5, 8 through 15, 30 and onward episodes of season one", "example X will match") + "

"; + tip += "

" + tr("Episode filter rules: ") + "

  • " + tr("Season number is a mandatory non-zero value") + "
  • " + + "
  • " + tr("Episode number is a mandatory non-zero value") + "
  • " + + "
  • " + tr("Filter must end with semicolon") + "
  • " + + "
  • " + tr("Three range types for episodes are supported: ") + "
  • " + "
    • " + "
    • " + tr("Single number: 1x25; matches episode 25 of season one") + "
    • " + + "
    • " + tr("Normal range: 1x25-40; matches episodes 25 through 40 of season one") + "
    • " + + "
    • " + tr("Infinite range: 1x25-; matches episodes 25 and upward of season one") + "
    • " + "
"; + ui->lineEFilter->setToolTip(tip); + initCategoryCombobox(); + loadFeedList(); + loadSettings(); + ok = connect(ui->listRules, SIGNAL(itemSelectionChanged()), SLOT(updateRuleDefinitionBox())); + Q_ASSERT(ok); + ok = connect(ui->listRules, SIGNAL(itemSelectionChanged()), SLOT(updateFeedList())); + Q_ASSERT(ok); + ok = connect(ui->listFeeds, SIGNAL(itemChanged(QListWidgetItem *)), SLOT(handleFeedCheckStateChange(QListWidgetItem *))); + Q_ASSERT(ok); + // Update matching articles when necessary + ok = connect(ui->lineContains, SIGNAL(textEdited(QString)), SLOT(updateMatchingArticles())); + Q_ASSERT(ok); + ok = connect(ui->lineContains, SIGNAL(textEdited(QString)), SLOT(updateMustLineValidity())); + Q_ASSERT(ok); + ok = connect(ui->lineNotContains, SIGNAL(textEdited(QString)), SLOT(updateMatchingArticles())); + Q_ASSERT(ok); + ok = connect(ui->lineNotContains, SIGNAL(textEdited(QString)), SLOT(updateMustNotLineValidity())); + Q_ASSERT(ok); + ok = connect(ui->checkRegex, SIGNAL(stateChanged(int)), SLOT(updateMatchingArticles())); + Q_ASSERT(ok); + ok = connect(ui->checkRegex, SIGNAL(stateChanged(int)), SLOT(updateMustLineValidity())); + Q_ASSERT(ok); + ok = connect(ui->checkRegex, SIGNAL(stateChanged(int)), SLOT(updateMustNotLineValidity())); + Q_ASSERT(ok); + ok = connect(this, SIGNAL(finished(int)), SLOT(onFinished(int))); + Q_ASSERT(ok); + ok = connect(ui->lineEFilter, SIGNAL(textEdited(QString)), SLOT(updateMatchingArticles())); + Q_ASSERT(ok); + editHotkey = new QShortcut(QKeySequence("F2"), ui->listRules, 0, 0, Qt::WidgetShortcut); + ok = connect(editHotkey, SIGNAL(activated()), SLOT(renameSelectedRule())); + Q_ASSERT(ok); + ok = connect(ui->listRules, SIGNAL(doubleClicked(QModelIndex)), SLOT(renameSelectedRule())); + Q_ASSERT(ok); + deleteHotkey = new QShortcut(QKeySequence::Delete, ui->listRules, 0, 0, Qt::WidgetShortcut); + ok = connect(deleteHotkey, SIGNAL(activated()), SLOT(on_removeRuleBtn_clicked())); + Q_ASSERT(ok); + updateRuleDefinitionBox(); + updateFeedList(); } AutomatedRssDownloader::~AutomatedRssDownloader() { - qDebug() << Q_FUNC_INFO; - delete editHotkey; - delete deleteHotkey; - delete ui; - delete m_editableRuleList; - delete m_episodeValidator; + qDebug() << Q_FUNC_INFO; + delete editHotkey; + delete deleteHotkey; + delete ui; + delete m_editableRuleList; + delete m_episodeValidator; } void AutomatedRssDownloader::loadSettings() { - // load dialog geometry - const Preferences* const pref = Preferences::instance(); - restoreGeometry(pref->getRssGeometry()); - ui->checkEnableDownloader->setChecked(pref->isRssDownloadingEnabled()); - ui->hsplitter->restoreState(pref->getRssHSplitterSizes()); - // Display download rules - loadRulesList(); + // load dialog geometry + const Preferences *const pref = Preferences::instance(); + restoreGeometry(pref->getRssGeometry()); + ui->checkEnableDownloader->setChecked(pref->isRssDownloadingEnabled()); + ui->hsplitter->restoreState(pref->getRssHSplitterSizes()); + // Display download rules + loadRulesList(); } void AutomatedRssDownloader::saveSettings() { - Preferences::instance()->setRssDownloadingEnabled(ui->checkEnableDownloader->isChecked()); - // Save dialog geometry - Preferences* const pref = Preferences::instance(); - pref->setRssGeometry(saveGeometry()); - pref->setRssHSplitterSizes(ui->hsplitter->saveState()); + Preferences::instance()->setRssDownloadingEnabled(ui->checkEnableDownloader->isChecked()); + // Save dialog geometry + Preferences *const pref = Preferences::instance(); + pref->setRssGeometry(saveGeometry()); + pref->setRssHSplitterSizes(ui->hsplitter->saveState()); } void AutomatedRssDownloader::loadRulesList() { - // Make sure we save the current item before clearing - if (m_editedRule) { - saveEditedRule(); - } - ui->listRules->clear(); - foreach (const QString &rule_name, m_editableRuleList->ruleNames()) { - QListWidgetItem *item = new QListWidgetItem(rule_name, ui->listRules); - item->setFlags(item->flags()|Qt::ItemIsUserCheckable); - if (m_editableRuleList->getRule(rule_name)->isEnabled()) - item->setCheckState(Qt::Checked); - else - item->setCheckState(Qt::Unchecked); - } - if (ui->listRules->count() > 0 && !ui->listRules->currentItem()) - ui->listRules->setCurrentRow(0); + // Make sure we save the current item before clearing + if (m_editedRule) + saveEditedRule(); + ui->listRules->clear(); + foreach (const QString &rule_name, m_editableRuleList->ruleNames()) { + QListWidgetItem *item = new QListWidgetItem(rule_name, ui->listRules); + item->setFlags(item->flags() | Qt::ItemIsUserCheckable); + if (m_editableRuleList->getRule(rule_name)->isEnabled()) + item->setCheckState(Qt::Checked); + else + item->setCheckState(Qt::Unchecked); + } + if (( ui->listRules->count() > 0) && !ui->listRules->currentItem()) + ui->listRules->setCurrentRow(0); } void AutomatedRssDownloader::loadFeedList() { - const Preferences* const pref = Preferences::instance(); - const QStringList feed_aliases = pref->getRssFeedsAliases(); - const QStringList feed_urls = pref->getRssFeedsUrls(); - QStringList existing_urls; - for (int i=0; ilistFeeds); - item->setData(Qt::UserRole, feed_url); - item->setFlags(item->flags()|Qt::ItemIsUserCheckable); - existing_urls << feed_url; - } + const Preferences *const pref = Preferences::instance(); + const QStringList feed_aliases = pref->getRssFeedsAliases(); + const QStringList feed_urls = pref->getRssFeedsUrls(); + QStringList existing_urls; + for (int i = 0; ilistFeeds); + item->setData(Qt::UserRole, feed_url); + item->setFlags(item->flags() | Qt::ItemIsUserCheckable); + existing_urls << feed_url; + } } void AutomatedRssDownloader::updateFeedList() { - disconnect(ui->listFeeds, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(handleFeedCheckStateChange(QListWidgetItem*))); - for (int i=0; ilistFeeds->count(); ++i) { - QListWidgetItem *item = ui->listFeeds->item(i); - const QString feed_url = item->data(Qt::UserRole).toString(); - bool all_enabled = false; - foreach (const QListWidgetItem *ruleItem, ui->listRules->selectedItems()) { - Rss::DownloadRulePtr rule = m_editableRuleList->getRule(ruleItem->text()); - if (!rule) continue; - qDebug() << "Rule" << rule->name() << "affects" << rule->rssFeeds().size() << "feeds."; - foreach (QString test, rule->rssFeeds()) { - qDebug() << "Feed is " << test; - } - if (rule->rssFeeds().contains(feed_url)) { - qDebug() << "Rule " << rule->name() << " affects feed " << feed_url; - all_enabled = true; - } else { - qDebug() << "Rule " << rule->name() << " does NOT affect feed " << feed_url; - all_enabled = false; - break; - } + disconnect(ui->listFeeds, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(handleFeedCheckStateChange(QListWidgetItem *))); + for (int i = 0; ilistFeeds->count(); ++i) { + QListWidgetItem *item = ui->listFeeds->item(i); + const QString feed_url = item->data(Qt::UserRole).toString(); + bool all_enabled = false; + foreach (const QListWidgetItem *ruleItem, ui->listRules->selectedItems()) { + Rss::DownloadRulePtr rule = m_editableRuleList->getRule(ruleItem->text()); + if (!rule) continue; + qDebug() << "Rule" << rule->name() << "affects" << rule->rssFeeds().size() << "feeds."; + foreach (QString test, rule->rssFeeds()) + qDebug() << "Feed is " << test; + if (rule->rssFeeds().contains(feed_url)) { + qDebug() << "Rule " << rule->name() << " affects feed " << feed_url; + all_enabled = true; + } + else { + qDebug() << "Rule " << rule->name() << " does NOT affect feed " << feed_url; + all_enabled = false; + break; + } + } + if (all_enabled) + item->setCheckState(Qt::Checked); + else + item->setCheckState(Qt::Unchecked); } - if (all_enabled) - item->setCheckState(Qt::Checked); - else - item->setCheckState(Qt::Unchecked); - } - ui->listFeeds->setEnabled(!ui->listRules->selectedItems().isEmpty()); - connect(ui->listFeeds, SIGNAL(itemChanged(QListWidgetItem*)), SLOT(handleFeedCheckStateChange(QListWidgetItem*))); - updateMatchingArticles(); + ui->listFeeds->setEnabled(!ui->listRules->selectedItems().isEmpty()); + connect(ui->listFeeds, SIGNAL(itemChanged(QListWidgetItem *)), SLOT(handleFeedCheckStateChange(QListWidgetItem *))); + updateMatchingArticles(); } bool AutomatedRssDownloader::isRssDownloaderEnabled() const { - return ui->checkEnableDownloader->isChecked(); + return ui->checkEnableDownloader->isChecked(); } void AutomatedRssDownloader::updateRuleDefinitionBox() { - qDebug() << Q_FUNC_INFO; - // Save previous rule first - saveEditedRule(); - // Update rule definition box - const QList selection = ui->listRules->selectedItems(); - if (selection.count() == 1) { - m_editedRule = selection.first(); - Rss::DownloadRulePtr rule = getCurrentRule(); - if (rule) { - ui->lineContains->setText(rule->mustContain()); - ui->lineNotContains->setText(rule->mustNotContain()); - QString ep = rule->episodeFilter(); - if (!ep.isEmpty()) - ui->lineEFilter->setText(ep); - else - ui->lineEFilter->clear(); - ui->saveDiffDir_check->setChecked(!rule->savePath().isEmpty()); - ui->lineSavePath->setText(Utils::Fs::toNativePath(rule->savePath())); - ui->checkRegex->blockSignals(true); - ui->checkRegex->setChecked(rule->useRegex()); - ui->checkRegex->blockSignals(false); - if (rule->category().isEmpty()) { - ui->comboCategory->setCurrentIndex(-1); - ui->comboCategory->clearEditText(); - } else { - ui->comboCategory->setCurrentIndex(ui->comboCategory->findText(rule->category())); - } - ui->comboAddPaused->setCurrentIndex(rule->addPaused()); - ui->spinIgnorePeriod->setValue(rule->ignoreDays()); - QDateTime dateTime = rule->lastMatch(); - QString lMatch; - if (dateTime.isValid()) - lMatch = tr("Last Match: %1 days ago").arg(dateTime.daysTo(QDateTime::currentDateTime())); - else - lMatch = tr("Last Match: Unknown"); - ui->lblLastMatch->setText(lMatch); - updateMustLineValidity(); - updateMustNotLineValidity(); - } else { - // New rule - clearRuleDefinitionBox(); - ui->lineContains->setText(selection.first()->text()); - ui->comboAddPaused->setCurrentIndex(0); + qDebug() << Q_FUNC_INFO; + // Save previous rule first + saveEditedRule(); + // Update rule definition box + const QList selection = ui->listRules->selectedItems(); + if (selection.count() == 1) { + m_editedRule = selection.first(); + Rss::DownloadRulePtr rule = getCurrentRule(); + if (rule) { + ui->lineContains->setText(rule->mustContain()); + ui->lineNotContains->setText(rule->mustNotContain()); + QString ep = rule->episodeFilter(); + if (!ep.isEmpty()) + ui->lineEFilter->setText(ep); + else + ui->lineEFilter->clear(); + ui->saveDiffDir_check->setChecked(!rule->savePath().isEmpty()); + ui->lineSavePath->setText(Utils::Fs::toNativePath(rule->savePath())); + ui->checkRegex->blockSignals(true); + ui->checkRegex->setChecked(rule->useRegex()); + ui->checkRegex->blockSignals(false); + if (rule->category().isEmpty()) { + ui->comboCategory->setCurrentIndex(-1); + ui->comboCategory->clearEditText(); + } + else { + ui->comboCategory->setCurrentIndex(ui->comboCategory->findText(rule->category())); + } + ui->comboAddPaused->setCurrentIndex(rule->addPaused()); + ui->spinIgnorePeriod->setValue(rule->ignoreDays()); + QDateTime dateTime = rule->lastMatch(); + QString lMatch; + if (dateTime.isValid()) + lMatch = tr("Last Match: %1 days ago").arg(dateTime.daysTo(QDateTime::currentDateTime())); + else + lMatch = tr("Last Match: Unknown"); + ui->lblLastMatch->setText(lMatch); + updateMustLineValidity(); + updateMustNotLineValidity(); + } + else { + // New rule + clearRuleDefinitionBox(); + ui->lineContains->setText(selection.first()->text()); + ui->comboAddPaused->setCurrentIndex(0); + } + updateFieldsToolTips(ui->checkRegex->isChecked()); + // Enable + ui->ruleDefBox->setEnabled(true); + } + else { + m_editedRule = 0; + // Clear + clearRuleDefinitionBox(); + ui->ruleDefBox->setEnabled(false); } - updateFieldsToolTips(ui->checkRegex->isChecked()); - // Enable - ui->ruleDefBox->setEnabled(true); - } else { - m_editedRule = 0; - // Clear - clearRuleDefinitionBox(); - ui->ruleDefBox->setEnabled(false); - } } void AutomatedRssDownloader::clearRuleDefinitionBox() { - ui->lineContains->clear(); - ui->lineNotContains->clear(); - ui->saveDiffDir_check->setChecked(false); - ui->lineSavePath->clear(); - ui->comboCategory->clearEditText(); - ui->checkRegex->setChecked(false); - ui->spinIgnorePeriod->setValue(0); - updateFieldsToolTips(ui->checkRegex->isChecked()); - updateMustLineValidity(); - updateMustNotLineValidity(); + ui->lineContains->clear(); + ui->lineNotContains->clear(); + ui->saveDiffDir_check->setChecked(false); + ui->lineSavePath->clear(); + ui->comboCategory->clearEditText(); + ui->checkRegex->setChecked(false); + ui->spinIgnorePeriod->setValue(0); + updateFieldsToolTips(ui->checkRegex->isChecked()); + updateMustLineValidity(); + updateMustNotLineValidity(); } Rss::DownloadRulePtr AutomatedRssDownloader::getCurrentRule() const { - QListWidgetItem * current_item = ui->listRules->currentItem(); - if (current_item) - return m_editableRuleList->getRule(current_item->text()); - return Rss::DownloadRulePtr(); + QListWidgetItem *current_item = ui->listRules->currentItem(); + if (current_item) + return m_editableRuleList->getRule(current_item->text()); + return Rss::DownloadRulePtr(); } void AutomatedRssDownloader::initCategoryCombobox() { - // Load torrent categories - QStringList categories = BitTorrent::Session::instance()->categories(); - std::sort(categories.begin(), categories.end(), Utils::String::naturalCompareCaseInsensitive); - ui->comboCategory->addItems(categories); + // Load torrent categories + QStringList categories = BitTorrent::Session::instance()->categories(); + std::sort(categories.begin(), categories.end(), Utils::String::naturalCompareCaseInsensitive); + ui->comboCategory->addItems(categories); } void AutomatedRssDownloader::saveEditedRule() { - if (!m_editedRule) return; - qDebug() << Q_FUNC_INFO << m_editedRule; - if (ui->listRules->findItems(m_editedRule->text(), Qt::MatchExactly).isEmpty()) { - qDebug() << "Could not find rule" << m_editedRule->text() << "in the UI list"; - qDebug() << "Probably removed the item, no need to save it"; - return; - } - Rss::DownloadRulePtr rule = m_editableRuleList->getRule(m_editedRule->text()); - if (!rule) { - rule = Rss::DownloadRulePtr(new Rss::DownloadRule); - rule->setName(m_editedRule->text()); - } - if (m_editedRule->checkState() == Qt::Unchecked) - rule->setEnabled(false); - else - rule->setEnabled(true); - rule->setUseRegex(ui->checkRegex->isChecked()); - rule->setMustContain(ui->lineContains->text()); - rule->setMustNotContain(ui->lineNotContains->text()); - rule->setEpisodeFilter(ui->lineEFilter->text()); - if (ui->saveDiffDir_check->isChecked()) - rule->setSavePath(ui->lineSavePath->text()); - else - rule->setSavePath(""); - rule->setCategory(ui->comboCategory->currentText()); - - rule->setAddPaused(Rss::DownloadRule::AddPausedState(ui->comboAddPaused->currentIndex())); - rule->setIgnoreDays(ui->spinIgnorePeriod->value()); - //rule->setRssFeeds(getSelectedFeeds()); - // Save it - m_editableRuleList->saveRule(rule); + if (!m_editedRule) return; + qDebug() << Q_FUNC_INFO << m_editedRule; + if (ui->listRules->findItems(m_editedRule->text(), Qt::MatchExactly).isEmpty()) { + qDebug() << "Could not find rule" << m_editedRule->text() << "in the UI list"; + qDebug() << "Probably removed the item, no need to save it"; + return; + } + Rss::DownloadRulePtr rule = m_editableRuleList->getRule(m_editedRule->text()); + if (!rule) { + rule = Rss::DownloadRulePtr(new Rss::DownloadRule); + rule->setName(m_editedRule->text()); + } + if (m_editedRule->checkState() == Qt::Unchecked) + rule->setEnabled(false); + else + rule->setEnabled(true); + rule->setUseRegex(ui->checkRegex->isChecked()); + rule->setMustContain(ui->lineContains->text()); + rule->setMustNotContain(ui->lineNotContains->text()); + rule->setEpisodeFilter(ui->lineEFilter->text()); + if (ui->saveDiffDir_check->isChecked()) + rule->setSavePath(ui->lineSavePath->text()); + else + rule->setSavePath(""); + rule->setCategory(ui->comboCategory->currentText()); + + rule->setAddPaused(Rss::DownloadRule::AddPausedState(ui->comboAddPaused->currentIndex())); + rule->setIgnoreDays(ui->spinIgnorePeriod->value()); + // rule->setRssFeeds(getSelectedFeeds()); + // Save it + m_editableRuleList->saveRule(rule); } - void AutomatedRssDownloader::on_addRuleBtn_clicked() { - // Ask for a rule name - const QString rule_name = AutoExpandableDialog::getText(this, tr("New rule name"), tr("Please type the name of the new download rule.")); - if (rule_name.isEmpty()) return; - // Check if this rule name already exists - if (m_editableRuleList->getRule(rule_name)) { - QMessageBox::warning(this, tr("Rule name conflict"), tr("A rule with this name already exists, please choose another name.")); - return; - } - // Add the new rule to the list - QListWidgetItem * item = new QListWidgetItem(rule_name, ui->listRules); - item->setFlags(item->flags()|Qt::ItemIsUserCheckable); - item->setCheckState(Qt::Checked); // Enable as a default - ui->listRules->clearSelection(); - ui->listRules->setCurrentItem(item); + // Ask for a rule name + const QString rule_name = AutoExpandableDialog::getText(this, tr("New rule name"), tr("Please type the name of the new download rule.")); + if (rule_name.isEmpty()) return; + // Check if this rule name already exists + if (m_editableRuleList->getRule(rule_name)) { + QMessageBox::warning(this, tr("Rule name conflict"), tr("A rule with this name already exists, please choose another name.")); + return; + } + // Add the new rule to the list + QListWidgetItem *item = new QListWidgetItem(rule_name, ui->listRules); + item->setFlags(item->flags() | Qt::ItemIsUserCheckable); + item->setCheckState(Qt::Checked); // Enable as a default + ui->listRules->clearSelection(); + ui->listRules->setCurrentItem(item); } void AutomatedRssDownloader::on_removeRuleBtn_clicked() { - const QList selection = ui->listRules->selectedItems(); - if (selection.isEmpty()) return; - // Ask for confirmation - QString confirm_text; - if (selection.count() == 1) - confirm_text = tr("Are you sure you want to remove the download rule named '%1'?").arg(selection.first()->text()); - else - confirm_text = tr("Are you sure you want to remove the selected download rules?"); - if (QMessageBox::question(this, tr("Rule deletion confirmation"), confirm_text, QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes) - return; - foreach (QListWidgetItem *item, selection) { - // Actually remove the item - ui->listRules->removeItemWidget(item); - const QString rule_name = item->text(); - // Clean up memory - delete item; - qDebug("Removed item for the UI list"); - // Remove it from the m_editableRuleList - m_editableRuleList->removeRule(rule_name); - } + const QList selection = ui->listRules->selectedItems(); + if (selection.isEmpty()) return; + // Ask for confirmation + QString confirm_text; + if (selection.count() == 1) + confirm_text = tr("Are you sure you want to remove the download rule named '%1'?").arg(selection.first()->text()); + else + confirm_text = tr("Are you sure you want to remove the selected download rules?"); + if (QMessageBox::question(this, tr("Rule deletion confirmation"), confirm_text, QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes) + return; + foreach (QListWidgetItem *item, selection) { + // Actually remove the item + ui->listRules->removeItemWidget(item); + const QString rule_name = item->text(); + // Clean up memory + delete item; + qDebug("Removed item for the UI list"); + // Remove it from the m_editableRuleList + m_editableRuleList->removeRule(rule_name); + } } void AutomatedRssDownloader::on_browseSP_clicked() { - QString save_path = QFileDialog::getExistingDirectory(this, tr("Destination directory"), QDir::homePath()); - if (!save_path.isEmpty()) - ui->lineSavePath->setText(Utils::Fs::toNativePath(save_path)); + QString save_path = QFileDialog::getExistingDirectory(this, tr("Destination directory"), QDir::homePath()); + if (!save_path.isEmpty()) + ui->lineSavePath->setText(Utils::Fs::toNativePath(save_path)); } void AutomatedRssDownloader::on_exportBtn_clicked() { - if (m_editableRuleList->isEmpty()) { - QMessageBox::warning(this, tr("Invalid action"), tr("The list is empty, there is nothing to export.")); - return; - } - // Ask for a save path - QString save_path = QFileDialog::getSaveFileName(this, tr("Where would you like to save the list?"), QDir::homePath(), tr("Rules list (*.rssrules)")); - if (save_path.isEmpty()) return; - if (!save_path.endsWith(".rssrules", Qt::CaseInsensitive)) - save_path += ".rssrules"; - if (!m_editableRuleList->serialize(save_path)) { - QMessageBox::warning(this, tr("I/O Error"), tr("Failed to create the destination file")); - return; - } + if (m_editableRuleList->isEmpty()) { + QMessageBox::warning(this, tr("Invalid action"), tr("The list is empty, there is nothing to export.")); + return; + } + // Ask for a save path + QString save_path = QFileDialog::getSaveFileName(this, tr("Where would you like to save the list?"), QDir::homePath(), tr("Rules list (*.rssrules)")); + if (save_path.isEmpty()) return; + if (!save_path.endsWith(".rssrules", Qt::CaseInsensitive)) + save_path += ".rssrules"; + if (!m_editableRuleList->serialize(save_path)) { + QMessageBox::warning(this, tr("I/O Error"), tr("Failed to create the destination file")); + return; + } } void AutomatedRssDownloader::on_importBtn_clicked() { - // Ask for filter path - QString load_path = QFileDialog::getOpenFileName(this, tr("Please point to the RSS download rules file"), QDir::homePath(), tr("Rules list")+QString(" (*.rssrules *.filters)")); - if (load_path.isEmpty() || !QFile::exists(load_path)) return; - // Load it - if (!m_editableRuleList->unserialize(load_path)) { - QMessageBox::warning(this, tr("Import Error"), tr("Failed to import the selected rules file")); - return; - } - // Reload the rule list - loadRulesList(); + // Ask for filter path + QString load_path = QFileDialog::getOpenFileName(this, tr("Please point to the RSS download rules file"), QDir::homePath(), tr("Rules list") + QString(" (*.rssrules *.filters)")); + if (load_path.isEmpty() || !QFile::exists(load_path)) return; + // Load it + if (!m_editableRuleList->unserialize(load_path)) { + QMessageBox::warning(this, tr("Import Error"), tr("Failed to import the selected rules file")); + return; + } + // Reload the rule list + loadRulesList(); } void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos) { - Q_UNUSED(pos); - QMenu menu; - QAction *addAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-add"), tr("Add new rule...")); - QAction *delAct = 0; - QAction *renameAct = 0; - const QList selection = ui->listRules->selectedItems(); - if (!selection.isEmpty()) { - if (selection.count() == 1) { - delAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Delete rule")); - menu.addSeparator(); - renameAct = menu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"), tr("Rename rule...")); - } else { - delAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Delete selected rules")); + Q_UNUSED(pos); + QMenu menu; + QAction *addAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-add"), tr("Add new rule...")); + QAction *delAct = 0; + QAction *renameAct = 0; + const QList selection = ui->listRules->selectedItems(); + if (!selection.isEmpty()) { + if (selection.count() == 1) { + delAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Delete rule")); + menu.addSeparator(); + renameAct = menu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"), tr("Rename rule...")); + } + else { + delAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Delete selected rules")); + } + } + QAction *act = menu.exec(QCursor::pos()); + if (!act) return; + if (act == addAct) { + on_addRuleBtn_clicked(); + return; + } + if (act == delAct) { + on_removeRuleBtn_clicked(); + return; + } + if (act == renameAct) { + renameSelectedRule(); + return; } - } - QAction *act = menu.exec(QCursor::pos()); - if (!act) return; - if (act == addAct) { - on_addRuleBtn_clicked(); - return; - } - if (act == delAct) { - on_removeRuleBtn_clicked(); - return; - } - if (act == renameAct) { - renameSelectedRule(); - return; - } } void AutomatedRssDownloader::renameSelectedRule() { - const QList selection = ui->listRules->selectedItems(); - if (selection.isEmpty()) - return; - - QListWidgetItem *item = selection.first(); - forever { - QString new_name = AutoExpandableDialog::getText(this, tr("Rule renaming"), tr("Please type the new rule name"), QLineEdit::Normal, item->text()); - new_name = new_name.trimmed(); - if (new_name.isEmpty()) return; - if (m_editableRuleList->ruleNames().contains(new_name, Qt::CaseInsensitive)) { - QMessageBox::warning(this, tr("Rule name conflict"), tr("A rule with this name already exists, please choose another name.")); - } else { - // Rename the rule - m_editableRuleList->renameRule(item->text(), new_name); - item->setText(new_name); - return; + const QList selection = ui->listRules->selectedItems(); + if (selection.isEmpty()) + return; + + QListWidgetItem *item = selection.first(); + forever { + QString new_name = AutoExpandableDialog::getText(this, tr("Rule renaming"), tr("Please type the new rule name"), QLineEdit::Normal, item->text()); + new_name = new_name.trimmed(); + if (new_name.isEmpty()) return; + if (m_editableRuleList->ruleNames().contains(new_name, Qt::CaseInsensitive)) { + QMessageBox::warning(this, tr("Rule name conflict"), tr("A rule with this name already exists, please choose another name.")); + } + else { + // Rename the rule + m_editableRuleList->renameRule(item->text(), new_name); + item->setText(new_name); + return; + } } - } } void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_item) { - if (ui->ruleDefBox->isEnabled()) { - // Make sure the current rule is saved - saveEditedRule(); - } - const QString feed_url = feed_item->data(Qt::UserRole).toString(); - foreach (QListWidgetItem* rule_item, ui->listRules->selectedItems()) { - Rss::DownloadRulePtr rule = m_editableRuleList->getRule(rule_item->text()); - Q_ASSERT(rule); - QStringList affected_feeds = rule->rssFeeds(); - if (feed_item->checkState() == Qt::Checked) { - if (!affected_feeds.contains(feed_url)) - affected_feeds << feed_url; - } else { - if (affected_feeds.contains(feed_url)) - affected_feeds.removeOne(feed_url); + if (ui->ruleDefBox->isEnabled()) + // Make sure the current rule is saved + saveEditedRule(); + const QString feed_url = feed_item->data(Qt::UserRole).toString(); + foreach (QListWidgetItem *rule_item, ui->listRules->selectedItems()) { + Rss::DownloadRulePtr rule = m_editableRuleList->getRule(rule_item->text()); + Q_ASSERT(rule); + QStringList affected_feeds = rule->rssFeeds(); + if (feed_item->checkState() == Qt::Checked) { + if (!affected_feeds.contains(feed_url)) + affected_feeds << feed_url; + } + else if (affected_feeds.contains(feed_url)) + affected_feeds.removeOne(feed_url); + // Save the updated rule + if (affected_feeds.size() != rule->rssFeeds().size()) { + rule->setRssFeeds(affected_feeds); + m_editableRuleList->saveRule(rule); + } } - // Save the updated rule - if (affected_feeds.size() != rule->rssFeeds().size()) { - rule->setRssFeeds(affected_feeds); - m_editableRuleList->saveRule(rule); - } - } - // Update Matching articles - updateMatchingArticles(); + // Update Matching articles + updateMatchingArticles(); } void AutomatedRssDownloader::updateMatchingArticles() { - ui->treeMatchingArticles->clear(); - Rss::ManagerPtr manager = m_manager.toStrongRef(); - if (!manager) - return; - const QHash all_feeds = manager->rootFolder()->getAllFeedsAsHash(); - - saveEditedRule(); - foreach (const QListWidgetItem *rule_item, ui->listRules->selectedItems()) { - Rss::DownloadRulePtr rule = m_editableRuleList->getRule(rule_item->text()); - if (!rule) continue; - foreach (const QString &feed_url, rule->rssFeeds()) { - qDebug() << Q_FUNC_INFO << feed_url; - if (!all_feeds.contains(feed_url)) continue; // Feed was removed - Rss::FeedPtr feed = all_feeds.value(feed_url); - Q_ASSERT(feed); - if (!feed) continue; - const QStringList matching_articles = rule->findMatchingArticles(feed); - if (!matching_articles.isEmpty()) - addFeedArticlesToTree(feed, matching_articles); + ui->treeMatchingArticles->clear(); + Rss::ManagerPtr manager = m_manager.toStrongRef(); + if (!manager) + return; + const QHash all_feeds = manager->rootFolder()->getAllFeedsAsHash(); + + saveEditedRule(); + foreach (const QListWidgetItem *rule_item, ui->listRules->selectedItems()) { + Rss::DownloadRulePtr rule = m_editableRuleList->getRule(rule_item->text()); + if (!rule) continue; + foreach (const QString &feed_url, rule->rssFeeds()) { + qDebug() << Q_FUNC_INFO << feed_url; + if (!all_feeds.contains(feed_url)) continue; // Feed was removed + Rss::FeedPtr feed = all_feeds.value(feed_url); + Q_ASSERT(feed); + if (!feed) continue; + const QStringList matching_articles = rule->findMatchingArticles(feed); + if (!matching_articles.isEmpty()) + addFeedArticlesToTree(feed, matching_articles); + } } - } } -void AutomatedRssDownloader::addFeedArticlesToTree(const Rss::FeedPtr& feed, const QStringList &articles) +void AutomatedRssDownloader::addFeedArticlesToTree(const Rss::FeedPtr &feed, const QStringList &articles) { - // Check if this feed is already in the tree - QTreeWidgetItem *treeFeedItem = 0; - for (int i=0; itreeMatchingArticles->topLevelItemCount(); ++i) { - QTreeWidgetItem *item = ui->treeMatchingArticles->topLevelItem(i); - if (item->data(0, Qt::UserRole).toString() == feed->url()) { - treeFeedItem = item; - break; + // Check if this feed is already in the tree + QTreeWidgetItem *treeFeedItem = 0; + for (int i = 0; itreeMatchingArticles->topLevelItemCount(); ++i) { + QTreeWidgetItem *item = ui->treeMatchingArticles->topLevelItem(i); + if (item->data(0, Qt::UserRole).toString() == feed->url()) { + treeFeedItem = item; + break; + } + } + // If there is none, create it + if (!treeFeedItem) { + treeFeedItem = new QTreeWidgetItem(QStringList() << feed->displayName()); + treeFeedItem->setToolTip(0, feed->displayName()); + QFont f = treeFeedItem->font(0); + f.setBold(true); + treeFeedItem->setFont(0, f); + treeFeedItem->setData(0, Qt::DecorationRole, GuiIconProvider::instance()->getIcon("inode-directory")); + treeFeedItem->setData(0, Qt::UserRole, feed->url()); + ui->treeMatchingArticles->addTopLevelItem(treeFeedItem); + } + // Insert the articles + foreach (const QString &art, articles) { + QTreeWidgetItem *item = new QTreeWidgetItem(QStringList() << art); + item->setToolTip(0, art); + treeFeedItem->addChild(item); } - } - // If there is none, create it - if (!treeFeedItem) { - treeFeedItem = new QTreeWidgetItem(QStringList() << feed->displayName()); - treeFeedItem->setToolTip(0, feed->displayName()); - QFont f = treeFeedItem->font(0); - f.setBold(true); - treeFeedItem->setFont(0, f); - treeFeedItem->setData(0, Qt::DecorationRole, GuiIconProvider::instance()->getIcon("inode-directory")); - treeFeedItem->setData(0, Qt::UserRole, feed->url()); - ui->treeMatchingArticles->addTopLevelItem(treeFeedItem); - } - // Insert the articles - foreach (const QString &art, articles) { - QTreeWidgetItem *item = new QTreeWidgetItem(QStringList() << art); - item->setToolTip(0, art); - treeFeedItem->addChild(item); - } - ui->treeMatchingArticles->expandItem(treeFeedItem); + ui->treeMatchingArticles->expandItem(treeFeedItem); } void AutomatedRssDownloader::updateFieldsToolTips(bool regex) { - QString tip; - if (regex) { - tip = tr("Regex mode: use Perl-like regular expressions"); - ui->lineContains->setToolTip(tip); - ui->lineNotContains->setToolTip(tip); - } else { - tip = tr("Wildcard mode: you can use
  • ? to match any single character
  • * to match zero or more of any characters
  • Whitespaces count as AND operators
"); - ui->lineContains->setToolTip(tip); - tip = tr("Wildcard mode: you can use
  • ? to match any single character
  • * to match zero or more of any characters
  • | is used as OR operator
"); - ui->lineNotContains->setToolTip(tip); - } + QString tip; + if (regex) { + tip = tr("Regex mode: use Perl-like regular expressions"); + ui->lineContains->setToolTip(tip); + ui->lineNotContains->setToolTip(tip); + } + else { + tip = tr("Wildcard mode: you can use
  • ? to match any single character
  • * to match zero or more of any characters
  • Whitespaces count as AND operators
"); + ui->lineContains->setToolTip(tip); + tip = tr("Wildcard mode: you can use
  • ? to match any single character
  • * to match zero or more of any characters
  • | is used as OR operator
"); + ui->lineNotContains->setToolTip(tip); + } } void AutomatedRssDownloader::updateMustLineValidity() { - const QString text = ui->lineContains->text(); - bool valid = true; - QStringList tokens; - if (ui->checkRegex->isChecked()) - tokens << text; - else - tokens << text.split(" "); - foreach (const QString &token, tokens) { - QRegExp reg(token, Qt::CaseInsensitive, ui->checkRegex->isChecked() ? QRegExp::RegExp : QRegExp::Wildcard); - if (!reg.isValid()) { - valid = false; - break; + const QString text = ui->lineContains->text(); + bool valid = true; + QStringList tokens; + if (ui->checkRegex->isChecked()) + tokens << text; + else + tokens << text.split(" "); + foreach (const QString &token, tokens) { + QRegExp reg(token, Qt::CaseInsensitive, ui->checkRegex->isChecked() ? QRegExp::RegExp : QRegExp::Wildcard); + if (!reg.isValid()) { + valid = false; + break; + } + } + if (valid) { + ui->lineContains->setStyleSheet(""); + ui->lbl_must_stat->setPixmap(QPixmap()); + } + else { + ui->lineContains->setStyleSheet("QLineEdit { color: #ff0000; }"); + ui->lbl_must_stat->setPixmap(GuiIconProvider::instance()->getIcon("task-attention").pixmap(16, 16)); } - } - if (valid) { - ui->lineContains->setStyleSheet(""); - ui->lbl_must_stat->setPixmap(QPixmap()); - } else { - ui->lineContains->setStyleSheet("QLineEdit { color: #ff0000; }"); - ui->lbl_must_stat->setPixmap(GuiIconProvider::instance()->getIcon("task-attention").pixmap(16, 16)); - } } void AutomatedRssDownloader::updateMustNotLineValidity() { - const QString text = ui->lineNotContains->text(); - bool valid = true; - QStringList tokens; - if (ui->checkRegex->isChecked()) - tokens << text; - else - tokens << text.split("|"); - foreach (const QString &token, tokens) { - QRegExp reg(token, Qt::CaseInsensitive, ui->checkRegex->isChecked() ? QRegExp::RegExp : QRegExp::Wildcard); - if (!reg.isValid()) { - valid = false; - break; + const QString text = ui->lineNotContains->text(); + bool valid = true; + QStringList tokens; + if (ui->checkRegex->isChecked()) + tokens << text; + else + tokens << text.split("|"); + foreach (const QString &token, tokens) { + QRegExp reg(token, Qt::CaseInsensitive, ui->checkRegex->isChecked() ? QRegExp::RegExp : QRegExp::Wildcard); + if (!reg.isValid()) { + valid = false; + break; + } + } + if (valid) { + ui->lineNotContains->setStyleSheet(""); + ui->lbl_mustnot_stat->setPixmap(QPixmap()); + } + else { + ui->lineNotContains->setStyleSheet("QLineEdit { color: #ff0000; }"); + ui->lbl_mustnot_stat->setPixmap(GuiIconProvider::instance()->getIcon("task-attention").pixmap(16, 16)); } - } - if (valid) { - ui->lineNotContains->setStyleSheet(""); - ui->lbl_mustnot_stat->setPixmap(QPixmap()); - } else { - ui->lineNotContains->setStyleSheet("QLineEdit { color: #ff0000; }"); - ui->lbl_mustnot_stat->setPixmap(GuiIconProvider::instance()->getIcon("task-attention").pixmap(16, 16)); - } } -void AutomatedRssDownloader::onFinished(int result) { - Q_UNUSED(result); - // Save current item on exit - saveEditedRule(); - m_ruleList->replace(m_editableRuleList); - m_ruleList->saveRulesToStorage(); - saveSettings(); +void AutomatedRssDownloader::onFinished(int result) +{ + Q_UNUSED(result); + // Save current item on exit + saveEditedRule(); + m_ruleList->replace(m_editableRuleList); + m_ruleList->saveRulesToStorage(); + saveSettings(); } diff --git a/src/gui/rss/automatedrssdownloader.h b/src/gui/rss/automatedrssdownloader.h index b89e667c4..36cfe5b67 100644 --- a/src/gui/rss/automatedrssdownloader.h +++ b/src/gui/rss/automatedrssdownloader.h @@ -40,7 +40,7 @@ QT_BEGIN_NAMESPACE namespace Ui { -class AutomatedRssDownloader; + class AutomatedRssDownloader; } QT_END_NAMESPACE @@ -54,54 +54,54 @@ QT_BEGIN_NAMESPACE class QListWidgetItem; QT_END_NAMESPACE -class AutomatedRssDownloader : public QDialog +class AutomatedRssDownloader: public QDialog { - Q_OBJECT + Q_OBJECT public: - explicit AutomatedRssDownloader(const QWeakPointer& manager, QWidget *parent = 0); - ~AutomatedRssDownloader(); - bool isRssDownloaderEnabled() const; + explicit AutomatedRssDownloader(const QWeakPointer &manager, QWidget *parent = 0); + ~AutomatedRssDownloader(); + bool isRssDownloaderEnabled() const; protected slots: - void loadSettings(); - void saveSettings(); - void loadRulesList(); - void handleFeedCheckStateChange(QListWidgetItem* feed_item); - void updateRuleDefinitionBox(); - void clearRuleDefinitionBox(); - void saveEditedRule(); - void loadFeedList(); - void updateFeedList(); + void loadSettings(); + void saveSettings(); + void loadRulesList(); + void handleFeedCheckStateChange(QListWidgetItem *feed_item); + void updateRuleDefinitionBox(); + void clearRuleDefinitionBox(); + void saveEditedRule(); + void loadFeedList(); + void updateFeedList(); private slots: - void displayRulesListMenu(const QPoint& pos); - void on_addRuleBtn_clicked(); - void on_removeRuleBtn_clicked(); - void on_browseSP_clicked(); - void on_exportBtn_clicked(); - void on_importBtn_clicked(); - void renameSelectedRule(); - void updateMatchingArticles(); - void updateFieldsToolTips(bool regex); - void updateMustLineValidity(); - void updateMustNotLineValidity(); - void onFinished(int result); + void displayRulesListMenu(const QPoint &pos); + void on_addRuleBtn_clicked(); + void on_removeRuleBtn_clicked(); + void on_browseSP_clicked(); + void on_exportBtn_clicked(); + void on_importBtn_clicked(); + void renameSelectedRule(); + void updateMatchingArticles(); + void updateFieldsToolTips(bool regex); + void updateMustLineValidity(); + void updateMustNotLineValidity(); + void onFinished(int result); private: - Rss::DownloadRulePtr getCurrentRule() const; - void initCategoryCombobox(); - void addFeedArticlesToTree(const Rss::FeedPtr& feed, const QStringList& articles); + Rss::DownloadRulePtr getCurrentRule() const; + void initCategoryCombobox(); + void addFeedArticlesToTree(const Rss::FeedPtr &feed, const QStringList &articles); private: - Ui::AutomatedRssDownloader *ui; - QWeakPointer m_manager; - QListWidgetItem* m_editedRule; - Rss::DownloadRuleList *m_ruleList; - Rss::DownloadRuleList *m_editableRuleList; - QRegExpValidator *m_episodeValidator; - QShortcut *editHotkey; - QShortcut *deleteHotkey; + Ui::AutomatedRssDownloader *ui; + QWeakPointer m_manager; + QListWidgetItem *m_editedRule; + Rss::DownloadRuleList *m_ruleList; + Rss::DownloadRuleList *m_editableRuleList; + QRegExpValidator *m_episodeValidator; + QShortcut *editHotkey; + QShortcut *deleteHotkey; }; #endif // AUTOMATEDRSSDOWNLOADER_H diff --git a/src/gui/rss/rss_imp.cpp b/src/gui/rss/rss_imp.cpp index 909b6432a..08f999655 100644 --- a/src/gui/rss/rss_imp.cpp +++ b/src/gui/rss/rss_imp.cpp @@ -65,13 +65,13 @@ namespace Article } // display a right-click menu -void RSSImp::displayRSSListMenu(const QPoint& pos) +void RSSImp::displayRSSListMenu(const QPoint &pos) { if (!m_feedList->indexAt(pos).isValid()) // No item under the mouse, clear selection m_feedList->clearSelection(); QMenu myRSSListMenu(this); - QList selectedItems = m_feedList->selectedItems(); + QList selectedItems = m_feedList->selectedItems(); if (selectedItems.size() > 0) { myRSSListMenu.addAction(actionUpdate); myRSSListMenu.addAction(actionMark_items_read); @@ -104,16 +104,16 @@ void RSSImp::displayRSSListMenu(const QPoint& pos) myRSSListMenu.exec(QCursor::pos()); } -void RSSImp::displayItemsListMenu(const QPoint&) +void RSSImp::displayItemsListMenu(const QPoint &) { QMenu myItemListMenu(this); - QList selectedItems = listArticles->selectedItems(); + QList selectedItems = listArticles->selectedItems(); if (selectedItems.size() <= 0) return; bool hasTorrent = false; bool hasLink = false; - foreach (const QListWidgetItem* item, selectedItems) { + foreach (const QListWidgetItem *item, selectedItems) { if (!item) continue; Rss::FeedPtr feed = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString()); if (!feed) continue; @@ -137,7 +137,7 @@ void RSSImp::displayItemsListMenu(const QPoint&) void RSSImp::askNewFolder() { - QTreeWidgetItem* parent_item = 0; + QTreeWidgetItem *parent_item = 0; Rss::FolderPtr rss_parent; if (m_feedList->selectedItems().size() > 0) { parent_item = m_feedList->selectedItems().at(0); @@ -154,7 +154,7 @@ void RSSImp::askNewFolder() Rss::FolderPtr newFolder(new Rss::Folder(new_name)); rss_parent->addFile(newFolder); - QTreeWidgetItem* folderItem = createFolderListItem(newFolder); + QTreeWidgetItem *folderItem = createFolderListItem(newFolder); if (parent_item) parent_item->addChild(folderItem); else @@ -172,7 +172,7 @@ void RSSImp::on_newFeedButton_clicked() { // Determine parent folder for new feed QTreeWidgetItem *parent_item = 0; - QList selected_items = m_feedList->selectedItems(); + QList selected_items = m_feedList->selectedItems(); if (!selected_items.empty()) { parent_item = selected_items.first(); // Consider the case where the user clicked on Unread item @@ -212,7 +212,7 @@ void RSSImp::on_newFeedButton_clicked() Rss::FeedPtr stream(new Rss::Feed(newUrl, m_rssManager.data())); rss_parent->addFile(stream); // Create TreeWidget item - QTreeWidgetItem* item = createFolderListItem(stream); + QTreeWidgetItem *item = createFolderListItem(stream); if (parent_item) parent_item->addChild(item); else @@ -226,23 +226,23 @@ void RSSImp::on_newFeedButton_clicked() // delete a stream by a button void RSSImp::deleteSelectedItems() { - QList selectedItems = m_feedList->selectedItems(); + QList selectedItems = m_feedList->selectedItems(); if (selectedItems.isEmpty()) return; if ((selectedItems.size() == 1) && (selectedItems.first() == m_feedList->stickyUnreadItem())) return; QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Deletion confirmation"), - tr("Are you sure you want to delete the selected RSS feeds?"), - QMessageBox::Yes|QMessageBox::No, QMessageBox::No); + tr("Are you sure you want to delete the selected RSS feeds?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); if (answer == QMessageBox::No) return; - foreach (QTreeWidgetItem* item, selectedItems) { + foreach (QTreeWidgetItem *item, selectedItems) { if (item == m_feedList->stickyUnreadItem()) continue; Rss::FilePtr rss_item = m_feedList->getRSSItem(item); - QTreeWidgetItem* parent = item->parent(); + QTreeWidgetItem *parent = item->parent(); // Notify TreeWidget m_feedList->itemAboutToBeRemoved(item); // Actually delete the item @@ -259,23 +259,22 @@ void RSSImp::deleteSelectedItems() updateItemInfos(m_feedList->stickyUnreadItem()); if (m_feedList->currentItem() == m_feedList->stickyUnreadItem()) populateArticleList(m_feedList->stickyUnreadItem()); - } void RSSImp::loadFoldersOpenState() { QStringList open_folders = Preferences::instance()->getRssOpenFolders(); - foreach (const QString& var_path, open_folders) { + foreach (const QString &var_path, open_folders) { QStringList path = var_path.split("\\"); - QTreeWidgetItem* parent = 0; - foreach (const QString& name, path) { + QTreeWidgetItem *parent = 0; + foreach (const QString &name, path) { int nbChildren = 0; if (parent) nbChildren = parent->childCount(); else nbChildren = m_feedList->topLevelItemCount(); for (int i = 0; i < nbChildren; ++i) { - QTreeWidgetItem* child; + QTreeWidgetItem *child; if (parent) child = parent->child(i); else @@ -294,8 +293,8 @@ void RSSImp::loadFoldersOpenState() void RSSImp::saveFoldersOpenState() { QStringList open_folders; - QList items = m_feedList->getAllOpenFolders(); - foreach (QTreeWidgetItem* item, items) { + QList items = m_feedList->getAllOpenFolders(); + foreach (QTreeWidgetItem *item, items) { QString path = m_feedList->getItemPath(item).join("\\"); qDebug("saving open folder: %s", qPrintable(path)); open_folders << path; @@ -306,17 +305,17 @@ void RSSImp::saveFoldersOpenState() // refresh all streams by a button void RSSImp::refreshAllFeeds() { - foreach (QTreeWidgetItem* item, m_feedList->getAllFeedItems()) + foreach (QTreeWidgetItem *item, m_feedList->getAllFeedItems()) item->setData(0, Qt::DecorationRole, QVariant(QIcon(":/icons/loading.png"))); m_rssManager->refresh(); } void RSSImp::downloadSelectedTorrents() { - QList selected_items = listArticles->selectedItems(); + QList selected_items = listArticles->selectedItems(); if (selected_items.size() <= 0) return; - foreach (QListWidgetItem* item, selected_items) { + foreach (QListWidgetItem *item, selected_items) { if (!item) continue; Rss::FeedPtr feed = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString()); if (!feed) continue; @@ -343,10 +342,10 @@ void RSSImp::downloadSelectedTorrents() // open the url of the selected RSS articles in the Web browser void RSSImp::openSelectedArticlesUrls() { - QList selected_items = listArticles->selectedItems(); + QList selected_items = listArticles->selectedItems(); if (selected_items.size() <= 0) return; - foreach (QListWidgetItem* item, selected_items) { + foreach (QListWidgetItem *item, selected_items) { if (!item) continue; Rss::FeedPtr feed = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString()); if (!feed) continue; @@ -367,13 +366,13 @@ void RSSImp::openSelectedArticlesUrls() updateItemInfos(m_feedList->getTreeItemFromUrl(selected_items.first()->data(Article::FeedUrlRole).toString())); } -//right-click on stream : give it an alias +// right-click on stream : give it an alias void RSSImp::renameSelectedRssFile() { - QList selectedItems = m_feedList->selectedItems(); + QList selectedItems = m_feedList->selectedItems(); if (selectedItems.size() != 1) return; - QTreeWidgetItem* item = selectedItems.first(); + QTreeWidgetItem *item = selectedItems.first(); if (item == m_feedList->stickyUnreadItem()) return; Rss::FilePtr rss_item = m_feedList->getRSSItem(item); @@ -401,8 +400,8 @@ void RSSImp::renameSelectedRssFile() // right-click on stream : refresh it void RSSImp::refreshSelectedItems() { - QList selectedItems = m_feedList->selectedItems(); - foreach (QTreeWidgetItem* item, selectedItems) { + QList selectedItems = m_feedList->selectedItems(); + foreach (QTreeWidgetItem *item, selectedItems) { Rss::FilePtr file = m_feedList->getRSSItem(item); // Update icons if (item == m_feedList->stickyUnreadItem()) { @@ -428,8 +427,8 @@ void RSSImp::refreshSelectedItems() void RSSImp::copySelectedFeedsURL() { QStringList URLs; - QList selectedItems = m_feedList->selectedItems(); - QTreeWidgetItem* item; + QList selectedItems = m_feedList->selectedItems(); + QTreeWidgetItem *item; foreach (item, selectedItems) if (m_feedList->isFeed(item)) URLs << m_feedList->getItemID(item); @@ -438,8 +437,8 @@ void RSSImp::copySelectedFeedsURL() void RSSImp::on_markReadButton_clicked() { - QList selectedItems = m_feedList->selectedItems(); - foreach (QTreeWidgetItem* item, selectedItems) { + QList selectedItems = m_feedList->selectedItems(); + foreach (QTreeWidgetItem *item, selectedItems) { Rss::FilePtr rss_item = m_feedList->getRSSItem(item); Q_ASSERT(rss_item); rss_item->markAsRead(); @@ -450,25 +449,25 @@ void RSSImp::on_markReadButton_clicked() populateArticleList(m_feedList->currentItem()); } -QTreeWidgetItem* RSSImp::createFolderListItem(const Rss::FilePtr& rssFile) +QTreeWidgetItem *RSSImp::createFolderListItem(const Rss::FilePtr &rssFile) { Q_ASSERT(rssFile); - QTreeWidgetItem* item = new QTreeWidgetItem; + QTreeWidgetItem *item = new QTreeWidgetItem; item->setData(0, Qt::DisplayRole, QVariant(rssFile->displayName() + QString::fromUtf8(" (") + QString::number(rssFile->unreadCount()) + QString(")"))); item->setData(0, Qt::DecorationRole, QIcon(rssFile->iconPath())); return item; } -void RSSImp::fillFeedsList(QTreeWidgetItem* parent, const Rss::FolderPtr& rss_parent) +void RSSImp::fillFeedsList(QTreeWidgetItem *parent, const Rss::FolderPtr &rss_parent) { QList children; if (parent) children = rss_parent->getContent(); else children = m_rssManager->rootFolder()->getContent(); - foreach (const Rss::FilePtr& rssFile, children) { - QTreeWidgetItem* item = createFolderListItem(rssFile); + foreach (const Rss::FilePtr &rssFile, children) { + QTreeWidgetItem *item = createFolderListItem(rssFile); Q_ASSERT(item); if (parent) parent->addChild(item); @@ -484,10 +483,10 @@ void RSSImp::fillFeedsList(QTreeWidgetItem* parent, const Rss::FolderPtr& rss_pa } } -QListWidgetItem* RSSImp::createArticleListItem(const Rss::ArticlePtr& article) +QListWidgetItem *RSSImp::createArticleListItem(const Rss::ArticlePtr &article) { Q_ASSERT(article); - QListWidgetItem* item = new QListWidgetItem; + QListWidgetItem *item = new QListWidgetItem; item->setData(Article::TitleRole, article->title()); item->setData(Article::FeedUrlRole, article->parent()->url()); @@ -505,7 +504,7 @@ QListWidgetItem* RSSImp::createArticleListItem(const Rss::ArticlePtr& article) } // fills the newsList -void RSSImp::populateArticleList(QTreeWidgetItem* item) +void RSSImp::populateArticleList(QTreeWidgetItem *item) { if (!item) { listArticles->clear(); @@ -529,8 +528,8 @@ void RSSImp::populateArticleList(QTreeWidgetItem* item) articles = rss_item->articleListByDateDesc(); qDebug("Got the list of news"); - foreach (const Rss::ArticlePtr& article, articles) { - QListWidgetItem* articleItem = createArticleListItem(article); + foreach (const Rss::ArticlePtr &article, articles) { + QListWidgetItem *articleItem = createArticleListItem(article); listArticles->addItem(articleItem); } qDebug("Added all news to the GUI"); @@ -539,7 +538,7 @@ void RSSImp::populateArticleList(QTreeWidgetItem* item) // display a news void RSSImp::refreshTextBrowser() { - QList selection = listArticles->selectedItems(); + QList selection = listArticles->selectedItems(); if (selection.empty()) return; QListWidgetItem *item = selection.first(); Q_ASSERT(item); @@ -559,7 +558,7 @@ void RSSImp::refreshTextBrowser() html += "
" + tr("Author: ") + "" + article->author() + "
"; html += ""; html += "
"; - if(Qt::mightBeRichText(article->description())) { + if (Qt::mightBeRichText(article->description())) { html += article->description(); } else { @@ -602,7 +601,7 @@ void RSSImp::refreshTextBrowser() void RSSImp::saveSlidersPosition() { // Remember sliders positions - Preferences* const pref = Preferences::instance(); + Preferences *const pref = Preferences::instance(); pref->setRssSideSplitterState(splitterSide->saveState()); pref->setRssMainSplitterState(splitterMain->saveState()); qDebug("Splitters position saved"); @@ -610,7 +609,7 @@ void RSSImp::saveSlidersPosition() void RSSImp::restoreSlidersPosition() { - const Preferences* const pref = Preferences::instance(); + const Preferences *const pref = Preferences::instance(); const QByteArray stateSide = pref->getRssSideSplitterState(); if (!stateSide.isEmpty()) splitterSide->restoreState(stateSide); @@ -619,9 +618,9 @@ void RSSImp::restoreSlidersPosition() splitterMain->restoreState(stateMain); } -void RSSImp::updateItemsInfos(const QList& items) +void RSSImp::updateItemsInfos(const QList &items) { - foreach (QTreeWidgetItem* item, items) + foreach (QTreeWidgetItem *item, items) updateItemInfos(item); } @@ -636,21 +635,22 @@ void RSSImp::updateItemInfos(QTreeWidgetItem *item) name = tr("Unread"); emit updateRSSCount(rss_item->unreadCount()); } - else + else { name = rss_item->displayName(); + } item->setText(0, name + QString::fromUtf8(" (") + QString::number(rss_item->unreadCount()) + QString(")")); // If item has a parent, update it too if (item->parent()) updateItemInfos(item->parent()); } -void RSSImp::updateFeedIcon(const QString& url, const QString& iconPath) +void RSSImp::updateFeedIcon(const QString &url, const QString &iconPath) { - QTreeWidgetItem* item = m_feedList->getTreeItemFromUrl(url); + QTreeWidgetItem *item = m_feedList->getTreeItemFromUrl(url); item->setData(0, Qt::DecorationRole, QVariant(QIcon(iconPath))); } -void RSSImp::updateFeedInfos(const QString& url, const QString& display_name, uint nbUnread) +void RSSImp::updateFeedInfos(const QString &url, const QString &display_name, uint nbUnread) { qDebug() << Q_FUNC_INFO << display_name; QTreeWidgetItem *item = m_feedList->getTreeItemFromUrl(url); @@ -665,7 +665,7 @@ void RSSImp::updateFeedInfos(const QString& url, const QString& display_name, ui updateItemInfos(m_feedList->stickyUnreadItem()); } -void RSSImp::onFeedContentChanged(const QString& url) +void RSSImp::onFeedContentChanged(const QString &url) { qDebug() << Q_FUNC_INFO << url; QTreeWidgetItem *item = m_feedList->getTreeItemFromUrl(url); @@ -682,8 +682,8 @@ void RSSImp::updateRefreshInterval(uint val) m_rssManager->updateRefreshInterval(val); } -RSSImp::RSSImp(QWidget *parent): - QWidget(parent), +RSSImp::RSSImp(QWidget *parent) + : QWidget(parent), m_rssManager(new Rss::Manager) { setupUi(this); @@ -717,12 +717,12 @@ RSSImp::RSSImp(QWidget *parent): populateArticleList(m_feedList->currentItem()); loadFoldersOpenState(); - connect(m_rssManager.data(), SIGNAL(feedInfosChanged(QString, QString, unsigned int)), SLOT(updateFeedInfos(QString, QString, unsigned int))); + connect(m_rssManager.data(), SIGNAL(feedInfosChanged(QString,QString,unsigned int)), SLOT(updateFeedInfos(QString,QString,unsigned int))); connect(m_rssManager.data(), SIGNAL(feedContentChanged(QString)), SLOT(onFeedContentChanged(QString))); - connect(m_rssManager.data(), SIGNAL(feedIconChanged(QString, QString)), SLOT(updateFeedIcon(QString, QString))); + connect(m_rssManager.data(), SIGNAL(feedIconChanged(QString,QString)), SLOT(updateFeedIcon(QString,QString))); - connect(m_feedList, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(displayRSSListMenu(const QPoint &))); - connect(listArticles, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(displayItemsListMenu(const QPoint &))); + connect(m_feedList, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(displayRSSListMenu(const QPoint&))); + connect(listArticles, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(displayItemsListMenu(const QPoint&))); // Feeds list actions connect(actionDelete, SIGNAL(triggered()), this, SLOT(deleteSelectedItems())); @@ -738,8 +738,8 @@ RSSImp::RSSImp(QWidget *parent): connect(actionOpen_news_URL, SIGNAL(triggered()), this, SLOT(openSelectedArticlesUrls())); connect(actionDownload_torrent, SIGNAL(triggered()), this, SLOT(downloadSelectedTorrents())); - connect(m_feedList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(populateArticleList(QTreeWidgetItem*))); - connect(m_feedList, SIGNAL(foldersAltered(QList)), this, SLOT(updateItemsInfos(QList))); + connect(m_feedList, SIGNAL(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *)), this, SLOT(populateArticleList(QTreeWidgetItem *))); + connect(m_feedList, SIGNAL(foldersAltered(QList)), this, SLOT(updateItemsInfos(QList))); connect(listArticles, SIGNAL(itemSelectionChanged()), this, SLOT(refreshTextBrowser())); connect(listArticles, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(downloadSelectedTorrents())); @@ -747,8 +747,8 @@ RSSImp::RSSImp(QWidget *parent): // Restore sliders position restoreSlidersPosition(); // Bind saveSliders slots - connect(splitterMain, SIGNAL(splitterMoved(int, int)), this, SLOT(saveSlidersPosition())); - connect(splitterSide, SIGNAL(splitterMoved(int, int)), this, SLOT(saveSlidersPosition())); + connect(splitterMain, SIGNAL(splitterMoved(int,int)), this, SLOT(saveSlidersPosition())); + connect(splitterSide, SIGNAL(splitterMoved(int,int)), this, SLOT(saveSlidersPosition())); qDebug("RSSImp constructed"); } diff --git a/src/gui/rss/rss_imp.h b/src/gui/rss/rss_imp.h index bd117d8f5..7dc1c2054 100644 --- a/src/gui/rss/rss_imp.h +++ b/src/gui/rss/rss_imp.h @@ -50,7 +50,7 @@ class RSSImp: public QWidget, public Ui::RSS Q_OBJECT public: - RSSImp(QWidget *parent); + RSSImp(QWidget * parent); ~RSSImp(); public slots: @@ -64,21 +64,21 @@ private slots: void on_newFeedButton_clicked(); void refreshAllFeeds(); void on_markReadButton_clicked(); - void displayRSSListMenu(const QPoint&); - void displayItemsListMenu(const QPoint&); + void displayRSSListMenu(const QPoint &); + void displayItemsListMenu(const QPoint &); void renameSelectedRssFile(); void refreshSelectedItems(); void copySelectedFeedsURL(); - void populateArticleList(QTreeWidgetItem* item); + void populateArticleList(QTreeWidgetItem *item); void refreshTextBrowser(); void updateFeedIcon(const QString &url, const QString &icon_path); void updateFeedInfos(const QString &url, const QString &display_name, uint nbUnread); - void onFeedContentChanged(const QString& url); - void updateItemsInfos(const QList &items); + void onFeedContentChanged(const QString &url); + void updateItemsInfos(const QList &items); void updateItemInfos(QTreeWidgetItem *item); void openSelectedArticlesUrls(); void downloadSelectedTorrents(); - void fillFeedsList(QTreeWidgetItem *parent = 0, const Rss::FolderPtr& rss_parent = Rss::FolderPtr()); + void fillFeedsList(QTreeWidgetItem *parent = 0, const Rss::FolderPtr &rss_parent = Rss::FolderPtr()); void saveSlidersPosition(); void restoreSlidersPosition(); void askNewFolder(); @@ -88,16 +88,15 @@ private slots: void on_rssDownloaderBtn_clicked(); private: - static QListWidgetItem* createArticleListItem(const Rss::ArticlePtr& article); - static QTreeWidgetItem* createFolderListItem(const Rss::FilePtr& rssFile); + static QListWidgetItem *createArticleListItem(const Rss::ArticlePtr &article); + static QTreeWidgetItem *createFolderListItem(const Rss::FilePtr &rssFile); private: Rss::ManagerPtr m_rssManager; FeedListWidget *m_feedList; - QListWidgetItem* m_currentArticle; + QListWidgetItem *m_currentArticle; QShortcut *editHotkey; QShortcut *deleteHotkey; - }; #endif diff --git a/src/gui/torrentmodel.cpp b/src/gui/torrentmodel.cpp index 63439a189..d18c3c627 100644 --- a/src/gui/torrentmodel.cpp +++ b/src/gui/torrentmodel.cpp @@ -65,15 +65,15 @@ TorrentModel::TorrentModel(QObject *parent) addTorrent(torrent); // Listen for torrent changes - connect(BitTorrent::Session::instance(), SIGNAL(torrentAdded(BitTorrent::TorrentHandle *const)), SLOT(addTorrent(BitTorrent::TorrentHandle *const))); - connect(BitTorrent::Session::instance(), SIGNAL(torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentAboutToBeRemoved(BitTorrent::TorrentHandle *const))); + connect(BitTorrent::Session::instance(), SIGNAL(torrentAdded(BitTorrent::TorrentHandle * const)), SLOT(addTorrent(BitTorrent::TorrentHandle * const))); + connect(BitTorrent::Session::instance(), SIGNAL(torrentAboutToBeRemoved(BitTorrent::TorrentHandle * const)), SLOT(handleTorrentAboutToBeRemoved(BitTorrent::TorrentHandle * const))); connect(BitTorrent::Session::instance(), SIGNAL(torrentsUpdated()), SLOT(handleTorrentsUpdated())); - connect(BitTorrent::Session::instance(), SIGNAL(torrentFinished(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const))); - connect(BitTorrent::Session::instance(), SIGNAL(torrentMetadataLoaded(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const))); - connect(BitTorrent::Session::instance(), SIGNAL(torrentResumed(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const))); - connect(BitTorrent::Session::instance(), SIGNAL(torrentPaused(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const))); - connect(BitTorrent::Session::instance(), SIGNAL(torrentFinishedChecking(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const))); + connect(BitTorrent::Session::instance(), SIGNAL(torrentFinished(BitTorrent::TorrentHandle * const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle * const))); + connect(BitTorrent::Session::instance(), SIGNAL(torrentMetadataLoaded(BitTorrent::TorrentHandle * const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle * const))); + connect(BitTorrent::Session::instance(), SIGNAL(torrentResumed(BitTorrent::TorrentHandle * const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle * const))); + connect(BitTorrent::Session::instance(), SIGNAL(torrentPaused(BitTorrent::TorrentHandle * const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle * const))); + connect(BitTorrent::Session::instance(), SIGNAL(torrentFinishedChecking(BitTorrent::TorrentHandle * const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle * const))); } int TorrentModel::rowCount(const QModelIndex &index) const @@ -92,7 +92,7 @@ QVariant TorrentModel::headerData(int section, Qt::Orientation orientation, int { if (orientation == Qt::Horizontal) { if (role == Qt::DisplayRole) { - switch(section) { + switch (section) { case TR_PRIORITY: return "#"; case TR_NAME: return tr("Name", "i.e: torrent name"); case TR_SIZE: return tr("Size", "i.e: torrent size"); @@ -127,7 +127,7 @@ QVariant TorrentModel::headerData(int section, Qt::Orientation orientation, int } } else if (role == Qt::TextAlignmentRole) { - switch(section) { + switch (section) { case TR_AMOUNT_DOWNLOADED: case TR_AMOUNT_UPLOADED: case TR_AMOUNT_DOWNLOADED_SESSION: @@ -173,7 +173,7 @@ QVariant TorrentModel::data(const QModelIndex &index, int role) const if ((role != Qt::DisplayRole) && (role != Qt::UserRole)) return QVariant(); - switch(index.column()) { + switch (index.column()) { case TR_NAME: return torrent->name(); case TR_PRIORITY: @@ -233,7 +233,7 @@ QVariant TorrentModel::data(const QModelIndex &index, int role) const return -1; return torrent->timeSinceActivity(); case TR_TOTAL_SIZE: - return torrent->totalSize(); + return torrent->totalSize(); default: return QVariant(); } @@ -251,7 +251,7 @@ bool TorrentModel::setData(const QModelIndex &index, const QVariant &value, int if (!torrent) return false; // Category, seed date and Name columns can be edited - switch(index.column()) { + switch (index.column()) { case TR_NAME: torrent->setName(value.toString()); break;