summaryrefslogtreecommitdiff
path: root/src/websnap.cpp
diff options
context:
space:
mode:
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;
-}