Skip to content

Commit

Permalink
Add Warning and Check notification type
Browse files Browse the repository at this point in the history
Similar to an error one, but used to display a Warning or Check (OK) image instead
Add supports for them in UDP interface, service API and mythutil
  • Loading branch information
jyavenard committed Jul 20, 2013
1 parent e07a7e3 commit 0767ea0
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 47 deletions.
Expand Up @@ -23,6 +23,7 @@ class SERVICE_PUBLIC FrontendServices : public Service
uint Timeout) = 0;

virtual bool SendNotification(bool Error,
const QString &Type,
const QString &Message,
const QString &Origin,
const QString &Description,
Expand Down
Expand Up @@ -126,6 +126,7 @@ class SERVICE_PUBLIC MythServices : public Service //, public QScriptable ???
int Timeout ) = 0;

virtual bool SendNotification ( bool Error,
const QString &Type,
const QString &Message,
const QString &Origin,
const QString &Description,
Expand Down
24 changes: 24 additions & 0 deletions mythtv/libs/libmythui/mythnotification.cpp
Expand Up @@ -18,6 +18,10 @@ QEvent::Type MythNotification::Info =
(QEvent::Type) QEvent::registerEventType();
QEvent::Type MythNotification::Error =
(QEvent::Type) QEvent::registerEventType();
QEvent::Type MythNotification::Warning =
(QEvent::Type) QEvent::registerEventType();
QEvent::Type MythNotification::Check =
(QEvent::Type) QEvent::registerEventType();

void MythNotification::SetId(int id)
{
Expand Down Expand Up @@ -59,3 +63,23 @@ QString MythPlaybackNotification::stringFromSeconds(int time)
str += QString::number(seconds);
return str;
}

MythNotification::Type MythNotification::TypeFromString(const QString &type)
{
if (type == "error")
{
return MythNotification::Error;
}
else if (type == "warning")
{
return MythNotification::Warning;
}
else if (type == "check")
{
return MythNotification::Check;
}
else
{
return MythNotification::New;
}
}
49 changes: 39 additions & 10 deletions mythtv/libs/libmythui/mythnotification.h
Expand Up @@ -27,11 +27,12 @@ class MUI_PUBLIC MythNotification : public MythEvent
static Type Update;
static Type Info;
static Type Error;
static Type Warning;
static Type Check;

MythNotification(Type t, void *parent = NULL)
: MythEvent(t), m_id(-1), m_parent(parent), m_fullScreen(false),
m_duration(0), m_visibility(kAll), m_priority(kDefault)

{
}

Expand All @@ -54,6 +55,19 @@ class MUI_PUBLIC MythNotification : public MythEvent
m_metadata = map;
}

MythNotification(Type t, const QString &title, const QString &author,
const QString &details = QString())
: MythEvent(t), m_id(-1), m_parent(NULL), m_fullScreen(false),
m_description(title), m_duration(0), m_visibility(kAll),
m_priority(kDefault)
{
DMAP map;
map["minm"] = title;
map["asar"] = author;
map["asal"] = details;
m_metadata = map;
}

MythNotification(Type t, const DMAP &metadata)
: MythEvent(t), m_id(-1), m_parent(NULL), m_fullScreen(false),
m_duration(0), m_metadata(metadata),
Expand Down Expand Up @@ -151,6 +165,11 @@ class MUI_PUBLIC MythNotification : public MythEvent
*/
void SetPriority(Priority n) { m_priority = n; }

/**
* return Type object from type name
*/
static Type TypeFromString(const QString &type);

// Getter
int GetId(void) const { return m_id; }
void *GetParent(void) const { return m_parent; }
Expand Down Expand Up @@ -265,7 +284,7 @@ class MUI_PUBLIC MythPlaybackNotification : public virtual MythNotification
// Setter
/**
* current playback position to be displayed with the notification.
* Value to be between 0 <= x <= 1.
* Value to be between 0 <= x <= 1.
* Note: x < 0 means no progress bar to be displayed.
*/
void SetProgress(float progress) { m_progress = progress; }
Expand Down Expand Up @@ -338,24 +357,34 @@ class MUI_PUBLIC MythMediaNotification : public MythImageNotification,
MythMediaNotification &operator=(const MythMediaNotification&);
};

class MUI_PUBLIC MythErrorNotification : public MythImageNotification
class MUI_PUBLIC MythErrorNotification : public MythNotification
{
public:
MythErrorNotification(const QString &title, const QString &author,
const QString &details = QString())
: MythNotification(title, author, details), MythImageNotification(New, QImage())
: MythNotification(Error, title, author, details)
{
SetDuration(10);
}
};

virtual MythEvent *clone(void) const { return new MythErrorNotification(*this); }

protected:
MythErrorNotification(const MythErrorNotification &o)
: MythNotification(o), MythImageNotification(o)
class MUI_PUBLIC MythWarningNotification : public MythNotification
{
public:
MythWarningNotification(const QString &title, const QString &author,
const QString &details = QString())
: MythNotification(Warning, title, author, details)
{
SetDuration(10);
}
};

MythErrorNotification &operator=(const MythErrorNotification&);
class MUI_PUBLIC MythCheckNotification : public MythNotification
{
public:
MythCheckNotification(const QString &title, const QString &author,
const QString &details = QString())
: MythNotification(Check, title, author, details) { }
};

#endif /* defined(__MythTV__mythnotification__) */
8 changes: 6 additions & 2 deletions mythtv/libs/libmythui/mythudplistener.cpp
Expand Up @@ -114,6 +114,7 @@ void MythUDPListener::Process(const QByteArray &buf, QHostAddress sender,
bool fullscreen = false;
bool error = false;
int visibility = 0;
QString type = "normal";

QDomNode n = docElem.firstChild();
while (!n.isNull())
Expand Down Expand Up @@ -141,6 +142,8 @@ void MythUDPListener::Process(const QByteArray &buf, QHostAddress sender,
error = e.text().toLower() == "true";
else if (e.tagName() == "visibility")
visibility = e.text().toUInt();
else if (e.tagName() == "type")
type = e.text();
else if (notification && e.tagName() == "progress")
{
bool ok;
Expand All @@ -152,7 +155,6 @@ void MythUDPListener::Process(const QByteArray &buf, QHostAddress sender,
{
LOG(VB_GENERAL, LOG_ERR, LOC + QString("Unknown element: %1")
.arg(e.tagName()));
return;
}
}
n = n.nextSibling();
Expand All @@ -167,7 +169,9 @@ void MythUDPListener::Process(const QByteArray &buf, QHostAddress sender,
if (notification)
{
origin = origin.isNull() ? tr("UDP Listener") : origin;
ShowNotification(error, msg, origin, description, image, extra,
ShowNotification(error ? MythNotification::Error :
MythNotification::TypeFromString(type),
msg, origin, description, image, extra,
progress_text, progress, timeout, fullscreen,
visibility);
}
Expand Down

0 comments on commit 0767ea0

Please sign in to comment.