Browse Source

Follow project coding style. Issue #2192.

adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
96ec6777e6
  1. 3
      src/rss/htmlbrowser.cpp
  2. 77
      src/rss/rss_imp.cpp
  3. 3
      src/rss/rss_imp.h

3
src/rss/htmlbrowser.cpp

@ -64,7 +64,8 @@ void HtmlBrowser::resourceLoaded(QNetworkReply *reply) @@ -64,7 +64,8 @@ void HtmlBrowser::resourceLoaded(QNetworkReply *reply)
if(reply->error() == QNetworkReply::NoError && reply->size() > 0) {
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.
// Otherwise HTMLBrowser will keep trying to download it every time article is displayed,
// since it's not possible to cache error responses.

77
src/rss/rss_imp.cpp

@ -52,8 +52,10 @@ @@ -52,8 +52,10 @@
#include "iconprovider.h"
#include "autoexpandabledialog.h"
namespace Article {
enum ArticleRoles {
namespace Article
{
enum ArticleRoles
{
TitleRole = Qt::DisplayRole,
IconRole = Qt::DecorationRole,
ColorRole = Qt::ForegroundRole,
@ -65,10 +67,9 @@ enum ArticleRoles { @@ -65,10 +67,9 @@ 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) {
@ -80,13 +81,12 @@ void RSSImp::displayRSSListMenu(const QPoint& pos) @@ -80,13 +81,12 @@ void RSSImp::displayRSSListMenu(const QPoint& pos)
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 {
else
myRSSListMenu.addAction(actionManage_cookies);
}
}
}
else {
myRSSListMenu.addAction(actionDelete);
myRSSListMenu.addSeparator();
@ -96,7 +96,8 @@ void RSSImp::displayRSSListMenu(const QPoint& pos) @@ -96,7 +96,8 @@ void RSSImp::displayRSSListMenu(const QPoint& pos)
myRSSListMenu.addSeparator();
myRSSListMenu.addAction(actionCopy_feed_URL);
}
}else{
}
else {
myRSSListMenu.addAction(actionNew_subscription);
myRSSListMenu.addAction(actionNew_folder);
myRSSListMenu.addSeparator();
@ -150,7 +151,8 @@ void RSSImp::askNewFolder() @@ -150,7 +151,8 @@ void RSSImp::askNewFolder()
parent_item = m_feedList->selectedItems().at(0);
rss_parent = qSharedPointerDynamicCast<RssFolder>(m_feedList->getRSSItem(parent_item));
Q_ASSERT(rss_parent);
} else {
}
else {
rss_parent = m_rssManager;
}
bool ok;
@ -181,19 +183,17 @@ void RSSImp::on_newFeedButton_clicked() @@ -181,19 +183,17 @@ void RSSImp::on_newFeedButton_clicked()
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 {
else
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 {
else
rss_parent = m_rssManager;
}
// Ask for feed URL
bool ok;
QString clip_txt = qApp->clipboard()->text();
@ -237,10 +237,11 @@ void RSSImp::deleteSelectedItems() @@ -237,10 +237,11 @@ void RSSImp::deleteSelectedItems()
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);
}
else {
if (selectedItems.first() == m_feedList->stickyUnreadItem())
return;
@ -342,8 +343,9 @@ void RSSImp::downloadSelectedTorrents() @@ -342,8 +343,9 @@ void RSSImp::downloadSelectedTorrents()
QString torrentLink = article->torrentUrl();
// Check if it is a magnet link
if (torrentLink.startsWith("magnet:", Qt::CaseInsensitive))
if (torrentLink.startsWith("magnet:", Qt::CaseInsensitive)) {
QBtSession::instance()->addMagnetInteractive(torrentLink);
}
else {
// Load possible cookies
QString feed_url = m_feedList->getItemID(m_feedList->selectedItems().first());
@ -388,7 +390,8 @@ void RSSImp::renameSelectedRssFile() @@ -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."));
ok = false;
}
} else {
}
else {
return;
}
} while (!ok);
@ -408,13 +411,15 @@ void RSSImp::refreshSelectedItems() @@ -408,13 +411,15 @@ void RSSImp::refreshSelectedItems()
if (item == m_feedList->stickyUnreadItem()) {
refreshAllFeeds();
return;
} else {
}
else {
if (!file->refresh())
continue;
// Update UI
if (qSharedPointerDynamicCast<RssFeed>(file)) {
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
foreach (QTreeWidgetItem *feed, m_feedList->getAllFeedItems(item))
feed->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
@ -428,10 +433,9 @@ void RSSImp::copySelectedFeedsURL() @@ -428,10 +433,9 @@ void RSSImp::copySelectedFeedsURL()
QStringList URLs;
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
QTreeWidgetItem* item;
foreach (item, selectedItems) {
foreach (item, selectedItems)
if (m_feedList->isFeed(item))
URLs << m_feedList->getItemID(item);
}
qApp->clipboard()->setText(URLs.join("\n"));
}
@ -462,11 +466,10 @@ QTreeWidgetItem* RSSImp::createFolderListItem(const RssFilePtr& rssFile) @@ -462,11 +466,10 @@ QTreeWidgetItem* RSSImp::createFolderListItem(const RssFilePtr& rssFile)
void RSSImp::fillFeedsList(QTreeWidgetItem* parent, const RssFolderPtr& rss_parent)
{
QList<RssFilePtr> children;
if (parent) {
if (parent)
children = rss_parent->getContent();
} else {
else
children = m_rssManager->getContent();
}
foreach (const RssFilePtr& rssFile, children) {
QTreeWidgetItem* item = createFolderListItem(rssFile);
Q_ASSERT(item);
@ -495,7 +498,8 @@ QListWidgetItem* RSSImp::createArticleListItem(const RssArticlePtr& article) @@ -495,7 +498,8 @@ QListWidgetItem* RSSImp::createArticleListItem(const RssArticlePtr& article)
if (article->isRead()) {
item->setData(Article::ColorRole, QVariant(QColor("grey")));
item->setData(Article::IconRole, QVariant(QIcon(":/Icons/sphere.png")));
} else {
}
else {
item->setData(Article::ColorRole, QVariant(QColor("blue")));
item->setData(Article::IconRole, QVariant(QIcon(":/Icons/sphere2.png")));
}
@ -560,17 +564,16 @@ void RSSImp::refreshTextBrowser() @@ -560,17 +564,16 @@ 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>";
html += "<div style='margin-left: 5px; margin-right: 5px;'>";
if(Qt::mightBeRichText(article->description())) {
html += article->description();
} else {
}
else {
QString description = article->description();
QRegExp rx;
// 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() @@ -620,14 +623,12 @@ void RSSImp::restoreSlidersPosition()
{
const Preferences* const pref = Preferences::instance();
QByteArray pos_h = pref->getRssHSplitterState();
if (!pos_h.isNull()) {
if (!pos_h.isNull())
splitter_h->restoreState(pos_h);
}
QByteArray pos_v = pref->getRssVSplitterState();
if (!pos_v.isNull()) {
if (!pos_v.isNull())
splitter_v->restoreState(pos_v);
}
}
void RSSImp::updateItemsInfos(const QList<QTreeWidgetItem*>& items)
{
@ -680,13 +681,13 @@ void RSSImp::onFeedContentChanged(const QString& url) @@ -680,13 +681,13 @@ void RSSImp::onFeedContentChanged(const QString& url)
// If the feed is selected, update the displayed news
if (m_feedList->currentItem() == item ) {
populateArticleList(item);
} else {
}
else {
// Update unread items
if (m_feedList->currentItem() == m_feedList->stickyUnreadItem()) {
if (m_feedList->currentItem() == m_feedList->stickyUnreadItem())
populateArticleList(m_feedList->stickyUnreadItem());
}
}
}
void RSSImp::updateRefreshInterval(uint val)
{

3
src/rss/rss_imp.h

@ -45,7 +45,8 @@ QT_BEGIN_NAMESPACE @@ -45,7 +45,8 @@ QT_BEGIN_NAMESPACE
class QTreeWidgetItem;
QT_END_NAMESPACE
class RSSImp : public QWidget, public Ui::RSS {
class RSSImp: public QWidget, public Ui::RSS
{
Q_OBJECT
public:

Loading…
Cancel
Save