add more spacing
[personal-kdebase.git] / runtime / nepomuk / services / queryservice / test / queryclient.cpp
blob86efed3e9eee5b1853adaa4640642a42fccc8074
1 /*
2 Copyright (c) 2008 Sebastian Trueg <trueg@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "queryclient.h"
20 #include "dbusoperators.h"
21 #include "result.h"
22 #include "query.h"
23 #include "queryparser.h"
24 #include "queryserviceclient.h"
26 #include <QtDBus/QDBusInterface>
27 #include <QtDBus/QDBusConnection>
28 #include <QtDBus/QDBusReply>
30 #include <QDebug>
31 #include <QtCore/QList>
35 QueryClient::QueryClient( const QString& query, const QStringList& rps )
36 : QObject()
38 m_client = new Nepomuk::Search::QueryServiceClient( this );
39 connect( m_client, SIGNAL( newEntries( const QList<Nepomuk::Search::Result>& ) ),
40 this, SLOT( slotNewEntries( const QList<Nepomuk::Search::Result>& ) ) );
41 connect( m_client, SIGNAL( entriesRemoved( const QList<QUrl>& ) ),
42 this, SLOT( slotEntriesRemoved( const QList<QUrl>& ) ) );
43 connect( m_client, SIGNAL( finishedListing() ),
44 this, SLOT( slotFinishedListing() ) );
46 Nepomuk::Search::Query q = Nepomuk::Search::QueryParser::parseQuery( query );
47 foreach( const QString& rp, rps ) {
48 q.addRequestProperty( QUrl( rp ) );
50 qDebug() << "parsed query:" << q;
52 m_client->query( q );
53 // QDBusInterface iface( "org.kde.nepomuk.services.nepomukqueryservice", "/nepomukqueryservice", "org.kde.nepomuk.Search" );
54 // QDBusReply<QDBusObjectPath> pathReply = iface.call( "query", QVariant::fromValue( q ) );
55 // QString path = pathReply.value().path();
56 // qDebug() << "Connecting to query object" << path;
57 // Q_ASSERT( QDBusConnection::sessionBus().connect( "org.kde.nepomuk.services.nepomukqueryservice",
58 // path,
59 // "org.kde.nepomuk.Query",
60 // "entriesRemoved",
61 // this,
62 // SLOT( slotEntriesRemoved( const QStringList& ) ) ) );
63 // Q_ASSERT( QDBusConnection::sessionBus().connect( "org.kde.nepomuk.services.nepomukqueryservice",
64 // path,
65 // "org.kde.nepomuk.Query",
66 // "finishedListing",
67 // this,
68 // SLOT( slotFinishedListing() ) ) );
69 // Q_ASSERT( QDBusConnection::sessionBus().connect( "org.kde.nepomuk.services.nepomukqueryservice",
70 // path,
71 // "org.kde.nepomuk.Query",
72 // "newEntries",
73 // this,
74 // SLOT( slotNewEntries( const QList<Nepomuk::Search::Result>& ) ) ) );
76 // QDBusInterface( "org.kde.nepomuk.services.nepomukqueryservice", path, "org.kde.nepomuk.Query" ).call( "list" );
80 QueryClient::~QueryClient()
85 void QueryClient::slotNewEntries( const QList<Nepomuk::Search::Result>& rl )
87 QTextStream s( stdout );
88 s << "New entries: " << endl;
89 foreach( const Nepomuk::Search::Result& r, rl ) {
90 s << " " << r.resourceUri().toString() << " (Score: " << r.score() << ")";
91 QHash<QUrl, Soprano::Node> rps = r.requestProperties();
92 s << " (";
93 for ( QHash<QUrl, Soprano::Node>::const_iterator it = rps.constBegin();
94 it != rps.constEnd(); ++it ) {
95 s << it.key() << ": " << it.value() << "; ";
97 s << ")" << endl;
102 void QueryClient::slotEntriesRemoved( const QList<QUrl>& l )
104 QTextStream s( stdout );
105 s << "Entries removed: ";
106 foreach( const QUrl& url, l ) {
107 s << url.toString();
109 s << endl;
113 void QueryClient::slotFinishedListing()
115 QTextStream s( stdout );
116 s << "Finished listing" << endl;
119 #include "queryclient.moc"