make youtube work on a single window

parent 09f87a9c
...@@ -213,24 +213,30 @@ void SkyliveProtocol::processPackets() ...@@ -213,24 +213,30 @@ void SkyliveProtocol::processPackets()
{ {
SKMessage mmsg("youtubevideo"); SKMessage mmsg("youtubevideo");
//#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
QString yt("http://youtube.googleapis.com/v/"); QString yt("http://youtube.googleapis.com/v/");
yt.append(paramlist[0]); yt.append(paramlist[0]);
yt.append("?autoplay=1&start="); yt.append("?autoplay=1&start=");
yt.append(paramlist[1]); yt.append(paramlist[1]);
//#else #else
//SKMessage mmsg("openurl"); //SKMessage mmsg("openurl");
/*
QString yt("http://www.youtube.com/embed/"); QString yt("http://www.youtube.com/embed/");
yt.append(paramlist[0]); yt.append(paramlist[0]);
yt.append("?html5=1&autoplay=1&start="); yt.append("?html5=1&autoplay=1&start=");
yt.append(paramlist[1]); yt.append(paramlist[1]);
#endif */ #endif
mmsg.parameters.insert("url", yt); mmsg.parameters.insert("url", yt);
mmsg.parameters.insert("volume", paramlist[2]); mmsg.parameters.insert("volume", paramlist[2]);
sendMessage(mmsg); 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 else
{ {
std::cout << "Unknown command from server" <<std::endl; std::cout << "Unknown command from server" <<std::endl;
......
...@@ -59,8 +59,10 @@ MainWin::MainWin(QString &htmlfile) ...@@ -59,8 +59,10 @@ MainWin::MainWin(QString &htmlfile)
registerHandler((QString)"openurl", (SKHandlerFunction)&MainWin::handle_openurl); registerHandler((QString)"openurl", (SKHandlerFunction)&MainWin::handle_openurl);
registerHandler((QString)"youtubevideo", (SKHandlerFunction)&MainWin::handle_youtubevideo); registerHandler((QString)"youtubevideo", (SKHandlerFunction)&MainWin::handle_youtubevideo);
registerHandler((QString)"closeyoutube", (SKHandlerFunction)&MainWin::handle_closeyoutube);
msgsender = SENDER; msgsender = SENDER;
yt_is_open=false;
} }
...@@ -139,16 +141,46 @@ void MainWin::handle_youtubevideo(SKMessage &msg) ...@@ -139,16 +141,46 @@ void MainWin::handle_youtubevideo(SKMessage &msg)
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("width")
//if(msg.parameters.contains("height); //if(msg.parameters.contains("height);
WebWin *wv = new WebWin(); if(!yt_is_open)
QWebPage *newWeb = new QWebPage(wv); {
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"])); void MainWin::ytclosesignal()
wv->show(); {
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 ...@@ -58,12 +58,17 @@ class MainWin : public SkylivexWin
MainWin(QString &htmlfile); MainWin(QString &htmlfile);
~MainWin(); ~MainWin();
QString msgsender; QString msgsender;
WebWin* yt;
bool yt_is_open;
void handle_corestarted(SKMessage &msg); void handle_corestarted(SKMessage &msg);
void handle_connected(SKMessage &msg); void handle_connected(SKMessage &msg);
void handle_asklogin(SKMessage &msg); void handle_asklogin(SKMessage &msg);
void handle_loginres(SKMessage &msg); void handle_loginres(SKMessage &msg);
void handle_openurl(SKMessage &msg); void handle_openurl(SKMessage &msg);
void handle_youtubevideo(SKMessage &msg); void handle_youtubevideo(SKMessage &msg);
void handle_closeyoutube(SKMessage &msg);
public slots:
void ytclosesignal();
}; };
......
...@@ -92,6 +92,11 @@ WebWin::~WebWin() ...@@ -92,6 +92,11 @@ WebWin::~WebWin()
} }
void WebWin::closeEvent(QCloseEvent *event)
{
emit closingWindow();
}
QWebView* WebWin::createWindow(QWebPage::WebWindowType type) QWebView* WebWin::createWindow(QWebPage::WebWindowType type)
{ {
WebWin *wv = new WebWin; WebWin *wv = new WebWin;
......
...@@ -72,6 +72,7 @@ class WebWin : public QWebView ...@@ -72,6 +72,7 @@ class WebWin : public QWebView
WebWin(); WebWin();
WebWin(QString &htmlfile); WebWin(QString &htmlfile);
~WebWin(); ~WebWin();
void closeEvent(QCloseEvent *event);
void setHtmlFile(QString &fname); void setHtmlFile(QString &fname);
void setHtmlFile(QString &fname, bool borders, bool transparentbg); void setHtmlFile(QString &fname, bool borders, bool transparentbg);
void setHtmlCont(QString cont, QUrl baseUrl, bool borders, bool transparentbg); void setHtmlCont(QString cont, QUrl baseUrl, bool borders, bool transparentbg);
...@@ -88,6 +89,7 @@ class WebWin : public QWebView ...@@ -88,6 +89,7 @@ class WebWin : public QWebView
signals: signals:
void putMessage(SKMessage &msg); void putMessage(SKMessage &msg);
void closingWindow();
// XXX Future usage // XXX Future usage
//protected: //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