blob: 0faadd63937836393da48aa929e74b95ad53e321 [file] [log] [blame]
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -04001/*
Stepan Salenikovichbe87d2c2016-01-25 14:14:34 -05002 * Copyright (C) 2015-2016 Savoir-faire Linux Inc.
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -04003 * 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.
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -040018 */
19
20#include "accountadvancedtab.h"
21
22#include <gtk/gtk.h>
23#include <account.h>
24
25struct _AccountAdvancedTab
26{
27 GtkBox parent;
28};
29
30struct _AccountAdvancedTabClass
31{
32 GtkBoxClass parent_class;
33};
34
35typedef struct _AccountAdvancedTabPrivate AccountAdvancedTabPrivate;
36
37struct _AccountAdvancedTabPrivate
38{
39 Account *account;
40 GtkWidget *vbox_main;
41 GtkWidget *frame_registration;
Stepan Salenikovich2371a892015-07-23 17:17:00 -040042 GtkWidget *box_registration;
43 GtkWidget *box_registration_expire;
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -040044 GtkWidget *adjustment_registration_timeout;
Stepan Salenikovich2371a892015-07-23 17:17:00 -040045 GtkWidget *checkbutton_allow_incoming_unknown;
46 GtkWidget *checkbutton_allow_incoming_history;
47 GtkWidget *checkbutton_allow_incoming_contacts;
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -040048 GtkWidget *frame_network_interface;
49 GtkWidget *box_network_interface;
50 GtkWidget *checkbutton_use_random_port;
51 GtkWidget *box_local_port;
52 GtkWidget *adjustment_local_port;
53 GtkWidget *radiobutton_same_as_local;
54 GtkWidget *radiobutton_set_published;
55 GtkWidget *box_published_address_port;
56 GtkWidget *entry_published_address;
57 GtkWidget *spinbutton_published_port;
58 GtkWidget *adjustment_published_port;
59 GtkWidget *checkbutton_use_stun;
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -040060 GtkWidget *grid_stun;
61 GtkWidget *entry_stunserver;
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -040062 GtkWidget *checkbutton_use_turn;
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -040063 GtkWidget *grid_turn;
64 GtkWidget *entry_turnserver;
65 GtkWidget *entry_turnusername;
66 GtkWidget *entry_turnpassword;
67 GtkWidget *entry_turnrealm;
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -040068 GtkWidget *adjustment_audio_port_min;
69 GtkWidget *adjustment_audio_port_max;
70 GtkWidget *adjustment_video_port_min;
71 GtkWidget *adjustment_video_port_max;
72
73 QMetaObject::Connection account_updated;
74};
75
76G_DEFINE_TYPE_WITH_PRIVATE(AccountAdvancedTab, account_advanced_tab, GTK_TYPE_BOX);
77
78#define ACCOUNT_ADVANCED_TAB_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ACCOUNT_ADVANCED_TAB_TYPE, AccountAdvancedTabPrivate))
79
80static void
81account_advanced_tab_dispose(GObject *object)
82{
83 AccountAdvancedTab *view = ACCOUNT_ADVANCED_TAB(object);
84 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(view);
85
86 QObject::disconnect(priv->account_updated);
87
88 G_OBJECT_CLASS(account_advanced_tab_parent_class)->dispose(object);
89}
90
91static void
92account_advanced_tab_init(AccountAdvancedTab *view)
93{
94 gtk_widget_init_template(GTK_WIDGET(view));
95}
96
97static void
98account_advanced_tab_class_init(AccountAdvancedTabClass *klass)
99{
100 G_OBJECT_CLASS(klass)->dispose = account_advanced_tab_dispose;
101
102 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
103 "/cx/ring/RingGnome/accountadvancedtab.ui");
104
105 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, vbox_main);
106 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, frame_registration);
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400107 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, box_registration);
108 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, box_registration_expire);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400109 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_registration_timeout);
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400110 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, checkbutton_allow_incoming_unknown);
111 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, checkbutton_allow_incoming_history);
112 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, checkbutton_allow_incoming_contacts);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400113 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, frame_network_interface);
114 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, box_network_interface);
115 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, checkbutton_use_random_port);
116 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, box_local_port);
117 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_local_port);
118 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, radiobutton_same_as_local);
119 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, radiobutton_set_published);
120 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, box_published_address_port);
121 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, entry_published_address);
122 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, spinbutton_published_port);
123 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_published_port);
124 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, checkbutton_use_stun);
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400125 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, grid_stun);
126 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, entry_stunserver);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400127 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, checkbutton_use_turn);
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400128 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, grid_turn);
129 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, entry_turnserver);
130 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, entry_turnusername);
131 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, entry_turnpassword);
132 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, entry_turnrealm);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400133 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_audio_port_min);
134 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_audio_port_max);
135 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_video_port_min);
136 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_video_port_max);
137}
138
139static void
140registration_expire_changed(GtkAdjustment *adjustment, AccountAdvancedTab *self)
141{
142 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
143 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
144
145 int timeout = (int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
146 priv->account->setRegistrationExpire(timeout);
147}
148
149static void
150local_port_changed(GtkAdjustment *adjustment, AccountAdvancedTab *self)
151{
152 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
153 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
154
155 unsigned short int local_port = (unsigned short int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
156
157 if (priv->account->protocol() != Account::Protocol::RING) {
158 priv->account->setLocalPort(local_port);
159 } else {
160 priv->account->setBootstrapPort(local_port);
161 }
162}
163
164static void
165same_as_local_toggled(GtkToggleButton *toggle_button, AccountAdvancedTab *self)
166{
167 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
168 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
169
170 gboolean published_same_as_local = gtk_toggle_button_get_active(toggle_button);
171
172 priv->account->setPublishedSameAsLocal(published_same_as_local);
173
174 /* disactivate the published address and port fields if same as local is true */
175 gtk_widget_set_sensitive(priv->box_published_address_port, !published_same_as_local);
176}
177
178static void
179published_address_changed(GtkEntry *entry, AccountAdvancedTab *self)
180{
181 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
182 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
183
184 priv->account->setPublishedAddress(gtk_entry_get_text(entry));
185}
186
187static void
188published_port_changed(GtkAdjustment *adjustment, AccountAdvancedTab *self)
189{
190 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
191 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
192
193 unsigned short int published_port = (unsigned short int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
194 priv->account->setPublishedPort(published_port);
195}
196
197static void
198stun_enabled_toggled(GtkToggleButton *toggle_button, AccountAdvancedTab *self)
199{
200 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
201 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
202
203 gboolean use_stun = gtk_toggle_button_get_active(toggle_button);
204
205 priv->account->setSipStunEnabled(use_stun);
206
207 /* disactivate the stun server entry if stun is disabled */
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400208 gtk_widget_set_sensitive(priv->grid_stun, use_stun);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400209}
210
211static void
212stun_server_changed(GtkEntry *entry, AccountAdvancedTab *self)
213{
214 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
215 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
216
217 priv->account->setSipStunServer(gtk_entry_get_text(entry));
218}
219
220static void
221turn_enabled_toggled(GtkToggleButton *toggle_button, AccountAdvancedTab *self)
222{
223 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
224 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
225
226 gboolean use_turn = gtk_toggle_button_get_active(toggle_button);
227
228 priv->account->setTurnEnabled(use_turn);
229
230 /* disactivate the turn server entry if turn is disabled */
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400231 gtk_widget_set_sensitive(priv->grid_turn, use_turn);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400232}
233
234static void
235turn_server_changed(GtkEntry *entry, AccountAdvancedTab *self)
236{
237 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
238 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
239
240 priv->account->setTurnServer(gtk_entry_get_text(entry));
241}
242
243static void
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400244turn_serverusername_changed(GtkEntry *entry, AccountAdvancedTab *self)
245{
246 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
247 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
248
249 priv->account->setTurnServerUsername(gtk_entry_get_text(entry));
250}
251
252static void
253turn_serverpassword_changed(GtkEntry *entry, AccountAdvancedTab *self)
254{
255 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
256 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
257
258 priv->account->setTurnServerPassword(gtk_entry_get_text(entry));
259}
260
261static void
262turn_serverrealm_changed(GtkEntry *entry, AccountAdvancedTab *self)
263{
264 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
265 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
266
267 priv->account->setTurnServerRealm(gtk_entry_get_text(entry));
268}
269
270static void
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400271audio_port_min_changed(GtkAdjustment *adjustment, AccountAdvancedTab *self)
272{
273 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
274 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
275
276 int port = (int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
277 priv->account->setAudioPortMin(port);
278}
279
280static void
281audio_port_max_changed(GtkAdjustment *adjustment, AccountAdvancedTab *self)
282{
283 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
284 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
285
286 int port = (int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
287 priv->account->setAudioPortMax(port);
288}
289
290static void
291video_port_min_changed(GtkAdjustment *adjustment, AccountAdvancedTab *self)
292{
293 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
294 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
295
296 int port = (int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
297 priv->account->setVideoPortMin(port);
298}
299
300static void
301video_port_max_changed(GtkAdjustment *adjustment, AccountAdvancedTab *self)
302{
303 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
304 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
305
306 int port = (int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
307 priv->account->setVideoPortMax(port);
308}
309
310static void
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400311allow_from_unknown_toggled(GtkToggleButton *toggle_button, AccountAdvancedTab *self)
312{
313 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
314 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
315
316 gboolean allow = gtk_toggle_button_get_active(toggle_button);
317
318 priv->account->setAllowIncomingFromUnknown(allow);
319}
320
321static void
322allow_from_history_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->setAllowIncomingFromHistory(allow);
330}
331
332static void
333allow_from_contacts_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->setAllowIncomingFromContact(allow);
341}
342
343static void
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400344build_tab_view(AccountAdvancedTab *self)
345{
346 g_return_if_fail(IS_ACCOUNT_ADVANCED_TAB(self));
347 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(self);
348
Stepan Salenikovichfea84052016-05-13 16:32:51 -0400349 /* only show registration timeout for SIP account */
350 if (priv->account->protocol() != Account::Protocol::SIP) {
351 gtk_container_remove(GTK_CONTAINER(priv->box_registration), priv->box_registration_expire);
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400352 priv->box_registration_expire = NULL;
Stepan Salenikovichfea84052016-05-13 16:32:51 -0400353 } else {
354 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_registration_timeout),
355 priv->account->registrationExpire());
356 g_signal_connect(priv->adjustment_registration_timeout,
357 "value-changed", G_CALLBACK(registration_expire_changed), self);
358 }
359
360 /* only show allow call options for Ring accounts */
361 if (priv->account->protocol() != Account::Protocol::RING) {
362 gtk_container_remove(GTK_CONTAINER(priv->box_registration), priv->checkbutton_allow_incoming_unknown);
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400363 priv->checkbutton_allow_incoming_unknown = NULL;
Stepan Salenikovichfea84052016-05-13 16:32:51 -0400364 gtk_container_remove(GTK_CONTAINER(priv->box_registration), priv->checkbutton_allow_incoming_history);
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400365 priv->checkbutton_allow_incoming_history = NULL;
Stepan Salenikovichfea84052016-05-13 16:32:51 -0400366 gtk_container_remove(GTK_CONTAINER(priv->box_registration), priv->checkbutton_allow_incoming_contacts);
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400367 priv->checkbutton_allow_incoming_contacts = NULL;
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400368 } else {
Stepan Salenikovichfea84052016-05-13 16:32:51 -0400369 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_allow_incoming_unknown),
370 priv->account->allowIncomingFromUnknown());
371 g_signal_connect(priv->checkbutton_allow_incoming_unknown,
372 "toggled", G_CALLBACK(allow_from_unknown_toggled), self);
373 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_allow_incoming_history),
374 priv->account->allowIncomingFromHistory());
375 g_signal_connect(priv->checkbutton_allow_incoming_history,
376 "toggled", G_CALLBACK(allow_from_history_toggled), self);
377 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_allow_incoming_contacts),
378 priv->account->allowIncomingFromContact());
379 g_signal_connect(priv->checkbutton_allow_incoming_contacts,
380 "toggled", G_CALLBACK(allow_from_contacts_toggled), self);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400381 }
382
383 /* local port */
384 if (priv->account->protocol() != Account::Protocol::RING) {
385 gtk_container_remove(GTK_CONTAINER(priv->box_network_interface), priv->checkbutton_use_random_port);
386 priv->checkbutton_use_random_port = NULL;
387 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_local_port),
388 priv->account->localPort());
389 g_signal_connect(priv->adjustment_local_port,
390 "value-changed", G_CALLBACK(local_port_changed), self);
391 } else {
392 /* TODO: when this option is added, for now just don't set it
393 * gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_local_port),
394 * priv->account->bootstrapPort());
395 */
396 gtk_container_remove(GTK_CONTAINER(priv->vbox_main), priv->frame_network_interface);
397 priv->frame_network_interface = NULL;
398 }
399
400 /* published address/port same as local */
401 if (priv->account->isPublishedSameAsLocal()) {
402 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->radiobutton_same_as_local), TRUE);
403
404 /* disactivate the published address and port fields if same as local is true */
405 gtk_widget_set_sensitive(priv->box_published_address_port, FALSE);
406 } else {
407 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->radiobutton_set_published), TRUE);
408 }
409
410 g_signal_connect(priv->radiobutton_same_as_local,
411 "toggled", G_CALLBACK(same_as_local_toggled), self);
412
413 /* published address and port */
414 gtk_entry_set_text(GTK_ENTRY(priv->entry_published_address),
415 priv->account->publishedAddress().toUtf8().constData());
416 g_signal_connect(priv->entry_published_address,
417 "changed", G_CALLBACK(published_address_changed), self);
418
419 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_published_port),
420 priv->account->publishedPort());
421 g_signal_connect(priv->adjustment_published_port,
422 "value-changed", G_CALLBACK(published_port_changed), self);
423
424 /* STUN */
425 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_use_stun),
426 priv->account->isSipStunEnabled());
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400427 gtk_entry_set_text(GTK_ENTRY(priv->entry_stunserver),
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400428 priv->account->sipStunServer().toUtf8().constData());
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400429 gtk_widget_set_sensitive(priv->grid_stun,
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400430 priv->account->isSipStunEnabled());
431 g_signal_connect(priv->checkbutton_use_stun,
432 "toggled", G_CALLBACK(stun_enabled_toggled), self);
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400433 g_signal_connect(priv->entry_stunserver,
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400434 "changed", G_CALLBACK(stun_server_changed), self);
435
436 /* TURN */
437 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_use_turn),
438 priv->account->isTurnEnabled());
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400439 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnserver),
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400440 priv->account->turnServer().toUtf8().constData());
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400441 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnusername),
442 priv->account->turnServerUsername().toUtf8().constData());
443 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnpassword),
444 priv->account->turnServerPassword().toUtf8().constData());
445 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnrealm),
446 priv->account->turnServerRealm().toUtf8().constData());
447 gtk_widget_set_sensitive(priv->grid_turn,
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400448 priv->account->isTurnEnabled());
449 g_signal_connect(priv->checkbutton_use_turn,
450 "toggled", G_CALLBACK(turn_enabled_toggled), self);
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400451 g_signal_connect(priv->entry_turnserver,
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400452 "changed", G_CALLBACK(turn_server_changed), self);
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400453 g_signal_connect(priv->entry_turnusername,
454 "changed", G_CALLBACK(turn_serverusername_changed), self);
455 g_signal_connect(priv->entry_turnpassword,
456 "changed", G_CALLBACK(turn_serverpassword_changed), self);
457 g_signal_connect(priv->entry_turnrealm,
458 "changed", G_CALLBACK(turn_serverrealm_changed), self);
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400459
460 /* audio/video rtp port range */
461 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_audio_port_min),
462 priv->account->audioPortMin());
463 g_signal_connect(priv->adjustment_audio_port_min,
464 "value-changed", G_CALLBACK(audio_port_min_changed), self);
465 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_audio_port_max),
466 priv->account->audioPortMax());
467 g_signal_connect(priv->adjustment_audio_port_min,
468 "value-changed", G_CALLBACK(audio_port_max_changed), self);
469 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_video_port_min),
470 priv->account->videoPortMin());
471 g_signal_connect(priv->adjustment_audio_port_min,
472 "value-changed", G_CALLBACK(video_port_min_changed), self);
473 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_video_port_max),
474 priv->account->videoPortMax());
475 g_signal_connect(priv->adjustment_video_port_max,
476 "value-changed", G_CALLBACK(video_port_max_changed), self);
477
478 /* update account UI if model is updated */
479 priv->account_updated = QObject::connect(
480 priv->account,
481 &Account::changed,
482 [=] () {
483 /* only show registration timeout for SIP account */
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400484 if ( priv->box_registration_expire ) {
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400485 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_registration_timeout),
486 priv->account->registrationExpire());
487 }
488
Stepan Salenikovich2371a892015-07-23 17:17:00 -0400489 if (priv->checkbutton_allow_incoming_unknown)
490 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_allow_incoming_unknown),
491 priv->account->allowIncomingFromUnknown());
492
493 if (priv->checkbutton_allow_incoming_history)
494 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_allow_incoming_history),
495 priv->account->allowIncomingFromHistory());
496
497 if (priv->checkbutton_allow_incoming_contacts)
498 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_allow_incoming_contacts),
499 priv->account->allowIncomingFromContact());
500
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400501 /* local port */
502 if (priv->account->protocol() != Account::Protocol::RING) {
503 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_local_port),
504 priv->account->localPort());
505 }
506
507 /* published address/port same as local */
508 if (priv->account->isPublishedSameAsLocal()) {
509 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->radiobutton_same_as_local), TRUE);
510 } else {
511 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->radiobutton_set_published), TRUE);
512 }
513
514 /* published address and port */
515 gtk_entry_set_text(GTK_ENTRY(priv->entry_published_address),
516 priv->account->publishedAddress().toUtf8().constData());
517 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_published_port),
518 priv->account->publishedPort());
519
520 /* STUN */
521 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_use_stun),
522 priv->account->isSipStunEnabled());
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400523 gtk_widget_set_sensitive(priv->grid_stun, priv->account->isSipStunEnabled());
524 gtk_entry_set_text(GTK_ENTRY(priv->entry_stunserver),
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400525 priv->account->sipStunServer().toUtf8().constData());
526
527 /* TURN */
528 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_use_turn),
529 priv->account->isTurnEnabled());
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400530 gtk_widget_set_sensitive(priv->grid_turn, priv->account->isTurnEnabled());
531 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnserver),
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400532 priv->account->turnServer().toUtf8().constData());
Stepan Salenikovich28c1f0c2015-08-06 11:42:41 -0400533 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnusername),
534 priv->account->turnServerUsername().toUtf8().constData());
535 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnpassword),
536 priv->account->turnServerPassword().toUtf8().constData());
537 gtk_entry_set_text(GTK_ENTRY(priv->entry_turnrealm),
538 priv->account->turnServerRealm().toUtf8().constData());
Stepan Salenikovichb7e6a732015-05-04 17:13:22 -0400539
540 /* audio/video rtp port range */
541 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_audio_port_min),
542 priv->account->audioPortMin());
543 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_audio_port_max),
544 priv->account->audioPortMax());
545 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_video_port_min),
546 priv->account->videoPortMin());
547 gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_video_port_max),
548 priv->account->videoPortMax());
549 }
550 );
551}
552
553GtkWidget *
554account_advanced_tab_new(Account *account)
555{
556 g_return_val_if_fail(account != NULL, NULL);
557
558 gpointer view = g_object_new(ACCOUNT_ADVANCED_TAB_TYPE, NULL);
559
560 AccountAdvancedTabPrivate *priv = ACCOUNT_ADVANCED_TAB_GET_PRIVATE(view);
561 priv->account = account;
562
563 build_tab_view(ACCOUNT_ADVANCED_TAB(view));
564
565 return (GtkWidget *)view;
566}