mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-22 08:27:24 -06:00
Coding style clean up
This commit is contained in:
@@ -122,19 +122,19 @@ void AutomatedRssDownloader::saveSettings()
|
||||
void AutomatedRssDownloader::loadRulesList()
|
||||
{
|
||||
// Make sure we save the current item before clearing
|
||||
if(m_editedRule) {
|
||||
if (m_editedRule) {
|
||||
saveEditedRule();
|
||||
}
|
||||
ui->listRules->clear();
|
||||
foreach (const QString &rule_name, m_ruleList->ruleNames()) {
|
||||
QListWidgetItem *item = new QListWidgetItem(rule_name, ui->listRules);
|
||||
item->setFlags(item->flags()|Qt::ItemIsUserCheckable);
|
||||
if(m_ruleList->getRule(rule_name)->isEnabled())
|
||||
if (m_ruleList->getRule(rule_name)->isEnabled())
|
||||
item->setCheckState(Qt::Checked);
|
||||
else
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
if(ui->listRules->count() > 0 && !ui->listRules->currentItem())
|
||||
if (ui->listRules->count() > 0 && !ui->listRules->currentItem())
|
||||
ui->listRules->setCurrentRow(0);
|
||||
}
|
||||
|
||||
@@ -144,11 +144,11 @@ void AutomatedRssDownloader::loadFeedList()
|
||||
const QStringList feed_aliases = settings.getRssFeedsAliases();
|
||||
const QStringList feed_urls = settings.getRssFeedsUrls();
|
||||
QStringList existing_urls;
|
||||
for(int i=0; i<feed_aliases.size(); ++i) {
|
||||
for (int i=0; i<feed_aliases.size(); ++i) {
|
||||
QString feed_url = feed_urls.at(i);
|
||||
feed_url = feed_url.split("\\").last();
|
||||
qDebug() << Q_FUNC_INFO << feed_url;
|
||||
if(existing_urls.contains(feed_url)) continue;
|
||||
if (existing_urls.contains(feed_url)) continue;
|
||||
QListWidgetItem *item = new QListWidgetItem(feed_aliases.at(i), ui->listFeeds);
|
||||
item->setData(Qt::UserRole, feed_url);
|
||||
item->setFlags(item->flags()|Qt::ItemIsUserCheckable);
|
||||
@@ -159,18 +159,18 @@ void AutomatedRssDownloader::loadFeedList()
|
||||
void AutomatedRssDownloader::updateFeedList()
|
||||
{
|
||||
disconnect(ui->listFeeds, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(handleFeedCheckStateChange(QListWidgetItem*)));
|
||||
for(int i=0; i<ui->listFeeds->count(); ++i) {
|
||||
for (int i=0; i<ui->listFeeds->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()) {
|
||||
foreach (const QListWidgetItem *ruleItem, ui->listRules->selectedItems()) {
|
||||
RssDownloadRulePtr rule = m_ruleList->getRule(ruleItem->text());
|
||||
if(!rule) continue;
|
||||
if (!rule) continue;
|
||||
qDebug() << "Rule" << rule->name() << "affects" << rule->rssFeeds().size() << "feeds.";
|
||||
foreach(QString test, rule->rssFeeds()) {
|
||||
foreach (QString test, rule->rssFeeds()) {
|
||||
qDebug() << "Feed is " << test;
|
||||
}
|
||||
if(rule->rssFeeds().contains(feed_url)) {
|
||||
if (rule->rssFeeds().contains(feed_url)) {
|
||||
qDebug() << "Rule " << rule->name() << " affects feed " << feed_url;
|
||||
all_enabled = true;
|
||||
} else {
|
||||
@@ -179,7 +179,7 @@ void AutomatedRssDownloader::updateFeedList()
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(all_enabled)
|
||||
if (all_enabled)
|
||||
item->setCheckState(Qt::Checked);
|
||||
else
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
@@ -201,7 +201,7 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
|
||||
saveEditedRule();
|
||||
// Update rule definition box
|
||||
const QList<QListWidgetItem*> selection = ui->listRules->selectedItems();
|
||||
if(selection.count() == 1) {
|
||||
if (selection.count() == 1) {
|
||||
m_editedRule = selection.first();
|
||||
RssDownloadRulePtr rule = getCurrentRule();
|
||||
if (rule) {
|
||||
@@ -250,7 +250,7 @@ void AutomatedRssDownloader::clearRuleDefinitionBox()
|
||||
RssDownloadRulePtr AutomatedRssDownloader::getCurrentRule() const
|
||||
{
|
||||
QListWidgetItem * current_item = ui->listRules->currentItem();
|
||||
if(current_item)
|
||||
if (current_item)
|
||||
return m_ruleList->getRule(current_item->text());
|
||||
return RssDownloadRulePtr();
|
||||
}
|
||||
@@ -259,16 +259,16 @@ void AutomatedRssDownloader::initLabelCombobox()
|
||||
{
|
||||
// Load custom labels
|
||||
const QStringList customLabels = Preferences().getTorrentLabels();
|
||||
foreach(const QString& label, customLabels) {
|
||||
foreach (const QString& label, customLabels) {
|
||||
ui->comboLabel->addItem(label);
|
||||
}
|
||||
}
|
||||
|
||||
void AutomatedRssDownloader::saveEditedRule()
|
||||
{
|
||||
if(!m_editedRule) return;
|
||||
if (!m_editedRule) return;
|
||||
qDebug() << Q_FUNC_INFO << m_editedRule;
|
||||
if(ui->listRules->findItems(m_editedRule->text(), Qt::MatchExactly).isEmpty()) {
|
||||
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;
|
||||
@@ -284,13 +284,13 @@ void AutomatedRssDownloader::saveEditedRule()
|
||||
rule->setUseRegex(ui->checkRegex->isChecked());
|
||||
rule->setMustContain(ui->lineContains->text());
|
||||
rule->setMustNotContain(ui->lineNotContains->text());
|
||||
if(ui->saveDiffDir_check->isChecked())
|
||||
if (ui->saveDiffDir_check->isChecked())
|
||||
rule->setSavePath(ui->lineSavePath->text());
|
||||
else
|
||||
rule->setSavePath("");
|
||||
rule->setLabel(ui->comboLabel->currentText());
|
||||
// Save new label
|
||||
if(!rule->label().isEmpty())
|
||||
if (!rule->label().isEmpty())
|
||||
Preferences().addTorrentLabel(rule->label());
|
||||
//rule->setRssFeeds(getSelectedFeeds());
|
||||
// Save it
|
||||
@@ -302,9 +302,9 @@ void AutomatedRssDownloader::on_addRuleBtn_clicked()
|
||||
{
|
||||
// Ask for a rule name
|
||||
const QString rule_name = QInputDialog::getText(this, tr("New rule name"), tr("Please type the name of the new download rule->"));
|
||||
if(rule_name.isEmpty()) return;
|
||||
if (rule_name.isEmpty()) return;
|
||||
// Check if this rule name already exists
|
||||
if(m_ruleList->getRule(rule_name)) {
|
||||
if (m_ruleList->getRule(rule_name)) {
|
||||
QMessageBox::warning(this, tr("Rule name conflict"), tr("A rule with this name already exists, please choose another name."));
|
||||
return;
|
||||
}
|
||||
@@ -319,16 +319,16 @@ void AutomatedRssDownloader::on_addRuleBtn_clicked()
|
||||
void AutomatedRssDownloader::on_removeRuleBtn_clicked()
|
||||
{
|
||||
const QList<QListWidgetItem*> selection = ui->listRules->selectedItems();
|
||||
if(selection.isEmpty()) return;
|
||||
if (selection.isEmpty()) return;
|
||||
// Ask for confirmation
|
||||
QString confirm_text;
|
||||
if(selection.count() == 1)
|
||||
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)
|
||||
if (QMessageBox::question(this, tr("Rule deletion confirmation"), confirm_text, QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes)
|
||||
return;
|
||||
foreach(QListWidgetItem *item, selection) {
|
||||
foreach (QListWidgetItem *item, selection) {
|
||||
// Actually remove the item
|
||||
ui->listRules->removeItemWidget(item);
|
||||
const QString rule_name = item->text();
|
||||
@@ -343,22 +343,22 @@ void AutomatedRssDownloader::on_removeRuleBtn_clicked()
|
||||
void AutomatedRssDownloader::on_browseSP_clicked()
|
||||
{
|
||||
QString save_path = QFileDialog::getExistingDirectory(this, tr("Destination directory"), QDir::homePath());
|
||||
if(!save_path.isEmpty())
|
||||
if (!save_path.isEmpty())
|
||||
ui->lineSavePath->setText(save_path);
|
||||
}
|
||||
|
||||
void AutomatedRssDownloader::on_exportBtn_clicked()
|
||||
{
|
||||
if(m_ruleList->isEmpty()) {
|
||||
if (m_ruleList->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))
|
||||
if (save_path.isEmpty()) return;
|
||||
if (!save_path.endsWith(".rssrules", Qt::CaseInsensitive))
|
||||
save_path += ".rssrules";
|
||||
if(!m_ruleList->serialize(save_path)) {
|
||||
if (!m_ruleList->serialize(save_path)) {
|
||||
QMessageBox::warning(this, tr("I/O Error"), tr("Failed to create the destination file"));
|
||||
return;
|
||||
}
|
||||
@@ -368,9 +368,9 @@ 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 (*.rssrules *.filters)"));
|
||||
if(load_path.isEmpty() || !QFile::exists(load_path)) return;
|
||||
if (load_path.isEmpty() || !QFile::exists(load_path)) return;
|
||||
// Load it
|
||||
if(!m_ruleList->unserialize(load_path)) {
|
||||
if (!m_ruleList->unserialize(load_path)) {
|
||||
QMessageBox::warning(this, tr("Import Error"), tr("Failed to import the selected rules file"));
|
||||
return;
|
||||
}
|
||||
@@ -386,8 +386,8 @@ void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos)
|
||||
QAction *delAct = 0;
|
||||
QAction *renameAct = 0;
|
||||
const QList<QListWidgetItem*> selection = ui->listRules->selectedItems();
|
||||
if(!selection.isEmpty()) {
|
||||
if(selection.count() == 1) {
|
||||
if (!selection.isEmpty()) {
|
||||
if (selection.count() == 1) {
|
||||
delAct = menu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Delete rule"));
|
||||
menu.addSeparator();
|
||||
renameAct = menu.addAction(IconProvider::instance()->getIcon("edit-rename"), tr("Rename rule->.."));
|
||||
@@ -396,16 +396,16 @@ void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos)
|
||||
}
|
||||
}
|
||||
QAction *act = menu.exec(QCursor::pos());
|
||||
if(!act) return;
|
||||
if(act == addAct) {
|
||||
if (!act) return;
|
||||
if (act == addAct) {
|
||||
on_addRuleBtn_clicked();
|
||||
return;
|
||||
}
|
||||
if(act == delAct) {
|
||||
if (act == delAct) {
|
||||
on_removeRuleBtn_clicked();
|
||||
return;
|
||||
}
|
||||
if(act == renameAct) {
|
||||
if (act == renameAct) {
|
||||
renameSelectedRule();
|
||||
return;
|
||||
}
|
||||
@@ -414,12 +414,12 @@ void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos)
|
||||
void AutomatedRssDownloader::renameSelectedRule()
|
||||
{
|
||||
QListWidgetItem *item = ui->listRules->currentItem();
|
||||
if(!item) return;
|
||||
if (!item) return;
|
||||
forever {
|
||||
QString new_name = QInputDialog::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_ruleList->ruleNames().contains(new_name, Qt::CaseInsensitive)) {
|
||||
if (new_name.isEmpty()) return;
|
||||
if (m_ruleList->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
|
||||
@@ -432,7 +432,7 @@ void AutomatedRssDownloader::renameSelectedRule()
|
||||
|
||||
void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_item)
|
||||
{
|
||||
if(ui->ruleDefBox->isEnabled()) {
|
||||
if (ui->ruleDefBox->isEnabled()) {
|
||||
// Make sure the current rule is saved
|
||||
saveEditedRule();
|
||||
}
|
||||
@@ -441,15 +441,15 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it
|
||||
RssDownloadRulePtr rule = m_ruleList->getRule(rule_item->text());
|
||||
Q_ASSERT(rule);
|
||||
QStringList affected_feeds = rule->rssFeeds();
|
||||
if(feed_item->checkState() == Qt::Checked) {
|
||||
if(!affected_feeds.contains(feed_url))
|
||||
if (feed_item->checkState() == Qt::Checked) {
|
||||
if (!affected_feeds.contains(feed_url))
|
||||
affected_feeds << feed_url;
|
||||
} else {
|
||||
if(affected_feeds.contains(feed_url))
|
||||
if (affected_feeds.contains(feed_url))
|
||||
affected_feeds.removeOne(feed_url);
|
||||
}
|
||||
// Save the updated rule
|
||||
if(affected_feeds.size() != rule->rssFeeds().size()) {
|
||||
if (affected_feeds.size() != rule->rssFeeds().size()) {
|
||||
rule->setRssFeeds(affected_feeds);
|
||||
m_ruleList->saveRule(rule);
|
||||
}
|
||||
@@ -461,7 +461,7 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it
|
||||
void AutomatedRssDownloader::updateMatchingArticles()
|
||||
{
|
||||
ui->treeMatchingArticles->clear();
|
||||
if(ui->ruleDefBox->isEnabled()) {
|
||||
if (ui->ruleDefBox->isEnabled()) {
|
||||
saveEditedRule();
|
||||
}
|
||||
RssManagerPtr manager = m_manager.toStrongRef();
|
||||
@@ -469,17 +469,17 @@ void AutomatedRssDownloader::updateMatchingArticles()
|
||||
return;
|
||||
const QHash<QString, RssFeedPtr> all_feeds = manager->getAllFeedsAsHash();
|
||||
|
||||
foreach(const QListWidgetItem *rule_item, ui->listRules->selectedItems()) {
|
||||
foreach (const QListWidgetItem *rule_item, ui->listRules->selectedItems()) {
|
||||
RssDownloadRulePtr rule = m_ruleList->getRule(rule_item->text());
|
||||
if(!rule) continue;
|
||||
foreach(const QString &feed_url, rule->rssFeeds()) {
|
||||
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
|
||||
if (!all_feeds.contains(feed_url)) continue; // Feed was removed
|
||||
RssFeedPtr feed = all_feeds.value(feed_url);
|
||||
Q_ASSERT(feed);
|
||||
if(!feed) continue;
|
||||
if (!feed) continue;
|
||||
const QStringList matching_articles = rule->findMatchingArticles(feed);
|
||||
if(!matching_articles.isEmpty())
|
||||
if (!matching_articles.isEmpty())
|
||||
addFeedArticlesToTree(feed, matching_articles);
|
||||
}
|
||||
}
|
||||
@@ -489,15 +489,15 @@ void AutomatedRssDownloader::addFeedArticlesToTree(const RssFeedPtr& feed, const
|
||||
{
|
||||
// Check if this feed is already in the tree
|
||||
QTreeWidgetItem *treeFeedItem = 0;
|
||||
for(int i=0; i<ui->treeMatchingArticles->topLevelItemCount(); ++i) {
|
||||
for (int i=0; i<ui->treeMatchingArticles->topLevelItemCount(); ++i) {
|
||||
QTreeWidgetItem *item = ui->treeMatchingArticles->topLevelItem(i);
|
||||
if(item->data(0, Qt::UserRole).toString() == feed->url()) {
|
||||
if (item->data(0, Qt::UserRole).toString() == feed->url()) {
|
||||
treeFeedItem = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If there is none, create it
|
||||
if(!treeFeedItem) {
|
||||
if (!treeFeedItem) {
|
||||
treeFeedItem = new QTreeWidgetItem(QStringList() << feed->displayName());
|
||||
treeFeedItem->setToolTip(0, feed->displayName());
|
||||
QFont f = treeFeedItem->font(0);
|
||||
@@ -508,7 +508,7 @@ void AutomatedRssDownloader::addFeedArticlesToTree(const RssFeedPtr& feed, const
|
||||
ui->treeMatchingArticles->addTopLevelItem(treeFeedItem);
|
||||
}
|
||||
// Insert the articles
|
||||
foreach(const QString &art, articles) {
|
||||
foreach (const QString &art, articles) {
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(QStringList() << art);
|
||||
item->setToolTip(0, art);
|
||||
treeFeedItem->addChild(item);
|
||||
@@ -519,7 +519,7 @@ void AutomatedRssDownloader::addFeedArticlesToTree(const RssFeedPtr& feed, const
|
||||
void AutomatedRssDownloader::updateFieldsToolTips(bool regex)
|
||||
{
|
||||
QString tip;
|
||||
if(regex) {
|
||||
if (regex) {
|
||||
tip = tr("Regex mode: use Perl-like regular expressions");
|
||||
ui->lineContains->setToolTip(tip);
|
||||
ui->lineNotContains->setToolTip(tip);
|
||||
@@ -536,18 +536,18 @@ void AutomatedRssDownloader::updateMustLineValidity()
|
||||
const QString text = ui->lineContains->text();
|
||||
bool valid = true;
|
||||
QStringList tokens;
|
||||
if(ui->checkRegex->isChecked())
|
||||
if (ui->checkRegex->isChecked())
|
||||
tokens << text;
|
||||
else
|
||||
tokens << text.split(" ");
|
||||
foreach(const QString &token, tokens) {
|
||||
foreach (const QString &token, tokens) {
|
||||
QRegExp reg(token, Qt::CaseInsensitive, ui->checkRegex->isChecked() ? QRegExp::RegExp : QRegExp::Wildcard);
|
||||
if(!reg.isValid()) {
|
||||
if (!reg.isValid()) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(valid) {
|
||||
if (valid) {
|
||||
ui->lineContains->setStyleSheet("");
|
||||
ui->lbl_must_stat->setPixmap(QPixmap());
|
||||
} else {
|
||||
@@ -561,18 +561,18 @@ void AutomatedRssDownloader::updateMustNotLineValidity()
|
||||
const QString text = ui->lineNotContains->text();
|
||||
bool valid = true;
|
||||
QStringList tokens;
|
||||
if(ui->checkRegex->isChecked())
|
||||
if (ui->checkRegex->isChecked())
|
||||
tokens << text;
|
||||
else
|
||||
tokens << text.split(QRegExp("[\\s|]"));
|
||||
foreach(const QString &token, tokens) {
|
||||
foreach (const QString &token, tokens) {
|
||||
QRegExp reg(token, Qt::CaseInsensitive, ui->checkRegex->isChecked() ? QRegExp::RegExp : QRegExp::Wildcard);
|
||||
if(!reg.isValid()) {
|
||||
if (!reg.isValid()) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(valid) {
|
||||
if (valid) {
|
||||
ui->lineNotContains->setStyleSheet("");
|
||||
ui->lbl_mustnot_stat->setPixmap(QPixmap());
|
||||
} else {
|
||||
|
||||
@@ -46,9 +46,9 @@ CookiesDlg::CookiesDlg(QWidget *parent, const QList<QByteArray> &raw_cookies) :
|
||||
ui->del_btn->setIcon(IconProvider::instance()->getIcon("list-remove"));
|
||||
|
||||
ui->infos_lbl->setText(tr("Common keys for cookies are : '%1', '%2'.\nYou should get this information from your Web browser preferences.").arg("uid").arg("pass"));
|
||||
foreach(const QByteArray &raw_cookie, raw_cookies) {
|
||||
foreach (const QByteArray &raw_cookie, raw_cookies) {
|
||||
QList<QByteArray> cookie_parts = raw_cookie.split('=');
|
||||
if(cookie_parts.size() != 2) continue;
|
||||
if (cookie_parts.size() != 2) continue;
|
||||
const int i = ui->cookiesTable->rowCount();
|
||||
ui->cookiesTable->setRowCount(i+1);
|
||||
ui->cookiesTable->setItem(i, COOKIE_KEY, new QTableWidgetItem(cookie_parts.first().data()));
|
||||
@@ -70,21 +70,21 @@ void CookiesDlg::on_add_btn_clicked() {
|
||||
void CookiesDlg::on_del_btn_clicked() {
|
||||
// Get selected cookie
|
||||
QList<QTableWidgetItem*> selection = ui->cookiesTable->selectedItems();
|
||||
if(!selection.isEmpty()) {
|
||||
if (!selection.isEmpty()) {
|
||||
ui->cookiesTable->removeRow(selection.first()->row());
|
||||
}
|
||||
}
|
||||
|
||||
QList<QByteArray> CookiesDlg::getCookies() const {
|
||||
QList<QByteArray> ret;
|
||||
for(int i=0; i<ui->cookiesTable->rowCount(); ++i) {
|
||||
for (int i=0; i<ui->cookiesTable->rowCount(); ++i) {
|
||||
QString key;
|
||||
if(ui->cookiesTable->item(i, COOKIE_KEY))
|
||||
if (ui->cookiesTable->item(i, COOKIE_KEY))
|
||||
key = ui->cookiesTable->item(i, COOKIE_KEY)->text().trimmed();
|
||||
QString value;
|
||||
if(ui->cookiesTable->item(i, COOKIE_VALUE))
|
||||
if (ui->cookiesTable->item(i, COOKIE_VALUE))
|
||||
value = ui->cookiesTable->item(i, COOKIE_VALUE)->text().trimmed();
|
||||
if(!key.isEmpty() && !value.isEmpty()) {
|
||||
if (!key.isEmpty() && !value.isEmpty()) {
|
||||
const QString raw_cookie = key+"="+value;
|
||||
qDebug("Cookie: %s", qPrintable(raw_cookie));
|
||||
ret << raw_cookie.toLocal8Bit();
|
||||
@@ -95,7 +95,7 @@ QList<QByteArray> CookiesDlg::getCookies() const {
|
||||
|
||||
QList<QByteArray> CookiesDlg::askForCookies(QWidget *parent, const QList<QByteArray> &raw_cookies, bool *ok) {
|
||||
CookiesDlg dlg(parent, raw_cookies);
|
||||
if(dlg.exec()) {
|
||||
if (dlg.exec()) {
|
||||
*ok = true;
|
||||
return dlg.getCookies();
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ void FeedListWidget::itemAboutToBeRemoved(QTreeWidgetItem *item) {
|
||||
m_feedsItems.remove(feed->id());
|
||||
} if (RssFolderPtr folder = qSharedPointerDynamicCast<RssFolder>(file)) {
|
||||
RssFeedList feeds = folder->getAllFeeds();
|
||||
foreach(const RssFeedPtr& feed, feeds) {
|
||||
foreach (const RssFeedPtr& feed, feeds) {
|
||||
m_feedsItems.remove(feed->id());
|
||||
}
|
||||
}
|
||||
@@ -84,8 +84,8 @@ QTreeWidgetItem* FeedListWidget::stickyUnreadItem() const {
|
||||
|
||||
QStringList FeedListWidget::getItemPath(QTreeWidgetItem* item) const {
|
||||
QStringList path;
|
||||
if(item) {
|
||||
if(item->parent())
|
||||
if (item) {
|
||||
if (item->parent())
|
||||
path << getItemPath(item->parent());
|
||||
path.append(getRSSItem(item)->id());
|
||||
}
|
||||
@@ -95,19 +95,19 @@ QStringList FeedListWidget::getItemPath(QTreeWidgetItem* item) const {
|
||||
QList<QTreeWidgetItem*> FeedListWidget::getAllOpenFolders(QTreeWidgetItem *parent) const {
|
||||
QList<QTreeWidgetItem*> open_folders;
|
||||
int nbChildren;
|
||||
if(parent)
|
||||
if (parent)
|
||||
nbChildren = parent->childCount();
|
||||
else
|
||||
nbChildren = topLevelItemCount();
|
||||
for(int i=0; i<nbChildren; ++i) {
|
||||
for (int i=0; i<nbChildren; ++i) {
|
||||
QTreeWidgetItem *item;
|
||||
if(parent)
|
||||
if (parent)
|
||||
item = parent->child(i);
|
||||
else
|
||||
item = topLevelItem(i);
|
||||
if(isFolder(item) && item->isExpanded()) {
|
||||
if (isFolder(item) && item->isExpanded()) {
|
||||
QList<QTreeWidgetItem*> open_subfolders = getAllOpenFolders(item);
|
||||
if(!open_subfolders.empty()) {
|
||||
if (!open_subfolders.empty()) {
|
||||
open_folders << open_subfolders;
|
||||
} else {
|
||||
open_folders << item;
|
||||
@@ -120,9 +120,9 @@ QList<QTreeWidgetItem*> FeedListWidget::getAllOpenFolders(QTreeWidgetItem *paren
|
||||
QList<QTreeWidgetItem*> FeedListWidget::getAllFeedItems(QTreeWidgetItem* folder) {
|
||||
QList<QTreeWidgetItem*> feeds;
|
||||
const int nbChildren = folder->childCount();
|
||||
for(int i=0; i<nbChildren; ++i) {
|
||||
for (int i=0; i<nbChildren; ++i) {
|
||||
QTreeWidgetItem *item = folder->child(i);
|
||||
if(isFeed(item)) {
|
||||
if (isFeed(item)) {
|
||||
feeds << item;
|
||||
} else {
|
||||
feeds << getAllFeedItems(item);
|
||||
@@ -166,21 +166,21 @@ QTreeWidgetItem* FeedListWidget::currentFeed() const {
|
||||
}
|
||||
|
||||
void FeedListWidget::updateCurrentFeed(QTreeWidgetItem* new_item) {
|
||||
if(!new_item) return;
|
||||
if(!m_rssMapping.contains(new_item)) return;
|
||||
if(isFeed(new_item) || new_item == m_unreadStickyItem)
|
||||
if (!new_item) return;
|
||||
if (!m_rssMapping.contains(new_item)) return;
|
||||
if (isFeed(new_item) || new_item == m_unreadStickyItem)
|
||||
m_currentFeed = new_item;
|
||||
}
|
||||
|
||||
void FeedListWidget::dragMoveEvent(QDragMoveEvent * event) {
|
||||
QTreeWidgetItem *item = itemAt(event->pos());
|
||||
if(item == m_unreadStickyItem) {
|
||||
if (item == m_unreadStickyItem) {
|
||||
event->ignore();
|
||||
} else {
|
||||
if(item && isFolder(item))
|
||||
if (item && isFolder(item))
|
||||
event->ignore();
|
||||
else {
|
||||
if(selectedItems().contains(m_unreadStickyItem)) {
|
||||
if (selectedItems().contains(m_unreadStickyItem)) {
|
||||
event->ignore();
|
||||
} else {
|
||||
QTreeWidget::dragMoveEvent(event);
|
||||
@@ -194,7 +194,7 @@ void FeedListWidget::dropEvent(QDropEvent *event) {
|
||||
QList<QTreeWidgetItem*> folders_altered;
|
||||
QTreeWidgetItem *dest_folder_item = itemAt(event->pos());
|
||||
RssFolderPtr dest_folder;
|
||||
if(dest_folder_item) {
|
||||
if (dest_folder_item) {
|
||||
dest_folder = qSharedPointerCast<RssFolder>(getRSSItem(dest_folder_item));
|
||||
folders_altered << dest_folder_item;
|
||||
} else {
|
||||
@@ -202,26 +202,26 @@ void FeedListWidget::dropEvent(QDropEvent *event) {
|
||||
}
|
||||
QList<QTreeWidgetItem *> src_items = selectedItems();
|
||||
// Check if there is not going to overwrite another file
|
||||
foreach(QTreeWidgetItem *src_item, src_items) {
|
||||
foreach (QTreeWidgetItem *src_item, src_items) {
|
||||
RssFilePtr file = getRSSItem(src_item);
|
||||
if(dest_folder->hasChild(file->id())) {
|
||||
if (dest_folder->hasChild(file->id())) {
|
||||
emit overwriteAttempt(file->id());
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Proceed with the move
|
||||
foreach(QTreeWidgetItem *src_item, src_items) {
|
||||
foreach (QTreeWidgetItem *src_item, src_items) {
|
||||
QTreeWidgetItem *parent_folder = src_item->parent();
|
||||
if(parent_folder && !folders_altered.contains(parent_folder))
|
||||
if (parent_folder && !folders_altered.contains(parent_folder))
|
||||
folders_altered << parent_folder;
|
||||
// Actually move the file
|
||||
RssFilePtr file = getRSSItem(src_item);
|
||||
m_rssManager->moveFile(file, dest_folder);
|
||||
}
|
||||
QTreeWidget::dropEvent(event);
|
||||
if(dest_folder_item)
|
||||
if (dest_folder_item)
|
||||
dest_folder_item->setExpanded(true);
|
||||
// Emit signal for update
|
||||
if(!folders_altered.empty())
|
||||
if (!folders_altered.empty())
|
||||
emit foldersAltered(folders_altered);
|
||||
}
|
||||
|
||||
@@ -63,22 +63,22 @@ enum ArticleRoles {
|
||||
|
||||
// display a right-click menu
|
||||
void RSSImp::displayRSSListMenu(const QPoint& pos){
|
||||
if(!m_feedList->indexAt(pos).isValid()) {
|
||||
if (!m_feedList->indexAt(pos).isValid()) {
|
||||
// No item under the mouse, clear selection
|
||||
m_feedList->clearSelection();
|
||||
}
|
||||
QMenu myRSSListMenu(this);
|
||||
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
|
||||
if(selectedItems.size() > 0) {
|
||||
if (selectedItems.size() > 0) {
|
||||
myRSSListMenu.addAction(actionUpdate);
|
||||
myRSSListMenu.addAction(actionMark_items_read);
|
||||
myRSSListMenu.addSeparator();
|
||||
if(selectedItems.size() == 1) {
|
||||
if(m_feedList->getRSSItem(selectedItems.first()) != m_rssManager) {
|
||||
if (selectedItems.size() == 1) {
|
||||
if (m_feedList->getRSSItem(selectedItems.first()) != m_rssManager) {
|
||||
myRSSListMenu.addAction(actionRename);
|
||||
myRSSListMenu.addAction(actionDelete);
|
||||
myRSSListMenu.addSeparator();
|
||||
if(m_feedList->isFolder(selectedItems.first())) {
|
||||
if (m_feedList->isFolder(selectedItems.first())) {
|
||||
myRSSListMenu.addAction(actionNew_folder);
|
||||
} else {
|
||||
myRSSListMenu.addAction(actionManage_cookies);
|
||||
@@ -86,7 +86,7 @@ void RSSImp::displayRSSListMenu(const QPoint& pos){
|
||||
}
|
||||
}
|
||||
myRSSListMenu.addAction(actionNew_subscription);
|
||||
if(m_feedList->isFeed(selectedItems.first())) {
|
||||
if (m_feedList->isFeed(selectedItems.first())) {
|
||||
myRSSListMenu.addSeparator();
|
||||
myRSSListMenu.addAction(actionCopy_feed_URL);
|
||||
}
|
||||
@@ -102,18 +102,18 @@ void RSSImp::displayRSSListMenu(const QPoint& pos){
|
||||
void RSSImp::displayItemsListMenu(const QPoint&){
|
||||
QMenu myItemListMenu(this);
|
||||
QList<QListWidgetItem*> selectedItems = listArticles->selectedItems();
|
||||
if(selectedItems.size() > 0) {
|
||||
if (selectedItems.size() > 0) {
|
||||
bool has_attachment = false;
|
||||
foreach(const QListWidgetItem *item, selectedItems) {
|
||||
foreach (const QListWidgetItem *item, selectedItems) {
|
||||
qDebug("text(3) URL: %s", qPrintable(item->data(Article::FeedUrlRole).toString()));
|
||||
qDebug("text(2) TITLE: %s", qPrintable(item->data(Article::TitleRole).toString()));
|
||||
if(m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
|
||||
if (m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
|
||||
->getItem(item->data(Article::IdRole).toString())->hasAttachment()) {
|
||||
has_attachment = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(has_attachment)
|
||||
if (has_attachment)
|
||||
myItemListMenu.addAction(actionDownload_torrent);
|
||||
myItemListMenu.addAction(actionOpen_news_URL);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ void RSSImp::on_actionManage_cookies_triggered() {
|
||||
bool ok = false;
|
||||
RssSettings settings;
|
||||
QList<QByteArray> raw_cookies = CookiesDlg::askForCookies(this, settings.getHostNameCookies(feed_hostname), &ok);
|
||||
if(ok) {
|
||||
if (ok) {
|
||||
settings.setHostNameCookies(feed_hostname, raw_cookies);
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ void RSSImp::on_actionManage_cookies_triggered() {
|
||||
void RSSImp::askNewFolder() {
|
||||
QTreeWidgetItem *parent_item = 0;
|
||||
RssFolderPtr rss_parent;
|
||||
if(m_feedList->selectedItems().size() > 0) {
|
||||
if (m_feedList->selectedItems().size() > 0) {
|
||||
parent_item = m_feedList->selectedItems().at(0);
|
||||
rss_parent = qSharedPointerDynamicCast<RssFolder>(m_feedList->getRSSItem(parent_item));
|
||||
Q_ASSERT(rss_parent);
|
||||
@@ -147,10 +147,10 @@ void RSSImp::askNewFolder() {
|
||||
}
|
||||
bool ok;
|
||||
QString new_name = QInputDialog::getText(this, tr("Please choose a folder name"), tr("Folder name:"), QLineEdit::Normal, tr("New folder"), &ok);
|
||||
if(ok) {
|
||||
if (ok) {
|
||||
RssFolderPtr new_folder = rss_parent->addFolder(new_name);
|
||||
QTreeWidgetItem* folder_item;
|
||||
if(parent_item)
|
||||
if (parent_item)
|
||||
folder_item = new QTreeWidgetItem(parent_item);
|
||||
else
|
||||
folder_item = new QTreeWidgetItem(m_feedList);
|
||||
@@ -160,7 +160,7 @@ void RSSImp::askNewFolder() {
|
||||
folder_item->setText(0, new_folder->displayName() + QString::fromUtf8(" (0)"));
|
||||
folder_item->setData(0,Qt::DecorationRole, QVariant(IconProvider::instance()->getIcon("inode-directory")));
|
||||
// Expand parent folder to display new folder
|
||||
if(parent_item)
|
||||
if (parent_item)
|
||||
parent_item->setExpanded(true);
|
||||
m_rssManager->saveStreamList();
|
||||
}
|
||||
@@ -177,18 +177,18 @@ void RSSImp::on_newFeedButton_clicked() {
|
||||
// Determine parent folder for new feed
|
||||
QTreeWidgetItem *parent_item = 0;
|
||||
QList<QTreeWidgetItem *> selected_items = m_feedList->selectedItems();
|
||||
if(!selected_items.empty()) {
|
||||
if (!selected_items.empty()) {
|
||||
parent_item = selected_items.first();
|
||||
// Consider the case where the user clicked on Unread item
|
||||
if(parent_item == m_feedList->stickyUnreadItem()) {
|
||||
if (parent_item == m_feedList->stickyUnreadItem()) {
|
||||
parent_item = 0;
|
||||
} else {
|
||||
if(m_feedList->isFolder(parent_item))
|
||||
if (m_feedList->isFolder(parent_item))
|
||||
parent_item = parent_item->parent();
|
||||
}
|
||||
}
|
||||
RssFolderPtr rss_parent;
|
||||
if(parent_item) {
|
||||
if (parent_item) {
|
||||
rss_parent = qSharedPointerCast<RssFolder>(m_feedList->getRSSItem(parent_item));
|
||||
} else {
|
||||
rss_parent = m_rssManager;
|
||||
@@ -197,14 +197,14 @@ void RSSImp::on_newFeedButton_clicked() {
|
||||
bool ok;
|
||||
QString clip_txt = qApp->clipboard()->text();
|
||||
QString default_url = "http://";
|
||||
if(clip_txt.startsWith("http://", Qt::CaseInsensitive) || clip_txt.startsWith("https://", Qt::CaseInsensitive) || clip_txt.startsWith("ftp://", Qt::CaseInsensitive)) {
|
||||
if (clip_txt.startsWith("http://", Qt::CaseInsensitive) || clip_txt.startsWith("https://", Qt::CaseInsensitive) || clip_txt.startsWith("ftp://", Qt::CaseInsensitive)) {
|
||||
default_url = clip_txt;
|
||||
}
|
||||
QString newUrl = QInputDialog::getText(this, tr("Please type a rss stream url"), tr("Stream URL:"), QLineEdit::Normal, default_url, &ok);
|
||||
if(ok) {
|
||||
if (ok) {
|
||||
newUrl = newUrl.trimmed();
|
||||
if(!newUrl.isEmpty()){
|
||||
if(m_feedList->hasFeed(newUrl)) {
|
||||
if (!newUrl.isEmpty()){
|
||||
if (m_feedList->hasFeed(newUrl)) {
|
||||
QMessageBox::warning(this, tr("qBittorrent"),
|
||||
tr("This rss feed is already in the list."),
|
||||
QMessageBox::Ok);
|
||||
@@ -213,7 +213,7 @@ void RSSImp::on_newFeedButton_clicked() {
|
||||
RssFeedPtr stream = rss_parent->addStream(m_rssManager.data(), newUrl);
|
||||
// Create TreeWidget item
|
||||
QTreeWidgetItem* item;
|
||||
if(parent_item)
|
||||
if (parent_item)
|
||||
item = new QTreeWidgetItem(parent_item);
|
||||
else
|
||||
item = new QTreeWidgetItem(m_feedList);
|
||||
@@ -231,9 +231,9 @@ void RSSImp::on_newFeedButton_clicked() {
|
||||
// delete a stream by a button
|
||||
void RSSImp::deleteSelectedItems() {
|
||||
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
|
||||
if(selectedItems.size() == 0) return;
|
||||
if (selectedItems.size() == 0) return;
|
||||
int ret;
|
||||
if(selectedItems.size() > 1)
|
||||
if (selectedItems.size() > 1)
|
||||
ret = QMessageBox::question(this, tr("Are you sure? -- qBittorrent"), tr("Are you sure you want to delete these elements from the list?"),
|
||||
tr("&Yes"), tr("&No"),
|
||||
QString(), 0, 1);
|
||||
@@ -241,9 +241,9 @@ void RSSImp::deleteSelectedItems() {
|
||||
ret = QMessageBox::question(this, tr("Are you sure? -- qBittorrent"), tr("Are you sure you want to delete this element from the list?"),
|
||||
tr("&Yes"), tr("&No"),
|
||||
QString(), 0, 1);
|
||||
if(!ret) {
|
||||
foreach(QTreeWidgetItem *item, selectedItems){
|
||||
if(m_feedList->currentFeed() == item){
|
||||
if (!ret) {
|
||||
foreach (QTreeWidgetItem *item, selectedItems){
|
||||
if (m_feedList->currentFeed() == item){
|
||||
textBrowser->clear();
|
||||
m_currentArticle = 0;
|
||||
listArticles->clear();
|
||||
@@ -272,22 +272,22 @@ void RSSImp::loadFoldersOpenState() {
|
||||
settings.beginGroup("Rss");
|
||||
QStringList open_folders = settings.value("open_folders", QStringList()).toStringList();
|
||||
settings.endGroup();
|
||||
foreach(QString var_path, open_folders) {
|
||||
foreach (QString var_path, open_folders) {
|
||||
QStringList path = var_path.split("\\");
|
||||
QTreeWidgetItem *parent = 0;
|
||||
foreach(QString name, path) {
|
||||
foreach (QString name, path) {
|
||||
int nbChildren = 0;
|
||||
if(parent)
|
||||
if (parent)
|
||||
nbChildren = parent->childCount();
|
||||
else
|
||||
nbChildren = m_feedList->topLevelItemCount();
|
||||
for(int i=0; i<nbChildren; ++i) {
|
||||
for (int i=0; i<nbChildren; ++i) {
|
||||
QTreeWidgetItem* child;
|
||||
if(parent)
|
||||
if (parent)
|
||||
child = parent->child(i);
|
||||
else
|
||||
child = m_feedList->topLevelItem(i);
|
||||
if(m_feedList->getRSSItem(child)->id() == name) {
|
||||
if (m_feedList->getRSSItem(child)->id() == name) {
|
||||
parent = child;
|
||||
parent->setExpanded(true);
|
||||
qDebug("expanding folder %s", qPrintable(name));
|
||||
@@ -301,7 +301,7 @@ void RSSImp::loadFoldersOpenState() {
|
||||
void RSSImp::saveFoldersOpenState() {
|
||||
QStringList open_folders;
|
||||
QList<QTreeWidgetItem*> items = m_feedList->getAllOpenFolders();
|
||||
foreach(QTreeWidgetItem* item, items) {
|
||||
foreach (QTreeWidgetItem* item, items) {
|
||||
QString path = m_feedList->getItemPath(item).join("\\");
|
||||
qDebug("saving open folder: %s", qPrintable(path));
|
||||
open_folders << path;
|
||||
@@ -314,7 +314,7 @@ void RSSImp::saveFoldersOpenState() {
|
||||
|
||||
// refresh all streams by a button
|
||||
void RSSImp::on_updateAllButton_clicked() {
|
||||
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();
|
||||
@@ -322,10 +322,10 @@ void RSSImp::on_updateAllButton_clicked() {
|
||||
|
||||
void RSSImp::downloadTorrent() {
|
||||
QList<QListWidgetItem *> selected_items = listArticles->selectedItems();
|
||||
foreach(const QListWidgetItem* item, selected_items) {
|
||||
foreach (const QListWidgetItem* item, selected_items) {
|
||||
RssArticlePtr article = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
|
||||
->getItem(item->data(Article::IdRole).toString());
|
||||
if(article->hasAttachment()) {
|
||||
if (article->hasAttachment()) {
|
||||
QBtSession::instance()->downloadFromUrl(article->torrentUrl());
|
||||
} else {
|
||||
QBtSession::instance()->downloadFromUrl(article->link());
|
||||
@@ -336,11 +336,11 @@ void RSSImp::downloadTorrent() {
|
||||
// open the url of the news in a browser
|
||||
void RSSImp::openNewsUrl() {
|
||||
QList<QListWidgetItem *> selected_items = listArticles->selectedItems();
|
||||
foreach(const QListWidgetItem* item, selected_items) {
|
||||
foreach (const QListWidgetItem* item, selected_items) {
|
||||
RssArticlePtr news = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
|
||||
->getItem(item->data(Article::IdRole).toString());
|
||||
const QString link = news->link();
|
||||
if(!link.isEmpty())
|
||||
if (!link.isEmpty())
|
||||
QDesktopServices::openUrl(QUrl(link));
|
||||
}
|
||||
}
|
||||
@@ -356,8 +356,8 @@ void RSSImp::renameFiles() {
|
||||
do {
|
||||
newName = QInputDialog::getText(this, tr("Please choose a new name for this RSS feed"), tr("New feed name:"), QLineEdit::Normal, m_feedList->getRSSItem(item)->displayName(), &ok);
|
||||
// Check if name is already taken
|
||||
if(ok) {
|
||||
if(rss_item->parent()->hasChild(newName)) {
|
||||
if (ok) {
|
||||
if (rss_item->parent()->hasChild(newName)) {
|
||||
QMessageBox::warning(0, tr("Name already in use"), tr("This name is already used by another item, please choose another one."));
|
||||
ok = false;
|
||||
}
|
||||
@@ -374,11 +374,11 @@ void RSSImp::renameFiles() {
|
||||
//right-click on stream : refresh it
|
||||
void RSSImp::refreshSelectedItems() {
|
||||
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
|
||||
foreach(QTreeWidgetItem* item, selectedItems){
|
||||
foreach (QTreeWidgetItem* item, selectedItems){
|
||||
RssFilePtr file = m_feedList->getRSSItem(item);
|
||||
// Update icons
|
||||
if(item == m_feedList->stickyUnreadItem()) {
|
||||
foreach(QTreeWidgetItem *feed, m_feedList->getAllFeedItems()) {
|
||||
if (item == m_feedList->stickyUnreadItem()) {
|
||||
foreach (QTreeWidgetItem *feed, m_feedList->getAllFeedItems()) {
|
||||
feed->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
|
||||
}
|
||||
file->refresh();
|
||||
@@ -388,7 +388,7 @@ void RSSImp::refreshSelectedItems() {
|
||||
item->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
|
||||
} else if (qSharedPointerDynamicCast<RssFolder>(file)) {
|
||||
// Update feeds in the folder
|
||||
foreach(QTreeWidgetItem *feed, m_feedList->getAllFeedItems(item)) {
|
||||
foreach (QTreeWidgetItem *feed, m_feedList->getAllFeedItems(item)) {
|
||||
feed->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
|
||||
}
|
||||
}
|
||||
@@ -402,8 +402,8 @@ void RSSImp::copySelectedFeedsURL() {
|
||||
QStringList URLs;
|
||||
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
|
||||
QTreeWidgetItem* item;
|
||||
foreach(item, selectedItems){
|
||||
if(m_feedList->isFeed(item))
|
||||
foreach (item, selectedItems){
|
||||
if (m_feedList->isFeed(item))
|
||||
URLs << m_feedList->getItemID(item);
|
||||
}
|
||||
qApp->clipboard()->setText(URLs.join("\n"));
|
||||
@@ -412,25 +412,25 @@ void RSSImp::copySelectedFeedsURL() {
|
||||
void RSSImp::on_markReadButton_clicked() {
|
||||
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
|
||||
QTreeWidgetItem* item;
|
||||
foreach(item, selectedItems){
|
||||
foreach (item, selectedItems){
|
||||
RssFilePtr rss_item = m_feedList->getRSSItem(item);
|
||||
rss_item->markAsRead();
|
||||
updateItemInfos(item);
|
||||
}
|
||||
if(selectedItems.size())
|
||||
if (selectedItems.size())
|
||||
refreshArticleList(m_feedList->currentItem());
|
||||
}
|
||||
|
||||
void RSSImp::fillFeedsList(QTreeWidgetItem *parent, const RssFolderPtr& rss_parent) {
|
||||
QList<RssFilePtr> children;
|
||||
if(parent) {
|
||||
if (parent) {
|
||||
children = rss_parent->getContent();
|
||||
} else {
|
||||
children = m_rssManager->getContent();
|
||||
}
|
||||
foreach (const RssFilePtr& rss_child, children){
|
||||
QTreeWidgetItem* item;
|
||||
if(!parent)
|
||||
if (!parent)
|
||||
item = new QTreeWidgetItem(m_feedList);
|
||||
else
|
||||
item = new QTreeWidgetItem(parent);
|
||||
@@ -438,7 +438,7 @@ void RSSImp::fillFeedsList(QTreeWidgetItem *parent, const RssFolderPtr& rss_pare
|
||||
// Notify TreeWidget of item addition
|
||||
m_feedList->itemAdded(item, rss_child);
|
||||
// Set Icon
|
||||
if(qSharedPointerDynamicCast<RssFeed>(rss_child)) {
|
||||
if (qSharedPointerDynamicCast<RssFeed>(rss_child)) {
|
||||
item->setData(0,Qt::DecorationRole, QVariant(QIcon(QString::fromUtf8(":/Icons/loading.png"))));
|
||||
} else if (RssFolderPtr folder = qSharedPointerDynamicCast<RssFolder>(rss_child)) {
|
||||
item->setData(0,Qt::DecorationRole, QVariant(IconProvider::instance()->getIcon("inode-directory")));
|
||||
@@ -450,19 +450,19 @@ void RSSImp::fillFeedsList(QTreeWidgetItem *parent, const RssFolderPtr& rss_pare
|
||||
|
||||
// fills the newsList
|
||||
void RSSImp::refreshArticleList(QTreeWidgetItem* item) {
|
||||
if(!item) {
|
||||
if (!item) {
|
||||
listArticles->clear();
|
||||
return;
|
||||
}
|
||||
|
||||
RssFilePtr rss_item = m_feedList->getRSSItem(item);
|
||||
if(!rss_item) return;
|
||||
if (!rss_item) return;
|
||||
|
||||
qDebug("Getting the list of news");
|
||||
RssArticleList news;
|
||||
if(rss_item == m_rssManager)
|
||||
if (rss_item == m_rssManager)
|
||||
news = rss_item->unreadArticleList();
|
||||
else if(rss_item)
|
||||
else if (rss_item)
|
||||
news = rss_item->articleList();
|
||||
// Sort
|
||||
RssManager::sortNewsList(news);
|
||||
@@ -471,12 +471,12 @@ void RSSImp::refreshArticleList(QTreeWidgetItem* item) {
|
||||
m_currentArticle = 0;
|
||||
listArticles->clear();
|
||||
qDebug("Got the list of news");
|
||||
foreach(const RssArticlePtr &article, news){
|
||||
foreach (const RssArticlePtr &article, news){
|
||||
QListWidgetItem* it = new QListWidgetItem(listArticles);
|
||||
it->setData(Article::TitleRole, article->title());
|
||||
it->setData(Article::FeedUrlRole, article->parent()->url());
|
||||
it->setData(Article::IdRole, article->guid());
|
||||
if(article->isRead()){
|
||||
if (article->isRead()){
|
||||
it->setData(Article::ColorRole, QVariant(QColor("grey")));
|
||||
it->setData(Article::IconRole, QVariant(QIcon(":/Icons/sphere.png")));
|
||||
}else{
|
||||
@@ -491,14 +491,14 @@ void RSSImp::refreshArticleList(QTreeWidgetItem* item) {
|
||||
// display a news
|
||||
void RSSImp::refreshTextBrowser() {
|
||||
QList<QListWidgetItem*> selection = listArticles->selectedItems();
|
||||
if(selection.empty()) return;
|
||||
if (selection.empty()) return;
|
||||
Q_ASSERT(selection.size() == 1);
|
||||
QListWidgetItem *item = selection.first();
|
||||
Q_ASSERT(item);
|
||||
if(item == m_currentArticle) return;
|
||||
if (item == m_currentArticle) return;
|
||||
// Stop displaying previous news if necessary
|
||||
if(m_feedList->currentFeed() == m_feedList->stickyUnreadItem()) {
|
||||
if(m_currentArticle) {
|
||||
if (m_feedList->currentFeed() == m_feedList->stickyUnreadItem()) {
|
||||
if (m_currentArticle) {
|
||||
disconnect(listArticles, SIGNAL(itemSelectionChanged()), this, SLOT(refreshTextBrowser()));
|
||||
listArticles->removeItemWidget(m_currentArticle);
|
||||
Q_ASSERT(m_currentArticle);
|
||||
@@ -512,10 +512,10 @@ void RSSImp::refreshTextBrowser() {
|
||||
QString html;
|
||||
html += "<div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'>";
|
||||
html += "<div style='background-color: #678db2; font-weight: bold; color: #fff;'>"+article->title() + "</div>";
|
||||
if(article->date().isValid()) {
|
||||
if (article->date().isValid()) {
|
||||
html += "<div style='background-color: #efefef;'><b>"+tr("Date: ")+"</b>"+article->date().toLocalTime().toString(Qt::SystemLocaleLongDate)+"</div>";
|
||||
}
|
||||
if(!article->author().isEmpty()) {
|
||||
if (!article->author().isEmpty()) {
|
||||
html += "<div style='background-color: #efefef;'><b>"+tr("Author: ")+"</b>"+article->author()+"</div>";
|
||||
}
|
||||
html += "</div>";
|
||||
@@ -540,17 +540,17 @@ void RSSImp::saveSlidersPosition() {
|
||||
void RSSImp::restoreSlidersPosition() {
|
||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
||||
QByteArray pos_h = settings.value("rss/splitter_h", QByteArray()).toByteArray();
|
||||
if(!pos_h.isNull()) {
|
||||
if (!pos_h.isNull()) {
|
||||
splitter_h->restoreState(pos_h);
|
||||
}
|
||||
QByteArray pos_v = settings.value("rss/splitter_v", QByteArray()).toByteArray();
|
||||
if(!pos_v.isNull()) {
|
||||
if (!pos_v.isNull()) {
|
||||
splitter_v->restoreState(pos_v);
|
||||
}
|
||||
}
|
||||
|
||||
void RSSImp::updateItemsInfos(const QList<QTreeWidgetItem *> &items) {
|
||||
foreach(QTreeWidgetItem* item, items) {
|
||||
foreach (QTreeWidgetItem* item, items) {
|
||||
updateItemInfos(item);
|
||||
}
|
||||
}
|
||||
@@ -561,13 +561,13 @@ void RSSImp::updateItemInfos(QTreeWidgetItem *item) {
|
||||
return;
|
||||
|
||||
QString name;
|
||||
if(rss_item == m_rssManager)
|
||||
if (rss_item == m_rssManager)
|
||||
name = tr("Unread");
|
||||
else
|
||||
name = rss_item->displayName();
|
||||
item->setText(0, name + QString::fromUtf8(" (") + QString::number(rss_item->unreadCount(), 10)+ QString(")"));
|
||||
// If item has a parent, update it too
|
||||
if(item->parent())
|
||||
if (item->parent())
|
||||
updateItemInfos(item->parent());
|
||||
}
|
||||
|
||||
@@ -581,19 +581,19 @@ void RSSImp::updateFeedInfos(const QString &url, const QString &display_name, ui
|
||||
QTreeWidgetItem *item = m_feedList->getTreeItemFromUrl(url);
|
||||
RssFeedPtr stream = qSharedPointerCast<RssFeed>(m_feedList->getRSSItem(item));
|
||||
item->setText(0, display_name + QString::fromUtf8(" (") + QString::number(nbUnread, 10)+ QString(")"));
|
||||
if(!stream->isLoading())
|
||||
if (!stream->isLoading())
|
||||
item->setData(0,Qt::DecorationRole, QVariant(QIcon(stream->icon())));
|
||||
// Update parent
|
||||
if(item->parent())
|
||||
if (item->parent())
|
||||
updateItemInfos(item->parent());
|
||||
// Update Unread item
|
||||
updateItemInfos(m_feedList->stickyUnreadItem());
|
||||
// If the feed is selected, update the displayed news
|
||||
if(m_feedList->currentItem() == item ){
|
||||
if (m_feedList->currentItem() == item ){
|
||||
refreshArticleList(item);
|
||||
} else {
|
||||
// Update unread items
|
||||
if(m_feedList->currentItem() == m_feedList->stickyUnreadItem()) {
|
||||
if (m_feedList->currentItem() == m_feedList->stickyUnreadItem()) {
|
||||
refreshArticleList(m_feedList->stickyUnreadItem());
|
||||
}
|
||||
}
|
||||
@@ -680,7 +680,7 @@ RSSImp::~RSSImp(){
|
||||
|
||||
void RSSImp::on_settingsButton_clicked() {
|
||||
RssSettingsDlg dlg(this);
|
||||
if(dlg.exec())
|
||||
if (dlg.exec())
|
||||
updateRefreshInterval(RssSettings().getRSSRefreshInterval());
|
||||
}
|
||||
|
||||
@@ -688,6 +688,6 @@ void RSSImp::on_rssDownloaderBtn_clicked()
|
||||
{
|
||||
AutomatedRssDownloader dlg(m_rssManager, this);
|
||||
dlg.exec();
|
||||
if(dlg.isRssDownloaderEnabled())
|
||||
if (dlg.isRssDownloaderEnabled())
|
||||
on_updateAllButton_clicked();
|
||||
}
|
||||
|
||||
@@ -223,33 +223,33 @@ RssArticlePtr xmlToRssArticle(RssFeed* parent, QXmlStreamReader& xml)
|
||||
while(!xml.atEnd()) {
|
||||
xml.readNext();
|
||||
|
||||
if(xml.isEndElement() && xml.name() == "item")
|
||||
if (xml.isEndElement() && xml.name() == "item")
|
||||
break;
|
||||
|
||||
if(xml.isStartElement()) {
|
||||
if(xml.name() == "title") {
|
||||
if (xml.isStartElement()) {
|
||||
if (xml.name() == "title") {
|
||||
title = xml.readElementText();
|
||||
}
|
||||
else if(xml.name() == "enclosure") {
|
||||
if(xml.attributes().value("type") == "application/x-bittorrent") {
|
||||
else if (xml.name() == "enclosure") {
|
||||
if (xml.attributes().value("type") == "application/x-bittorrent") {
|
||||
torrentUrl = xml.attributes().value("url").toString();
|
||||
}
|
||||
}
|
||||
else if(xml.name() == "link") {
|
||||
else if (xml.name() == "link") {
|
||||
link = xml.readElementText();
|
||||
if(guid.isEmpty())
|
||||
if (guid.isEmpty())
|
||||
guid = link;
|
||||
}
|
||||
else if(xml.name() == "description") {
|
||||
else if (xml.name() == "description") {
|
||||
description = xml.readElementText();
|
||||
}
|
||||
else if(xml.name() == "pubDate") {
|
||||
else if (xml.name() == "pubDate") {
|
||||
date = RssArticle::parseDate(xml.readElementText());
|
||||
}
|
||||
else if(xml.name() == "author") {
|
||||
else if (xml.name() == "author") {
|
||||
author = xml.readElementText();
|
||||
}
|
||||
else if(xml.name() == "guid") {
|
||||
else if (xml.name() == "guid") {
|
||||
guid = xml.readElementText();
|
||||
}
|
||||
}
|
||||
@@ -271,7 +271,7 @@ RssArticlePtr xmlToRssArticle(RssFeed* parent, QXmlStreamReader& xml)
|
||||
|
||||
RssArticlePtr hashToRssArticle(RssFeed* parent, const QVariantHash &h) {
|
||||
const QString guid = h.value("id").toString();
|
||||
if(guid.isEmpty()) return RssArticlePtr();
|
||||
if (guid.isEmpty()) return RssArticlePtr();
|
||||
|
||||
RssArticlePtr art(new RssArticle(parent, guid));
|
||||
art->m_title = h.value("title", "").toString();
|
||||
@@ -302,7 +302,7 @@ QString RssArticle::link() const {
|
||||
}
|
||||
|
||||
QString RssArticle::description() const{
|
||||
if(m_description.isNull())
|
||||
if (m_description.isNull())
|
||||
return "";
|
||||
return m_description;
|
||||
}
|
||||
|
||||
@@ -43,26 +43,26 @@ RssDownloadRule::RssDownloadRule(): m_enabled(false), m_useRegex(false)
|
||||
|
||||
bool RssDownloadRule::matches(const QString &article_title) const
|
||||
{
|
||||
foreach(const QString& token, m_mustContain) {
|
||||
if(token.isEmpty() || token == "")
|
||||
foreach (const QString& token, m_mustContain) {
|
||||
if (token.isEmpty() || token == "")
|
||||
continue;
|
||||
QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard);
|
||||
//reg.setMinimal(false);
|
||||
if(reg.indexIn(article_title) < 0) return false;
|
||||
if (reg.indexIn(article_title) < 0) return false;
|
||||
}
|
||||
qDebug("Checking not matching tokens");
|
||||
// Checking not matching
|
||||
foreach(const QString& token, m_mustNotContain) {
|
||||
if(token.isEmpty()) continue;
|
||||
foreach (const QString& token, m_mustNotContain) {
|
||||
if (token.isEmpty()) continue;
|
||||
QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard);
|
||||
if(reg.indexIn(article_title) > -1) return false;
|
||||
if (reg.indexIn(article_title) > -1) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RssDownloadRule::setMustContain(const QString &tokens)
|
||||
{
|
||||
if(m_useRegex)
|
||||
if (m_useRegex)
|
||||
m_mustContain = QStringList() << tokens;
|
||||
else
|
||||
m_mustContain = tokens.split(" ");
|
||||
@@ -70,7 +70,7 @@ void RssDownloadRule::setMustContain(const QString &tokens)
|
||||
|
||||
void RssDownloadRule::setMustNotContain(const QString &tokens)
|
||||
{
|
||||
if(m_useRegex)
|
||||
if (m_useRegex)
|
||||
m_mustNotContain = QStringList() << tokens;
|
||||
else
|
||||
m_mustNotContain = tokens.split(QRegExp("[\\s|]"));
|
||||
@@ -83,7 +83,7 @@ RssDownloadRulePtr RssDownloadRule::fromOldFormat(const QVariantHash &rule_hash,
|
||||
rule->setName(rule_name);
|
||||
rule->setMustContain(rule_hash.value("matches", "").toString());
|
||||
rule->setMustNotContain(rule_hash.value("not", "").toString());
|
||||
if(!feed_url.isEmpty())
|
||||
if (!feed_url.isEmpty())
|
||||
rule->setRssFeeds(QStringList() << feed_url);
|
||||
rule->setSavePath(rule_hash.value("save_path", "").toString());
|
||||
// Is enabled?
|
||||
@@ -128,7 +128,7 @@ bool RssDownloadRule::operator==(const RssDownloadRule &other) {
|
||||
|
||||
void RssDownloadRule::setSavePath(const QString &save_path)
|
||||
{
|
||||
if(!save_path.isEmpty() && QDir(save_path) != QDir(Preferences().getSavePath()))
|
||||
if (!save_path.isEmpty() && QDir(save_path) != QDir(Preferences().getSavePath()))
|
||||
m_savePath = save_path;
|
||||
else
|
||||
m_savePath = QString();
|
||||
@@ -138,7 +138,7 @@ QStringList RssDownloadRule::findMatchingArticles(const RssFeedPtr& feed) const
|
||||
{
|
||||
QStringList ret;
|
||||
const RssArticleHash& feed_articles = feed->articleHash();
|
||||
for(RssArticleHash::ConstIterator artIt = feed_articles.begin(); artIt != feed_articles.end(); artIt++) {
|
||||
for (RssArticleHash::ConstIterator artIt = feed_articles.begin(); artIt != feed_articles.end(); artIt++) {
|
||||
const QString title = artIt.value()->title();
|
||||
if (matches(title))
|
||||
ret << title;
|
||||
|
||||
@@ -44,7 +44,7 @@ RssDownloadRuleList::RssDownloadRuleList(){
|
||||
|
||||
RssDownloadRuleList* RssDownloadRuleList::instance()
|
||||
{
|
||||
if(!m_instance)
|
||||
if (!m_instance)
|
||||
m_instance = new RssDownloadRuleList;
|
||||
return m_instance;
|
||||
}
|
||||
@@ -61,9 +61,9 @@ RssDownloadRulePtr RssDownloadRuleList::findMatchingRule(const QString &feed_url
|
||||
{
|
||||
Q_ASSERT(RssSettings().isRssDownloadingEnabled());
|
||||
QStringList rule_names = m_feedRules.value(feed_url);
|
||||
foreach(const QString &rule_name, rule_names) {
|
||||
foreach (const QString &rule_name, rule_names) {
|
||||
RssDownloadRulePtr rule = m_rules[rule_name];
|
||||
if(rule->isEnabled() && rule->matches(article_title)) return rule;
|
||||
if (rule->isEnabled() && rule->matches(article_title)) return rule;
|
||||
}
|
||||
return RssDownloadRulePtr();
|
||||
}
|
||||
@@ -77,7 +77,7 @@ void RssDownloadRuleList::saveRulesToStorage()
|
||||
void RssDownloadRuleList::loadRulesFromStorage()
|
||||
{
|
||||
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
|
||||
if(qBTRSS.contains("feed_filters")) {
|
||||
if (qBTRSS.contains("feed_filters")) {
|
||||
importFeedsInOldFormat(qBTRSS.value("feed_filters").toHash());
|
||||
// Remove outdated rules
|
||||
qBTRSS.remove("feed_filters");
|
||||
@@ -91,16 +91,16 @@ void RssDownloadRuleList::loadRulesFromStorage()
|
||||
|
||||
void RssDownloadRuleList::importFeedsInOldFormat(const QHash<QString, QVariant> &rules)
|
||||
{
|
||||
foreach(const QString &feed_url, rules.keys()) {
|
||||
foreach (const QString &feed_url, rules.keys()) {
|
||||
importFeedRulesInOldFormat(feed_url, rules.value(feed_url).toHash());
|
||||
}
|
||||
}
|
||||
|
||||
void RssDownloadRuleList::importFeedRulesInOldFormat(const QString &feed_url, const QHash<QString, QVariant> &rules)
|
||||
{
|
||||
foreach(const QString &rule_name, rules.keys()) {
|
||||
foreach (const QString &rule_name, rules.keys()) {
|
||||
RssDownloadRulePtr rule = RssDownloadRule::fromOldFormat(rules.value(rule_name).toHash(), feed_url, rule_name);
|
||||
if(!rule) continue;
|
||||
if (!rule) continue;
|
||||
// Check for rule name clash
|
||||
while(m_rules.contains(rule->name())) {
|
||||
rule->setName(rule->name()+"_");
|
||||
@@ -113,7 +113,7 @@ void RssDownloadRuleList::importFeedRulesInOldFormat(const QString &feed_url, co
|
||||
QVariantHash RssDownloadRuleList::toVariantHash() const
|
||||
{
|
||||
QVariantHash ret;
|
||||
foreach(const RssDownloadRulePtr &rule, m_rules.values()) {
|
||||
foreach (const RssDownloadRulePtr &rule, m_rules.values()) {
|
||||
ret.insert(rule->name(), rule->toVariantHash());
|
||||
}
|
||||
return ret;
|
||||
@@ -121,9 +121,9 @@ QVariantHash RssDownloadRuleList::toVariantHash() const
|
||||
|
||||
void RssDownloadRuleList::loadRulesFromVariantHash(const QVariantHash &h)
|
||||
{
|
||||
foreach(const QVariant& v, h.values()) {
|
||||
foreach (const QVariant& v, h.values()) {
|
||||
RssDownloadRulePtr rule = RssDownloadRule::fromNewFormat(v.toHash());
|
||||
if(rule && !rule->name().isEmpty()) {
|
||||
if (rule && !rule->name().isEmpty()) {
|
||||
saveRule(rule);
|
||||
}
|
||||
}
|
||||
@@ -133,13 +133,13 @@ void RssDownloadRuleList::saveRule(const RssDownloadRulePtr &rule)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << rule->name();
|
||||
Q_ASSERT(rule);
|
||||
if(m_rules.contains(rule->name())) {
|
||||
if (m_rules.contains(rule->name())) {
|
||||
qDebug("This is an update, removing old rule first");
|
||||
removeRule(rule->name());
|
||||
}
|
||||
m_rules.insert(rule->name(), rule);
|
||||
// Update feedRules hashtable
|
||||
foreach(const QString &feed_url, rule->rssFeeds()) {
|
||||
foreach (const QString &feed_url, rule->rssFeeds()) {
|
||||
m_feedRules[feed_url].append(rule->name());
|
||||
}
|
||||
// Save rules
|
||||
@@ -150,10 +150,10 @@ void RssDownloadRuleList::saveRule(const RssDownloadRulePtr &rule)
|
||||
void RssDownloadRuleList::removeRule(const QString &name)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << name;
|
||||
if(!m_rules.contains(name)) return;
|
||||
if (!m_rules.contains(name)) return;
|
||||
RssDownloadRulePtr rule = m_rules.take(name);
|
||||
// Update feedRules hashtable
|
||||
foreach(const QString &feed_url, rule->rssFeeds()) {
|
||||
foreach (const QString &feed_url, rule->rssFeeds()) {
|
||||
m_feedRules[feed_url].removeOne(rule->name());
|
||||
}
|
||||
// Save rules
|
||||
@@ -162,12 +162,12 @@ void RssDownloadRuleList::removeRule(const QString &name)
|
||||
|
||||
void RssDownloadRuleList::renameRule(const QString &old_name, const QString &new_name)
|
||||
{
|
||||
if(!m_rules.contains(old_name)) return;
|
||||
if (!m_rules.contains(old_name)) return;
|
||||
RssDownloadRulePtr rule = m_rules.take(old_name);
|
||||
rule->setName(new_name);
|
||||
m_rules.insert(new_name, rule);
|
||||
// Update feedRules hashtable
|
||||
foreach(const QString &feed_url, rule->rssFeeds()) {
|
||||
foreach (const QString &feed_url, rule->rssFeeds()) {
|
||||
m_feedRules[feed_url].replace(m_feedRules[feed_url].indexOf(old_name), new_name);
|
||||
}
|
||||
// Save rules
|
||||
@@ -182,7 +182,7 @@ RssDownloadRulePtr RssDownloadRuleList::getRule(const QString &name) const
|
||||
bool RssDownloadRuleList::serialize(const QString& path)
|
||||
{
|
||||
QFile f(path);
|
||||
if(f.open(QIODevice::WriteOnly)) {
|
||||
if (f.open(QIODevice::WriteOnly)) {
|
||||
QDataStream out(&f);
|
||||
out.setVersion(QDataStream::Qt_4_5);
|
||||
out << toVariantHash();
|
||||
@@ -196,16 +196,16 @@ bool RssDownloadRuleList::serialize(const QString& path)
|
||||
bool RssDownloadRuleList::unserialize(const QString &path)
|
||||
{
|
||||
QFile f(path);
|
||||
if(f.open(QIODevice::ReadOnly)) {
|
||||
if (f.open(QIODevice::ReadOnly)) {
|
||||
QDataStream in(&f);
|
||||
if(path.endsWith(".filters", Qt::CaseInsensitive)) {
|
||||
if (path.endsWith(".filters", Qt::CaseInsensitive)) {
|
||||
// Old format (< 2.5.0)
|
||||
qDebug("Old serialization format detected, processing...");
|
||||
in.setVersion(QDataStream::Qt_4_3);
|
||||
QVariantHash tmp;
|
||||
in >> tmp;
|
||||
f.close();
|
||||
if(tmp.isEmpty()) return false;
|
||||
if (tmp.isEmpty()) return false;
|
||||
qDebug("Processing was successful!");
|
||||
// Unfortunately the feed_url is lost
|
||||
importFeedRulesInOldFormat("", tmp);
|
||||
@@ -215,7 +215,7 @@ bool RssDownloadRuleList::unserialize(const QString &path)
|
||||
QVariantHash tmp;
|
||||
in >> tmp;
|
||||
f.close();
|
||||
if(tmp.isEmpty()) return false;
|
||||
if (tmp.isEmpty()) return false;
|
||||
qDebug("Processing was successful!");
|
||||
loadRulesFromVariantHash(tmp);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ RssFeed::RssFeed(RssManager* manager, RssFolder* parent, const QString &url):
|
||||
}
|
||||
|
||||
RssFeed::~RssFeed(){
|
||||
if(!m_icon.startsWith(":/") && QFile::exists(m_icon))
|
||||
if (!m_icon.startsWith(":/") && QFile::exists(m_icon))
|
||||
QFile::remove(m_icon);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ void RssFeed::loadItemsFromDisk() {
|
||||
}
|
||||
|
||||
void RssFeed::refresh() {
|
||||
if(m_loading) {
|
||||
if (m_loading) {
|
||||
qWarning() << Q_FUNC_INFO << "Feed" << this->displayName() << "is already being refreshed, ignoring request";
|
||||
return;
|
||||
}
|
||||
@@ -143,11 +143,11 @@ void RssFeed::rename(const QString &new_name){
|
||||
|
||||
// Return the alias if the stream has one, the url if it has no alias
|
||||
QString RssFeed::displayName() const {
|
||||
if(!m_alias.isEmpty()) {
|
||||
if (!m_alias.isEmpty()) {
|
||||
//qDebug("getName() returned alias: %s", (const char*)alias.toLocal8Bit());
|
||||
return m_alias;
|
||||
}
|
||||
if(!m_title.isEmpty()) {
|
||||
if (!m_title.isEmpty()) {
|
||||
//qDebug("getName() returned title: %s", (const char*)title.toLocal8Bit());
|
||||
return m_title;
|
||||
}
|
||||
@@ -160,7 +160,7 @@ QString RssFeed::url() const{
|
||||
}
|
||||
|
||||
QString RssFeed::icon() const{
|
||||
if(m_downloadFailure)
|
||||
if (m_downloadFailure)
|
||||
return ":/Icons/oxygen/unavailable.png";
|
||||
return m_icon;
|
||||
}
|
||||
@@ -170,7 +170,7 @@ bool RssFeed::hasCustomIcon() const{
|
||||
}
|
||||
|
||||
void RssFeed::setIconPath(const QString &path) {
|
||||
if(path.isEmpty() || !QFile::exists(path)) return;
|
||||
if (path.isEmpty() || !QFile::exists(path)) return;
|
||||
m_icon = path;
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ void RssFeed::markAsRead() {
|
||||
uint RssFeed::unreadCount() const{
|
||||
uint nbUnread = 0;
|
||||
for (RssArticleHash::ConstIterator it=m_articles.begin(); it != m_articles.end(); it++) {
|
||||
if(!it.value()->isRead())
|
||||
if (!it.value()->isRead())
|
||||
++nbUnread;
|
||||
}
|
||||
return nbUnread;
|
||||
@@ -205,7 +205,7 @@ RssArticleList RssFeed::articleList() const{
|
||||
RssArticleList RssFeed::unreadArticleList() const {
|
||||
RssArticleList unread_news;
|
||||
for (RssArticleHash::ConstIterator it = m_articles.begin(); it != m_articles.end(); it++) {
|
||||
if(!it.value()->isRead())
|
||||
if (!it.value()->isRead())
|
||||
unread_news << it.value();
|
||||
}
|
||||
return unread_news;
|
||||
@@ -229,8 +229,8 @@ bool RssFeed::parseRSS(QIODevice* device) {
|
||||
}
|
||||
while (!xml.atEnd()) {
|
||||
xml.readNext();
|
||||
if(xml.isStartElement()) {
|
||||
if(xml.name() != "rss") {
|
||||
if (xml.isStartElement()) {
|
||||
if (xml.name() != "rss") {
|
||||
qDebug("ERROR: this is not a rss file, root tag is <%s>", qPrintable(xml.name().toString()));
|
||||
return false;
|
||||
} else {
|
||||
@@ -242,37 +242,37 @@ bool RssFeed::parseRSS(QIODevice* device) {
|
||||
while(!xml.atEnd()) {
|
||||
xml.readNext();
|
||||
|
||||
if(!xml.isStartElement())
|
||||
if (!xml.isStartElement())
|
||||
continue;
|
||||
|
||||
if(xml.name() != "channel")
|
||||
if (xml.name() != "channel")
|
||||
continue;
|
||||
|
||||
// Parse channel content
|
||||
while(!xml.atEnd()) {
|
||||
xml.readNext();
|
||||
|
||||
if(xml.isEndElement() && xml.name() == "channel")
|
||||
if (xml.isEndElement() && xml.name() == "channel")
|
||||
break; // End of this channel, parse the next one
|
||||
|
||||
if(!xml.isStartElement())
|
||||
if (!xml.isStartElement())
|
||||
continue;
|
||||
|
||||
if(xml.name() == "title") {
|
||||
if (xml.name() == "title") {
|
||||
m_title = xml.readElementText();
|
||||
if(m_alias == url())
|
||||
if (m_alias == url())
|
||||
rename(m_title);
|
||||
}
|
||||
else if(xml.name() == "image") {
|
||||
else if (xml.name() == "image") {
|
||||
QString icon_path = xml.attributes().value("url").toString();
|
||||
if(!icon_path.isEmpty()) {
|
||||
if (!icon_path.isEmpty()) {
|
||||
m_iconUrl = icon_path;
|
||||
m_manager->rssDownloader()->downloadUrl(m_iconUrl);
|
||||
}
|
||||
}
|
||||
else if(xml.name() == "item") {
|
||||
else if (xml.name() == "item") {
|
||||
RssArticlePtr art = xmlToRssArticle(this, xml);
|
||||
if(art && !itemAlreadyExists(art->guid()))
|
||||
if (art && !itemAlreadyExists(art->guid()))
|
||||
m_articles.insert(art->guid(), art);
|
||||
}
|
||||
}
|
||||
@@ -282,7 +282,7 @@ bool RssFeed::parseRSS(QIODevice* device) {
|
||||
resizeList();
|
||||
|
||||
// RSS Feed Downloader
|
||||
if(RssSettings().isRssDownloadingEnabled())
|
||||
if (RssSettings().isRssDownloadingEnabled())
|
||||
downloadMatchingArticleTorrents();
|
||||
|
||||
// Save items to disk (for safety)
|
||||
@@ -295,15 +295,15 @@ void RssFeed::downloadMatchingArticleTorrents() {
|
||||
Q_ASSERT(RssSettings().isRssDownloadingEnabled());
|
||||
for (RssArticleHash::ConstIterator it = m_articles.begin(); it != m_articles.end(); it++) {
|
||||
RssArticlePtr item = it.value();
|
||||
if(item->isRead()) continue;
|
||||
if (item->isRead()) continue;
|
||||
QString torrent_url;
|
||||
if(item->hasAttachment())
|
||||
if (item->hasAttachment())
|
||||
torrent_url = item->torrentUrl();
|
||||
else
|
||||
torrent_url = item->link();
|
||||
// Check if the item should be automatically downloaded
|
||||
RssDownloadRulePtr matching_rule = RssDownloadRuleList::instance()->findMatchingRule(m_url, item->title());
|
||||
if(matching_rule) {
|
||||
if (matching_rule) {
|
||||
// Item was downloaded, consider it as Read
|
||||
item->markAsRead();
|
||||
// Download the torrent
|
||||
@@ -316,11 +316,11 @@ void RssFeed::downloadMatchingArticleTorrents() {
|
||||
void RssFeed::resizeList() {
|
||||
const uint max_articles = RssSettings().getRSSMaxArticlesPerFeed();
|
||||
const uint nb_articles = m_articles.size();
|
||||
if(nb_articles > max_articles) {
|
||||
if (nb_articles > max_articles) {
|
||||
RssArticleList listItems = m_articles.values();
|
||||
RssManager::sortNewsList(listItems);
|
||||
const int excess = nb_articles - max_articles;
|
||||
for(uint i=nb_articles-excess; i<nb_articles; ++i){
|
||||
for (uint i=nb_articles-excess; i<nb_articles; ++i){
|
||||
m_articles.remove(listItems.at(i)->guid());
|
||||
}
|
||||
}
|
||||
@@ -330,9 +330,9 @@ void RssFeed::resizeList() {
|
||||
bool RssFeed::parseXmlFile(const QString &file_path){
|
||||
qDebug("openRss() called");
|
||||
QFile fileRss(file_path);
|
||||
if(!fileRss.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
if (!fileRss.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qDebug("openRss error: open failed, no file or locked, %s", qPrintable(file_path));
|
||||
if(QFile::exists(file_path)) {
|
||||
if (QFile::exists(file_path)) {
|
||||
fileRss.remove();
|
||||
}
|
||||
return false;
|
||||
@@ -341,25 +341,25 @@ bool RssFeed::parseXmlFile(const QString &file_path){
|
||||
// start reading the xml
|
||||
bool ret = parseRSS(&fileRss);
|
||||
fileRss.close();
|
||||
if(QFile::exists(file_path))
|
||||
if (QFile::exists(file_path))
|
||||
fileRss.remove();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// read and store the downloaded rss' informations
|
||||
void RssFeed::handleFinishedDownload(const QString& url, const QString &file_path) {
|
||||
if(url == m_url) {
|
||||
if (url == m_url) {
|
||||
qDebug() << Q_FUNC_INFO << "Successfuly downloaded RSS feed at" << url;
|
||||
m_downloadFailure = false;
|
||||
m_loading = false;
|
||||
// Parse the download RSS
|
||||
if(parseXmlFile(file_path)) {
|
||||
if (parseXmlFile(file_path)) {
|
||||
m_refreshed = true;
|
||||
m_manager->forwardFeedInfosChanged(m_url, displayName(), unreadCount()); // XXX: Ugly
|
||||
qDebug() << Q_FUNC_INFO << "Feed parsed successfuly";
|
||||
}
|
||||
}
|
||||
else if(url == m_iconUrl) {
|
||||
else if (url == m_iconUrl) {
|
||||
m_icon = file_path;
|
||||
qDebug() << Q_FUNC_INFO << "icon path:" << m_icon;
|
||||
m_manager->forwardFeedIconChanged(m_url, m_icon); // XXX: Ugly
|
||||
@@ -367,7 +367,7 @@ void RssFeed::handleFinishedDownload(const QString& url, const QString &file_pat
|
||||
}
|
||||
|
||||
void RssFeed::handleDownloadFailure(const QString &url, const QString& error) {
|
||||
if(url != m_url) return;
|
||||
if (url != m_url) return;
|
||||
m_downloadFailure = true;
|
||||
m_loading = false;
|
||||
m_manager->forwardFeedInfosChanged(m_url, displayName(), unreadCount()); // XXX: Ugly
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
QStringList RssFile::pathHierarchy() const {
|
||||
QStringList path;
|
||||
if(parent())
|
||||
if (parent())
|
||||
path << parent()->pathHierarchy();
|
||||
path << id();
|
||||
return path;
|
||||
|
||||
@@ -186,7 +186,7 @@ void RssFolder::removeAllSettings() {
|
||||
|
||||
void RssFolder::saveItemsToDisk()
|
||||
{
|
||||
foreach(const RssFilePtr& child, m_children.values()) {
|
||||
foreach (const RssFilePtr& child, m_children.values()) {
|
||||
child->saveItemsToDisk();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ RssManager::~RssManager(){
|
||||
}
|
||||
|
||||
void RssManager::updateRefreshInterval(uint val){
|
||||
if(m_refreshInterval != val) {
|
||||
if (m_refreshInterval != val) {
|
||||
m_refreshInterval = val;
|
||||
m_refreshTimer.start(m_refreshInterval*60000);
|
||||
qDebug("New RSS refresh interval is now every %dmin", m_refreshInterval);
|
||||
@@ -65,20 +65,20 @@ void RssManager::loadStreamList() {
|
||||
RssSettings settings;
|
||||
const QStringList streamsUrl = settings.getRssFeedsUrls();
|
||||
const QStringList aliases = settings.getRssFeedsAliases();
|
||||
if(streamsUrl.size() != aliases.size()){
|
||||
if (streamsUrl.size() != aliases.size()){
|
||||
std::cerr << "Corrupted Rss list, not loading it\n";
|
||||
return;
|
||||
}
|
||||
uint i = 0;
|
||||
qDebug() << Q_FUNC_INFO << streamsUrl;
|
||||
foreach(QString s, streamsUrl){
|
||||
foreach (QString s, streamsUrl){
|
||||
QStringList path = s.split("\\", QString::SkipEmptyParts);
|
||||
if(path.empty()) continue;
|
||||
if (path.empty()) continue;
|
||||
const QString feed_url = path.takeLast();
|
||||
qDebug() << "Feed URL:" << feed_url;
|
||||
// Create feed path (if it does not exists)
|
||||
RssFolder* feed_parent = this;
|
||||
foreach(const QString &folder_name, path) {
|
||||
foreach (const QString &folder_name, path) {
|
||||
qDebug() << "Adding parent folder:" << folder_name;
|
||||
feed_parent = feed_parent->addFolder(folder_name).data();
|
||||
}
|
||||
@@ -86,7 +86,7 @@ void RssManager::loadStreamList() {
|
||||
qDebug() << "Adding feed to parent folder";
|
||||
RssFeedPtr stream = feed_parent->addStream(this, feed_url);
|
||||
const QString alias = aliases.at(i);
|
||||
if(!alias.isEmpty()) {
|
||||
if (!alias.isEmpty()) {
|
||||
stream->rename(alias);
|
||||
}
|
||||
++i;
|
||||
@@ -104,7 +104,7 @@ void RssManager::forwardFeedIconChanged(const QString &url, const QString &icon_
|
||||
|
||||
void RssManager::moveFile(const RssFilePtr& file, const RssFolderPtr& dest_folder) {
|
||||
RssFolder* src_folder = file->parent();
|
||||
if(dest_folder != src_folder) {
|
||||
if (dest_folder != src_folder) {
|
||||
// Remove reference in old folder
|
||||
src_folder->takeChild(file->id());
|
||||
// add to new Folder
|
||||
@@ -118,9 +118,9 @@ void RssManager::saveStreamList() const {
|
||||
QStringList streamsUrl;
|
||||
QStringList aliases;
|
||||
QList<RssFeedPtr> streams = getAllFeeds();
|
||||
foreach(const RssFeedPtr& stream, streams) {
|
||||
foreach (const RssFeedPtr& stream, streams) {
|
||||
QString stream_path = stream->pathHierarchy().join("\\");
|
||||
if(stream_path.isNull()) {
|
||||
if (stream_path.isNull()) {
|
||||
stream_path = "";
|
||||
}
|
||||
qDebug("Saving stream path: %s", qPrintable(stream_path));
|
||||
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
|
||||
QList<QByteArray> getHostNameCookies(const QString &host_name) const {
|
||||
QMap<QString, QVariant> hosts_table = value("Rss/hosts_cookies").toMap();
|
||||
if(!hosts_table.contains(host_name)) return QList<QByteArray>();
|
||||
if (!hosts_table.contains(host_name)) return QList<QByteArray>();
|
||||
QByteArray raw_cookies = hosts_table.value(host_name).toByteArray();
|
||||
return raw_cookies.split(':');
|
||||
}
|
||||
@@ -97,10 +97,10 @@ public:
|
||||
void setHostNameCookies(const QString &host_name, const QList<QByteArray> &cookies) {
|
||||
QMap<QString, QVariant> hosts_table = value("Rss/hosts_cookies").toMap();
|
||||
QByteArray raw_cookies = "";
|
||||
foreach(const QByteArray& cookie, cookies) {
|
||||
foreach (const QByteArray& cookie, cookies) {
|
||||
raw_cookies += cookie + ":";
|
||||
}
|
||||
if(raw_cookies.endsWith(":"))
|
||||
if (raw_cookies.endsWith(":"))
|
||||
raw_cookies.chop(1);
|
||||
hosts_table.insert(host_name, raw_cookies);
|
||||
setValue("Rss/hosts_cookies", hosts_table);
|
||||
|
||||
Reference in New Issue
Block a user