File: responsewaiter.h

package info (click to toggle)
kdeconnect 25.04.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,584 kB
  • sloc: cpp: 22,922; xml: 520; python: 92; sh: 25; makefile: 5
file content (68 lines) | stat: -rw-r--r-- 1,411 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
/**
 * SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
 *
 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
 */

#ifndef RESPONSE_WAITER_H
#define RESPONSE_WAITER_H

#include <QObject>
#include <QTimer>
#include <QVariant>

class QDBusPendingCall;
class QDBusPendingCallWatcher;

class DBusResponseWaiter : public QObject
{
    Q_OBJECT

public:
    static DBusResponseWaiter *instance();

    /// extract QDbusPendingCall from \p variant and blocks until completed
    Q_INVOKABLE QVariant waitForReply(QVariant variant) const;

    const QDBusPendingCall *extractPendingCall(QVariant &variant) const;

private:
    DBusResponseWaiter();

    static DBusResponseWaiter *m_instance;
    QList<int> m_registered;
};

class DBusAsyncResponse : public QObject
{
    Q_OBJECT
    Q_PROPERTY(bool autoDelete READ autodelete WRITE setAutodelete)

public:
    explicit DBusAsyncResponse(QObject *parent = nullptr);

    Q_INVOKABLE void setPendingCall(QVariant e);

    void setAutodelete(bool b)
    {
        m_autodelete = b;
    };
    bool autodelete() const
    {
        return m_autodelete;
    }

Q_SIGNALS:
    void success(const QVariant &result);
    void error(const QString &message);

private Q_SLOTS:
    void onCallFinished(QDBusPendingCallWatcher *watcher);
    void onTimeout();

private:
    QTimer m_timeout;
    bool m_autodelete;
};

#endif