MythTV  master
mythflashplayer.cpp
Go to the documentation of this file.
1 #include <cstdlib>
2 #include <iostream>
3 
4 // qt
5 #include <QApplication>
6 #include <QEvent>
7 
8 // MythTV
9 #include <libmyth/mythcontext.h>
11 #include <libmythtv/playgroup.h>
13 #include <libmythui/mythuihelper.h>
15 
16 // mythbrowser
17 #include "mythflashplayer.h"
18 #include "webpage.h"
19 
21  QStringList &urlList)
22  : MythScreenType (parent, "mythflashplayer"),
23  m_url(urlList[0])
24 {
25  m_fftime = PlayGroup::GetSetting("Default", "skipahead", 30);
26  m_rewtime = PlayGroup::GetSetting("Default", "skipback", 5);
27  m_jumptime = PlayGroup::GetSetting("Default", "jump", 10);
28  QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
31 }
32 
33 
35 {
36  QGuiApplication::restoreOverrideCursor();
37 
38  if (m_browser)
39  {
40  m_browser->disconnect();
42  m_browser = nullptr;
43  }
46 }
47 
49 {
50  if (!m_browser)
51  m_browser = new MythUIWebBrowser(this, "mythflashplayer");
52  m_browser->SetArea(MythRect(GetMythMainWindow()->GetUIScreenRect()));
53  m_browser->Init();
54  m_browser->SetActive(true);
55  m_browser->Show();
56 
58 
60 
61  m_url.replace("mythflash://", "http://");
62  LOG(VB_GENERAL, LOG_INFO, QString("Opening %1").arg(m_url));
63  m_browser->LoadPage(QUrl::fromEncoded(m_url.toLocal8Bit()));
64 
65  return true;
66 }
67 
68 QVariant MythFlashPlayer::evaluateJavaScript(const QString& source)
69 {
70  return (m_browser ? m_browser->evaluateJavaScript(source) : QVariant());
71 }
72 
73 bool MythFlashPlayer::keyPressEvent(QKeyEvent *event)
74 {
75  QStringList actions;
76  bool handled = GetMythMainWindow()->TranslateKeyPress("TV Playback", event, actions);
77 
78  for (int i = 0; i < actions.size() && !handled; i++)
79  {
80  QString action = actions[i];
81  handled = true;
82 
83  if (action == "PAUSE")
84  evaluateJavaScript("play();");
85  else if (action == "INFO")
86  evaluateJavaScript("info();");
87  else if (action == "SEEKFFWD")
88  evaluateJavaScript(QString("seek(%1);").arg(m_fftime));
89  else if (action == "SEEKRWND")
90  evaluateJavaScript(QString("seek(-%1);").arg(m_rewtime));
91  else if (action == "CHANNELUP")
92  evaluateJavaScript(QString("seek(%1);").arg(m_jumptime * 60));
93  else if (action == "CHANNELDOWN")
94  evaluateJavaScript(QString("seek(-%1);").arg(m_jumptime * 60));
95  else if (action == "VOLUMEUP")
96  evaluateJavaScript("adjustVolume(2);");
97  else if (action == "VOLUMEDOWN")
98  evaluateJavaScript("adjustVolume(-2);");
99  else
100  handled = false;
101 
102  if (handled)
103  return true;
104  }
105 
106  if (m_browser)
107  handled = m_browser->keyPressEvent(event);
108 
109  if (!handled && MythScreenType::keyPressEvent(event))
110  handled = true;
111 
112  return handled;
113 }
MythUIWebBrowser::SetActive
void SetActive(bool active)
Toggles the active state of the widget.
Definition: mythuiwebbrowser.cpp:1113
PlayGroup::GetSetting
static int GetSetting(const QString &name, const QString &field, int defval)
Definition: playgroup.cpp:248
MythUIType::DeleteChild
void DeleteChild(const QString &name)
Delete a named child of this UIType.
Definition: mythuitype.cpp:150
MythFlashPlayer::MythFlashPlayer
MythFlashPlayer(MythScreenStack *parent, QStringList &urlList)
Definition: mythflashplayer.cpp:20
MythScreenStack
Definition: mythscreenstack.h:16
MythMainWindow::RestoreScreensaver
static void RestoreScreensaver()
Definition: mythmainwindow.cpp:577
MythUIType::SetArea
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:611
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
playgroup.h
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
MythFlashPlayer::evaluateJavaScript
QVariant evaluateJavaScript(const QString &source)
Definition: mythflashplayer.cpp:68
MythRect
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:17
MythMainWindow::DisableScreensaver
static void DisableScreensaver()
Definition: mythmainwindow.cpp:583
MythFlashPlayer::m_url
QString m_url
Definition: mythflashplayer.h:22
MythUIWebBrowser::LoadPage
void LoadPage(const QUrl &url)
Loads the specified url and displays it.
Definition: mythuiwebbrowser.cpp:1042
MythFlashPlayer::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythflashplayer.cpp:73
MythUIWebBrowser::evaluateJavaScript
QVariant evaluateJavaScript(const QString &scriptSource)
Evaluates the JavaScript code in scriptSource.
Definition: mythuiwebbrowser.cpp:1304
MythUIType::Show
void Show(void)
Definition: mythuitype.cpp:1149
mythlogging.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:1112
MythScreenType::SetFocusWidget
bool SetFocusWidget(MythUIType *widget=nullptr)
Definition: mythscreentype.cpp:118
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:206
MythFlashPlayer::m_fftime
int m_fftime
Definition: mythflashplayer.h:23
MythUIWebBrowser::Init
void Init(void)
Initializes the widget ready for use.
Definition: mythuiwebbrowser.cpp:856
mythflashplayer.h
webpage.h
mythuihelper.h
MythFlashPlayer::Create
bool Create(void) override
Definition: mythflashplayer.cpp:48
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:404
mythcontext.h
MythFlashPlayer::m_browser
MythUIWebBrowser * m_browser
Definition: mythflashplayer.h:21
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
build_compdb.action
action
Definition: build_compdb.py:9
MythFlashPlayer::m_jumptime
int m_jumptime
Definition: mythflashplayer.h:25
MythFlashPlayer::m_rewtime
int m_rewtime
Definition: mythflashplayer.h:24
MythUIWebBrowser
Web browsing widget.
Definition: mythuiwebbrowser.h:132
MythFlashPlayer::~MythFlashPlayer
~MythFlashPlayer() override
Definition: mythflashplayer.cpp:34
mythuiwebbrowser.h
MythUIWebBrowser::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythuiwebbrowser.cpp:1519
mythmainwindow.h
MythMainWindow::PauseIdleTimer
void PauseIdleTimer(bool Pause)
Pause the idle timeout timer.
Definition: mythmainwindow.cpp:2155