summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/previewimage.cpp49
-rw-r--r--src/previewimage.h57
-rw-r--r--src/webpluginfactory.cpp12
-rw-r--r--src/websnap.cpp94
-rw-r--r--src/websnap.h67
-rw-r--r--src/webview.h6
7 files changed, 273 insertions, 13 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4aa01913..c443de2e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,6 +2,7 @@
SET( rekonq_SRCS
homepage.cpp
+ previewimage.cpp
websnap.cpp
networkaccessmanager.cpp
autosaver.cpp
diff --git a/src/previewimage.cpp b/src/previewimage.cpp
new file mode 100644
index 00000000..300b7ee7
--- /dev/null
+++ b/src/previewimage.cpp
@@ -0,0 +1,49 @@
+/* ============================================================
+*
+* 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 <KUrl>
+#include <KStandardDirs>
+
+
+PreviewImage::PreviewImage(const KUrl &url, const QString &fileName)
+ : QLabel()
+ , m_url(url)
+ , m_fileName(fileName)
+{
+ QString path = KStandardDirs::locate("appdata", "pics/loading.mng"); //QString("thumbs/") + m_fileName, true);
+ setPixmap( QPixmap(path) );
+}
+
+
+PreviewImage::~PreviewImage()
+{
+}
+
+void PreviewImage::doItYourself()
+{
+}
diff --git a/src/previewimage.h b/src/previewimage.h
new file mode 100644
index 00000000..e0ee3aec
--- /dev/null
+++ b/src/previewimage.h
@@ -0,0 +1,57 @@
+/* ============================================================
+*
+* 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 <QLabel>
+#include <QImage>
+#include <KUrl>
+
+
+class PreviewImage : public QLabel
+{
+ Q_OBJECT
+
+public:
+ explicit PreviewImage(const KUrl &url, const QString &fileName);
+
+ PreviewImage(const PreviewImage &); // Q_DECLARE_METATYPE requires a copy-constructor
+
+ ~PreviewImage();
+
+public slots:
+ void doItYourself();
+
+private:
+ QPixmap m_pixmap;
+ KUrl m_url;
+ QString m_fileName;
+};
+// Q_DECLARE_METATYPE(PreviewImage)
+
+#endif // PREVIEW_IMAGE_H
diff --git a/src/webpluginfactory.cpp b/src/webpluginfactory.cpp
index 3754c03d..9ff0011d 100644
--- a/src/webpluginfactory.cpp
+++ b/src/webpluginfactory.cpp
@@ -28,15 +28,11 @@
#include "webpluginfactory.h"
#include "webpluginfactory.moc"
-#include "webview.h"
-#include "webpage.h"
-
-#include "websnap.h"
-
-#include <QWebFrame>
-
#include "application.h"
#include "mainwindow.h"
+#include "previewimage.h"
+
+#include <KDebug>
WebPluginFactory::WebPluginFactory(QObject *parent)
: QWebPluginFactory(parent)
@@ -66,7 +62,7 @@ QObject *WebPluginFactory::create(const QString &mimeType,
url = argumentValues.at(i);
++i;
}
- return new WebSnap(url,fileName);
+ return new PreviewImage(url,fileName);
}
kDebug() << "No plugins found for" << mimeType;
diff --git a/src/websnap.cpp b/src/websnap.cpp
new file mode 100644
index 00000000..4892d78f
--- /dev/null
+++ b/src/websnap.cpp
@@ -0,0 +1,94 @@
+/* ============================================================
+*
+* 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>
+
+
+#define WIDTH 200
+#define HEIGHT 150
+
+
+WebSnap::WebSnap(const KUrl &url, const QString &fileName)
+ : QObject()
+ , m_url(url)
+ , m_image(new QImage(WIDTH, HEIGHT, QImage::Format_ARGB32_Premultiplied))
+ , m_fileName(fileName)
+{
+ // this to not register websnap history
+ m_page.settings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, true);
+
+ m_targetSize = QSize(200, 150);
+ connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(saveResult(bool)));
+ QTimer::singleShot(0, this, SLOT(load()));
+}
+
+
+void WebSnap::load()
+{
+ m_page.mainFrame()->load(m_url);
+}
+
+
+void WebSnap::saveResult(bool ok)
+{
+ // crude error-checking
+ if (!ok)
+ {
+ kDebug() << "Error loading site..";
+ return;
+ }
+
+ // find proper size, we stick to sensible aspect ratio
+ QSize size = m_page.mainFrame()->contentsSize();
+ size.setHeight(size.width() * 150 / 200);
+
+ // create the target surface
+ 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, Qt::SmoothTransformation);
+
+ QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + m_fileName, true);
+ if( m_image->save(path) )
+ {
+ emit finished();
+ }
+}
diff --git a/src/websnap.h b/src/websnap.h
new file mode 100644
index 00000000..be2ad10b
--- /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 <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);
+
+ QImage *previewImage();
+
+signals:
+ void finished();
+
+private slots:
+ void load();
+ void saveResult(bool ok);
+
+private:
+ QWebPage m_page;
+ KUrl m_url;
+ QImage *m_image;
+ QString m_fileName;
+ QSize m_targetSize;
+};
+
+#endif // WEB_SNAP_H
diff --git a/src/webview.h b/src/webview.h
index 16b199ff..a132a193 100644
--- a/src/webview.h
+++ b/src/webview.h
@@ -45,10 +45,7 @@ class WebView : public QWebView
public:
explicit WebView(QWidget *parent = 0);
-
- // Q_DECLARE_METATYPE requires a copy-constructor
- WebView(const WebView &);
-
+
WebPage *page();
KUrl url() const;
QString lastStatusBarText() const;
@@ -85,6 +82,5 @@ private:
int m_progress;
QString m_statusBarText;
};
-Q_DECLARE_METATYPE(WebView)
#endif