Skip to content

Commit

Permalink
Add handling for media events to mythui. See code comments and docume…
Browse files Browse the repository at this point in the history
…ntation for details. Bumps the library API version, plugins will need to be rebuilt.
  • Loading branch information
stuartm committed Jan 27, 2011
1 parent ffbae3f commit 2a01d50
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 6 deletions.
5 changes: 4 additions & 1 deletion mythtv/libs/libmyth/mythmediamonitor.cpp
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/mythmedia.h
Expand Up @@ -183,7 +183,7 @@ class MPUBLIC MediaEvent : public QEvent

protected:
MediaStatus m_OldStatus;
QPointer<MythMediaDevice> m_Device;
MythMediaDevice *m_Device;
};

#endif
40 changes: 40 additions & 0 deletions mythtv/libs/libmythui/mythmainwindow.cpp
Expand Up @@ -44,6 +44,7 @@ using namespace std;
#include "compat.h"
#include "mythsignalingtimer.h"
#include "mythcorecontext.h"
#include "mythmedia.h"

// Libmythui headers
#include "myththemebase.h"
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions mythtv/libs/libmythui/mythscreenstack.cpp
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythui/mythscreenstack.h
Expand Up @@ -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;
Expand Down
16 changes: 12 additions & 4 deletions mythtv/libs/libmythui/mythuitype.cpp
Expand Up @@ -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())))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions mythtv/libs/libmythui/mythuitype.h
Expand Up @@ -10,6 +10,7 @@
#include "xmlparsebase.h"
#include "mythrect.h"
#include "mythgesture.h"
#include <mythmedia.h>

class MythImage;
class MythPainter;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2a01d50

Please sign in to comment.