summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-02-07 00:01:52 +0100
committerAndrea Diamantini <adjam7@gmail.com>2010-02-07 00:01:52 +0100
commitf4f86382a7dc3f57a62820df19afd8b1b1d9355d (patch)
treefdb618f2877f61ddfc3f91504a1675420d8e2f78 /src
parentMerge commit 'refs/merge-requests/86' of git://gitorious.org/rekonq/mainline ... (diff)
parentFix loading previews : when load finished, result wasn't shown (diff)
downloadrekonq-f4f86382a7dc3f57a62820df19afd8b1b1d9355d.tar.xz
Merge commit 'refs/merge-requests/84' of git://gitorious.org/rekonq/mainline into matgic_tab_page
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/data/home.html80
-rw-r--r--src/mainwindow.cpp5
-rw-r--r--src/mainwindow.h8
-rw-r--r--src/previewimage.cpp430
-rw-r--r--src/previewimage.h101
-rw-r--r--src/protocolhandler.cpp33
-rw-r--r--src/rekonqpage/newtabpage.cpp240
-rw-r--r--src/rekonqpage/newtabpage.h35
-rw-r--r--src/rekonqpage/previewselectorbar.cpp160
-rw-r--r--src/rekonqpage/previewselectorbar.h60
-rw-r--r--src/urlbar/urlbar.cpp1
-rw-r--r--src/webpage.cpp1
-rw-r--r--src/webpage.h2
-rw-r--r--src/webpluginfactory.cpp28
-rw-r--r--src/websnap.cpp80
-rw-r--r--src/websnap.h24
17 files changed, 612 insertions, 678 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b0a3fbd8..00cfbf77 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -11,7 +11,6 @@ SET( rekonq_KDEINIT_SRCS
findbar.cpp
mainview.cpp
mainwindow.cpp
- previewimage.cpp
sessionmanager.cpp
tabbar.cpp
webpage.cpp
@@ -32,6 +31,7 @@ SET( rekonq_KDEINIT_SRCS
history/historypanel.cpp
#----------------------------------------
rekonqpage/newtabpage.cpp
+ rekonqpage/previewselectorbar.cpp
#----------------------------------------
settings/settingsdialog.cpp
#----------------------------------------
diff --git a/src/data/home.html b/src/data/home.html
index 9d8f390f..51b9ceec 100644
--- a/src/data/home.html
+++ b/src/data/home.html
@@ -54,6 +54,10 @@ margin-top: 0.5em;
a{
color: #3F7AB7;
text-decoration: none;
+-webkit-transition-property: color;
+-webkit-transition-duration: 0.5s;
+-webkit-transition-timing-function: ease;
+
}
a:hover{
color: black;
@@ -62,7 +66,7 @@ color: black;
/* ------------------------------------------------------- */
/* page sections */
-#container {
+#rekonq-newtabpage {
width: 100%;
}
@@ -118,18 +122,59 @@ margin-top: -5%;
/* Thumbnail class */
.thumbnail {
-text-align: center;
display: inline-block;
-width:25%;
-margin-top: 7%;
-min-width:250px;
-min-height:192px;
+width:25%; margin-top: 7%;
+min-width:250px; min-height:192px;
+}
+
+.preview img {
+}
+.preview {
+display: table-cell;
+vertical-align: middle;
+width: 200px; height: 150px;
+padding: 14px 16px;
+background: url(%2/bg.png) no-repeat;
+-webkit-background-size: 100% 100%;
+-webkit-background-clip: padding;
+}
+.thumbnail:hover .preview , .thumbnail:hover .button img {
+opacity: 0.8;
}
-.thumbnail object{
+.button img, .preview {
+-webkit-transition-property: opacity;
+-webkit-transition-duration: 0.8s;
+-webkit-transition-timing-function: ease-in-out;
+}
+
+.button img {
+display: inline-block;
+width: 16px;
+height: 16px;
+opacity: 0;
+}
+
+.remove {
+float: right;
+}
+.modify {
+float: left;
+}
+
+.title {
+display: block;
+width: 200px;
+height: 15px;
+padding: 0 14px;
text-align: center;
-width:228px;
-height:192px;
+}
+
+.thumbnail a {
+text-align:center;
+}
+.thumbnail a:hover, span {
+color:#3F7AB7;
}
/* -------------------------------------------------------- */
@@ -146,7 +191,7 @@ margin-bottom: 0.5em;
<body>
-<div id="container">
+<div id="rekonq-newtabpage">
<div id="navigation">
</div>
@@ -162,11 +207,16 @@ margin-bottom: 0.5em;
</a>
</div>
<div class="thumbnail">
- <object type="application/image-preview" data="">
- <param name="title" />
- <param name="index" />
- <param name="isFavorite" />
- </object>
+ <a>
+ <div class ="preview">
+ <img />
+ </div>
+ <div class="title">
+ <a class="button modify"><img /></a>
+ <span><a></a></span>
+ <a class="button remove"><img /></a>
+ </div>
+ </a>
</div>
<h3></h3>
<a></a>
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index e4890b72..9e6bfb03 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -98,6 +98,7 @@ MainWindow::MainWindow()
: KMainWindow()
, m_view( new MainView(this) )
, m_findBar( new FindBar(this) )
+ , m_previewSelectorBar( new PreviewSelectorBar(this) )
, m_historyPanel(0)
, m_bookmarksPanel(0)
, m_webInspectorPanel(0)
@@ -122,6 +123,7 @@ MainWindow::MainWindow()
QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(m_view);
+ layout->addWidget(m_previewSelectorBar);
layout->addWidget(m_findBar);
centralWidget->setLayout(layout);
@@ -648,6 +650,9 @@ void MainWindow::updateActions()
QAction *historyForwardAction = actionByName(KStandardAction::name(KStandardAction::Forward));
historyForwardAction->setEnabled(currentTab()->view()->history()->canGoForward());
+
+ if(m_previewSelectorBar->isVisible())
+ m_previewSelectorBar->setPage(currentTab()->page());
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 35632c64..f7746893 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -1,4 +1,5 @@
-/* ============================================================
+
+class PreviewSelectorBar;/* ============================================================
*
* This file is a part of the rekonq project
*
@@ -32,6 +33,7 @@
// Local Includes
#include "application.h"
+#include "previewselectorbar.h"
// KDE Includes
#include <KMainWindow>
@@ -156,7 +158,9 @@ private slots:
private:
MainView *m_view;
FindBar *m_findBar;
-
+
+ PreviewSelectorBar *m_previewSelectorBar;
+
HistoryPanel *m_historyPanel;
BookmarksPanel *m_bookmarksPanel;
WebInspectorPanel *m_webInspectorPanel;
diff --git a/src/previewimage.cpp b/src/previewimage.cpp
deleted file mode 100644
index 9c8bb194..00000000
--- a/src/previewimage.cpp
+++ /dev/null
@@ -1,430 +0,0 @@
-/* ============================================================
-*
-* 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 "previewimage.h"
-#include "previewimage.moc"
-
-// Local Includes
-#include "historymanager.h"
-#include "rekonq.h"
-#include "mainwindow.h"
-#include "mainview.h"
-
-// KDE Includes
-#include <KUrl>
-#include <KStandardDirs>
-#include <KDebug>
-#include <KMenu>
-#include <KAction>
-#include <KLocale>
-
-// Qt Includes
-#include <QFile>
-#include <QMovie>
-#include <QMouseEvent>
-#include <QHBoxLayout>
-#include <QVBoxLayout>
-#include <QPainter>
-
-
-PreviewImage::PreviewImage(const QUrl &url, const QString &title, int index, bool isFavorite)
- : QWidget()
- , ws(0)
- , loadingSnapshot(false)
- , m_url(url)
- , m_title(title)
- , m_isFavorite(isFavorite)
- , m_index(index)
- , m_button(0)
- , m_imageLabel(new QLabel)
- , m_textLabel(new QLabel)
- , m_backgroundLabel(new QLabel)
- , m_previewLabel(new QLabel)
-{
-
- int borderTop = 14;
- int borderRight = 16;
- int borderBottom = 14;
- int borderLeft = 16;
-
- int previewWidth = 200;
- int previewHeight = 150;
-
- int urlHeight = 18;
-
- m_size = QSize(borderLeft+previewWidth+borderRight, borderTop+previewHeight+borderBottom+urlHeight);
-
- setFixedSize(m_size);
- m_previewLabel->setFixedSize(m_size);
-
- m_backgroundLabel->setPixmap(renderBackground(previewWidth,previewHeight, borderTop, borderBottom, borderLeft, borderRight));
-
- m_previewLabel->setAlignment(Qt::AlignCenter);
- m_backgroundLabel->setAlignment(Qt::AlignCenter);
- m_imageLabel->setAlignment(Qt::AlignCenter);
- m_textLabel->setAlignment(Qt::AlignCenter);
-
- m_previewLabel->setLayout(new QVBoxLayout);
- m_previewLabel->layout()->setMargin(0);
- m_previewLabel->layout()->addWidget(m_backgroundLabel);
- m_previewLabel->layout()->addWidget(m_textLabel);
- m_previewLabel->setCursor(Qt::PointingHandCursor);
-
- m_backgroundLabel->setLayout(new QVBoxLayout);
- m_backgroundLabel->layout()->addWidget(m_imageLabel);
-
- setLayout(new QHBoxLayout);
- layout()->setMargin(0);
- layout()->setAlignment(Qt::AlignCenter);
- layout()->addWidget(m_previewLabel);
-
- connect(this, SIGNAL(loadUrl(const KUrl &, const Rekonq::OpenType &)),
- Application::instance(), SLOT(loadUrl(const KUrl &, const Rekonq::OpenType &)));
-
- loadUrlPreview(url);
-}
-
-
-PreviewImage::~PreviewImage()
-{
- delete ws;
- delete m_textLabel;
- delete m_imageLabel;
- delete m_backgroundLabel;
- delete m_previewLabel;
-}
-
-
-QPixmap PreviewImage::renderBackground(int w, int h, int t, int b, int l, int r)
-{
- QImage backImage(KStandardDirs::locate("appdata", "pics/bg.png"));
- QImage resultImage(QSize(w + l + r, h + t + b), QImage::Format_ARGB32_Premultiplied);
-
- if (!backImage.isNull())
- {
- int sw = backImage.width() - l - r;
- int sh = backImage.height() - t - b;
- QPainter pt(&resultImage);
- pt.setCompositionMode(QPainter::CompositionMode_Source);
- pt.fillRect(resultImage.rect(), Qt::transparent);
- pt.drawImage(QRect(0, 0, l, t), backImage, QRect(0, 0, l, t));
- pt.drawImage(QRect(l, 0, w, t), backImage, QRect(l, 0, sw, t));
- pt.drawImage(QRect(l + w, 0, r, t), backImage, QRect(l + sw, 0, r, t));
- pt.drawImage(QRect(0, t, l, h), backImage, QRect(0, t, l, sh));
- pt.drawImage(QRect(l, t, w, h), backImage, QRect(l, t, sw, sh));
- pt.drawImage(QRect(l + w, t, r, h), backImage, QRect(l + sw, t, r, sh));
- pt.drawImage(QRect(0, t + h, l , b), backImage, QRect(0, t + sh, l , b));
- pt.drawImage(QRect(l, t + h, w, b), backImage, QRect(l, t + sh, sw, b));
- pt.drawImage(QRect(l + w, t + h, w, b), backImage, QRect(l + sw, t + sh, sw, b));
- pt.end();
- }
-
- return QPixmap::fromImage(resultImage);
-}
-
-
-void PreviewImage::loadUrlPreview(const QUrl& url)
-{
- m_url = url;
-
- if(url.isEmpty())
- {
- showEmptyPreview();
- return;
- }
-
- m_previewLabel->setFixedSize(m_size); //unhide
-
- m_savePath = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(m_url) + ".png", true);
-
- if(QFile::exists(m_savePath))
- {
- m_pixmap.load(m_savePath);
- m_imageLabel->setPixmap(m_pixmap);
- checkTitle();
- m_textLabel->setText(m_title);
- }
- else
- {
- loadingSnapshot = true;
- ws = new WebSnap( url );
- connect(ws, SIGNAL(finished()), this, SLOT(snapFinished()));
-
- QString path = KStandardDirs::locate("appdata", "pics/busywidget.gif");
-
- // load an animation waiting for site preview
- QMovie *movie = new QMovie(path, QByteArray(), this);
- movie->setSpeed(50);
- m_imageLabel->setMovie(movie);
- movie->start();
- m_textLabel->setText( i18n("Loading preview...") );
- setCursor(Qt::BusyCursor);
- }
-}
-
-
-void PreviewImage::snapFinished()
-{
- loadingSnapshot = false;
- QMovie *m = m_imageLabel->movie();
- delete m;
- m_imageLabel->setMovie(0);
-
- m_pixmap = ws->previewImage();
- m_imageLabel->setPixmap(m_pixmap);
- checkTitle();
- m_textLabel->setText(m_title);
-
- setCursor(Qt::PointingHandCursor);
-
- m_pixmap.save(m_savePath);
-
- if(m_index > -1)
- {
- // Update title
- QStringList names = ReKonfig::previewNames();
- // update url (for added thumbs)
- QStringList urls = ReKonfig::previewUrls();
-
- // stripTrailingSlash to be sure to get the same string for same address
- urls.replace(m_index, ws->snapUrl().toString(QUrl::StripTrailingSlash));
- names.replace(m_index, ws->snapTitle());
-
- ReKonfig::setPreviewNames(names);
- ReKonfig::setPreviewUrls(urls);
-
- ReKonfig::self()->writeConfig();
- }
-}
-
-
-void PreviewImage::showEmptyPreview()
-{
- if(!m_isFavorite)
- return;
-
- m_imageLabel->clear();
- m_textLabel->clear();
-
- m_previewLabel->setFixedSize(0,0); //hide
-
-
- m_button = new QToolButton();
- m_button->setDefaultAction(historyMenu());
- m_button->setPopupMode(QToolButton::InstantPopup);
- m_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
- m_button->setText(i18n("Add Preview"));
- m_button->setAutoRaise(true);
- m_button->setIconSize(QSize(48, 48));
- layout()->addWidget(m_button);
-}
-
-
-void PreviewImage::mouseDoubleClickEvent(QMouseEvent *event)
-{
- kDebug() << "no double click over here, thanks :D";
- Q_UNUSED(event);
-}
-
-
-void PreviewImage::mouseMoveEvent(QMouseEvent *event)
-{
- kDebug() << "moving mouse over preview image";
- Q_UNUSED(event)
-}
-
-
-void PreviewImage::mousePressEvent(QMouseEvent *event)
-{
- if(event->button() == Qt::LeftButton)
- {
- emit loadUrl(m_url, Rekonq::CurrentTab);
- return;
- }
- else if(event->button() == Qt::MidButton)
- {
- emit loadUrl(m_url, Rekonq::SettingOpenTab);
- return;
- }
-
- QWidget::mousePressEvent(event);
-}
-
-
-void PreviewImage::mouseReleaseEvent(QMouseEvent *event)
-{
- kDebug() << "NO000... don't leave your finger from the button!!";
- Q_UNUSED(event)
-}
-
-
-void PreviewImage::contextMenuEvent(QContextMenuEvent* event)
-{
- if(!m_isFavorite)
- return;
-
- if(loadingSnapshot)
- return;
-
- KMenu menu(this);
- KAction *a;
-
- if(!m_url.isEmpty())
- {
- a = new KAction(KIcon("edit-delete"), i18n("Remove Thumbnail"), this);
- connect(a, SIGNAL(triggered(bool)), this, SLOT(removeMe()));
- menu.addAction(a);
-
- a = new KAction(KIcon("view-refresh"), i18n("Refresh Thumbnail"), &menu);
- connect(a, SIGNAL(triggered(bool)), this, SLOT(refreshPreview()));
- menu.addAction(a);
- }
- menu.addAction(historyMenu());
-
- menu.exec(mapToGlobal(event->pos()));
-}
-
-
-KActionMenu* PreviewImage::historyMenu()
-{
- KActionMenu *histMenu = new KActionMenu(KIcon("insert-image"), i18n("Set Page to Preview"), this);
- QList<HistoryItem> history = Application::historyManager()->history();
-
- if(history.isEmpty())
- {
- KAction *a = new KAction(i18n("History is Empty"), this);
- a->setEnabled(false);
- histMenu->addAction(a);
- return histMenu;
- }
-
- int maxItems = 15;
- for (int i = 0; i < maxItems && i < history.size() ; ++i)
- {
- HistoryItem it = history.at(i);
- KAction *a = new KAction(Application::icon(it.url), it.title, this);
- QStringList urlData;
- urlData << it.url << it.title;
- a->setData(urlData);
- connect(a, SIGNAL(triggered(bool)), this, SLOT(setUrlFromAction()));
- histMenu->addAction(a);
- }
-
- return histMenu;
-}
-
-
-void PreviewImage::removeMe()
-{
- QStringList names = ReKonfig::previewNames();
- QStringList urls = ReKonfig::previewUrls();
-
- int index = urls.indexOf(QRegExp(m_url.toString(QUrl::StripTrailingSlash), Qt::CaseSensitive, QRegExp::FixedString));
-
- urls.replace(index, QString(""));
- names.replace(index, QString(""));
-
- ReKonfig::setPreviewNames(names);
- ReKonfig::setPreviewUrls(urls);
-
- // sync file data
- ReKonfig::self()->writeConfig();
-
- showEmptyPreview();
-
- m_url = "";
-}
-
-
-void PreviewImage::setUrlFromAction()
-{
- KAction *a = qobject_cast<KAction*>(sender());
- QStringList urlData = a->data().toStringList();
-
- m_url = KUrl(urlData.at(0));
- m_title = urlData.at(1);
- checkTitle();
-
- if(m_button)
- {
- m_imageLabel->layout()->deleteLater();
- m_button->menu()->deleteLater();
- m_button->deleteLater();
- }
- loadUrlPreview(m_url);
-
- // Update title
- QStringList names = ReKonfig::previewNames();
- // update url (for added thumbs)
- QStringList urls = ReKonfig::previewUrls();
-
- // stripTrailingSlash to be sure to get the same string for same address
- urls.replace(m_index, m_url.toString(QUrl::StripTrailingSlash));
- names.replace(m_index, m_title);
-
- ReKonfig::setPreviewNames(names);
- ReKonfig::setPreviewUrls(urls);
-
- ReKonfig::self()->writeConfig();
-}
-
-
-void PreviewImage::refreshPreview()
-{
- QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(m_url) + ".png", true);
- QFile::remove(path);
- loadUrlPreview(m_url);
-}
-
-
-QString PreviewImage::guessNameFromUrl(QUrl url)
-{
- QString name = url.toString( QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash );
-
- // TODO learn Regular Expressions :)
- // and implement something better here..
- name.remove('/');
- name.remove('&');
- name.remove('.');
- name.remove('-');
- name.remove('_');
- name.remove('?');
- name.remove('=');
- name.remove('+');
-
- return name;
-}
-
-
-void PreviewImage::checkTitle()
-{
- if(m_title.length() > 23)
- {
- m_title.truncate(20);
- m_title += "...";
- }
-}
diff --git a/src/previewimage.h b/src/previewimage.h
deleted file mode 100644
index 4dd8df3b..00000000
--- a/src/previewimage.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/* ============================================================
-*
-* 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
-
-// Local Includes
-#include "websnap.h"
-#include "application.h"
-
-// KDE Includes
-#include <KActionMenu>
-
-// Qt Includes
-#include <QLabel>
-#include <QFrame>
-#include <QImage>
-#include <QUrl>
-#include <QToolButton>
-#include <QSize>
-
-
-class PreviewImage : public QWidget
-{
- Q_OBJECT
-
-public:
- PreviewImage(const QUrl &url, const QString &title, int index, bool isFavorite);
- ~PreviewImage();
-
- QString guessNameFromUrl(QUrl url);
-
-public slots:
- void snapFinished();
- void removeMe();
- void setUrlFromAction();
- void refreshPreview();
-
-signals:
- void loadUrl(const KUrl &, const Rekonq::OpenType &);
-
-protected:
- void contextMenuEvent(QContextMenuEvent *event);
- void mouseDoubleClickEvent(QMouseEvent *event);
- void mouseMoveEvent(QMouseEvent *event);
- void mousePressEvent(QMouseEvent *event);
- void mouseReleaseEvent(QMouseEvent *event);
-
- void loadUrlPreview(const QUrl &url);
- KActionMenu *historyMenu();
- void showEmptyPreview();
-
-private:
- void checkTitle();
- QPixmap renderBackground(int w, int h, int t, int b, int l, int r);
-
- QPixmap m_pixmap;
- WebSnap *ws;
-
- QString m_savePath;
- bool loadingSnapshot;
-
- QUrl m_url;
- QString m_title;
- bool m_isFavorite;
- int m_index;
-
- QToolButton *m_button;
-
- QLabel *m_imageLabel;
- QLabel *m_textLabel;
- QLabel *m_backgroundLabel;
- QLabel *m_previewLabel;
-
- QSize m_size;
-};
-
-#endif // PREVIEW_IMAGE_H
diff --git a/src/protocolhandler.cpp b/src/protocolhandler.cpp
index c90afd19..a9339cfa 100644
--- a/src/protocolhandler.cpp
+++ b/src/protocolhandler.cpp
@@ -108,36 +108,9 @@ bool ProtocolHandler::preHandling(const QNetworkRequest &request, QWebFrame *fra
// "about" handling
if ( _url.protocol() == QLatin1String("about") )
{
- if( _url == KUrl("about:home") )
- {
- switch(ReKonfig::newTabStartPage())
- {
- case 0: // favorites
- _url = KUrl("about:favorites");
- break;
- case 1: // closed tabs
- _url = KUrl("about:closedTabs");
- break;
- case 2: // history
- _url = KUrl("about:history");
- break;
- case 3: // bookmarks
- _url = KUrl("about:bookmarks");
- break;
- default: // unuseful
- break;
- }
- }
- if( _url == KUrl("about:closedTabs")
- || _url == KUrl("about:history")
- || _url == KUrl("about:bookmarks")
- || _url == KUrl("about:favorites")
- )
- {
- NewTabPage p(frame);
- p.generate(_url);
- return true;
- }
+ NewTabPage p(frame);
+ p.generate(_url);
+ return true;
}
return false;
diff --git a/src/rekonqpage/newtabpage.cpp b/src/rekonqpage/newtabpage.cpp
index 66f74b86..19f1686f 100644
--- a/src/rekonqpage/newtabpage.cpp
+++ b/src/rekonqpage/newtabpage.cpp
@@ -26,6 +26,7 @@
// Self Includes
#include "newtabpage.h"
+#include "newtabpage.moc"
// Auto Includes
#include "rekonq.h"
@@ -36,6 +37,8 @@
#include "application.h"
#include "mainwindow.h"
#include "mainview.h"
+#include "websnap.h"
+#include "previewselectorbar.h"
// KDE Includes
#include <KStandardDirs>
@@ -43,6 +46,7 @@
#include <KDebug>
#include <KConfig>
#include <KConfigGroup>
+#include <KDialog>
// Qt Includes
#include <QFile>
@@ -50,6 +54,7 @@
NewTabPage::NewTabPage(QWebFrame *frame)
: m_root(frame->documentElement())
+ , m_url(KUrl())
{
QString htmlFilePath = KStandardDirs::locate("data", "rekonq/htmls/home.html");
@@ -70,8 +75,33 @@ NewTabPage::~NewTabPage()
}
-void NewTabPage::generate(const KUrl &url)
-{
+void NewTabPage::generate(KUrl url)
+{
+ if(KUrl("about:preview").isParentOf(url))
+ {
+ if(url.directory() == QString("preview/remove"))
+ {
+ removePreview(url.fileName().toInt());
+ return;
+ }
+ if(url.directory() == QString("preview/modify"))
+ {
+ int index = url.fileName().toInt();
+ Application::instance()->mainWindow()->findChild<PreviewSelectorBar *>()
+ ->enable(index, qobject_cast< WebPage* >(m_root.webFrame()->page()));
+ return;
+ }
+ }
+
+ if( url != KUrl("about:home")
+ && url != KUrl("about:favorites")
+ && url != KUrl("about:closedTabs")
+ && url != KUrl("about:history")
+ && url != KUrl("about:bookmarks")
+ )
+ return;
+
+
QWebPage *page = m_root.webFrame()->page();
page->mainFrame()->setHtml(m_html);
@@ -80,26 +110,29 @@ void NewTabPage::generate(const KUrl &url)
browsingMenu(url);
QString title;
- if(url == KUrl("about:closedTabs"))
+ if(url == KUrl("about:home") || url == KUrl("about:favorites"))
+ {
+ favoritesPage();
+ title = i18n("Favorites");
+ url = KUrl("about:favorites");
+ }
+ else if(url == KUrl("about:closedTabs"))
{
closedTabsPage();
title = i18n("Closed Tabs");
}
- if(url == KUrl("about:history"))
+ else if(url == KUrl("about:history"))
{
historyPage();
title = i18n("History");
}
- if(url == KUrl("about:bookmarks"))
+ else if(url == KUrl("about:bookmarks"))
{
bookmarksPage();
title = i18n("Bookmarks");
}
- if(url == KUrl("about:home") || url == KUrl("about:favorites"))
- {
- favoritesPage();
- title = i18n("Favorites");
- }
+
+ m_url = url;
m_root.document().findFirst("title").setPlainText(title);
}
@@ -107,41 +140,150 @@ void NewTabPage::generate(const KUrl &url)
void NewTabPage::favoritesPage()
{
+ m_root.addClass("favorites");
+
QStringList names = ReKonfig::previewNames();
QStringList urls = ReKonfig::previewUrls();
-
- m_root.addClass("favorites");
for(int i=0; i<8; ++i)
{
- QWebElement speed = markup(".thumbnail");
- speed.findFirst("object").setAttribute("data" , urls.at(i));
- speed.findFirst("param[name=title]").setAttribute("value", names.at(i));
- speed.findFirst("param[name=index]").setAttribute("value", QString::number(i));
- speed.findFirst("param[name=isFavorite]").setAttribute("value", "true");
- m_root.appendInside(speed);
+ KUrl url = urls.at(i);
+ QWebElement prev;
+
+ if(url.isEmpty())
+ prev = emptyPreview(i);
+ else if(!QFile::exists(WebSnap::fileForUrl(url).toLocalFile()))
+ prev = loadingPreview(i, url);
+ else
+ prev = validPreview(i, url, names.at(i));
+
+ setupPreview(prev, i);
+
+ m_root.appendInside(prev);
}
}
-// FIXME : port to new PreviewImage API to use...
-/*QString NewTabPage::lastVisitedPage()
+QWebElement NewTabPage::emptyPreview(int index)
+{
+ QWebElement prev = markup(".thumbnail");
+
+ prev.findFirst(".preview img").setAttribute("src" , QString("file:///") +
+ KIconLoader::global()->iconPath("insert-image", KIconLoader::Desktop));
+ prev.findFirst("span").appendInside(i18n("Set a Preview..."));
+ prev.findFirst("a").setAttribute("href", QString("about:preview/modify/" + QVariant(index).toString()));
+
+ setupPreview(prev, index);
+ hideControls(prev);
+
+ return prev;
+}
+
+
+QWebElement NewTabPage::loadingPreview(int index, KUrl url)
+{
+ QWebElement prev = markup(".thumbnail");
+
+ prev.findFirst(".preview img").setAttribute("src" ,
+ QString("file:///") + KStandardDirs::locate("appdata", "pics/busywidget.gif"));
+ prev.findFirst("span").appendInside(i18n("Loading Preview..."));
+ prev.findFirst("a").setAttribute("href", url.toMimeDataString());
+
+ setupPreview(prev, index);
+ showControls(prev);
+
+ new WebSnap(url, m_root.webFrame()->page(), index);
+
+ return prev;
+}
+
+QWebElement NewTabPage::validPreview(int index, KUrl url, QString title)
{
- QString last;
- QList<HistoryItem> history = Application::historyManager()->history();
- for (int i = 0; i < 8 && i < history.size(); ++i)
+ QWebElement prev = markup(".thumbnail");
+ KUrl previewPath = WebSnap::fileForUrl(url);
+ QString iString = QVariant(index).toString();
+
+ prev.findFirst(".preview img").setAttribute("src" , previewPath.toMimeDataString());
+ prev.findFirst("a").setAttribute("href", url.toMimeDataString());
+ prev.findFirst("span a").setAttribute("href", url.toMimeDataString());
+ prev.findFirst("span").setPlainText(checkTitle(title));
+
+ setupPreview(prev, index);
+ showControls(prev);
+
+ return prev;
+}
+
+
+void NewTabPage::hideControls(QWebElement e)
+{
+ e.findFirst(".remove").setStyleProperty("visibility", "hidden");
+ e.findFirst(".modify").setStyleProperty("visibility", "hidden");
+}
+void NewTabPage::showControls(QWebElement e)
+{
+ e.findFirst(".remove").setStyleProperty("visibility", "visible");
+ e.findFirst(".modify").setStyleProperty("visibility", "visible");
+}
+
+void NewTabPage::setupPreview(QWebElement e, int index)
+{
+ e.findFirst(".remove img").setAttribute("src", QString("file:///") +
+ KIconLoader::global()->iconPath("edit-delete", KIconLoader::DefaultState));
+ e.findFirst(".remove").setAttribute("title", "Remove favorite");
+ e.findFirst(".modify img").setAttribute("src", QString("file:///") +
+ KIconLoader::global()->iconPath("insert-image", KIconLoader::DefaultState));
+ e.findFirst(".modify").setAttribute("title", "Set new favorite");
+
+ e.findFirst(".modify").setAttribute("href", QString("about:preview/modify/" + QVariant(index).toString()));
+ e.findFirst(".remove").setAttribute("href", QString("about:preview/remove/" + QVariant(index).toString()));
+
+ e.setAttribute("id", "preview" + QVariant(index).toString());
+}
+
+
+void NewTabPage::snapFinished(int index, KUrl url, QString title)
+{
+ // do not try to modify the page if it isn't the newTabPage
+ if(m_root.document().findAll("#rekonq-newtabpage").count() == 0)
+ return;
+
+ QWebElement prev = m_root.findFirst("#preview" + QVariant(index).toString());
+ QWebElement newPrev = validPreview(index, url, title);
+
+ if(m_root.findAll(".closedTabs").count() != 0)
+ hideControls(newPrev);
+
+ prev.replace(newPrev);
+
+ // update title
+ if(m_root.findAll(".favorites").count() != 0)
{
- HistoryItem it = history.at(i);
- last += "<div class=\"thumbnail\">";
- last += "<object type=\"application/image-preview\" data=\"" + it.url + "\" >";
- last += "</object>";
- last += "<br />";
- last += "<a href=\"" + it.url + "\">" + it.title + "</a></div>";
+ QStringList names = ReKonfig::previewNames();
+ names.replace(index, title);
+ ReKonfig::setPreviewNames(names);
+
+ ReKonfig::self()->writeConfig();
}
+}
- return last;
-}*/
+void NewTabPage::removePreview(int index)
+{
+ QStringList names = ReKonfig::previewNames();
+ QStringList urls = ReKonfig::previewUrls();
+
+ urls.replace(index, QString(""));
+ names.replace(index, QString(""));
+
+ ReKonfig::setPreviewNames(names);
+ ReKonfig::setPreviewUrls(urls);
+
+ ReKonfig::self()->writeConfig();
+
+ QWebElement prev = m_root.findFirst("#preview" + QVariant(index).toString());
+ prev.replace(emptyPreview(index));
+}
void NewTabPage::browsingMenu(const KUrl &currentUrl)
@@ -192,6 +334,8 @@ void NewTabPage::browsingMenu(const KUrl &currentUrl)
void NewTabPage::historyPage()
{
+ m_root.addClass("history");
+
HistoryTreeModel *model = Application::historyManager()->historyTreeModel();
int i = 0;
@@ -222,6 +366,8 @@ void NewTabPage::historyPage()
void NewTabPage::bookmarksPage()
{
+ m_root.addClass("bookmarks");
+
KBookmarkGroup bookGroup = Application::bookmarkProvider()->rootGroup();
if (bookGroup.isNull())
{
@@ -268,13 +414,35 @@ void NewTabPage::createBookItem(const KBookmark &bookmark, QWebElement parent)
void NewTabPage::closedTabsPage()
{
+ m_root.addClass("closedTabs");
+
QList<HistoryItem> links = Application::instance()->mainWindow()->mainView()->recentlyClosedTabs();
+
+ for(int i=0; i < links.count(); ++i)
+ {
+ HistoryItem item = links.at(i);
+ QWebElement prev;
+
+ if(item.url.isEmpty())
+ continue;
+ else if(!QFile::exists(WebSnap::fileForUrl(item.url).toLocalFile()))
+ prev = loadingPreview(i, item.url);
+ else
+ prev = validPreview(i, item.url, item.title);
+
+ prev.setAttribute("id", "preview" + QVariant(i).toString());
+ hideControls(prev);
+ m_root.appendInside(prev);
+ }
+}
- foreach(const HistoryItem &item, links)
+
+QString NewTabPage::checkTitle(QString title)
+{
+ if(title.length() > 23)
{
- QWebElement closed = markup(".thumbnail");
- closed.findFirst("object").setAttribute("data" , item.url);
- closed.findFirst("param[name=title]").setAttribute("value", item.title);
- m_root.appendInside(closed);
+ title.truncate(20);
+ title += "...";
}
+ return title;
}
diff --git a/src/rekonqpage/newtabpage.h b/src/rekonqpage/newtabpage.h
index 003aa84e..9d41946e 100644
--- a/src/rekonqpage/newtabpage.h
+++ b/src/rekonqpage/newtabpage.h
@@ -28,24 +28,22 @@
#define REKONQ_NEW_TAB_PAGE
-// rekonq Includes
-#include <webpage.h>
-
// KDE Includes
#include <KUrl>
// Qt Includes
-#include <QtCore/QObject>
-#include <QtCore/QString>
+#include <QObject>
+#include <QString>
#include <QWebElement>
// Forward Includes
class KBookmark;
+class WebPage;
-class NewTabPage
+class NewTabPage : public QObject
{
-
+Q_OBJECT
public:
NewTabPage(QWebFrame *frame);
~NewTabPage();
@@ -55,13 +53,28 @@ public:
* about: url and loads the corresponding part of the
* new tab page
*/
- void generate(const KUrl &url = KUrl("about:home"));
+ void generate(KUrl url = KUrl("about:home"));
+
+public slots:
+ void snapFinished(int index, KUrl url, QString title);
+ void removePreview(int index);
protected: // these are the function to build the new tab page
void browsingMenu(const KUrl &currentUrl);
void favoritesPage();
- //QString lastVisitedPage();
+ QWebElement emptyPreview(int index);
+ QWebElement loadingPreview(int index, KUrl url);
+ QWebElement validPreview(int index, KUrl url, QString title);
+
+ /** This function takes a QwebElement with the .thumbnail structure.
+ It hides the "remove" and "modify" buttons->
+ */
+ void hideControls(QWebElement e);
+ void showControls(QWebElement e);
+ void setupPreview(QWebElement e, int index);
+
+
void historyPage();
void bookmarksPage();
void closedTabsPage();
@@ -77,10 +90,14 @@ private:
{
return m_root.document().findFirst("#models > " + selector).clone();
}
+
+ QString checkTitle(QString title);
QString m_html;
QWebElement m_root;
+
+ KUrl m_url;
};
#endif // REKONQ_NEW_TAB_PAGE
diff --git a/src/rekonqpage/previewselectorbar.cpp b/src/rekonqpage/previewselectorbar.cpp
new file mode 100644
index 00000000..5f3956d7
--- /dev/null
+++ b/src/rekonqpage/previewselectorbar.cpp
@@ -0,0 +1,160 @@
+/*
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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 3 of the License, or
+ (at your option) any later version.
+
+ 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/>.
+
+*/
+
+
+// Auto Includes
+#include "previewselectorbar.h"
+
+// Local Include
+#include "rekonq.h"
+#include "websnap.h"
+
+// KDE Includes
+#include <KIcon>
+#include <KLocalizedString>
+
+// Qt Includes
+#include <QToolButton>
+#include <QHBoxLayout>
+#include <QString>
+
+
+PreviewSelectorBar::PreviewSelectorBar(QWidget* parent)
+ : QWidget(parent)
+ , m_button(0)
+ , m_label(0)
+ , m_page(0)
+{
+ hide();
+}
+
+
+void PreviewSelectorBar::setup()
+{
+ if(m_button != 0)
+ return;
+
+ m_label = new QLabel(i18n("Please open up the webpage you want to add as favorite"), this);
+ m_label->setWordWrap(true);
+
+ QToolButton *closeButton = new QToolButton(this);
+ closeButton->setAutoRaise(true);
+ closeButton->setIcon(KIcon("dialog-close"));
+ connect(closeButton, SIGNAL(clicked(bool)), SLOT(hide()));
+
+ m_button = new QPushButton(KIcon("insert-image"), i18n("Set to This Page"), this);
+ m_button->setMaximumWidth(250);
+ connect(m_button, SIGNAL(clicked(bool)), SLOT(clicked()));
+
+ // layout
+ QHBoxLayout *layout = new QHBoxLayout(this);
+ layout->addWidget(closeButton);
+ layout->addWidget(m_label);
+ layout->addWidget(m_button);
+
+ layout->setContentsMargins(2, 0, 2, 0);
+
+ setLayout(layout);
+}
+
+
+void PreviewSelectorBar::setPage(WebPage* page)
+{
+ m_page = page;
+ verifyUrl();
+}
+
+
+void PreviewSelectorBar::verifyUrl()
+{
+ if(m_page->mainFrame()->url().scheme() != "about")
+ {
+ m_button->setEnabled(true);
+ m_button->setToolTip("");
+ }
+ else
+ {
+ m_button->setEnabled(false);
+ m_button->setToolTip(i18n("You can not add this webpage as favorite"));
+ }
+}
+
+
+void PreviewSelectorBar::enable(int previewIndex, WebPage* page)
+{
+ if(m_page != 0)
+ disconnect(m_page, 0, this, 0);
+
+
+ setup();
+ m_previewIndex = previewIndex;
+ m_page = page;
+
+ verifyUrl();
+
+ show();
+
+ connect(page, SIGNAL(loadStarted()), SLOT(loadProgress()));
+ connect(page, SIGNAL(loadProgress(int)), SLOT(loadProgress()));
+ connect(page, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
+ connect(page->mainFrame(), SIGNAL(urlChanged(QUrl)), SLOT(verifyUrl()));
+}
+
+
+void PreviewSelectorBar::loadProgress()
+{
+ m_button->setEnabled(false);
+ m_button->setToolTip(i18n("Page is loading..."));
+}
+
+
+
+void PreviewSelectorBar::loadFinished()
+{
+ m_button->setEnabled(true);
+ m_button->setToolTip("");
+
+ verifyUrl();
+}
+
+
+void PreviewSelectorBar::clicked()
+{
+ KUrl url = m_page->mainFrame()->url();
+
+ WebSnap::savePreview(WebSnap::renderPreview(*m_page), url);
+
+ QStringList names = ReKonfig::previewNames();
+ QStringList urls = ReKonfig::previewUrls();
+
+ urls.replace(m_previewIndex, url.toMimeDataString());
+ names.replace(m_previewIndex, m_page->mainFrame()->title());
+
+ ReKonfig::setPreviewNames(names);
+ ReKonfig::setPreviewUrls(urls);
+
+ ReKonfig::self()->writeConfig();
+
+
+ m_page->mainFrame()->load(KUrl("about:favorites"));
+
+ hide();
+}
+
+
diff --git a/src/rekonqpage/previewselectorbar.h b/src/rekonqpage/previewselectorbar.h
new file mode 100644
index 00000000..aa011fe4
--- /dev/null
+++ b/src/rekonqpage/previewselectorbar.h
@@ -0,0 +1,60 @@
+/*
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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 3 of the License, or
+ (at your option) any later version.
+
+ 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 PREVIEWSELECTORBAR_H
+#define PREVIEWSELECTORBAR_H
+
+// Local Includes
+#include "webpage.h"
+
+// Qt Includes
+#include <QWidget>
+#include <QPushButton>
+#include <QLabel>
+
+class PreviewSelectorBar : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ PreviewSelectorBar(QWidget *parent = 0);
+
+ void setPage(WebPage *page);
+
+ public slots:
+ void enable(int previewIndex, WebPage *page);
+ void clicked();
+
+ void loadProgress();
+ void loadFinished();
+
+ void verifyUrl();
+
+ private:
+ void setup();
+
+ QPushButton *m_button;
+ QLabel *m_label;
+
+ int m_previewIndex;
+ WebPage *m_page;
+
+};
+
+#endif // PREVIEWSELECTORBAR_H
diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp
index adeba6ae..4d9765a2 100644
--- a/src/urlbar/urlbar.cpp
+++ b/src/urlbar/urlbar.cpp
@@ -148,7 +148,6 @@ void UrlBar::setUrl(const QUrl& url)
m_currentUrl = KUrl(url);
updateUrl();
}
-
}
diff --git a/src/webpage.cpp b/src/webpage.cpp
index b2bedffc..f2ea412d 100644
--- a/src/webpage.cpp
+++ b/src/webpage.cpp
@@ -118,6 +118,7 @@ bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &r
if (frame && m_protHandler.preHandling( request, frame ))
{
return false;
+
}
m_requestedUrl = request.url();
diff --git a/src/webpage.h b/src/webpage.h
index 9169ad60..c8ecc89a 100644
--- a/src/webpage.h
+++ b/src/webpage.h
@@ -32,8 +32,10 @@
#define WEBPAGE_H
+
// Local Includes
#include "protocolhandler.h"
+#include "newtabpage.h"
// KDE Includes
#include <KWebPage>
diff --git a/src/webpluginfactory.cpp b/src/webpluginfactory.cpp
index aec4e18d..ac18fece 100644
--- a/src/webpluginfactory.cpp
+++ b/src/webpluginfactory.cpp
@@ -32,7 +32,6 @@
#include "rekonq.h"
#include "application.h"
#include "mainwindow.h"
-#include "previewimage.h"
#include "clicktoflash.h"
// KDE Includes
@@ -65,27 +64,7 @@ QObject *WebPluginFactory::create(const QString &mimeType,
const QStringList &argumentValues) const
{
kDebug() << "loading mimeType: " << mimeType;
-
- if(mimeType == QString("application/image-preview") )
- {
- QString title;
- int number = -1;
- bool isFavorite = false;
-
- int i;
- i = argumentNames.indexOf( QString("title") );
- if(i > -1)
- title = argumentValues.at(i);
- i = argumentNames.indexOf( QString("isFavorite") );
- if(i > -1)
- isFavorite = true;
- i = argumentNames.indexOf( QString("index") );
- if(i > -1)
- number = argumentValues.at(i).toInt();
-
- return new PreviewImage(url, title, number, isFavorite);
- }
-
+
if(ReKonfig::pluginsEnabled() == 0) // plugins are enabled
{
kDebug() << "No plugins found for" << mimeType << ". Falling back to QtWebKit ones...";
@@ -112,10 +91,7 @@ QList<QWebPluginFactory::Plugin> WebPluginFactory::plugins() const
{
QList<KWebPluginFactory::Plugin> plugins = KWebPluginFactory::plugins();
- QWebPluginFactory::Plugin p;
- p.name = "application/image-preview";
- p.description = "plugin for embedding Web snapped images";
- plugins.append(p);
+ KWebPluginFactory::Plugin p;
p.name = "application/x-shockwave-flash";
p.description = "Plugin for flash animations";
diff --git a/src/websnap.cpp b/src/websnap.cpp
index 7dcbb836..11b70e9e 100644
--- a/src/websnap.cpp
+++ b/src/websnap.cpp
@@ -29,6 +29,9 @@
#include "websnap.h"
#include "websnap.moc"
+// Local Includes
+#include "newtabpage.h"
+
// KDE Includes
#include <KDebug>
#include <KStandardDirs>
@@ -42,14 +45,12 @@
#include <QFile>
-#define WIDTH 200
-#define HEIGHT 150
-
-
-WebSnap::WebSnap(const QUrl &url)
+WebSnap::WebSnap(const QUrl& url, QWebPage* originatingPage, int previewIndex)
: QObject()
{
m_url = url;
+ m_originatingPage = originatingPage;
+ m_previewIndex = previewIndex;
// this to not register websnap history
m_page.settings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, true);
@@ -84,17 +85,10 @@ QPixmap WebSnap::renderPreview(const QWebPage &page,int w, int h)
// find the best size
QSize size;
- if (page.viewportSize().width() && page.viewportSize().height())
- {
- size = page.viewportSize();
- }
- else
- {
- int width = page.mainFrame()->contentsSize().width();
- if (width < 640) width = 640;
- size = QSize(width,width*((0.0+h)/w));
- page.setViewportSize(size);
- }
+ int width = page.mainFrame()->contentsSize().width();
+ if (width < 640) width = 640;
+ size = QSize(width,width*((0.0+h)/w));
+ page.setViewportSize(size);
// create the page image
QImage pageImage = QImage(size, QImage::Format_ARGB32_Premultiplied);
@@ -115,17 +109,63 @@ QPixmap WebSnap::renderPreview(const QWebPage &page,int w, int h)
}
+void WebSnap::savePreview(QPixmap pm, KUrl url)
+{
+ kDebug() << "saving preview";
+ QFile::remove(fileForUrl(url).toLocalFile());
+ pm.save(fileForUrl(url).toLocalFile());
+}
+
+
+KUrl WebSnap::fileForUrl(KUrl url)
+{
+ QString filePath =
+ KStandardDirs::locateLocal("cache", QString("thumbs/") + WebSnap::guessNameFromUrl(url) + ".png", true);
+ return KUrl(filePath);
+}
+
+
+QString WebSnap::guessNameFromUrl(QUrl url)
+{
+ QString name = url.toString( QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash );
+
+ // TODO learn Regular Expressions :)
+ // and implement something better here..
+ name.remove('/');
+ name.remove('&');
+ name.remove('.');
+ name.remove('-');
+ name.remove('_');
+ name.remove('?');
+ name.remove('=');
+ name.remove('+');
+
+ return name;
+}
+
+
void WebSnap::saveResult(bool ok)
{
// crude error-checking
if (!ok)
{
kDebug() << "Error loading site..";
- return;
+ m_snapTitle = "Error...";
+ m_image = QPixmap();
}
-
- m_image = renderPreview(m_page, WIDTH, HEIGHT);
- emit finished();
+ else
+ {
+ m_image = renderPreview(m_page, WIDTH, HEIGHT);
+ m_snapTitle = m_page.mainFrame()->title();
+ }
+ QFile::remove(fileForUrl(m_url).toLocalFile());
+ m_image.save(fileForUrl(m_url).toLocalFile());
+
+ //m_originatingPage->mainFrame()->load(KUrl("about:preview/replace/" + QVariant(m_previewIndex).toString()));
+ NewTabPage p(m_originatingPage->mainFrame());
+ p.snapFinished(m_previewIndex, m_url, m_snapTitle);
+
+ deleteLater();
}
diff --git a/src/websnap.h b/src/websnap.h
index 6c5b4af9..e15c2dcf 100644
--- a/src/websnap.h
+++ b/src/websnap.h
@@ -37,6 +37,9 @@
#include <QImage>
#include <QWebPage>
+#define WIDTH 200
+#define HEIGHT 150
+
/**
* This class renders a site producing an image based
@@ -48,21 +51,25 @@ class WebSnap : public QObject
Q_OBJECT
public:
- WebSnap(const QUrl &url);
+ WebSnap(const QUrl &url, QWebPage *originatingPage, int previewIndex);
~WebSnap();
- QPixmap previewImage();
- static QPixmap renderPreview(const QWebPage &page, int w, int h);
+ QPixmap previewImage(); // TODO : remove
+
+ static QPixmap renderPreview(const QWebPage &page, int w = WIDTH, int h = HEIGHT);
+
+ static KUrl fileForUrl(KUrl url);
+
+ static QString guessNameFromUrl(QUrl url);
+
+ static void savePreview(QPixmap pm, KUrl url);
QString snapTitle();
QUrl snapUrl();
-signals:
- void finished();
-
private slots:
void load();
- void saveResult(bool ok);
+ void saveResult(bool ok = true);
private:
QWebPage m_page;
@@ -70,6 +77,9 @@ private:
QUrl m_url;
QString m_snapTitle;
+
+ QWebPage *m_originatingPage;
+ int m_previewIndex;
};
#endif // WEB_SNAP_H