Skip to content

Commit

Permalink
Add support to send user notification via the UDP listener interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jyavenard committed Jul 2, 2013
1 parent 98c828b commit 5316e59
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions mythtv/libs/libmythui/mythudplistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "mythlogging.h"
#include "mythmainwindow.h"
#include "mythudplistener.h"
#include "mythuinotificationcenter.h"

#define LOC QString("UDPListener: ")

Expand Down Expand Up @@ -77,15 +78,22 @@ void MythUDPListener::Process(const QByteArray &buf, QHostAddress sender,
}

QDomElement docElem = doc.documentElement();
bool notification = false;
if (!docElem.isNull())
{
if (docElem.tagName() != "mythmessage")
if (docElem.tagName() != "mythmessage" &&
docElem.tagName() != "mythnotification")
{
LOG(VB_GENERAL, LOG_ERR, LOC +
"Unknown UDP packet (not <mythmessage> XML)");
return;
}

if (docElem.tagName() == "mythnotification")
{
notification = true;
}

QString version = docElem.attribute("version", "");
if (version.isEmpty())
{
Expand Down Expand Up @@ -120,14 +128,23 @@ void MythUDPListener::Process(const QByteArray &buf, QHostAddress sender,

if (!msg.isEmpty())
{
LOG(VB_GENERAL, LOG_INFO, QString("Received %1 '%2', timeout %3")
.arg(notification ? "notification" : "message").arg(msg).arg(timeout));
if (timeout > 1000)
timeout = 0;
LOG(VB_GENERAL, LOG_INFO, QString("Received message '%1', timeout %2")
.arg(msg).arg(timeout));
QStringList args;
args << QString::number(timeout);
MythMainWindow *window = GetMythMainWindow();
MythEvent* me = new MythEvent(MythEvent::MythUserMessage, msg, args);
qApp->postEvent(window, me);
timeout = notification ? 5 : 0;
if (notification)
{
MythNotification n(msg, tr("UDP Listener"));
n.SetDuration(timeout);
MythUINotificationCenter::GetInstance()->Queue(n);
}
else
{
QStringList args;
args << QString::number(timeout);
MythMainWindow *window = GetMythMainWindow();
MythEvent* me = new MythEvent(MythEvent::MythUserMessage, msg, args);
qApp->postEvent(window, me);
}
}
}

0 comments on commit 5316e59

Please sign in to comment.