Permalink
Browse files

Add handling for media events to mythui. See code comments and docume…

…ntation for details. Bumps the library API version, plugins will need to be rebuilt.
  • Loading branch information...
1 parent ffbae3f commit 2a01d5046ff743b521fe121ced31ea1133a3f3c4 @stuartm stuartm committed Jan 27, 2011
@@ -652,7 +652,10 @@ void MediaMonitor::JumpToMediaHandler(MythMediaDevice* pMedia)
handlers.at(selected).callback(pMedia);
}
-// Signal handler.
+/**
+ * \brief Slot which is called when the device status changes and posts a
+ * media event to the mainwindow
+ */
void MediaMonitor::mediaStatusChanged(MediaStatus oldStatus,
MythMediaDevice* pMedia)
{
@@ -183,7 +183,7 @@ class MPUBLIC MediaEvent : public QEvent
protected:
MediaStatus m_OldStatus;
- QPointer<MythMediaDevice> m_Device;
+ MythMediaDevice *m_Device;
};
#endif
@@ -44,6 +44,7 @@ using namespace std;
#include "compat.h"
#include "mythsignalingtimer.h"
#include "mythcorecontext.h"
+#include "mythmedia.h"
// Libmythui headers
#include "myththemebase.h"
@@ -2061,6 +2062,45 @@ void MythMainWindow::customEvent(QEvent *ce)
}
}
#endif
+ else if (ce->type() == MediaEvent::kEventType)
+ {
+ MediaEvent *me = static_cast<MediaEvent*>(ce);
+
+ // A listener based system might be more efficient, but we should never
+ // have that many screens open at once so impact should be minimal.
+ //
+ // This approach is simpler for everyone to follow. Plugin writers
+ // don't have to worry about adding their screens to the list because
+ // all screens receive media events.
+ //
+ // Events are even sent to hidden or backgrounded screens, this avoids
+ // the need for those to poll for changes when they become visible again
+ // however this needs to be kept in mind if media changes trigger
+ // actions which would not be appropriate when the screen doesn't have
+ // focus. It is the programmers responsibility to ignore events when
+ // necessary.
+ QVector<MythScreenStack *>::Iterator it;
+ for (it = d->stackList.begin(); it != d->stackList.end(); ++it)
+ {
+ QVector<MythScreenType *> screenList;
+ (*it)->GetScreenList(screenList);
+ QVector<MythScreenType *>::Iterator sit;
+ for (sit = screenList.begin(); sit != screenList.end(); ++it)
+ {
+ MythScreenType *screen = (*sit);
+ if (screen)
+ screen->mediaEvent(me);
+ }
+ }
+
+ // Debugging
+ MythMediaDevice *device = me->getDevice();
+ if (device)
+ {
+ VERBOSE(VB_GENERAL, QString("Media Event: %1 - %2")
+ .arg(device->getDevicePath()).arg(device->getStatus()));
+ }
+ }
else if (ce->type() == ScreenSaverEvent::kEventType)
{
ScreenSaverEvent *sse = static_cast<ScreenSaverEvent *>(ce);
@@ -186,6 +186,15 @@ void MythScreenStack::GetDrawOrder(QVector<MythScreenType *> &screens)
screens = m_DrawOrder;
}
+void MythScreenStack::GetScreenList(QVector<MythScreenType *> &screens)
+{
+ if (m_InNewTransition)
+ CheckNewFadeTransition();
+ CheckDeletes();
+
+ screens = m_Children;
+}
+
void MythScreenStack::ScheduleInitIfNeeded(void)
{
// make sure Init() is called outside the paintEvent
@@ -29,6 +29,7 @@ class MPUBLIC MythScreenStack : public QObject
MythScreenType *GetTopScreen(void) const;
void GetDrawOrder(QVector<MythScreenType *> &screens);
+ void GetScreenList(QVector<MythScreenType *> &screens);
void ScheduleInitIfNeeded(void);
void AllowReInit(void) { m_DoInit = true; }
int TotalScreens() const;
@@ -112,7 +112,7 @@ static QObject *qChildHelper(const char *objName, const char *inheritsClass,
else if ((!inheritsClass || obj->inherits(inheritsClass))
&& (!objName || obj->objectName() == oName))
return obj;
- if (recursiveSearch && (dynamic_cast<MythUIGroup *>(obj) != NULL)
+ if (recursiveSearch && (dynamic_cast<MythUIGroup *>(obj) != NULL)
&& (obj = qChildHelper(objName, inheritsClass,
recursiveSearch,
obj->children())))
@@ -707,14 +707,22 @@ void MythUIType::customEvent(QEvent *)
/** \brief Mouse click/movement handler, receives mouse gesture events from the
* QCoreApplication event loop. Should not be used directly.
*
- * \param uitype The mythuitype receiving the event
* \param event Mouse event
*/
-bool MythUIType::gestureEvent(MythGestureEvent *ge)
+bool MythUIType::gestureEvent(MythGestureEvent *)
{
return false;
}
+/** \brief Media/Device status event handler, received from MythMediaMonitor
+ *
+ * \param event Media event
+ */
+void MythUIType::mediaEvent (MediaEvent*)
+{
+ return;
+}
+
void MythUIType::LoseFocus(void)
{
if (!m_CanHaveFocus || !m_HasFocus)
@@ -853,7 +861,7 @@ bool MythUIType::ParseElement(
const QString &filename, QDomElement &element, bool showWarnings)
{
//FIXME add movement etc.
-
+
if (element.tagName() == "position")
SetPosition(parsePoint(element));
else if (element.tagName() == "area")
@@ -10,6 +10,7 @@
#include "xmlparsebase.h"
#include "mythrect.h"
#include "mythgesture.h"
+#include <mythmedia.h>
class MythImage;
class MythPainter;
@@ -131,6 +132,7 @@ class MPUBLIC MythUIType : public QObject, public XMLParseBase
virtual bool keyPressEvent(QKeyEvent *);
virtual bool gestureEvent(MythGestureEvent *);
+ virtual void mediaEvent(MediaEvent *);
MythFontProperties *GetFont(const QString &text) const;
bool AddFont(const QString &text, MythFontProperties *fontProp);

0 comments on commit 2a01d50

Please sign in to comment.