~phablet-team/telephony-service/qml-start-chat

« back to all changes in this revision

Viewing changes to libtelephonyservice/rolesinterface.h

Updated roles management using Roles interface client and events received from messaging framework.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2016 Canonical, Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *  Roberto Mier Escandon <roberto.escandon@canonical.com>
 
6
 *
 
7
 * This file is part of telephony-service.
 
8
 *
 
9
 * telephony-service is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU General Public License as published by
 
11
 * the Free Software Foundation; version 3.
 
12
 *
 
13
 * history-service is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
#ifndef CHANNELINTERFACEROLESINTERFACE_H
 
23
#define CHANNELINTERFACEROLESINTERFACE_H
 
24
 
 
25
#include <QMap>
 
26
 
 
27
#include <TelepathyQt/AbstractInterface>
 
28
#include <TelepathyQt/ChannelInterface>
 
29
 
 
30
/**
 
31
 * \struct HandleRolesMap
 
32
 * \ingroup mapping
 
33
 * \headerfile TelepathyQt/types.h <TelepathyQt/Types>
 
34
 *
 
35
 * Convertible with
 
36
 * QMap<uint, uint>, but needed to have a discrete type in the Qt type system.
 
37
 *
 
38
 * A map from channel-specific handles to their owners.
 
39
 */
 
40
struct HandleRolesMap : public QMap<uint, uint>
 
41
{
 
42
    inline HandleRolesMap() : QMap<uint, uint>() {}
 
43
    inline HandleRolesMap(const QMap<uint, uint>& a) : QMap<uint, uint>(a) {}
 
44
 
 
45
    inline HandleRolesMap& operator=(const QMap<uint, uint>& a)
 
46
    {
 
47
        *(static_cast<QMap<uint, uint>*>(this)) = a;
 
48
        return *this;
 
49
    }
 
50
};
 
51
 
 
52
Q_DECLARE_METATYPE(HandleRolesMap)
 
53
 
 
54
class ChannelInterfaceRolesInterface : public Tp::AbstractInterface
 
