summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2014-12-14 03:26:46 +0100
committerJavier <dev.git@javispedro.com>2014-12-14 03:26:46 +0100
commitf40514fe681f5163deb5f579140ef4f7ac77f5a8 (patch)
treec3edddde3cbc98a797d5a1a7b745c2c5d3b99eba /app
parentdf30ca18eebd2dfec03c589b607d45a5891cf2b2 (diff)
add icons to the slots managament UI
Diffstat (limited to 'app')
-rw-r--r--app/app.pro8
-rw-r--r--app/pebble.cpp12
-rw-r--r--app/pebbleappiconprovider.cpp28
-rw-r--r--app/pebbleappiconprovider.h18
-rw-r--r--app/pebbledinterface.cpp18
-rw-r--r--app/pebbledinterface.h6
-rw-r--r--app/qml/pages/AppConfigPage.qml14
-rw-r--r--app/qml/pages/InstallAppDialog.qml17
-rw-r--r--app/qml/pages/WatchPage.qml49
-rw-r--r--app/qml/pebble.qml4
10 files changed, 145 insertions, 29 deletions
diff --git a/app/app.pro b/app/app.pro
index d375800..48fcf68 100644
--- a/app/app.pro
+++ b/app/app.pro
@@ -3,16 +3,18 @@ TARGET = pebble
CONFIG += sailfishapp
QT += dbus
-QMAKE_CXXFLAGS += -std=c++0x
+CONFIG += c++11
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
SOURCES += \
pebble.cpp \
- pebbledinterface.cpp
+ pebbledinterface.cpp \
+ pebbleappiconprovider.cpp
HEADERS += \
- pebbledinterface.h
+ pebbledinterface.h \
+ pebbleappiconprovider.h
DBUS_INTERFACES += ../org.pebbled.Watch.xml
diff --git a/app/pebble.cpp b/app/pebble.cpp
index 44f1aeb..41da080 100644
--- a/app/pebble.cpp
+++ b/app/pebble.cpp
@@ -33,16 +33,22 @@
#include <sailfishapp.h>
#include "pebbledinterface.h"
+#include "pebbleappiconprovider.h"
int main(int argc, char *argv[])
{
- // Register Pebble daemon interface object on QML side
- qmlRegisterType<PebbledInterface>("org.pebbled", 0, 1, "PebbledInterface");
-
QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
+ qmlRegisterUncreatableType<PebbledInterface>("org.pebbled", 0, 1, "PebbledInterface",
+ "Please use pebbled context property");
+
QScopedPointer<QQuickView> view(SailfishApp::createView());
+ QScopedPointer<PebbledInterface> pebbled(new PebbledInterface);
+ QScopedPointer<PebbleAppIconProvider> appicons(new PebbleAppIconProvider(pebbled.data()));
+
view->rootContext()->setContextProperty("APP_VERSION", APP_VERSION);
+ view->rootContext()->setContextProperty("pebbled", pebbled.data());
+ view->engine()->addImageProvider("pebble-app-icon", appicons.data());
view->setSource(SailfishApp::pathTo("qml/pebble.qml"));
view->show();
diff --git a/app/pebbleappiconprovider.cpp b/app/pebbleappiconprovider.cpp
new file mode 100644
index 0000000..0e694ff
--- /dev/null
+++ b/app/pebbleappiconprovider.cpp
@@ -0,0 +1,28 @@
+#include <QDebug>
+#include <QUrl>
+#include "pebbleappiconprovider.h"
+
+PebbleAppIconProvider::PebbleAppIconProvider(PebbledInterface *interface)
+ : QQuickImageProvider(QQmlImageProviderBase::Image), pebbled(interface)
+{
+}
+
+QImage PebbleAppIconProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
+{
+ QUuid uuid(QUrl::fromPercentEncoding(id.toLatin1()));
+ QImage img = pebbled->menuIconForApp(uuid);
+
+ if (requestedSize.width() > 0 && requestedSize.height() > 0) {
+ img = img.scaled(requestedSize, Qt::KeepAspectRatio);
+ } else if (requestedSize.width() > 0) {
+ img = img.scaledToWidth(requestedSize.width());
+ } else if (requestedSize.height() > 0) {
+ img = img.scaledToHeight(requestedSize.height());
+ }
+
+ if (size) {
+ *size = img.size();
+ }
+
+ return img;
+}
diff --git a/app/pebbleappiconprovider.h b/app/pebbleappiconprovider.h
new file mode 100644
index 0000000..c76641a
--- /dev/null
+++ b/app/pebbleappiconprovider.h
@@ -0,0 +1,18 @@
+#ifndef PEBBLEAPPICONPROVIDER_H
+#define PEBBLEAPPICONPROVIDER_H
+
+#include <QQuickImageProvider>
+#include "pebbledinterface.h"
+
+class PebbleAppIconProvider : public QQuickImageProvider
+{
+public:
+ explicit PebbleAppIconProvider(PebbledInterface *interface);
+
+ QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
+
+private:
+ PebbledInterface *pebbled;
+};
+
+#endif // PEBBLEAPPICONPROVIDER_H
diff --git a/app/pebbledinterface.cpp b/app/pebbledinterface.cpp
index 588e24a..c978dd0 100644
--- a/app/pebbledinterface.cpp
+++ b/app/pebbledinterface.cpp
@@ -183,7 +183,7 @@ QUrl PebbledInterface::configureApp(const QString &uuid)
}
}
-bool PebbledInterface::isAppInstalled(const QString &uuid)
+bool PebbledInterface::isAppInstalled(const QString &uuid) const
{
QUuid u(uuid);
@@ -196,6 +196,11 @@ bool PebbledInterface::isAppInstalled(const QString &uuid)
return false;
}
+QImage PebbledInterface::menuIconForApp(const QUuid &uuid) const
+{
+ return _appMenuIcons.value(uuid);
+}
+
void PebbledInterface::setAppConfiguration(const QString &uuid, const QString &data)
{
qDebug() << Q_FUNC_INFO << uuid << data;
@@ -210,8 +215,11 @@ void PebbledInterface::launchApp(const QString &uuid)
// TODO Terrible hack; need to give time for the watch to open the app
// A better solution would be to wait until AppUuidChanged is generated.
+ QUuid u(uuid);
+ if (u.isNull()) return;
int sleep_count = 0;
- while (watch->appUuid() != uuid && sleep_count < 5) {
+ while (QUuid(watch->appUuid()) != u && sleep_count < 5) {
+ qDebug() << "Waiting for" << u.toString() << "to launch";
QThread::sleep(1);
sleep_count++;
}
@@ -271,6 +279,7 @@ void PebbledInterface::refreshAllApps()
{
_apps.clear();
_appsByUuid.clear();
+ _appMenuIcons.clear();
qDebug() << "refreshing all apps list";
@@ -288,6 +297,11 @@ void PebbledInterface::refreshAllApps()
m.insert("shortName", orig.value("short-name"));
m.insert("longName", orig.value("long-name"));
+ QByteArray pngIcon = orig.value("menu-icon").toByteArray();
+ if (!pngIcon.isEmpty()) {
+ _appMenuIcons.insert(uuid, QImage::fromData(pngIcon, "PNG"));
+ }
+
_apps.append(QVariant::fromValue(m));
}
diff --git a/app/pebbledinterface.h b/app/pebbledinterface.h
index e468505..51efa12 100644
--- a/app/pebbledinterface.h
+++ b/app/pebbledinterface.h
@@ -5,6 +5,7 @@
#include <QUrl>
#include <QHash>
#include <QUuid>
+#include <QImage>
#include <QDBusInterface>
class OrgPebbledWatchInterface;
@@ -39,7 +40,9 @@ public:
Q_INVOKABLE QUrl configureApp(const QString &uuid);
- Q_INVOKABLE bool isAppInstalled(const QString &uuid);
+ Q_INVOKABLE bool isAppInstalled(const QString &uuid) const;
+
+ QImage menuIconForApp(const QUuid &uuid) const;
signals:
void enabledChanged();
@@ -82,6 +85,7 @@ private:
QStringList _appSlots;
QVariantList _apps;
QHash<QUuid, int> _appsByUuid;
+ QHash<QUuid, QImage> _appMenuIcons;
};
#endif // PEBBLEDINTERFACE_H
diff --git a/app/qml/pages/AppConfigPage.qml b/app/qml/pages/AppConfigPage.qml
index 10fbe05..00eb05c 100644
--- a/app/qml/pages/AppConfigPage.qml
+++ b/app/qml/pages/AppConfigPage.qml
@@ -11,6 +11,7 @@ Page {
SilicaWebView {
id: webview
+ visible: url != ""
anchors.fill: parent
header: PageHeader {
@@ -32,8 +33,17 @@ Page {
}
}
- ViewPlaceholder {
- enabled: url == ""
+ Text {
+ anchors.centerIn: parent
+ visible: url == ""
text: qsTr("No configuration settings available")
+ width: parent.width - 2*Theme.paddingLarge
+ horizontalAlignment: Text.AlignHCenter
+ wrapMode: Text.Wrap
+ font {
+ pixelSize: Theme.fontSizeLarge
+ family: Theme.fontFamilyHeading
+ }
+ color: Theme.highlightColor
}
}
diff --git a/app/qml/pages/InstallAppDialog.qml b/app/qml/pages/InstallAppDialog.qml
index 3a3c0b1..79283a6 100644
--- a/app/qml/pages/InstallAppDialog.qml
+++ b/app/qml/pages/InstallAppDialog.qml
@@ -27,20 +27,29 @@ Dialog {
property string uuid: modelData.uuid
property bool alreadyInstalled: pebbled.isAppInstalled(uuid)
- Image {
- id: appImage
+ Item {
+ id: appIcon
+ width: Theme.itemSizeSmall
+ height: Theme.itemSizeSmall
+
anchors {
top: parent.top
left: parent.left
leftMargin: Theme.paddingLarge
}
- width: Theme.itemSizeSmall
+
+ Image {
+ id: appImage
+ anchors.centerIn: parent
+ source: "image://pebble-app-icon/" + uuid;
+ scale: 2
+ }
}
Label {
id: appName
anchors {
- left: appImage.right
+ left: appIcon.right
leftMargin: Theme.paddingMedium
right: parent.right
rightMargin: Theme.paddiumLarge
diff --git a/app/qml/pages/WatchPage.qml b/app/qml/pages/WatchPage.qml
index ce9d636..3a712ab 100644
--- a/app/qml/pages/WatchPage.qml
+++ b/app/qml/pages/WatchPage.qml
@@ -77,7 +77,8 @@ Page {
}
Item {
- height: Theme.paddingMedium
+ width: parent.width
+ height: Theme.paddingLarge
}
Label {
@@ -139,26 +140,49 @@ Page {
}
- Image {
- id: slotImage
+ Item {
+ id: slotIcon
+ width: Theme.itemSizeSmall
+ height: Theme.itemSizeSmall
+
anchors {
top: parent.top
left: parent.left
leftMargin: Theme.paddingLarge
}
- width: Theme.itemSizeSmall
- }
- BusyIndicator {
- id: slotBusy
- anchors.centerIn: slotImage
- running: slotDelegate.busy
+ Image {
+ id: slotImage
+ anchors.centerIn: parent
+ source: isKnownApp ? "image://pebble-app-icon/" + modelData : ""
+ scale: 2
+ visible: !isEmptySlot && isKnownApp && !slotBusy.running
+ }
+
+ Rectangle {
+ width: 30
+ height: 30
+ anchors.centerIn: parent
+ scale: 2
+ border {
+ width: 2
+ color: slotDelegate.highlighted ? Theme.highlightColor : Theme.primaryColor
+ }
+ color: "transparent"
+ visible: isEmptySlot && !slotBusy.running
+ }
+
+ BusyIndicator {
+ id: slotBusy
+ anchors.centerIn: parent
+ running: slotDelegate.busy
+ }
}
Label {
id: slotName
anchors {
- left: slotImage.right
+ left: slotIcon.right
leftMargin: Theme.paddingMedium
right: parent.right
rightMargin: Theme.paddiumLarge
@@ -173,6 +197,11 @@ Page {
id: slotMenu
ContextMenu {
MenuItem {
+ text: qsTr("Install app...")
+ visible: isEmptySlot
+ onClicked: install();
+ }
+ MenuItem {
text: qsTr("Configure...")
visible: !isEmptySlot && isKnownApp
onClicked: configure();
diff --git a/app/qml/pebble.qml b/app/qml/pebble.qml
index da3bfb5..2e26ebe 100644
--- a/app/qml/pebble.qml
+++ b/app/qml/pebble.qml
@@ -38,8 +38,4 @@ ApplicationWindow
{
initialPage: Component { ManagerPage { } }
cover: Qt.resolvedUrl("cover/CoverPage.qml")
-
- PebbledInterface {
- id: pebbled
- }
}