MythTV  master
miniplayer.cpp
Go to the documentation of this file.
1 
2 #include "miniplayer.h"
3 
4 #include <chrono>
5 
6 // mythtv
7 #include <mythcontext.h>
8 #include <mythmainwindow.h>
9 #include <lcddevice.h>
10 
11 // mythmusic
12 #include "musicplayer.h"
13 #include "decoder.h"
14 
15 #include <QTimer>
16 
17 using namespace std::chrono_literals;
18 
19 
21  : MusicCommon(parent, nullptr, "music_miniplayer")
22 {
24  m_displayTimer = new QTimer(this);
25  m_displayTimer->setSingleShot(true);
27 }
28 
30 {
31  gPlayer->removeListener(this);
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  Close();
44 }
45 
47 {
48  // Load the theme for this screen
49  bool err = LoadWindowFromXML("music-ui.xml", "miniplayer", this);
50 
51  if (!err)
52  return false;
53 
54  // find common widgets available on any view
55  err = CreateCommon();
56 
57  if (err)
58  {
59  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'miniplayer'");
60  return false;
61  }
62 
63  m_displayTimer->start(10s);
64 
66 
67  return true;
68 }
69 
70 bool MiniPlayer::keyPressEvent(QKeyEvent *event)
71 {
72  // restart the display timer on any keypress if it is active
73  if (m_displayTimer && m_displayTimer->isActive())
74  m_displayTimer->start();
75 
76  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
77  return true;
78 
79  QStringList actions;
80  bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions);
81 
82  for (int i = 0; i < actions.size() && !handled; i++)
83  {
84  QString action = actions[i];
85  handled = true;
86 
87  if (action == "SELECT")
88  {
89  if (m_displayTimer)
90  m_displayTimer->stop();
91  }
92  else if (action == "ESCAPE")
93  {
94  Close();
95  }
96  else if (action == "MENU")
97  {
99  //showAutoMode();
100  }
101  else
102  handled = false;
103  }
104 
105  if (!handled && MusicCommon::keyPressEvent(event))
106  handled = true;
107 
108  return handled;
109 }
MusicCommon::m_currentView
MusicView m_currentView
Definition: musiccommon.h:139
gPlayer
MusicPlayer * gPlayer
Definition: musicplayer.cpp:35
MV_MINIPLAYER
@ MV_MINIPLAYER
Definition: musiccommon.h:42
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
MiniPlayer::MiniPlayer
MiniPlayer(MythScreenStack *parent)
Definition: miniplayer.cpp:20
MusicPlayer::getAutoShowPlayer
bool getAutoShowPlayer(void) const
Definition: musicplayer.h:109
MusicCommon::CreateCommon
bool CreateCommon(void)
Definition: musiccommon.cpp:80
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:402
MusicCommon::keyPressEvent
bool keyPressEvent(QKeyEvent *e) override
Key event handler.
Definition: musiccommon.cpp:580
MiniPlayer::timerTimeout
void timerTimeout(void)
Definition: miniplayer.cpp:41
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
MiniPlayer::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: miniplayer.cpp:70
MythScreenStack
Definition: mythscreenstack.h:16
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MusicPlayer::removeListener
void removeListener(QObject *listener)
Definition: musicplayer.cpp:159
LCD::Get
static LCD * Get(void)
Definition: lcddevice.cpp:67
MythScreenType::GetFocusWidget
MythUIType * GetFocusWidget(void) const
Definition: mythscreentype.cpp:112
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:222
MiniPlayer::Create
bool Create(void) override
Definition: miniplayer.cpp:46
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:692
MiniPlayer::~MiniPlayer
~MiniPlayer() override
Definition: miniplayer.cpp:29
mythcontext.h
miniplayer.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:108
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:108
lcddevice.h
mythmainwindow.h
LCD
Definition: lcddevice.h:170
MusicCommon
Definition: musiccommon.h:48
decoder.h
MiniPlayer::m_displayTimer
QTimer * m_displayTimer
Definition: miniplayer.h:25
musicplayer.h