- 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 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 getNominalHeight(){ return SCREEN_HEIGHT;};
|
||||||
int getNominalWidth(){ return SCREEN_WIDTH;};
|
int getNominalWidth(){ return SCREEN_WIDTH;};
|
||||||
float getNominalRatio() { return ((float)SCREEN_WIDTH / (float)SCREEN_HEIGHT);};
|
float getNominalRatio() { return ((float)SCREEN_WIDTH / (float)SCREEN_HEIGHT);};
|
||||||
|
|||||||
@@ -13,38 +13,38 @@
|
|||||||
class FileDownloader : public QObject
|
class FileDownloader : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool done READ isDone NOTIFY downloaded)
|
|
||||||
Q_PROPERTY(qint64 received READ received NOTIFY receivedChanged)
|
Q_PROPERTY(qint64 received READ received NOTIFY receivedChanged)
|
||||||
Q_PROPERTY(QUrl url READ getDownloadUrl WRITE setDownloadUrl NOTIFY downloadUrlChanged)
|
Q_PROPERTY(QUrl url READ getDownloadUrl WRITE setDownloadUrl NOTIFY downloadUrlChanged)
|
||||||
|
Q_PROPERTY(QString hash READ getHash NOTIFY hashChanged)
|
||||||
public:
|
public:
|
||||||
explicit FileDownloader(QString localPath, QUrl url=QUrl(""), QObject *parent = 0);
|
explicit FileDownloader(QString localPath, QObject *parent = 0);
|
||||||
virtual ~FileDownloader();
|
virtual ~FileDownloader();
|
||||||
qint64 received() const {return m_received;};
|
qint64 received() const {return m_received;};
|
||||||
bool isDone() {return m_done;};
|
|
||||||
QUrl getDownloadUrl() {return m_downloadUrl;};
|
QUrl getDownloadUrl() {return m_downloadUrl;};
|
||||||
|
QString getHash() {return m_hash;};
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void downloaded();
|
|
||||||
void receivedChanged();
|
void receivedChanged();
|
||||||
void downloadUrlChanged();
|
void downloadUrlChanged();
|
||||||
|
void hashChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void fileDownloaded(QNetworkReply* pReply){
|
void fileDownloaded(QNetworkReply* pReply){
|
||||||
if(m_tmp.write(pReply->readAll()) == -1) return;
|
if(m_tmp.write(pReply->readAll()) == -1) return;
|
||||||
|
if(QFile(m_localPath).exists())
|
||||||
|
QFile::remove(m_localPath);
|
||||||
|
|
||||||
if(!m_tmp.rename(m_localPath)) return;
|
if(!m_tmp.rename(m_localPath)) return;
|
||||||
|
|
||||||
|
computeHash(m_tmp);
|
||||||
m_tmp.setAutoRemove(false);
|
m_tmp.setAutoRemove(false);
|
||||||
|
|
||||||
m_done = true;
|
|
||||||
//emit a signal
|
|
||||||
emit downloaded();
|
|
||||||
};
|
};
|
||||||
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal){
|
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal){
|
||||||
m_received = bytesReceived*100/bytesTotal;
|
m_received = bytesReceived*100/bytesTotal;
|
||||||
emit receivedChanged();
|
emit receivedChanged();
|
||||||
};
|
};
|
||||||
void setDownloadUrl(QUrl url);
|
void setDownloadUrl(QUrl url);
|
||||||
|
void computeHash(QFile& file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -53,8 +53,8 @@ private:
|
|||||||
QTemporaryFile m_tmp;
|
QTemporaryFile m_tmp;
|
||||||
QString m_localPath;
|
QString m_localPath;
|
||||||
QUrl m_downloadUrl;
|
QUrl m_downloadUrl;
|
||||||
|
QString m_hash;
|
||||||
bool m_OK;
|
bool m_OK;
|
||||||
bool m_done;
|
|
||||||
};
|
};
|
||||||
QML_DECLARE_TYPEINFO(FileDownloader, QML_HAS_ATTACHED_PROPERTIES)
|
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"
|
#include "corewrapper.h"
|
||||||
|
|
||||||
#define ACTUAL_SCREEN_WIDTH (SCREEN_WIDTH)
|
#define ACTUAL_SCREEN_WIDTH (SCREEN_WIDTH)
|
||||||
@@ -38,10 +60,6 @@ WagicCore::WagicCore(QDeclarativeItem *parent) :
|
|||||||
setWidth(480);
|
setWidth(480);
|
||||||
setHeight(272);
|
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();
|
g_startTimer.restart();
|
||||||
m_lastTickCount = g_startTimer.elapsed();
|
m_lastTickCount = g_startTimer.elapsed();
|
||||||
}
|
}
|
||||||
@@ -125,7 +143,7 @@ void WagicCore::setActive(bool active)
|
|||||||
if(!m_active && active)
|
if(!m_active && active)
|
||||||
{
|
{
|
||||||
m_engine->Resume();
|
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
|
// 30 fps max on mobile
|
||||||
m_timerId = startTimer(33);
|
m_timerId = startTimer(33);
|
||||||
#else
|
#else
|
||||||
@@ -138,8 +156,8 @@ void WagicCore::setActive(bool active)
|
|||||||
else if(m_active && !active)
|
else if(m_active && !active)
|
||||||
{
|
{
|
||||||
m_engine->Pause();
|
m_engine->Pause();
|
||||||
#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)
|
||||||
killTimer(timerId);
|
killTimer(m_timerId);
|
||||||
#endif
|
#endif
|
||||||
m_active = active;
|
m_active = active;
|
||||||
emit activeChanged();
|
emit activeChanged();
|
||||||
@@ -250,11 +268,11 @@ void WagicCore::keyPressEvent(QKeyEvent *event)
|
|||||||
#if (defined Q_WS_MAEMO_5)
|
#if (defined Q_WS_MAEMO_5)
|
||||||
case Qt::Key_F7:
|
case Qt::Key_F7:
|
||||||
/* interrupt please */
|
/* interrupt please */
|
||||||
g_engine->HoldKey_NoRepeat(JGE_BTN_SEC);
|
m_engine->HoldKey_NoRepeat(JGE_BTN_SEC);
|
||||||
break;
|
break;
|
||||||
case Qt::Key_F8:
|
case Qt::Key_F8:
|
||||||
/* next phase please */
|
/* next phase please */
|
||||||
g_engine->HoldKey_NoRepeat(JGE_BTN_PREV);
|
m_engine->HoldKey_NoRepeat(JGE_BTN_PREV);
|
||||||
break;
|
break;
|
||||||
#endif // Q_WS_MAEMO_5
|
#endif // Q_WS_MAEMO_5
|
||||||
case Qt::Key_F:
|
case Qt::Key_F:
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#include "filedownloader.h"
|
#include "filedownloader.h"
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
FileDownloader::FileDownloader(QString localPath, QUrl url, QObject *parent) :
|
FileDownloader::FileDownloader(QString localPath, QObject *parent) :
|
||||||
QObject(parent), m_received(0), m_OK(false), m_done(false)
|
QObject(parent), m_received(0), m_hash(""), m_OK(false)
|
||||||
|
|
||||||
{
|
{
|
||||||
QDir dir(QDir::homePath());
|
QDir dir(QDir::homePath());
|
||||||
@@ -16,25 +17,28 @@ FileDownloader::FileDownloader(QString localPath, QUrl url, QObject *parent) :
|
|||||||
|
|
||||||
QFile local(m_localPath);
|
QFile local(m_localPath);
|
||||||
if(local.exists()) {
|
if(local.exists()) {
|
||||||
m_done = true;
|
computeHash(local);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if(!url.isEmpty())
|
|
||||||
setDownloadUrl(url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileDownloader::setDownloadUrl(QUrl url)
|
void FileDownloader::setDownloadUrl(QUrl url)
|
||||||
{
|
{
|
||||||
connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)),
|
if((!url.isEmpty()) && url.toString() != m_downloadUrl.toString())
|
||||||
SLOT(fileDownloaded(QNetworkReply*)));
|
{
|
||||||
|
connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)),
|
||||||
|
SLOT(fileDownloaded(QNetworkReply*)));
|
||||||
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
QNetworkReply* reply = m_WebCtrl.get(request);
|
QNetworkReply* reply = m_WebCtrl.get(request);
|
||||||
|
|
||||||
connect(reply, SIGNAL(downloadProgress(qint64, qint64)),
|
connect(reply, SIGNAL(downloadProgress(qint64, qint64)),
|
||||||
SLOT(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();
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,10 +7,13 @@ Rectangle {
|
|||||||
height: 272
|
height: 272
|
||||||
state: "DOWNLOADING"
|
state: "DOWNLOADING"
|
||||||
color: "black"
|
color: "black"
|
||||||
|
property url resource: "http://wagic.googlecode.com/files/core_017.zip"
|
||||||
|
property string hash: "cc6f9415f747acea500cdce190f0df6ee41db7cb"
|
||||||
|
|
||||||
states: [
|
states: [
|
||||||
State {
|
State {
|
||||||
name: "DOWNLOADING"
|
name: "DOWNLOADING"
|
||||||
|
when: (fileDownloader.hash != hash)
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: column1; visible: true
|
target: column1; visible: true
|
||||||
}
|
}
|
||||||
@@ -18,12 +21,12 @@ Rectangle {
|
|||||||
target: wagic; visible: false
|
target: wagic; visible: false
|
||||||
}
|
}
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target:fileDownloader; url: "http://wagic.googlecode.com/files/core_017.zip"
|
target:fileDownloader; url: resource
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "NORMAL"
|
name: "NORMAL"
|
||||||
when: (fileDownloader.done == true)
|
when: (fileDownloader.hash == hash)
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: column1; visible: false
|
target: column1; visible: false
|
||||||
}
|
}
|
||||||
@@ -72,7 +75,7 @@ Rectangle {
|
|||||||
id: wagic
|
id: wagic
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
visible: false
|
visible: false
|
||||||
active: Qt.WindowActive
|
active: Qt.application.active
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
Rectangle {
|
Rectangle {
|
||||||
@@ -87,6 +90,9 @@ Rectangle {
|
|||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
|
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
|
||||||
|
property int lastTick: 0
|
||||||
|
property int lastX: 0
|
||||||
|
property int lastY: 0
|
||||||
|
|
||||||
onPositionChanged: {
|
onPositionChanged: {
|
||||||
wagic.pixelInput(
|
wagic.pixelInput(
|
||||||
@@ -95,18 +101,36 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onPressed: {
|
onPressed: {
|
||||||
if(mouse.button == Qt.LeftButton)
|
wagic.pixelInput(
|
||||||
wagic.doOK()
|
(mouse.x*wagic.nominalWidth)/width,
|
||||||
else if(mouse.button == Qt.MiddleButton)
|
(mouse.y*wagic.nominalHeight)/height)
|
||||||
|
|
||||||
|
if(mouse.button == Qt.LeftButton) {
|
||||||
|
lastTick = wagic.getTick()
|
||||||
|
lastX = mouse.x
|
||||||
|
lastY = mouse.y
|
||||||
|
} else if(mouse.button == Qt.MiddleButton)
|
||||||
wagic.doCancel()
|
wagic.doCancel()
|
||||||
else if(mouse.button == Qt.RightButton)
|
else if(mouse.button == Qt.RightButton)
|
||||||
wagic.doNext()
|
wagic.doNext()
|
||||||
}
|
}
|
||||||
|
|
||||||
onReleased: {
|
onReleased: {
|
||||||
if(mouse.button == Qt.LeftButton)
|
if(mouse.button == Qt.LeftButton) {
|
||||||
wagic.done()
|
var currentTick = wagic.getTick()
|
||||||
else if(mouse.button == Qt.MiddleButton)
|
if(currentTick - lastTick <= 250 )
|
||||||
|
{
|
||||||
|
if(Math.abs(lastX-mouse.x) < 50 && Math.abs(lastY-mouse.y) < 50 )
|
||||||
|
{
|
||||||
|
wagic.doOK()
|
||||||
|
// wagic.done()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(currentTick - lastTick >= 250)
|
||||||
|
{
|
||||||
|
wagic.doScroll(mouse.x - lastX, mouse.y - lastY)
|
||||||
|
}
|
||||||
|
} else if(mouse.button == Qt.MiddleButton)
|
||||||
wagic.done()
|
wagic.done()
|
||||||
else if(mouse.button == Qt.RightButton)
|
else if(mouse.button == Qt.RightButton)
|
||||||
wagic.done()
|
wagic.done()
|
||||||
|
|||||||
Reference in New Issue
Block a user