summaryrefslogtreecommitdiff
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
parentOpen new tab near previous (diff)
downloadrekonq-7c6db1a17dbede4911d2c13cd36a485272f3e5a4.tar.xz
We have thumbnails! Hugh!
-rw-r--r--data/home.html97
-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
6 files changed, 311 insertions, 165 deletions
diff --git a/data/home.html b/data/home.html
index d1a200cf..68ab9326 100644
--- a/data/home.html
+++ b/data/home.html
@@ -17,74 +17,38 @@ 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;
}
/* ------------------------------------------------------- */
-h2{
+h1{
color: #00f;
}
-td{
-padding: 2em;
-vertical-align: top;
-}
-
-td.bookmarks{
- border-left: 2px solid #0000FF;
- border-top-width: 0px;
- border-bottom-width: 0px;
-}
-
-.indent {
-margin-left: 2em;
+.float {
+ float: right;
+ width: 30%;
+ background-color: orange;
+ border-width: 2px;
+ border-style: solid;
+ border-color: black;
+ padding: 10px;
+ margin: 8px;
+ font-weight: bold;
+ color: white;
+ clear: right;
}
-</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";
- }
+float:left;
+width:230px;
+margin:0 10px 10px 10px;
}
-</script>
+</style>
<!-- =================================================================================== -->
@@ -93,24 +57,13 @@ 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>
+<div class="float">%1</div>
+<div class="float">%2</div>
+<div>%3</div>
</body>
</html>
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