Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 1 | /* |
Stepan Salenikovich | be87d2c | 2016-01-25 14:14:34 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 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. |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "accountadvancedtab.h" |
| 21 | |
| 22 | #include <gtk/gtk.h> |
| 23 | #include <account.h> |
| 24 | |
| 25 | struct _AccountAdvancedTab |
| 26 | { |
| 27 | GtkBox parent; |
| 28 | }; |
| 29 | |
| 30 | struct _AccountAdvancedTabClass |
| 31 | { |
| 32 | GtkBoxClass parent_class; |
| 33 | }; |
| 34 | |
| 35 | typedef struct _AccountAdvancedTabPrivate AccountAdvancedTabPrivate; |
| 36 | |
| 37 | struct _AccountAdvancedTabPrivate |
| 38 | { |
| 39 | Account *account; |
| 40 | GtkWidget *vbox_main; |
| 41 | GtkWidget *frame_registration; |
Stepan Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 42 | GtkWidget *box_registration; |
| 43 | GtkWidget *box_registration_expire; |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 44 | GtkWidget *adjustment_registration_timeout; |
Stepan Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 45 | GtkWidget *checkbutton_allow_incoming_unknown; |
| 46 | GtkWidget *checkbutton_allow_incoming_history; |
| 47 | GtkWidget *checkbutton_allow_incoming_contacts; |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 48 | 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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 60 | GtkWidget *grid_stun; |
| 61 | GtkWidget *entry_stunserver; |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 62 | GtkWidget *checkbutton_use_turn; |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 63 | GtkWidget *grid_turn; |
| 64 | GtkWidget *entry_turnserver; |
| 65 | GtkWidget *entry_turnusername; |
| 66 | GtkWidget *entry_turnpassword; |
| 67 | GtkWidget *entry_turnrealm; |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 68 | 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 | |
| 76 | G_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 | |
| 80 | static void |
| 81 | account_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 | |
| 91 | static void |
| 92 | account_advanced_tab_init(AccountAdvancedTab *view) |
| 93 | { |
| 94 | gtk_widget_init_template(GTK_WIDGET(view)); |
| 95 | } |
| 96 | |
| 97 | static void |
| 98 | account_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 Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 107 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 109 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, adjustment_registration_timeout); |
Stepan Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 110 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 113 | 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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 125 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 127 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountAdvancedTab, checkbutton_use_turn); |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 128 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 133 | 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 | |
| 139 | static void |
| 140 | registration_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 | |
| 149 | static void |
| 150 | local_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 | |
| 164 | static void |
| 165 | same_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 | |
| 178 | static void |
| 179 | published_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 | |
| 187 | static void |
| 188 | published_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 | |
| 197 | static void |
| 198 | stun_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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 208 | gtk_widget_set_sensitive(priv->grid_stun, use_stun); |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | static void |
| 212 | stun_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 | |
| 220 | static void |
| 221 | turn_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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 231 | gtk_widget_set_sensitive(priv->grid_turn, use_turn); |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | static void |
| 235 | turn_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 | |
| 243 | static void |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 244 | turn_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 | |
| 252 | static void |
| 253 | turn_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 | |
| 261 | static void |
| 262 | turn_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 | |
| 270 | static void |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 271 | audio_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 | |
| 280 | static void |
| 281 | audio_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 | |
| 290 | static void |
| 291 | video_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 | |
| 300 | static void |
| 301 | video_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 | |
| 310 | static void |
Stepan Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 311 | allow_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 | |
| 321 | static void |
| 322 | allow_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 | |
| 332 | static void |
| 333 | allow_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 | |
| 343 | static void |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 344 | build_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 Salenikovich | fea8405 | 2016-05-13 16:32:51 -0400 | [diff] [blame] | 349 | /* 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 Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 352 | priv->box_registration_expire = NULL; |
Stepan Salenikovich | fea8405 | 2016-05-13 16:32:51 -0400 | [diff] [blame] | 353 | } 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 Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 363 | priv->checkbutton_allow_incoming_unknown = NULL; |
Stepan Salenikovich | fea8405 | 2016-05-13 16:32:51 -0400 | [diff] [blame] | 364 | gtk_container_remove(GTK_CONTAINER(priv->box_registration), priv->checkbutton_allow_incoming_history); |
Stepan Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 365 | priv->checkbutton_allow_incoming_history = NULL; |
Stepan Salenikovich | fea8405 | 2016-05-13 16:32:51 -0400 | [diff] [blame] | 366 | gtk_container_remove(GTK_CONTAINER(priv->box_registration), priv->checkbutton_allow_incoming_contacts); |
Stepan Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 367 | priv->checkbutton_allow_incoming_contacts = NULL; |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 368 | } else { |
Stepan Salenikovich | fea8405 | 2016-05-13 16:32:51 -0400 | [diff] [blame] | 369 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 381 | } |
| 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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 427 | gtk_entry_set_text(GTK_ENTRY(priv->entry_stunserver), |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 428 | priv->account->sipStunServer().toUtf8().constData()); |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 429 | gtk_widget_set_sensitive(priv->grid_stun, |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 430 | priv->account->isSipStunEnabled()); |
| 431 | g_signal_connect(priv->checkbutton_use_stun, |
| 432 | "toggled", G_CALLBACK(stun_enabled_toggled), self); |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 433 | g_signal_connect(priv->entry_stunserver, |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 434 | "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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 439 | gtk_entry_set_text(GTK_ENTRY(priv->entry_turnserver), |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 440 | priv->account->turnServer().toUtf8().constData()); |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 441 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 448 | priv->account->isTurnEnabled()); |
| 449 | g_signal_connect(priv->checkbutton_use_turn, |
| 450 | "toggled", G_CALLBACK(turn_enabled_toggled), self); |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 451 | g_signal_connect(priv->entry_turnserver, |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 452 | "changed", G_CALLBACK(turn_server_changed), self); |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 453 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 459 | |
| 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 Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 484 | if ( priv->box_registration_expire ) { |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 485 | gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_registration_timeout), |
| 486 | priv->account->registrationExpire()); |
| 487 | } |
| 488 | |
Stepan Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 489 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 501 | /* 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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 523 | gtk_widget_set_sensitive(priv->grid_stun, priv->account->isSipStunEnabled()); |
| 524 | gtk_entry_set_text(GTK_ENTRY(priv->entry_stunserver), |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 525 | 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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 530 | gtk_widget_set_sensitive(priv->grid_turn, priv->account->isTurnEnabled()); |
| 531 | gtk_entry_set_text(GTK_ENTRY(priv->entry_turnserver), |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 532 | priv->account->turnServer().toUtf8().constData()); |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 533 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 539 | |
| 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 | |
| 553 | GtkWidget * |
| 554 | account_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 | } |