Some changes in visual and network modules.
This commit is contained in:
parent
247c547630
commit
b209fcf8cc
@ -3,6 +3,8 @@
|
||||
|
||||
Fixed:
|
||||
<ul>
|
||||
<li>Some visual tweaking.</li>
|
||||
<li>URL redirection now works with relative redirecting addresses.</li>
|
||||
<li>Messages are now sorted using active locale.</li>
|
||||
<li>Fixed bug #49 and duplicate feed/category detection.</li>
|
||||
<li>Experimentally fixed bug #50.</li>
|
||||
|
@ -177,12 +177,15 @@ QPair<FeedsModelFeed*, QNetworkReply::NetworkError> FeedsModelFeed::guessFeed(co
|
||||
}
|
||||
|
||||
QByteArray feed_contents;
|
||||
if ((result.second = NetworkFactory::downloadFile(url,
|
||||
qApp->settings()->value(APP_CFG_FEEDS, "feed_update_timeout", DOWNLOAD_TIMEOUT).toInt(),
|
||||
feed_contents,
|
||||
!username.isEmpty(),
|
||||
username,
|
||||
password)) == QNetworkReply::NoError) {
|
||||
NetworkResult network_result = NetworkFactory::downloadFile(url,
|
||||
qApp->settings()->value(APP_CFG_FEEDS, "feed_update_timeout", DOWNLOAD_TIMEOUT).toInt(),
|
||||
feed_contents,
|
||||
!username.isEmpty(),
|
||||
username,
|
||||
password);
|
||||
result.second = network_result.first;
|
||||
|
||||
if (result.second == QNetworkReply::NoError) {
|
||||
// Feed XML was obtained, now we need to try to guess
|
||||
// its encoding before we can read further data.
|
||||
QString xml_schema_encoding;
|
||||
@ -392,7 +395,7 @@ QVariant FeedsModelFeed::data(int column, int role) const {
|
||||
void FeedsModelFeed::update() {
|
||||
QByteArray feed_contents;
|
||||
int download_timeout = qApp->settings()->value(APP_CFG_FEEDS, "feed_update_timeout", DOWNLOAD_TIMEOUT).toInt();
|
||||
m_networkError = NetworkFactory::downloadFile(url(), download_timeout, feed_contents, passwordProtected(), username(), password());
|
||||
m_networkError = NetworkFactory::downloadFile(url(), download_timeout, feed_contents, passwordProtected(), username(), password()).first;
|
||||
|
||||
if (m_networkError != QNetworkReply::NoError) {
|
||||
qWarning("Error during fetching of new messages for feed '%s' (id %d).", qPrintable(url()), id());
|
||||
|
@ -476,7 +476,8 @@ void FeedsView::initializeContextMenuCategoriesFeeds() {
|
||||
qApp->mainForm()->m_ui->m_actionEditSelectedFeedCategory <<
|
||||
qApp->mainForm()->m_ui->m_actionViewSelectedItemsNewspaperMode <<
|
||||
qApp->mainForm()->m_ui->m_actionMarkSelectedFeedsAsRead <<
|
||||
qApp->mainForm()->m_ui->m_actionMarkSelectedFeedsAsUnread);
|
||||
qApp->mainForm()->m_ui->m_actionMarkSelectedFeedsAsUnread <<
|
||||
qApp->mainForm()->m_ui->m_actionDeleteSelectedFeedCategory);
|
||||
}
|
||||
|
||||
void FeedsView::initializeContextMenuEmptySpace() {
|
||||
|
@ -151,7 +151,7 @@ QPair<UpdateInfo, QNetworkReply::NetworkError> SystemFactory::checkForUpdates()
|
||||
QPair<UpdateInfo, QNetworkReply::NetworkError> result;
|
||||
QByteArray releases_xml;
|
||||
|
||||
result.second = NetworkFactory::downloadFile(RELEASES_LIST, DOWNLOAD_TIMEOUT, releases_xml);
|
||||
result.second = NetworkFactory::downloadFile(RELEASES_LIST, DOWNLOAD_TIMEOUT, releases_xml).first;
|
||||
|
||||
if (result.second == QNetworkReply::NoError) {
|
||||
result.first = parseUpdatesFile(releases_xml);
|
||||
|
@ -24,7 +24,8 @@
|
||||
|
||||
Downloader::Downloader(QObject *parent)
|
||||
: QObject(parent), m_activeReply(NULL), m_downloadManager(new SilentNetworkAccessManager(this)),
|
||||
m_timer(new QTimer(this)), m_lastOutputData(QByteArray()), m_lastOutputError(QNetworkReply::NoError) {
|
||||
m_timer(new QTimer(this)), m_lastOutputData(QByteArray()),
|
||||
m_lastOutputError(QNetworkReply::NoError), m_lastContentType(QVariant()) {
|
||||
|
||||
m_timer->setInterval(DOWNLOAD_TIMEOUT);
|
||||
m_timer->setSingleShot(true);
|
||||
@ -65,7 +66,14 @@ void Downloader::finished(QNetworkReply *reply) {
|
||||
// Communication indicates that HTTP redirection is needed.
|
||||
// Setup redirection URL and download again.
|
||||
QNetworkRequest request = reply->request();
|
||||
request.setUrl(redirection_url);
|
||||
|
||||
if (redirection_url.host().isEmpty()) {
|
||||
request.setUrl(QUrl(reply->request().url().scheme() + "://" + reply->request().url().host() +
|
||||
redirection_url.toString()));
|
||||
}
|
||||
else {
|
||||
request.setUrl(redirection_url);
|
||||
}
|
||||
|
||||
m_activeReply->deleteLater();
|
||||
m_activeReply = NULL;
|
||||
@ -76,6 +84,7 @@ void Downloader::finished(QNetworkReply *reply) {
|
||||
// No redirection is indicated. Final file is obtained in our "reply" object.
|
||||
// Read the data into output buffer.
|
||||
m_lastOutputData = reply->readAll();
|
||||
m_lastContentType = reply->header(QNetworkRequest::ContentTypeHeader);
|
||||
m_lastOutputError = reply->error();
|
||||
|
||||
m_activeReply->deleteLater();
|
||||
@ -108,6 +117,10 @@ void Downloader::runGetRequest(const QNetworkRequest &request) {
|
||||
this, SLOT(progressInternal(qint64,qint64)));
|
||||
}
|
||||
|
||||
QVariant Downloader::lastContentType() const {
|
||||
return m_lastContentType;
|
||||
}
|
||||
|
||||
QNetworkReply::NetworkError Downloader::lastOutputError() const {
|
||||
return m_lastOutputError;
|
||||
}
|
||||
|
@ -37,9 +37,10 @@ class Downloader : public QObject {
|
||||
explicit Downloader(QObject *parent = 0);
|
||||
virtual ~Downloader();
|
||||
|
||||
// Access to last received full output data/error.
|
||||
// Access to last received full output data/error/content-type.
|
||||
QByteArray lastOutputData() const;
|
||||
QNetworkReply::NetworkError lastOutputError() const;
|
||||
QVariant lastContentType() const;
|
||||
|
||||
public slots:
|
||||
// Performs asynchronous download of given file. Redirections are handled.
|
||||
@ -71,6 +72,7 @@ class Downloader : public QObject {
|
||||
|
||||
QByteArray m_lastOutputData;
|
||||
QNetworkReply::NetworkError m_lastOutputError;
|
||||
QVariant m_lastContentType;
|
||||
};
|
||||
|
||||
#endif // DOWNLOADER_H
|
||||
|
@ -105,7 +105,7 @@ QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QString &url,
|
||||
QString google_s2_with_url = QString("http://www.google.com/s2/favicons?domain=%1").arg(Qt::escape(url));
|
||||
#endif
|
||||
QByteArray icon_data;
|
||||
QNetworkReply::NetworkError network_result = downloadFile(google_s2_with_url, timeout, icon_data);
|
||||
QNetworkReply::NetworkError network_result = downloadFile(google_s2_with_url, timeout, icon_data).first;
|
||||
|
||||
if (network_result == QNetworkReply::NoError) {
|
||||
QPixmap icon_pixmap;
|
||||
@ -116,13 +116,14 @@ QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QString &url,
|
||||
return network_result;
|
||||
}
|
||||
|
||||
QNetworkReply::NetworkError NetworkFactory::downloadFile(const QString &url, int timeout,
|
||||
QByteArray &output, bool protected_contents,
|
||||
const QString &username, const QString &password) {
|
||||
NetworkResult NetworkFactory::downloadFile(const QString &url, int timeout,
|
||||
QByteArray &output, bool protected_contents,
|
||||
const QString &username, const QString &password) {
|
||||
// Here, we want to achieve "synchronous" approach because we want synchronout download API for
|
||||
// some use-cases too.
|
||||
Downloader downloader;
|
||||
QEventLoop loop;
|
||||
NetworkResult result;
|
||||
|
||||
// We need to quit event loop when the download finishes.
|
||||
QObject::connect(&downloader, SIGNAL(completed(QNetworkReply::NetworkError)), &loop, SLOT(quit()));
|
||||
@ -130,6 +131,8 @@ QNetworkReply::NetworkError NetworkFactory::downloadFile(const QString &url, int
|
||||
downloader.downloadFile(url, timeout, protected_contents, username, password);
|
||||
loop.exec();
|
||||
output = downloader.lastOutputData();
|
||||
result.first = downloader.lastOutputError();
|
||||
result.second = downloader.lastContentType();
|
||||
|
||||
return downloader.lastOutputError();
|
||||
return result;
|
||||
}
|
||||
|
@ -20,8 +20,12 @@
|
||||
|
||||
#include <QNetworkReply>
|
||||
#include <QCoreApplication>
|
||||
#include <QPair>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
typedef QPair<QNetworkReply::NetworkError, QVariant> NetworkResult;
|
||||
|
||||
class NetworkFactory {
|
||||
Q_DECLARE_TR_FUNCTIONS(NetworkFactory)
|
||||
|
||||
@ -39,9 +43,9 @@ class NetworkFactory {
|
||||
|
||||
// Performs SYNCHRONOUS download of file with given URL
|
||||
// and given timeout.
|
||||
static QNetworkReply::NetworkError downloadFile(const QString &url, int timeout, QByteArray &output,
|
||||
bool protected_contents = false, const QString &username = QString(),
|
||||
const QString &password = QString());
|
||||
static NetworkResult downloadFile(const QString &url, int timeout, QByteArray &output,
|
||||
bool protected_contents = false, const QString &username = QString(),
|
||||
const QString &password = QString());
|
||||
};
|
||||
|
||||
#endif // NETWORKFACTORY_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user