blob: 1aeeaa3aaa9755a308ea9561e3fd1c38f10ece71 [file] [log] [blame]
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -04001/*
2 * Copyright (C) 2015 Savoir-Faire Linux Inc.
3 * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Additional permission under GNU GPL version 3 section 7:
20 *
21 * If you modify this program, or any covered work, by linking or
22 * combining it with the OpenSSL project's OpenSSL library (or a
23 * modified version of that library), containing parts covered by the
24 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
25 * grants you additional permission to convey the resulting work.
26 * Corresponding Source for a non-source form of such a combination
27 * shall include the source code for the parts of OpenSSL used as well
28 * as that of the covered work.
29 */
30
31#include "accountadvancedtab.h"
32
33#include <gtk/gtk.h>
34#include <account.h>
35
36struct _AccountAdvancedTab
37{
38 GtkBox parent;
39};
40
41struct _AccountAdvancedTabClass
42{
43 GtkBoxClass parent_class;
44};
45
46typedef struct _AccountAdvancedTabPrivate AccountAdvancedTabPrivate;
47
48struct _AccountAdvancedTabPrivate
49{
50 Account *account;
51 GtkWidget *vbox_main;
52 GtkWidget *frame_registration;
Stepan Salenikovich2371a892015-07-23 17:17:00 -040053 GtkWidget *box_registration;
54 GtkWidget *box_registration_expire;
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -040055 GtkWidget *adjustment_registration_timeout;
Stepan Salenikovich2371a892015-07-23 17:17:00 -040056 GtkWidget *checkbutton_allow_incoming_unknown;
57 GtkWidget *checkbutton_allow_incoming_history;
58 GtkWidget *checkbutton_allow_incoming_contacts;
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -040059 GtkWidget *frame_network_interface;
60 GtkWidget *box_network_interface;
61 GtkWidget *checkbutton_use_random_port;
62 GtkWidget *box_local_port;
63 GtkWidget *adjustment_local_port;
64 GtkWidget *radiobutton_same_as_local;
65 GtkWidget *radiobutton_set_published;
66 GtkWidget *box_published_address_port;
67 GtkWidget *entry_published_address;
68 GtkWidget *spinbutton_published_port;
69 GtkWidget *adjustment_published_port;
70 GtkWidget *checkbutton_use_stun;
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -040071 GtkWidget *grid_stun;
72 GtkWidget *entry_stunserver;
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -040073 GtkWidget *checkbutton_use_turn;
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -040074 GtkWidget *grid_turn;
75 GtkWidget *entry_turnserver;
76 GtkWidget *entry_turnusername;
77 GtkWidget *entry_turnpassword;
78 GtkWidget *entry_turnrealm;
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -040079 GtkWidget *adjustment_audio_port_min;
80 GtkWidget *adjustment_audio_port_max;
81 GtkWidget *adjustment_video_port_min;
82 GtkWidget *adjustment_video_port_max;
83
84 QMetaObject::Connection account_updated;
85};
86
87G_DEFINE_TYPE_WITH_PRIVATE(AccountAdvancedTab, account_advanced_tab, GTK_TYPE_BOX);
88
89#define ACCOUNT_ADVANCED_TAB_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ACCOUNT_ADVANCED_TAB_TYPE, AccountAdvancedTabPrivate))
90
91static void
92account_advanced_tab_dispose(GObject *object)
93{
94 AccountAdvancedTab *view = ACCOUNT_ADVANCED_TAB(object);
95 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(view);
96
97 QObject::disconnect(priv->account_updated);
98
99 G_OBJECT_CLASS(account_advanced_tab_parent_class)->dispose(object);
100}
101
102static void
103account_advanced_tab_init(AccountAdvancedTab *view)
104{
105 gtk_widget_init_template(GTK_WIDGET(view));
106}
107
108static void
109account_advanced_tab_class_init(AccountAdvancedTabClass *klass)
110{
111 G_OBJECT_CLASS(klass)->dispose = account_advanced_tab_dispose;
112
113 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
114 "/cx/ring/RingGnome/accountadvancedtab.ui");
115
116 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, vbox_main);
117 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, frame_registration);
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400118 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, box_registration);
119 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, box_registration_expire);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400120 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_registration_timeout);
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400121 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, checkbutton_allow_incoming_unknown);
122 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, checkbutton_allow_incoming_history);
123 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, checkbutton_allow_incoming_contacts);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400124 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, frame_network_interface);
125 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, box_network_interface);
126 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, checkbutton_use_random_port);
127 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, box_local_port);
128 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_local_port);
129 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, radiobutton_same_as_local);
130 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, radiobutton_set_published);
131 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, box_published_address_port);
132 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, entry_published_address);
133 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, spinbutton_published_port);
134 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_published_port);
135 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, checkbutton_use_stun);
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400136 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, grid_stun);
137 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, entry_stunserver);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400138 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, checkbutton_use_turn);
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400139 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, grid_turn);
140 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, entry_turnserver);
141 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, entry_turnusername);
142 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, entry_turnpassword);
143 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, entry_turnrealm);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400144 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_audio_port_min);
145 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_audio_port_max);
146 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_video_port_min);
147 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_video_port_max);
148}
149
150static void
151registration_expire_changed(GtkAdjustment *adjustment, AccountAdvancedTab *self)
152{
153 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
154 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
155
156 int timeout = (int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
157 priv->account->setRegistrationExpire(timeout);
158}
159
160static void
161local_port_changed(GtkAdjustment *adjustment, AccountAdvancedTab *self)
162{
163 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
164 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
165
166 unsigned short int local_port = (unsigned short int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
167
168 if (priv->account->protocol() != Account::Protocol::RING) {
169 priv->account->setLocalPort(local_port);
170 } else {
171 priv->account->setBootstrapPort(local_port);
172 }
173}
174
175static void
176same_as_local_toggled(GtkToggleButton *toggle_button, AccountAdvancedTab *self)
177{
178 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
179 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
180
181 gboolean published_same_as_local = gtk_toggle_button_get_active(toggle_button);
182
183 priv->account->setPublishedSameAsLocal(published_same_as_local);
184
185 /* disactivate the published address and port fields if same as local is true */
186 gtk_widget_set_sensitive(priv->box_published_address_port, !published_same_as_local);
187}
188
189static void
190published_address_changed(GtkEntry *entry, AccountAdvancedTab *self)
191{
192 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
193 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
194
195 priv->account->setPublishedAddress(gtk_entry_get_text(entry));
196}
197
198static void
199published_port_changed(GtkAdjustment *adjustment, AccountAdvancedTab *self)
200{
201 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
202 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
203
204 unsigned short int published_port = (unsigned short int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
205 priv->account->setPublishedPort(published_port);
206}
207
208static void
209stun_enabled_toggled(GtkToggleButton *toggle_button, AccountAdvancedTab *self)
210{
211 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
212 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
213
214 gboolean use_stun = gtk_toggle_button_get_active(toggle_button);
215
216 priv->account->setSipStunEnabled(use_stun);
217
218 /* disactivate the stun server entry if stun is disabled */
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400219 gtk_widget_set_sensitive(priv->grid_stun, use_stun);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400220}
221
222static void
223stun_server_changed(GtkEntry *entry, AccountAdvancedTab *self)
224{
225 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
226 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
227
228 priv->account->setSipStunServer(gtk_entry_get_text(entry));
229}
230
231static void
232turn_enabled_toggled(GtkToggleButton *toggle_button, AccountAdvancedTab *self)
233{
234 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
235 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
236
237 gboolean use_turn = gtk_toggle_button_get_active(toggle_button);
238
239 priv->account->setTurnEnabled(use_turn);
240
241 /* disactivate the turn server entry if turn is disabled */
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400242 gtk_widget_set_sensitive(priv->grid_turn, use_turn);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400243}
244
245static void
246turn_server_changed(GtkEntry *entry, AccountAdvancedTab *self)
247{
248 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
249 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
250
251 priv->account->setTurnServer(gtk_entry_get_text(entry));
252}
253
254static void
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400255turn_serverusername_changed(GtkEntry *entry, AccountAdvancedTab *self)
256{
257 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
258 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
259
260 priv->account->setTurnServerUsername(gtk_entry_get_text(entry));
261}
262
263static void
264turn_serverpassword_changed(GtkEntry *entry, AccountAdvancedTab *self)
265{
266 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
267 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
268
269 priv->account->setTurnServerPassword(gtk_entry_get_text(entry));
270}
271
272static void
273turn_serverrealm_changed(GtkEntry *entry, AccountAdvancedTab *self)
274{
275 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
276 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
277
278 priv->account->setTurnServerRealm(gtk_entry_get_text(entry));
279}
280
281static void
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400282audio_port_min_changed(GtkAdjustment *adjustment, AccountAdvancedTab *self)
283{
284 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
285 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
286
287 int port = (int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
288 priv->account->setAudioPortMin(port);
289}
290
291static void
292audio_port_max_changed(GtkAdjustment *adjustment, AccountAdvancedTab *self)
293{
294 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
295 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
296
297 int port = (int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
298 priv->account->setAudioPortMax(port);
299}
300
301static void
302video_port_min_changed(GtkAdjustment *adjustment, AccountAdvancedTab *self)
303{
304 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
305 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
306
307 int port = (int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
308 priv->account->setVideoPortMin(port);
309}
310
311static void
312video_port_max_changed(GtkAdjustment *adjustment, AccountAdvancedTab *self)
313{
314 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
315 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
316
317 int port = (int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
318 priv->account->setVideoPortMax(port);
319}
320
321static void
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400322allow_from_unknown_toggled(GtkToggleButton *toggle_button, AccountAdvancedTab *self)
323{
324 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
325 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
326
327 gboolean allow = gtk_toggle_button_get_active(toggle_button);
328
329 priv->account->setAllowIncomingFromUnknown(allow);
330}
331
332static void
333allow_from_history_toggled(GtkToggleButton *toggle_button, AccountAdvancedTab *self)
334{
335 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
336 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
337
338 gboolean allow = gtk_toggle_button_get_active(toggle_button);
339
340 priv->account->setAllowIncomingFromHistory(allow);
341}
342
343static void
344allow_from_contacts_toggled(GtkToggleButton *toggle_button, AccountAdvancedTab *self)
345{
346 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
347 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
348
349 gboolean allow = gtk_toggle_button_get_active(toggle_button);
350
351 priv->account->setAllowIncomingFromContact(allow);
352}
353
354static void
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400355build_tab_view(AccountAdvancedTab *self)
356{
357 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
358 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
359
360 /* check if its ip2ip account */
361 const QByteArray& alias = priv->account->alias().toUtf8();
362
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400363 /* if account is IP2IP we don't need the registration box */
364 if (strcmp(alias.constData(), "IP2IP") == 0) {
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400365 gtk_container_remove(GTK_CONTAINER(priv->vbox_main), priv->frame_registration);
366 priv->frame_registration = NULL;
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400367 priv->box_registration = NULL;
368 priv->box_registration_expire = NULL;
369 priv->checkbutton_allow_incoming_unknown = NULL;
370 priv->checkbutton_allow_incoming_history = NULL;
371 priv->checkbutton_allow_incoming_contacts = NULL;
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400372 } else {
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400373 /* only show registration timeout for SIP account */
374 if (priv->account->protocol() != Account::Protocol::SIP) {
375 gtk_container_remove(GTK_CONTAINER(priv->box_registration), priv->box_registration_expire);
376 priv->box_registration_expire = NULL;
377 } else {
378 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_registration_timeout),
379 priv->account->registrationExpire());
380 g_signal_connect(priv->adjustment_registration_timeout,
381 "value-changed", G_CALLBACK(registration_expire_changed), self);
382 }
383
384 /* only show allow call options for Ring accounts */
385 if (priv->account->protocol() != Account::Protocol::RING) {
386 gtk_container_remove(GTK_CONTAINER(priv->box_registration), priv->checkbutton_allow_incoming_unknown);
387 priv->checkbutton_allow_incoming_unknown = NULL;
388 gtk_container_remove(GTK_CONTAINER(priv->box_registration), priv->checkbutton_allow_incoming_history);
389 priv->checkbutton_allow_incoming_history = NULL;
390 gtk_container_remove(GTK_CONTAINER(priv->box_registration), priv->checkbutton_allow_incoming_contacts);
391 priv->checkbutton_allow_incoming_contacts = NULL;
392 } else {
393 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_allow_incoming_unknown),
394 priv->account->allowIncomingFromUnknown());
395 g_signal_connect(priv->checkbutton_allow_incoming_unknown,
396 "toggled", G_CALLBACK(allow_from_unknown_toggled), self);
397 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_allow_incoming_history),
398 priv->account->allowIncomingFromHistory());
399 g_signal_connect(priv->checkbutton_allow_incoming_history,
400 "toggled", G_CALLBACK(allow_from_history_toggled), self);
401 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_allow_incoming_contacts),
402 priv->account->allowIncomingFromContact());
403 g_signal_connect(priv->checkbutton_allow_incoming_contacts,
404 "toggled", G_CALLBACK(allow_from_contacts_toggled), self);
405 }
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400406 }
407
408 /* local port */
409 if (priv->account->protocol() != Account::Protocol::RING) {
410 gtk_container_remove(GTK_CONTAINER(priv->box_network_interface), priv->checkbutton_use_random_port);
411 priv->checkbutton_use_random_port = NULL;
412 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_local_port),
413 priv->account->localPort());
414 g_signal_connect(priv->adjustment_local_port,
415 "value-changed", G_CALLBACK(local_port_changed), self);
416 } else {
417 /* TODO: when this option is added, for now just don't set it
418 * gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_local_port),
419 * priv->account->bootstrapPort());
420 */
421 gtk_container_remove(GTK_CONTAINER(priv->vbox_main), priv->frame_network_interface);
422 priv->frame_network_interface = NULL;
423 }
424
425 /* published address/port same as local */
426 if (priv->account->isPublishedSameAsLocal()) {
427 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->radiobutton_same_as_local), TRUE);
428
429 /* disactivate the published address and port fields if same as local is true */
430 gtk_widget_set_sensitive(priv->box_published_address_port, FALSE);
431 } else {
432 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->radiobutton_set_published), TRUE);
433 }
434
435 g_signal_connect(priv->radiobutton_same_as_local,
436 "toggled", G_CALLBACK(same_as_local_toggled), self);
437
438 /* published address and port */
439 gtk_entry_set_text(GTK_ENTRY(priv->entry_published_address),
440 priv->account->publishedAddress().toUtf8().constData());
441 g_signal_connect(priv->entry_published_address,
442 "changed", G_CALLBACK(published_address_changed), self);
443
444 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_published_port),
445 priv->account->publishedPort());
446 g_signal_connect(priv->adjustment_published_port,
447 "value-changed", G_CALLBACK(published_port_changed), self);
448
449 /* STUN */
450 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_use_stun),
451 priv->account->isSipStunEnabled());
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400452 gtk_entry_set_text(GTK_ENTRY(priv->entry_stunserver),
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400453 priv->account->sipStunServer().toUtf8().constData());
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400454 gtk_widget_set_sensitive(priv->grid_stun,
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400455 priv->account->isSipStunEnabled());
456 g_signal_connect(priv->checkbutton_use_stun,
457 "toggled", G_CALLBACK(stun_enabled_toggled), self);
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400458 g_signal_connect(priv->entry_stunserver,
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400459 "changed", G_CALLBACK(stun_server_changed), self);
460
461 /* TURN */
462 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_use_turn),
463 priv->account->isTurnEnabled());
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400464 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnserver),
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400465 priv->account->turnServer().toUtf8().constData());
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400466 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnusername),
467 priv->account->turnServerUsername().toUtf8().constData());
468 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnpassword),
469 priv->account->turnServerPassword().toUtf8().constData());
470 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnrealm),
471 priv->account->turnServerRealm().toUtf8().constData());
472 gtk_widget_set_sensitive(priv->grid_turn,
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400473 priv->account->isTurnEnabled());
474 g_signal_connect(priv->checkbutton_use_turn,
475 "toggled", G_CALLBACK(turn_enabled_toggled), self);
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400476 g_signal_connect(priv->entry_turnserver,
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400477 "changed", G_CALLBACK(turn_server_changed), self);
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400478 g_signal_connect(priv->entry_turnusername,
479 "changed", G_CALLBACK(turn_serverusername_changed), self);
480 g_signal_connect(priv->entry_turnpassword,
481 "changed", G_CALLBACK(turn_serverpassword_changed), self);
482 g_signal_connect(priv->entry_turnrealm,
483 "changed", G_CALLBACK(turn_serverrealm_changed), self);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400484
485 /* audio/video rtp port range */
486 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_audio_port_min),
487 priv->account->audioPortMin());
488 g_signal_connect(priv->adjustment_audio_port_min,
489 "value-changed", G_CALLBACK(audio_port_min_changed), self);
490 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_audio_port_max),
491 priv->account->audioPortMax());
492 g_signal_connect(priv->adjustment_audio_port_min,
493 "value-changed", G_CALLBACK(audio_port_max_changed), self);
494 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_video_port_min),
495 priv->account->videoPortMin());
496 g_signal_connect(priv->adjustment_audio_port_min,
497 "value-changed", G_CALLBACK(video_port_min_changed), self);
498 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_video_port_max),
499 priv->account->videoPortMax());
500 g_signal_connect(priv->adjustment_video_port_max,
501 "value-changed", G_CALLBACK(video_port_max_changed), self);
502
503 /* update account UI if model is updated */
504 priv->account_updated = QObject::connect(
505 priv->account,
506 &Account::changed,
507 [=] () {
508 /* only show registration timeout for SIP account */
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400509 if ( priv->box_registration_expire ) {
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400510 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_registration_timeout),
511 priv->account->registrationExpire());
512 }
513
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400514 if (priv->checkbutton_allow_incoming_unknown)
515 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_allow_incoming_unknown),
516 priv->account->allowIncomingFromUnknown());
517
518 if (priv->checkbutton_allow_incoming_history)
519 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_allow_incoming_history),
520 priv->account->allowIncomingFromHistory());
521
522 if (priv->checkbutton_allow_incoming_contacts)
523 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_allow_incoming_contacts),
524 priv->account->allowIncomingFromContact());
525
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400526 /* local port */
527 if (priv->account->protocol() != Account::Protocol::RING) {
528 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_local_port),
529 priv->account->localPort());
530 }
531
532 /* published address/port same as local */
533 if (priv->account->isPublishedSameAsLocal()) {
534 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->radiobutton_same_as_local), TRUE);
535 } else {
536 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->radiobutton_set_published), TRUE);
537 }
538
539 /* published address and port */
540 gtk_entry_set_text(GTK_ENTRY(priv->entry_published_address),
541 priv->account->publishedAddress().toUtf8().constData());
542 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_published_port),
543 priv->account->publishedPort());
544
545 /* STUN */
546 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_use_stun),
547 priv->account->isSipStunEnabled());
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400548 gtk_widget_set_sensitive(priv->grid_stun, priv->account->isSipStunEnabled());
549 gtk_entry_set_text(GTK_ENTRY(priv->entry_stunserver),
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400550 priv->account->sipStunServer().toUtf8().constData());
551
552 /* TURN */
553 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_use_turn),
554 priv->account->isTurnEnabled());
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400555 gtk_widget_set_sensitive(priv->grid_turn, priv->account->isTurnEnabled());
556 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnserver),
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400557 priv->account->turnServer().toUtf8().constData());
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400558 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnusername),
559 priv->account->turnServerUsername().toUtf8().constData());
560 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnpassword),
561 priv->account->turnServerPassword().toUtf8().constData());
562 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnrealm),
563 priv->account->turnServerRealm().toUtf8().constData());
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400564
565 /* audio/video rtp port range */
566 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_audio_port_min),
567 priv->account->audioPortMin());
568 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_audio_port_max),
569 priv->account->audioPortMax());
570 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_video_port_min),
571 priv->account->videoPortMin());
572 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_video_port_max),
573 priv->account->videoPortMax());
574 }
575 );
576}
577
578GtkWidget *
579account_advanced_tab_new(Account *account)
580{
581 g_return_val_if_fail(account != NULL, NULL);
582
583 gpointer view = g_object_new(ACCOUNT_ADVANCED_TAB_TYPE, NULL);
584
585 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(view);
586 priv->account = account;
587
588 build_tab_view(ACCOUNT_ADVANCED_TAB(view));
589
590 return (GtkWidget *)view;
591}