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

@ -52,8 +52,10 @@
#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,
@ -65,10 +67,9 @@ enum ArticleRoles {
// 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"));
} }
@ -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")));
} }
@ -560,17 +564,16 @@ void RSSImp::refreshTextBrowser()
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,14 +623,12 @@ 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)
{ {
@ -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());
} }
} }

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: