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

List:       kde-commits
Subject:    [kdeplasma-addons/plasma/sreich/youtube-runner] runners/youtube: use qnetworkaccessmanger, it actual
From:       Shaun Reich <shaun.reich () kdemail ! net>
Date:       2012-02-26 15:26:58
Message-ID: 20120226152658.AF259A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit f2c101100dd3e1d7e597488073465d1e370c2985 by Shaun Reich.
Committed on 26/02/2012 at 16:00.
Pushed by sreich into branch 'plasma/sreich/youtube-runner'.

use qnetworkaccessmanger, it actually works. unlike kio

A  +48   -0    runners/youtube/tubejob.cpp     [License: LGPL (v2+)]
A  +49   -0    runners/youtube/tubejob.h     [License: LGPL (v2+)]
M  +4    -1    runners/youtube/youtube.cpp

http://commits.kde.org/kdeplasma-addons/f2c101100dd3e1d7e597488073465d1e370c2985

diff --git a/runners/youtube/tubejob.cpp b/runners/youtube/tubejob.cpp
new file mode 100644
index 0000000..72dd860
--- /dev/null
+++ b/runners/youtube/tubejob.cpp
@@ -0,0 +1,48 @@
+/******************************************************************************
+ *  Copyright (C) 2012 by Shaun Reich <sreich@kde.org                         *
+ *                                                                            *
+ *  This library is free software; you can redistribute it and/or modify      *
+ *  it under the terms of the GNU Lesser General Public License as published  *
+ *  by the Free Software Foundation; either version 2 of the License or (at   *
+ *  your option) any later version.                                           *
+ *                                                                            *
+ *  This library 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         *
+ *  Library General Public License for more details.                          *
+ *                                                                            *
+ *  You should have received a copy of the GNU Lesser General Public License  *
+ *  along with this library; see the file COPYING.LIB.                        *
+ *  If not, see <http://www.gnu.org/licenses/>.                               *
+ *****************************************************************************/
+
+#include "tubejob.h"
+
+#include <KDebug>
+#include <KToolInvocation>
+
+#include <QNetworkAccessManager>
+#include <QNetworkReply>
+
+TubeJob::TubeJob(const QString& term)
+  : QObject()
+  , m_manager(0)
+{
+    kDebug() << "%%%%%% TubeJob ctor hit! QUERY TERM: " + term;
+
+    m_manager = new QNetworkAccessManager(this);
+
+    QNetworkRequest request = \
QNetworkRequest(QUrl("http://gdata.youtube.com/feeds/api/videos?max-results=1&q=" + \
term)); +    m_manager->get(request);
+
+    connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, \
SLOT(jobCompleted(QNetworkReply*))); +}
+
+void TubeJob::jobCompleted(QNetworkReply* reply)
+{
+    kDebug() << "JOBCOMPLETED, BYTE ARRAY: " << reply->readAll();
+//    kDebug() << "JOB FINISHED!!: " << m_job->data();
+    emit finished();
+}
+
+#include "tubejob.moc"
diff --git a/runners/youtube/tubejob.h b/runners/youtube/tubejob.h
new file mode 100644
index 0000000..27214a0
--- /dev/null
+++ b/runners/youtube/tubejob.h
@@ -0,0 +1,49 @@
+/******************************************************************************
+ *  Copyright (C) 2012 by Shaun Reich <sreich@kde.org>                        *
+ *                                                                            *
+ *  This library is free software; you can redistribute it and/or modify      *
+ *  it under the terms of the GNU Lesser General Public License as published  *
+ *  by the Free Software Foundation; either version 2 of the License or (at   *
+ *  your option) any later version.                                           *
+ *                                                                            *
+ *  This library 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         *
+ *  Library General Public License for more details.                          *
+ *                                                                            *
+ *  You should have received a copy of the GNU Lesser General Public License  *
+ *  along with this library; see the file COPYING.LIB.                        *
+ *  If not, see <http://www.gnu.org/licenses/>.                               *
+ *****************************************************************************/
+
+#ifndef TUBEJOB_H
+#define TUBEJOB_H
+
+#include <QObject>
+#include <KIO/Job>
+
+#include <KUrl>
+
+class QNetworkReply;
+class QNetworkAccessManager;
+
+class TubeJob : public QObject
+{
+    Q_OBJECT
+
+public:
+    TubeJob(const QString& term);
+
+    void start();
+
+private Q_SLOTS:
+    void jobCompleted(QNetworkReply *reply);
+
+Q_SIGNALS:
+    void finished();
+
+private:
+    QNetworkAccessManager *m_manager;
+};
+
+#endif
diff --git a/runners/youtube/youtube.cpp b/runners/youtube/youtube.cpp
index a1110ee..b59e355 100644
--- a/runners/youtube/youtube.cpp
+++ b/runners/youtube/youtube.cpp
@@ -51,9 +51,10 @@ YouTube::~YouTube()
 
 void YouTube::match(Plasma::RunnerContext &context)
 {
-    kDebug() << "MATCH MADE, emitting matchmade";
+    kDebug() << "YouTube Runner, MATCH MADE";
 
     const QString term = context.query();
+
     if (term.length() < 3) {
         return;
     }
@@ -62,6 +63,8 @@ void YouTube::match(Plasma::RunnerContext &context)
         return;
     }
 
+    kDebug() << "YouTube Runner, Sleeping for 1 seconds";
+
     QEventLoop loop;
     // Wait a second, we don't want to  query on every keypress
     QMutex mutex;


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

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