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"
23 #include "queryparser.h"
24 #include "queryserviceclient.h"
26 #include <QtDBus/QDBusInterface>
27 #include <QtDBus/QDBusConnection>
28 #include <QtDBus/QDBusReply>
31 #include <QtCore/QList>
35 QueryClient::QueryClient( const QString
& query
, const QStringList
& rps
)
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
;
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",
59 // "org.kde.nepomuk.Query",
62 // SLOT( slotEntriesRemoved( const QStringList& ) ) ) );
63 // Q_ASSERT( QDBusConnection::sessionBus().connect( "org.kde.nepomuk.services.nepomukqueryservice",
65 // "org.kde.nepomuk.Query",
68 // SLOT( slotFinishedListing() ) ) );
69 // Q_ASSERT( QDBusConnection::sessionBus().connect( "org.kde.nepomuk.services.nepomukqueryservice",
71 // "org.kde.nepomuk.Query",
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();
93 for ( QHash
<QUrl
, Soprano::Node
>::const_iterator it
= rps
.constBegin();
94 it
!= rps
.constEnd(); ++it
) {
95 s
<< it
.key() << ": " << it
.value() << "; ";
102 void QueryClient::slotEntriesRemoved( const QList
<QUrl
>& l
)
104 QTextStream
s( stdout
);
105 s
<< "Entries removed: ";
106 foreach( const QUrl
& url
, l
) {
113 void QueryClient::slotFinishedListing()
115 QTextStream
s( stdout
);
116 s
<< "Finished listing" << endl
;
119 #include "queryclient.moc"