summaryrefslogtreecommitdiff
path: root/saltoqd
diff options
context:
space:
mode:
Diffstat (limited to 'saltoqd')
-rw-r--r--saltoqd/commmanager.cpp6
-rw-r--r--saltoqd/commmanager.h3
-rw-r--r--saltoqd/contactsmanager.cpp3
-rw-r--r--saltoqd/main.cpp6
-rw-r--r--saltoqd/saltoqd.pro4
-rw-r--r--saltoqd/systemmanager.cpp6
-rw-r--r--saltoqd/toqconnection.cpp18
-rw-r--r--saltoqd/toqconnection.h5
-rw-r--r--saltoqd/toqmanager.cpp16
-rw-r--r--saltoqd/toqmanager.h5
10 files changed, 51 insertions, 21 deletions
diff --git a/saltoqd/commmanager.cpp b/saltoqd/commmanager.cpp
index f54bb89..878fba2 100644
--- a/saltoqd/commmanager.cpp
+++ b/saltoqd/commmanager.cpp
@@ -8,8 +8,8 @@ using namespace CommHistory;
static const int RECORD_LIMIT = 20;
static const int PER_GROUP_LIMIT = 10;
-CommManager::CommManager(StorageManager *storage, ContactsManager *contacts, ToqManager *toq) :
- QObject(toq), _toq(toq), _contacts(contacts), _storage(storage),
+CommManager::CommManager(MDConfGroup *settings, StorageManager *storage, ContactsManager *contacts, ToqManager *toq) :
+ QObject(toq), _toq(toq), _contacts(contacts), _storage(storage), _settings(settings),
_calls(new CallModel(this)),
_convs(new GroupModel(this)),
_refreshTimer(new QTimer(this))
@@ -63,7 +63,7 @@ void CommManager::scheduleRefresh()
void CommManager::refresh()
{
- qDebug() << "refreshing now";
+ qDebug() << "Refreshing recent comms";
QMultiMap<QDateTime, QJsonObject> events;
int rows = _calls->rowCount();
diff --git a/saltoqd/commmanager.h b/saltoqd/commmanager.h
index b4604bb..45c0af9 100644
--- a/saltoqd/commmanager.h
+++ b/saltoqd/commmanager.h
@@ -11,7 +11,7 @@ class CommManager : public QObject
{
Q_OBJECT
public:
- explicit CommManager(StorageManager *storage, ContactsManager *contacts, ToqManager *toq);
+ explicit CommManager(MDConfGroup *settings, StorageManager *storage, ContactsManager *contacts, ToqManager *toq);
public slots:
void scheduleRefresh();
@@ -25,6 +25,7 @@ private:
ToqManager *_toq;
ContactsManager *_contacts;
StorageManager *_storage;
+ MDConfGroup *_settings;
CommHistory::CallModel *_calls;
CommHistory::GroupModel *_convs;
diff --git a/saltoqd/contactsmanager.cpp b/saltoqd/contactsmanager.cpp
index 2bc79d2..4e17e0f 100644
--- a/saltoqd/contactsmanager.cpp
+++ b/saltoqd/contactsmanager.cpp
@@ -102,9 +102,6 @@ void ContactsManager::refresh()
QJsonObject root;
root.insert("DataStore", store);
- QJsonDocument doc(root);
- qDebug() << doc.toJson();
-
_storage->updateStore(storeName, root);
emit changed();
diff --git a/saltoqd/main.cpp b/saltoqd/main.cpp
index 1f34c0d..cc17ca3 100644
--- a/saltoqd/main.cpp
+++ b/saltoqd/main.cpp
@@ -5,8 +5,10 @@ int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
- QBluetoothAddress addr("64:9C:81:00:13:EF");
- QScopedPointer<ToqManager> manager(new ToqManager(addr));
+ QScopedPointer<MDConfGroup> settings(new MDConfGroup);
+ settings->setPath("/apps/saltoq");
+
+ QScopedPointer<ToqManager> manager(new ToqManager(settings.data()));
return app.exec();
}
diff --git a/saltoqd/saltoqd.pro b/saltoqd/saltoqd.pro
index 8661518..e261b36 100644
--- a/saltoqd/saltoqd.pro
+++ b/saltoqd/saltoqd.pro
@@ -5,8 +5,8 @@ QT += dbus bluetooth contacts
CONFIG += c++11 link_pkgconfig
-PKGCONFIG += zlib commhistory-qt5 openobex qtcontacts-sqlite-qt5-extensions
-INCLUDEPATH += /usr/include/commhistory-qt5
+PKGCONFIG += zlib mlite5 commhistory-qt5 openobex qtcontacts-sqlite-qt5-extensions
+INCLUDEPATH += /usr/include/commhistory-qt5 /usr/include/mlite5
SOURCES += main.cpp \
toqconnection.cpp \
diff --git a/saltoqd/systemmanager.cpp b/saltoqd/systemmanager.cpp
index ac0c5b5..bd5a563 100644
--- a/saltoqd/systemmanager.cpp
+++ b/saltoqd/systemmanager.cpp
@@ -34,8 +34,12 @@ void SystemManager::handleGetTimeMessage(const ToqConnection::Message &msg)
time(&now);
localtime_r(&now, &now_info);
+ int offset = now_info.tm_gmtoff;
+ // Seems that the watch manually adds 1h if we are on DST.
+ if (now_info.tm_isdst) offset -= 3600;
+
detail.insert("epoch_time", qint64(now));
- detail.insert("time_zone", int(now_info.tm_gmtoff));
+ detail.insert("time_zone", offset);
detail.insert("dst", int(now_info.tm_isdst));
reply.insert("result", int(0));
diff --git a/saltoqd/toqconnection.cpp b/saltoqd/toqconnection.cpp
index 9468aa8..92d3353 100644
--- a/saltoqd/toqconnection.cpp
+++ b/saltoqd/toqconnection.cpp
@@ -7,9 +7,9 @@
static const int HEADER_LENGTH = 10;
-ToqConnection::ToqConnection(const QBluetoothAddress &address, QObject *parent) :
+ToqConnection::ToqConnection(QObject *parent) :
QObject(parent),
- _address(address), _socket(0),
+ _socket(0),
_reconnectTimer(new QTimer(this)),
_lastTransactionId(0)
{
@@ -18,7 +18,6 @@ ToqConnection::ToqConnection(const QBluetoothAddress &address, QObject *parent)
_reconnectTimer->setSingleShot(true);
_reconnectTimer->setInterval(1000);
- _reconnectTimer->start();
}
QString ToqConnection::nameOfEndpoint(Endpoint ep)
@@ -51,6 +50,19 @@ quint32 ToqConnection::checksum(QIODevice *dev)
return crc;
}
+void ToqConnection::setAddress(const QBluetoothAddress &address)
+{
+ qDebug() << address.toString() << _address.toString();
+ if (address != _address) {
+ _address = address;
+ if (isConnected()) {
+ _socket->disconnectFromService();
+ } else {
+ _reconnectTimer->start();
+ }
+ }
+}
+
quint16 ToqConnection::newTransactionId()
{
if (_lastTransactionId >= 0xFFFA) {
diff --git a/saltoqd/toqconnection.h b/saltoqd/toqconnection.h
index 0d295e2..4d8ecc6 100644
--- a/saltoqd/toqconnection.h
+++ b/saltoqd/toqconnection.h
@@ -11,10 +11,10 @@ class ToqConnection : public QObject
Q_OBJECT
Q_ENUMS(CoreEndpoints)
Q_PROPERTY(bool connected READ isConnected NOTIFY connectedChanged)
- Q_PROPERTY(QBluetoothAddress address READ address CONSTANT)
+ Q_PROPERTY(QBluetoothAddress address READ address WRITE setAddress)
public:
- explicit ToqConnection(const QBluetoothAddress &address, QObject *parent = 0);
+ explicit ToqConnection(QObject *parent = 0);
typedef quint8 Endpoint;
@@ -56,6 +56,7 @@ public:
bool isConnected() const;
QBluetoothAddress address() const;
+ void setAddress(const QBluetoothAddress &address);
quint16 newTransactionId();
diff --git a/saltoqd/toqmanager.cpp b/saltoqd/toqmanager.cpp
index 3f850d1..f03ba54 100644
--- a/saltoqd/toqmanager.cpp
+++ b/saltoqd/toqmanager.cpp
@@ -14,9 +14,10 @@
static const bool PROTO_DEBUG = true;
-ToqManager::ToqManager(const QBluetoothAddress &address, QObject *parent) :
+ToqManager::ToqManager(MDConfGroup *settings, QObject *parent) :
QObject(parent),
- _conn(new ToqConnection(address, this)),
+ _settings(settings),
+ _conn(new ToqConnection(this)),
_obex(new ObexConnection(_conn, this)),
_versionManager(new VersionManager(this)),
_systemManager(new SystemManager(this)),
@@ -24,7 +25,7 @@ ToqManager::ToqManager(const QBluetoothAddress &address, QObject *parent) :
_storageManager(new StorageManager(_obex, this)),
_musicManager(new MusicManager(this)),
_contactsManager(new ContactsManager(_storageManager, this)),
- _commManager(new CommManager(_storageManager, _contactsManager, this)),
+ _commManager(new CommManager(_settings, _storageManager, _contactsManager, this)),
_voiceCallManager(new VoiceCallManager(this)),
_weatherManager(new WeatherManager(_fmsManager, this))
{
@@ -34,6 +35,8 @@ ToqManager::ToqManager(const QBluetoothAddress &address, QObject *parent) :
this, &ToqManager::connected);
connect(_conn, &ToqConnection::disconnected,
this, &ToqManager::disconnected);
+
+ _conn->setAddress(QBluetoothAddress(_settings->value("address").toString()));
}
void ToqManager::setEndpointListener(ToqConnection::Endpoint ep, EndpointHandler *handler)
@@ -88,3 +91,10 @@ void ToqManager::handleToqMessage(const ToqConnection::Message &msg)
qWarning() << "No registered handler for endpoint" << ToqConnection::nameOfEndpoint(msg.destination);
}
}
+
+void ToqManager::handleSettingsChanged(const QString &key)
+{
+ if (key == "address") {
+ _conn->setAddress(QBluetoothAddress(_settings->value("address").toString()));
+ }
+}
diff --git a/saltoqd/toqmanager.h b/saltoqd/toqmanager.h
index b1fe4a5..1b2773c 100644
--- a/saltoqd/toqmanager.h
+++ b/saltoqd/toqmanager.h
@@ -2,6 +2,7 @@
#define TOQMANAGER_H
#include <QtCore/QObject>
+#include <MDConfGroup>
#include "toqconnection.h"
@@ -20,7 +21,7 @@ class ToqManager : public QObject
{
Q_OBJECT
public:
- explicit ToqManager(const QBluetoothAddress &address, QObject *parent = 0);
+ explicit ToqManager(MDConfGroup *settings, QObject *parent = 0);
struct EndpointHandler {
virtual void handleMessage(const ToqConnection::Message &msg) = 0;
@@ -45,8 +46,10 @@ signals:
private slots:
void handleToqMessage(const ToqConnection::Message &msg);
+ void handleSettingsChanged(const QString &key);
private:
+ MDConfGroup *_settings;
ToqConnection *_conn;
ObexConnection *_obex;
QHash<ToqConnection::Endpoint, EndpointHandler*> _handlers;