diff --git a/src/plugins/welcome/communitywelcomepagewidget.cpp b/src/plugins/welcome/communitywelcomepagewidget.cpp index d9043daf83d0f390a87fb7800eb476905bd9a2ef..e489761824baa225070bf4540f0e21796de6141e 100644 --- a/src/plugins/welcome/communitywelcomepagewidget.cpp +++ b/src/plugins/welcome/communitywelcomepagewidget.cpp @@ -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; } diff --git a/src/plugins/welcome/communitywelcomepagewidget.h b/src/plugins/welcome/communitywelcomepagewidget.h index 228ff5ccc2267559ee5754a5ea8f515db0d54394..3bfb9d72bea3bb8b81df58a5601950ca8de81722 100644 --- a/src/plugins/welcome/communitywelcomepagewidget.h +++ b/src/plugins/welcome/communitywelcomepagewidget.h @@ -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); diff --git a/src/plugins/welcome/rssfetcher.cpp b/src/plugins/welcome/rssfetcher.cpp index ecd1140910b9ff43991353d859df2a519fbceb38..7b272e35f31e4060785974e86de5da290dcea47f 100644 --- a/src/plugins/welcome/rssfetcher.cpp +++ b/src/plugins/welcome/rssfetcher.cpp @@ -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); diff --git a/src/plugins/welcome/rssfetcher.h b/src/plugins/welcome/rssfetcher.h index db1fba88b6a6445c653b4a866ff03387660d01df..09c9db848e845e816841abe2de5a78249d629bef 100644 --- a/src/plugins/welcome/rssfetcher.h +++ b/src/plugins/welcome/rssfetcher.h @@ -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