-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.cpp
292 lines (272 loc) · 8.92 KB
/
account.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/* $Id: account.cpp */
/*
* Copyright (C) 2012-2014 Dmytro Mishchenko <arkadiamail@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "account.h"
#include <QSettings>
#include <QDebug>
#include <QDataStream>
#include <QStringList>
Account::Account() :
displayName(""),
userId(""),
domain(""),
enabled(true),
realm(""),
authName(""),
userPassword(""),
sipRegister(false),
sipRegistrar(""),
regExpiry(300),
useOutboundProxy(false),
outbound(""),
publish(false),
transport("UDP"),
natKeepAlive(20),
allow_contact_rewrite(false),
allow_via_rewrite(true),
use_rfc5626(true),
no_stun(false),
srtp("disabled"),
srtpReq("TLS"),
caFile(""),
privKeyFile(""),
certFile(""),
zrtpEnabled(false),
pjSipAccId(-1),
regStatus(""),
regStatusText(""),
mwiStatus(false),
mwiNumNewMsg(0),
mwiNumOldMsg(0),
callRecAll(false),
callRecConf(false),
autoAnswer(false),
ringTone(0),
contactPlusReplace(""),
contactPrefix(""),
mwi(true),
vmNumber(""),
vmDTMF(""),
id(0)
{
}
Account::~Account()
{
}
void Account::loadSettings()
{
QSettings settings;
settings.beginGroup("Account/" + QString::number(id));
displayName = settings.value("displayName").toString();
userId = settings.value("userId").toString();
domain = settings.value("domain").toString();
enabled = settings.value("enabled").toBool();
realm = settings.value("realm", "").toString();
authName = settings.value("authName").toString();
userPassword = settings.value("userPassword").toString();
sipRegister = settings.value("sipRegister").toBool();
sipRegistrar = settings.value("sipRegistrar").toString();
regExpiry = settings.value("regExpiry", 300).toInt();
useOutboundProxy = settings.value("useOutboundProxy").toBool();
outbound = settings.value("outbound").toString();
publish = settings.value("publish").toBool();
transport = settings.value("transport", "UDP").toString();
natKeepAlive = settings.value("natKeepAlive", 15).toInt();
allow_contact_rewrite = settings.value("allow_contact_rewrite", false).toBool();
allow_via_rewrite = settings.value("allow_via_rewrite", true).toBool();
use_rfc5626 = settings.value("use_rfc5626", true).toBool();
no_stun = settings.value("no_stun", false).toBool();
srtp = settings.value("srtp", "disabled").toString();
srtpReq = settings.value("srtpReq", "TLS").toString();
zrtpEnabled = settings.value("zrtpEnabled").toBool();
callRecAll = settings.value("callRecAll", false).toBool();
callRecConf = settings.value("callRecConf", false).toBool();
autoAnswer = settings.value("autoAnswer", false).toBool();
ringTone = settings.value("ringTone", 0).toInt();
contactPlusReplace = settings.value("contactPlusReplace").toString();
contactPrefix = settings.value("contactPrefix").toString();
mwi = settings.value("mwi", true).toBool();
vmNumber = settings.value("vmNumber").toString();
vmDTMF = settings.value("vmDTMF").toString();
settings.endGroup();
}
void Account::saveSettings() const
{
QSettings settings;
settings.beginGroup("Account/" + QString::number(id));
settings.setValue("displayName", displayName);
settings.setValue("userId", userId);
settings.setValue("domain", domain);
settings.setValue("enabled", enabled);
settings.setValue("realm", realm);
settings.setValue("authName", authName);
settings.setValue("userPassword", userPassword);
settings.setValue("sipRegister", sipRegister);
settings.setValue("sipRegistrar", sipRegistrar);
settings.setValue("regExpiry", regExpiry);
settings.setValue("useOutboundProxy", useOutboundProxy);
settings.setValue("outbound", outbound);
settings.setValue("publish", publish);
settings.setValue("transport", transport);
settings.setValue("natKeepAlive", natKeepAlive);
settings.setValue("allow_contact_rewrite", allow_contact_rewrite);
settings.setValue("allow_via_rewrite", allow_via_rewrite);
settings.setValue("use_rfc5626", use_rfc5626);
settings.setValue("no_stun", no_stun);
settings.setValue("srtp", srtp);
settings.setValue("srtpReq", srtpReq);
settings.setValue("zrtpEnabled", zrtpEnabled);
settings.setValue("callRecAll", callRecAll);
settings.setValue("callRecConf", callRecConf);
settings.setValue("autoAnswer", autoAnswer);
settings.setValue("ringTone", ringTone);
settings.setValue("contactPlusReplace", contactPlusReplace);
settings.setValue("contactPrefix", contactPrefix);
settings.setValue("mwi", mwi);
settings.setValue("vmNumber", vmNumber);
settings.setValue("vmDTMF", vmDTMF);
settings.endGroup();
settings.sync();
}
void Account::remove() const
{
QSettings settings;
settings.beginGroup("Account/" + QString::number(id));
settings.remove("");
settings.endGroup();
settings.sync();
}
bool Account::active() const
{
if (enabled && !domain.isEmpty() && !userId.isEmpty()) {
return true;
}
return false;
}
QString Account::infoRegistration() const
{
if (regStatus.isEmpty()) {
return "";
}
QStringList rs;
rs << regStatus;
if (!regStatusText.isEmpty()) {
rs << "\n(" + regStatusText + ")";
}
return rs.join(" ");
}
QString Account::infoVoicemail() const
{
if (!mwiStatus) {
return "";
}
QStringList vmInfo;
vmInfo << QObject::tr("Voicemail:");
if (mwiNumNewMsg) {
vmInfo << QString::number(mwiNumNewMsg) << QObject::tr("new");
}
if (mwiNumOldMsg) {
vmInfo << QString::number(mwiNumOldMsg) << QObject::tr("old");
}
return vmInfo.join(" ");
}
// Return Account name suitable for displaying in dropdown lists
QString Account::name() const
{
if (userId.isEmpty() && domain.isEmpty())
return "nousername@nodomain";
else {
return userId + "@" + domain;
if (regStatus.isEmpty()) {
return userId + "@" + domain;
}
else {
QString nameStr = userId + "@" + domain;
nameStr += " (" + regStatus + ")";
if (mwiStatus) {
QStringList vmInfo;
vmInfo << "\n";
vmInfo << QObject::tr("Voicemail:");
if (mwiNumNewMsg) {
vmInfo << QString::number(mwiNumNewMsg) << QObject::tr("new");
}
if (mwiNumOldMsg) {
vmInfo << QString::number(mwiNumOldMsg) << QObject::tr("old");
}
nameStr += vmInfo.join(" ");
}
return nameStr;
}
}
}
QString Account::name(int maxLen) const
{
QString fullName = name();
int firstSpace = fullName.indexOf(' ');
if (firstSpace > 0 && firstSpace < maxLen) {
return fullName.left(firstSpace);
}
return fullName.left(maxLen);
}
QString Account::nameShort() const
{
#define ACCOUNT_NAME_MAX_LENGTH 15
#define ACCOUNT_NAME_LENGTH_DISPLAY 10
if (userId.isEmpty()) {
if (domain.isEmpty()) {
return "nousername";
}
else {
return domain;
}
}
else {
// Shorten very long names
if (userId.length() > ACCOUNT_NAME_MAX_LENGTH) {
QString name = userId.left(ACCOUNT_NAME_LENGTH_DISPLAY);
name.append("...");
return name;
}
return userId;
}
}
int Account::accId() const
{
return id;
}
void Account::setAccId(int accId)
{
id = accId;
}
QDebug operator<<(QDebug dbg, const Account &ac)
{
dbg.maybeSpace() << "AccId:" << ac.id << endl;
dbg.maybeSpace() << "DisplayName:" << ac.displayName << endl;
dbg.maybeSpace() << "UserId:" << ac.userId << endl;
dbg.maybeSpace() << "Domain:" << ac.domain << endl;
dbg.maybeSpace() << "Enabled:" << ac.enabled << endl;
dbg.maybeSpace() << "pjSipAccId:" << ac.pjSipAccId << endl;
dbg.maybeSpace() << "regStatus:" << ac.regStatus << endl;
if (!ac.regStatusText.isEmpty()) {
dbg.maybeSpace() << "regStatusText:" << ac.regStatusText << endl;
}
dbg.maybeSpace() << "MWI:" << ac.mwiStatus << ac.mwiNumNewMsg << ac.mwiNumOldMsg << endl;
dbg.maybeSpace() << "Transport:" << ac.transport << endl;
dbg.maybeSpace() << "Reg info:" << ac.regInfo;
return dbg.maybeSpace();
}