- Merged QWidget and QML Qt frontends, just define QT_WIDGET to select the QWidget one
- Coded a resource package download GUI based on QWidget - Removed compilation warning on unused variable - Updated Maemo desktop file to start directly the binary - Updated .pro file - Updated version macros to be able to compose the resource package file - Updated QML interface for Android - Updated QML interface to not contain the name of the resource package - Updated the file downloader class to be able to get the resource package hash from the google code server - Updated the file downloaded class to verify the resource package hash from the remote server at each startup to be able to perform automatic update - Defined several JGE operation as static to clean up the wagic wrapper
This commit is contained in:
@@ -6,56 +6,116 @@
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <qdeclarative.h>
|
||||
#include <QTemporaryFile>
|
||||
#ifdef QT_WIDGET
|
||||
#include <QProgressDialog>
|
||||
#else
|
||||
#include <qdeclarative.h>
|
||||
#endif //QT_WIDGET
|
||||
|
||||
|
||||
class FileDownloader : public QObject
|
||||
class FileDownloader :
|
||||
#ifdef QT_WIDGET
|
||||
public QProgressDialog
|
||||
#else
|
||||
public QObject
|
||||
#endif //QT_WIDGET
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(qint64 received READ received NOTIFY receivedChanged)
|
||||
Q_PROPERTY(QUrl url READ getDownloadUrl WRITE setDownloadUrl NOTIFY downloadUrlChanged)
|
||||
Q_PROPERTY(QString hash READ getHash NOTIFY hashChanged)
|
||||
Q_PROPERTY(QString status READ getStatus NOTIFY statusChanged)
|
||||
Q_PROPERTY(DownloadState state READ getState NOTIFY stateChanged )
|
||||
Q_PROPERTY(QString state_string READ getStateString NOTIFY stateStringChanged )
|
||||
Q_ENUMS(DownloadState)
|
||||
public:
|
||||
explicit FileDownloader(QString localPath, QObject *parent = 0);
|
||||
enum DownloadState {
|
||||
NETWORK_ERROR,
|
||||
DOWNLOADING_HASH,
|
||||
DOWNLOADING_FILE,
|
||||
DOWNLOADED
|
||||
} ;
|
||||
|
||||
explicit FileDownloader(QString localPath, QString targetFile, QObject *parent = 0);
|
||||
virtual ~FileDownloader();
|
||||
qint64 received() const {return m_received;};
|
||||
QUrl getDownloadUrl() {return m_downloadUrl;};
|
||||
QString getHash() {return m_hash;};
|
||||
QString getStatus() {return m_status;};
|
||||
DownloadState getState() {
|
||||
return m_state;
|
||||
};
|
||||
QString getStateString() {
|
||||
if(m_state == DOWNLOADING_HASH )
|
||||
return "DOWNLOADING_HASH";
|
||||
else if(m_state == DOWNLOADING_FILE )
|
||||
return "DOWNLOADING_FILE";
|
||||
else
|
||||
return "DOWNLOADED";
|
||||
}
|
||||
|
||||
signals:
|
||||
void receivedChanged();
|
||||
void downloadUrlChanged();
|
||||
void hashChanged();
|
||||
void receivedChanged(int value);
|
||||
void statusChanged();
|
||||
void stateChanged(DownloadState state);
|
||||
void stateStringChanged();
|
||||
|
||||
private slots:
|
||||
void fileDownloaded(QNetworkReply* pReply){
|
||||
if(m_tmp.write(pReply->readAll()) == -1) return;
|
||||
void fileDownloaded(){
|
||||
if(m_tmp.write(m_downloadReply->readAll()) == -1) return;
|
||||
if(QFile(m_localPath).exists())
|
||||
QFile::remove(m_localPath);
|
||||
|
||||
if(!m_tmp.rename(m_localPath)) return;
|
||||
|
||||
computeHash(m_tmp);
|
||||
computeLocalHash(m_tmp);
|
||||
m_tmp.setAutoRemove(false);
|
||||
m_state = DOWNLOADED;
|
||||
emit stateChanged(m_state);
|
||||
};
|
||||
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal){
|
||||
if(m_tmp.write(m_downloadReply->readAll()) == -1) return;
|
||||
m_received = bytesReceived*100/bytesTotal;
|
||||
emit receivedChanged();
|
||||
emit receivedChanged(m_received);
|
||||
};
|
||||
void setDownloadUrl(QUrl url);
|
||||
void computeHash(QFile& file);
|
||||
void computeLocalHash(QFile& file);
|
||||
void requestHash(QUrl url);
|
||||
void computeRemoteHash();
|
||||
void handleStateChange(DownloadState state){
|
||||
#ifdef QT_WIDGET
|
||||
switch(state) {
|
||||
case DOWNLOADED:
|
||||
case NETWORK_ERROR:
|
||||
emit finished(0);
|
||||
break;
|
||||
case DOWNLOADING_HASH:
|
||||
break;
|
||||
case DOWNLOADING_FILE:
|
||||
show();
|
||||
break;
|
||||
}
|
||||
|
||||
#else
|
||||
emit stateStringChanged();
|
||||
#endif //QT_WIDGET
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
DownloadState m_state;
|
||||
QNetworkAccessManager m_WebCtrl;
|
||||
qint64 m_received;
|
||||
QTemporaryFile m_tmp;
|
||||
QString m_targetFile;
|
||||
QString m_localPath;
|
||||
QUrl m_downloadUrl;
|
||||
QString m_hash;
|
||||
QString m_localHash;
|
||||
QString m_remoteHash;
|
||||
bool m_OK;
|
||||
QString m_status;
|
||||
QNetworkReply* m_downloadReply;
|
||||
QNetworkReply* m_hashReply;
|
||||
};
|
||||
#ifndef QT_WIDGET
|
||||
QML_DECLARE_TYPEINFO(FileDownloader, QML_HAS_ATTACHED_PROPERTIES)
|
||||
#endif //QT_WIDGET
|
||||
|
||||
#endif // FILEDOWNLOADER_H
|
||||
|
||||
Reference in New Issue
Block a user