Follow project coding style. Issue #2192.

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

View file

@ -13,16 +13,16 @@
#include "fs_utils.h"
HtmlBrowser::HtmlBrowser(QWidget* parent)
: QTextBrowser(parent)
: QTextBrowser(parent)
{
m_netManager = new QNetworkAccessManager(this);
m_diskCache = new QNetworkDiskCache(this);
m_netManager = new QNetworkAccessManager(this);
m_diskCache = new QNetworkDiskCache(this);
m_diskCache->setCacheDirectory(QDir::cleanPath(fsutils::cacheLocation() + "/rss"));
m_diskCache->setMaximumCacheSize(50 * 1024 * 1024);
qDebug() << "HtmlBrowser cache path:" << m_diskCache->cacheDirectory() << " max size:" << m_diskCache->maximumCacheSize() / 1024 / 1024 << "MB";
m_netManager->setCache(m_diskCache);
m_diskCache->setMaximumCacheSize(50 * 1024 * 1024);
qDebug() << "HtmlBrowser cache path:" << m_diskCache->cacheDirectory() << " max size:" << m_diskCache->maximumCacheSize() / 1024 / 1024 << "MB";
m_netManager->setCache(m_diskCache);
connect(m_netManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(resourceLoaded(QNetworkReply*)));
connect(m_netManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(resourceLoaded(QNetworkReply*)));
}
HtmlBrowser::~HtmlBrowser()
@ -31,62 +31,63 @@ HtmlBrowser::~HtmlBrowser()
QVariant HtmlBrowser::loadResource(int type, const QUrl &name)
{
if(type == QTextDocument::ImageResource) {
QUrl url(name);
if(url.scheme().isEmpty())
url.setScheme("http");
if(type == QTextDocument::ImageResource) {
QUrl url(name);
if(url.scheme().isEmpty())
url.setScheme("http");
QIODevice *dev = m_diskCache->data(url);
if(dev != 0) {
qDebug() << "HtmlBrowser::loadResource() cache " << url.toString();
QByteArray res = dev->readAll();
delete dev;
return res;
}
QIODevice *dev = m_diskCache->data(url);
if(dev != 0) {
qDebug() << "HtmlBrowser::loadResource() cache " << url.toString();
QByteArray res = dev->readAll();
delete dev;
return res;
}
if(!m_activeRequests.contains(url)) {
m_activeRequests.insert(url, true);
qDebug() << "HtmlBrowser::loadResource() get " << url.toString();
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
m_netManager->get(req);
}
if(!m_activeRequests.contains(url)) {
m_activeRequests.insert(url, true);
qDebug() << "HtmlBrowser::loadResource() get " << url.toString();
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
m_netManager->get(req);
}
return QVariant();
}
return QVariant();
}
return QTextBrowser::loadResource(type, name);
return QTextBrowser::loadResource(type, name);
}
void HtmlBrowser::resourceLoaded(QNetworkReply *reply)
{
m_activeRequests.remove(reply->request().url());
m_activeRequests.remove(reply->request().url());
if(reply->error() == QNetworkReply::NoError && reply->size() > 0) {
qDebug() << "HtmlBrowser::resourceLoaded() save " << reply->request().url().toString();
} 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.
QNetworkCacheMetaData metaData;
QNetworkCacheMetaData::AttributesMap atts;
metaData.setUrl(reply->request().url());
metaData.setSaveToDisk(true);
atts[QNetworkRequest::HttpStatusCodeAttribute] = 200;
atts[QNetworkRequest::HttpReasonPhraseAttribute] = "Ok";
metaData.setAttributes(atts);
metaData.setLastModified(QDateTime::currentDateTime());
metaData.setExpirationDate(QDateTime::currentDateTime().addDays(1));
QIODevice *dev = m_diskCache->prepare(metaData);
if(!dev)
return;
QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(32, 32).save(dev, "PNG");
m_diskCache->insert(dev);
}
// Refresh the document display and keep scrollbars where they are
int sx = horizontalScrollBar()->value();
int sy = verticalScrollBar()->value();
document()->setHtml(document()->toHtml());
horizontalScrollBar()->setValue(sx);
verticalScrollBar()->setValue(sy);
if(reply->error() == QNetworkReply::NoError && reply->size() > 0) {
qDebug() << "HtmlBrowser::resourceLoaded() save " << reply->request().url().toString();
}
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.
QNetworkCacheMetaData metaData;
QNetworkCacheMetaData::AttributesMap atts;
metaData.setUrl(reply->request().url());
metaData.setSaveToDisk(true);
atts[QNetworkRequest::HttpStatusCodeAttribute] = 200;
atts[QNetworkRequest::HttpReasonPhraseAttribute] = "Ok";
metaData.setAttributes(atts);
metaData.setLastModified(QDateTime::currentDateTime());
metaData.setExpirationDate(QDateTime::currentDateTime().addDays(1));
QIODevice *dev = m_diskCache->prepare(metaData);
if(!dev)
return;
QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(32, 32).save(dev, "PNG");
m_diskCache->insert(dev);
}
// Refresh the document display and keep scrollbars where they are
int sx = horizontalScrollBar()->value();
int sy = verticalScrollBar()->value();
document()->setHtml(document()->toHtml());
horizontalScrollBar()->setValue(sx);
verticalScrollBar()->setValue(sy);
}

