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 }
ZMMiniPlayer::timerTimeout
void timerTimeout(void)
Definition: zmminiplayer.cpp:41
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
ZMLivePlayer::m_players
vector< Player * > * m_players
Definition: zmliveplayer.h:93
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:1106
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:57
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:96
LCD::Get
static LCD * Get(void)
Definition: lcddevice.cpp:64
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:18
ZMMiniPlayer::customEvent
void customEvent(QEvent *event) override
Definition: zmminiplayer.cpp:69
ALERT
@ ALERT
Definition: zmserver.h:67
ZMLivePlayer
Definition: zmliveplayer.h:62
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:57
zmminiplayer.h
ZMLivePlayer::m_frameTimer
QTimer * m_frameTimer
Definition: zmliveplayer.h:88
ZMMiniPlayer::~ZMMiniPlayer
~ZMMiniPlayer() override
Definition: zmminiplayer.cpp:29
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:20
ZMMiniPlayer::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: zmminiplayer.cpp:111
mythcontext.h
ALARM
@ ALARM
Definition: zmserver.h:66
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:107
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