Replace WebImageView with NetImageManager and NetImageTracker classes
Resolves #31 and should take care of #30 #28 #23 #12
This commit is contained in:
parent
58d094a6d5
commit
b5bfd3e09e
4 changed files with 0 additions and 116 deletions
|
@ -121,7 +121,6 @@ config_pri_source_group1 {
|
||||||
$$quote($$BASEDIR/src/ActiveFrameQML.cpp) \
|
$$quote($$BASEDIR/src/ActiveFrameQML.cpp) \
|
||||||
$$quote($$BASEDIR/src/Pnut.cpp) \
|
$$quote($$BASEDIR/src/Pnut.cpp) \
|
||||||
$$quote($$BASEDIR/src/Pnut_test.cpp) \
|
$$quote($$BASEDIR/src/Pnut_test.cpp) \
|
||||||
$$quote($$BASEDIR/src/WebImageView.cpp) \
|
|
||||||
$$quote($$BASEDIR/src/applicationui.cpp) \
|
$$quote($$BASEDIR/src/applicationui.cpp) \
|
||||||
$$quote($$BASEDIR/src/main.cpp) \
|
$$quote($$BASEDIR/src/main.cpp) \
|
||||||
$$quote($$BASEDIR/src/netimagemanager.cpp) \
|
$$quote($$BASEDIR/src/netimagemanager.cpp) \
|
||||||
|
@ -130,7 +129,6 @@ config_pri_source_group1 {
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$quote($$BASEDIR/src/ActiveFrameQML.h) \
|
$$quote($$BASEDIR/src/ActiveFrameQML.h) \
|
||||||
$$quote($$BASEDIR/src/Pnut.h) \
|
$$quote($$BASEDIR/src/Pnut.h) \
|
||||||
$$quote($$BASEDIR/src/WebImageView.h) \
|
|
||||||
$$quote($$BASEDIR/src/applicationui.hpp) \
|
$$quote($$BASEDIR/src/applicationui.hpp) \
|
||||||
$$quote($$BASEDIR/src/globals.h) \
|
$$quote($$BASEDIR/src/globals.h) \
|
||||||
$$quote($$BASEDIR/src/netimagemanager.h) \
|
$$quote($$BASEDIR/src/netimagemanager.h) \
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
#include "WebImageView.h"
|
|
||||||
#include <bb/cascades/Image>
|
|
||||||
|
|
||||||
QNetworkAccessManager * WebImageView::mNetManager = new QNetworkAccessManager;
|
|
||||||
QNetworkDiskCache * WebImageView::mNetworkDiskCache = new QNetworkDiskCache();
|
|
||||||
|
|
||||||
WebImageView::WebImageView() {
|
|
||||||
mNetworkDiskCache->setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation));
|
|
||||||
mNetManager->setCache(mNetworkDiskCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
const QUrl& WebImageView::url() const {
|
|
||||||
return mUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebImageView::setUrl(const QUrl& url) {
|
|
||||||
|
|
||||||
mUrl = url;
|
|
||||||
mLoading = 0;
|
|
||||||
|
|
||||||
resetImage();
|
|
||||||
QNetworkRequest request;
|
|
||||||
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
|
|
||||||
request.setUrl(url);
|
|
||||||
|
|
||||||
QNetworkReply * reply = mNetManager->get(QNetworkRequest(request));
|
|
||||||
connect(reply,SIGNAL(finished()), this, SLOT(imageLoaded()));
|
|
||||||
connect(reply,SIGNAL(downloadProgress ( qint64 , qint64 )), this, SLOT(dowloadProgressed(qint64,qint64)));
|
|
||||||
emit urlChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
double WebImageView::loading() const {
|
|
||||||
return mLoading;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebImageView::imageLoaded() {
|
|
||||||
|
|
||||||
QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
|
|
||||||
|
|
||||||
QVariant possibleRedirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
|
|
||||||
|
|
||||||
mRedirectUrl = this->redirectUrl(possibleRedirectUrl.toUrl(),mRedirectUrl);
|
|
||||||
if (!mRedirectUrl.isEmpty()) {
|
|
||||||
this->setUrl(mRedirectUrl);
|
|
||||||
} else {
|
|
||||||
setImage(Image(reply->readAll()));
|
|
||||||
}
|
|
||||||
|
|
||||||
reply->deleteLater();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebImageView::dowloadProgressed(qint64 bytes,qint64 total) {
|
|
||||||
|
|
||||||
|
|
||||||
mLoading = double(bytes)/double(total);
|
|
||||||
emit loadingChanged();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl WebImageView::redirectUrl(const QUrl& possibleRedirectUrl, const QUrl& oldRedirectUrl) const {
|
|
||||||
QUrl redirectUrl;
|
|
||||||
if (!possibleRedirectUrl.isEmpty() && possibleRedirectUrl != oldRedirectUrl) {
|
|
||||||
redirectUrl = possibleRedirectUrl;
|
|
||||||
}
|
|
||||||
return redirectUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
#ifndef WEBIMAGEVIEW_H_
|
|
||||||
#define WEBIMAGEVIEW_H_
|
|
||||||
|
|
||||||
#include <bb/cascades/ImageView>
|
|
||||||
#include <QUrl>
|
|
||||||
using namespace bb::cascades;
|
|
||||||
|
|
||||||
class QNetworkAccessManager;
|
|
||||||
class WebImageView: public bb::cascades::ImageView {
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PROPERTY (QUrl url READ url WRITE setUrl NOTIFY urlChanged)
|
|
||||||
Q_PROPERTY (float loading READ loading NOTIFY loadingChanged)
|
|
||||||
|
|
||||||
public:
|
|
||||||
WebImageView();
|
|
||||||
const QUrl& url() const;
|
|
||||||
double loading() const;
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void setUrl(const QUrl& url);
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void imageLoaded();
|
|
||||||
void dowloadProgressed(qint64,qint64);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void urlChanged();
|
|
||||||
void loadingChanged();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
static QNetworkAccessManager * mNetManager;
|
|
||||||
static QNetworkDiskCache * mNetworkDiskCache;
|
|
||||||
QUrl mUrl;
|
|
||||||
QUrl mRedirectUrl;
|
|
||||||
float mLoading;
|
|
||||||
|
|
||||||
QUrl redirectUrl(const QUrl& possibleRedirectUrl, const QUrl& oldRedirectUrl) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* WEBIMAGEVIEW_H_ */
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
#include "applicationui.hpp"
|
#include "applicationui.hpp"
|
||||||
#include "Pnut.h"
|
#include "Pnut.h"
|
||||||
#include "WebImageView.h"
|
|
||||||
#include "ActiveFrameQML.h"
|
#include "ActiveFrameQML.h"
|
||||||
#include "netimagemanager.h"
|
#include "netimagemanager.h"
|
||||||
#include "netimagetracker.h"
|
#include "netimagetracker.h"
|
||||||
|
@ -57,7 +56,6 @@ ApplicationUI::ApplicationUI() :
|
||||||
|
|
||||||
qmlRegisterType<Pnut>("com.monkeystew.pnut", 1, 0, "Pnut");
|
qmlRegisterType<Pnut>("com.monkeystew.pnut", 1, 0, "Pnut");
|
||||||
qmlRegisterType<QTimer> ("com.monkeystew.qtimer", 1, 0, "QTimer");
|
qmlRegisterType<QTimer> ("com.monkeystew.qtimer", 1, 0, "QTimer");
|
||||||
qmlRegisterType<WebImageView>("org.labsquare", 1, 0, "WebImageView");
|
|
||||||
qmlRegisterType<NetImageTracker>("com.netimage", 1, 0, "NetImageTracker");
|
qmlRegisterType<NetImageTracker>("com.netimage", 1, 0, "NetImageTracker");
|
||||||
qmlRegisterType<NetImageManager>("com.netimage", 1, 0, "NetImageManager");
|
qmlRegisterType<NetImageManager>("com.netimage", 1, 0, "NetImageManager");
|
||||||
|
|
||||||
|
|
Reference in a new issue