Commit 10157163 authored by Daniel Molkentin's avatar Daniel Molkentin
Browse files

Move RSSFetcher into its own thread.

This should keep QNAM from blocking the startup in some network setups.

Reviewed-by: dt
Task-number: QTCREATORBUG-1250
parent deba7405
......@@ -90,9 +90,12 @@ CommunityWelcomePageWidget::CommunityWelcomePageWidget(QWidget *parent) :
connect(ui->supportSitesTreeWidget, SIGNAL(activated(QString)), SLOT(slotUrlClicked(QString)));
connect(m_rssFetcher, SIGNAL(newsItemReady(QString, QString, QString)),
ui->newsTreeWidget, SLOT(addNewsItem(QString, QString, QString)));
ui->newsTreeWidget, SLOT(addNewsItem(QString, QString, QString)), Qt::QueuedConnection);
connect(this, SIGNAL(startRssFetching(QUrl)), m_rssFetcher, SLOT(fetch(QUrl)), Qt::QueuedConnection);
//: Add localized feed here only if one exists
m_rssFetcher->fetch(QUrl(tr("http://labs.trolltech.com/blogs/feed")));
m_rssFetcher->start(QThread::LowestPriority);
emit startRssFetching(QUrl(tr("http://labs.trolltech.com/blogs/feed")));
populateWelcomeTreeWidget(supportSites, sizeof(supportSites)/sizeof(Site), ui->supportSitesTreeWidget);
populateWelcomeTreeWidget(sites, sizeof(sites)/sizeof(Site), ui->miscSitesTreeWidget);
......@@ -100,6 +103,8 @@ CommunityWelcomePageWidget::CommunityWelcomePageWidget(QWidget *parent) :
CommunityWelcomePageWidget::~CommunityWelcomePageWidget()
{
m_rssFetcher->exit();
m_rssFetcher->wait();
delete m_rssFetcher;
delete ui;
}
......
......@@ -32,6 +32,10 @@
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class QUrl;
QT_END_NAMESPACE
namespace Welcome {
namespace Internal {
......@@ -49,6 +53,9 @@ public:
explicit CommunityWelcomePageWidget(QWidget *parent = 0);
~CommunityWelcomePageWidget();
signals:
void startRssFetching(const QUrl& url);
private slots:
void slotUrlClicked(const QString &data);
......
......@@ -33,6 +33,7 @@
#include <QtCore/QDebug>
#include <QtCore/QSysInfo>
#include <QtCore/QLocale>
#include <QtCore/QEventLoop>
#include <QtGui/QDesktopServices>
#include <QtGui/QLineEdit>
#include <QtNetwork/QNetworkReply>
......@@ -113,15 +114,22 @@ static const QString getOsString()
return osString;
}
RSSFetcher::RSSFetcher(int maxItems, QObject *parent)
: QObject(parent), m_maxItems(maxItems), m_items(0)
RSSFetcher::RSSFetcher(int maxItems)
: QThread(0), m_maxItems(maxItems), m_items(0), m_networkAccessManager(0)
{
moveToThread(this);
}
RSSFetcher::~RSSFetcher()
{
}
void RSSFetcher::run()
{
exec();
delete m_networkAccessManager;
}
void RSSFetcher::fetch(const QUrl &url)
{
QString agentStr = QString::fromLatin1("Qt-Creator/%1 (QHttp %2; %3; %4; %5 bit)")
......@@ -130,9 +138,9 @@ void RSSFetcher::fetch(const QUrl &url)
.arg(QSysInfo::WordSize);
QNetworkRequest req(url);
req.setRawHeader("User-Agent", agentStr.toLatin1());
if (m_networkAccessManager.isNull()) {
m_networkAccessManager.reset(new QNetworkAccessManager);
connect(m_networkAccessManager.data(), SIGNAL(finished(QNetworkReply*)),
if (!m_networkAccessManager) {
m_networkAccessManager = new QNetworkAccessManager;
connect(m_networkAccessManager, SIGNAL(finished(QNetworkReply*)),
SLOT(fetchingFinished(QNetworkReply*)));
}
m_networkAccessManager->get(req);
......
......@@ -30,8 +30,7 @@
#ifndef RSSFETCHER_H
#define RSSFETCHER_H
#include <QtCore/QScopedPointer>
#include <QtCore/QObject>
#include <QtCore/QThread>
QT_BEGIN_NAMESPACE
class QNetworkReply;
......@@ -43,11 +42,12 @@ QT_END_NAMESPACE
namespace Welcome {
namespace Internal {
class RSSFetcher : public QObject
class RSSFetcher : public QThread
{
Q_OBJECT
public:
explicit RSSFetcher(int maxItems, QObject *parent = 0);
explicit RSSFetcher(int maxItems);
virtual void run();
virtual ~RSSFetcher();
signals:
......@@ -64,9 +64,9 @@ private:
void parseXml(QIODevice *);
const int m_maxItems;
QScopedPointer<QNetworkAccessManager> m_networkAccessManager;
int m_items;
QNetworkAccessManager* m_networkAccessManager;
};
} // namespace Welcome
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment