- 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:
Xawotihs
2012-01-15 18:50:38 +00:00
parent 9d99309b13
commit 12a431ff8c
13 changed files with 546 additions and 738 deletions
+64 -16
View File
@@ -2,10 +2,21 @@
#include <QDir>
#include <QCryptographicHash>
FileDownloader::FileDownloader(QString localPath, QObject *parent) :
QObject(parent), m_received(0), m_hash(""), m_OK(false)
FileDownloader::FileDownloader(QString localPath, QString targetFile, QObject *parent) :
#ifdef QT_WIDGET
QProgressDialog("Downloading resources", "", 0, 100, (QWidget*)parent, 0),
#else
QObject(parent),
#endif //QT_WIDGET
m_state(NETWORK_ERROR), m_received(0), m_targetFile(targetFile), m_localHash(""), m_OK(false)
{
#ifdef QT_WIDGET
setCancelButton(0);
#endif //QT_WIDGET
connect(this, SIGNAL(receivedChanged(int)), SLOT(setValue(int)));
connect(this, SIGNAL(stateChanged(DownloadState)), SLOT(handleStateChange(DownloadState)));
QDir dir(QDir::homePath());
if(!dir.mkpath(localPath))
{
@@ -17,27 +28,40 @@ FileDownloader::FileDownloader(QString localPath, QObject *parent) :
QFile local(m_localPath);
if(local.exists()) {
computeHash(local);
/* a file is already present in the local path */
computeLocalHash(local);
m_state = DOWNLOADED;
}
if(m_WebCtrl.networkAccessible()) {
/* Network is OK, we request the remote hash file */
m_state = DOWNLOADING_HASH;
requestHash(QUrl("http://code.google.com/p/wagic/downloads/detail?name="+m_targetFile));
}
emit stateChanged(m_state);
}
void FileDownloader::setDownloadUrl(QUrl url)
{
if((!url.isEmpty()) && url.toString() != m_downloadUrl.toString())
if((!url.isEmpty()))
{
connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)),
SLOT(fileDownloaded(QNetworkReply*)));
if(!m_WebCtrl.networkAccessible()) {
m_status = "Network not accessible, press retry when the network is accessible.";
emit statusChanged();
return;
}
QNetworkRequest request(url);
QNetworkReply* reply = m_WebCtrl.get(request);
m_downloadReply = m_WebCtrl.get(request);
connect(reply, SIGNAL(downloadProgress(qint64, qint64)),
connect(m_downloadReply, SIGNAL(downloadProgress(qint64, qint64)),
SLOT(downloadProgress(qint64, qint64)));
m_OK = m_tmp.open();
connect(m_downloadReply, SIGNAL(finished()), SLOT(fileDownloaded()));
m_status = "Downloading Resources";
m_downloadUrl.setUrl(url.toString());
emit downloadUrlChanged();
m_OK = m_tmp.open();
}
}
@@ -47,15 +71,39 @@ FileDownloader::~FileDownloader()
}
void FileDownloader::computeHash(QFile& file)
void FileDownloader::requestHash(QUrl url)
{
QNetworkRequest request(url);
m_hashReply = m_WebCtrl.get(request);
connect(m_hashReply, SIGNAL(finished()), SLOT(computeRemoteHash()));
}
void FileDownloader::computeRemoteHash()
{
QString aString = m_hashReply->readAll();
int index = aString.indexOf("SHA1 Checksum: ");
m_remoteHash = aString.mid(index+52, 40);
if(m_localHash != m_remoteHash)
{ /* We download the real file */
m_state = DOWNLOADING_FILE;
setDownloadUrl(QUrl("http://wagic.googlecode.com/files/" + m_targetFile));
}
else
{
m_state = DOWNLOADED;
}
emit stateChanged(m_state);
}
void FileDownloader::computeLocalHash(QFile& file)
{
QCryptographicHash crypto(QCryptographicHash::Sha1);
file.open(QFile::ReadOnly);
while(!file.atEnd()){
crypto.addData(file.read(8192));
crypto.addData(file.read(8192));
}
QByteArray hash = crypto.result();
m_hash = hash.toHex();
emit hashChanged();
m_localHash = hash.toHex();
}