Skip to content

Commit

Permalink
Add a new MythUDPListener class to libmythui.
Browse files Browse the repository at this point in the history
To test:- mythtvosd --template=alert --alert_text='Hello world!'

This replaces the old udpnotify class in libmythtv and the new object is
owned by MythMainWindow. The UDP port setting is reinstated and moved
from the Playback screen to the General settings pages.

I've retained the XML functionality to ensure we don't pick up stray UDP
broadcast messages and to make the most of the eXtensibility once we've
settled on a general framework and UI for messaging (e.g. to add timeout
settings).

For the time being, mythtvosd will work as above but I will replace it
with a new command line utility (mythmessage?) with the template
handling removed.
  • Loading branch information
Mark Kendall committed Dec 23, 2010
1 parent 200d3bf commit 7b4f59a
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 18 deletions.
4 changes: 2 additions & 2 deletions mythtv/libs/libmythui/libmythui.pro
Expand Up @@ -29,7 +29,7 @@ HEADERS += themeinfo.h mythxdisplay.h DisplayRes.h DisplayResScreen.h
HEADERS += mythgenerictree.h mythuibuttontree.h mythuiutils.h
HEADERS += mythvirtualkeyboard.h mythuishape.h mythuiguidegrid.h
HEADERS += mythrender_base.h mythfontmanager.h mythuieditbar.h
HEADERS += mythdisplay.h mythuivideo.h
HEADERS += mythdisplay.h mythuivideo.h mythudplistener.h

SOURCES = mythmainwindow.cpp mythpainter.cpp mythimage.cpp mythrect.cpp
SOURCES += myththemebase.cpp mythpainter_qimage.cpp mythpainter_yuva.cpp
Expand All @@ -46,7 +46,7 @@ SOURCES += themeinfo.cpp mythxdisplay.cpp DisplayRes.cpp DisplayResScreen.cpp
SOURCES += mythgenerictree.cpp mythuibuttontree.cpp mythuiutils.cpp
SOURCES += mythvirtualkeyboard.cpp mythuishape.cpp mythuiguidegrid.cpp
SOURCES += mythfontmanager.cpp mythuieditbar.cpp
SOURCES += mythdisplay.cpp mythuivideo.cpp
SOURCES += mythdisplay.cpp mythuivideo.cpp mythudplistener.cpp


inc.path = $${PREFIX}/include/mythtv/libmythui/
Expand Down
4 changes: 4 additions & 0 deletions mythtv/libs/libmythui/mythmainwindow.cpp
Expand Up @@ -50,6 +50,7 @@ using namespace std;
#include "screensaver.h"
#include "lirc.h"
#include "lircevent.h"
#include "mythudplistener.h"

#ifdef USING_APPLEREMOTE
#include "AppleRemoteListener.h"
Expand Down Expand Up @@ -254,6 +255,7 @@ class MythMainWindowPrivate
bool m_drawEnabled;

MythThemeBase *m_themeBase;
MythUDPListener *m_udpListener;
};

// Make keynum in QKeyEvent be equivalent to what's in QKeySequence
Expand Down Expand Up @@ -457,6 +459,8 @@ MythMainWindow::MythMainWindow(const bool useDB)
d->appleRemote->start();
#endif

d->m_udpListener = new MythUDPListener();

InitKeys();

d->gestureTimer = new QTimer(this);
Expand Down
123 changes: 123 additions & 0 deletions mythtv/libs/libmythui/mythudplistener.cpp
@@ -0,0 +1,123 @@
#include <QCoreApplication>
#include <QUdpSocket>
#include <QDomDocument>

#include "mythcorecontext.h"
#include "mythverbose.h"
#include "mythmainwindow.h"
#include "mythudplistener.h"

#define LOC QString("UDPListener: ")
#define ERR QString("UPDListener Error: ")

MythUDPListener::MythUDPListener()
{
uint udp_port = gCoreContext->GetNumSetting("UDPNotifyPort", 0);
m_socket = new QUdpSocket(this);
connect(m_socket, SIGNAL(readyRead()),
this, SLOT(ReadPending()));
if (m_socket->bind(udp_port))
{
VERBOSE(VB_GENERAL, LOC + QString("bound to port %1").arg(udp_port));
}
else
{
VERBOSE(VB_GENERAL, LOC +
QString("failed to bind to port %1").arg(udp_port));
}
}

void MythUDPListener::deleteLater(void)
{
TeardownAll();
disconnect();
QObject::deleteLater();
}

void MythUDPListener::TeardownAll(void)
{
if (!m_socket)
return;

VERBOSE(VB_GENERAL, LOC + "Disconnecting");

m_socket->disconnect();
m_socket->close();
m_socket->deleteLater();
m_socket = NULL;
}