View file

@ -8,23 +8,23 @@ class QNetworkAccessManager;
class QNetworkDiskCache;
class QNetworkReply;
class HtmlBrowser : public QTextBrowser
class HtmlBrowser: public QTextBrowser
{
Q_OBJECT
public:
explicit HtmlBrowser(QWidget* parent = 0);
~HtmlBrowser();
Q_OBJECT
public:
explicit HtmlBrowser(QWidget* parent = 0);
~HtmlBrowser();
virtual QVariant loadResource(int type, const QUrl &name);
virtual QVariant loadResource(int type, const QUrl &name);
protected:
QNetworkAccessManager *m_netManager;
QNetworkDiskCache *m_diskCache;
QHash<QUrl, bool> m_activeRequests;
QNetworkAccessManager *m_netManager;
QNetworkDiskCache *m_diskCache;
QHash<QUrl, bool> m_activeRequests;
protected slots:
void resourceLoaded(QNetworkReply *reply);
void resourceLoaded(QNetworkReply *reply);
};
#endif // HTMLBROWSER_H

File diff suppressed because it is too large Load diff

View file

@ -45,55 +45,56 @@ QT_BEGIN_NAMESPACE
class QTreeWidgetItem;
QT_END_NAMESPACE
class RSSImp : public QWidget, public Ui::RSS {
Q_OBJECT
class RSSImp: public QWidget, public Ui::RSS
{
Q_OBJECT
public:
RSSImp(QWidget *parent);
~RSSImp();
RSSImp(QWidget *parent);
~RSSImp();
public slots:
void deleteSelectedItems();
void updateRefreshInterval(uint val);
void deleteSelectedItems();
void updateRefreshInterval(uint val);
private slots:
void on_newFeedButton_clicked();
void refreshAllFeeds();
void on_markReadButton_clicked();
void displayRSSListMenu(const QPoint&);
void displayItemsListMenu(const QPoint&);
void renameSelectedRssFile();
void refreshSelectedItems();
void copySelectedFeedsURL();
void populateArticleList(QTreeWidgetItem* item);
void refreshTextBrowser();
void updateFeedIcon(const QString &url, const QString &icon_path);
void updateFeedInfos(const QString &url, const QString &display_name, uint nbUnread);
void onFeedContentChanged(const QString& url);
void updateItemsInfos(const QList<QTreeWidgetItem*> &items);
void updateItemInfos(QTreeWidgetItem *item);
void openSelectedArticlesUrls();
void downloadSelectedTorrents();
void fillFeedsList(QTreeWidgetItem *parent=0, const RssFolderPtr& rss_parent = RssFolderPtr());
void saveSlidersPosition();
void restoreSlidersPosition();
void askNewFolder();
void saveFoldersOpenState();
void loadFoldersOpenState();
void on_actionManage_cookies_triggered();
void on_settingsButton_clicked();
void on_rssDownloaderBtn_clicked();
void on_newFeedButton_clicked();
void refreshAllFeeds();
void on_markReadButton_clicked();
void displayRSSListMenu(const QPoint&);
void displayItemsListMenu(const QPoint&);
void renameSelectedRssFile();
void refreshSelectedItems();
void copySelectedFeedsURL();
void populateArticleList(QTreeWidgetItem* item);
void refreshTextBrowser();
void updateFeedIcon(const QString &url, const QString &icon_path);
void updateFeedInfos(const QString &url, const QString &display_name, uint nbUnread);
void onFeedContentChanged(const QString& url);
void updateItemsInfos(const QList<QTreeWidgetItem*> &items);
void updateItemInfos(QTreeWidgetItem *item);
void openSelectedArticlesUrls();
void downloadSelectedTorrents();
void fillFeedsList(QTreeWidgetItem *parent = 0, const RssFolderPtr& rss_parent = RssFolderPtr());
void saveSlidersPosition();
void restoreSlidersPosition();
void askNewFolder();
void saveFoldersOpenState();
void loadFoldersOpenState();
void on_actionManage_cookies_triggered();
void on_settingsButton_clicked();
void on_rssDownloaderBtn_clicked();
private:
static QListWidgetItem* createArticleListItem(const RssArticlePtr& article);
static QTreeWidgetItem* createFolderListItem(const RssFilePtr& rssFile);
static QListWidgetItem* createArticleListItem(const RssArticlePtr& article);
static QTreeWidgetItem* createFolderListItem(const RssFilePtr& rssFile);
private:
RssManagerPtr m_rssManager;
FeedListWidget *m_feedList;
QListWidgetItem* m_currentArticle;
QShortcut *editHotkey;
QShortcut *deleteHotkey;
RssManagerPtr m_rssManager;
FeedListWidget *m_feedList;
QListWidgetItem* m_currentArticle;
QShortcut *editHotkey;
QShortcut *deleteHotkey;
};