From 19d7611101253c27a841480fca55f1bc5cd767b6 Mon Sep 17 00:00:00 2001 From: matgic78 Date: Sun, 22 Nov 2009 14:53:33 +0100 Subject: clicktoflash : step 2 make it work when there are more than one plugin in the same page --- src/clicktoflash.cpp | 33 +++++++++++++++++++++++++++------ src/clicktoflash.h | 8 ++++++-- src/webpluginfactory.cpp | 2 +- 3 files changed, 34 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/clicktoflash.cpp b/src/clicktoflash.cpp index d89c1ec5..39d55e5a 100644 --- a/src/clicktoflash.cpp +++ b/src/clicktoflash.cpp @@ -39,9 +39,9 @@ #include -ClickToFlash::ClickToFlash(const WebPluginFactory *factory, QWidget *parent) +ClickToFlash::ClickToFlash(const WebPluginFactory *factory, QUrl pluginUrl, QWidget *parent) : QWidget(parent) - , m_factory(factory) + , m_url(pluginUrl) { kDebug() << "creating clicktoflash"; @@ -96,6 +96,7 @@ void ClickToFlash::loadAll() */ void ClickToFlash::load(bool loadAll) { + kDebug() << "called"; QWidget *parent = parentWidget(); QWebView *view = 0; while (parent) @@ -126,17 +127,37 @@ void ClickToFlash::load(bool loadAll) elements.append(docElement.findAll(selector.arg(QLatin1String("embed")))); QWebElement element; + kDebug() << m_url; + bool isRightElement = false; foreach (element, elements) { - QWebElement substitute = element.clone(); - emit signalLoadClickToFlash(true); - element.replace(substitute); + // TODO : find a proper solution to compare a QWebElement with a plugin + if(QUrl(element.attribute("data")) == m_url + || QUrl(element.attribute("src")) == m_url) + isRightElement = true; + + QWebElementCollection collec = element.findAll("param"); + int i = 0; + while(i < collec.count() && isRightElement == false) + { + if(QUrl(collec.at(i).attribute("value")) == m_url) + isRightElement = true; + i++; + } + + if(isRightElement) + { + QWebElement substitute = element.clone(); + emit signalLoadClickToFlash(true); + element.replace(substitute); + return; + } } frames += frame->childFrames(); } - deleteLater(); + //deleteLater(); } diff --git a/src/clicktoflash.h b/src/clicktoflash.h index 382c6001..3660a1f9 100644 --- a/src/clicktoflash.h +++ b/src/clicktoflash.h @@ -31,6 +31,7 @@ #include #include +#include class WebPluginFactory; @@ -38,7 +39,10 @@ class ClickToFlash : public QWidget { Q_OBJECT public: - ClickToFlash(const WebPluginFactory *factory, QWidget *parent = 0); + /** + pluginUrl : used to find the right QWebElement between the ones of the different plugins + */ + ClickToFlash(const WebPluginFactory *factory, QUrl pluginUrl, QWidget *parent = 0); signals: void signalLoadClickToFlash(bool); @@ -52,7 +56,7 @@ private slots: void load(bool loadAll = false); private: - const WebPluginFactory *m_factory; + const QUrl m_url; }; #endif // CLICKTOFLASH_H diff --git a/src/webpluginfactory.cpp b/src/webpluginfactory.cpp index 2c8ed181..1478339b 100644 --- a/src/webpluginfactory.cpp +++ b/src/webpluginfactory.cpp @@ -88,7 +88,7 @@ QObject *WebPluginFactory::create(const QString &mimeType, if(mimeType == QString("application/x-shockwave-flash") && !loadClickToFlash) // the button wasn't clicked { - ClickToFlash* ctf = new ClickToFlash(this); + ClickToFlash* ctf = new ClickToFlash(this, url); connect(ctf, SIGNAL(signalLoadClickToFlash(bool)), this, SLOT(setLoadClickToFlash(bool))); return ctf; } -- cgit v1.2.1