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
|
#ifndef CARDMANAGER_H
#define CARDMANAGER_H
#include <QtGui/QImage>
#include "fmsmanager.h"
class CardManager;
class CardDeck;
class Card;
class Card : public QObject
{
Q_OBJECT
Q_PROPERTY(QString id READ id CONSTANT)
Q_PROPERTY(QString header READ header WRITE setHeader NOTIFY headerChanged)
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
Q_PROPERTY(QString info READ info WRITE setInfo NOTIFY infoChanged)
Q_PROPERTY(QDateTime dateTime READ dateTime WRITE setDateTime NOTIFY dateTimeChanged)
Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged)
Q_PROPERTY(QString picture READ picture WRITE setPicture NOTIFY pictureChanged)
Q_PROPERTY(bool vibrate READ isVibrate WRITE setVibrate NOTIFY vibrateChanged)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QStringList menuOptions READ menuOptions WRITE setMenuOptions NOTIFY menuOptionsChanged)
// TODO card events, divider
Q_PROPERTY(bool open READ isOpen NOTIFY openChanged)
Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged)
public:
explicit Card(const QString &id, QObject *parent = 0);
QString id() const;
QString header() const;
void setHeader(const QString &header);
QString title() const;
void setTitle(const QString &title);
QString info() const;
void setInfo(const QString &info);
QDateTime dateTime() const;
void setDateTime(const QDateTime &dt);
QString icon() const;
void setIcon(const QString &url);
QString picture() const;
void setPicture(const QString &url);
bool isVibrate() const;
void setVibrate(bool vibrate);
QString text() const;
void setText(const QString &text);
QStringList menuOptions() const;
void setMenuOptions(const QStringList &options);
bool isOpen() const;
void setOpen(bool open);
bool isVisible() const;
void setVisible(bool visible);
signals:
void headerChanged();
void titleChanged();
void infoChanged();
void dateTimeChanged();
void iconChanged();
void pictureChanged();
void vibrateChanged();
void textChanged();
void menuOptionsChanged();
void openChanged();
void visibleChanged();
void optionSelected(const QString &option);
private:
QString _id;
QString _header;
QString _title;
QString _info;
QDateTime _dateTime;
QString _icon;
QString _picture;
bool _vibrate;
QString _text;
QStringList _options;
bool _open;
bool _visible;
};
class CardDeck : public QObject
{
Q_OBJECT
Q_PROPERTY(QString package READ package CONSTANT)
Q_PROPERTY(QString application READ application CONSTANT)
Q_PROPERTY(QList<Card*> cards READ cards)
public:
explicit CardDeck(const QString &package, const QString &application, QObject *parent = 0);
QString package() const;
QString application() const;
QList<Card*> cards() const;
Card * cardAt(int position) const;
Card * cardAt(const QString &id) const;
void appendCard(Card * card);
void insertCard(int position, Card * card);
void removeCard(int position);
void removeCard(Card * card);
signals:
void messageReceived(const QString &message);
void needsRefresh();
void cardAdded(Card * card);
void cardRemoved(Card * card);
private slots:
void scheduleRefresh();
private:
QString _package;
QString _application;
QList<Card*> _deck;
QHash<QString, Card*> _ids;
QTimer *_refreshTimer;
};
class CardManager : public QObject, public ToqManager::EndpointHandler
{
Q_OBJECT
public:
explicit CardManager(FmsManager *fms, ToqManager *toq);
void handleMessage(const ToqConnection::Message &msg) Q_DECL_OVERRIDE;
public slots:
void installDeck(CardDeck *deck);
void uninstallDeck(CardDeck *deck);
QString sendImage(CardDeck *deck, const QString &iconName, const QImage &image);
private:
static QString escapeString(const QString &s);
QString generateCardDescription(const QString &verb, Card * card) const;
QByteArray packMessage(CardDeck *deck, const QString &msg) const;
QPair<CardDeck *, QString> unpackMessage(const QByteArray &data) const;
QHash<QString,QString> unpackDictionary(const QString &data) const;
private slots:
void refreshDeck(CardDeck *deck);
void handleToqConnected();
void handleDeckNeedsRefresh();
void handleCardAdded(Card * card);
void handleCardRemoved(Card * card);
private:
ToqManager *_toq;
FmsManager *_fms;
QHash<QString, CardDeck*> _decks;
QSet<QString> _pending;
};
#endif // CARDMANAGER_H
|