-
Notifications
You must be signed in to change notification settings - Fork 345
/
mythnotification.h
356 lines (305 loc) · 11.3 KB
/
mythnotification.h
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
//
// mythnotification.h
// MythTV
//
// Created by Jean-Yves Avenard on 25/06/13.
// Copyright (c) 2013 Bubblestuff Pty Ltd. All rights reserved.
//
#ifndef __MythTV__mythnotification__
#define __MythTV__mythnotification__
#include <QMutex>
#include <QMap>
#include <QImage>
#include "mythevent.h"
#include "mythuiexp.h"
typedef QMap<QString,QString> DMAP;
class MUI_PUBLIC MythNotification : public MythEvent
{
public:
static Type New;
static Type Update;
static Type Info;
static Type Error;
MythNotification(Type t, void *parent = NULL)
: MythEvent(t), m_id(-1), m_parent(parent), m_fullScreen(false),
m_duration(0), m_visibility(kAll), m_priority(kDefault)
{
}
MythNotification(int id, void *parent)
: MythEvent(Update), m_id(id), m_parent(parent), m_fullScreen(false),
m_duration(0), m_visibility(kAll), m_priority(kDefault)
{
}
MythNotification(const QString &title, const QString &author,
const QString &details = QString())
: MythEvent(New), m_id(-1), m_parent(NULL), m_fullScreen(false),
m_description(title), m_duration(0), m_visibility(kAll),
m_priority(kDefault)
{
DMAP map;
map["minm"] = title;
map["asar"] = author;
map["asal"] = details;
m_metadata = map;
}
MythNotification(Type t, const DMAP &metadata)
: MythEvent(t), m_id(-1), m_parent(NULL), m_fullScreen(false),
m_duration(0), m_metadata(metadata),
m_visibility(kAll), m_priority(kDefault)
{
}
virtual ~MythNotification()
{
}
virtual MythEvent *clone(void) const { return new MythNotification(*this); }
/** Priority enum
* A notification can be given a priority. Display order of notification
* will be sorted according to the priority level
*/
enum Priority {
kDefault = 0,
kLow,
kMedium,
kHigh,
kHigher,
kHighest,
};
/** Visibility enum
* A notification can be given visibility mask allowing to not be visible
* under some circumstances, like the screen currently being displayed.
* This is used to prevent redundant information appearing more than once:
* like in MythMusic, there's no need to show music notifications
*/
enum Visibility {
kNone = 0,
kAll = ~0,
kPlayback = (1 << 1),
kSettings = (1 << 2),
kWizard = (1 << 3),
kVideos = (1 << 4),
kMusic = (1 << 5),
kRecordings = (1 << 6),
};
// Setter
/**
* Optional MythNotification elements
*/
/**
* contains the application registration id
* Required to update an existing notification screen owned by an application
*/
void SetId(int id);
/**
* contains the parent address. Required if id is set
* Id provided must match the parent address as provided during the
* MythUINotificationCenter registration, otherwise the id value will be
* ignored
*/
void SetParent(void *parent) { m_parent = parent; }
/**
* a notification may request to be displayed in full screen,
* this request may not be fullfilled should the theme not handle full screen
* notification
*/
void SetFullScreen(bool f) { m_fullScreen = f; }
/**
* contains a short description of the notification
*/
void SetDescription(const QString &desc) { m_description = desc; }
/**
* metadata of the notification.
* In DMAP format. DMAP can contains various information such as artist,
* album name, author name, genre etc..
*/
void SetMetaData(const DMAP &data) { m_metadata = data; }
/**
* contains a duration during which the notification will be displayed for.
* The duration is informative only as the MythUINotificationCenter will
* determine automatically how long a notification can be displayed for
* and will depend on priority, visibility and other factors
*/
void SetDuration(int duration) { m_duration = duration; };
/**
* contains an alternative notification style.
* Should a style be defined, the Notification Center will attempt to load
* an alternative theme and fall back to the default one if unsuccessful
*/
void SetStyle(const QString &style) { m_style = style; }
/**
* For future use, not implemented at this stage
*/
void SetVisibility(Visibility n) { m_visibility = n; }
void SetPriority(Priority n) { m_priority = n; }
// Getter
int GetId(void) { return m_id; }
void *GetParent(void) { return m_parent; }
bool GetFullScreen(void) { return m_fullScreen; }
QString GetDescription(void) { return m_description; }
DMAP GetMetaData(void) { return m_metadata; }
int GetDuration(void) { return m_duration; };
QString GetStyle(void) { return m_style; }
Visibility GetVisibility(void) { return m_visibility; }
Priority GetPriority(void) { return m_priority; }
protected:
MythNotification(const MythNotification &o)
: MythEvent(o),
m_id(o.m_id), m_parent(o.m_parent), m_fullScreen(o.m_fullScreen),
m_description(o.m_description),
m_duration(o.m_duration), m_metadata(o.m_metadata),
m_visibility(o.m_visibility), m_priority(o.m_priority)
{
}
MythNotification &operator=(const MythNotification&);
protected:
int m_id;
void *m_parent;
bool m_fullScreen;
QString m_description;
int m_duration;
DMAP m_metadata;
QString m_style;
Visibility m_visibility;
Priority m_priority;
};
class MUI_PUBLIC MythImageNotification : public virtual MythNotification
{
public:
MythImageNotification(Type t, const QImage &image)
: MythNotification(t), m_image(image)
{
}
MythImageNotification(Type t, const QString &imagePath)
: MythNotification(t), m_imagePath(imagePath)
{
}
MythImageNotification(Type t, const QImage &image, const DMAP &metadata)
: MythNotification(t, metadata), m_image(image)
{
}
MythImageNotification(Type t, const QString &imagePath, const DMAP &metadata)
: MythNotification(t, metadata), m_imagePath(imagePath)
{
}
virtual MythEvent *clone(void) const { return new MythImageNotification(*this); }
// Setter
/**
* image to be displayed with the notification
*/
void SetImage(const QImage &image) { m_image = image; }
/**
* image filename to be displayed with the notification
*/
void SetImagePath(const QString &image) { m_imagePath = image; }
//Getter
QImage GetImage(void) { return m_image; }
QString GetImagePath(void) { return m_imagePath; }
protected:
MythImageNotification(const MythImageNotification &o)
: MythNotification(o), m_image(o.m_image), m_imagePath(o.m_imagePath)
{
}
MythImageNotification &operator=(const MythImageNotification&);
protected:
QImage m_image;
QString m_imagePath;
};
class MUI_PUBLIC MythPlaybackNotification : public virtual MythNotification
{
public:
MythPlaybackNotification(Type t, float progress, const QString &progressText)
: MythNotification(t), m_progress(progress), m_progressText(progressText)
{
}
MythPlaybackNotification(Type t, float progress, const QString &progressText,
const DMAP &metadata)
: MythNotification(t, metadata),
m_progress(progress), m_progressText(progressText)
{
}
MythPlaybackNotification(Type t, int duration, int position)
: MythNotification(t)
{
m_progress = (float)position / (float)duration;
m_progressText = stringFromSeconds(duration);
}
virtual MythEvent *clone(void) const { return new MythPlaybackNotification(*this); }
// Setter
/**
* current playback position to be displayed with the notification.
* Value to be between 0 <= x <= 1.
* Note: x < 0 means no progress bar to be displayed.
*/
void SetProgress(float progress) { m_progress = progress; }
/**
* text to be displayed with the notification as duration or progress.
*/
void SetProgressText(const QString &text) { m_progressText = text; }
//Getter
float GetProgress(void) { return m_progress; }
QString GetProgressText(void) { return m_progressText; }
// utility methods
static QString stringFromSeconds(int time);
protected:
MythPlaybackNotification(const MythPlaybackNotification &o)
: MythNotification(o),
m_progress(o.m_progress), m_progressText(o.m_progressText)
{
}
MythPlaybackNotification &operator=(const MythPlaybackNotification&);
protected:
float m_progress;
QString m_progressText;
};
class MUI_PUBLIC MythMediaNotification : public MythImageNotification,
public MythPlaybackNotification
{
public:
MythMediaNotification(Type t, const QImage &image, const DMAP &metadata,
float progress, const QString &durationText)
: MythNotification(t, metadata), MythImageNotification(t, image),
MythPlaybackNotification(t, progress, durationText)
{
}
MythMediaNotification(Type t, const QImage &image, const DMAP &metadata,
int duration, int position)
: MythNotification(t, metadata), MythImageNotification(t, image),
MythPlaybackNotification(t, duration, position)
{
}
MythMediaNotification(Type t, const QString &imagePath, const DMAP &metadata,
float progress, const QString &durationText)
: MythNotification(t, metadata), MythImageNotification(t, imagePath),
MythPlaybackNotification(t, progress, durationText)
{
}
MythMediaNotification(Type t, const QString &imagePath, const DMAP &metadata,
int duration, int position)
: MythNotification(t, metadata), MythImageNotification(t, imagePath),
MythPlaybackNotification(t, duration, position)
{
}
virtual MythEvent *clone(void) const { return new MythMediaNotification(*this); }
protected:
MythMediaNotification(const MythMediaNotification &o)
: MythNotification(o), MythImageNotification(o), MythPlaybackNotification(o)
{
}
MythMediaNotification &operator=(const MythMediaNotification&);
};
class MUI_PUBLIC MythErrorNotification : public MythImageNotification
{
public:
MythErrorNotification(const QString &title, const QString &author,
const QString &details = QString())
: MythNotification(title, author, details), MythImageNotification(New, "error.png")
{
}
virtual MythEvent *clone(void) const { return new MythErrorNotification(*this); }
protected:
MythErrorNotification(const MythErrorNotification &o)
: MythNotification(o), MythImageNotification(o)
{
}
MythErrorNotification &operator=(const MythErrorNotification&);
};
#endif /* defined(__MythTV__mythnotification__) */