Go to the documentation of this file.
10 #include <QCoreApplication>
30 #define LOC QString("NotificationCenter: ")
32 static constexpr int8_t
HGAP { 5 };
38 (QEvent::Type) QEvent::registerEventType();
57 screen->setParent(
nullptr);
79 screen->deleteLater();
100 if (poppedFullscreen)
130 QVector<MythScreenType *>::const_iterator it =
m_children.end() - 1;
135 auto *s = qobject_cast<MythNotificationScreen *>(*it);
157 m_timer(new QTimer(this))
166 :
MythScreenType(stack,
"mythnotification"), m_id(notification.GetId()),
167 m_duration(notification.GetDuration()),
168 m_timer(new QTimer(this))
179 m_imagePath(s.m_imagePath),
181 m_origin(s.m_origin),
182 m_description(s.m_description),
184 m_duration(s.m_duration),
185 m_progress(s.m_progress),
186 m_progresstext(s.m_progresstext),
187 m_fullscreen(s.m_fullscreen),
188 m_content(s.m_content),
189 m_update(s.m_content),
191 m_timer(new QTimer(this)),
200 LOG(VB_GUI, LOG_DEBUG,
LOC +
"MythNotificationScreen dtor");
212 m_type = notification.type();
273 if (!notification.
GetStyle().isEmpty())
303 bool foundtheme =
false;
313 theme =
"notification-full";
317 theme =
"notification-image";
321 theme =
"notification";
324 QString theme_attempt = theme + (
m_style.isEmpty() ?
"" :
"-" +
m_style);
328 if (!foundtheme && theme_attempt != theme)
352 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"Create: Set media state to %1").arg((
m_content &
kNoArtwork) ?
"noartwork" :
"ok"));
423 tmap[
"progress"] = QString(
"%1").arg((
int)(
m_progress * 100));
482 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"Init: Set media state to %1").arg((
m_update &
kNoArtwork) ?
"noartwork" :
"ok"));
501 const char *state {
nullptr};
523 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"SetErrorState: Set error state to %1").arg(state));
695 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"Screen id %1 \"%2\" expired")
704 if (
m_id > 0 && s < 0s)
707 std::chrono::milliseconds ms = s;
719 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"Screen %1 expires at %2")
730 for (
int i = 0; i < actions.size() && !handled; i++)
732 const QString&
action = actions[i];
752 "mythnotificationcenter",
759 const bool isGuiThread =
760 QThread::currentThread() == QCoreApplication::instance()->thread();
764 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Destructor not called from GUI thread");
767 QMutexLocker lock(&
m_lock);
790 auto *screen = qobject_cast<MythNotificationScreen*>(sender());
791 if (screen ==
nullptr)
796 LOG(VB_GUI, LOG_DEBUG,
LOC +
797 QString(
"ScreenDeleted: Entering (%1)").arg(duefordeletion));
808 LOG(VB_GUI, LOG_DEBUG,
LOC +
809 QString(
"%1 screen removed from screens list").arg(num));
814 LOG(VB_GUI, LOG_DEBUG,
LOC +
815 QString(
"Screen[%1] not found in screens list").arg(screen->m_id));
846 LOG(VB_GUI, LOG_DEBUG,
LOC +
847 "ScreenDeleted: Suspending registered screen");
852 LOG(VB_GUI, LOG_DEBUG,
LOC +
853 "ScreenDeleted: Deleting registered screen");
865 QMutexLocker lock(&
m_lock);
867 int id = notification.
GetId();
876 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
877 QString(
"Queue: 0x%1, not registered for id (%2)")
878 .arg((
size_t)parent, QT_POINTER_SIZE, 16, QChar(
'0'))
901 QCoreApplication::postEvent(
909 QMutexLocker lock(&
m_lock);
916 bool created =
false;
925 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"Creating screen %1, \"%2\"")
926 .arg(
id).arg(n->GetDescription()));
932 LOG(VB_GENERAL, LOG_ERR,
LOC +
933 QString(
"ProcessQueue: couldn't create required screen"));
945 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"Using screen %1, \"%2\"")
946 .arg(
id).arg(screen->
m_title));
953 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"Reloading screen %1, \"%2\"")
954 .arg(
id).arg(screen->
m_title));
966 if (created || !
m_screens.contains(screen))
968 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"Inserting screen %1").arg(
id));
1013 QMutexLocker lock(&
m_lock);
1027 QMutexLocker lock(&
m_lock);
1031 LOG(VB_GENERAL, LOG_ERR,
LOC +
1032 QString(
"UnRegister: 0x%1, no such registration (%2)")
1033 .arg((
size_t)from, QT_POINTER_SIZE, 16, QChar(
'0'))
1040 LOG(VB_GENERAL, LOG_ERR,
LOC +
1041 QString(
"UnRegister: 0x%1, not registered for id (%2")
1042 .arg((
size_t)from, QT_POINTER_SIZE, 16, QChar(
'0'))
1052 QCoreApplication::postEvent(
1086 screen->deleteLater();
1102 bool needdelete =
false;
1107 bool closeimemdiately = it.value();
1113 if (screen !=
nullptr && !
m_suspended.contains(
id))
1116 if (screen->
m_duration <= 0s || closeimemdiately)
1146 QList<MythNotificationScreen*>::iterator it =
m_screens.begin();
1147 QList<MythNotificationScreen*>::iterator itend =
m_screens.end();
1175 QList<MythNotificationScreen*>::iterator it =
m_screens.begin();
1176 QList<MythNotificationScreen*>::iterator itend =
m_screens.end();
1178 for (; it != itend; ++it)
1197 QList<MythNotificationScreen*>::iterator it =
m_screens.begin();
1198 QList<MythNotificationScreen*>::iterator itend =
m_screens.end();
1202 for (; it != itend; ++it)
1204 if ((*it)->IsVisible())
1206 (*it)->AdjustIndex(position++,
true);
1210 (*it)->AdjustIndex(position,
true);
1212 if ((*it)->m_fullscreen)
1222 QList<MythScreenType*> list;
1223 QVector<MythScreenType*> screens;
1230 QMutexLocker lock(&
m_lock);
1235 for (
auto *item : std::as_const(screens))
1237 auto *screen = qobject_cast<MythNotificationScreen*>(item);
1260 if (screen->m_fullscreen)
1264 list.append(newscreen);
1286 QMutexLocker lock(&
m_lock);
1294 QList<MythNotificationScreen *>::const_iterator it =
m_screens.cend() - 1;
1326 const bool isGuiThread =
1327 QThread::currentThread() == QCoreApplication::instance()->thread();
1331 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Constructor not called from GUI thread");
1337 const bool isGuiThread =
1338 QThread::currentThread() == QCoreApplication::instance()->thread();
1342 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Destructor not called from GUI thread");
1351 return d->
Queue(notification);
1356 const bool isGuiThread =
1357 QThread::currentThread() == QCoreApplication::instance()->thread();
1361 LOG(VB_GENERAL, LOG_ERR,
LOC +
"ProcessQueue not called from GUI thread");
1380 const auto *s = qobject_cast<const MythNotificationScreen*>(screen);
1388 const auto *s = qobject_cast<const MythNotificationScreen*>(screen);
1391 return s->m_created;
1401 auto *s = qobject_cast<MythNotificationScreen*>(screen);
1427 const QString &from,
1428 const QString &detail,
1433 QString(), QString(), QString(), -1, -1s,
false,
1434 visibility, priority);
1438 const QString &from,
1439 const QString &detail,
1444 QString(), QString(), QString(), -1, -1s,
false,
1445 visibility, priority);
1450 const QString &origin,
1451 const QString &detail,
1452 const QString &image,
1453 const QString &extra,
1454 const QString &progress_text,
float progress,
1455 std::chrono::seconds duration,
1459 const QString &style)
1462 msg, origin, detail, image, extra, progress_text,
progress,
1463 duration, fullscreen, visibility, priority, style);
1468 const QString &origin,
1469 const QString &detail,
1470 const QString &image,
1471 const QString &extra,
1472 const QString &progress_text,
float progress,
1473 std::chrono::seconds duration,
1477 const QString &style)
1486 data[
"asar"] = origin.isNull() ? QCoreApplication::translate(
"(Common)",
1488 data[
"asal"] = detail;
1489 data[
"asfm"] = extra;
1497 if (duration != 0s &&
1507 if (!image.isEmpty())
static QDateTime ScreenExpiryTime(const MythScreenType *screen)
Return when the given screen is going to expire will return an invalid QDateTime if screen isn't a My...
MythScreenStack * GetMainStack()
void UpdateFrom(const MythNotificationScreen &s)
Copy metadata from another notification.
void ProcessQueue(void)
ProcessQueue will be called by the GUI event handler and will process all queued MythNotifications an...
Image widget, displays a single image or multiple images in sequence.
bool RemoveFirst(void)
Will remove the oldest notification from the stack return true if a screen was removed; or false if n...
QList< MythNotificationScreen * > m_deletedScreens
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
static void error(const char *str,...)
void ShowNotificationError(const QString &msg, const QString &from, const QString &detail, const VNMask visibility, const MythNotification::Priority priority)
convenience utility to display error message as notification
MythUIStateType * m_errorState
QString GetImagePath() const
void ShowNotification(const QString &msg, const QString &from, const QString &detail, const VNMask visibility, const MythNotification::Priority priority)
void ScreenStackDeleted(void)
MythUIText * m_descriptionText
int QueuedNotifications(void) const
Returns number of notifications currently queued.
bool RemoveFirst(void)
Will remove the oldest notification from the stack return true if a screen was removed; or false if n...
void SetDuration(std::chrono::seconds Duration)
Contains a duration during which the notification will be displayed for. The duration is informative ...
int Register(void *from)
An application can register in which case it will be assigned a reusable screen, which can be modifie...
void GetNotificationScreens(QList< MythScreenType * > &screens)
Return the list of notification screens being currently displayed.
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
int QueuedNotifications(void) const
Returns number of notifications currently queued.
void PopScreen(MythScreenType *screen, bool allowFade=true, bool deleteScreen=true) override
MythImage * GetFormatImage()
Returns a blank reference counted image in the format required for the Draw functions for this painte...
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
void DeleteAllRegistrations(void)
std::chrono::seconds GetDuration() const
virtual MythPainter * GetPainter(void)
int Register(void *from)
An application can register in which case it will be assigned a reusable screen, which can be modifie...
void SetPriority(Priority nPriority)
Reserved for future use, not implemented at this stage.
bool Queue(const MythNotification ¬ification)
Queue a notification Queue() is thread-safe and can be called from anywhere.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Screen in which all other widgets are contained and rendered.
void SetNotification(MythNotification ¬ification)
void SetVisibility(VNMask nVisibility)
Define a bitmask of Visibility.
void DeleteUnregistered(void)
void Reset(void) override
Reset the image back to the default defined in the theme.
bool GetFullScreen() const
QList< MythNotificationScreen * > m_screens
void SetStyle(const QString &sStyle)
Contains an alternative notification style. Should a style be defined, the Notification Center will a...
QMap< int, void * > m_clients
QVector< MythScreenType * > m_children
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
QMap< MythNotificationScreen *, MythNotificationScreen * > m_converted
void RefreshScreenPosition(int from=0)
Re-position screens on display.
QVector< MythScreenType * > m_drawOrder
virtual MythRect GetArea(void) const
If the object has a minimum area defined, return it, other wise return the default area.
MythNotificationScreenStack * m_screenStack
static constexpr std::chrono::milliseconds DEFAULT_DURATION
QHash< QString, QString > InfoMap
void GetScreenList(QVector< MythScreenType * > &screens)
MythNotificationCenter(void)
MythNotification::Type m_type
void SetAlpha(int newalpha)
static const int kFadeVal
void ProcessQueue(void)
ProcessQueue will be called by the GUI event handler and will process all queued MythNotifications an...
std::chrono::seconds m_duration
void SetFullScreen(bool FullScreen)
A notification may request to be displayed in full screen, this request may not be fullfilled should ...
MythUIText * m_originText
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
MythUIStateType * m_mediaState
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
void SetPosition(int x, int y)
Convenience method, calls SetPosition(const MythPoint&) Override that instead to change functionality...
~MythNotificationScreen() override
Priority GetPriority() const
virtual ~MythNotificationCenter()
void AdjustAlpha(int mode, int alphachange, int minalpha=0, int maxalpha=255)
MythUIText * m_progresstextText
MythEvent * clone() const override
MythScreenType * GetTopScreen(void) const override
virtual MythPoint GetPosition(void) const
int DisplayedNotifications(void) const
Returns number of notifications currently displayed.
void setY(const QString &sY)
int DecrRef(void) override
Decrements reference count and deletes on 0.
virtual void SetTextFromMap(const InfoMap &infoMap)
static const Type kEventType
void UpdatePlayback(float progress, const QString &text)
Update playback position information.
int InsertScreen(MythNotificationScreen *screen)
Insert screen into list of screens.
int RemoveScreen(MythNotificationScreen *screen)
Remove screen from list of screens.
MythNotificationScreen(MythScreenStack *stack, int id=-1)
MythNotificationScreenStack * m_originalScreenStack
MythScreenStack * GetScreenStack() const
void UnRegister(void *from, int id, bool closeimemdiately=false)
Unregister the client.
void AdjustYPosition(void)
Update Y position of the screen All children elements will be relocated.
static constexpr int8_t HGAP
MythNotificationScreen * CreateScreen(MythNotification *notification, int id=-1)
CreateScreen will create a MythNotificationScreen instance.
void DeleteAllScreens(void)
MythUIProgressBar * m_progressBar
All purpose text widget, displays a text string.
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
QVector< MythScreenType * > m_toDelete
QMap< int, MythNotificationScreen * > m_registrations
MythNotification::Priority m_priority
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
bool IsDeleting(void) const
void AdjustIndex(int by, bool set=false)
void SetIndex(int index)
set index, without recalculating coordinates
virtual void SetVisible(bool visible)
void GetNotificationScreens(QList< MythScreenType * > &screens)
Return the list of notification screens being currently displayed.
MythNotificationCenter * GetNotificationCenter(void)
void UnRegister(void *from, int id, bool closeimemdiately=false)
Unregister the client.
virtual void PopScreen(MythScreenType *screen=nullptr, bool allowFade=true, bool deleteScreen=true)
static void UpdateScreen(MythScreenType *screen)
Will call ::doInit() if the screen is a MythNotificationScreen and ::Create() has been called for it ...
MythScreenType * m_topScreen
MythMainWindow * GetMythMainWindow(void)
static const Type kWarning
static const Type kUpdate
int DisplayedNotifications(void) const
Returns number of notifications currently displayed.
bool IsExitingToMain() const
void SetImage(MythImage *img)
Should not be used unless absolutely necessary since it bypasses the image caching and threaded loade...
void UpdateMetaData(const DMAP &data)
Read some DMAP tag to extract title, artist, album and file format.
void Init(void) override
Update the various fields of a MythNotificationScreen.
static MythNotificationCenter * GetInstance(void)
returns the MythNotificationCenter singleton
virtual void aboutToHide(void)
void SetDeleting(bool deleting)
virtual void RecalculateDrawOrder(void)
MythUIImage * m_artworkImage
static const iso6937table * d
void SetErrorState(void) const
QString getHeight(void) const
void Assign(const QImage &img)
QMap< QString, QString > DMAP
void ScreenDeleted(void)
Remove screen from screens list.
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
void SetVisible(bool visible) override
QMap< int, bool > m_unregistered
void UpdateArtwork(const QImage &image)
Update artwork image.
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
bool IsFullscreen(void) const
void SetSingleShotTimer(std::chrono::seconds s, bool update=false)
This widget is used for grouping other widgets for display when a particular named state is called....
static bool ScreenCreated(const MythScreenType *screen)
Return true if ::Create() has been called on screen.
VNMask GetVisibility() const
bool DisplayState(const QString &name)
QList< MythNotification * > m_notifications
bool Create(void) override
void SetFullscreen(bool full)
virtual MythScreenType * GetTopScreen(void) const
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
bool Queue(const MythNotification ¬ification)
Queue a notification Queue() is thread-safe and can be called from anywhere.