- implemented the swipe and touch logic in QML
- Added a SHA1 hash verification of the downloaded resource file - Fixed the activation/deactivation of the QML UI to avoid burning the battery
This commit is contained in:
@@ -49,6 +49,12 @@ public:
|
||||
}
|
||||
};
|
||||
Q_INVOKABLE void pixelInput(int x, int y);
|
||||
Q_INVOKABLE qint64 getTick() {
|
||||
return g_startTimer.elapsed();
|
||||
};
|
||||
Q_INVOKABLE void doScroll(int x, int y) {
|
||||
m_engine->Scroll(x, y);
|
||||
};
|
||||
int getNominalHeight(){ return SCREEN_HEIGHT;};
|
||||
int getNominalWidth(){ return SCREEN_WIDTH;};
|
||||
float getNominalRatio() { return ((float)SCREEN_WIDTH / (float)SCREEN_HEIGHT);};
|
||||
|
||||
@@ -13,38 +13,38 @@
|
||||
class FileDownloader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool done READ isDone NOTIFY downloaded)
|
||||
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)
|
||||
public:
|
||||
explicit FileDownloader(QString localPath, QUrl url=QUrl(""), QObject *parent = 0);
|
||||
explicit FileDownloader(QString localPath, QObject *parent = 0);
|
||||
virtual ~FileDownloader();
|
||||
qint64 received() const {return m_received;};
|
||||
bool isDone() {return m_done;};
|
||||
QUrl getDownloadUrl() {return m_downloadUrl;};
|
||||
QString getHash() {return m_hash;};
|
||||
|
||||
signals:
|
||||
void downloaded();
|
||||
void receivedChanged();
|
||||
void downloadUrlChanged();
|
||||
void hashChanged();
|
||||
|
||||
private slots:
|
||||
void fileDownloaded(QNetworkReply* pReply){
|
||||
if(m_tmp.write(pReply->readAll()) == -1) return;
|
||||
if(QFile(m_localPath).exists())
|
||||
QFile::remove(m_localPath);
|
||||
|
||||
if(!m_tmp.rename(m_localPath)) return;
|
||||
|
||||
computeHash(m_tmp);
|
||||
m_tmp.setAutoRemove(false);
|
||||
|
||||
m_done = true;
|
||||
//emit a signal
|
||||
emit downloaded();
|
||||
};
|
||||
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal){
|
||||
m_received = bytesReceived*100/bytesTotal;
|
||||
emit receivedChanged();
|
||||
};
|
||||
void setDownloadUrl(QUrl url);
|
||||
void computeHash(QFile& file);
|
||||
|
||||
private:
|
||||
|
||||
@@ -53,8 +53,8 @@ private:
|
||||
QTemporaryFile m_tmp;
|
||||
QString m_localPath;
|
||||
QUrl m_downloadUrl;
|
||||
QString m_hash;
|
||||
bool m_OK;
|
||||
bool m_done;
|
||||
};
|
||||
QML_DECLARE_TYPEINFO(FileDownloader, QML_HAS_ATTACHED_PROPERTIES)
|
||||
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
#include <qplatformdefs.h>
|
||||
#include <QtOpenGL>
|
||||
|
||||
#if (defined FORCE_GLES)
|
||||
#undef GL_ES_VERSION_2_0
|
||||
#undef GL_VERSION_2_0
|
||||
#define GL_VERSION_ES_CM_1_1 1
|
||||
#ifndef GL_OES_VERSION_1_1
|
||||
#define glOrthof glOrtho
|
||||
#define glClearDepthf glClearDepth
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (defined FORCE_GLES)
|
||||
#undef GL_ES_VERSION_2_0
|
||||
#undef GL_VERSION_2_0
|
||||
#define GL_VERSION_ES_CM_1_1 1
|
||||
#define glOrthof glOrtho
|
||||
#define glClearDepthf glClearDepth
|
||||
#endif
|
||||
|
||||
|
||||
#include "corewrapper.h"
|
||||
|
||||
#define ACTUAL_SCREEN_WIDTH (SCREEN_WIDTH)
|
||||
@@ -38,10 +60,6 @@ WagicCore::WagicCore(QDeclarativeItem *parent) :
|
||||
setWidth(480);
|
||||
setHeight(272);
|
||||
|
||||
// BindKey is a static method, m_engine is not even initialized
|
||||
for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i)
|
||||
m_engine->BindKey(gDefaultBindings[i].keysym, gDefaultBindings[i].keycode);
|
||||
|
||||
g_startTimer.restart();
|
||||
m_lastTickCount = g_startTimer.elapsed();
|
||||
}
|
||||
@@ -125,7 +143,7 @@ void WagicCore::setActive(bool active)
|
||||
if(!m_active && active)
|
||||
{
|
||||
m_engine->Resume();
|
||||
#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID)
|
||||
#if (defined Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID)
|
||||
// 30 fps max on mobile
|
||||
m_timerId = startTimer(33);
|
||||
#else
|
||||
@@ -138,8 +156,8 @@ void WagicCore::setActive(bool active)
|
||||
else if(m_active && !active)
|
||||
{
|
||||
m_engine->Pause();
|
||||
#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID)
|
||||
killTimer(timerId);
|
||||
#if (defined Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID)
|
||||
killTimer(m_timerId);
|
||||
#endif
|
||||
m_active = active;
|
||||
emit activeChanged();
|
||||
@@ -250,11 +268,11 @@ void WagicCore::keyPressEvent(QKeyEvent *event)
|
||||
#if (defined Q_WS_MAEMO_5)
|
||||
case Qt::Key_F7:
|
||||
/* interrupt please */
|
||||
g_engine->HoldKey_NoRepeat(JGE_BTN_SEC);
|
||||
m_engine->HoldKey_NoRepeat(JGE_BTN_SEC);
|
||||
break;
|
||||
case Qt::Key_F8:
|
||||
/* next phase please */
|
||||
g_engine->HoldKey_NoRepeat(JGE_BTN_PREV);
|
||||
m_engine->HoldKey_NoRepeat(JGE_BTN_PREV);
|
||||
break;
|
||||
#endif // Q_WS_MAEMO_5
|
||||
case Qt::Key_F:
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include "filedownloader.h"
|
||||
#include <QDir>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
FileDownloader::FileDownloader(QString localPath, QUrl url, QObject *parent) :
|
||||
QObject(parent), m_received(0), m_OK(false), m_done(false)
|
||||
FileDownloader::FileDownloader(QString localPath, QObject *parent) :
|
||||
QObject(parent), m_received(0), m_hash(""), m_OK(false)
|
||||
|
||||
{
|
||||
QDir dir(QDir::homePath());
|
||||
@@ -16,25 +17,28 @@ FileDownloader::FileDownloader(QString localPath, QUrl url, QObject *parent) :
|
||||
|
||||
QFile local(m_localPath);
|
||||
if(local.exists()) {
|
||||
m_done = true;
|
||||
return;
|
||||
computeHash(local);
|
||||
}
|
||||
if(!url.isEmpty())
|
||||
setDownloadUrl(url);
|
||||
}
|
||||
|
||||
void FileDownloader::setDownloadUrl(QUrl url)
|
||||
{
|
||||
connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)),
|
||||
SLOT(fileDownloaded(QNetworkReply*)));
|
||||
if((!url.isEmpty()) && url.toString() != m_downloadUrl.toString())
|
||||
{
|
||||
connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)),
|
||||
SLOT(fileDownloaded(QNetworkReply*)));
|
||||
|
||||
QNetworkRequest request(url);
|
||||
QNetworkReply* reply = m_WebCtrl.get(request);
|
||||
QNetworkRequest request(url);
|
||||
QNetworkReply* reply = m_WebCtrl.get(request);
|
||||
|
||||
connect(reply, SIGNAL(downloadProgress(qint64, qint64)),
|
||||
SLOT(downloadProgress(qint64, qint64)));
|
||||
connect(reply, SIGNAL(downloadProgress(qint64, qint64)),
|
||||
SLOT(downloadProgress(qint64, qint64)));
|
||||
|
||||
m_OK = m_tmp.open();
|
||||
m_OK = m_tmp.open();
|
||||
|
||||
m_downloadUrl.setUrl(url.toString());
|
||||
emit downloadUrlChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,3 +46,16 @@ FileDownloader::~FileDownloader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FileDownloader::computeHash(QFile& file)
|
||||
{
|
||||
QCryptographicHash crypto(QCryptographicHash::Sha1);
|
||||
file.open(QFile::ReadOnly);
|
||||
while(!file.atEnd()){
|
||||
crypto.addData(file.read(8192));
|
||||
}
|
||||
QByteArray hash = crypto.result();
|
||||
|
||||
m_hash = hash.toHex();
|
||||
emit hashChanged();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user