1 | /* |
---|---|
2 | This file is part of the KDE Baloo Project |
3 | SPDX-FileCopyrightText: 2013 Vishesh Handa <me@vhanda.in> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
6 | */ |
7 | |
8 | #include "queryrunnable.h" |
9 | #include <QAtomicInt> |
10 | |
11 | using namespace Baloo; |
12 | |
13 | class BALOO_CORE_NO_EXPORT QueryRunnable::Private { |
14 | public: |
15 | Query m_query; |
16 | QAtomicInt m_stop; |
17 | |
18 | bool stopRequested() const { |
19 | return m_stop.loadRelaxed(); |
20 | } |
21 | |
22 | }; |
23 | |
24 | QueryRunnable::QueryRunnable(const Query& query, QObject* parent) |
25 | : QObject(parent) |
26 | , d(new Private) |
27 | { |
28 | d->m_query = query; |
29 | d->m_stop = false; |
30 | } |
31 | |
32 | QueryRunnable::~QueryRunnable() = default; |
33 | |
34 | void QueryRunnable::stop() |
35 | { |
36 | d->m_stop.storeRelaxed(newValue: true); |
37 | } |
38 | |
39 | void QueryRunnable::run() |
40 | { |
41 | ResultIterator it = d->m_query.exec(); |
42 | while (!d->stopRequested() && it.next()) { |
43 | Q_EMIT queryResult(queryRunnable: this, filePath: it.filePath()); |
44 | } |
45 | |
46 | Q_EMIT finished(queryRunnable: this); |
47 | } |
48 | |
49 | #include "moc_queryrunnable.cpp" |
50 |