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