[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdeplasma-addons/plasma/sreich/youtube-runner] runners/youtube: add the icon engine, successfully l
From:       Shaun Reich <shaun.reich () kdemail ! net>
Date:       2012-02-26 18:43:06
Message-ID: 20120226184306.DD586A60B9 () git ! kde ! org
[Download RAW message or body]

Git commit 549e547cf48af858ea9fb1a188c6deceeea8cb0c by Shaun Reich.
Committed on 26/02/2012 at 19:29.
Pushed by sreich into branch 'plasma/sreich/youtube-runner'.

add the icon engine, successfully loads the qimage as an icon

thanks go to kdepepo/christopher feck

M  +1    -0    runners/youtube/CMakeLists.txt
A  +64   -0    runners/youtube/imageiconengine.cpp     [License: LGPL (v2)]
A  +39   -0    runners/youtube/imageiconengine.h     [License: LGPL (v2)]
M  +1    -1    runners/youtube/tubejob.cpp
M  +22   -19   runners/youtube/youtube.cpp

http://commits.kde.org/kdeplasma-addons/549e547cf48af858ea9fb1a188c6deceeea8cb0c

diff --git a/runners/youtube/CMakeLists.txt b/runners/youtube/CMakeLists.txt
index 999048e..584cc0e 100644
--- a/runners/youtube/CMakeLists.txt
+++ b/runners/youtube/CMakeLists.txt
@@ -1,4 +1,5 @@
 set(krunner_youtube_SRCS
+    imageiconengine.cpp
     youtube.cpp
     tubejob.cpp
 )
