make youtube work on a single window

parent 09f87a9c
......@@ -213,24 +213,30 @@ void SkyliveProtocol::processPackets()
{
SKMessage mmsg("youtubevideo");
//#if defined(Q_OS_WIN)
#if defined(Q_OS_WIN)
QString yt("http://youtube.googleapis.com/v/");
yt.append(paramlist[0]);
yt.append("?autoplay=1&start=");
yt.append(paramlist[1]);
//#else
#else
//SKMessage mmsg("openurl");
/*
QString yt("http://www.youtube.com/embed/");
yt.append(paramlist[0]);
yt.append("?html5=1&autoplay=1&start=");
yt.append(paramlist[1]);
#endif */
#endif
mmsg.parameters.insert("url", yt);
mmsg.parameters.insert("volume", paramlist[2]);
sendMessage(mmsg);
}
}
else if(pkt.cmd=="CLOSEYOUTUBE")
{
SKMessage mmsg("closeyoutube");
QList<QString> paramlist = pkt.params.split(PARAM_SEPARATOR);
mmsg.parameters.insert("when", paramlist[0]);
sendMessage(mmsg);
}
else
{
std::cout << "Unknown command from server" <<std::endl;
......
......@@ -59,8 +59,10 @@ MainWin::MainWin(QString &htmlfile)
registerHandler((QString)"openurl", (SKHandlerFunction)&MainWin::handle_openurl);
registerHandler((QString)"youtubevideo", (SKHandlerFunction)&MainWin::handle_youtubevideo);
registerHandler((QString)"closeyoutube", (SKHandlerFunction)&MainWin::handle_closeyoutube);
msgsender = SENDER;
yt_is_open=false;
}
......@@ -136,19 +138,49 @@ void MainWin::handle_youtubevideo(SKMessage &msg)
{
if(msg.parameters.contains("url"))
{
std::cout << "OPEN URL " << msg.parameters["url"].toStdString() << std::endl;
std::cout << "OPEN URL " << msg.parameters["url"].toStdString() << std::endl;
//if(msg.parameters.contains("width")
//if(msg.parameters.contains("height);
WebWin *wv = new WebWin();
QWebPage *newWeb = new QWebPage(wv);
if(!yt_is_open)
{
yt = new WebWin();
yt_is_open=true;
QWebPage *newWeb = new QWebPage(yt);
yt->setPage(newWeb);
yt->setAttribute(Qt::WA_DeleteOnClose, true);
yt->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
yt->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
yt->setUrl(QUrl(msg.parameters["url"]));
connect(yt, SIGNAL(closingWindow()), this, SLOT(ytclosesignal()));
yt->show();
}
else
{
yt->setUrl(QUrl(msg.parameters["url"]));
}
wv->setPage(newWeb);
wv->setAttribute(Qt::WA_DeleteOnClose, true);
wv->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
wv->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
wv->setUrl(QUrl(msg.parameters["url"]));
wv->show();
}
}
}
void MainWin::ytclosesignal()
{
yt_is_open=false;
}
void MainWin::handle_closeyoutube(SKMessage &msg)
{
if(msg.handle=="closeyoutube")
{
try
{
if(yt_is_open)
yt->close();
}
catch(int e)
{
std::cout << "ERROR Closing youtube window " << std::endl;
}
}
}
......
......@@ -58,12 +58,17 @@ class MainWin : public SkylivexWin
MainWin(QString &htmlfile);
~MainWin();
QString msgsender;
WebWin* yt;
bool yt_is_open;
void handle_corestarted(SKMessage &msg);
void handle_connected(SKMessage &msg);
void handle_asklogin(SKMessage &msg);
void handle_loginres(SKMessage &msg);
void handle_openurl(SKMessage &msg);
void handle_youtubevideo(SKMessage &msg);
void handle_closeyoutube(SKMessage &msg);
public slots:
void ytclosesignal();
};
......
......@@ -92,6 +92,11 @@ WebWin::~WebWin()
}
void WebWin::closeEvent(QCloseEvent *event)
{
emit closingWindow();
}
QWebView* WebWin::createWindow(QWebPage::WebWindowType type)
{
WebWin *wv = new WebWin;
......
......@@ -72,6 +72,7 @@ class WebWin : public QWebView
WebWin();
WebWin(QString &htmlfile);
~WebWin();
void closeEvent(QCloseEvent *event);
void setHtmlFile(QString &fname);
void setHtmlFile(QString &fname, bool borders, bool transparentbg);
void setHtmlCont(QString cont, QUrl baseUrl, bool borders, bool transparentbg);
......@@ -88,6 +89,7 @@ class WebWin : public QWebView
signals:
void putMessage(SKMessage &msg);
void closingWindow();
// XXX Future usage
//protected:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment