10#include <QCoreApplication>
30#define LOC QString("NotificationCenter: ")
32static 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())
QString GetImagePath() const
void Assign(const QImage &img)
int DecrRef(void) override
Decrements reference count and deletes on 0.
MythScreenStack * GetMainStack()
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
bool IsExitingToMain() const
static const Type kEventType
void ProcessQueue(void)
ProcessQueue will be called by the GUI event handler and will process all queued MythNotifications an...
void UnRegister(void *from, int id, bool closeimemdiately=false)
Unregister the client.
static void UpdateScreen(MythScreenType *screen)
Will call ::doInit() if the screen is a MythNotificationScreen and ::Create() has been called for it ...
int Register(void *from)
An application can register in which case it will be assigned a reusable screen, which can be modifie...
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...
static MythNotificationCenter * GetInstance(void)
returns the MythNotificationCenter singleton
static bool ScreenCreated(const MythScreenType *screen)
Return true if ::Create() has been called on screen.
virtual ~MythNotificationCenter()
void GetNotificationScreens(QList< MythScreenType * > &screens)
Return the list of notification screens being currently displayed.
int DisplayedNotifications(void) const
Returns number of notifications currently displayed.
int QueuedNotifications(void) const
Returns number of notifications currently queued.
MythNotificationCenter(void)
bool RemoveFirst(void)
Will remove the oldest notification from the stack return true if a screen was removed; or false if n...
bool Queue(const MythNotification ¬ification)
Queue a notification Queue() is thread-safe and can be called from anywhere.
static const int kFadeVal
void PopScreen(MythScreenType *screen, bool allowFade=true, bool deleteScreen=true) override
MythScreenType * GetTopScreen(void) const override
void UpdatePlayback(float progress, const QString &text)
Update playback position information.
void UpdateArtwork(const QImage &image)
Update artwork image.
MythNotificationScreen(MythScreenStack *stack, int id=-1)
void UpdateFrom(const MythNotificationScreen &s)
Copy metadata from another notification.
void SetIndex(int index)
set index, without recalculating coordinates
void AdjustIndex(int by, bool set=false)
MythUIText * m_originText
MythUIStateType * m_errorState
bool Create(void) override
void SetSingleShotTimer(std::chrono::seconds s, bool update=false)
std::chrono::seconds m_duration
void SetNotification(MythNotification ¬ification)
void UpdateMetaData(const DMAP &data)
Read some DMAP tag to extract title, artist, album and file format.
void AdjustYPosition(void)
Update Y position of the screen All children elements will be relocated.
MythNotification::Priority m_priority
MythUIImage * m_artworkImage
MythUIText * m_progresstextText
MythUIStateType * m_mediaState
MythUIText * m_descriptionText
MythNotification::Type m_type
~MythNotificationScreen() override
void Init(void) override
Update the various fields of a MythNotificationScreen.
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
MythUIProgressBar * m_progressBar
void SetErrorState(void) const
void SetVisibility(VNMask nVisibility)
Define a bitmask of Visibility.
Priority GetPriority() const
static const Type kUpdate
void SetFullScreen(bool FullScreen)
A notification may request to be displayed in full screen, this request may not be fullfilled should ...
bool GetFullScreen() const
void SetStyle(const QString &sStyle)
Contains an alternative notification style. Should a style be defined, the Notification Center will a...
MythEvent * clone() const override
static const Type kWarning
std::chrono::seconds GetDuration() const
void SetDuration(std::chrono::seconds Duration)
Contains a duration during which the notification will be displayed for. The duration is informative ...
VNMask GetVisibility() const
void SetPriority(Priority nPriority)
Reserved for future use, not implemented at this stage.
MythImage * GetFormatImage()
Returns a blank reference counted image in the format required for the Draw functions for this painte...
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
void setY(const QString &sY)
QString getHeight(void) const
virtual void PopScreen(MythScreenType *screen=nullptr, bool allowFade=true, bool deleteScreen=true)
void GetScreenList(QVector< MythScreenType * > &screens)
virtual void RecalculateDrawOrder(void)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
QVector< MythScreenType * > m_drawOrder
QVector< MythScreenType * > m_children
MythScreenType * m_topScreen
virtual MythScreenType * GetTopScreen(void) const
QVector< MythScreenType * > m_toDelete
Screen in which all other widgets are contained and rendered.
void SetFullscreen(bool full)
void SetDeleting(bool deleting)
virtual void aboutToHide(void)
MythScreenStack * GetScreenStack() const
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
bool IsDeleting(void) const
bool IsFullscreen(void) const
virtual void SetTextFromMap(const InfoMap &infoMap)
Image widget, displays a single image or multiple images in sequence.
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
void SetImage(MythImage *img)
Should not be used unless absolutely necessary since it bypasses the image caching and threaded loade...
void Reset(void) override
Reset the image back to the default defined in the theme.
void SetVisible(bool visible) override
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
This widget is used for grouping other widgets for display when a particular named state is called.
bool DisplayState(const QString &name)
All purpose text widget, displays a text string.
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
virtual void SetVisible(bool visible)
virtual MythPainter * GetPainter(void)
void AdjustAlpha(int mode, int alphachange, int minalpha=0, int maxalpha=255)
virtual MythRect GetArea(void) const
If the object has a minimum area defined, return it, other wise return the default area.
void SetPosition(int x, int y)
Convenience method, calls SetPosition(const MythPoint&) Override that instead to change functionality...
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
void SetAlpha(int newalpha)
virtual MythPoint GetPosition(void) const
int DisplayedNotifications(void) const
Returns number of notifications currently displayed.
QMap< int, bool > m_unregistered
void RefreshScreenPosition(int from=0)
Re-position screens on display.
QList< MythNotificationScreen * > m_deletedScreens
int InsertScreen(MythNotificationScreen *screen)
Insert screen into list of screens.
MythNotificationScreenStack * m_screenStack
int RemoveScreen(MythNotificationScreen *screen)
Remove screen from list of screens.
QMap< int, void * > m_clients
void DeleteUnregistered(void)
QMap< MythNotificationScreen *, MythNotificationScreen * > m_converted
void ScreenStackDeleted(void)
bool Queue(const MythNotification ¬ification)
Queue a notification Queue() is thread-safe and can be called from anywhere.
bool RemoveFirst(void)
Will remove the oldest notification from the stack return true if a screen was removed; or false if n...
MythNotificationScreen * CreateScreen(MythNotification *notification, int id=-1)
CreateScreen will create a MythNotificationScreen instance.
void DeleteAllRegistrations(void)
void DeleteAllScreens(void)
void GetNotificationScreens(QList< MythScreenType * > &screens)
Return the list of notification screens being currently displayed.
void ScreenDeleted(void)
Remove screen from screens list.
void ProcessQueue(void)
ProcessQueue will be called by the GUI event handler and will process all queued MythNotifications an...
int QueuedNotifications(void) const
Returns number of notifications currently queued.
MythNotificationScreenStack * m_originalScreenStack
void UnRegister(void *from, int id, bool closeimemdiately=false)
Unregister the client.
QMap< int, MythNotificationScreen * > m_registrations
int Register(void *from)
An application can register in which case it will be assigned a reusable screen, which can be modifie...
QList< MythNotificationScreen * > m_screens
QList< MythNotification * > m_notifications
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
static const iso6937table * d
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
MythNotificationCenter * GetNotificationCenter(void)
MythMainWindow * GetMythMainWindow(void)
QMap< QString, QString > DMAP
static constexpr std::chrono::milliseconds DEFAULT_DURATION
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
static constexpr int8_t HGAP
void ShowNotification(const QString &msg, const QString &from, const QString &detail, const VNMask visibility, const MythNotification::Priority priority)
QHash< QString, QString > InfoMap
QDateTime current(bool stripped)
Returns current Date and Time in UTC.