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 // myth
9 #include <mythlogging.h>
10 #include <mythcontext.h>
11 #include <mythmainwindow.h>
12 #include <mythuiwebbrowser.h>
13 #include <mythuihelper.h>
14 #include <playgroup.h>
15 
16 // mythbrowser
17 #include "webpage.h"
18 #include "mythflashplayer.h"
19 
20 using namespace std;
21 
23  QStringList &urlList)
24  : MythScreenType (parent, "mythflashplayer"),
25  m_url(urlList[0])
26 {
27  m_fftime = PlayGroup::GetSetting("Default", "skipahead", 30);
28  m_rewtime = PlayGroup::GetSetting("Default", "skipback", 5);
29  m_jumptime = PlayGroup::GetSetting("Default", "jump", 10);
30  qApp->setOverrideCursor(QCursor(Qt::BlankCursor));
33 }
34 
35 
37 {
38  qApp->restoreOverrideCursor();
39 
40  if (m_browser)
41  {
42  m_browser->disconnect();
44  m_browser = nullptr;
45  }
48 }
49 
51 {
52  if (!m_browser)
53  m_browser = new MythUIWebBrowser(this, "mythflashplayer");
54  m_browser->SetArea(GetMythMainWindow()->GetUIScreenRect());
55  m_browser->Init();
56  m_browser->SetActive(true);
57  m_browser->Show();
58 
60 
62 
63  m_url.replace("mythflash://", "http://");
64  LOG(VB_GENERAL, LOG_INFO, QString("Opening %1").arg(m_url));
65  m_browser->LoadPage(QUrl::fromEncoded(m_url.toLocal8Bit()));
66 
67  return true;
68 }
69 
70 QVariant MythFlashPlayer::evaluateJavaScript(const QString& source)
71 {
72  return (m_browser ? m_browser->evaluateJavaScript(source) : QVariant());
73 }
74 
75 bool MythFlashPlayer::keyPressEvent(QKeyEvent *event)
76 {
77  QStringList actions;
78  bool handled = GetMythMainWindow()->TranslateKeyPress("TV Playback", event, actions);
79 
80  for (int i = 0; i < actions.size() && !handled; i++)
81  {
82  QString action = actions[i];
83  handled = true;
84 
85  if (action == "PAUSE")
86  evaluateJavaScript("play();");
87  else if (action == "INFO")
88  evaluateJavaScript("info();");
89  else if (action == "SEEKFFWD")
90  evaluateJavaScript(QString("seek(%1);").arg(m_fftime));
91  else if (action == "SEEKRWND")
92  evaluateJavaScript(QString("seek(-%1);").arg(m_rewtime));
93  else if (action == "CHANNELUP")
94  evaluateJavaScript(QString("seek(%1);").arg(m_jumptime * 60));
95  else if (action == "CHANNELDOWN")
96  evaluateJavaScript(QString("seek(-%1);").arg(m_jumptime * 60));
97  else if (action == "VOLUMEUP")
98  evaluateJavaScript("adjustVolume(2);");
99  else if (action == "VOLUMEDOWN")
100  evaluateJavaScript("adjustVolume(-2);");
101  else
102  handled = false;
103 
104  if (handled)
105  return true;
106  }
107 
108  if (m_browser)
109  handled = m_browser->keyPressEvent(event);
110 
111  if (!handled && MythScreenType::keyPressEvent(event))
112  handled = true;
113 
114  return handled;
115 }
void Show(void)
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
void LoadPage(const QUrl &url)
Loads the specified url and displays it.
void DisableScreensaver(void)
QVariant evaluateJavaScript(const QString &)
void DeleteChild(const QString &name)
Delete a named child of this UIType.
Definition: mythuitype.cpp:147
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
void Init(void)
Initializes the widget ready for use.
void BuildFocusList(void)
MythUIHelper * GetMythUI()
MythMainWindow * GetMythMainWindow(void)
void SetActive(bool active)
Toggles the active state of the widget.
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:591
void PauseIdleTimer(bool pause)
void RestoreScreensaver(void)
bool Create(void) override
bool keyPressEvent(QKeyEvent *) override
Key event handler.
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
static int GetSetting(const QString &name, const QString &field, int defval)
Definition: playgroup.cpp:246
QVariant evaluateJavaScript(const QString &scriptSource)
Evaluates the JavaScript code in scriptSource.
MythUIWebBrowser * m_browser
MythFlashPlayer(MythScreenStack *parent, QStringList &urlList)
bool SetFocusWidget(MythUIType *widget=nullptr)
Screen in which all other widgets are contained and rendered.
Web browsing widget.