summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJavier S. Pedro <dev.git@javispedro.com>2014-09-06 03:25:38 +0200
committerJavier S. Pedro <dev.git@javispedro.com>2014-09-06 03:25:38 +0200
commited40a7f1cbc1da5ae21c58882df241fc0071c2f7 (patch)
treea3e34febb658c4cc5b631577d685361ab489678a /src
parent643db0927177037646b61cc4af21b9af1428b0e4 (diff)
downloadsalmeta-ed40a7f1cbc1da5ae21c58882df241fc0071c2f7.tar.gz
salmeta-ed40a7f1cbc1da5ae21c58882df241fc0071c2f7.zip
adding initial UI to select device
Diffstat (limited to 'src')
-rw-r--r--src/controller.cpp7
-rw-r--r--src/reconnecttimer.cpp27
-rw-r--r--src/reconnecttimer.h7
-rw-r--r--src/salmeta.cpp10
-rw-r--r--src/watchviewitem.cpp15
-rw-r--r--src/watchviewitem.h20
6 files changed, 59 insertions, 27 deletions
diff --git a/src/controller.cpp b/src/controller.cpp
index 02c8252..047ad96 100644
--- a/src/controller.cpp
+++ b/src/controller.cpp
@@ -22,10 +22,11 @@ Controller::Controller(const QString &settingsPrefix, QQuickView *view, QObject
connect(_settings, &MDConfGroup::valueChanged, this, &Controller::handleSettingChanged);
connect(_metawatch, &MetaWatch::connected, _reconnect, &ReconnectTimer::stop);
connect(_metawatch, &MetaWatch::connected, this, &Controller::handleMetaWatchConnected);
- connect(_metawatch, &MetaWatch::disconnected, _reconnect, &ReconnectTimer::start);
+ connect(_metawatch, &MetaWatch::disconnected, _reconnect, &ReconnectTimer::scheduleNextAttempt);
connect(_metawatch, &MetaWatch::batteryStatus, this, &Controller::handleMetaWatchBatteryStatus);
- connect(_reconnect, &ReconnectTimer::tick, _metawatch, &MetaWatch::connectDevice);
- _reconnect->start();
+ connect(_reconnect, &ReconnectTimer::tryReconnect, _metawatch, &MetaWatch::connectDevice);
+
+ _reconnect->scheduleNextAttempt();
reloadPages();
}
diff --git a/src/reconnecttimer.cpp b/src/reconnecttimer.cpp
index eaf6cbb..a58a13e 100644
--- a/src/reconnecttimer.cpp
+++ b/src/reconnecttimer.cpp
@@ -15,33 +15,33 @@ ReconnectTimer::ReconnectTimer(QObject *parent)
: QObject(parent),
_iphb(iphb_open(0)),
_notifier(new QSocketNotifier(iphb_get_fd(_iphb), QSocketNotifier::Read, this)),
- _active(false)
+ _active(false),
+ _counter(0)
{
connect(_notifier, &QSocketNotifier::activated, this, &ReconnectTimer::handleIphbActivity);
}
ReconnectTimer::~ReconnectTimer()
{
- iphb_close(_iphb);
+ _active = false;
+ _iphb = iphb_close(_iphb);
}
-void ReconnectTimer::start()
+void ReconnectTimer::scheduleNextAttempt()
{
_active = true;
- _counter = 0;
- setupWait();
+
+ time_t res = iphb_wait2(_iphb, wait_times[_counter] / 2, wait_times[_counter], 0, 0);
+
+ if (res == -1) {
+ qErrnoWarning("Failed to iphb_wait");
+ }
}
void ReconnectTimer::stop()
{
_active = false;
_counter = 0;
- iphb_wait(_iphb, 0, 0, 0);
-}
-
-void ReconnectTimer::setupWait()
-{
- iphb_wait(_iphb, wait_times[_counter] / 2, wait_times[_counter], 0);
}
void ReconnectTimer::handleIphbActivity()
@@ -55,10 +55,9 @@ void ReconnectTimer::handleIphbActivity()
return;
}
- emit tick();
-
+ _active = false;
if (++_counter > num_wait_times)
_counter = num_wait_times;
- setupWait();
+ emit tryReconnect();
}
diff --git a/src/reconnecttimer.h b/src/reconnecttimer.h
index c8d901f..af4ae98 100644
--- a/src/reconnecttimer.h
+++ b/src/reconnecttimer.h
@@ -13,14 +13,11 @@ public:
~ReconnectTimer();
public slots:
- void start();
+ void scheduleNextAttempt();
void stop();
signals:
- void tick();
-
-private:
- void setupWait();
+ void tryReconnect();
private slots:
void handleIphbActivity();
diff --git a/src/salmeta.cpp b/src/salmeta.cpp
index c4bcb0c..f13cd64 100644
--- a/src/salmeta.cpp
+++ b/src/salmeta.cpp
@@ -2,9 +2,10 @@
#include <sailfishapp.h>
#include "controller.h"
+#include "watchviewitem.h"
static bool launch_daemon = false;
-static QString settings_key_prefix;
+static QString settings_key_prefix("/apps/salmeta/watch0");
int main(int argc, char *argv[])
{
@@ -24,16 +25,15 @@ int main(int argc, char *argv[])
++it;
}
- if (launch_daemon) {
- if (settings_key_prefix.isEmpty()) {
- settings_key_prefix = "/apps/salmeta/watch0";
- }
+ qmlRegisterType<WatchViewItem>("com.javispedro.salmeta", 1, 0, "WatchView");
+ if (launch_daemon) {
qDebug() << "Starting salmeta (daemon) with settings from" << settings_key_prefix;
new Controller(settings_key_prefix, SailfishApp::createView());
} else {
QQuickView *view = SailfishApp::createView();
+ view->rootContext()->setContextProperty("settingsPrefix", settings_key_prefix);
view->setSource(SailfishApp::pathTo("qml/salmeta.qml"));
view->show();
}
diff --git a/src/watchviewitem.cpp b/src/watchviewitem.cpp
new file mode 100644
index 0000000..dbd4e8a
--- /dev/null
+++ b/src/watchviewitem.cpp
@@ -0,0 +1,15 @@
+#include <QtCore/QDebug>
+#include <QtGui/QPainter>
+
+#include "watchviewitem.h"
+
+WatchViewItem::WatchViewItem(QQuickItem *parent) :
+ QQuickPaintedItem(parent)
+{
+ setFillColor(Qt::white);
+}
+
+void WatchViewItem::paint(QPainter *painter)
+{
+
+}
diff --git a/src/watchviewitem.h b/src/watchviewitem.h
new file mode 100644
index 0000000..5219852
--- /dev/null
+++ b/src/watchviewitem.h
@@ -0,0 +1,20 @@
+#ifndef WATCHVIEWITEM_H
+#define WATCHVIEWITEM_H
+
+#include <QtQuick/QQuickPaintedItem>
+
+class WatchViewItem : public QQuickPaintedItem
+{
+ Q_OBJECT
+public:
+ explicit WatchViewItem(QQuickItem *parent = 0);
+
+ void paint(QPainter *painter);
+
+signals:
+
+public slots:
+
+};
+
+#endif // WATCHVIEWITEM_H