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  auto *me = dynamic_cast<MythEvent*>(event);
74  if (!me)
75  return;
76 
77  if (me->Message().startsWith("ZONEMINDER_NOTIFICATION"))
78  {
79  QStringList list = me->Message().simplified().split(' ');
80 
81  if (list.size() < 2)
82  return;
83 
84  int monID = list[1].toInt();
85  if (monID != m_alarmMonitor)
86  {
87  m_alarmMonitor = monID;
88 
89  m_frameTimer->stop();
90 
91  Monitor *mon = ZMClient::get()->getMonitorByID(monID);
92 
93  if (mon)
94  {
95  m_players->at(0)->setMonitor(mon);
96  m_players->at(0)->updateCamera();
97  }
98 
100  }
101 
102  // restart the display timer on any notification messages if it is active
103  if (m_displayTimer->isActive())
104  m_displayTimer->start(10000);
105  }
106  }
107 
109 }
110 
111 bool ZMMiniPlayer::keyPressEvent(QKeyEvent *event)
112 {
113  // restart the display timer on any keypress if it is active
114  if (m_displayTimer && m_displayTimer->isActive())
115  m_displayTimer->start();
116 
117  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
118  return true;
119 
120  QStringList actions;
121  bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions);
122 
123  for (int i = 0; i < actions.size() && !handled; i++)
124  {
125  QString action = actions[i];
126  handled = true;
127 
128  if (action == "SELECT")
129  {
130  if (m_displayTimer)
131  m_displayTimer->stop();
132  }
133  else if (action == "ESCAPE")
134  {
135  Close();
136  }
137  else if (action == "MENU")
138  {
139  }
140  else
141  handled = false;
142  }
143 
144  if (!handled && ZMLivePlayer::keyPressEvent(event))
145  handled = true;
146 
147  return handled;
148 }
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.
void customEvent(QEvent *event) override
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:855
QTimer * m_displayTimer
Definition: zmminiplayer.h:28
static LCD * Get(void)
Definition: lcddevice.cpp:65
virtual void Close()
bool Create(void) override
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.
QTimer * m_frameTimer
Definition: zmliveplayer.h:88
bool Create(void) override