diff options
-rw-r--r-- | data/home.html | 98 | ||||
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/homepage.cpp | 159 | ||||
-rw-r--r-- | src/homepage.h | 14 | ||||
-rw-r--r-- | src/mainview.cpp | 14 | ||||
-rw-r--r-- | src/mainview.h | 5 | ||||
-rw-r--r-- | src/mainwindow.cpp | 2 | ||||
-rw-r--r-- | src/previewimage.cpp | 67 | ||||
-rw-r--r-- | src/previewimage.h | 55 | ||||
-rw-r--r-- | src/rekonq.kcfg | 14 | ||||
-rw-r--r-- | src/settings.cpp | 45 | ||||
-rw-r--r-- | src/settings_newtabpage.ui | 74 | ||||
-rw-r--r-- | src/webpage.cpp | 3 | ||||
-rw-r--r-- | src/webpluginfactory.cpp | 89 | ||||
-rw-r--r-- | src/webpluginfactory.h | 52 | ||||
-rw-r--r-- | src/websnap.cpp | 103 | ||||
-rw-r--r-- | src/websnap.h | 67 | ||||
-rw-r--r-- | src/webview.h | 2 |
18 files changed, 705 insertions, 162 deletions
diff --git a/data/home.html b/data/home.html index d1a200cf..0471e3a6 100644 --- a/data/home.html +++ b/data/home.html @@ -17,74 +17,47 @@ font-family: sans-serif; font-size: 100%; } -/* ------------------------------------------------------- */ - -div#container{ -margin: 0; -} - -div#header{ -margin: 0; -padding: 2px; -background-color:#00f; -color: #ff0; -text-align: center; -} - -div#footer{ -background-color:#00f; -color: #ff0; -text-align: center; +#header{ +text-align:right; +padding: 10px; +margin:5px; } /* ------------------------------------------------------- */ -h2{ +h1{ color: #00f; } -td{ -padding: 2em; -vertical-align: top; +#float { +float: right; +width: 30%; +clear: right; } -td.bookmarks{ - border-left: 2px solid #0000FF; - border-top-width: 0px; - border-bottom-width: 0px; +.block { +background-color: #FFA500; +border: 2px solid #000000; +padding: 0.5em; +margin:15px; +font-weight: bold; +color: white; +clear: right; } -.indent { -margin-left: 2em; +#left{ +width:70%; +margin-right:30%; } -</style> - -<!-- =================================================================================== --> -<script type="text/javascript"> -function ToggleVisibility(image, element) +.thumbnail { - // Find the image. - var image = document.getElementById(image) - - // Find the element to hide/unhide. - var element = document.getElementById(element) - - // Check the element's current state. - if (element.style.display == "none") - { - // If hidden, unhide it. - element.style.display = "block"; - image.src = "%1open.png"; - } - else - { - // If not hidden, hide it. - element.style.display = "none"; - image.src = "%1closed.png"; - } +text-align: center; +float:left; +width:230px; +margin:15px; } -</script> +</style> <!-- =================================================================================== --> @@ -93,24 +66,15 @@ function ToggleVisibility(image, element) <body> <div id="header"> -<h1>rekonq home page</h1> +<h1>rekonq</h1> </div> -<table width="100%"> -<tr> -<td width="40%"><h2>History</h2></td> -<td width="60%"><h2>Bookmarks</h2></td> -</tr> - -<tr> -<td>%2</td> -<td class="bookmarks">%3</td> -</tr> -</table> -<div id="footer"> -rekonq, lightweight Web Browser for KDE based on Webkit. +<div id="float"> +<div class="block">%1</div> +<div class="block">%2</div> </div> +<div id="left">%3</div> </body> </html> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f7d54c39..c443de2e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,8 @@ SET( rekonq_SRCS homepage.cpp + previewimage.cpp + websnap.cpp networkaccessmanager.cpp autosaver.cpp application.cpp @@ -23,6 +25,7 @@ SET( rekonq_SRCS lineedit.cpp webpage.cpp sessionmanager.cpp + webpluginfactory.cpp ) @@ -30,6 +33,7 @@ KDE4_ADD_UI_FILES( rekonq_SRCS password.ui proxy.ui settings_general.ui + settings_newtabpage.ui settings_fonts.ui settings_proxy.ui settings_webkit.ui diff --git a/src/homepage.cpp b/src/homepage.cpp index 6acd4afd..14db5806 100644 --- a/src/homepage.cpp +++ b/src/homepage.cpp @@ -28,15 +28,22 @@ #include "homepage.h" #include "homepage.moc" +// Auto Includes +#include "rekonq.h" + // Local Includes #include "historymodels.h" #include "bookmarks.h" #include "application.h" +#include "mainwindow.h" +#include "mainview.h" // KDE Includes #include <KStandardDirs> #include <KIconLoader> #include <KDebug> +#include <KConfig> +#include <KConfigGroup> // Qt Includes #include <QFile> @@ -46,7 +53,6 @@ HomePage::HomePage(QObject *parent) : QObject(parent) { m_homePagePath = KStandardDirs::locate("data", "rekonq/htmls/home.html"); - m_imagesPath = "file://" + KStandardDirs::locate("appdata", "pics/"); } @@ -65,114 +71,105 @@ QString HomePage::rekonqHomePage() return QString(""); } - QString history = fillHistory(); - - QString bookmarks = fillBookmarks(); + QString speed = speedDial(); + QString search = searchEngines(); + QString lastBlock = ReKonfig::showLastVisitedSites() ? fillRecentHistory() : recentlyClosedTabs() ; + QString html = QString(QLatin1String(file.readAll())) - .arg(m_imagesPath) - .arg(history) - .arg(bookmarks); + .arg(search) + .arg(lastBlock) + .arg(speed) + ; return html; } -QString HomePage::fillHistory() +QString HomePage::speedDial() { - QString history = QString(); - HistoryTreeModel *model = Application::historyManager()->historyTreeModel(); + QStringList names = ReKonfig::previewNames(); + QStringList urls = ReKonfig::previewUrls(); - int i = 0; - do + QString speed = QString(); + for(int i = 0; i< urls.count(); ++i) { - QModelIndex index = model->index(i, 0, QModelIndex() ); - if(model->hasChildren(index)) - { - QString s = QString::number(i); - history += createSubMenu(index.data().toString(), s); - history += "<p id=\"y" + s + "\" class=\"indent\" style=\"display:none\">"; - for(int j=0; j< model->rowCount(index); ++j) - { - QModelIndex son = model->index(j, 0, index ); -// FIXME add an icon to each history item history += "<img src=\"" + ciao + "\" alt=\"icon\" />"; - history += QString("<a href=\"") + son.data(HistoryModel::UrlStringRole).toString() + QString("\">") + - son.data().toString() + QString("</a><br />"); - } - history += "</p>"; - } - else - { - history += QString("<p> NO CHILDREN: ") + index.data().toString() + QString("</p>"); - } - i++; + speed += "<div class=\"thumbnail\">"; + speed += "<a href=\"" + urls.at(i) + "\">"; + speed += "<object type=\"application/image-preview\" width=\"200\">"; + speed += "<param name=\"url\" value=\"" + urls.at(i) + "\">"; + speed += "<param name=\"position\" value=\"" + QString::number(i) + "\">"; + speed += "</object>"; + speed += "<br />"; + speed += names.at(i) + "</a></div>"; } - while( model->hasIndex( i , 0 , QModelIndex() ) ); - - return history; - + return speed; } -QString HomePage::fillBookmarks() +QString HomePage::searchEngines() { - KBookmarkGroup toolBarGroup = Application::bookmarkProvider()->rootGroup(); - if (toolBarGroup.isNull()) - { - return QString("Error retrieving bookmarks!"); - } - - QString str = QString(""); - KBookmark bookmark = toolBarGroup.first(); - while (!bookmark.isNull()) - { - str += createBookItem(bookmark); - bookmark = toolBarGroup.next(bookmark); - } + QString engines = "<h2>Search Engines</h2>"; + + // Google search engine + engines += "<form method=\"get\" action=\"http://www.google.com/search\">"; + engines += "<label for=\"q\">Google:</label>"; + engines += "<input type=\"text\" name=\"q\" />"; + engines += "</form>"; - return str; + return engines; } -QString HomePage::createSubMenu(const QString &item, const QString &s) +QString HomePage::recentlyClosedTabs() { - QString menu = "<div onClick=\"ToggleVisibility('x" + s + "','y" + s + "')\">"; - - menu += "<p><img id=\"x" + s + "\" src=\"" + m_imagesPath + "closed.png\" /> <b><u>" + item + "</u></b></p></div>"; - return menu; + QString closed = "<h2>Recently closed tabs</h2>"; + closed += "<ul>"; + + KUrl::List links = Application::instance()->mainWindow()->mainView()->recentlyClosedTabs(); + + foreach(const KUrl &url, links) + { + closed += "<li><a href=\"" + url.prettyUrl() + "\">" + url.prettyUrl() + "</a></li>"; + } + + closed += "</ul>"; + return closed; } -QString HomePage::createBookItem(const KBookmark &bookmark) +QString HomePage::fillRecentHistory() { - static int i = 0; + QString history = "<h2>Last 20 visited sites</h2>"; + history += "<ul>"; - if (bookmark.isGroup()) + HistoryTreeModel *model = Application::historyManager()->historyTreeModel(); + + int i = 0; + do { - QString result = QString(""); - QString ss = "b" + QString::number(i); - i++; - - KBookmarkGroup group = bookmark.toGroup(); - KBookmark bm = group.first(); - result += createSubMenu( bookmark.text() , ss ); - result += "<p id=\"y" + ss + "\" class=\"indent\" style=\"display:none\">"; - - while (!bm.isNull()) + QModelIndex index = model->index(i, 0, QModelIndex() ); + if(model->hasChildren(index)) { - result += createBookItem(bm); //menuAction->addAction(fillBookmarkBar(bm)); - bm = group.next(bm); + for(int j=0; j< model->rowCount(index) && i<20 ; ++j) + { + QModelIndex son = model->index(j, 0, index ); + + history += "<li>"; + history += QString("<a href=\"") + son.data(HistoryModel::UrlStringRole).toString() + QString("\">"); + history += son.data().toString(); + history += QString("</a>"); + history += "</li>"; + + i++; + } } - result += "</p>"; - return result; - } - - if(bookmark.isSeparator()) - { - return QString("<hr />"); + i++; } + while( i<20 || model->hasIndex( i , 0 , QModelIndex() ) ); + + history += "<ul>"; + + return history; - QString str = ""; // FIXME Add icon "<img src=\"" + KStandardDirs::findResource( "icon", bookmark.icon() + ".png" ) + "\" alt=\"icon\" />"; - str += "<a href=\"" + bookmark.url().prettyUrl() + "\">" + bookmark.text() + "</a><br />"; - return str; } diff --git a/src/homepage.h b/src/homepage.h index e8b5b4f5..7604f0c3 100644 --- a/src/homepage.h +++ b/src/homepage.h @@ -40,20 +40,18 @@ class HomePage : public QObject Q_OBJECT public: - HomePage(QObject *parent = 0); + HomePage(QObject *parent); ~HomePage(); QString rekonqHomePage(); private: - QString fillHistory(); - QString fillBookmarks(); - - QString createSubMenu(const QString &, const QString &); - QString createBookItem(const KBookmark &); - + QString speedDial(); + QString searchEngines(); + QString recentlyClosedTabs(); + QString fillRecentHistory(); + QString m_homePagePath; - QString m_imagesPath; }; #endif // REKONQ_HOME_PAGE diff --git a/src/mainview.cpp b/src/mainview.cpp index c28953d7..a662bbb0 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -176,6 +176,8 @@ void MainView::clear() /// TODO What exactly do we need to clear here? m_urlBar->clearHistory(); m_urlBar->clear(); + + m_recentlyClosedTabs.clear(); } @@ -299,7 +301,7 @@ void MainView::newTab() urlBar()->setUrl(KUrl("")); urlBar()->setFocus(); - HomePage p; + HomePage p(w); switch(ReKonfig::newTabsBehaviour()) { @@ -405,11 +407,13 @@ void MainView::slotCloseTab(int index) int risp = KMessageBox::questionYesNo(this, i18n("You have modified this page and when closing it you would lose the modifications.\n" "Do you really want to close this page?\n"), - i18n("Do you really want to close this page?")); + i18n("Closing tab confirmation")); if (risp == KMessageBox::No) return; } hasFocus = tab->hasFocus(); + + m_recentlyClosedTabs.prepend(tab->url()); } QWidget *webView = widget(index); @@ -585,3 +589,9 @@ void MainView::resizeEvent(QResizeEvent *event) { KTabWidget::resizeEvent(event); } + + +KUrl::List MainView::recentlyClosedTabs() +{ + return m_recentlyClosedTabs; +} diff --git a/src/mainview.h b/src/mainview.h index 4eb1d4bd..297871b0 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -71,6 +71,8 @@ public: WebView *currentWebView() const; int webViewIndex(WebView *webView) const; + KUrl::List recentlyClosedTabs(); + /** * show and hide TabBar if user doesn't choose * "Always Show TabBar" option @@ -123,7 +125,6 @@ public slots: void slotWebReload(); void slotWebStop(); - private slots: void slotCurrentChanged(int index); @@ -159,6 +160,8 @@ private: QString m_loadingGitPath; int m_currentTabIndex; + + KUrl::List m_recentlyClosedTabs; }; #endif // MAINVIEW_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1dc56f7a..5a095a72 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -743,7 +743,7 @@ void MainWindow::slotHome() if(ReKonfig::useNewTabPage()) { - HomePage p; + HomePage p(w); w->setHtml( p.rekonqHomePage(), QUrl()); } else diff --git a/src/previewimage.cpp b/src/previewimage.cpp new file mode 100644 index 00000000..d027bfd1 --- /dev/null +++ b/src/previewimage.cpp @@ -0,0 +1,67 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com> +* +* +* 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 <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + +#include "previewimage.h" +#include "previewimage.moc" + +#include <QFile> + +#include <KUrl> +#include <KStandardDirs> +#include <KDebug> + +PreviewImage::PreviewImage(const QString &url, const QString &pos) + : QLabel() + , ws(0) +{ + QString path = KStandardDirs::locateLocal("cache", QString("thumbs/rek") + pos + ".png", true); + + if(QFile::exists(path)) + { + kDebug() << "exists! Loading it..."; + m_pixmap.load(path); + setPixmap( m_pixmap ); + } + else + { + QString path = KStandardDirs::locate("appdata", "pics/loading.mng"); + setPixmap( QPixmap(path) ); + + ws = new WebSnap( url, pos ); + connect(ws, SIGNAL(finished()), this, SLOT(setSiteImage())); + } +} + + +PreviewImage::~PreviewImage() +{ + kDebug() << "bye bye.."; +} + +void PreviewImage::setSiteImage() +{ + kDebug() << "Done. works?"; + setPixmap( ws->previewImage() ); +} diff --git a/src/previewimage.h b/src/previewimage.h new file mode 100644 index 00000000..612d98c6 --- /dev/null +++ b/src/previewimage.h @@ -0,0 +1,55 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com> +* +* +* 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 <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + + +#ifndef PREVIEW_IMAGE_H +#define PREVIEW_IMAGE_H + + +#include "websnap.h" + +#include <QLabel> +#include <QImage> + + +class PreviewImage : public QLabel +{ + Q_OBJECT + +public: + PreviewImage(const QString &url, const QString &pos); + + ~PreviewImage(); + +public slots: + void setSiteImage(); + +private: + QPixmap m_pixmap; + + WebSnap *ws; +}; + +#endif // PREVIEW_IMAGE_H diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg index 04115ac8..3de675f8 100644 --- a/src/rekonq.kcfg +++ b/src/rekonq.kcfg @@ -9,6 +9,20 @@ <kcfgfile name="rekonqrc" /> +<!-- New Tab Page Settings --> + <group name="NewTabPage"> + <entry name="previewNames" type="StringList"> + <default>KDE site,Google,rekonq</default> + </entry> + <entry name="previewUrls" type="StringList"> + <default>http://www.kde.org,http://www.google.com,http://rekonq.sourceforge.net</default> + </entry> + <entry name="showLastVisitedSites" type="Bool"> + <default>true</default> + </entry> + </group> + + <!-- General Settings --> <group name="General"> <entry name="useNewTabPage" type="Bool"> diff --git a/src/settings.cpp b/src/settings.cpp index 843b3375..1950c40a 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -41,6 +41,7 @@ //Ui Includes #include "ui_settings_general.h" +#include "ui_settings_newtabpage.h" #include "ui_settings_fonts.h" #include "ui_settings_proxy.h" #include "ui_settings_webkit.h" @@ -62,6 +63,7 @@ class Private { private: Ui::general generalUi; + Ui::newtabpage newtabpageUi; Ui::fonts fontsUi; Ui::proxy proxyUi; Ui::webkit webkitUi; @@ -86,6 +88,12 @@ Private::Private(SettingsDialog *parent) pageItem->setIcon(KIcon("rekonq")); widget = new QWidget; + newtabpageUi.setupUi(widget); + widget->layout()->setMargin(0); + pageItem = parent->addPage(widget , i18n("New Tab Page")); + pageItem->setIcon(KIcon("tab-new")); + + widget = new QWidget; fontsUi.setupUi(widget); widget->layout()->setMargin(0); pageItem = parent->addPage(widget , i18n("Fonts")); @@ -146,7 +154,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) connect(this, SIGNAL(applyClicked()), this, SLOT(saveSettings())); connect(this, SIGNAL(okClicked()), this, SLOT(saveSettings())); - + setWebSettingsToolTips(); } @@ -177,6 +185,28 @@ void SettingsDialog::setWebSettingsToolTips() // we need this function to UPDATE the config widget data.. void SettingsDialog::readConfig() { + // ====== New Tab Page + QTableWidget *t = d->newtabpageUi.tableWidget; + QStringList names, urls; + names = ReKonfig::previewNames(); + urls = ReKonfig::previewUrls(); + for(int i=0; i< urls.count(); ++i) + { + QTableWidgetItem *name = new QTableWidgetItem( names.at(i) ); + t->setItem(i,0,name); + QTableWidgetItem *url = new QTableWidgetItem( urls.at(i) ); + t->setItem(i,1,url); + } + + ReKonfig::setPreviewNames(names); + ReKonfig::setPreviewUrls(urls); + + if( ReKonfig::showLastVisitedSites() ) + d->newtabpageUi.showLastVisitedSites->setChecked( true ); + else + d->newtabpageUi.showRecentlyClosedTabs->setChecked( true ); + + // ======= Fonts d->fontsUi.kcfg_fixedFont->setOnlyFixed(true); @@ -190,6 +220,19 @@ void SettingsDialog::readConfig() // we need this function to SAVE settings in rc file.. void SettingsDialog::saveSettings() { + QTableWidget *t = d->newtabpageUi.tableWidget; + QStringList names, urls; + for(int i=0; i<9; ++i) + { + names << t->item(i,0)->text(); + urls << t->item(i,1)->text(); + } + + ReKonfig::setPreviewNames(names); + ReKonfig::setPreviewUrls(urls); + + ReKonfig::setShowLastVisitedSites( d->newtabpageUi.showLastVisitedSites->isChecked() ); + ReKonfig::self()->writeConfig(); d->ebrowsingModule->save(); d->cookiesModule->save(); diff --git a/src/settings_newtabpage.ui b/src/settings_newtabpage.ui new file mode 100644 index 00000000..2061d285 --- /dev/null +++ b/src/settings_newtabpage.ui @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>newtabpage</class> + <widget class="QWidget" name="newtabpage"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>377</width> + <height>444</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Previews</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QTableWidget" name="tableWidget"> + <property name="rowCount"> + <number>9</number> + </property> + <property name="columnCount"> + <number>2</number> + </property> + <row/> + <row/> + <row/> + <row/> + <row/> + <row/> + <row/> + <row/> + <row/> + <column/> + <column/> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox_2"> + <property name="title"> + <string>blocks</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QRadioButton" name="showLastVisitedSites"> + <property name="text"> + <string>show last 20 visited sites</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="showRecentlyClosedTabs"> + <property name="text"> + <string>show recently closed tabs</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/src/webpage.cpp b/src/webpage.cpp index b33d2cce..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 <KStandardDirs> @@ -73,6 +74,8 @@ WebPage::WebPage(QObject *parent) , m_pressedButtons(Qt::NoButton) , m_requestedUrl() { + 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..1e599327 --- /dev/null +++ b/src/webpluginfactory.cpp @@ -0,0 +1,89 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com> +* +* +* 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 <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + + +// Self Includes +#include "webpluginfactory.h" +#include "webpluginfactory.moc" + +#include "application.h" +#include "mainwindow.h" +#include "previewimage.h" + +#include <KDebug> + +WebPluginFactory::WebPluginFactory(QObject *parent) + : QWebPluginFactory(parent) +{ +} + + +WebPluginFactory::~WebPluginFactory() +{ +} + + +QObject *WebPluginFactory::create(const QString &mimeType, + const QUrl &url, + const QStringList &argumentNames, + const QStringList &argumentValues) const +{ + kDebug() << "loading mimeType: " << mimeType; + + if(mimeType == QString("application/image-preview") ) + { + QString url, pos; + for(int i = 0; i<argumentNames.count(); ++i) + { + if(argumentNames.at(i) == QString("url")) + { + url = argumentValues.at(i); + } + if(argumentNames.at(i) == QString("position")) + { + pos = argumentValues.at(i); + } + } + return new PreviewImage(url, pos); + } + + kDebug() << "No plugins found for" << mimeType; + QWebView* webView = new QWebView; + webView->load(url); + return webView; +} + + +QList<QWebPluginFactory::Plugin> WebPluginFactory::plugins() const +{ + QList<QWebPluginFactory::Plugin> plugins; + + QWebPluginFactory::Plugin p; + p.name = "application/image-preview"; + p.description = "plugin for embedding Web snapped images"; + 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 <adjam7 at gmail dot com> +* +* +* 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 <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + + +#ifndef WEB_PLUGIN_FACTORY_H +#define WEB_PLUGIN_FACTORY_H + + +#include <QtWebKit/QWebPluginFactory> +#include <QtCore/QList> +#include <QtGui/QWidget> + + +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<Plugin> plugins() const; +}; + +#endif // WEB_PLUGIN_FACTORY_H diff --git a/src/websnap.cpp b/src/websnap.cpp new file mode 100644 index 00000000..ec537b32 --- /dev/null +++ b/src/websnap.cpp @@ -0,0 +1,103 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 Nokia Corporation <qt-info@nokia.com> +* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com> +* +* +* 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 <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + + +#include "websnap.h" +#include "websnap.moc" + +#include <KDebug> +#include <KStandardDirs> + +#include <QSize> +#include <QWebFrame> +#include <QWebSettings> +#include <QPainter> +#include <QTimer> +#include <QFile> + + +#define WIDTH 200 +#define HEIGHT 150 + + +WebSnap::WebSnap(const QString &url, const QString &pos) + : QObject() +{ + m_url = url; + m_pos = pos; + + // this to not register websnap history + m_page.settings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, true); + connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(saveResult(bool))); + QTimer::singleShot(0, this, SLOT(load())); +} + + +void WebSnap::load() +{ + kDebug() << "loading.."; + m_page.mainFrame()->load( QUrl(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() * HEIGHT / WIDTH ); + + // create the target surface + m_image = QPixmap(WIDTH, HEIGHT); + 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(WIDTH, HEIGHT, Qt::KeepAspectRatioByExpanding); + + + QString path = KStandardDirs::locateLocal("cache", QString("thumbs/rek") + m_pos + ".png", true); + if( m_image.save(path) ) + { + kDebug() << "finished"; + emit finished(); + } +} + + +QPixmap WebSnap::previewImage() +{ + return m_image; +} diff --git a/src/websnap.h b/src/websnap.h new file mode 100644 index 00000000..2bcdfef8 --- /dev/null +++ b/src/websnap.h @@ -0,0 +1,67 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 Nokia Corporation <qt-info@nokia.com> +* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com> +* +* +* 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 <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + +#ifndef WEB_SNAP_H +#define WEB_SNAP_H + + +#include <KUrl> + +#include <QtCore/QObject> +#include <QPixmap> +#include <QWebPage> + + +/** + * 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 QString &url, const QString &pos); + + QPixmap previewImage(); + +signals: + void finished(); + +private slots: + void load(); + void saveResult(bool ok); + +private: + QWebPage m_page; + QPixmap m_image; + + QString m_url; + QString m_pos; +}; + +#endif // WEB_SNAP_H diff --git a/src/webview.h b/src/webview.h index f1e5272c..a132a193 100644 --- a/src/webview.h +++ b/src/webview.h @@ -45,7 +45,7 @@ class WebView : public QWebView public: explicit WebView(QWidget *parent = 0); - + WebPage *page(); KUrl url() const; QString lastStatusBarText() const; |