summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rpm/saltoq.spec2
-rw-r--r--rpm/saltoq.yaml2
-rw-r--r--saltoqd/agendamanager.cpp120
-rw-r--r--saltoqd/agendamanager.h35
-rw-r--r--saltoqd/commmanager.cpp2
-rw-r--r--saltoqd/commmanager.h4
-rw-r--r--saltoqd/main.cpp4
-rw-r--r--saltoqd/saltoqd.pro12
-rw-r--r--saltoqd/settings.cpp15
-rw-r--r--saltoqd/settings.h29
-rw-r--r--saltoqd/toqmanager.cpp14
-rw-r--r--saltoqd/toqmanager.h10
12 files changed, 229 insertions, 20 deletions
diff --git a/rpm/saltoq.spec b/rpm/saltoq.spec
index d628acf..5b8cb72 100644
--- a/rpm/saltoq.spec
+++ b/rpm/saltoq.spec
@@ -37,6 +37,8 @@ BuildRequires: pkgconfig(libiphb)
BuildRequires: pkgconfig(zlib)
BuildRequires: pkgconfig(commhistory-qt5)
BuildRequires: pkgconfig(qtcontacts-sqlite-qt5-extensions)
+BuildRequires: pkgconfig(libmkcal-qt5)
+BuildRequires: pkgconfig(libkcalcoren-qt5)
BuildRequires: pkgconfig(openobex)
BuildRequires: qt5-qtconnectivity-qtbluetooth-devel
diff --git a/rpm/saltoq.yaml b/rpm/saltoq.yaml
index 5626da9..fc205a4 100644
--- a/rpm/saltoq.yaml
+++ b/rpm/saltoq.yaml
@@ -25,6 +25,8 @@ PkgConfigBR:
- zlib
- commhistory-qt5
- qtcontacts-sqlite-qt5-extensions
+ - libmkcal-qt5
+ - libkcalcoren-qt5
- openobex
PkgBR:
diff --git a/saltoqd/agendamanager.cpp b/saltoqd/agendamanager.cpp
new file mode 100644
index 0000000..75b9c7d
--- /dev/null
+++ b/saltoqd/agendamanager.cpp
@@ -0,0 +1,120 @@
+#include <QtCore/QJsonArray>
+#include "agendamanager.h"
+
+const int LIMIT_EVENTS = 10;
+const int LIMIT_DAYS = 7 * 2;
+
+AgendaManager::AgendaManager(StorageManager *storage, ToqManager *toq) :
+ QObject(toq), _toq(toq), _storage(storage),
+ _calendar(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone())),
+ _calendarStorage(_calendar->defaultStorage(_calendar)),
+ _refreshTimer(new QTimer(this))
+{
+ _refreshTimer->setSingleShot(true);
+ _refreshTimer->setInterval(2000);
+ connect(_refreshTimer, &QTimer::timeout,
+ this, &AgendaManager::refresh);
+
+ _calendarStorage->registerObserver(this);
+
+ if (_calendarStorage->open()) {
+ scheduleRefresh();
+ } else {
+ qWarning() << "Cannot open calendar database";
+ }
+}
+
+AgendaManager::~AgendaManager()
+{
+ _calendarStorage->unregisterObserver(this);
+}
+
+void AgendaManager::scheduleRefresh()
+{
+ if (!_refreshTimer->isActive()) {
+ _refreshTimer->start();
+ }
+}
+
+void AgendaManager::refresh()
+{
+ qDebug() << "Now refreshing";
+
+ QDate today = QDate::currentDate();
+ QDate endDate = today.addDays(LIMIT_DAYS);
+ int count = 0;
+ count += _calendarStorage->loadRecurringIncidences();
+ qDebug() << "Loaded" << count << "recurring events";
+ count += _calendarStorage->load(today, endDate);
+ qDebug() << "Loaded" << count << "events total";
+
+ QMap<QDate, QJsonArray> recordsByDay;
+
+ auto events = _calendar->rawExpandedEvents(today, endDate, true, true);
+ for (const auto &expanded : events) {
+ const QDateTime &start = expanded.first.dtStart;
+ const QDateTime &end = expanded.first.dtEnd;
+ KCalCore::Incidence::Ptr incidence = expanded.second;
+ QJsonObject record;
+ QJsonObject details;
+ details.insert("StartTime", qint64(start.toTime_t()));
+ details.insert("EndTime", qint64(end.toTime_t()));
+ details.insert("AllDay", incidence->allDay());
+ details.insert("Title", incidence->summary());
+ if (!incidence->location().isEmpty()) {
+ details.insert("Location", incidence->location());
+ }
+ mKCal::Notebook::Ptr notebook = _calendarStorage->notebook(_calendar->notebook(incidence));
+ if (notebook) {
+ details.insert("Organizer", notebook->name());
+ }
+ record.insert("ItemId", incidence->uid());
+ record.insert("AgendaDetails", details);
+
+ recordsByDay[start.date()].append(record);
+ }
+
+ QJsonArray dayRecords;
+ for (auto it = recordsByDay.begin(); it != recordsByDay.end(); ++it) {
+ QDateTime dt(it.key(), QTime(0, 0, 0));
+ QJsonObject record;
+ QJsonObject payload;
+ payload.insert("Date", qint64(dt.toTime_t()));
+ payload.insert("AgendaRecords", it.value());
+ record.insert("RecordId", dayRecords.size() + 1);
+ record.insert("RecordPayload", payload);
+ dayRecords.append(record);
+ }
+
+ QString storeName("Phub.Phone.Agenda");
+ QJsonObject store;
+ store.insert("Name", storeName);
+ store.insert("Records", dayRecords);
+
+ QJsonObject root;
+ root.insert("DataStore", store);
+
+ _storage->updateStore(storeName, root);
+}
+
+void AgendaManager::storageModified(mKCal::ExtendedStorage *storage, const QString &info)
+{
+ Q_UNUSED(storage);
+ qDebug() << "Storage modified:" << info;
+ scheduleRefresh();
+}
+
+void AgendaManager::storageProgress(mKCal::ExtendedStorage *storage, const QString &info)
+{
+ Q_UNUSED(storage);
+ Q_UNUSED(info);
+ // Nothing to do
+}
+
+void AgendaManager::storageFinished(mKCal::ExtendedStorage *storage, bool error, const QString &info)
+{
+ Q_UNUSED(storage);
+ Q_UNUSED(error);
+ Q_UNUSED(info);
+ // Nothing to do
+}
diff --git a/saltoqd/agendamanager.h b/saltoqd/agendamanager.h
new file mode 100644
index 0000000..e70edb6
--- /dev/null
+++ b/saltoqd/agendamanager.h
@@ -0,0 +1,35 @@
+#ifndef AGENDAMANAGER_H
+#define AGENDAMANAGER_H
+
+#include "storagemanager.h"
+#include <extendedstorage.h>
+
+class AgendaManager : public QObject, public mKCal::ExtendedStorageObserver
+{
+ Q_OBJECT
+public:
+ explicit AgendaManager(StorageManager *storage, ToqManager *toq);
+ ~AgendaManager();
+
+public slots:
+ void scheduleRefresh();
+
+protected:
+ void storageModified(mKCal::ExtendedStorage *storage, const QString &info) Q_DECL_OVERRIDE;
+ void storageProgress(mKCal::ExtendedStorage *storage, const QString &info) Q_DECL_OVERRIDE;
+ void storageFinished(mKCal::ExtendedStorage *storage, bool error, const QString &info) Q_DECL_OVERRIDE;
+
+private slots:
+ void refresh();
+
+private:
+ ToqManager *_toq;
+ StorageManager *_storage;
+
+ mKCal::ExtendedCalendar::Ptr _calendar;
+ mKCal::ExtendedStorage::Ptr _calendarStorage;
+
+ QTimer *_refreshTimer;
+};
+
+#endif // AGENDAMANAGER_H
diff --git a/saltoqd/commmanager.cpp b/saltoqd/commmanager.cpp
index b078c0c..01aaf4b 100644
--- a/saltoqd/commmanager.cpp
+++ b/saltoqd/commmanager.cpp
@@ -8,7 +8,7 @@ using namespace CommHistory;
static const int RECORD_LIMIT = 20;
static const int PER_GROUP_LIMIT = 10;
-CommManager::CommManager(MDConfGroup *settings, StorageManager *storage, ContactsManager *contacts, ToqManager *toq) :
+CommManager::CommManager(Settings *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)),
diff --git a/saltoqd/commmanager.h b/saltoqd/commmanager.h
index 45c0af9..26f73a3 100644
--- a/saltoqd/commmanager.h
+++ b/saltoqd/commmanager.h
@@ -11,7 +11,7 @@ class CommManager : public QObject
{
Q_OBJECT
public:
- explicit CommManager(MDConfGroup *settings, StorageManager *storage, ContactsManager *contacts, ToqManager *toq);
+ explicit CommManager(Settings *settings, StorageManager *storage, ContactsManager *contacts, ToqManager *toq);
public slots:
void scheduleRefresh();
@@ -25,7 +25,7 @@ private:
ToqManager *_toq;
ContactsManager *_contacts;
StorageManager *_storage;
- MDConfGroup *_settings;
+ Settings *_settings;
CommHistory::CallModel *_calls;
CommHistory::GroupModel *_convs;
diff --git a/saltoqd/main.cpp b/saltoqd/main.cpp
index cc17ca3..6fa4257 100644
--- a/saltoqd/main.cpp
+++ b/saltoqd/main.cpp
@@ -5,9 +5,7 @@ int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
- QScopedPointer<MDConfGroup> settings(new MDConfGroup);
- settings->setPath("/apps/saltoq");
-
+ QScopedPointer<Settings> settings(new Settings("/apps/saltoq"));
QScopedPointer<ToqManager> manager(new ToqManager(settings.data()));
return app.exec();
diff --git a/saltoqd/saltoqd.pro b/saltoqd/saltoqd.pro
index 7e3a324..983475c 100644
--- a/saltoqd/saltoqd.pro
+++ b/saltoqd/saltoqd.pro
@@ -5,8 +5,8 @@ QT += dbus bluetooth contacts
CONFIG += c++11 link_pkgconfig
-PKGCONFIG += zlib dbus-1 mlite5 commhistory-qt5 openobex qtcontacts-sqlite-qt5-extensions
-INCLUDEPATH += /usr/include/dbus-1.0 /usr/include/mlite5 /usr/include/commhistory-qt5
+PKGCONFIG += zlib dbus-1 mlite5 commhistory-qt5 openobex qtcontacts-sqlite-qt5-extensions libmkcal-qt5 libkcalcoren-qt5
+INCLUDEPATH += /usr/include/dbus-1.0 /usr/include/mlite5 /usr/include/commhistory-qt5 /usr/include/mkcal-qt5 /usr/include/kcalcoren-qt5
SOURCES += main.cpp \
toqconnection.cpp \
@@ -22,7 +22,9 @@ SOURCES += main.cpp \
weathermanager.cpp \
obexconnection.cpp \
contactsmanager.cpp \
- cardmanager.cpp
+ cardmanager.cpp \
+ agendamanager.cpp \
+ settings.cpp
HEADERS += \
toqconnection.h \
@@ -38,7 +40,9 @@ HEADERS += \
weathermanager.h \
obexconnection.h \
contactsmanager.h \
- cardmanager.h
+ cardmanager.h \
+ agendamanager.h \
+ settings.h
DBUS_ADAPTORS += org.freedesktop.Notifications.xml
diff --git a/saltoqd/settings.cpp b/saltoqd/settings.cpp
new file mode 100644
index 0000000..b5f1815
--- /dev/null
+++ b/saltoqd/settings.cpp
@@ -0,0 +1,15 @@
+#include "settings.h"
+
+Settings::Settings(const QString &path, QObject *parent) :
+ MDConfGroup(path, parent, BindProperties)
+{
+ resolveMetaObject();
+}
+
+void Settings::setAddress(const QString &addr)
+{
+ if (addr != _address) {
+ _address = addr;
+ emit addressChanged();
+ }
+}
diff --git a/saltoqd/settings.h b/saltoqd/settings.h
new file mode 100644
index 0000000..bfc0dcb
--- /dev/null
+++ b/saltoqd/settings.h
@@ -0,0 +1,29 @@
+#ifndef SETTINGS_H
+#define SETTINGS_H
+
+#include <MDConfGroup>
+
+class Settings : public MDConfGroup
+{
+ Q_OBJECT
+ Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged)
+
+public:
+ explicit Settings(const QString &path, QObject *parent = 0);
+
+ QString address() const;
+ void setAddress(const QString &addr);
+
+signals:
+ void addressChanged();
+
+private:
+ QString _address;
+};
+
+inline QString Settings::address() const
+{
+ return _address;
+}
+
+#endif // SETTINGS_H
diff --git a/saltoqd/toqmanager.cpp b/saltoqd/toqmanager.cpp
index 104551e..ea59874 100644
--- a/saltoqd/toqmanager.cpp
+++ b/saltoqd/toqmanager.cpp
@@ -9,13 +9,14 @@
#include "musicmanager.h"
#include "contactsmanager.h"
#include "commmanager.h"
+#include "agendamanager.h"
#include "voicecallmanager.h"
#include "weathermanager.h"
#include "notificationmanager.h"
static const bool PROTO_DEBUG = true;
-ToqManager::ToqManager(MDConfGroup *settings, QObject *parent) :
+ToqManager::ToqManager(Settings *settings, QObject *parent) :
QObject(parent),
_settings(settings),
_conn(new ToqConnection(this)),
@@ -27,6 +28,7 @@ ToqManager::ToqManager(MDConfGroup *settings, QObject *parent) :
_musicManager(new MusicManager(this)),
_contactsManager(new ContactsManager(_storageManager, this)),
_commManager(new CommManager(_settings, _storageManager, _contactsManager, this)),
+ _agendaManager(new AgendaManager(_storageManager, this)),
_voiceCallManager(new VoiceCallManager(_contactsManager, this)),
_weatherManager(new WeatherManager(_fmsManager, this)),
_cardManager(new CardManager(_fmsManager, this)),
@@ -38,8 +40,10 @@ ToqManager::ToqManager(MDConfGroup *settings, QObject *parent) :
this, &ToqManager::connected);
connect(_conn, &ToqConnection::disconnected,
this, &ToqManager::disconnected);
+ connect(_settings, &Settings::addressChanged,
+ this, &ToqManager::handleSettingsAddressChanged);
- _conn->setAddress(QBluetoothAddress(_settings->value("address").toString()));
+ _conn->setAddress(QBluetoothAddress(_settings->address()));
}
void ToqManager::setEndpointListener(ToqConnection::Endpoint ep, EndpointHandler *handler)
@@ -109,9 +113,7 @@ void ToqManager::handleToqMessage(const ToqConnection::Message &msg)
}
}
-void ToqManager::handleSettingsChanged(const QString &key)
+void ToqManager::handleSettingsAddressChanged()
{
- if (key == "address") {
- _conn->setAddress(QBluetoothAddress(_settings->value("address").toString()));
- }
+ _conn->setAddress(QBluetoothAddress(_settings->address()));
}
diff --git a/saltoqd/toqmanager.h b/saltoqd/toqmanager.h
index 03eb0de..0333fa7 100644
--- a/saltoqd/toqmanager.h
+++ b/saltoqd/toqmanager.h
@@ -2,9 +2,9 @@
#define TOQMANAGER_H
#include <QtCore/QObject>
-#include <MDConfGroup>
#include "toqconnection.h"
+#include "settings.h"
class ObexConnection;
class VersionManager;
@@ -14,6 +14,7 @@ class StorageManager;
class MusicManager;
class ContactsManager;
class CommManager;
+class AgendaManager;
class VoiceCallManager;
class WeatherManager;
class CardManager;
@@ -23,7 +24,7 @@ class ToqManager : public QObject
{
Q_OBJECT
public:
- explicit ToqManager(MDConfGroup *settings, QObject *parent = 0);
+ explicit ToqManager(Settings *settings, QObject *parent = 0);
struct EndpointHandler {
virtual void handleMessage(const ToqConnection::Message &msg) = 0;
@@ -52,10 +53,10 @@ signals:
private slots:
void handleToqMessage(const ToqConnection::Message &msg);
- void handleSettingsChanged(const QString &key);
+ void handleSettingsAddressChanged();
private:
- MDConfGroup *_settings;
+ Settings *_settings;
ToqConnection *_conn;
ObexConnection *_obex;
QHash<ToqConnection::Endpoint, EndpointHandler*> _handlers;
@@ -67,6 +68,7 @@ private:
MusicManager *_musicManager;
ContactsManager *_contactsManager;
CommManager *_commManager;
+ AgendaManager *_agendaManager;
VoiceCallManager *_voiceCallManager;
WeatherManager *_weatherManager;
CardManager *_cardManager;