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 using namespace std::chrono_literals;
20 
21 // the maximum image size we are ever likely to get from ZM
22 #define MAX_IMAGE_SIZE (2048*1536*3)
23 
24 const int FRAME_UPDATE_TIME = 1000 / 10; // try to update the frame 10 times a second
25 
27  : ZMLivePlayer(parent, true),
28  m_displayTimer(new QTimer(this))
29 {
30  m_displayTimer->setSingleShot(true);
32 
33 }
34 
36 {
38 
39  // Timers are deleted by Qt
40  m_displayTimer->disconnect();
41  m_displayTimer = nullptr;
42 
43  if (LCD *lcd = LCD::Get())
44  lcd->switchToTime ();
45 }
46 
48 {
49  // if we was triggered because of an alarm wait for the monitor to become idle
50  if (m_alarmMonitor != -1)
51  {
53  if (mon && (mon->state == ALARM || mon->state == ALERT))
54  {
55  m_displayTimer->start(10s);
56  return;
57  }
58  }
59 
60  Close();
61 }
62 
64 {
65  if (!ZMLivePlayer::Create())
66  return false;
67 
68  m_displayTimer->start(10s);
69 
71 
72  return true;
73 }
74 
75 void ZMMiniPlayer::customEvent (QEvent* event)
76 {
77  if (event->type() == MythEvent::MythEventMessage)
78  {
79  auto *me = dynamic_cast<MythEvent*>(event);
80  if (!me)
81  return;
82 
83  if (me->Message().startsWith("ZONEMINDER_NOTIFICATION"))
84  {
85  QStringList list = me->Message().simplified().split(' ');
86 
87  if (list.size() < 2)
88  return;
89 
90  int monID = list[1].toInt();
91  if (monID != m_alarmMonitor)
92  {
93  m_alarmMonitor = monID;
94 
95  m_frameTimer->stop();
96 
97  Monitor *mon = ZMClient::get()->getMonitorByID(monID);
98 
99  if (mon)
100  {
101  m_players->at(0)->setMonitor(mon);
102  m_players->at(0)->updateCamera();
103  }
104 
106  }
107 
108  // restart the display timer on any notification messages if it is active
109  if (m_displayTimer->isActive())
110  m_displayTimer->start(10s);
111  }
112  }
113 
115 }
116 
117 bool ZMMiniPlayer::keyPressEvent(QKeyEvent *event)
118 {
119  // restart the display timer on any keypress if it is active
120  if (m_displayTimer && m_displayTimer->isActive())
121  m_displayTimer->start();
122 
123  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
124  return true;
125 
126  QStringList actions;
127  bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions);
128 
129  for (int i = 0; i < actions.size() && !handled; i++)
130  {
131  QString action = actions[i];
132  handled = true;
133 
134  if (action == "SELECT")
135  {
136  if (m_displayTimer)
137  m_displayTimer->stop();
138  }
139  else if (action == "ESCAPE")
140  {
141  Close();
142  }
143  else if (action == "MENU")
144  {
145  }
146  else
147  handled = false;
148  }
149 
150  if (!handled && ZMLivePlayer::keyPressEvent(event))
151  handled = true;
152 
153  return handled;
154 }
ZMMiniPlayer::timerTimeout
void timerTimeout(void)
Definition: zmminiplayer.cpp:47
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
MythMainWindow::TranslateKeyPress
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
Definition: mythmainwindow.cpp:1142
MythEvent
This class is used as a container for messages.
Definition: mythevent.h:17
MythScreenStack
Definition: mythscreenstack.h:16
ZMMiniPlayer::Create
bool Create(void) override
Definition: zmminiplayer.cpp:63
ZMClient::getMonitorByID
Monitor * getMonitorByID(int monID)
Definition: zmclient.cpp:855
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:67
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
FRAME_UPDATE_TIME
const int FRAME_UPDATE_TIME
Definition: zmminiplayer.cpp:24
ZMMiniPlayer::customEvent
void customEvent(QEvent *event) override
Definition: zmminiplayer.cpp:75
ALERT
@ ALERT
Definition: zmserver.h:69
ZMLivePlayer
Definition: zmliveplayer.h:61
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:35
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:26
ZMMiniPlayer::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: zmminiplayer.cpp:117
ZMLivePlayer::m_players
std::vector< Player * > * m_players
Definition: zmliveplayer.h:92
mythcontext.h
ALARM
@ ALARM
Definition: zmserver.h:68
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:108
build_compdb.action
action
Definition: build_compdb.py:9
ZMLivePlayer::customEvent
void customEvent(QEvent *event) override
Definition: zmliveplayer.cpp:273
Monitor
Definition: zmdefines.h:100
lcddevice.h
mythmainwindow.h
MythObservable::removeListener
void removeListener(QObject *listener)
Remove a listener to the observable.
Definition: mythobservable.cpp:55
LCD
Definition: lcddevice.h:170