Skip to content

Commit 2a01d50

Browse files
committed
Add handling for media events to mythui. See code comments and documentation for details. Bumps the library API version, plugins will need to be rebuilt.
1 parent ffbae3f commit 2a01d50

File tree

7 files changed

+69
-6
lines changed

7 files changed

+69
-6
lines changed

mythtv/libs/libmyth/mythmediamonitor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,10 @@ void MediaMonitor::JumpToMediaHandler(MythMediaDevice* pMedia)
652652
handlers.at(selected).callback(pMedia);
653653
}
654654

655-
// Signal handler.
655+
/**
656+
* \brief Slot which is called when the device status changes and posts a
657+
* media event to the mainwindow
658+
*/
656659
void MediaMonitor::mediaStatusChanged(MediaStatus oldStatus,
657660
MythMediaDevice* pMedia)
658661
{

mythtv/libs/libmythbase/mythmedia.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class MPUBLIC MediaEvent : public QEvent
183183

184184
protected:
185185
MediaStatus m_OldStatus;
186-
QPointer<MythMediaDevice> m_Device;
186+
MythMediaDevice *m_Device;
187187
};
188188

189189
#endif

mythtv/libs/libmythui/mythmainwindow.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

mythtv/libs/libmythui/mythscreenstack.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ void MythScreenStack::GetDrawOrder(QVector<MythScreenType *> &screens)
186186
screens = m_DrawOrder;
187187
}
188188

189+
void MythScreenStack::GetScreenList(QVector<MythScreenType *> &screens)
190+
{
191+
if (m_InNewTransition)
192+
CheckNewFadeTransition();
193+
CheckDeletes();
194+
195+
screens = m_Children;
196+
}
197+
189198
void MythScreenStack::ScheduleInitIfNeeded(void)
190199
{
191200
// make sure Init() is called outside the paintEvent

mythtv/libs/libmythui/mythscreenstack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class MPUBLIC MythScreenStack : public QObject
2929
MythScreenType *GetTopScreen(void) const;
3030

3131
void GetDrawOrder(QVector<MythScreenType *> &screens);
32+
void GetScreenList(QVector<MythScreenType *> &screens);
3233
void ScheduleInitIfNeeded(void);
3334
void AllowReInit(void) { m_DoInit = true; }
3435
int TotalScreens() const;

mythtv/libs/libmythui/mythuitype.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static QObject *qChildHelper(const char *objName, const char *inheritsClass,
112112
else if ((!inheritsClass || obj->inherits(inheritsClass))
113113
&& (!objName || obj->objectName() == oName))
114114
return obj;
115-
if (recursiveSearch && (dynamic_cast<MythUIGroup *>(obj) != NULL)
115+
if (recursiveSearch && (dynamic_cast<MythUIGroup *>(obj) != NULL)
116116
&& (obj = qChildHelper(objName, inheritsClass,
117117
recursiveSearch,
118118
obj->children())))
@@ -707,14 +707,22 @@ void MythUIType::customEvent(QEvent *)
707707
/** \brief Mouse click/movement handler, receives mouse gesture events from the
708708
* QCoreApplication event loop. Should not be used directly.
709709
*
710-
* \param uitype The mythuitype receiving the event
711710
* \param event Mouse event
712711
*/
713-
bool MythUIType::gestureEvent(MythGestureEvent *ge)
712+
bool MythUIType::gestureEvent(MythGestureEvent *)
714713
{
715714
return false;
716715
}
717716

717+
/** \brief Media/Device status event handler, received from MythMediaMonitor
718+
*
719+
* \param event Media event
720+
*/
721+
void MythUIType::mediaEvent (MediaEvent*)
722+
{
723+
return;
724+
}
725+
718726
void MythUIType::LoseFocus(void)
719727
{
720728
if (!m_CanHaveFocus || !m_HasFocus)
@@ -853,7 +861,7 @@ bool MythUIType::ParseElement(
853861
const QString &filename, QDomElement &element, bool showWarnings)
854862
{
855863
//FIXME add movement etc.
856-
864+
857865
if (element.tagName() == "position")
858866
SetPosition(parsePoint(element));
859867
else if (element.tagName() == "area")

mythtv/libs/libmythui/mythuitype.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "xmlparsebase.h"
1111
#include "mythrect.h"
1212
#include "mythgesture.h"
13+
#include <mythmedia.h>
1314

1415
class MythImage;
1516
class MythPainter;
@@ -131,6 +132,7 @@ class MPUBLIC MythUIType : public QObject, public XMLParseBase
131132

132133
virtual bool keyPressEvent(QKeyEvent *);
133134
virtual bool gestureEvent(MythGestureEvent *);
135+
virtual void mediaEvent(MediaEvent *);
134136

135137
MythFontProperties *GetFont(const QString &text) const;
136138
bool AddFont(const QString &text, MythFontProperties *fontProp);

0 commit comments

Comments
 (0)