/
contactauthorizer.h
142 lines (123 loc) · 4.92 KB
/
contactauthorizer.h
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/******************************************************************************
**
** This file is part of commhistory-daemon.
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Reto Zingg <reto.zingg@nokia.com>
**
** This library is free software; you can redistribute it and/or modify it
** under the terms of the GNU Lesser General Public License version 2.1 as
** published by the Free Software Foundation.
**
** 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this library; if not, write to the Free Software Foundation, Inc.,
** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**
******************************************************************************/
#ifndef CONTACTAUTHORIZER_H
#define CONTACTAUTHORIZER_H
// Qt
#include <QObject>
#include <QHash>
// Tp
#include <TelepathyQt/Account>
#include <TelepathyQt/Contact>
#include <TelepathyQt/Connection>
#include <TelepathyQt/ContactManager>
class MNotification;
namespace RTComLogger
{
class Request {
public:
bool operator==(const Request& other) const
{
if (contact && other.contact
&& !contact->handle().isEmpty() && !other.contact->handle().isEmpty()
&& contact->handle().first() == other.contact->handle().first()) {
return true;
} else {
return false;
}
}
Request& operator=(const Request& other) {
if (this != &other) {
notificationId = other.notificationId;
contact = other.contact;
message = other.message;
filename = other.filename;
transactionId = other.transactionId;
}
return *this;
}
bool isValid() {return !contact.isNull();}
QString notificationId;
Tp::ContactPtr contact;
QString message;
QString filename;
QUuid transactionId;
};
typedef QList<Request> AuthRequests;
class ContactAuthorizer : public QObject
{
Q_OBJECT
public:
explicit ContactAuthorizer(const Tp::ConnectionPtr& connection,
const Tp::AccountPtr& account,
QObject *parent = 0);
virtual ~ContactAuthorizer();
private Q_SLOTS:
void slotShowAuthorizationDialog(const QString& contactId,
const QString& accountPath,
const QString& filename,
const QString& message,
const QString& transactionId,
const QString& unused);
void slotPresencePublicationRequested(const Tp::Contacts &contacts);
void slotContactsUpgraded(Tp::PendingOperation *);
void slotConnectionInvalidated(Tp::DBusProxy*,const QString&, const QString&);
void slotConnectionFeaturesReady(Tp::PendingOperation* op);
void slotAuthoriserQueryFinished(QDBusPendingCallWatcher*);
void slotDialogDismissed(const QString& dialogId, int result);
void slotAvatarDataChanged(const Tp::AvatarData &);
void slotAvatarTokenChanged(const QString& avatarToken);
void slotRequestContactsReady(Tp::PendingOperation* operation);
void slotAuthorizationAccepted(Tp::PendingOperation* operation);
void slotContactBlocked(Tp::PendingOperation* operation);
void slotConnectionStatusChanged(Tp::ConnectionStatus connectionStatus);
void slotPublishStateChanged(Tp::Contact::PresenceState state,
const QString &message);
private:
void listenToAuthorization(const Tp::ConnectionPtr& connection);
void requestAvatar(const Tp::ContactPtr& contact);
void queueAuthorization(const Tp::Contacts contacts,
AuthRequests& requestQueue);
void queueAuthorization(const Tp::ContactPtr& contact,
const QString& avatarFile);
void upgradeContacts(const Tp::Contacts& contacts);
void fireAuthorisationRequest();
void startBuddyAuthorizerUI(class Request& request);
void authorizeContact(const Tp::ContactPtr& contact);
void blockContact(const Tp::ContactPtr& contact);
void removeNotificationForOngoingRequest();
private:
Tp::ConnectionPtr m_connection;
Tp::AccountPtr m_account;
Tp::ContactManagerPtr m_pContactManager;
// ready to be fired auth., requests
AuthRequests m_authRequests;
// Published auth requests
AuthRequests m_publishedAuthRequests;
// some information is still being fetched
AuthRequests m_authRequestWaitingForAvatar;
// request that is handled at the moment
Request m_ongoingRequest;
bool m_requestTapped;
};
} // namespace RTComLogger
Q_DECLARE_METATYPE(RTComLogger::Request)
#endif // CONTACTAUTHORIZER_H