summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/clicktoflash.cpp73
-rw-r--r--src/clicktoflash.h15
-rw-r--r--src/webpluginfactory.cpp7
-rw-r--r--src/webpluginfactory.h5
4 files changed, 36 insertions, 64 deletions
diff --git a/src/clicktoflash.cpp b/src/clicktoflash.cpp
index 39d55e5a..9c11dc57 100644
--- a/src/clicktoflash.cpp
+++ b/src/clicktoflash.cpp
@@ -36,10 +36,12 @@
#include <QWebView>
#include <QWebElement>
#include <QHBoxLayout>
+#include <QContextMenuEvent>
+#include <KMenu>
#include <KDebug>
-ClickToFlash::ClickToFlash(const WebPluginFactory *factory, QUrl pluginUrl, QWidget *parent)
+ClickToFlash::ClickToFlash(QUrl pluginUrl, QWidget *parent)
: QWidget(parent)
, m_url(pluginUrl)
{
@@ -54,49 +56,14 @@ ClickToFlash::ClickToFlash(const WebPluginFactory *factory, QUrl pluginUrl, QWid
button->setText(i18n("Load animation"));
button->setAutoRaise(false);
layout()->addWidget(button);
- connect(button, SIGNAL(clicked(bool)), this, SLOT(load(bool)));
+ connect(button, SIGNAL(clicked(bool)), this, SLOT(load()));
}
-/*void ClickToFlash::showContextMenu()
-{
- QMenu menu;
- menu.addAction(tr("Load"), this, SLOT(load()));
- menu.addAction(tr("Load All"), this, SLOT(loadAll()));
- menu.addSeparator();
- QString host = url.host();
- QAction *add = menu.addAction(tr("Add %1 to Whitelist").arg(host), this, SLOT(addToWhitelist()));
- QAction *remove = menu.addAction(tr("Remove from Whitelist"), this, SLOT(removeFromWhitelist()));
- bool onWhitelist = m_plugin->onWhitelist(host);
- add->setEnabled(!onWhitelist);
- remove->setEnabled(onWhitelist);
- menu.addSeparator();
- menu.addAction(tr("Settings"), this, SLOT(configure()));
- menu.exec(QCursor::pos());
-}
-
-void ClickToFlash::addToWhitelist()
-{
- m_plugin->addToWhitelist(url.host());
-}
-
-void ClickToFlash::removeFromWhitelist()
-{
- m_plugin->removeFromWhitelist(url.host());
-}
-void ClickToFlash::configure()
+void ClickToFlash::load()
{
- m_plugin->configure();
-}
-
-void ClickToFlash::loadAll()
-{
- load(true);
-}
-*/
-void ClickToFlash::load(bool loadAll)
-{
- kDebug() << "called";
+ //bool loadAll = true;
+
QWidget *parent = parentWidget();
QWebView *view = 0;
while (parent)
@@ -125,28 +92,30 @@ void ClickToFlash::load(bool loadAll)
QWebElementCollection elements;
elements.append(docElement.findAll(selector.arg(QLatin1String("object"))));
elements.append(docElement.findAll(selector.arg(QLatin1String("embed"))));
-
- QWebElement element;
- kDebug() << m_url;
+
bool isRightElement = false;
- foreach (element, elements)
+ foreach (QWebElement element, elements)
{
// TODO : find a proper solution to compare a QWebElement with a plugin
+ // With this "manual" test, it's probably not working everywhere
if(QUrl(element.attribute("data")) == m_url
- || QUrl(element.attribute("src")) == m_url)
+ || QUrl(element.attribute("src")) == m_url)
isRightElement = true;
-
- QWebElementCollection collec = element.findAll("param");
- int i = 0;
- while(i < collec.count() && isRightElement == false)
+ else
{
- if(QUrl(collec.at(i).attribute("value")) == m_url)
+ 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++;
+ i++;
+ }
}
if(isRightElement)
{
+ kDebug() << "called";
QWebElement substitute = element.clone();
emit signalLoadClickToFlash(true);
element.replace(substitute);
@@ -157,7 +126,7 @@ void ClickToFlash::load(bool loadAll)
frames += frame->childFrames();
}
- //deleteLater();
+ deleteLater();
}
diff --git a/src/clicktoflash.h b/src/clicktoflash.h
index 3660a1f9..35c661d4 100644
--- a/src/clicktoflash.h
+++ b/src/clicktoflash.h
@@ -39,23 +39,18 @@ class ClickToFlash : public QWidget
{
Q_OBJECT
public:
- /**
- pluginUrl : used to find the right QWebElement between the ones of the different plugins
- */
- ClickToFlash(const WebPluginFactory *factory, QUrl pluginUrl, QWidget *parent = 0);
+ ClickToFlash(QUrl pluginUrl, QWidget *parent = 0);
signals:
void signalLoadClickToFlash(bool);
private slots:
- /*void configure();
- void addToWhitelist();
- void removeFromWhitelist();
- void showContextMenu();
- void loadAll();*/
- void load(bool loadAll = false);
+ void load();
private:
+ /**
+ used to find the right QWebElement between the ones of the different plugins
+ */
const QUrl m_url;
};
diff --git a/src/webpluginfactory.cpp b/src/webpluginfactory.cpp
index 0d333748..d1c1ccbe 100644
--- a/src/webpluginfactory.cpp
+++ b/src/webpluginfactory.cpp
@@ -86,13 +86,16 @@ QObject *WebPluginFactory::create(const QString &mimeType,
return new PreviewImage(url, title, number, isFavorite);
}
- if(ReKonfig::pluginsEnabled() == 0)
+ if(ReKonfig::pluginsEnabled() == 0) // plugins are enabled
+ {
+ kDebug() << "No plugins found for" << mimeType << ". Falling back to QtWebKit ones...";
return 0;
+ }
if(mimeType == QString("application/x-shockwave-flash")
&& !loadClickToFlash) // the button wasn't clicked
{
- ClickToFlash* ctf = new ClickToFlash(this, url);
+ ClickToFlash* ctf = new ClickToFlash(url);
connect(ctf, SIGNAL(signalLoadClickToFlash(bool)), this, SLOT(setLoadClickToFlash(bool)));
return ctf;
}
diff --git a/src/webpluginfactory.h b/src/webpluginfactory.h
index 20dc6642..c1e4c28f 100644
--- a/src/webpluginfactory.h
+++ b/src/webpluginfactory.h
@@ -52,12 +52,17 @@ public:
virtual QList<Plugin> plugins() const;
signals:
+
void signalLoadClickToFlash(bool) const;
public slots:
void setLoadClickToFlash(bool load);
private:
+ /**
+ When true, force loading of next flash animation (don't show clicktoflash)
+ We use signals/slots to set this property because QWebPluginFactory::create is const
+ */
bool loadClickToFlash;
};