Follow project coding style. Issue #2192.

This commit is contained in:
sledgehammer999 2014-12-07 12:11:18 +02:00
commit 96ec6777e6
4 changed files with 673 additions and 670 deletions

View file

@ -64,7 +64,8 @@ void HtmlBrowser::resourceLoaded(QNetworkReply *reply)
if(reply->error() == QNetworkReply::NoError && reply->size() > 0) { if(reply->error() == QNetworkReply::NoError && reply->size() > 0) {
qDebug() << "HtmlBrowser::resourceLoaded() save " << reply->request().url().toString(); qDebug() << "HtmlBrowser::resourceLoaded() save " << reply->request().url().toString();
} else { }
else {
// If resource failed to load, replace it with warning icon and store it in cache for 1 day. // If resource failed to load, replace it with warning icon and store it in cache for 1 day.
// Otherwise HTMLBrowser will keep trying to download it every time article is displayed, // Otherwise HTMLBrowser will keep trying to download it every time article is displayed,
// since it's not possible to cache error responses. // since it's not possible to cache error responses.

View file

@ -8,7 +8,7 @@ class QNetworkAccessManager;
class QNetworkDiskCache; class QNetworkDiskCache;
class QNetworkReply; class QNetworkReply;
class HtmlBrowser : public QTextBrowser class HtmlBrowser: public QTextBrowser
{ {
Q_OBJECT Q_OBJECT

View file

@ -52,23 +52,24 @@
#include "iconprovider.h" #include "iconprovider.h"
#include "autoexpandabledialog.h" #include "autoexpandabledialog.h"
namespace Article { namespace Article
enum ArticleRoles { {
enum ArticleRoles
{
TitleRole = Qt::DisplayRole, TitleRole = Qt::DisplayRole,
IconRole = Qt::DecorationRole, IconRole = Qt::DecorationRole,
ColorRole = Qt::ForegroundRole, ColorRole = Qt::ForegroundRole,
IdRole = Qt::UserRole + 1, IdRole = Qt::UserRole + 1,
FeedUrlRole = Qt::UserRole + 2 FeedUrlRole = Qt::UserRole + 2
}; };
} }
// display a right-click menu // display a right-click menu
void RSSImp::displayRSSListMenu(const QPoint& pos) 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 // No item under the mouse, clear selection
m_feedList->clearSelection(); m_feedList->clearSelection();
}
QMenu myRSSListMenu(this); QMenu myRSSListMenu(this);
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems(); QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
if (selectedItems.size() > 0) { if (selectedItems.size() > 0) {
@ -80,13 +81,12 @@ void RSSImp::displayRSSListMenu(const QPoint& pos)
myRSSListMenu.addAction(actionRename); myRSSListMenu.addAction(actionRename);
myRSSListMenu.addAction(actionDelete); myRSSListMenu.addAction(actionDelete);
myRSSListMenu.addSeparator(); myRSSListMenu.addSeparator();
if (m_feedList->isFolder(selectedItems.first())) { if (m_feedList->isFolder(selectedItems.first()))
myRSSListMenu.addAction(actionNew_folder); myRSSListMenu.addAction(actionNew_folder);
} else { else
myRSSListMenu.addAction(actionManage_cookies); myRSSListMenu.addAction(actionManage_cookies);
} }
} }
}
else { else {
myRSSListMenu.addAction(actionDelete); myRSSListMenu.addAction(actionDelete);
myRSSListMenu.addSeparator(); myRSSListMenu.addSeparator();
@ -96,7 +96,8 @@ void RSSImp::displayRSSListMenu(const QPoint& pos)
myRSSListMenu.addSeparator(); myRSSListMenu.addSeparator();
myRSSListMenu.addAction(actionCopy_feed_URL); myRSSListMenu.addAction(actionCopy_feed_URL);
} }
}else{ }
else {
myRSSListMenu.addAction(actionNew_subscription); myRSSListMenu.addAction(actionNew_subscription);
myRSSListMenu.addAction(actionNew_folder); myRSSListMenu.addAction(actionNew_folder);
myRSSListMenu.addSeparator(); myRSSListMenu.addSeparator();
@ -150,7 +151,8 @@ void RSSImp::askNewFolder()
parent_item = m_feedList->selectedItems().at(0); parent_item = m_feedList->selectedItems().at(0);
rss_parent = qSharedPointerDynamicCast<RssFolder>(m_feedList->getRSSItem(parent_item)); rss_parent = qSharedPointerDynamicCast<RssFolder>(m_feedList->getRSSItem(parent_item));
Q_ASSERT(rss_parent); Q_ASSERT(rss_parent);
} else { }
else {
rss_parent = m_rssManager; rss_parent = m_rssManager;
} }
bool ok; bool ok;
@ -181,19 +183,17 @@ void RSSImp::on_newFeedButton_clicked()
if (!selected_items.empty()) { if (!selected_items.empty()) {
parent_item = selected_items.first(); parent_item = selected_items.first();
// Consider the case where the user clicked on Unread item // 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; parent_item = 0;
} else { else
if (!m_feedList->isFolder(parent_item)) if (!m_feedList->isFolder(parent_item))
parent_item = parent_item->parent(); parent_item = parent_item->parent();
} }
}
RssFolderPtr rss_parent; RssFolderPtr rss_parent;
if (parent_item) { if (parent_item)
rss_parent = qSharedPointerCast<RssFolder>(m_feedList->getRSSItem(parent_item)); rss_parent = qSharedPointerCast<RssFolder>(m_feedList->getRSSItem(parent_item));
} else { else
rss_parent = m_rssManager; rss_parent = m_rssManager;
}
// Ask for feed URL // Ask for feed URL
bool ok; bool ok;
QString clip_txt = qApp->clipboard()->text(); QString clip_txt = qApp->clipboard()->text();
@ -237,10 +237,11 @@ void RSSImp::deleteSelectedItems()
return; return;
int ret; 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?"), 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"), tr("&Yes"), tr("&No"),
QString(), 0, 1); QString(), 0, 1);
}
else { else {
if (selectedItems.first() == m_feedList->stickyUnreadItem()) if (selectedItems.first() == m_feedList->stickyUnreadItem())
return; return;
@ -342,8 +343,9 @@ void RSSImp::downloadSelectedTorrents()
QString torrentLink = article->torrentUrl(); QString torrentLink = article->torrentUrl();
// Check if it is a magnet link // Check if it is a magnet link
if (torrentLink.startsWith("magnet:", Qt::CaseInsensitive)) if (torrentLink.startsWith("magnet:", Qt::CaseInsensitive)) {
QBtSession::instance()->addMagnetInteractive(torrentLink); QBtSession::instance()->addMagnetInteractive(torrentLink);
}
else { else {
// Load possible cookies // Load possible cookies
QString feed_url = m_feedList->getItemID(m_feedList->selectedItems().first()); QString feed_url = m_feedList->getItemID(m_feedList->selectedItems().first());
@ -388,7 +390,8 @@ void RSSImp::renameSelectedRssFile()
QMessageBox::warning(0, tr("Name already in use"), tr("This name is already used by another item, please choose another one.")); QMessageBox::warning(0, tr("Name already in use"), tr("This name is already used by another item, please choose another one."));
ok = false; ok = false;
} }
} else { }
else {
return; return;
} }
} while (!ok); } while (!ok);
@ -408,13 +411,15 @@ void RSSImp::refreshSelectedItems()
if (item == m_feedList->stickyUnreadItem()) { if (item == m_feedList->stickyUnreadItem()) {
refreshAllFeeds(); refreshAllFeeds();
return; return;
} else { }
else {
if (!file->refresh()) if (!file->refresh())
continue; continue;
// Update UI // Update UI
if (qSharedPointerDynamicCast<RssFeed>(file)) { if (qSharedPointerDynamicCast<RssFeed>(file)) {
item->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png"))); item->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
} else if (qSharedPointerDynamicCast<RssFolder>(file)) { }
else if (qSharedPointerDynamicCast<RssFolder>(file)) {
// Update feeds in the folder // 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"))); feed->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
@ -428,10 +433,9 @@ void RSSImp::copySelectedFeedsURL()
QStringList URLs; QStringList URLs;
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems(); QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
QTreeWidgetItem* item; QTreeWidgetItem* item;
foreach (item, selectedItems) { foreach (item, selectedItems)
if (m_feedList->isFeed(item)) if (m_feedList->isFeed(item))
URLs << m_feedList->getItemID(item); URLs << m_feedList->getItemID(item);
}
qApp->clipboard()->setText(URLs.join("\n")); qApp->clipboard()->setText(URLs.join("\n"));
} }
@ -453,7 +457,7 @@ QTreeWidgetItem* RSSImp::createFolderListItem(const RssFilePtr& rssFile)
{ {
Q_ASSERT(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::DisplayRole, QVariant(rssFile->displayName() + QString::fromUtf8(" (") + QString::number(rssFile->unreadCount()) + QString(")")));
item->setData(0, Qt::DecorationRole, rssFile->icon()); item->setData(0, Qt::DecorationRole, rssFile->icon());
return item; return item;
@ -462,11 +466,10 @@ QTreeWidgetItem* RSSImp::createFolderListItem(const RssFilePtr& rssFile)
void RSSImp::fillFeedsList(QTreeWidgetItem* parent, const RssFolderPtr& rss_parent) void RSSImp::fillFeedsList(QTreeWidgetItem* parent, const RssFolderPtr& rss_parent)
{ {
QList<RssFilePtr> children; QList<RssFilePtr> children;
if (parent) { if (parent)
children = rss_parent->getContent(); children = rss_parent->getContent();
} else { else
children = m_rssManager->getContent(); children = m_rssManager->getContent();
}
foreach (const RssFilePtr& rssFile, children) { foreach (const RssFilePtr& rssFile, children) {
QTreeWidgetItem* item = createFolderListItem(rssFile); QTreeWidgetItem* item = createFolderListItem(rssFile);
Q_ASSERT(item); Q_ASSERT(item);
@ -495,7 +498,8 @@ QListWidgetItem* RSSImp::createArticleListItem(const RssArticlePtr& article)
if (article->isRead()) { if (article->isRead()) {
item->setData(Article::ColorRole, QVariant(QColor("grey"))); item->setData(Article::ColorRole, QVariant(QColor("grey")));
item->setData(Article::IconRole, QVariant(QIcon(":/Icons/sphere.png"))); item->setData(Article::IconRole, QVariant(QIcon(":/Icons/sphere.png")));
} else { }
else {
item->setData(Article::ColorRole, QVariant(QColor("blue"))); item->setData(Article::ColorRole, QVariant(QColor("blue")));
item->setData(Article::IconRole, QVariant(QIcon(":/Icons/sphere2.png"))); item->setData(Article::IconRole, QVariant(QIcon(":/Icons/sphere2.png")));
} }
@ -559,18 +563,17 @@ void RSSImp::refreshTextBrowser()
RssArticlePtr article = stream->getItem(item->data(Article::IdRole).toString()); RssArticlePtr article = stream->getItem(item->data(Article::IdRole).toString());
QString html; QString html;
html += "<div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'>"; 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>"; 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>"; 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 style='background-color: #efefef;'><b>"+tr("Author: ")+"</b>"+article->author()+"</div>";
}
html += "</div>"; html += "</div>";
html += "<div style='margin-left: 5px; margin-right: 5px;'>"; html += "<div style='margin-left: 5px; margin-right: 5px;'>";
if(Qt::mightBeRichText(article->description())) { if(Qt::mightBeRichText(article->description())) {
html += article->description(); html += article->description();
} else { }
else {
QString description = article->description(); QString description = article->description();
QRegExp rx; QRegExp rx;
// If description is plain text, replace BBCode tags with HTML and wrap everything in <pre></pre> so it looks nice // If description is plain text, replace BBCode tags with HTML and wrap everything in <pre></pre> so it looks nice
@ -620,13 +623,11 @@ void RSSImp::restoreSlidersPosition()
{ {
const Preferences* const pref = Preferences::instance(); const Preferences* const pref = Preferences::instance();
QByteArray pos_h = pref->getRssHSplitterState(); QByteArray pos_h = pref->getRssHSplitterState();
if (!pos_h.isNull()) { if (!pos_h.isNull())
splitter_h->restoreState(pos_h); splitter_h->restoreState(pos_h);
}
QByteArray pos_v = pref->getRssVSplitterState(); QByteArray pos_v = pref->getRssVSplitterState();
if (!pos_v.isNull()) { if (!pos_v.isNull())
splitter_v->restoreState(pos_v); splitter_v->restoreState(pos_v);
}
} }
void RSSImp::updateItemsInfos(const QList<QTreeWidgetItem*>& items) void RSSImp::updateItemsInfos(const QList<QTreeWidgetItem*>& items)
@ -646,7 +647,7 @@ void RSSImp::updateItemInfos(QTreeWidgetItem *item)
name = tr("Unread"); name = tr("Unread");
else else
name = rss_item->displayName(); name = rss_item->displayName();
item->setText(0, name + QString::fromUtf8(" (") + QString::number(rss_item->unreadCount())+ QString(")")); item->setText(0, name + QString::fromUtf8(" (") + QString::number(rss_item->unreadCount()) + QString(")"));
// If item has a parent, update it too // If item has a parent, update it too
if (item->parent()) if (item->parent())
updateItemInfos(item->parent()); updateItemInfos(item->parent());
@ -663,7 +664,7 @@ void RSSImp::updateFeedInfos(const QString& url, const QString& display_name, ui
qDebug() << Q_FUNC_INFO << display_name; qDebug() << Q_FUNC_INFO << display_name;
QTreeWidgetItem *item = m_feedList->getTreeItemFromUrl(url); QTreeWidgetItem *item = m_feedList->getTreeItemFromUrl(url);
RssFeedPtr stream = qSharedPointerCast<RssFeed>(m_feedList->getRSSItem(item)); RssFeedPtr stream = qSharedPointerCast<RssFeed>(m_feedList->getRSSItem(item));
item->setText(0, display_name + QString::fromUtf8(" (") + QString::number(nbUnread)+ QString(")")); item->setText(0, display_name + QString::fromUtf8(" (") + QString::number(nbUnread) + QString(")"));
if (!stream->isLoading()) if (!stream->isLoading())
item->setData(0, Qt::DecorationRole, QVariant(stream->icon())); item->setData(0, Qt::DecorationRole, QVariant(stream->icon()));
// Update parent // Update parent
@ -680,11 +681,11 @@ void RSSImp::onFeedContentChanged(const QString& url)
// If the feed is selected, update the displayed news // If the feed is selected, update the displayed news
if (m_feedList->currentItem() == item ) { if (m_feedList->currentItem() == item ) {
populateArticleList(item); populateArticleList(item);
} else {
// Update unread items
if (m_feedList->currentItem() == m_feedList->stickyUnreadItem()) {
populateArticleList(m_feedList->stickyUnreadItem());
} }
else {
// Update unread items
if (m_feedList->currentItem() == m_feedList->stickyUnreadItem())
populateArticleList(m_feedList->stickyUnreadItem());
} }
} }
@ -693,7 +694,7 @@ void RSSImp::updateRefreshInterval(uint val)
m_rssManager->updateRefreshInterval(val); m_rssManager->updateRefreshInterval(val);
} }
RSSImp::RSSImp(QWidget *parent) : RSSImp::RSSImp(QWidget *parent):
QWidget(parent), QWidget(parent),
m_rssManager(new RssManager) m_rssManager(new RssManager)
{ {
@ -735,8 +736,8 @@ RSSImp::RSSImp(QWidget *parent) :
connect(m_rssManager.data(), SIGNAL(feedContentChanged(QString)), SLOT(onFeedContentChanged(QString))); 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(m_feedList, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(displayRSSListMenu(const QPoint &)));
connect(listArticles, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(displayItemsListMenu(const QPoint&))); connect(listArticles, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(displayItemsListMenu(const QPoint &)));
// Feeds list actions // Feeds list actions
connect(actionDelete, SIGNAL(triggered()), this, SLOT(deleteSelectedItems())); connect(actionDelete, SIGNAL(triggered()), this, SLOT(deleteSelectedItems()));

View file

@ -45,7 +45,8 @@ QT_BEGIN_NAMESPACE
class QTreeWidgetItem; class QTreeWidgetItem;
QT_END_NAMESPACE QT_END_NAMESPACE
class RSSImp : public QWidget, public Ui::RSS { class RSSImp: public QWidget, public Ui::RSS
{
Q_OBJECT Q_OBJECT
public: public:
@ -74,7 +75,7 @@ private slots:
void updateItemInfos(QTreeWidgetItem *item); void updateItemInfos(QTreeWidgetItem *item);
void openSelectedArticlesUrls(); void openSelectedArticlesUrls();
void downloadSelectedTorrents(); void downloadSelectedTorrents();
void fillFeedsList(QTreeWidgetItem *parent=0, const RssFolderPtr& rss_parent = RssFolderPtr()); void fillFeedsList(QTreeWidgetItem *parent = 0, const RssFolderPtr& rss_parent = RssFolderPtr());
void saveSlidersPosition(); void saveSlidersPosition();
void restoreSlidersPosition(); void restoreSlidersPosition();
void askNewFolder(); void askNewFolder();