summaryrefslogtreecommitdiff
path: root/daemon/timelineitem.h
blob: 9d7850c59827b0c8acad3f64d363e6f746277373 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#ifndef TIMELINEITEM_H
#define TIMELINEITEM_H

#include <QByteArray>
#include <QDateTime>

#include "watchconnector.h"


class TimelineAttribute
{
public:
    enum Type {
        TypeTitle = 0x01,
        TypeSubtitle = 0x02,
        TypeBody = 0x03,
        TypeTinyIcon = 0x04,
        TypeLargeIcon = 0x06,
        TypeFieldNames = 0x19,
        TypeFieldValues = 0x1a,
        TypeColor = 0x1c,
        TypeRecurring = 0x1f
    };
    enum IconID {
        IconIDDefaultBell = 0x01,
        IconIDDefaultMissedCall = 0x02,
        IconIDReminder = 0x03,
        IconIDFlag = 0x04,
        IconIDWhatsApp = 0x05,
        IconIDTwitter = 0x06,
        IconIDTelegram = 0x07,
        IconIDHangout = 0x08,
        IconIDGMail = 0x09,
        IconIDFlash = 0x0a, // TODO: what service is this?
        IconIDFacebook = 0x0b,
        IconIDMusic = 0x0c,
        IconIDAlarm = 0x0d,
        IconIDWeather = 0x0e,
        IconIDGuess = 0x31
    };

    enum Color {
        ColorWhite = 0x00,
        ColorBlack = 0x80,
        ColorDarkBlue = 0x81,
        ColorBlue = 0x82,
        ColorLightBlue = 0x83,
        ColorDarkGreen = 0x84,
        ColorGray = 0x85,
        ColorBlue2 = 0x86,
        ColorLightBlue2 = 0x87,
        ColorGreen = 0x88,
        ColorOliveGreen = 0x89,
        ColorLightGreen = 0x90,
        ColorViolet = 0x91,
        ColorViolet2 = 0x91,
        ColorBlue3 = 0x92,
        ColorBrown = 0x93,
        ColorGray2 = 0x94,
        ColorBlue4 = 0x95,
        ColorBlue5 = 0x96,
        ColorRed = 0xA0,
        ColorOrange = 0xB8,
        ColorYellow = 0xBC
    };

    TimelineAttribute(Type type, const QByteArray &content):
        m_type(type),
        m_content(content)
    {}

    TimelineAttribute(Type type, IconID iconId):
        m_type(type)
    {
        setContent(iconId);
    }
    TimelineAttribute(Type type, Color color):
        m_type(type)
    {
        setContent(color);
    }
    TimelineAttribute(Type type, const QStringList &values):
        m_type(type)
    {
        setContent(values);
    }
    TimelineAttribute(Type type, quint8 data):
        m_type(type)
    {
        setContent(data);
    }

    void setContent(const QString &content);
    void setContent(IconID iconId);
    void setContent(Color color);
    void setContent(const QStringList &values);
    void setContent(quint8 data);

    QByteArray serialize() const;
private:
    Type m_type;
    QByteArray m_content;
};

class TimelineAction: public PebblePacket
{
public:
    enum Type {
        TypeAncsDismiss = 1,
        TypeGeneric = 2,
        TypeResponse = 3,
        TypeDismiss = 4,
        TypeHTTP = 5,
        TypeSnooze = 6,
        TypeOpenWatchApp = 7,
        TypeEmpty = 8,
        TypeRemove = 9,
        TypeOpenPin = 10
    };
    TimelineAction(quint8 actionId, Type type, const QList<TimelineAttribute> &attributes = QList<TimelineAttribute>());
    void appendAttribute(const TimelineAttribute &attribute);

    QByteArray serialize() const override {
        QByteArray ret;
        ret.append(m_actionId);
        ret.append((quint8)m_type);
        ret.append(m_attributes.count());
        foreach (const TimelineAttribute &attr, m_attributes) {
            ret.append(attr.serialize());
        }
        return ret;
    }

private:
    quint8 m_actionId;
    Type m_type;
    QList<TimelineAttribute> m_attributes;
};

class TimelineItem: public PebblePacket
{
public:
    enum Type {
        TypeNotification = 1,
        TypePin = 2,
        TypeReminder = 3
    };

    // TODO: this is probably not complete and maybe even wrong.
    enum Flag {
        FlagNone = 0x00,
        FlagSingleEvent = 0x01,
        FlagTimeInUTC = 0x02,
        FlagAllDay = 0x04
    };
    Q_DECLARE_FLAGS(Flags, Flag)

    // TODO: This is not complete
    enum Layout {
        LayoutGenericPin = 0x01,
        LayoutCalendar = 0x02
    };

    TimelineItem(Type type, TimelineItem::Flags flags = FlagNone, const QDateTime &timestamp = QDateTime::currentDateTime(), quint16 duration = 0);
    TimelineItem(const QUuid &uuid, Type type, Flags flags = FlagNone, const QDateTime &timestamp = QDateTime::currentDateTime(), quint16 duration = 0);

    QUuid itemId() const;

    void setLayout(quint8 layout);
    void setFlags(Flags flags);

    void appendAttribute(const TimelineAttribute &attribute);
    void appendAction(const TimelineAction &action);

    QList<TimelineAttribute> attributes() const;
    QList<TimelineAction> actions() const;

    QByteArray serialize() const override;

private:
    QUuid m_itemId;
    QUuid m_parentId;
    QDateTime m_timestamp;
    quint16 m_duration = 0;
    Type m_type;
    Flags m_flags; // quint16
    quint8 m_layout = 0x01; // TODO: find out what this is about
    QList<TimelineAttribute> m_attributes;
    QList<TimelineAction> m_actions;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(TimelineItem::Flags)

#endif // TIMELINEITEM_H