void MythUDPListener::ReadPending(void)
{
QByteArray buf;
while (m_socket->hasPendingDatagrams())
{
buf.resize(m_socket->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;

m_socket->readDatagram(buf.data(), buf.size(),
&sender, &senderPort);

Process(buf);
}
}

void MythUDPListener::Process(const QByteArray &buf)
{
QString errorMsg;
int errorLine = 0;
int errorColumn = 0;
QDomDocument doc;
if (!doc.setContent(buf, false, &errorMsg, &errorLine, &errorColumn))
{
VERBOSE(VB_IMPORTANT, ERR +
QString("Parsing xml:\n\t\t\t at line: %1 column: %2\n\t\t\t%3")
.arg(errorLine).arg(errorColumn).arg(errorMsg));

return;
}

QDomElement docElem = doc.documentElement();
if (!docElem.isNull())
{
if (docElem.tagName() != "mythnotify")
{
VERBOSE(VB_IMPORTANT, ERR +
"Unknown UDP packet (not <mythnotify> XML)");
return;
}

QString version = docElem.attribute("version", "");
if (version.isEmpty())
{
VERBOSE(VB_IMPORTANT, ERR +
"<mythnotify> missing 'version' attribute");
return;
}
}

QDomNode n = docElem.firstChild();
while (!n.isNull())
{
QDomElement e = n.toElement();
if (!e.isNull())
{
if (e.tagName() == "container")
{
QString msg = e.text();
VERBOSE(VB_GENERAL, LOC + msg);
MythMainWindow *window = GetMythMainWindow();
MythEvent* me = new MythEvent(MythEvent::MythUserMessage, msg);
qApp->postEvent(window, me);
}
else
{
VERBOSE(VB_IMPORTANT, ERR + QString("Unknown element: %1")
.arg(e.tagName()));
return;
}
}
n = n.nextSibling();
}
}
33 changes: 33 additions & 0 deletions mythtv/libs/libmythui/mythudplistener.h
@@ -0,0 +1,33 @@
#ifndef MYTHUDPLISTENER_H
#define MYTHUDPLISTENER_H

#include <QObject>

class QByteArray;
class QUdpSocket;
class QDomElement;

class MythUDPListener : public QObject
{
Q_OBJECT

public:
MythUDPListener();

public slots:
virtual void deleteLater(void);

private slots:
void ReadPending(void);

private:
~MythUDPListener(void) { TeardownAll(); }

void Process(const QByteArray &buf);
void TeardownAll(void);

private:
QUdpSocket *m_socket;
};

#endif // MYTHUDPLISTENER_H
29 changes: 13 additions & 16 deletions mythtv/programs/mythfrontend/globalsettings.cpp
Expand Up @@ -1525,21 +1525,6 @@ static HostCheckBox *AltClearSavedPosition()
return gc;
}

// This currently does not work
/*
static HostLineEdit *UDPNotifyPort()
{
HostLineEdit *ge = new HostLineEdit("UDPNotifyPort");
ge->setLabel(QObject::tr("UDP notify port"));
ge->setValue("6948");
ge->setHelpText(QObject::tr("During playback, MythTV will listen for "
"connections from the \"mythtvosd\" or \"mythudprelay\" "
"programs on this port. For additional information, see "
"http://www.mythtv.org/wiki/MythNotify ."));
return ge;
}
*/

static HostComboBox *PlaybackExitPrompt()
{
HostComboBox *gc = new HostComboBox("PlaybackExitPrompt");
Expand Down Expand Up @@ -2730,6 +2715,18 @@ static HostSpinBox *NetworkControlPort()
return gs;
}

static HostLineEdit *UDPNotifyPort()
{
HostLineEdit *ge = new HostLineEdit("UDPNotifyPort");
ge->setLabel(QObject::tr("UDP notify port"));
ge->setValue("6948");
ge->setHelpText(QObject::tr("MythTV will listen for "
"connections from the \"mythtvosd\" or \"mythudprelay\" "
"programs on this port. For additional information, see "
"http://www.mythtv.org/wiki/MythNotify ."));
return ge;
}

static HostCheckBox *RealtimePriority()
{
HostCheckBox *gc = new HostCheckBox("RealtimePriority");
Expand Down Expand Up @@ -3380,6 +3377,7 @@ MainGeneralSettings::MainGeneralSettings()
remotecontrol->addChild(LircDaemonDevice());
remotecontrol->addChild(NetworkControlEnabled());
remotecontrol->addChild(NetworkControlPort());
remotecontrol->addChild(UDPNotifyPort());
addChild(remotecontrol);
}

Expand Down Expand Up @@ -3540,7 +3538,6 @@ OSDSettings::OSDSettings()
osd->addChild(SubtitleFont());
osd->addChild(OSDCC708TextZoomPercentage());
osd->addChild(SubtitleCodec());
//osd->addChild(UDPNotifyPort());
addChild(osd);

//VerticalConfigurationGroup *cc = new VerticalConfigurationGroup(false);
Expand Down

0 comments on commit 7b4f59a

Please sign in to comment.