NOISSUE refactor *Download into more, smaller pieces
* Download is now Download. * Download uses Sink subclasses to process various events. * Validators can be used to further customize the Sink behaviour.
This commit is contained in:
@ -37,7 +37,7 @@ void NewsChecker::reloadNews()
|
||||
qDebug() << "Reloading news.";
|
||||
|
||||
NetJob* job = new NetJob("News RSS Feed");
|
||||
job->addNetAction(ByteArrayDownload::make(m_feedUrl));
|
||||
job->addNetAction(Net::Download::makeByteArray(m_feedUrl, &newsData));
|
||||
QObject::connect(job, &NetJob::succeeded, this, &NewsChecker::rssDownloadFinished);
|
||||
QObject::connect(job, &NetJob::failed, this, &NewsChecker::rssDownloadFailed);
|
||||
m_newsNetJob.reset(job);
|
||||
@ -49,13 +49,7 @@ void NewsChecker::rssDownloadFinished()
|
||||
// Parse the XML file and process the RSS feed entries.
|
||||
qDebug() << "Finished loading RSS feed.";
|
||||
|
||||
QByteArray data;
|
||||
{
|
||||
ByteArrayDownloadPtr dl = std::dynamic_pointer_cast<ByteArrayDownload>(m_newsNetJob->first());
|
||||
data = dl->m_data;
|
||||
m_newsNetJob.reset();
|
||||
}
|
||||
|
||||
m_newsNetJob.reset();
|
||||
QDomDocument doc;
|
||||
{
|
||||
// Stuff to store error info in.
|
||||
@ -64,12 +58,14 @@ void NewsChecker::rssDownloadFinished()
|
||||
int errorCol = -1;
|
||||
|
||||
// Parse the XML.
|
||||
if (!doc.setContent(data, false, &errorMsg, &errorLine, &errorCol))
|
||||
if (!doc.setContent(newsData, false, &errorMsg, &errorLine, &errorCol))
|
||||
{
|
||||
QString fullErrorMsg = QString("Error parsing RSS feed XML. %s at %d:%d.").arg(errorMsg, errorLine, errorCol);
|
||||
fail(fullErrorMsg);
|
||||
newsData.clear();
|
||||
return;
|
||||
}
|
||||
newsData.clear();
|
||||
}
|
||||
|
||||
// If the parsing succeeded, read it.
|
||||
|
@ -74,7 +74,7 @@ protected slots:
|
||||
void rssDownloadFinished();
|
||||
void rssDownloadFailed(QString reason);
|
||||
|
||||
protected:
|
||||
protected: /* data */
|
||||
//! The URL for the RSS feed to fetch.
|
||||
QString m_feedUrl;
|
||||
|
||||
@ -87,21 +87,19 @@ protected:
|
||||
//! True if news has been loaded.
|
||||
bool m_loadedNews;
|
||||
|
||||
QByteArray newsData;
|
||||
|
||||
/*!
|
||||
* Gets the error message that was given last time the news was loaded.
|
||||
* If the last news load succeeded, this will be an empty string.
|
||||
*/
|
||||
QString m_lastLoadError;
|
||||
|
||||
protected slots:
|
||||
/// Emits newsLoaded() and sets m_lastLoadError to empty string.
|
||||
void succeed();
|
||||
|
||||
/*!
|
||||
* Emits newsLoaded() and sets m_lastLoadError to empty string.
|
||||
*/
|
||||
void Q_SLOT succeed();
|
||||
|
||||
/*!
|
||||
* Emits newsLoadingFailed() and sets m_lastLoadError to the given message.
|
||||
*/
|
||||
void Q_SLOT fail(const QString& errorMsg);
|
||||
/// Emits newsLoadingFailed() and sets m_lastLoadError to the given message.
|
||||
void fail(const QString& errorMsg);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user