• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

xesamrunner.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright (C) 2007 Teemu Rytilahti <tpr@iki.fi>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License version 2 as
00006  *   published by the Free Software Foundation
00007  *
00008  *   This program is distributed in the hope that it will be useful,
00009  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *   GNU General Public License for more details
00012  *
00013  *   You should have received a copy of the GNU Library General Public
00014  *   License along with this program; if not, write to the
00015  *   Free Software Foundation, Inc.,
00016  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017  */
00018 
00019 #include "xesamrunner.h"
00020 
00021 #include <QDBusInterface>
00022 #include <QDBusReply>
00023 #include <QDBusMetaType>
00024 #include <QStringList>
00025 #include <QVector>
00026 
00027 #include <KDebug>
00028 #include <KMimeType>
00029 #include <KRun>
00030 #include <KUrl>
00031 #include <KIcon>
00032 
00033 Q_DECLARE_METATYPE(QList<QList<QVariant> >)
00034 static int typeId = qDBusRegisterMetaType<QList<QList<QVariant> > >();
00035 
00036 XesamRunner::XesamRunner(QObject *parent, const QVariantList& args)
00037     : Plasma::AbstractRunner(parent, args)
00038 {
00039     KGlobal::locale()->insertCatalog("krunner_xesam");
00040     Q_UNUSED(args);
00041     // set the name shown after the result in krunner window
00042     setObjectName(i18n("Desktop Search"));
00043     setSpeed(AbstractRunner::SlowSpeed);
00044 }
00045 
00046 XesamRunner::~XesamRunner()
00047 {
00048 }
00049 
00050 void XesamRunner::match(Plasma::RunnerContext &context)
00051 {
00052     if (context.query().length()<3) return;
00053 
00054     QDBusInterface xesam("org.freedesktop.xesam.searcher",
00055                          "/org/freedesktop/xesam/searcher/main");
00056 
00057     QDBusReply<QString> reply = xesam.call("NewSession");
00058     if (!reply.isValid()) return;
00059     
00060     QString session = reply;
00061     xesam.call("SetProperty", session, "hit.fields",
00062                QStringList() << "uri" << "dc:title");
00063 
00064     QString query = 
00065         "<?xml version='1.0' encoding='UTF-8'?>"
00066         "<request xmlns='http://freedesktop.org/standards/xesam/1.0/query'>"
00067         "<userQuery>%1</userQuery>"
00068         "</request>";
00069     QString userQuery = context.query();
00070 
00071     reply = xesam.call("NewSearch", session, query.arg(userQuery));
00072     if (!reply.isValid()) return;
00073 
00074     QString search = reply;
00075 
00076     QDBusReply<void> start_reply = xesam.call("StartSearch", search);
00077     if (!start_reply.isValid()) return;
00078 
00079     xesam.call("GetHitCount", search);
00080     QDBusReply<QList<QList<QVariant> > > hits_reply
00081         = xesam.call("GetHits", search, (quint32)10);
00082     if (!hits_reply.isValid()) return;
00083 
00084     QList<QList<QVariant> > hits = hits_reply;
00085 
00086     xesam.call("CloseSession", session);
00087 
00088     foreach (const QList<QVariant> &hit, hits) {
00089         if (hit.isEmpty()) continue;
00090 
00091         QString url = hit[0].toString();
00092 
00093         QString title;
00094         if (hit.size()>1) {
00095             title = hit[1].toString();
00096         } else {
00097             title = hit[0].toString();
00098         }
00099 
00100         Plasma::QueryMatch match(this);
00101         match.setType(Plasma::QueryMatch::PossibleMatch);
00102         match.setIcon(KIcon("text-x-generic"));
00103         match.setData(url);
00104         match.setText(title);
00105         match.setRelevance(1);
00106         context.addMatch(userQuery, match);
00107     }
00108 }
00109 
00110 void XesamRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
00111 {
00112     Q_UNUSED(context)
00113     QMutexLocker lock(bigLock());
00114     new KRun(KUrl(match.data().toString()), 0);
00115 }
00116 
00117 #include "xesamrunner.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal