summaryrefslogtreecommitdiff
path: root/daemon/manager.h
blob: cf40aedea44ffbff376786cc3fc62c3acbe0d0ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef MANAGER_H
#define MANAGER_H

#include "watchconnector.h"
#include "dbusconnector.h"
#include "voicecallmanager.h"
#include "notificationmanager.h"
#include "watchcommands.h"
#include "settings.h"

#include <QObject>
#include <QBluetoothLocalDevice>
#include <QDBusContext>
#include <QtContacts/QContactManager>
#include <QtContacts/QContactDetailFilter>
#include <MNotification>
#include <Log4Qt/Logger>

using namespace QtContacts;

class Manager :
        public QObject,
        protected QDBusContext
{
    Q_OBJECT
    LOG4QT_DECLARE_QCLASS_LOGGER

    friend class PebbledProxy;

    Q_PROPERTY(QString mpris READ mpris)
    Q_PROPERTY(QVariantMap mprisMetadata READ getMprisMetadata WRITE setMprisMetadata NOTIFY mprisMetadataChanged)

    QBluetoothLocalDevice btDevice;

    watch::WatchConnector *watch;
    DBusConnector *dbus;
    VoiceCallManager *voice;
    NotificationManager *notifications;

    WatchCommands *commands;

    Settings *settings;

    MNotification notification;

    QContactManager *contacts;
    QContactDetailFilter numberFilter;

    QString defaultProfile;

    QString lastSeenMpris;

public:
    explicit Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallManager *voice, NotificationManager *notifications, Settings *settings);

    Q_INVOKABLE QString findPersonByNumber(QString number);
    Q_INVOKABLE QString getCurrentProfile();
    Q_INVOKABLE QString mpris();
    QVariantMap mprisMetadata;
    QVariantMap getMprisMetadata() { return mprisMetadata; }

protected:
    void transliterateCyrillic(const QString &text);

signals:
    void mprisMetadataChanged(QVariantMap);

public slots:
    void hangupAll();
    void applyProfile();

protected slots:
    void onSettingChanged(const QString &key);
    void onSettingsChanged();
    void onPebbleChanged();
    void onConnectedChanged();
    void onActiveVoiceCallChanged();
    void onVoiceError(const QString &message);
    void onActiveVoiceCallStatusChanged();
    void onNotifyError(const QString &message);
    void onSmsNotify(const QString &sender, const QString &data);
    void onTwitterNotify(const QString &sender, const QString &data);
    void onFacebookNotify(const QString &sender, const QString &data);
    void onEmailNotify(const QString &sender, const QString &data,const QString &subject);
    void onMprisPropertiesChanged(QString,QMap<QString,QVariant>,QStringList);
    void setMprisMetadata(QDBusArgument metadata);
    void setMprisMetadata(QVariantMap metadata);
};

class PebbledProxy : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QVariantMap pebble READ pebble)
    Q_PROPERTY(QString name READ pebbleName)
    Q_PROPERTY(QString address READ pebbleAddress)
    Q_PROPERTY(bool connected READ pebbleConnected)

    QVariantMap pebble() { return static_cast<Manager*>(parent())->dbus->pebble(); }
    QString pebbleName() { return static_cast<Manager*>(parent())->dbus->pebble()["Name"].toString(); }
    QString pebbleAddress() { return static_cast<Manager*>(parent())->dbus->pebble()["Address"].toString(); }
    bool pebbleConnected() { return static_cast<Manager*>(parent())->watch->isConnected(); }

public:
    explicit PebbledProxy(QObject *parent) : QObject(parent) {}

public slots:
    void ping(int val) { static_cast<Manager*>(parent())->watch->ping((unsigned int)val); }
    void time() { static_cast<Manager*>(parent())->watch->time(); }
    void disconnect() { static_cast<Manager*>(parent())->watch->disconnect(); }
    void reconnect() { static_cast<Manager*>(parent())->watch->reconnect(); }

};

#endif // MANAGER_H