717 changes: 717 additions & 0 deletions mythtv/libs/libmythui/cecadapter.cpp

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions mythtv/libs/libmythui/cecadapter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef CECADAPTER_H_
#define CECADAPTER_H_

#include <QMutex>
#include "mthread.h"

#define LIBCEC_ENABLED QString("libCECEnabled")
#define LIBCEC_DEVICE QString("libCECDevice")
#define LIBCEC_PORT QString("libCECPort")
#define LIBCEC_DEVICEID QString("libCECDeviceID")
#define POWEROFFTV_ALLOWED QString("PowerOffTVAllowed")
#define POWEROFFTV_ONEXIT QString("PowerOffTVOnExit")
#define POWERONTV_ALLOWED QString("PowerOnTVAllowed")
#define POWERONTV_ONSTART QString("PowerOnTVOnStart")

class CECAdapterPriv;

class CECAdapter : public QObject, public MThread
{
Q_OBJECT

public:
static QStringList GetDeviceList(void);

CECAdapter();
virtual ~CECAdapter();
bool IsValid();
void Action(const QString &action);

public slots:
void Process();

private:
CECAdapterPriv *m_priv;
static QMutex *gLock;
};

#endif

6 changes: 6 additions & 0 deletions mythtv/libs/libmythui/libmythui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ using_lirc {
SOURCES += lirc.cpp lircevent.cpp lirc_client.c
}

using_libcec {
DEFINES += USING_LIBCEC
HEADERS += cecadapter.h
SOURCES += cecadapter.cpp
}

using_xrandr {
DEFINES += USING_XRANDR
HEADERS += DisplayResX.h
Expand Down
50 changes: 50 additions & 0 deletions mythtv/libs/libmythui/mythmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ using namespace std;
#include "jsmenuevent.h"
#endif

#ifdef USING_LIBCEC
#include "cecadapter.h"
#endif

#include "mythscreentype.h"
#include "mythpainter.h"
#ifdef USE_OPENGL_PAINTER
Expand Down Expand Up @@ -134,6 +138,11 @@ class MythMainWindowPrivate
appleRemoteListener(NULL),
appleRemote(NULL),
#endif

#ifdef USING_LIBCEC
cecAdapter(NULL),
#endif

exitingtomain(false),
popwindows(false),

Expand Down Expand Up @@ -202,6 +211,10 @@ class MythMainWindowPrivate
AppleRemote *appleRemote;
#endif

#ifdef USING_LIBCEC
CECAdapter* cecAdapter;
#endif

bool exitingtomain;
bool popwindows;

Expand Down Expand Up @@ -444,6 +457,15 @@ MythMainWindow::MythMainWindow(const bool useDB)
d->appleRemote->start();
#endif

#ifdef USING_LIBCEC
d->cecAdapter = new CECAdapter();
if (!d->cecAdapter->IsValid())
{
delete d->cecAdapter;
d->cecAdapter = NULL;
}
#endif

d->m_udpListener = new MythUDPListener();

InitKeys();
Expand Down Expand Up @@ -524,6 +546,11 @@ MythMainWindow::~MythMainWindow()
delete d->appleRemoteListener;
#endif

#ifdef USING_LIBCEC
if (d->cecAdapter)
delete d->cecAdapter;
#endif

delete d;
}

Expand Down Expand Up @@ -1102,6 +1129,11 @@ void MythMainWindow::InitKeys()
RegisterKey("Global", ACTION_8, QT_TRANSLATE_NOOP("MythControls","8"), "8");
RegisterKey("Global", ACTION_9, QT_TRANSLATE_NOOP("MythControls","9"), "9");

RegisterKey("Global", ACTION_TVPOWERON, QT_TRANSLATE_NOOP("MythControls",
"Turn the display on"), "");
RegisterKey("Global", ACTION_TVPOWEROFF, QT_TRANSLATE_NOOP("MythControls",
"Turn the display off"), "");

RegisterKey("Global", "SYSEVENT01", QT_TRANSLATE_NOOP("MythControls",
"Trigger System Key Event #1"), "");
RegisterKey("Global", "SYSEVENT02", QT_TRANSLATE_NOOP("MythControls",
Expand Down Expand Up @@ -1824,6 +1856,24 @@ bool MythMainWindow::HandleMedia(const QString &handler, const QString &mrl,
return false;
}

void MythMainWindow::HandleTVPower(bool poweron)
{
if (poweron)
{
#ifdef USING_LIBCEC
if (d->cecAdapter)
d->cecAdapter->Action(ACTION_TVPOWERON);
#endif
}
else
{
#ifdef USING_LIBCEC
if (d->cecAdapter)
d->cecAdapter->Action(ACTION_TVPOWEROFF);
#endif
}
}

void MythMainWindow::AllowInput(bool allow)
{
d->AllowInput = allow;
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythui/mythmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class MUI_PUBLIC MythMainWindow : public QWidget
const QString& subtitle="", const QString& director="",
int season=0, int episode=0, const QString& inetref="",
int lenMins=120, const QString& year="1895");
void HandleTVPower(bool poweron);

void JumpTo(const QString &destination, bool pop = true);
bool DestinationExists(const QString &destination) const;
Expand Down
6 changes: 4 additions & 2 deletions mythtv/libs/libmythui/mythscreentype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,11 @@ bool MythScreenType::keyPressEvent(QKeyEvent *event)
else if (action.startsWith("SYSEVENT"))
gCoreContext->SendSystemEvent(QString("KEY_%1").arg(action.mid(8)));
else if (action == ACTION_SCREENSHOT)
{
GetMythMainWindow()->ScreenShot();
}
else if (action == ACTION_TVPOWERON)
GetMythMainWindow()->HandleTVPower(true);
else if (action == ACTION_TVPOWEROFF)
GetMythMainWindow()->HandleTVPower(false);
else
handled = false;
}
Expand Down
3 changes: 3 additions & 0 deletions mythtv/libs/libmythui/mythuiactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@
#define ACTION_HANDLEMEDIA "HANDLEMEDIA"
#define ACTION_SCREENSHOT "SCREENSHOT"

#define ACTION_TVPOWEROFF "TVPOWEROFF"
#define ACTION_TVPOWERON "TVPOWERON"

#endif // MYTHUI_ACTIONS_H