2 Copyright (c) 2009 Volker Krause <vkrause@kde.org>
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 #include "messagesearch.h"
22 #include <akonadi/item.h>
23 #include <akonadi/linkjob.h>
25 #include <Nepomuk/ResourceManager>
28 #include <Soprano/QueryResultIterator>
29 #include <Soprano/StatementIterator>
30 #include <Soprano/Model>
32 MessageSearch::MessageSearch(const QString
& query
, const Akonadi::Collection
& destination
, QObject
* parent
) :
35 m_destination( destination
),
38 kDebug() << query
<< destination
;
40 foreach ( const QByteArray
&keyId
, listCryptoContainers() )
41 searchInContainer( keyId
);
45 void MessageSearch::searchInContainer(const QByteArray
& keyId
)
48 if ( !mountCryptoContainer( keyId
) ) {
49 kDebug() << "Unable to mount crypto container for key" << keyId
;
53 Q_ASSERT( !hasActiveCryptoModel() );
54 Soprano::Model
* model
= cryptoModel( keyId
);
57 #if 0 // Temporary debugging code, will need this again tomorrow
59 Soprano::StatementIterator it
= model
->listStatements();
60 foreach ( Soprano::Statement s
, it
.allStatements() )
61 kDebug() << "###" << s
.subject().toString() << s
.predicate().toString() << s
.object().toString();
65 Soprano::QueryResultIterator it
= model
->executeQuery( m_query
, Soprano::Query::QUERY_LANGUAGE_SPARQL
);
66 kDebug() << model
->lastError().message();
67 Akonadi::Item::List result
;
69 kDebug() << "Found:" << it
.binding( 0 ).toString();
70 Akonadi::Item item
= Akonadi::Item::fromUrl( KUrl( it
.binding( 0 ).toString() ) );
72 result
.append( item
);
77 Akonadi::LinkJob
*linkJob
= new Akonadi::LinkJob( m_destination
, result
, this );
78 connect( linkJob
, SIGNAL(result(KJob
*)), SLOT(linkResult(KJob
*)) );
82 unmountCryptoContainer();
83 Q_ASSERT( !hasActiveCryptoModel() );
86 void MessageSearch::linkResult(KJob
* job
)
89 kWarning() << job
->errorText();
93 void MessageSearch::ref()
98 void MessageSearch::deref()
101 if ( m_refCount
<= 0 )
105 #include "messagesearch.moc"