aboutsummaryrefslogtreecommitdiff
path: root/src/base/QXmppPubSubSubscribeOptions.h
blob: 006eb9516d10e294ed5e37cae8fce7f2f8d896ad (plain) (blame)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * Copyright (C) 2008-2021 The QXmpp developers
 *
 * Author:
 *  Linus Jahn
 *
 * Source:
 *  https://github.com/qxmpp-project/qxmpp
 *
 * This file is a part of QXmpp library.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 */

#ifndef QXMPPPUBSUBSUBSCRIBEOPTIONS_H
#define QXMPPPUBSUBSUBSCRIBEOPTIONS_H

#include "QXmppDataForm.h"
#include "QXmppDataFormBase.h"
#include "QXmppGlobal.h"

#include <QFlags>
#include <QSharedDataPointer>

class QDateTime;
class QDomElement;
class QXmlStreamWriter;
class QXmppDataForm;
class QXmppPubSubSubscribeOptionsPrivate;

class QXMPP_EXPORT QXmppPubSubSubscribeOptions : public QXmppExtensibleDataFormBase
{
public:
    enum PresenceState : uint8_t {
        Unset = 0x00,
        Online = 0x01,
        Away = 0x02,
        Chat = 0x04,
        DoNotDisturb = 0x08,
        ExtendedAway = 0x10
    };
    Q_DECLARE_FLAGS(PresenceStates, PresenceState)
    static PresenceStates presenceStatesFromStringList(const QStringList &);
    static QStringList presenceStatesToStringList(PresenceStates);

    enum SubscriptionType : uint8_t {
        Items,
        Nodes
    };

    enum SubscriptionDepth : uint8_t {
        TopLevelOnly,
        Recursive
    };

    static std::optional<QXmppPubSubSubscribeOptions> fromDataForm(const QXmppDataForm &form);

    QXmppPubSubSubscribeOptions();
    QXmppPubSubSubscribeOptions(const QXmppPubSubSubscribeOptions &);
    virtual ~QXmppPubSubSubscribeOptions();

    QXmppPubSubSubscribeOptions &operator=(const QXmppPubSubSubscribeOptions &);

    std::optional<bool> notificationsEnabled() const;
    void setNotificationsEnabled(std::optional<bool> notifying);

    std::optional<bool> digestsEnabled() const;
    void setDigestsEnabled(std::optional<bool> digestsEnabled);

    std::optional<quint32> digestFrequencyMs() const;
    void setDigestFrequencyMs(std::optional<quint32> digestFrequencyMs);

    QDateTime expire() const;
    void setExpire(const QDateTime &expire);

    std::optional<bool> bodyIncluded() const;
    void setBodyIncluded(std::optional<bool> bodyIncluded);

    PresenceStates notificationRules() const;
    void setNotificationRules(PresenceStates notificationRules);

    std::optional<SubscriptionType> subscriptionType() const;
    void setSubscriptionType(std::optional<SubscriptionType> subscriptionType);

    std::optional<SubscriptionDepth> subscriptionDepth() const;
    void setSubscriptionDepth(std::optional<SubscriptionDepth> subscriptionDepth);

protected:
    QString formType() const override;
    bool parseField(const QXmppDataForm::Field &) override;
    void serializeForm(QXmppDataForm &) const override;

private:
    QSharedDataPointer<QXmppPubSubSubscribeOptionsPrivate> d;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppPubSubSubscribeOptions::PresenceStates)
Q_DECLARE_METATYPE(QXmppPubSubSubscribeOptions)

#endif  // QXMPPPUBSUBSUBSCRIBEOPTIONS_H