[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdeplasma-addons/plasma/sreich/bing-runner] runners: add initial bing runner
From: Shaun Reich <shaun.reich () kdemail ! net>
Date: 2012-02-26 13:47:12
Message-ID: 20120226134712.B1E08A60A6 () git ! kde ! org
[Download RAW message or body]
Git commit 3c4951301fb384ee4c932fc333fec383e738f228 by Shaun Reich.
Committed on 26/02/2012 at 07:04.
Pushed by sreich into branch 'plasma/sreich/bing-runner'.
add initial bing runner
this is meant mostly for images i think. it looks like it has a nice
api. how ironic is this world that microsoft's search engine is the one
with the easiest and only non-limited by queries count api.
M +1 -0 runners/CMakeLists.txt
A +11 -0 runners/bing/CMakeLists.txt
A +2 -0 runners/bing/Messages.sh
A +155 -0 runners/bing/bing.cpp [License: LGPL (v2+)]
A +16 -0 runners/bing/bing.desktop
A +60 -0 runners/bing/bing.h [License: LGPL (v2+)]
http://commits.kde.org/kdeplasma-addons/3c4951301fb384ee4c932fc333fec383e738f228
diff --git a/runners/CMakeLists.txt b/runners/CMakeLists.txt
index 21418d2..fe52c8d 100644
--- a/runners/CMakeLists.txt
+++ b/runners/CMakeLists.txt
@@ -1,5 +1,6 @@
add_subdirectory(audioplayercontrol)
add_subdirectory(browserhistory)
+add_subdirectory(bing)
add_subdirectory(converter)
add_subdirectory(datetime)
add_subdirectory(duckduckgo)
diff --git a/runners/bing/CMakeLists.txt b/runners/bing/CMakeLists.txt
new file mode 100644
index 0000000..e615724
--- /dev/null
+++ b/runners/bing/CMakeLists.txt
@@ -0,0 +1,11 @@
+set(krunner_bing_SRCS
+ bing.cpp
+)
+
+kde4_add_plugin(krunner_bing ${krunner_bing_SRCS})
+target_link_libraries(krunner_bing ${KDE4_PLASMA_LIBS} ${KDE4_KIO_LIBS} \
${QJSON_LIBRARIES}) +
+install(TARGETS krunner_bing DESTINATION ${PLUGIN_INSTALL_DIR} )
+
+install(FILES bing.desktop DESTINATION ${SERVICES_INSTALL_DIR})
+
diff --git a/runners/bing/Messages.sh b/runners/bing/Messages.sh
new file mode 100755
index 0000000..def5058
--- /dev/null
+++ b/runners/bing/Messages.sh
@@ -0,0 +1,2 @@
+#! /usr/bin/env bash
+$XGETTEXT *.cpp -o $podir/plasma_runner_bing.pot
diff --git a/runners/bing/bing.cpp b/runners/bing/bing.cpp
new file mode 100644
index 0000000..c3a9334
--- /dev/null
+++ b/runners/bing/bing.cpp
@@ -0,0 +1,155 @@
+/******************************************************************************
+ * 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 "bing.h"
+
+#include <KDebug>
+#include <KToolInvocation>
+
+#include <QtCore/QTimer>
+#include <QtCore/QWaitCondition>
+#include <QtCore/QEventLoop>
+#include <qjson/parser.h>
+
+Bing::Bing(QObject *parent, const QVariantList& args)
+ : Plasma::AbstractRunner(parent, args)
+{
+ Q_UNUSED(args);
+ setObjectName(QLatin1String("Bing"));
+ setIgnoredTypes(Plasma::RunnerContext::FileSystem | \
Plasma::RunnerContext::Directory | Plasma::RunnerContext::NetworkLocation); +
+ Plasma::RunnerSyntax s(QLatin1String( ":q:" ), i18n("Finds Bing search matching \
:q:.")); + s.addExampleQuery(QLatin1String("bing :q:"));
+ addSyntax(s);
+
+ addSyntax(Plasma::RunnerSyntax(QLatin1String( "bing" ), i18n("Lists the search \
entries matching the query, using Bing search"))); + \
addSyntax(Plasma::RunnerSyntax(QLatin1String( "wolfram" ), i18n("Searches using \
Wolfram Alpha, powered by Bing"))); + \
addSyntax(Plasma::RunnerSyntax(QLatin1String( "define" ), i18n("Defines words using \
dictionaries, powered by Bing"))); + setSpeed(SlowSpeed);
+ setPriority(LowPriority);
+
+ qRegisterMetaType<Plasma::RunnerContext*>();
+
+ KUrl url;
+ const QString& appId = "";
+ url = "http://api.bing.net/json.aspx?" + "AppId=" + appId + "&Query=xbox" + \
"&Sources=Image" + "&Version=2.0" + "&Image.Count=10" + "&Image.Offset=0"; + // \
"http://api.bing.com/?q=define+ostensibly&format=json&pretty=1"); +
+ m_job = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo);
+ connect(m_job, SIGNAL(result(KJob*)), this, SLOT(jobFinished(KJob*)));
+ m_job->start();
+}
+
+Bing::~Bing()
+{
+}
+
+void Bing::match(Plasma::RunnerContext &context)
+{
+ kDebug() << "MATCH MADE, emitting matchmade";
+// connect(this, SIGNAL(matchMade(Plasma::RunnerContext*)), this, \
SLOT(startBingJob(Plasma::RunnerContext*))); + // emit matchMade(&context);
+
+ const QString term = context.query();
+ if (term.length() < 3) {
+ return;
+ }
+
+ if (!context.isValid()) {
+ return;
+ }
+}
+
+void Bing::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch \
&match) +{
+// Q_UNUSED(context)
+// const QString session = match.data().toString();
+// kDebug() << "Open Konsole Session " << session;
+//
+// if (!session.isEmpty()) {
+// QStringList args;
+// args << QLatin1String( "--profile" );
+// args << session;
+// kDebug() << "=== START: konsole" << args;
+// KToolInvocation::kdeinitExec(QLatin1String( "konsole" ), args);
+// }
+}
+
+void Bing::startBingJob(Plasma::RunnerContext *context)
+{
+
+ kDebug() << "%%%%%% RUNNING JOB!";
+}
+
+void Bing::dataArrived(KIO::Job* job, const QByteArray& data)
+{
+// kDebug() << "DATA:" << data;
+ if (!data.isEmpty()) {
+ buffer << data;
+// parseJson(data);
+ }
+// const QString term = context->query();
+// Plasma::QueryMatch match(this);
+// match.setType(Plasma::QueryMatch::PossibleMatch);
+//
+// // match.setRelevance(1.0);
+// // match.setIcon(m_icon);
+//// match.setData("TEST");
+// match.setText(QLatin1String( "Bing: " ));
+//
+// context->addMatch(term, match);
+
+}
+
+void Bing::jobFinished(KJob *job)
+{
+ parseJson(m_job->data());
+}
+
+void Bing::parseJson(const QByteArray& data)
+{
+ kDebug() << "JSON PARSER ONLINE";
+ QJson::Parser parser;
+ const QVariantMap resultsMap = parser.parse(data).toMap();
+
+ const QString& match = "bing";
+
+ if (match == "define") {
+ //dictionary mode
+ kDebug() << "Heading:" << resultsMap.value("Heading");
+ kDebug() << "AbstractSource:" << resultsMap.value("AbstractSource");
+ kDebug() << "Abstract:" << resultsMap.value("Abstract");
+ kDebug() << "AbstractURL:" << resultsMap.value("AbstractURL");
+ } else if (match == "wolfram") {
+ //wolfram mode (simple redirection, because web search providers are \
assholes) + kDebug() << "Redirect:" << resultsMap.value("Redirect");
+ } else if (match == "bing") {
+ QList<QVariant> related = resultsMap.value("RelatedTopics").toList();
+
+ 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 "bing.moc"
diff --git a/runners/bing/bing.desktop b/runners/bing/bing.desktop
new file mode 100644
index 0000000..70a74b7
--- /dev/null
+++ b/runners/bing/bing.desktop
@@ -0,0 +1,16 @@
+[Desktop Entry]
+Name=Bing
+
+Comment=Matches Bing queries
+
+Icon=
+
+X-KDE-ServiceTypes=Plasma/Runner
+Type=Service
+X-KDE-Library=krunner_bing
+X-KDE-PluginInfo-Author=Shaun M. Reich
+X-KDE-PluginInfo-Email=sreich@kde.org
+X-KDE-PluginInfo-Name=bing
+X-KDE-PluginInfo-Version=1.0
+X-KDE-PluginInfo-License=LGPL
+X-KDE-PluginInfo-EnabledByDefault=true
diff --git a/runners/bing/bing.h b/runners/bing/bing.h
new file mode 100644
index 0000000..29d8854
--- /dev/null
+++ b/runners/bing/bing.h
@@ -0,0 +1,60 @@
+/******************************************************************************
+ * 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 BING_H
+#define BING_H
+
+#include <Plasma/AbstractRunner>
+
+#include <Plasma/RunnerContext>
+
+#include <KIO/Job>
+
+#include <KUrl>
+#include <QDataStream>
+
+class Bing : public Plasma::AbstractRunner {
+ Q_OBJECT
+
+public:
+ Bing(QObject *parent, const QVariantList& args);
+ ~Bing();
+
+ void match(Plasma::RunnerContext &context);
+ void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match);
+
+Q_SIGNALS:
+ void matchMade(Plasma::RunnerContext *context);
+
+private slots:
+ void dataArrived(KIO::Job* job, const QByteArray& data);
+ void startBingJob(Plasma::RunnerContext *context);
+ void jobFinished(KJob* job);
+
+private:
+ void parseJson(const QByteArray& buffer);
+
+ QDataStream buffer;
+ KIO::StoredTransferJob *m_job;
+};
+
+Q_DECLARE_METATYPE(Plasma::RunnerContext*);
+
+K_EXPORT_PLASMA_RUNNER(bing, Bing)
+
+#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic