summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-09-13 18:20:57 +0200
committerAndrea Diamantini <adjam7@gmail.com>2009-09-14 18:36:47 +0200
commit7c6db1a17dbede4911d2c13cd36a485272f3e5a4 (patch)
treeaa98fa5466a8daa479a9ccb4f90612560393193f /src
parentOpen new tab near previous (diff)
downloadrekonq-7c6db1a17dbede4911d2c13cd36a485272f3e5a4.tar.xz
We have thumbnails! Hugh!
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/homepage.cpp216
-rw-r--r--src/homepage.h9
-rw-r--r--src/websnap.cpp88
-rw-r--r--src/websnap.h65
5 files changed, 286 insertions, 93 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f7d54c39..db3722fb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,6 +1,7 @@
### ------- SETTING REKONQ FILES..
SET( rekonq_SRCS
+ websnap.cpp
homepage.cpp
networkaccessmanager.cpp
autosaver.cpp
diff --git a/src/homepage.cpp b/src/homepage.cpp
index 6acd4afd..59078c51 100644
--- a/src/homepage.cpp
+++ b/src/homepage.cpp
@@ -32,6 +32,7 @@
#include "historymodels.h"
#include "bookmarks.h"
#include "application.h"
+#include "websnap.h"
// KDE Includes
#include <KStandardDirs>
@@ -46,7 +47,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 +65,156 @@ QString HomePage::rekonqHomePage()
return QString("");
}
- QString history = fillHistory();
-
- QString bookmarks = fillBookmarks();
+ QString speed = speedDial();
+ QString search = searchEngines();
+ QString closedtabs = recentlyClosedTabs();
+
QString html = QString(QLatin1String(file.readAll()))
- .arg(m_imagesPath)
- .arg(history)
- .arg(bookmarks);
+ .arg(search)
+ .arg(closedtabs)
+ .arg(speed)
+ ;
return html;
}
-QString HomePage::fillHistory()
+QString HomePage::speedDial()
{
- QString history = QString();
- HistoryTreeModel *model = Application::historyManager()->historyTreeModel();
+ KUrl::List ul ;
+ ul << KUrl("http://www.google.it") << KUrl("http://www.kde.org") << KUrl("http://rekonq.sourceforge.net")
+ << KUrl("http://www.slacky.eu") << KUrl("http://kde-apps.org") << KUrl("http://www.kernel.org")
+ << KUrl("http://it.wikipedia.org") << KUrl("http://www.adjam.org") << KUrl("http://adjamblog.wordpress.com");
- int i = 0;
- do
+ QString speed = QString();
+ for(int i = 0; i< ul.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
+ KUrl url = ul.at(i);
+ QString fileName = QString("thumb") + QString::number(i) + QString(".png");
+ QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + fileName, true);
+ if( !QFile::exists(path) )
{
- history += QString("<p> NO CHILDREN: ") + index.data().toString() + QString("</p>");
+ kDebug() << "websnap";
+ WebSnap *ws = new WebSnap(url, fileName);
}
- i++;
+
+ speed += "<img class=\"thumbnail\" src=\"" + path + "\" width=\"200\" alt=\"" + url.prettyUrl() + "\" />";
}
- 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 = "engines";
- 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 + "')\">";
+ QString closedtabs = "closed";
- menu += "<p><img id=\"x" + s + "\" src=\"" + m_imagesPath + "closed.png\" /> <b><u>" + item + "</u></b></p></div>";
- return menu;
+ return closedtabs;
}
-
-QString HomePage::createBookItem(const KBookmark &bookmark)
-{
- static int i = 0;
-
- if (bookmark.isGroup())
- {
- 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())
- {
- result += createBookItem(bm); //menuAction->addAction(fillBookmarkBar(bm));
- bm = group.next(bm);
- }
- result += "</p>";
- return result;
- }
-
- if(bookmark.isSeparator())
- {
- return QString("<hr />");
- }
-
- 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;
-}
+// QString HomePage::fillHistory()
+// {
+// QString history = QString();
+// HistoryTreeModel *model = Application::historyManager()->historyTreeModel();
+//
+// int i = 0;
+// do
+// {
+// 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++;
+// }
+// while( model->hasIndex( i , 0 , QModelIndex() ) );
+//
+// return history;
+//
+// }
+//
+//
+// QString HomePage::fillBookmarks()
+// {
+// 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);
+// }
+//
+// return str;
+// }
+//
+//
+// QString HomePage::createSubMenu(const QString &item, const QString &s)
+// {
+// 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 HomePage::createBookItem(const KBookmark &bookmark)
+// {
+// static int i = 0;
+//
+// if (bookmark.isGroup())
+// {
+// 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())
+// {
+// result += createBookItem(bm); //menuAction->addAction(fillBookmarkBar(bm));
+// bm = group.next(bm);
+// }
+// result += "</p>";
+// return result;
+// }
+//
+// if(bookmark.isSeparator())
+// {
+// return QString("<hr />");
+// }
+//
+// 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..c4ef7fc5 100644
--- a/src/homepage.h
+++ b/src/homepage.h
@@ -46,14 +46,11 @@ public:
QString rekonqHomePage();
private:
- QString fillHistory();
- QString fillBookmarks();
-
- QString createSubMenu(const QString &, const QString &);
- QString createBookItem(const KBookmark &);
+ QString speedDial();
+ QString searchEngines();
+ QString recentlyClosedTabs();
QString m_homePagePath;
- QString m_imagesPath;
};
#endif // REKONQ_HOME_PAGE
diff --git a/src/websnap.cpp b/src/websnap.cpp
new file mode 100644
index 00000000..8bacd3b2
--- /dev/null
+++ b/src/websnap.cpp
@@ -0,0 +1,88 @@
+/* ============================================================
+*
+* 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 <QPainter>
+#include <QTimer>
+
+
+WebSnap::WebSnap(const KUrl &url, const QString &fileName)
+ : QObject()
+ , m_url(url)
+ , m_image(QImage())
+ , m_fileName(fileName)
+{
+ 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..";
+ emit finished();
+ 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);
+ m_image.save( path );
+
+ emit finished();
+}
diff --git a/src/websnap.h b/src/websnap.h
new file mode 100644
index 00000000..cbb786c7
--- /dev/null
+++ b/src/websnap.h
@@ -0,0 +1,65 @@
+/* ============================================================
+*
+* 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 <QImage>
+#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 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