diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/homepage.cpp | 3 | ||||
-rw-r--r-- | src/previewimage.cpp | 15 | ||||
-rw-r--r-- | src/previewimage.h | 14 | ||||
-rw-r--r-- | src/webpluginfactory.cpp | 16 | ||||
-rw-r--r-- | src/websnap.cpp | 27 | ||||
-rw-r--r-- | src/websnap.h | 9 |
6 files changed, 44 insertions, 40 deletions
diff --git a/src/homepage.cpp b/src/homepage.cpp index 00f0611a..76c4f393 100644 --- a/src/homepage.cpp +++ b/src/homepage.cpp @@ -94,13 +94,10 @@ QString HomePage::speedDial() QString speed = QString(); for(int i = 0; i< urls.count(); ++i) { - QString pageName = QString("page") + QString::number(i); - speed += "<div class=\"thumbnail\">"; speed += "<a href=\"" + urls.at(i) + "\">"; speed += "<object type=\"application/image-preview\" width=\"200\">"; speed += "<param name=\"url\" value=\"" + urls.at(i) + "\">"; - speed += "<param name=\"fileName\" value=\"" + pageName + "\">"; speed += "</object>"; speed += "<br />"; speed += names.at(i) + "</a></div>"; diff --git a/src/previewimage.cpp b/src/previewimage.cpp index 300b7ee7..2d963171 100644 --- a/src/previewimage.cpp +++ b/src/previewimage.cpp @@ -28,22 +28,27 @@ #include <KUrl> #include <KStandardDirs> +#include <KDebug> - -PreviewImage::PreviewImage(const KUrl &url, const QString &fileName) +PreviewImage::PreviewImage(const QString &url) : QLabel() - , m_url(url) - , m_fileName(fileName) + , ws(0) { QString path = KStandardDirs::locate("appdata", "pics/loading.mng"); //QString("thumbs/") + m_fileName, true); setPixmap( QPixmap(path) ); + kDebug() << url; + ws = new WebSnap( KUrl(url) ); + connect(ws, SIGNAL(finished()), this, SLOT(setSiteImage())); } PreviewImage::~PreviewImage() { + kDebug() << "bye bye.."; } -void PreviewImage::doItYourself() +void PreviewImage::setSiteImage() { + kDebug() << "Done. works?"; + setPixmap( ws->previewImage() ); } diff --git a/src/previewimage.h b/src/previewimage.h index e0ee3aec..7cb6c00b 100644 --- a/src/previewimage.h +++ b/src/previewimage.h @@ -28,9 +28,10 @@ #define PREVIEW_IMAGE_H +#include "websnap.h" + #include <QLabel> #include <QImage> -#include <KUrl> class PreviewImage : public QLabel @@ -38,20 +39,17 @@ class PreviewImage : public QLabel Q_OBJECT public: - explicit PreviewImage(const KUrl &url, const QString &fileName); + PreviewImage(const QString &url); - PreviewImage(const PreviewImage &); // Q_DECLARE_METATYPE requires a copy-constructor - ~PreviewImage(); public slots: - void doItYourself(); + void setSiteImage(); private: QPixmap m_pixmap; - KUrl m_url; - QString m_fileName; + + WebSnap *ws; }; -// Q_DECLARE_METATYPE(PreviewImage) #endif // PREVIEW_IMAGE_H diff --git a/src/webpluginfactory.cpp b/src/webpluginfactory.cpp index 9ff0011d..9d7755c5 100644 --- a/src/webpluginfactory.cpp +++ b/src/webpluginfactory.cpp @@ -50,19 +50,17 @@ QObject *WebPluginFactory::create(const QString &mimeType, const QStringList &argumentNames, const QStringList &argumentValues) const { + kDebug() << "loading mimeType: " << mimeType; + if(mimeType == QString("application/image-preview") ) { - QString url, fileName; - int i = 0; - Q_FOREACH(const QString &key, argumentNames) + for(int i = 0; i<argumentNames.count(); ++i) { - if(key == QString("url")) - url = argumentValues.at(i); - if(key == QString("fileName")) - url = argumentValues.at(i); - ++i; + if(argumentNames.at(i) == QString("url")) + { + return new PreviewImage( argumentValues.at(i) ); + } } - return new PreviewImage(url,fileName); } kDebug() << "No plugins found for" << mimeType; diff --git a/src/websnap.cpp b/src/websnap.cpp index 4892d78f..349f2329 100644 --- a/src/websnap.cpp +++ b/src/websnap.cpp @@ -42,16 +42,13 @@ #define HEIGHT 150 -WebSnap::WebSnap(const KUrl &url, const QString &fileName) +WebSnap::WebSnap(const KUrl &url) : 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())); } @@ -59,6 +56,7 @@ WebSnap::WebSnap(const KUrl &url, const QString &fileName) void WebSnap::load() { + kDebug() << "loading.."; m_page.mainFrame()->load(m_url); } @@ -74,21 +72,30 @@ void WebSnap::saveResult(bool ok) // find proper size, we stick to sensible aspect ratio QSize size = m_page.mainFrame()->contentsSize(); - size.setHeight(size.width() * 150 / 200); + size.setHeight(size.width() * HEIGHT / WIDTH ); // create the target surface - m_image->fill(Qt::transparent); + m_image = QPixmap(WIDTH, HEIGHT); + m_image.fill(Qt::transparent); // render and rescale - QPainter p(m_image); + 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); + m_image = m_image.scaled(WIDTH, HEIGHT, Qt::KeepAspectRatioByExpanding); - QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + m_fileName, true); - if( m_image->save(path) ) + + QString path = KStandardDirs::locateLocal("cache", QString("thumbs/uno.png"), true); + if( m_image.save(path) ) { + kDebug() << "finished"; emit finished(); } } + + +QPixmap WebSnap::previewImage() +{ + return m_image; +} diff --git a/src/websnap.h b/src/websnap.h index be2ad10b..7e77da49 100644 --- a/src/websnap.h +++ b/src/websnap.h @@ -31,7 +31,7 @@ #include <KUrl> #include <QtCore/QObject> -#include <QImage> +#include <QPixmap> #include <QWebPage> @@ -45,9 +45,9 @@ class WebSnap : public QObject Q_OBJECT public: - WebSnap(const KUrl &url, const QString &fileName); + WebSnap(const KUrl &url); - QImage *previewImage(); + QPixmap previewImage(); signals: void finished(); @@ -59,9 +59,8 @@ private slots: private: QWebPage m_page; KUrl m_url; - QImage *m_image; + QPixmap m_image; QString m_fileName; - QSize m_targetSize; }; #endif // WEB_SNAP_H |