Ticket #9301: mythbrowser.patch

File mythbrowser.patch, 6.0 KB (added by Jonatan <mythtv@…>, 9 years ago)
  • mythplugins/mythbrowser/mythbrowser/bookmarkmanager.cpp

     
    1919#include "bookmarkeditor.h"
    2020#include "browserdbutil.h"
    2121#include "mythbrowser.h"
     22#include "mythflashplayer.h"
    2223
    2324// ---------------------------------------------------
    2425
     
    381382    {
    382383        MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
    383384
    384         MythBrowser *mythbrowser = new MythBrowser(mainStack, urls, zoom.toFloat());
     385        MythScreenType *mythbrowser;
     386        if (urls[0].startsWith("mythflash://"))
     387            mythbrowser = new MythFlashPlayer(mainStack, urls);
     388        else
     389            mythbrowser = new MythBrowser(mainStack, urls, zoom.toFloat());
    385390
    386391        if (mythbrowser->Create())
    387392        {
  • mythplugins/mythbrowser/mythbrowser/mythflashplayer.h

     
     1#ifndef MYTHFLASHPLAYER_H
     2#define MYTHFLASHPLAYER_H
     3
     4#include <mythscreentype.h>
     5
     6class MythUIWebBrowser;
     7
     8class MythFlashPlayer : public MythScreenType
     9{
     10  Q_OBJECT
     11
     12  public:
     13    MythFlashPlayer(MythScreenStack *parent, QStringList &urlList);
     14    ~MythFlashPlayer();
     15
     16    bool Create(void);
     17    bool keyPressEvent(QKeyEvent *);
     18
     19  private:
     20    QVariant evaluateJavaScript(const QString&);
     21    MythUIWebBrowser*         m_browser;
     22    QString                   m_url;
     23};
     24
     25#endif
  • mythplugins/mythbrowser/mythbrowser/mythbrowser.pro

     
    1616INSTALLS += installimages
    1717
    1818# Input
    19 HEADERS += mythbrowser.h webpage.h
     19HEADERS += mythbrowser.h mythflashplayer.h webpage.h
    2020HEADERS += bookmarkmanager.h bookmarkeditor.h browserdbutil.h
    21 SOURCES += main.cpp mythbrowser.cpp webpage.cpp
     21SOURCES += main.cpp mythbrowser.cpp mythflashplayer.cpp webpage.cpp
    2222SOURCES += bookmarkmanager.cpp bookmarkeditor.cpp browserdbutil.cpp
    2323
    2424include ( ../../libs-targetfix.pro )
  • mythplugins/mythbrowser/mythbrowser/main.cpp

     
    1515#include "bookmarkmanager.h"
    1616#include "browserdbutil.h"
    1717#include "mythbrowser.h"
     18#include "mythflashplayer.h"
    1819
    1920using namespace std;
    2021
     
    3031    float zoom = gCoreContext->GetSetting("WebBrowserZoomLevel", "1.4").toFloat();
    3132
    3233    MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
     34    MythScreenType *mythbrowser;
     35    if (urls[0].startsWith("mythflash://"))
     36        mythbrowser = new MythFlashPlayer(mainStack, urls);
     37    else
     38        mythbrowser = new MythBrowser(mainStack, urls, zoom);
    3339
    34     MythBrowser *mythbrowser = new MythBrowser(mainStack, urls, zoom);
    35 
    3640    if (mythbrowser->Create())
    3741        mainStack->AddScreen(mythbrowser);
    3842    else
  • mythplugins/mythbrowser/mythbrowser/mythflashplayer.cpp

     
     1#include <stdlib.h>
     2#include <iostream>
     3
     4// qt
     5#include <QApplication>
     6#include <QEvent>
     7
     8// myth
     9#include <mythverbose.h>
     10#include <mythcontext.h>
     11#include <libmythui/mythmainwindow.h>
     12#include <mythuiwebbrowser.h>
     13
     14// mythbrowser
     15#include "webpage.h"
     16#include "mythflashplayer.h"
     17
     18using namespace std;
     19
     20MythFlashPlayer::MythFlashPlayer(MythScreenStack *parent,
     21                         QStringList &urlList)
     22    : MythScreenType (parent, "mythflashplayer"),
     23      m_browser(NULL), m_url(urlList[0])
     24{
     25    qApp->setOverrideCursor(QCursor(Qt::BlankCursor));
     26}
     27
     28
     29MythFlashPlayer::~MythFlashPlayer()
     30{
     31    qApp->restoreOverrideCursor();
     32
     33    if (m_browser)
     34    {
     35        m_browser->disconnect();
     36        DeleteChild(m_browser);
     37        m_browser = NULL;
     38    }
     39}
     40
     41bool MythFlashPlayer::Create(void)
     42{
     43    m_browser = new MythUIWebBrowser(this, "mythflashplayer");
     44    m_browser->SetArea(GetMythMainWindow()->GetUIScreenRect());
     45    m_browser->Init();
     46    m_browser->SetActive(true);
     47    m_browser->Show();
     48
     49    BuildFocusList();
     50
     51    SetFocusWidget(m_browser);
     52
     53    m_url.replace("mythflash://", "http://");
     54    VERBOSE(VB_GENERAL, QString("Opening %1").arg(m_url));
     55    m_browser->LoadPage(QUrl::fromEncoded(m_url.toLocal8Bit()));
     56
     57    return true;
     58}
     59
     60QVariant MythFlashPlayer::evaluateJavaScript(const QString& source)
     61{
     62    return m_browser->evaluateJavaScript(source);
     63}
     64
     65bool MythFlashPlayer::keyPressEvent(QKeyEvent *event)
     66{
     67    QStringList actions;
     68    bool handled = GetMythMainWindow()->TranslateKeyPress("TV Playback", event, actions);
     69
     70    for (int i = 0; i < actions.size() && !handled; i++)
     71    {
     72        QString action = actions[i];
     73        handled = true;
     74
     75        if (action == "PAUSE")
     76            evaluateJavaScript("play();");
     77        else if (action == "SEEKFFWD")
     78            evaluateJavaScript("seek(10);");
     79        else if (action == "SEEKRWND")
     80            evaluateJavaScript("seek(-10);");
     81        else if (action == "CHANNELUP")
     82            evaluateJavaScript("seek(60);");
     83        else if (action == "CHANNELDOWN")
     84            evaluateJavaScript("seek(-60);");
     85        else
     86            handled = false;
     87
     88        if (handled)
     89            return true;
     90    }
     91
     92    handled = m_browser->keyPressEvent(event);
     93
     94    if (!handled && MythScreenType::keyPressEvent(event))
     95        handled = true;
     96
     97    return handled;
     98}