Go to the documentation of this file.
10 #include <QCoreApplication>
31 #define LOC QString("NotificationCenter: ")
34 #define DEFAULT_DURATION 5000 // in ms
39 (QEvent::Type) QEvent::registerEventType();
58 screen->setParent(
nullptr);
80 screen->deleteLater();
101 if (poppedFullscreen)
131 QVector<MythScreenType *>::const_iterator it =
m_children.end() - 1;
136 auto *s = qobject_cast<MythNotificationScreen *>(*it);
158 m_timer(new QTimer(this))
167 :
MythScreenType(stack,
"mythnotification"), m_id(notification.GetId()),
168 m_duration(notification.GetDuration()),
169 m_timer(new QTimer(this))
180 m_imagePath(s.m_imagePath),
182 m_origin(s.m_origin),
183 m_description(s.m_description),
185 m_duration(s.m_duration),
186 m_progress(s.m_progress),
187 m_progresstext(s.m_progresstext),
188 m_fullscreen(s.m_fullscreen),
189 m_content(s.m_content),
190 m_update(s.m_content),
192 m_timer(new QTimer(this)),
201 LOG(VB_GUI, LOG_DEBUG,
LOC +
"MythNotificationScreen dtor");
213 m_type = notification.type();
274 if (!notification.
GetStyle().isEmpty())
304 bool foundtheme =
false;
314 theme =
"notification-full";
318 theme =
"notification-image";
322 theme =
"notification";
325 QString theme_attempt = theme + (
m_style.isEmpty() ?
"" :
"-" +
m_style);
329 if (!foundtheme && theme_attempt != theme)
424 tmap[
"progress"] = QString(
"%1").arg((
int)(
m_progress * 100));
502 const char *state =
"ok";
524 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"SetErrorState: Set error state to %1").
arg(state));
697 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"Screen id %1 \"%2\" expired")
706 if (
m_id > 0 && s < 0)
721 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"Screen %1 expires at %2")
732 for (
int i = 0; i < actions.size() && !handled; i++)
734 QString
action = actions[i];
754 "mythnotificationcenter",
761 const bool isGuiThread =
762 QThread::currentThread() == QCoreApplication::instance()->thread();
766 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Destructor not called from GUI thread");
769 QMutexLocker lock(&
m_lock);
792 auto *screen = qobject_cast<MythNotificationScreen*>(sender());
793 if (screen ==
nullptr)
798 LOG(VB_GUI, LOG_DEBUG,
LOC +
799 QString(
"ScreenDeleted: Entering (%1)").
arg(duefordeletion));
810 LOG(VB_GUI, LOG_DEBUG,
LOC +
811 QString(
"%1 screen removed from screens list").
arg(num));
816 LOG(VB_GUI, LOG_DEBUG,
LOC +
817 QString(
"Screen[%1] not found in screens list").
arg(screen->m_id));
848 LOG(VB_GUI, LOG_DEBUG,
LOC +
849 "ScreenDeleted: Suspending registered screen");
854 LOG(VB_GUI, LOG_DEBUG,
LOC +
855 "ScreenDeleted: Deleting registered screen");
867 QMutexLocker lock(&
m_lock);
869 int id = notification.
GetId();
878 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
879 QString(
"Queue: 0x%1, not registered for id (%2)")
880 .
arg((
size_t)parent, QT_POINTER_SIZE, 16, QChar(
'0'))
903 QCoreApplication::postEvent(
911 QMutexLocker lock(&
m_lock);
918 bool created =
false;
927 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"Creating screen %1, \"%2\"")
928 .
arg(
id).
arg(n->GetDescription()));
934 LOG(VB_GENERAL, LOG_ERR,
LOC +
935 QString(
"ProcessQueue: couldn't create required screen"));
947 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"Using screen %1, \"%2\"")
955 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"Reloading screen %1, \"%2\"")
968 if (created || !
m_screens.contains(screen))
970 LOG(VB_GUI, LOG_DEBUG,
LOC + QString(
"Inserting screen %1").
arg(
id));
1015 QMutexLocker lock(&
m_lock);
1029 QMutexLocker lock(&
m_lock);
1033 LOG(VB_GENERAL, LOG_ERR,
LOC +
1034 QString(
"UnRegister: 0x%1, no such registration (%2)")
1035 .
arg((
size_t)from, QT_POINTER_SIZE, 16, QChar(
'0'))
1042 LOG(VB_GENERAL, LOG_ERR,
LOC +
1043 QString(
"UnRegister: 0x%1, not registered for id (%2")
1044 .
arg((
size_t)from, QT_POINTER_SIZE, 16, QChar(
'0'))
1054 QCoreApplication::postEvent(
1088 screen->deleteLater();
1104 bool needdelete =
false;
1109 bool closeimemdiately = it.value();
1115 if (screen !=
nullptr && !
m_suspended.contains(
id))
1118 if (screen->
m_duration <= 0 || closeimemdiately)
1148 QList<MythNotificationScreen*>::iterator it =
m_screens.begin();
1149 QList<MythNotificationScreen*>::iterator itend =
m_screens.end();
1177 QList<MythNotificationScreen*>::iterator it =
m_screens.begin();
1178 QList<MythNotificationScreen*>::iterator itend =
m_screens.end();
1180 for (; it != itend; ++it)
1199 QList<MythNotificationScreen*>::iterator it =
m_screens.begin();
1200 QList<MythNotificationScreen*>::iterator itend =
m_screens.end();
1204 for (; it != itend; ++it)
1206 if ((*it)->IsVisible())
1208 (*it)->AdjustIndex(position++,
true);
1212 (*it)->AdjustIndex(position,
true);
1214 if ((*it)->m_fullscreen)
1224 QList<MythScreenType*> list;
1225 QVector<MythScreenType*> screens;
1232 QMutexLocker lock(&
m_lock);
1237 for (
auto *item : qAsConst(screens))
1239 auto *screen = qobject_cast<MythNotificationScreen*>(item);
1262 if (screen->m_fullscreen)
1266 list.append(newscreen);
1288 QMutexLocker lock(&
m_lock);
1296 QList<MythNotificationScreen *>::const_iterator it =
m_screens.cend() - 1;
1328 const bool isGuiThread =
1329 QThread::currentThread() == QCoreApplication::instance()->thread();
1333 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Constructor not called from GUI thread");
1339 const bool isGuiThread =
1340 QThread::currentThread() == QCoreApplication::instance()->thread();
1344 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Destructor not called from GUI thread");
1353 return d->
Queue(notification);
1358 const bool isGuiThread =
1359 QThread::currentThread() == QCoreApplication::instance()->thread();
1363 LOG(VB_GENERAL, LOG_ERR,
LOC +
"ProcessQueue not called from GUI thread");
1382 const auto *s = qobject_cast<const MythNotificationScreen*>(screen);
1390 const auto *s = qobject_cast<const MythNotificationScreen*>(screen);
1393 return s->m_created;
1403 auto *s = qobject_cast<MythNotificationScreen*>(screen);
1429 const QString &from,
1430 const QString &detail,
1435 QString(), QString(), QString(), -1, -1,
false,
1436 visibility, priority);
1440 const QString &from,
1441 const QString &detail,
1446 QString(), QString(), QString(), -1, -1,
false,
1447 visibility, priority);
1452 const QString &origin,
1453 const QString &detail,
1454 const QString &image,
1455 const QString &extra,
1456 const QString &progress_text,
float progress,
1461 const QString &style)
1464 msg, origin, detail, image, extra, progress_text,
progress,
1465 duration, fullscreen, visibility, priority, style);
1470 const QString &origin,
1471 const QString &detail,
1472 const QString &image,
1473 const QString &extra,
1474 const QString &progress_text,
float progress,
1479 const QString &style)
1488 data[
"asar"] = origin.isNull() ? QCoreApplication::translate(
"(Common)",
1490 data[
"asal"] = detail;
1491 data[
"asfm"] = extra;
1509 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
void SetDuration(int Duration)
Contains a duration during which the notification will be displayed for. The duration is informative ...
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...
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)
arg(title).arg(filename).arg(doDelete))
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
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...
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)
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.
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)
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 SetSingleShotTimer(int s, bool update=false)
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
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.