From 08d36eb82a9cc7ef9cc3efe40f26e1a732c8c602 Mon Sep 17 00:00:00 2001 From: Javier Date: Mon, 23 Mar 2015 04:27:19 +0100 Subject: use plain glibc for tz information --- saltoqd/musicmanager.cpp | 8 ++++---- saltoqd/notificationmanager.cpp | 1 - saltoqd/systemmanager.cpp | 21 ++++++++++++--------- saltoqd/toqconnection.cpp | 11 +++++++++-- saltoqd/toqconnection.h | 2 +- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/saltoqd/musicmanager.cpp b/saltoqd/musicmanager.cpp index 8b1e9a9..bc7e2de 100644 --- a/saltoqd/musicmanager.cpp +++ b/saltoqd/musicmanager.cpp @@ -43,17 +43,17 @@ void MusicManager::handleMessage(const ToqConnection::Message &msg) _isPlayerVisible = true; break; case 1: - callMprisMethod("Play"); + if (!_curService.isEmpty()) callMprisMethod("Play"); // TODO Reply with new metadata! break; case 2: - callMprisMethod("Pause"); + if (!_curService.isEmpty()) callMprisMethod("Pause"); break; case 3: - callMprisMethod("Next"); + if (!_curService.isEmpty()) callMprisMethod("Next"); break; case 4: - callMprisMethod("Previous"); + if (!_curService.isEmpty()) callMprisMethod("Previous"); break; case 0x8004: // Player closing? _isPlayerVisible = false; diff --git a/saltoqd/notificationmanager.cpp b/saltoqd/notificationmanager.cpp index fb52785..45020cb 100644 --- a/saltoqd/notificationmanager.cpp +++ b/saltoqd/notificationmanager.cpp @@ -3,5 +3,4 @@ NotificationManager::NotificationManager(ToqManager *toq) : QObject(toq), _toq(toq) { - } diff --git a/saltoqd/systemmanager.cpp b/saltoqd/systemmanager.cpp index 4f74ea4..ac0c5b5 100644 --- a/saltoqd/systemmanager.cpp +++ b/saltoqd/systemmanager.cpp @@ -1,5 +1,4 @@ -#include -#include +#include #include "systemmanager.h" #include "voicecallmanager.h" @@ -27,17 +26,21 @@ void SystemManager::handleMessage(const ToqConnection::Message &msg) void SystemManager::handleGetTimeMessage(const ToqConnection::Message &msg) { - QJsonObject reply, time; - QDateTime dt = QDateTime::currentDateTime(); - QTimeZone tz = dt.timeZone(); + QJsonObject reply, detail; - time.insert("epoch_time", qint64(dt.toTime_t())); - time.insert("time_zone", tz.standardTimeOffset(dt)); - time.insert("dst", tz.isDaylightTime(dt) ? 1 : 0); + // Seems that QTimeZone is completely broken on Jolla ("timed/localtime") + time_t now; + tm now_info; + time(&now); + localtime_r(&now, &now_info); + + detail.insert("epoch_time", qint64(now)); + detail.insert("time_zone", int(now_info.tm_gmtoff)); + detail.insert("dst", int(now_info.tm_isdst)); reply.insert("result", int(0)); reply.insert("description", QLatin1String("current time")); - reply.insert("time", time); + reply.insert("time", detail); _toq->sendReply(msg, 0x4000, reply); } diff --git a/saltoqd/toqconnection.cpp b/saltoqd/toqconnection.cpp index c2e2349..564b7d2 100644 --- a/saltoqd/toqconnection.cpp +++ b/saltoqd/toqconnection.cpp @@ -21,11 +21,16 @@ ToqConnection::ToqConnection(const QBluetoothAddress &address, QObject *parent) _reconnectTimer->start(); } -const char * ToqConnection::nameOfEndpoint(Endpoint ep) +QString ToqConnection::nameOfEndpoint(Endpoint ep) { int index = staticMetaObject.indexOfEnumerator("CoreEndpoints"); QMetaEnum epEnum = staticMetaObject.enumerator(index); - return epEnum.valueToKey(ep); + const char * ret = epEnum.valueToKey(ep); + if (ret) { + return QString::fromLatin1(ret); + } else { + return QString::number(ep); + } } quint32 ToqConnection::checksum(const QByteArray &data) @@ -151,7 +156,9 @@ void ToqConnection::handleSocketDisconnected() void ToqConnection::handleSocketError(QBluetoothSocket::SocketError error) { + Q_ASSERT(_socket); qWarning() << error << _socket->errorString(); + _socket->disconnectFromService(); } void ToqConnection::handleSocketData() diff --git a/saltoqd/toqconnection.h b/saltoqd/toqconnection.h index 47a3132..fec20a8 100644 --- a/saltoqd/toqconnection.h +++ b/saltoqd/toqconnection.h @@ -48,7 +48,7 @@ public: QJsonDocument payload; }; - static const char * nameOfEndpoint(Endpoint ep); + static QString nameOfEndpoint(Endpoint ep); static quint32 checksum(const QByteArray &data); static quint32 checksum(QIODevice *dev); -- cgit v1.2.3