summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Andreas <github@smurfy.de>2015-01-14 02:10:36 +0100
committerPhilipp Andreas <github@smurfy.de>2015-01-14 02:10:36 +0100
commit857d9547a9fc4a00c6e621fb54720d047ba90864 (patch)
treed6aa0a6ea8bf76e6da7d353ff6084db82d583fa9
parente8f9a4da6c486ee4da9ae300019856976ff0a760 (diff)
First prototype of pebble app store integration
-rw-r--r--app/app.pro11
-rw-r--r--app/pebble.cpp3
-rw-r--r--app/pebblestoreview.cpp50
-rw-r--r--app/pebblestoreview.h23
-rw-r--r--app/qml/pages/AppStorePage.qml24
-rw-r--r--app/qml/pages/ManagerPage.qml4
6 files changed, 111 insertions, 4 deletions
diff --git a/app/app.pro b/app/app.pro
index 97c6232..9600919 100644
--- a/app/app.pro
+++ b/app/app.pro
@@ -2,7 +2,7 @@ TARGET = pebble
CONFIG += sailfishapp
-QT += dbus
+QT += dbus webkit quick-private webkit-private
CONFIG += c++11
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
@@ -10,11 +10,13 @@ DEFINES += APP_VERSION=\\\"$$VERSION\\\"
SOURCES += \
pebble.cpp \
pebbledinterface.cpp \
- pebbleappiconprovider.cpp
+ pebbleappiconprovider.cpp \
+ pebblestoreview.cpp
HEADERS += \
pebbledinterface.h \
- pebbleappiconprovider.h
+ pebbleappiconprovider.h \
+ pebblestoreview.h
DBUS_INTERFACES += ../org.pebbled.Watch.xml
@@ -30,7 +32,8 @@ OTHER_FILES += \
qml/images/* \
translations/*.ts \
pebble.desktop \
- pebble.png
+ pebble.png \
+ qml/pages/AppStorePage.qml
CONFIG += sailfishapp_i18n
TRANSLATIONS += translations/pebble-es.ts
diff --git a/app/pebble.cpp b/app/pebble.cpp
index 22f6ac1..dd3c915 100644
--- a/app/pebble.cpp
+++ b/app/pebble.cpp
@@ -34,6 +34,7 @@
#include <sailfishapp.h>
#include "pebbledinterface.h"
#include "pebbleappiconprovider.h"
+#include "pebblestoreview.h"
int main(int argc, char *argv[])
{
@@ -48,6 +49,8 @@ int main(int argc, char *argv[])
qmlRegisterUncreatableType<PebbledInterface>("org.pebbled", 0, 1, "PebbledInterface",
"Please use pebbled context property");
+ qmlRegisterType<PebbleStoreView>("org.pebbled", 0, 1, "PebbleStoreView");
+
QScopedPointer<QQuickView> view(SailfishApp::createView());
QScopedPointer<PebbledInterface> pebbled(new PebbledInterface);
QScopedPointer<PebbleAppIconProvider> appicons(new PebbleAppIconProvider(pebbled.data()));
diff --git a/app/pebblestoreview.cpp b/app/pebblestoreview.cpp
new file mode 100644
index 0000000..011d056
--- /dev/null
+++ b/app/pebblestoreview.cpp
@@ -0,0 +1,50 @@
+#include "pebblestoreview.h"
+#include <QUrlQuery>
+#include <QJsonDocument>
+#include <QJsonObject>
+
+PebbleStoreView::PebbleStoreView()
+ : QQuickWebView()
+{
+ connect(this, SIGNAL(navigationRequested(QWebNavigationRequest*)), this, SLOT(onNavigationRequested(QWebNavigationRequest*)));
+}
+
+
+void PebbleStoreView::onNavigationRequested(QWebNavigationRequest* request)
+{
+ if (request->url().scheme() == "pebble") {
+ if (request->url().host() == "login") {
+ QUrlQuery *accessTokenFragment = new QUrlQuery(request->url().fragment());
+ qDebug()<<"login"<<accessTokenFragment->queryItemValue("access_token");
+ emit loginSuccess(accessTokenFragment->queryItemValue("access_token"));
+ }
+ }
+ if (request->url().scheme() == "pebble-method-call-js-frame") {
+ QString urlStr = "";
+
+ //Basic parse error string
+ QRegExp reg(".*; source was \"(.*)\";.*");
+ reg.setMinimal(true);
+ if (reg.indexIn(request->url().errorString()) > -1) {
+ urlStr = reg.cap(1);
+ reg.setPattern("method=(.*)&args=(.*)$");
+ reg.setMinimal(true);
+ if (reg.indexIn(urlStr) > -1) {
+ QString methodStr = reg.cap(1);
+ QString argsStr = QUrl::fromPercentEncoding(reg.cap(2).toUtf8());
+ emit call(methodStr, argsStr);
+ if (methodStr == "loadAppToDeviceAndLocker") {
+ QJsonDocument jsonResponse = QJsonDocument::fromJson(argsStr.toUtf8());
+ QJsonObject jsonObject = jsonResponse.object();
+ QJsonObject data = jsonObject.value("data").toObject();
+ qDebug()<<"download"<<data.value("title").toString()<<data.value("pbw_file").toString();
+ emit downloadPebbleApp(data.value("title").toString(), data.value("pbw_file").toString());
+ }
+ }
+ }
+ }
+}
+
+
+
+
diff --git a/app/pebblestoreview.h b/app/pebblestoreview.h
new file mode 100644
index 0000000..f0d18f6
--- /dev/null
+++ b/app/pebblestoreview.h
@@ -0,0 +1,23 @@
+#ifndef PEBBLESTOREVIEW_H
+#define PEBBLESTOREVIEW_H
+
+#include <private/qquickwebview_p.h>
+#include <private/qwebnavigationrequest_p.h>
+#include <QQuickItem>
+
+class PebbleStoreView : public QQuickWebView
+{
+ Q_OBJECT
+public:
+ PebbleStoreView();
+
+public slots:
+ void onNavigationRequested(QWebNavigationRequest* request);
+
+signals:
+ void loginSuccess(const QString & accessToken);
+ void downloadPebbleApp(const QString & title, const QString & downloadUrl);
+ void call(const QString &, const QString &);
+};
+
+#endif // PEBBLESTOREVIEW_H
diff --git a/app/qml/pages/AppStorePage.qml b/app/qml/pages/AppStorePage.qml
new file mode 100644
index 0000000..95bb2db
--- /dev/null
+++ b/app/qml/pages/AppStorePage.qml
@@ -0,0 +1,24 @@
+import QtQuick 2.0
+import QtQml 2.1
+import Sailfish.Silica 1.0
+import org.pebbled 0.1
+
+Page {
+ id: page
+
+ PebbleStoreView {
+ id: webview
+ anchors.fill: parent
+ url: "https://auth.getpebble.com/oauth/authorize?client_id=f88739e8e7a696c411236c41afc81cbef16dc54c3ff633d92dd4ceb0e5a25e5f&response_type=token&mid=xxx&pid=xxx&platform=android&mobile=sign_in&redirect_uri=pebble%3A%2F%2Flogin"
+
+ onLoginSuccess: {
+ console.log("ON Login " + accessToken);
+ webview.url = "https://apps-prod.getpebble.com/en_US/?access_token=" + accessToken + "#/watchfaces"
+ }
+
+ onDownloadPebbleApp: {
+ console.log("ON DOWNLOAD " + title);
+ console.log(downloadUrl);
+ }
+ }
+}
diff --git a/app/qml/pages/ManagerPage.qml b/app/qml/pages/ManagerPage.qml
index 814c9d8..c0dd411 100644
--- a/app/qml/pages/ManagerPage.qml
+++ b/app/qml/pages/ManagerPage.qml
@@ -65,6 +65,10 @@ Page {
text: qsTr("About")
onClicked: pageStack.push(Qt.resolvedUrl("AboutPage.qml"))
}
+ MenuItem {
+ text: qsTr("Pebble Appstore")
+ onClicked: pageStack.push(Qt.resolvedUrl("AppStorePage.qml"))
+ }
}
Column {