From 966f6f99a3a2e89f6974bfee05886b8499385992 Mon Sep 17 00:00:00 2001 From: Lionel Chauvin Date: Wed, 19 Jan 2011 22:25:03 +0100 Subject: Save downloaded images of opensearch suggestions like websnaps RB:100397 Reviewed by me ;) --- src/urlbar/listitem.cpp | 23 ++++++++++++++++------- src/urlbar/listitem.h | 3 +-- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index f7514f2a..1794233e 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -365,15 +365,23 @@ PreviewLabel::PreviewLabel(const QString &url, int width, int height, QWidget *p ImageLabel::ImageLabel(const QString &url, int width, int height, QWidget *parent) : QLabel(parent), - m_width(width), - m_height(height) + m_url(url) { setFixedSize(width, height); - KIO::TransferJob *job = KIO::get(KUrl(url), KIO::NoReload, KIO::HideProgressInfo); - connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)), - this, SLOT(slotData(KIO::Job*, const QByteArray&))); - connect(job, SIGNAL(result(KJob *)), - this, SLOT(slotResult(KJob *))); + if (WebSnap::existsImage(KUrl(url))) + { + QPixmap pix; + pix.load(WebSnap::imagePathFromUrl(url)); + setPixmap(pix); + } + else + { + KIO::TransferJob *job = KIO::get(KUrl(url), KIO::NoReload, KIO::HideProgressInfo); + connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)), + this, SLOT(slotData(KIO::Job*, const QByteArray&))); + connect(job, SIGNAL(result(KJob *)), + this, SLOT(slotResult(KJob *))); + } } @@ -390,6 +398,7 @@ void ImageLabel::slotResult(KJob *) if (!pix.loadFromData(m_data)) kDebug() << "error while loading image: "; setPixmap(pix); + pix.save(WebSnap::imagePathFromUrl(m_url), "PNG"); } diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index 30089ce9..0ad5ab38 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -254,8 +254,7 @@ public: ImageLabel(const QString &url, int width, int height, QWidget *parent); private: - int m_width; - int m_height; + QString m_url; QByteArray m_data; private slots: -- cgit v1.2.1