summaryrefslogtreecommitdiff
path: root/src/websnap.cpp
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-03-16 01:45:50 +0100
committerAndrea Diamantini <adjam7@gmail.com>2010-03-16 01:45:50 +0100
commitc4a3ac8eb53f109a3da1f53f279fc86edcb92597 (patch)
tree8ef689aac509629d33fce88c6b2ad31e8837285f /src/websnap.cpp
parentMerge commit 'refs/merge-requests/104' of git://gitorious.org/rekonq/mainline... (diff)
downloadrekonq-c4a3ac8eb53f109a3da1f53f279fc86edcb92597.tar.xz
First bunch of fixes for the NewTabPage + WebSnap chain.
It seems clear (to me) that they leaks memory, so they urgently need fixes. And a complete redesign. This is just a first (the easiest) part of it: - Removed some unuseful methods, - Added some documentation for the WebSnap class - Cleaned code, in general
Diffstat (limited to 'src/websnap.cpp')
-rw-r--r--src/websnap.cpp46
1 files changed, 17 insertions, 29 deletions
diff --git a/src/websnap.cpp b/src/websnap.cpp
index ceb24b4f..906bbc1e 100644
--- a/src/websnap.cpp
+++ b/src/websnap.cpp
@@ -60,15 +60,11 @@ WebSnap::WebSnap(const QUrl& url, QWebFrame *frame, int index)
m_page.settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(saveResult(bool)));
+
QTimer::singleShot(0, this, SLOT(load()));
}
-WebSnap::~WebSnap()
-{
-}
-
-
void WebSnap::load()
{
m_page.mainFrame()->load(m_url);
@@ -77,7 +73,7 @@ void WebSnap::load()
// NOTE please, be careful modifying this.
// You are playing with fire..
-QPixmap WebSnap::renderPreview(const QWebPage &page, int w, int h)
+QPixmap WebSnap::renderPreview(const QWebPage &page, int w, int h, bool save)
{
// prepare page
page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
@@ -87,7 +83,10 @@ QPixmap WebSnap::renderPreview(const QWebPage &page, int w, int h)
// find the best size
QSize size;
int width = page.mainFrame()->contentsSize().width();
- if (width < 640) width = 640;
+ if (width < 640)
+ {
+ width = 640;
+ }
size = QSize(width,width*((0.0+h)/w));
page.setViewportSize(size);
@@ -106,15 +105,16 @@ QPixmap WebSnap::renderPreview(const QWebPage &page, int w, int h)
page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAsNeeded);
page.setViewportSize(oldSize);
- return QPixmap::fromImage(pageImage);
-}
-
-
-void WebSnap::savePreview(QPixmap pm, KUrl url)
-{
- kDebug() << "saving preview";
- QFile::remove(fileForUrl(url).toLocalFile());
- pm.save(fileForUrl(url).toLocalFile());
+ QPixmap pm = QPixmap::fromImage(pageImage);
+ if(save)
+ {
+ KUrl url( page.mainFrame()->url() );
+ kDebug() << "saving preview";
+ QFile::remove( fileForUrl(url).toLocalFile() );
+ pm.save(fileForUrl(url).toLocalFile());
+ }
+
+ return pm;
}
@@ -164,7 +164,7 @@ void WebSnap::saveResult(bool ok)
NewTabPage p( m_frame );
p.snapFinished(m_previewIndex, m_url, m_snapTitle);
- deleteLater();
+ this->deleteLater();
}
@@ -172,15 +172,3 @@ QString WebSnap::snapTitle()
{
return m_page.mainFrame()->title();
}
-
-
-QUrl WebSnap::snapUrl()
-{
- return m_url;
-}
-
-
-QPixmap WebSnap::previewImage()
-{
- return m_image;
-}