1 /*
2 * Copyright (C) 2013 Daniel Vrátil <dvratil@redhat.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 */
19
20 #include "pending-logger-search-impl.h"
21 #include "abstract-logger-plugin.h"
22
23 #include "debug.h"
24
PendingLoggerSearchImpl(const QString & term,QObject * parent)25 PendingLoggerSearchImpl::PendingLoggerSearchImpl(const QString& term, QObject* parent):
26 PendingLoggerSearch(term, parent)
27 {
28 if (plugins().isEmpty()) {
29 emitFinished();
30 return;
31 }
32
33 Q_FOREACH (KTp::AbstractLoggerPlugin *plugin, plugins()) {
34 PendingLoggerOperation *op = plugin->search(term);
35 if (!op) {
36 continue;
37 }
38
39 connect(op, SIGNAL(finished(KTp::PendingLoggerOperation*)),
40 this, SLOT(operationFinished(KTp::PendingLoggerOperation*)));
41 mRunningOps << op;
42 }
43 }
44
~PendingLoggerSearchImpl()45 PendingLoggerSearchImpl::~PendingLoggerSearchImpl()
46 {
47 }
48
operationFinished(KTp::PendingLoggerOperation * op)49 void PendingLoggerSearchImpl::operationFinished(KTp::PendingLoggerOperation *op)
50 {
51 Q_ASSERT(mRunningOps.contains(op));
52 mRunningOps.removeAll(op);
53
54 KTp::PendingLoggerSearch *operation = qobject_cast<KTp::PendingLoggerSearch*>(op);
55 Q_ASSERT(operation);
56
57 const QList<KTp::LogSearchHit> hits = operation->searchHits();
58 qCDebug(KTP_LOGGER) << "Plugin" << op->parent() << "returned" << hits.count() << "results";
59 appendSearchHits(hits);
60
61 if (mRunningOps.isEmpty()) {
62 emitFinished();
63 }
64 }
65