-
Notifications
You must be signed in to change notification settings - Fork 342
/
mythuinotificationcenter.cpp
1446 lines (1251 loc) · 39 KB
/
mythuinotificationcenter.cpp
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// mythuinotificationcenter.cpp
// MythTV
//
// Created by Jean-Yves Avenard on 25/06/13.
// Copyright (c) 2013 Bubblestuff Pty Ltd. All rights reserved.
//
#include <QCoreApplication>
#include <QEvent>
#include <QObject>
#include <QThread>
#include <QTimer>
#include "mythcorecontext.h"
#include "mythmainwindow.h"
#include "mythuinotificationcenter.h"
#include "mythuinotificationcenter_private.h"
#include "mythpainter.h"
#include "mythscreenstack.h"
#include "mythscreentype.h"
#include "mythuiimage.h"
#include "mythuitext.h"
#include "mythuiprogressbar.h"
#include "mythdate.h"
#define LOC QString("NotificationCenter: ")
#define HGAP 5
#define DEFAULT_DURATION 5000 // in ms
//// MythUINotificationCenterEvent
QEvent::Type MythUINotificationCenterEvent::kEventType =
(QEvent::Type) QEvent::registerEventType();
//// class MythNotificationScreenStack
void MythNotificationScreenStack::PopScreen(MythScreenType *screen, bool allowFade,
bool deleteScreen)
{
if (!screen || screen->IsDeleting())
return;
bool poppedFullscreen = screen->IsFullscreen();
screen->aboutToHide();
if (m_Children.isEmpty())
return;
MythMainWindow *mainwindow = GetMythMainWindow();
screen->setParent(0);
if (allowFade && m_DoTransitions && !mainwindow->IsExitingToMain())
{
screen->SetFullscreen(false);
if (deleteScreen)
{
screen->SetDeleting(true);
m_ToDelete.push_back(screen);
}
screen->AdjustAlpha(1, -kFadeVal);
}
else
{
for (int i = 0; i < m_Children.size(); ++i)
{
if (m_Children.at(i) == screen)
{
m_Children.remove(i);
break;
}
}
if (deleteScreen)
screen->deleteLater();
screen = NULL;
}
m_topScreen = NULL;
RecalculateDrawOrder();
// If we're fading it, we still want to draw it.
if (screen && !m_DrawOrder.contains(screen))
m_DrawOrder.push_back(screen);
if (!m_Children.isEmpty())
{
QVector<MythScreenType *>::Iterator it;
for (it = m_DrawOrder.begin(); it != m_DrawOrder.end(); ++it)
{
if (*it != screen && !(*it)->IsDeleting())
{
m_topScreen = (*it);
(*it)->SetAlpha(255);
if (poppedFullscreen)
(*it)->aboutToShow();
}
}
}
if (m_topScreen)
{
m_topScreen->SetRedraw();
}
else
{
// Screen still needs to be redrawn if we have popped the last screen
// off the popup stack, or similar
if (mainwindow->GetMainStack())
{
MythScreenType *mainscreen = mainwindow->GetMainStack()->GetTopScreen();
if (mainscreen)
mainscreen->SetRedraw();
}
}
}
MythScreenType *MythNotificationScreenStack::GetTopScreen(void) const
{
if (!m_Children.isEmpty())
return m_Children.front();
return NULL;
}
//// class MythUINotificationScreen
MythUINotificationScreen::MythUINotificationScreen(MythScreenStack *stack,
int id)
: MythScreenType(stack, "mythuinotification"), m_id(id),
m_duration(-1), m_progress(-1.0), m_fullscreen(false),
m_added(false),
m_created(false), m_content(kNone), m_update(kAll),
m_artworkImage(NULL), m_titleText(NULL), m_originText(NULL),
m_descriptionText(NULL), m_extraText(NULL), m_progresstextText(NULL),
m_progressBar(NULL), m_errorState(NULL), m_mediaState(NULL),
m_index(0),
m_timer(new QTimer(this)),
m_visibility(MythNotification::kAll),
m_priority(MythNotification::kDefault),
m_refresh(true)
{
// Set timer if need be
SetSingleShotTimer(m_duration);
connect(m_timer, SIGNAL(timeout()), this, SLOT(ProcessTimer()));
}
MythUINotificationScreen::MythUINotificationScreen(MythScreenStack *stack,
MythNotification ¬ification)
: MythScreenType(stack, "mythuinotification"), m_id(notification.GetId()),
m_duration(notification.GetDuration()), m_progress(-1.0),
m_fullscreen(false),
m_added(false), m_created(false), m_content(kNone),
m_update(kAll),
m_artworkImage(NULL), m_titleText(NULL), m_originText(NULL),
m_descriptionText(NULL), m_extraText(NULL), m_progresstextText(NULL),
m_progressBar(NULL), m_errorState(NULL), m_mediaState(NULL),
m_index(0),
m_timer(new QTimer(this)),
m_visibility(MythNotification::kAll),
m_priority(MythNotification::kDefault),
m_refresh(true)
{
SetNotification(notification);
connect(m_timer, SIGNAL(timeout()), this, SLOT(ProcessTimer()));
}
MythUINotificationScreen::MythUINotificationScreen(MythScreenStack *stack,
const MythUINotificationScreen &s)
: MythScreenType(stack, "mythuinotification"),
m_duration(-1), m_progress(-1.0), m_fullscreen(false),
m_added(false),
m_created(false), m_content(kNone), m_update(kAll),
m_artworkImage(NULL), m_titleText(NULL), m_originText(NULL),
m_descriptionText(NULL), m_extraText(NULL), m_progresstextText(NULL),
m_progressBar(NULL), m_errorState(NULL), m_mediaState(NULL),
m_timer(new QTimer(this)),
m_visibility(MythNotification::kAll),
m_priority(MythNotification::kDefault),
m_refresh(true)
{
*this = s;
connect(m_timer, SIGNAL(timeout()), this, SLOT(ProcessTimer()));
}
MythUINotificationScreen::~MythUINotificationScreen()
{
m_timer->stop();
LOG(VB_GUI, LOG_DEBUG, LOC + "MythUINotificationScreen dtor");
// We can't rely on Exiting() default MythScreenType signal as
// by the time it is emitted, the destructor would have already been called
// making the members unusable
emit ScreenDeleted();
}
void MythUINotificationScreen::SetNotification(MythNotification ¬ification)
{
bool update = notification.type() == MythNotification::Update;
m_update = kNone;
MythErrorNotification *error =
dynamic_cast<MythErrorNotification*>(¬ification);
if (error)
{
m_update |= kError;
}
MythImageNotification *img =
dynamic_cast<MythImageNotification*>(¬ification);
if (img)
{
QString path = img->GetImagePath();
m_update |= kImage;
if (path.isNull())
{
UpdateArtwork(img->GetImage());
}
else
{
UpdateArtwork(path);
}
}
MythPlaybackNotification *play =
dynamic_cast<MythPlaybackNotification*>(¬ification);
if (play)
{
UpdatePlayback(play->GetProgress(), play->GetProgressText());
m_update |= kDuration;
}
MythMediaNotification *media =
dynamic_cast<MythMediaNotification*>(¬ification);
if (media && m_imagePath.isEmpty() && m_image.isNull())
{
m_update |= kNoArtwork;
}
if (!notification.GetMetaData().isEmpty())
{
UpdateMetaData(notification.GetMetaData());
m_update |= kMetaData;
}
else if (!update)
{
// A new notification, will always update the metadata field
m_update |= kMetaData;
}
if (!notification.GetStyle().isEmpty())
{
m_style = notification.GetStyle();
m_update |= kStyle;
}
if (!update)
{
m_content = m_update;
m_fullscreen = notification.GetFullScreen();
}
m_duration = notification.GetDuration();
m_visibility = notification.GetVisibility();
if (!m_visibility)
{
// no visibility is all visibility to get around QVariant always making 0 the default
m_visibility = ~0;
}
m_priority = notification.GetPriority();
// Set timer if need be
SetSingleShotTimer(m_duration, update);
// We need to re-run init
m_refresh = true;
}
bool MythUINotificationScreen::Create(void)
{
bool foundtheme = false;
// Load the theme for this screen
// The xml file containing the screen definition is airplay-ui.xml in this
// example, the name of the screen in the xml is airplaypicture. This
// should make sense when you look at the xml below
QString theme;
if (m_fullscreen)
{
theme = "notification-full";
}
else if (m_content & kImage)
{
theme = "notification-image";
}
else
{
theme = "notification";
}
QString theme_attempt = theme + (m_style.isEmpty() ? "" : "-" + m_style);
// See if we have an alternative theme available as defined in the notification
foundtheme = LoadWindowFromXML("notification-ui.xml", theme_attempt, this);
if (!foundtheme && theme_attempt != theme)
{
// if not, default to the main one
foundtheme = LoadWindowFromXML("notification-ui.xml", theme, this);
}
if (!foundtheme) // If we cannot load the theme for any reason ...
return false;
m_artworkImage = dynamic_cast<MythUIImage*>(GetChild("image"));
m_titleText = dynamic_cast<MythUIText*>(GetChild("title"));
m_originText = dynamic_cast<MythUIText*>(GetChild("origin"));
m_descriptionText = dynamic_cast<MythUIText*>(GetChild("description"));
m_extraText = dynamic_cast<MythUIText*>(GetChild("extra"));
m_progresstextText = dynamic_cast<MythUIText*>(GetChild("progress_text"));
m_progressBar = dynamic_cast<MythUIProgressBar*>(GetChild("progress"));
m_errorState = dynamic_cast<MythUIStateType*>(GetChild("errorstate"));
m_mediaState = dynamic_cast<MythUIStateType*>(GetChild("mediastate"));
if (m_errorState)
{
m_errorState->DisplayState(m_content & kError ? "error" : "ok");
LOG(VB_GUI, LOG_DEBUG, LOC + QString("Create: Set error state to %1").arg(m_content & kError ? "error" : "ok"));
}
if (m_mediaState && (m_update & kImage))
{
m_mediaState->DisplayState(m_content & kNoArtwork ? "noartwork" : "ok");
LOG(VB_GUI, LOG_DEBUG, LOC + QString("Create: Set media state to %1").arg(m_content & kNoArtwork ? "noartwork" : "ok"));
}
// store original position
m_position = GetPosition();
m_created = true;
if ((m_visibility & ~MythNotification::kPlayback) == 0)
{
// Visibility will be set automatically during video playback
// so can be ignored here
SetVisible(false);
}
// We need to re-run init
m_refresh = true;
return true;
}
/**
* Update the various fields of a MythUINotificationScreen.
*/
void MythUINotificationScreen::Init(void)
{
if (!m_refresh) // nothing got changed so far, return
return;
AdjustYPosition();
if (m_artworkImage && (m_update & kImage))
{
if (!m_imagePath.isNull())
{
// We have a path to the image, use it
m_artworkImage->SetFilename(m_imagePath);
m_artworkImage->Load();
}
else if (!m_image.isNull())
{
// We don't have a path to the image, but the image itself
MythImage *img = new MythImage(m_artworkImage->GetPainter());
img->Assign(m_image);
m_artworkImage->SetImage(img);
img->DecrRef();
}
else
{
// Will default to displaying whatever placeholder image is defined
// in the xml by the themer, means we can show _something_ rather than
// a big empty hole. Generally you always want to call Reset() in
// these circumstances
m_artworkImage->Reset();
}
}
if (m_update != kNone)
{
InfoMap tmap;
tmap["title"] = m_title;
if (m_update & kImage)
{
tmap["image"] = m_imagePath;
}
tmap["origin"] = m_origin;
tmap["description"] = m_description;
tmap["extra"] = m_extra;
if (m_update & kDuration)
{
tmap["progress_text"] = m_progresstext;
tmap["progress"] = QString("%1").arg((int)(m_progress * 100));
}
SetTextFromMap(tmap);
}
if (m_update & kMetaData)
{
if (m_titleText && m_title.isNull())
{
m_titleText->Reset();
}
if (m_originText && m_origin.isNull())
{
m_originText->Reset();
}
if (m_descriptionText && m_description.isNull())
{
m_descriptionText->Reset();
}
if (m_extraText && m_extra.isNull())
{
m_extraText->Reset();
}
}
if (m_update & kDuration)
{
if (m_progresstextText && m_progresstext.isEmpty())
{
m_progresstextText->Reset();
}
if (m_progressBar)
{
if (m_progress >= 0)
{
m_progressBar->SetStart(0);
m_progressBar->SetTotal(100);
m_progressBar->SetUsed(100 * m_progress);
}
else
{
// Same as above, calling Reset() allows for a sane, themer defined
//default to be displayed
m_progressBar->Reset();
}
}
}
if (m_progressBar)
{
m_progressBar->SetVisible((m_content & kDuration) != 0);
}
if (m_errorState)
{
m_errorState->DisplayState(m_update & kError ? "error" : "ok");
LOG(VB_GUI, LOG_DEBUG, LOC + QString("Init: Set error state to %1").arg(m_update & kError ? "error" : "ok"));
}
if (m_mediaState && (m_update & kImage))
{
m_mediaState->DisplayState(m_update & kNoArtwork ? "noartwork" : "ok");
LOG(VB_GUI, LOG_DEBUG, LOC + QString("Init: Set media state to %1").arg(m_update & kNoArtwork ? "noartwork" : "ok"));
}
// No field will be refreshed the next time unless specified otherwise
m_update = kNone;
if (GetScreenStack() && !m_added)
{
GetScreenStack()->AddScreen(this);
m_added = true;
}
m_refresh = false;
}
/**
* Update artwork image.
* must call Init() for screen to be updated.
*/
void MythUINotificationScreen::UpdateArtwork(const QImage &image)
{
m_image = image;
// We need to re-run init
m_refresh = true;
}
/**
* Update artwork image via URL or file path.
* must call Init() for screen to be updated.
*/
void MythUINotificationScreen::UpdateArtwork(const QString &image)
{
m_imagePath = image;
// We need to re-run init
m_refresh = true;
}
/**
* Read some DMAP tag to extract title, artist, album and file format.
* must call Init() for screen to be updated.
* If metadata update flag is set; a Null string means to leave the text field
* unchanged.
*/
void MythUINotificationScreen::UpdateMetaData(const DMAP &data)
{
QString tmp;
tmp = data["minm"];
if (!(tmp.isNull() && (m_update & kMetaData)))
{
m_title = tmp;
}
tmp = data["asar"];
if (!(tmp.isNull() && (m_update & kMetaData)))
{
m_origin = tmp;
}
tmp = data["asal"];
if (!(tmp.isNull() && (m_update & kMetaData)))
{
m_description = tmp;
}
tmp = data["asfm"];
if (!(tmp.isNull() && (m_update & kMetaData)))
{
m_extra = tmp;
}
// We need to re-run init
m_refresh = true;
}
/**
* Update playback position information.
* must call Init() for screen to be updated.
*/
void MythUINotificationScreen::UpdatePlayback(float progress, const QString &text)
{
m_progress = progress;
m_progresstext = text;
// We need to re-run init
m_refresh = true;
}
/**
* Update Y position of the screen
* All children elements will be relocated.
*/
void MythUINotificationScreen::AdjustYPosition(void)
{
MythPoint point = m_position;
point.setY(m_position.getY().toInt() + (GetHeight() + HGAP) * m_index);
if (point == GetPosition())
return;
SetPosition(point);
// We need to re-run init
m_refresh = true;
}
void MythUINotificationScreen::AdjustIndex(int by, bool set)
{
if (set)
{
m_index = by;
}
else
{
m_index += by;
}
AdjustYPosition();
}
/**
* set index, without recalculating coordinates
*/
void MythUINotificationScreen::SetIndex(int index)
{
if (index != m_index)
{
m_refresh = true;
m_index = index;
}
}
int MythUINotificationScreen::GetHeight(void)
{
return GetArea().getHeight().toInt();
}
void MythUINotificationScreen::ProcessTimer(void)
{
LOG(VB_GUI, LOG_DEBUG, LOC + "ProcessTimer()");
// delete screen
GetScreenStack()->PopScreen(this, true, true);
}
MythUINotificationScreen &MythUINotificationScreen::operator=(const MythUINotificationScreen &s)
{
// check if anything have changed
m_refresh = !(
m_id == s.m_id &&
m_image == s.m_image &&
m_imagePath == s.m_imagePath &&
m_title == s.m_title &&
m_origin == s.m_origin &&
m_description == s.m_description &&
m_extra == s.m_extra &&
m_duration == s.m_duration &&
m_progress == s.m_progress &&
m_progresstext == s.m_progresstext &&
m_content == s.m_content &&
m_fullscreen == s.m_fullscreen &&
m_expiry == s.m_expiry &&
m_index == s.m_index &&
m_style == s.m_style &&
m_visibility == s.m_visibility &&
m_priority == s.m_priority
);
m_id = s.m_id;
m_image = s.m_image;
m_imagePath = s.m_imagePath;
m_title = s.m_title;
m_origin = s.m_origin;
m_description = s.m_description;
m_extra = s.m_extra;
m_duration = s.m_duration;
m_progress = s.m_progress;
m_progresstext = s.m_progresstext;
m_content = s.m_content;
m_fullscreen = s.m_fullscreen;
m_expiry = s.m_expiry;
m_index = s.m_index;
m_style = s.m_style;
m_visibility = s.m_visibility;
m_priority = s.m_priority;
m_update = m_content; // so all fields are initialised regardless of notification type
return *this;
}
void MythUINotificationScreen::SetSingleShotTimer(int s, bool update)
{
// only registered application can display non-expiring notification
if (m_id > 0 && s < 0)
return;
int ms = s * 1000;
ms = ms <= DEFAULT_DURATION ? DEFAULT_DURATION : ms;
if (!update)
{
m_creation = MythDate::current();
}
m_expiry = MythDate::current().addMSecs(ms);
m_timer->stop();
m_timer->setSingleShot(true);
m_timer->start(ms);
}
// Public event handling
bool MythUINotificationScreen::keyPressEvent(QKeyEvent *event)
{
QStringList actions;
bool handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
for (int i = 0; i < actions.size() && !handled; i++)
{
QString action = actions[i];
if (action == "ESCAPE")
{
if (MythDate::current() < m_creation.addMSecs(MIN_LIFE))
return true; // was updated less than 1s ago, ignore
}
}
if (!handled)
{
handled = MythScreenType::keyPressEvent(event);
}
return handled;
}
/////////////////////// NCPrivate
NCPrivate::NCPrivate()
: m_currentId(0)
{
m_screenStack = new MythNotificationScreenStack(GetMythMainWindow(),
"mythuinotification",
this);
m_originalScreenStack = m_screenStack;
}
NCPrivate::~NCPrivate()
{
const bool isGuiThread =
QThread::currentThread() == QCoreApplication::instance()->thread();
if (!isGuiThread)
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Destructor not called from GUI thread");
}
QMutexLocker lock(&m_lock);
DeleteUnregistered();
DeleteAllRegistrations();
DeleteAllScreens();
// Delete all outstanding queued notifications
foreach(MythNotification *n, m_notifications)
{
delete n;
}
m_notifications.clear();
delete m_screenStack;
m_originalScreenStack = m_screenStack = NULL;
}
/**
* Remove screen from screens list.
* Qt slot called upon MythScreenType::Exiting().
*/
void NCPrivate::ScreenDeleted(void)
{
MythUINotificationScreen *screen =
static_cast<MythUINotificationScreen*>(sender());
bool duefordeletion = m_deletedScreens.contains(screen);
LOG(VB_GUI, LOG_DEBUG, LOC +
QString("ScreenDeleted: Entering (%1)").arg(duefordeletion));
// Check that screen wasn't about to be deleted
if (duefordeletion)
{
m_deletedScreens.removeAll(screen);
}
int n = m_screens.indexOf(screen);
if (n >= 0)
{
int num = m_screens.removeAll(screen);
LOG(VB_GUI, LOG_DEBUG, LOC +
QString("%1 screen removed from screens list").arg(num));
RefreshScreenPosition();
}
else
{
LOG(VB_GUI, LOG_DEBUG, LOC +
QString("Screen[%1] not found in screens list").arg(screen->m_id));
}
// remove the converted equivalent screen if any
if (m_converted.contains(screen))
{
delete m_converted[screen];
}
m_converted.remove(screen);
// search if an application had registered for it
if (m_registrations.contains(screen->m_id))
{
if (!duefordeletion)
{
if (!m_screenStack)
{
// we're in the middle of being deleted
m_registrations.remove(screen->m_id);
m_unregistered.remove(screen->m_id);
}
else
{
// don't remove the id from the list, as the application is still registered
// re-create the screen
MythUINotificationScreen *newscreen =
new MythUINotificationScreen(m_screenStack, *screen);
connect(newscreen, SIGNAL(ScreenDeleted()), this, SLOT(ScreenDeleted()));
m_registrations[screen->m_id] = newscreen;
// Screen was deleted, add it to suspended list
m_suspended.append(screen->m_id);
LOG(VB_GUI, LOG_DEBUG, LOC +
"ScreenDeleted: Suspending registered screen");
}
}
else
{
LOG(VB_GUI, LOG_DEBUG, LOC +
"ScreenDeleted: Deleting registered screen");
}
}
}
void NCPrivate::ScreenStackDeleted(void)
{
m_screenStack = NULL;
}
bool NCPrivate::Queue(const MythNotification ¬ification)
{
QMutexLocker lock(&m_lock);
int id = notification.GetId();
void *parent = notification.GetParent();
MythNotification *tmp = static_cast<MythNotification*>(notification.clone());
if (id > 0)
{
// quick sanity check to ensure the right caller is attempting
// to register a notification
if (!m_registrations.contains(id) || m_clients[id] != parent)
{
LOG(VB_GENERAL, LOG_DEBUG, LOC +
QString("Queue: 0x%1, not registered for id (%2)")
.arg((size_t)parent, QT_POINTER_SIZE, 16)
.arg(id));
id = -1;
}
else
{
// check if notification card has been suspended, in which case
// refuse all notification updates
if (m_suspended.contains(id))
{
if (notification.type() == MythNotification::Update)
{
delete tmp;
return false;
}
// got something else than an update, remove it from the
// suspended list
m_suspended.removeAll(id);
}
}
}
m_notifications.append(tmp);
// Tell the GUI thread we have new notifications to process
QCoreApplication::postEvent(
GetMythMainWindow(), new MythUINotificationCenterEvent());
return true;
}
void NCPrivate::ProcessQueue(void)
{
QMutexLocker lock(&m_lock);
DeleteAllScreens();
foreach (MythNotification *n, m_notifications)
{
int id = n->GetId();
bool created = false;
MythUINotificationScreen *screen = NULL;
if (id > 0)
{
screen = m_registrations[id];
}
if (!screen)
{
// We have a registration, but no screen. Create one and display it
screen = CreateScreen(n);
if (!screen) // Reads screen definition from xml, and constructs screen
{
LOG(VB_GENERAL, LOG_ERR, LOC +
QString("ProcessQueue: couldn't create required screen"));
delete n;
continue; // something is wrong ; ignore
}
if (id > 0)
{
m_registrations[id] = screen;
}
created = true;
}
else
{
screen->SetNotification(*n);
}
// if the screen got allocated, but did't read theme yet, do it now
if (screen && !screen->m_created)
{
if (!screen->Create())
{
delete screen;
delete n;
continue;
}
created = true;
}
if (created || !m_screens.contains(screen))
{
int pos = InsertScreen(screen);
// adjust vertical positions
RefreshScreenPosition(pos);
}
screen->doInit();
delete n;
}
m_notifications.clear();
DeleteUnregistered();
}
/**
* CreateScreen will create a MythUINotificationScreen instance.
* This screen will not be displayed until it is used.
*/
MythUINotificationScreen *NCPrivate::CreateScreen(MythNotification *n, int id)
{
MythUINotificationScreen *screen;
if (n)
{
screen = new MythUINotificationScreen(m_screenStack, *n);
}
else
{
screen = new MythUINotificationScreen(m_screenStack, id);
}
if (!screen->Create()) // Reads screen definition from xml, and constructs screen
{
// If we can't create the screen then we can't display it, so delete
// and abort
delete screen;
return NULL;
}
connect(screen, SIGNAL(ScreenDeleted()), this, SLOT(ScreenDeleted()));
return screen;
}
int NCPrivate::Register(void *from)
{
QMutexLocker lock(&m_lock);
if (!from)
return -1;
m_currentId++;
m_registrations.insert(m_currentId, NULL);
m_clients.insert(m_currentId, from);
return m_currentId;
}
void NCPrivate::UnRegister(void *from, int id, bool closeimemdiately)
{
QMutexLocker lock(&m_lock);
if (!m_registrations.contains(id))
{
LOG(VB_GENERAL, LOG_ERR, LOC +
QString("UnRegister: 0x%1, no such registration (%2)")
.arg((size_t)from, QT_POINTER_SIZE, 16)
.arg(id));
return;
}
if (m_clients[id] != from)
{
LOG(VB_GENERAL, LOG_ERR, LOC +
QString("UnRegister: 0x%1, not registered for id (%2")
.arg((size_t)from, QT_POINTER_SIZE, 16)
.arg(id));
}
// queue the de-registration
m_unregistered[id] = closeimemdiately;
m_clients.remove(id);
// Tell the GUI thread we have something to process
QCoreApplication::postEvent(
GetMythMainWindow(), new MythUINotificationCenterEvent());
}
void NCPrivate::DeleteAllRegistrations(void)
{
QMap<int, MythUINotificationScreen*>::iterator it = m_registrations.begin();