From 47a26d10894d4c88d219dba8d04c0eae4ea48974 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 15 Sep 2009 17:14:14 +0200 Subject: Here we are, embedding Qt Widgets.. Now it's time to RUN working or I'll be dismissed!! This implementation works quite fine, it's a bit slow but really better than the previous one. It crashes gloriously loading flash contents (Qt bug? WebPlugin one's?) and does not resize well webviews.. --- src/CMakeLists.txt | 2 +- src/homepage.cpp | 3 +- src/mainview.cpp | 1 - src/rekonq.kcfg | 4 +-- src/settings.cpp | 1 - src/webpage.cpp | 6 ++-- src/webpluginfactory.cpp | 76 ++++++++++++++++++++++++++++++++++++++++ src/webpluginfactory.h | 52 +++++++++++++++++++++++++++ src/websnap.cpp | 91 ------------------------------------------------ src/websnap.h | 65 ---------------------------------- src/webview.h | 4 +++ 11 files changed, 139 insertions(+), 166 deletions(-) create mode 100644 src/webpluginfactory.cpp create mode 100644 src/webpluginfactory.h delete mode 100644 src/websnap.cpp delete mode 100644 src/websnap.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9b24e2ec..755ae33d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,6 @@ ### ------- SETTING REKONQ FILES.. SET( rekonq_SRCS - websnap.cpp homepage.cpp networkaccessmanager.cpp autosaver.cpp @@ -24,6 +23,7 @@ SET( rekonq_SRCS lineedit.cpp webpage.cpp sessionmanager.cpp + webpluginfactory.cpp ) diff --git a/src/homepage.cpp b/src/homepage.cpp index 0cd966f4..f6867c7e 100644 --- a/src/homepage.cpp +++ b/src/homepage.cpp @@ -37,7 +37,6 @@ #include "application.h" #include "mainwindow.h" #include "mainview.h" -#include "websnap.h" // KDE Includes #include @@ -99,7 +98,7 @@ QString HomePage::speedDial() speed += "
"; speed += ""; - speed += ""; + speed += ""; speed += ""; speed += ""; // speed += "\"""; diff --git a/src/mainview.cpp b/src/mainview.cpp index 038562e8..accc1610 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -42,7 +42,6 @@ #include "webview.h" #include "sessionmanager.h" #include "homepage.h" -#include "websnap.h" // KDE Includes #include diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg index 6b57a9fa..417b7fbc 100644 --- a/src/rekonq.kcfg +++ b/src/rekonq.kcfg @@ -12,10 +12,10 @@ - KDE site,Google,rekonq,SourceForge,kde-apps,kernel, wikipedia,wordpress,adjam site + KDE site,Google,rekonq - http://www.kde.org,http://www.google.com,http://rekonq.sourceforge.net,http://sourceforge.net,http://kde-apps.org,http://www.kernel.org,http://wikipedia.org,http://wordpress.com,http://www.adjam.org + http://www.kde.org,http://www.google.com,http://rekonq.sourceforge.net false diff --git a/src/settings.cpp b/src/settings.cpp index 9767b676..504e2460 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -38,7 +38,6 @@ #include "mainwindow.h" #include "networkaccessmanager.h" #include "webview.h" -#include "websnap.h" //Ui Includes #include "ui_settings_general.h" diff --git a/src/webpage.cpp b/src/webpage.cpp index ea902932..697cf448 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -42,6 +42,7 @@ #include "cookiejar.h" #include "networkaccessmanager.h" #include "webview.h" +#include "webpluginfactory.h" // KDE Includes #include @@ -73,9 +74,8 @@ WebPage::WebPage(QObject *parent) , m_pressedButtons(Qt::NoButton) , m_requestedUrl() { - // Enable plugin support - settings()->setAttribute(QWebSettings::PluginsEnabled, true); - + setPluginFactory(new WebPluginFactory(this)); + setForwardUnsupportedContent(true); setNetworkAccessManager(Application::networkAccessManager()); diff --git a/src/webpluginfactory.cpp b/src/webpluginfactory.cpp new file mode 100644 index 00000000..1ff1b783 --- /dev/null +++ b/src/webpluginfactory.cpp @@ -0,0 +1,76 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + + +// Self Includes +#include "webpluginfactory.h" +#include "webpluginfactory.moc" + +#include "webview.h" +#include "webpage.h" + +#include + +#include "application.h" +#include "mainwindow.h" + +WebPluginFactory::WebPluginFactory(QObject *parent) + : QWebPluginFactory(parent) +{ +} + + +WebPluginFactory::~WebPluginFactory() +{ +} + + +QObject *WebPluginFactory::create(const QString &mimeType, + const QUrl &url, + const QStringList &argumentNames, + const QStringList &argumentValues) const +{ + Q_UNUSED(mimeType) + Q_UNUSED(argumentNames) + Q_UNUSED(argumentValues) + + WebView* w = new WebView( Application::instance()->mainWindow()->currentTab() ); + w->load(url); +// w->page()->setViewportSize(w->page()->mainFrame()->contentsSize()); + return w; +} + + +QList WebPluginFactory::plugins() const +{ + QList plugins; + + QWebPluginFactory::Plugin p; + p.name = "WebView"; + p.description = "plugin for embedding WebViews"; + plugins.append(p); + + return plugins; +} diff --git a/src/webpluginfactory.h b/src/webpluginfactory.h new file mode 100644 index 00000000..c63b0ce3 --- /dev/null +++ b/src/webpluginfactory.h @@ -0,0 +1,52 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + + +#ifndef WEB_PLUGIN_FACTORY_H +#define WEB_PLUGIN_FACTORY_H + + +#include +#include +#include + + +class WebPluginFactory : public QWebPluginFactory +{ +Q_OBJECT + +public: + WebPluginFactory(QObject *parent); + ~WebPluginFactory(); + + virtual QObject *create(const QString &mimeType, + const QUrl &url, + const QStringList &argumentNames, + const QStringList &argumentValues) const; + + virtual QList plugins() const; +}; + +#endif // WEB_PLUGIN_FACTORY_H diff --git a/src/websnap.cpp b/src/websnap.cpp deleted file mode 100644 index 1f564223..00000000 --- a/src/websnap.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 Nokia Corporation -* Copyright (C) 2009 by Andrea Diamantini -* -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License as -* published by the Free Software Foundation; either version 2 of -* the License or (at your option) version 3 or any later version -* accepted by the membership of KDE e.V. (or its successor approved -* by the membership of KDE e.V.), which shall act as a proxy -* defined in Section 14 of version 3 of the license. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* ============================================================ */ - - -#include "websnap.h" -#include "websnap.moc" - -#include -#include - -#include -#include -#include -#include -#include - - -WebSnap::WebSnap(const KUrl &url, const QString &fileName) - : QObject() - , m_url(url) - , m_image(QImage()) - , m_fileName(fileName) -{ - // this to not register websnap history - m_page.settings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, true); - - m_targetSize = QSize(200, 150); - connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(saveResult(bool))); - QTimer::singleShot(0, this, SLOT(load())); -} - - -void WebSnap::load() -{ - m_page.mainFrame()->load(m_url); -} - - -void WebSnap::saveResult(bool ok) -{ - // crude error-checking - if (!ok) - { - kDebug() << "Error loading site.."; - return; - } - - // find proper size, we stick to sensible aspect ratio - QSize size = m_page.mainFrame()->contentsSize(); - size.setHeight(size.width() * m_targetSize.height() / m_targetSize.width()); - - // create the target surface - m_image = QImage( size , QImage::Format_ARGB32_Premultiplied); - m_image.fill(Qt::transparent); - - // render and rescale - QPainter p(&m_image); - m_page.setViewportSize(m_page.mainFrame()->contentsSize()); - m_page.mainFrame()->render(&p); - p.end(); - m_image = m_image.scaled(m_targetSize, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); - - QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + m_fileName, true); - if( m_image.save(path) ) - { - emit finished(); - } -} diff --git a/src/websnap.h b/src/websnap.h deleted file mode 100644 index 8993fd08..00000000 --- a/src/websnap.h +++ /dev/null @@ -1,65 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 Nokia Corporation -* Copyright (C) 2009 by Andrea Diamantini -* -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License as -* published by the Free Software Foundation; either version 2 of -* the License or (at your option) version 3 or any later version -* accepted by the membership of KDE e.V. (or its successor approved -* by the membership of KDE e.V.), which shall act as a proxy -* defined in Section 14 of version 3 of the license. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* ============================================================ */ - -#ifndef WEB_SNAP_H -#define WEB_SNAP_H - - -#include - -#include -#include -#include - - -/** - * This class renders a site producing an image based - * on that. - * Heavily based on Graphics-Dojo WebSnap example (thanks!) - */ -class WebSnap : public QObject -{ - Q_OBJECT - -public: - WebSnap(const KUrl &url, const QString &fileName); - -signals: - void finished(); - -private slots: - void load(); - void saveResult(bool ok); - -private: - QWebPage m_page; - KUrl m_url; - QImage m_image; - QString m_fileName; - QSize m_targetSize; -}; - -#endif // WEB_SNAP_H diff --git a/src/webview.h b/src/webview.h index f1e5272c..16b199ff 100644 --- a/src/webview.h +++ b/src/webview.h @@ -45,6 +45,9 @@ class WebView : public QWebView public: explicit WebView(QWidget *parent = 0); + + // Q_DECLARE_METATYPE requires a copy-constructor + WebView(const WebView &); WebPage *page(); KUrl url() const; @@ -82,5 +85,6 @@ private: int m_progress; QString m_statusBarText; }; +Q_DECLARE_METATYPE(WebView) #endif -- cgit v1.2.1