@@ -44,6 +44,7 @@ using namespace std;
4444#include " compat.h"
4545#include " mythsignalingtimer.h"
4646#include " mythcorecontext.h"
47+ #include " mythmedia.h"
4748
4849// Libmythui headers
4950#include " myththemebase.h"
@@ -2061,6 +2062,45 @@ void MythMainWindow::customEvent(QEvent *ce)
20612062 }
20622063 }
20632064#endif
2065+ else if (ce->type () == MediaEvent::kEventType )
2066+ {
2067+ MediaEvent *me = static_cast <MediaEvent*>(ce);
2068+
2069+ // A listener based system might be more efficient, but we should never
2070+ // have that many screens open at once so impact should be minimal.
2071+ //
2072+ // This approach is simpler for everyone to follow. Plugin writers
2073+ // don't have to worry about adding their screens to the list because
2074+ // all screens receive media events.
2075+ //
2076+ // Events are even sent to hidden or backgrounded screens, this avoids
2077+ // the need for those to poll for changes when they become visible again
2078+ // however this needs to be kept in mind if media changes trigger
2079+ // actions which would not be appropriate when the screen doesn't have
2080+ // focus. It is the programmers responsibility to ignore events when
2081+ // necessary.
2082+ QVector<MythScreenStack *>::Iterator it;
2083+ for (it = d->stackList .begin (); it != d->stackList .end (); ++it)
2084+ {
2085+ QVector<MythScreenType *> screenList;
2086+ (*it)->GetScreenList (screenList);
2087+ QVector<MythScreenType *>::Iterator sit;
2088+ for (sit = screenList.begin (); sit != screenList.end (); ++it)
2089+ {
2090+ MythScreenType *screen = (*sit);
2091+ if (screen)
2092+ screen->mediaEvent (me);
2093+ }
2094+ }
2095+
2096+ // Debugging
2097+ MythMediaDevice *device = me->getDevice ();
2098+ if (device)
2099+ {
2100+ VERBOSE (VB_GENERAL, QString (" Media Event: %1 - %2" )
2101+ .arg (device->getDevicePath ()).arg (device->getStatus ()));
2102+ }
2103+ }
20642104 else if (ce->type () == ScreenSaverEvent::kEventType )
20652105 {
20662106 ScreenSaverEvent *sse = static_cast <ScreenSaverEvent *>(ce);
0 commit comments