MythTV  master
zmminiplayer.cpp
Go to the documentation of this file.
1 
2 #include "zmminiplayer.h"
3 
4 // mythtv
5 #include <mythcontext.h>
6 #include <lcddevice.h>
7 #include <mythuiimage.h>
8 #include <mythmainwindow.h>
9 
10 // mythzoneminder
11 #include "zmclient.h"
12 
13 #include <QTimer>
14 
15 // the maximum image size we are ever likely to get from ZM
16 #define MAX_IMAGE_SIZE (2048*1536*3)
17 
18 const int FRAME_UPDATE_TIME = 1000 / 10; // try to update the frame 10 times a second
19 
21  : ZMLivePlayer(parent, true),
22  m_displayTimer(new QTimer(this))
23 {
24  m_displayTimer->setSingleShot(true);
25  connect(m_displayTimer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
26 
27 }
28 
30 {
32 
33  // Timers are deleted by Qt
34  m_displayTimer->disconnect();
35  m_displayTimer = nullptr;
36 
37  if (LCD *lcd = LCD::Get())
38  lcd->switchToTime ();
39 }
40 
42 {
43  // if we was triggered because of an alarm wait for the monitor to become idle
44  if (m_alarmMonitor != -1)
45  {
47  if (mon && (mon->state == ALARM || mon->state == ALERT))
48  {
49  m_displayTimer->start(10000);
50  return;
51  }
52  }
53 
54  Close();
55 }
56 
58 {
59  if (!ZMLivePlayer::Create())
60  return false;
61 
62  m_displayTimer->start(10000);
63 
65 
66  return true;
67 }
68 
69 void ZMMiniPlayer::customEvent (QEvent* event)
70 {
71  if (event->type() == MythEvent::MythEventMessage)
72  {
73  MythEvent *me = static_cast<MythEvent*>(event);
74 
75  if (!me)
76  return;
77 
78  if (me->Message().startsWith("ZONEMINDER_NOTIFICATION"))
79  {
80  QStringList list = me->Message().simplified().split(' ');
81 
82  if (list.size() < 2)
83  return;
84 
85  int monID = list[1].toInt();
86  if (monID != m_alarmMonitor)
87  {
88  m_alarmMonitor = monID;
89 
90  m_frameTimer->stop();
91 
92  Monitor *mon = ZMClient::get()->getMonitorByID(monID);
93 
94  if (mon)
95  {
96  m_players->at(0)->setMonitor(mon);
97  m_players->at(0)->updateCamera();
98  }
99 
101  }
102 
103  // restart the display timer on any notification messages if it is active
104  if (m_displayTimer->isActive())
105  m_displayTimer->start(10000);
106  }
107  }
108 
109  // Parent MythUIType handler always returns false. (Shouldn't it
110  // call up?) Continue to call QObject as before.
111  QObject::customEvent(event);
112 }
113 
114 bool ZMMiniPlayer::keyPressEvent(QKeyEvent *event)
115 {
116  // restart the display timer on any keypress if it is active
117  if (m_displayTimer && m_displayTimer->isActive())
118  m_displayTimer->start();
119 
120  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
121  return true;
122 
123  QStringList actions;
124  bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions);
125 
126  for (int i = 0; i < actions.size() && !handled; i++)
127  {
128  QString action = actions[i];
129  handled = true;
130 
131  if (action == "SELECT")
132  {
133  if (m_displayTimer)
134  m_displayTimer->stop();
135  }
136  else if (action == "ESCAPE")
137  {
138  Close();
139  }
140  else if (action == "MENU")
141  {
142  }
143  else
144  handled = false;
145  }
146 
147  if (!handled && ZMLivePlayer::keyPressEvent(event))
148  handled = true;
149 
150  return handled;
151 }
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:91
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
bool keyPressEvent(QKeyEvent *) override
Key event handler.
static Type MythEventMessage
Definition: mythevent.h:66
void removeListener(QObject *listener)
Remove a listener to the observable.
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
void addListener(QObject *listener)
Add a listener to the observable.
Monitor * getMonitorByID(int monID)
Definition: zmclient.cpp:857
QTimer * m_displayTimer
Definition: zmminiplayer.h:28
static LCD * Get(void)
Definition: lcddevice.cpp:65
virtual void Close()
bool Create(void) override
This class is used as a container for messages.
Definition: mythevent.h:16
void customEvent(QEvent *event) override
State state
Definition: zmdefines.h:127
static ZMClient * get(void)
Definition: zmclient.cpp:38
int m_alarmMonitor
Definition: zmliveplayer.h:96
vector< Player * > * m_players
Definition: zmliveplayer.h:93
MythUIType * GetFocusWidget(void) const
MythMainWindow * GetMythMainWindow(void)
ZMMiniPlayer(MythScreenStack *parent)
const int FRAME_UPDATE_TIME
Definition: zmserver.h:66
Definition: lcddevice.h:165
void timerTimeout(void)
Definition: zmserver.h:67
bool keyPressEvent(QKeyEvent *) override
Key event handler.
const QString & Message() const
Definition: mythevent.h:58
QTimer * m_frameTimer
Definition: zmliveplayer.h:88
bool Create(void) override