Browse Source

Follow project coding style. Issue #2192.

adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
96ec6777e6
  1. 113
      src/rss/htmlbrowser.cpp
  2. 18
      src/rss/htmlbrowser.h
  3. 1165
      src/rss/rss_imp.cpp
  4. 79
      src/rss/rss_imp.h

113
src/rss/htmlbrowser.cpp

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

18
src/rss/htmlbrowser.h

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

1165
src/rss/rss_imp.cpp

File diff suppressed because it is too large Load Diff

79
src/rss/rss_imp.h

@ -45,55 +45,56 @@ 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:
RSSImp(QWidget *parent); RSSImp(QWidget *parent);
~RSSImp(); ~RSSImp();
public slots: public slots:
void deleteSelectedItems(); void deleteSelectedItems();
void updateRefreshInterval(uint val); void updateRefreshInterval(uint val);
private slots: private slots:
void on_newFeedButton_clicked(); void on_newFeedButton_clicked();
void refreshAllFeeds(); void refreshAllFeeds();
void on_markReadButton_clicked(); void on_markReadButton_clicked();
void displayRSSListMenu(const QPoint&); void displayRSSListMenu(const QPoint&);
void displayItemsListMenu(const QPoint&); void displayItemsListMenu(const QPoint&);
void renameSelectedRssFile(); void renameSelectedRssFile();
void refreshSelectedItems(); void refreshSelectedItems();
void copySelectedFeedsURL(); void copySelectedFeedsURL();
void populateArticleList(QTreeWidgetItem* item); void populateArticleList(QTreeWidgetItem* item);
void refreshTextBrowser(); void refreshTextBrowser();
void updateFeedIcon(const QString &url, const QString &icon_path); void updateFeedIcon(const QString &url, const QString &icon_path);
void updateFeedInfos(const QString &url, const QString &display_name, uint nbUnread); void updateFeedInfos(const QString &url, const QString &display_name, uint nbUnread);
void onFeedContentChanged(const QString& url); void onFeedContentChanged(const QString& url);
void updateItemsInfos(const QList<QTreeWidgetItem*> &items); void updateItemsInfos(const QList<QTreeWidgetItem*> &items);
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();
void saveFoldersOpenState(); void saveFoldersOpenState();
void loadFoldersOpenState(); void loadFoldersOpenState();
void on_actionManage_cookies_triggered(); void on_actionManage_cookies_triggered();
void on_settingsButton_clicked(); void on_settingsButton_clicked();
void on_rssDownloaderBtn_clicked(); void on_rssDownloaderBtn_clicked();
private: private:
static QListWidgetItem* createArticleListItem(const RssArticlePtr& article); static QListWidgetItem* createArticleListItem(const RssArticlePtr& article);
static QTreeWidgetItem* createFolderListItem(const RssFilePtr& rssFile); static QTreeWidgetItem* createFolderListItem(const RssFilePtr& rssFile);
private: private:
RssManagerPtr m_rssManager; RssManagerPtr m_rssManager;
FeedListWidget *m_feedList; FeedListWidget *m_feedList;
QListWidgetItem* m_currentArticle; QListWidgetItem* m_currentArticle;
QShortcut *editHotkey; QShortcut *editHotkey;
QShortcut *deleteHotkey; QShortcut *deleteHotkey;
}; };

Loading…
Cancel
Save