MythTV  master
miniplayer.cpp
Go to the documentation of this file.
1 
2 // C++
3 #include <chrono>
4 
5 // Qt
6 #include <QTimer>
7 
8 // MythTV
9 #include <libmyth/mythcontext.h>
10 #include <libmythbase/lcddevice.h>
12 
13 // mythmusic
14 #include "decoder.h"
15 #include "miniplayer.h"
16 #include "musicplayer.h"
17 
18 
20  : MusicCommon(parent, nullptr, "music_miniplayer")
21 {
23  m_displayTimer = new QTimer(this);
24  m_displayTimer->setSingleShot(true);
26 }
27 
29 {
30  gPlayer->removeListener(this);
31 
32  // Timers are deleted by Qt
33  m_displayTimer->disconnect();
34  m_displayTimer = nullptr;
35 
36  if (LCD *lcd = LCD::Get())
37  lcd->switchToTime ();
38 }
39 
41 {
42  Close();
43 }
44 
46 {
47  // Load the theme for this screen
48  bool err = LoadWindowFromXML("music-ui.xml", "miniplayer", this);
49 
50  if (!err)
51  return false;
52 
53  // find common widgets available on any view
54  err = CreateCommon();
55 
56  if (err)
57  {
58  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'miniplayer'");
59  return false;
60  }
61 
62  m_displayTimer->start(10s);
63 
65 
66  return true;
67 }
68 
69 bool MiniPlayer::keyPressEvent(QKeyEvent *event)
70 {
71  // restart the display timer on any keypress if it is active
72  if (m_displayTimer && m_displayTimer->isActive())
73  m_displayTimer->start();
74 
75  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
76  return true;
77 
78  QStringList actions;
79  bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions);
80 
81  for (int i = 0; i < actions.size() && !handled; i++)
82  {
83  QString action = actions[i];
84  handled = true;
85 
86  if (action == "SELECT")
87  {
88  if (m_displayTimer)
89  m_displayTimer->stop();
90  }
91  else if (action == "ESCAPE")
92  {
93  Close();
94  }
95  else if (action == "MENU")
96  {
98  //showAutoMode();
99  }
100  else
101  handled = false;
102  }
103 
104  if (!handled && MusicCommon::keyPressEvent(event))
105  handled = true;
106 
107  return handled;
108 }
MusicCommon::m_currentView
MusicView m_currentView
Definition: musiccommon.h:141
gPlayer
MusicPlayer * gPlayer
Definition: musicplayer.cpp:37
MV_MINIPLAYER
@ MV_MINIPLAYER
Definition: musiccommon.h:43
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:102
MiniPlayer::MiniPlayer
MiniPlayer(MythScreenStack *parent)
Definition: miniplayer.cpp:19
MusicPlayer::getAutoShowPlayer
bool getAutoShowPlayer(void) const
Definition: musicplayer.h:116
MusicCommon::CreateCommon
bool CreateCommon(void)
Definition: musiccommon.cpp:76
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:386
MusicCommon::keyPressEvent
bool keyPressEvent(QKeyEvent *e) override
Key event handler.
Definition: musiccommon.cpp:573
MiniPlayer::timerTimeout
void timerTimeout(void)
Definition: miniplayer.cpp:40
MiniPlayer::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: miniplayer.cpp:69
MythScreenStack
Definition: mythscreenstack.h:16
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MusicPlayer::removeListener
void removeListener(QObject *listener)
Definition: musicplayer.cpp:161
LCD::Get
static LCD * Get(void)
Definition: lcddevice.cpp:69
MythScreenType::GetFocusWidget
MythUIType * GetFocusWidget(void) const
Definition: mythscreentype.cpp:113
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:1112
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:206
MiniPlayer::Create
bool Create(void) override
Definition: miniplayer.cpp:45
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:687
MiniPlayer::~MiniPlayer
~MiniPlayer() override
Definition: miniplayer.cpp:28
mythcontext.h
miniplayer.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
build_compdb.action
action
Definition: build_compdb.py:9
MusicPlayer::autoShowPlayer
void autoShowPlayer(bool autoShow)
This will allow/disallow the mini player showing on track changes.
Definition: musicplayer.h:115
lcddevice.h
mythmainwindow.h
LCD
Definition: lcddevice.h:169
MusicCommon
Definition: musiccommon.h:49
decoder.h
MiniPlayer::m_displayTimer
QTimer * m_displayTimer
Definition: miniplayer.h:27
musicplayer.h