-
Notifications
You must be signed in to change notification settings - Fork 0
/
addcontacttask.cpp
134 lines (100 loc) · 2.98 KB
/
addcontacttask.cpp
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
#include <kdebug.h>
#include <kopete/kopetemetacontact.h>
#include <kopete/kopetecontact.h>
#include "mrimaccount.h"
#include "debug.h"
#include "addcontacttask.h"
struct AddContactTask::Private {
QString groupName;
Kopete::MetaContact* m;
MrimAccount *account;
MRAProtocol *proto;
int groupId;
QString email;
QString nickName;
Private() : m(0), account(0), proto(0), groupId(0) {
}
};
AddContactTask::AddContactTask(MrimAccount *account)
: QObject(static_cast<QObject*>(account))
, d(new Private)
{
d->account = account;
d->proto = account->getMraProtocol();
}
AddContactTask::~AddContactTask() {
delete d;
}
void AddContactTask::setGroupName( const QString &groupName ) {
d->groupName = groupName;
}
void AddContactTask::setMetaContact( Kopete::MetaContact* m ) {
d->m = m;
}
void AddContactTask::setEmail( const QString &email ) {
d->email = email;
}
void AddContactTask::setNickName( const QString &nickName ) {
d->nickName = nickName;
}
void AddContactTask::run() {
mrimDebug() << __PRETTY_FUNCTION__;
if ( !d->m || d->groupName.isEmpty() ) {
mrimWarning() << "neither metacontact nor groupName is set";
return;
}
int gid = d->account->getGroupIdByName( d->groupName );
if ( gid == -1 ) {
d->proto->addGroupToContactList(d->groupName, this);
} else {
d->groupId = gid;
d->proto->addToContactList(
0,
d->groupId,
d->email,
d->nickName,
d->account->myself()->contactId(),
tr("Please, authorize me."),
this
);
}
}
void AddContactTask::runAddGroupWithoutContact() {
if ( d->groupName.isEmpty() ) {
mrimWarning() << "neither metacontact nor groupName is set";
return;
}
int gid = d->account->getGroupIdByName( d->groupName );
if ( gid == -1 ) {
d->proto->addGroupToContactList(d->groupName, this);
} else {
mrimDebug() << "the group " << d->groupName << " is already exists";
}
}
void AddContactTask::groupAddedSuccessfully() {
d->groupId = d->account->addGroupAndReturnId(d->groupName);
if ( d->nickName.isEmpty() ) {
mrimDebug() << "nickname is empty => return here";
return;
}
d->proto->addToContactList(
0,
d->groupId,
d->email,
d->nickName,
d->account->myself()->contactId(),
tr("Please, authorize me."),
this
);
}
void AddContactTask::groupAddFailed(int status) {
Q_UNUSED(status);
/// TODO: implement me
}
void AddContactTask::contactAddedSuccessfully() {
d->account->addContact(d->email, d->m, Kopete::Account::ChangeKABC);
}
void AddContactTask::contactAddFailed(int status) {
Q_UNUSED(status);
/// TODO: implement me
}