File: AppStreamConcurrentPool.h

package info (click to toggle)
plasma-discover 6.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,288 kB
  • sloc: cpp: 30,576; xml: 2,710; python: 311; sh: 5; makefile: 5
file content (70 lines) | stat: -rw-r--r-- 1,716 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 *   SPDX-FileCopyrightText: 2024 Aleix Pol Gonzalez <aleixpol@kde.org>
 *
 *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
 */

#pragma once

#include <QFuture>
#include <QMutex>
#include <QPointer>

#include <AppStreamQt/pool.h>

#include "discovercommon_export.h"

namespace AppStream
{

/**
 * Convenience façade class to have QtConcurrent-enabled pools
 */
class DISCOVERCOMMON_EXPORT ConcurrentPool : public QObject
{
    Q_OBJECT
public:
    /**
     * Tells which @p pool to use and in which thread pool the jobs will be run
     *
     * @param pool takes ownership
     * @param threadPool does not take ownership
     */
    void reset(AppStream::Pool *pool, QThreadPool *threadPool);

    QFuture<ComponentBox> search(const QString &term);

    QFuture<ComponentBox> components();

    QFuture<ComponentBox> componentsById(const QString &cid);

    QFuture<ComponentBox> componentsByProvided(Provided::Kind kind, const QString &item);

    QFuture<ComponentBox> componentsByKind(Component::Kind kind);

    QFuture<ComponentBox> componentsByCategories(const QStringList &categories);

    QFuture<ComponentBox> componentsByLaunchable(Launchable::Kind kind, const QString &value);

    QFuture<ComponentBox> componentsByExtends(const QString &extendedId);

    QFuture<ComponentBox> componentsByBundleId(Bundle::Kind kind, const QString &bundleId, bool matchPrefix);

    QString lastError();
    void loadAsync();

    AppStream::Pool *get() const
    {
        return m_pool.get();
    }

Q_SIGNALS:
    void loadFinished(bool success);

private:
    QMutex m_mutex;
    std::unique_ptr<AppStream::Pool> m_pool;
    QPointer<QThreadPool> m_threadPool;
};

}