diff --git a/runners/youtube/imageiconengine.cpp \
b/runners/youtube/imageiconengine.cpp new file mode 100644
index 0000000..48b27a3
--- /dev/null
+++ b/runners/youtube/imageiconengine.cpp
@@ -0,0 +1,64 @@
+/*
+ *   Copyright (C) 2009 Christoph Feck <christoph@maxiom.de>
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Library General Public License version 2 as
+ *   published by the Free Software Foundation
+ *
+ *   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 Library General Public
+ *   License along with this program; if not, write to the
+ *   Free Software Foundation, Inc.,
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "imageiconengine.h"
+
+#include <QtGui/QApplication>
+#include <QtGui/QPainter>
+#include <QtGui/QStyle>
+#include <QtGui/QStyleOption>
+
+ImageIconEngine::ImageIconEngine(const QImage &image)
+    : m_image(image)
+{
+}
+
+ImageIconEngine::~ImageIconEngine()
+{
+}
+
+QSize ImageIconEngine::actualSize(const QSize &size, QIcon::Mode mode, QIcon::State \
state) +{
+    Q_UNUSED(mode);
+    Q_UNUSED(state);
+
+    return size;
+}
+
+void ImageIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, \
QIcon::State state) +{
+    painter->fillRect(rect, Qt::transparent);
+    QPixmap p = pixmap(rect.size(), mode, state);
+    QRect r = p.rect();
+    r.moveCenter(rect.center());
+    painter->drawPixmap(r, p);
+}
+
+QPixmap ImageIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State \
state) +{
+    Q_UNUSED(state);
+
+    QImage image = m_image;
+    if (size.isValid() && size != image.size()) {
+        image = image.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+    }
+
+    QStyleOption opt;
+    return QApplication::style()->generatedIconPixmap(mode, \
QPixmap::fromImage(image), &opt); +}
+
diff --git a/runners/youtube/imageiconengine.h b/runners/youtube/imageiconengine.h
new file mode 100644
index 0000000..a67ca42
--- /dev/null
+++ b/runners/youtube/imageiconengine.h
@@ -0,0 +1,39 @@
+/*
+ *   Copyright (C) 2009 Christoph Feck <christoph@maxiom.de>
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Library General Public License version 2 as
+ *   published by the Free Software Foundation
+ *
+ *   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 Library General Public
+ *   License along with this program; if not, write to the
+ *   Free Software Foundation, Inc.,
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef IMAGEICONENGINE_H
+#define IMAGEICONENGINE_H
+
+#include <QtGui/QIconEngineV2>
+#include <QtGui/QIcon>
+
+class ImageIconEngine : public QIconEngineV2
+{
+    public:
+        ImageIconEngine(const QImage &image);
+        ~ImageIconEngine();
+
+        QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
+        void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, \
QIcon::State state); +        QPixmap pixmap(const QSize &size, QIcon::Mode mode, \
QIcon::State state); +
+    private:
+        QImage m_image;
+};
+
+#endif
diff --git a/runners/youtube/tubejob.cpp b/runners/youtube/tubejob.cpp
index bf20042..3f14704 100644
--- a/runners/youtube/tubejob.cpp
+++ b/runners/youtube/tubejob.cpp
@@ -32,7 +32,7 @@ TubeJob::TubeJob(const QString& term)
 
     m_manager = new QNetworkAccessManager(this);
 
-    QNetworkRequest request = \
QNetworkRequest(QUrl("http://gdata.youtube.com/feeds/api/videos?max-results=3&alt=json&q=" \
+ term)); +    QNetworkRequest request = \
QNetworkRequest(QUrl("http://gdata.youtube.com/feeds/api/videos?max-results=15&alt=json&q=" \
+ term));  m_manager->get(request);
 
     connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, \
                SLOT(jobCompleted(QNetworkReply*)));
diff --git a/runners/youtube/youtube.cpp b/runners/youtube/youtube.cpp
index a4a87cc..61434ef 100644
--- a/runners/youtube/youtube.cpp
+++ b/runners/youtube/youtube.cpp
@@ -18,6 +18,7 @@
 
 #include "youtube.h"
 #include "tubejob.h"
+#include "imageiconengine.h"
 
 #include <KDebug>
 #include <KToolInvocation>
@@ -28,6 +29,7 @@
 #include <QtCore/QTimer>
 #include <QtCore/QWaitCondition>
 #include <QtCore/QEventLoop>
+#include <qfile.h>
 #include <QtGui/QIcon>
 #include <qjson/parser.h>
 #include <kde4/KDE/KRun>
@@ -114,42 +116,43 @@ void YouTube::parseJson(const QByteArray& data, \
Plasma::RunnerContext &context)  
         //FIXME: horrible horrible assumption
         const QString& thumbnail = \
thumbnailList.at(0).toMap().value("url").toString(); +//        const QString& \
thumbnail = "http://upload.wikimedia.org/wikipedia/commons/b/b2/WhiteCat.jpg";  \
kDebug() << "THUMBNAIL URL: " << thumbnail;  
         QEventLoop loop;
         m_thumbnailDownloader = new QNetworkAccessManager();
         connect(m_thumbnailDownloader, SIGNAL(finished(QNetworkReply*)), &loop, \
SLOT(quit()));  
-        QNetworkRequest request = QNetworkRequest(url);
+        QNetworkRequest request = QNetworkRequest(QUrl(thumbnail));
+
         QNetworkReply *reply= m_thumbnailDownloader->get(request);
         loop.exec();
 
-//        QPixmap pixmap;
- //       pixmap.loadFromData(reply->readAll());
-        QImage image;
-        image.fromData(reply->readAll());
-
-//        QIcon icon = QIcon(pixmap);
-
         Plasma::QueryMatch match(this);
         match.setType(Plasma::QueryMatch::PossibleMatch);
 
-//        match.setIcon(image);
-        //  match.setRelevance(1.0);
-        //  match.setIcon(m_icon);
+        kDebug() << "ERROR!!" << reply->error();
+
+        QByteArray data = reply->readAll();
+        kDebug() << "DATAAAA:" << data;
+
+        QFile file("SREICHTESTFIL");
+        file.open(QIODevice::ReadWrite | QIODevice::Text);
+        file.write(data);
+        file.close();
+
+        QImage image;
+//        Q_ASSERT(image.load("SREICHTESTFIL"));
+        Q_ASSERT(image.loadFromData(data));
+
+        QIcon icon(new ImageIconEngine(image));
+        match.setIcon(icon);
+
         match.setData(url);
         match.setText(QString(title + " on YouTube"));
 
         context.addMatch(term, match);
     }
-
-//    foreach (const QVariant& variant, related) {
-//        QVariantMap submap = variant.toMap();
-//
-//        kDebug() << "FirstURL:" << submap.value("FirstURL");
-//        kDebug() << "Text:" << submap.value("Text");
-//        kDebug() << "Icon:" << submap.value("Icon").toMap().value("URL");
-//    }
 }
 
 #include "youtube.moc"


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic