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
10#include <libmythtv/playgroup.h>
14
15// mythbrowser
16#include "mythflashplayer.h"
17#include "webpage.h"
18
20 QStringList &urlList)
21 : MythScreenType (parent, "mythflashplayer"),
22 m_url(urlList[0])
23{
24 m_fftime = PlayGroup::GetSetting("Default", "skipahead", 30);
25 m_rewtime = PlayGroup::GetSetting("Default", "skipback", 5);
26 m_jumptime = PlayGroup::GetSetting("Default", "jump", 10);
27 QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
30}
31
32
34{
35 QGuiApplication::restoreOverrideCursor();
36
37 if (m_browser)
38 {
39 m_browser->disconnect();
41 m_browser = nullptr;
42 }
45}
46
48{
49 if (!m_browser)
50 m_browser = new MythUIWebBrowser(this, "mythflashplayer");
51 m_browser->SetArea(MythRect(GetMythMainWindow()->GetUIScreenRect()));
52 m_browser->Init();
53 m_browser->SetActive(true);
54 m_browser->Show();
55
57
59
60 m_url.replace("mythflash://", "http://");
61 LOG(VB_GENERAL, LOG_INFO, QString("Opening %1").arg(m_url));
62 m_browser->LoadPage(QUrl::fromEncoded(m_url.toLocal8Bit()));
63
64 return true;
65}
66
67void MythFlashPlayer::runJavaScript(const QString& source)
68{
69 if (m_browser)
70 m_browser->RunJavaScript(source);
71}
72
73bool 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 const QString& action = actions[i];
81 handled = true;
82
83 if (action == "PAUSE")
84 runJavaScript("play();");
85 else if (action == "INFO")
86 runJavaScript("info();");
87 else if (action == "SEEKFFWD")
88 runJavaScript(QString("seek(%1);").arg(m_fftime));
89 else if (action == "SEEKRWND")
90 runJavaScript(QString("seek(-%1);").arg(m_rewtime));
91 else if (action == "CHANNELUP")
92 runJavaScript(QString("seek(%1);").arg(m_jumptime * 60));
93 else if (action == "CHANNELDOWN")
94 runJavaScript(QString("seek(-%1);").arg(m_jumptime * 60));
95 else if (action == "VOLUMEUP")
96 runJavaScript("adjustVolume(2);");
97 else if (action == "VOLUMEDOWN")
98 runJavaScript("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}
~MythFlashPlayer() override
MythFlashPlayer(MythScreenStack *parent, QStringList &urlList)
MythUIWebBrowser * m_browser
void runJavaScript(const QString &source)
bool Create(void) override
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
static void DisableScreensaver()
void PauseIdleTimer(bool Pause)
Pause the idle timeout timer.
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
static void RestoreScreensaver()
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:18
Screen in which all other widgets are contained and rendered.
void BuildFocusList(void)
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
bool SetFocusWidget(MythUIType *widget=nullptr)
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:610
void DeleteChild(const QString &name)
Delete a named child of this UIType.
Definition: mythuitype.cpp:153
void Show(void)
virtual bool keyPressEvent(QKeyEvent *event)
Key event handler.
Definition: mythuitype.cpp:989
Web browsing widget.
void LoadPage(const QUrl &url)
Loads the specified url and displays it.
void Init(void)
Initializes the widget ready for use.
void RunJavaScript(const QString &scriptSource)
void SetActive(bool active)
Toggles the active state of the widget.
static int GetSetting(const QString &name, const QString &field, int defval)
Definition: playgroup.cpp:277
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)