55
{
 
56
    Q_OBJECT
 
57
public:
 
58
 
 
59
    /**
 
60
     * Returns the name of the interface "org.freedesktop.Telepathy.Channel.Interface.Roles", which this class
 
61
     * represents.
 
62
     *
 
63
     * \return The D-Bus interface name.
 
64
     */
 
65
    static inline QLatin1String staticInterfaceName()
 
66
    {
 
67
        return QLatin1String("org.freedesktop.Telepathy.Channel.Interface.Roles");
 
68
    }
 
69
 
 
70
    /**
 
71
     * Creates a ChannelInterfaceRolesInterface associated with the given object on the session bus.
 
72
     *
 
73
     * \param busName Name of the service the object is on.
 
74
     * \param objectPath Path to the object on the service.
 
75
     * \param parent Passed to the parent class constructor.
 
76
     */
 
77
    ChannelInterfaceRolesInterface(
 
78
        const QString& busName,
 
79
        const QString& objectPath,
 
80
        QObject* parent = 0
 
81
    );
 
82
 
 
83
    /**
 
84
     * Creates a ChannelInterfaceRolesInterface associated with the given object on the given bus.
 
85
     *
 
86
     * \param connection The bus via which the object can be reached.
 
87
     * \param busName Name of the service the object is on.
 
88
     * \param objectPath Path to the object on the service.
 
89
     * \param parent Passed to the parent class constructor.
 
90
     */
 
91
    ChannelInterfaceRolesInterface(
 
92
        const QDBusConnection& connection,
 
93
        const QString& busName,
 
94
        const QString& objectPath,
 
95
        QObject* parent = 0
 
96
    );
 
97
 
 
98
    /**
 
99
     * Creates a ChannelInterfaceRolesInterface associated with the same object as the given proxy.
 
100
     *
 
101
     * \param proxy The proxy to use. It will also be the QObject::parent()
 
102
     *               for this object.
 
103
     */
 
104
    ChannelInterfaceRolesInterface(Tp::DBusProxy *proxy);
 
105
 
 
106
    /**
 
107
     * Creates a ChannelInterfaceRolesInterface associated with the same object as the given proxy.
 
108
     * Additionally, the created proxy will have the same parent as the given
 
109
     * proxy.
 
110
     *
 
111
     * \param mainInterface The proxy to use.
 
112
     */
 
113
    explicit ChannelInterfaceRolesInterface(const Tp::Client::ChannelInterface& mainInterface);
 
114
 
 
115
    /**
 
116
     * Creates a ChannelInterfaceRolesInterface associated with the same object as the given proxy.
 
117
     * However, a different parent object can be specified.
 
118
     *
 
119
     * \param mainInterface The proxy to use.
 
120
     * \param parent Passed to the parent class constructor.
 
121
     */
 
122
    ChannelInterfaceRolesInterface(const Tp::Client::ChannelInterface& mainInterface, QObject* parent);
 
123
 
 
124
    /**
 
125
     * Asynchronous getter for the remote object property \c Roles of type \c HandleRolesMap.
 
126
     *
 
127
     * \return A pending variant which will emit finished when the property has been
 
128
     *          retrieved.
 
129
     */
 
130
    inline Tp::PendingVariant *requestPropertyRoles() const
 
131
    {
 
132
        return internalRequestProperty(QLatin1String("Roles"));
 
133
    }
 
134
 
 
135
    /**
 
136
     * Asynchronous getter for the remote object property \c CanUpdateRoles of type \c bool.
 
137
     *
 
138
     * \return A pending variant which will emit finished when the property has been
 
139
     *          retrieved.
 
140
     */
 
141
    inline Tp::PendingVariant *requestPropertyCanUpdateRoles() const
 
142
    {
 
143
        return internalRequestProperty(QLatin1String("CanUpdateRoles"));
 
144
    }
 
145
 
 
146
    /**
 
147
     * Request all of the DBus properties on the interface.
 
148
     *
 
149
     * \return A pending variant map which will emit finished when the properties have
 
150
     *          been retrieved.
 
151
     */
 
152
    Tp::PendingVariantMap *requestAllProperties() const
 
153
    {
 
154
        return internalRequestAllProperties();
 
155
    }
 
156
 
 
157
    /**
 
158
     * Synchronous version to get Roles property
 
159
     */
 
160
    HandleRolesMap getRoles() const;
 
161
 
 
162
    /**
 
163
     * Synchronous version to get CanUpdateRoles property
 
164
     */
 
165
    bool getCanUpdateRoles() const;
 
166
 
 
167
public Q_SLOTS:
 
168
    /**
 
169
     * Begins a call to the D-Bus method \c UpdateRoles on the remote object.
 
170
     *
 
171
     * Update the roles in the server
 
172
     *
 
173
     */
 
174
    inline QDBusPendingReply<> UpdateRoles(const HandleRolesMap &contactRoles, int timeout = -1)
 
175
    {
 
176
        if (!invalidationReason().isEmpty()) {
 
177
            return QDBusPendingReply<>(QDBusMessage::createError(
 
178
                invalidationReason(),
 
179
                invalidationMessage()
 
180
            ));
 
181
        }
 
182
 
 
183
        QDBusMessage callMessage = QDBusMessage::createMethodCall(this->service(), this->path(),
 
184
                this->staticInterfaceName(), QLatin1String("UpdateRoles"));
 
185
        callMessage << QVariant::fromValue(contactRoles);
 
186
        return this->connection().asyncCall(callMessage, timeout);
 
187
    }
 
188
 
 
189
Q_SIGNALS:
 
190
    /**
 
191
     * Represents the signal \c RolesChanged on the remote object.
 
192
     *
 
193
     * Emitted when the state the roles of the channel has changed.
 
194
     *
 
195
     * \param added
 
196
     *
 
197
     *     map of handles and related roles added
 
198
     *
 
199
     * \param removed
 
200
     *
 
201
     *     map of handles and related roles removed
 
202
     */
 
203
     void RolesChanged(const HandleRolesMap &added, const HandleRolesMap& removed);
 
204
 
 
205
protected:
 
206
    virtual void invalidate(Tp::DBusProxy *, const QString &, const QString &);
 
207
 
 
208
};
 
209
 
 
210
#endif // CHANNELINTERFACEROLESINTERFACE_H