Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 36 | struct _AccountAdvancedTab |
| 37 | { |
| 38 | GtkBox parent; |
| 39 | }; |
| 40 | |
| 41 | struct _AccountAdvancedTabClass |
| 42 | { |
| 43 | GtkBoxClass parent_class; |
| 44 | }; |
| 45 | |
| 46 | typedef struct _AccountAdvancedTabPrivate AccountAdvancedTabPrivate; |
| 47 | |
| 48 | struct _AccountAdvancedTabPrivate |
| 49 | { |
| 50 | Account *account; |
| 51 | GtkWidget *vbox_main; |
| 52 | GtkWidget *frame_registration; |
Stepan Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 53 | GtkWidget *box_registration; |
| 54 | GtkWidget *box_registration_expire; |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 55 | GtkWidget *adjustment_registration_timeout; |
Stepan Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 56 | GtkWidget *checkbutton_allow_incoming_unknown; |
| 57 | GtkWidget *checkbutton_allow_incoming_history; |
| 58 | GtkWidget *checkbutton_allow_incoming_contacts; |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 59 | 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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 71 | GtkWidget *grid_stun; |
| 72 | GtkWidget *entry_stunserver; |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 73 | GtkWidget *checkbutton_use_turn; |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 74 | GtkWidget *grid_turn; |
| 75 | GtkWidget *entry_turnserver; |
| 76 | GtkWidget *entry_turnusername; |
| 77 | GtkWidget *entry_turnpassword; |
| 78 | GtkWidget *entry_turnrealm; |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 79 | 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 | |
| 87 | G_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 | |
| 91 | static void |
| 92 | account_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 | |
| 102 | static void |
| 103 | account_advanced_tab_init(AccountAdvancedTab *view) |
| 104 | { |
| 105 | gtk_widget_init_template(GTK_WIDGET(view)); |
| 106 | } |
| 107 | |
| 108 | static void |
| 109 | account_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 Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 118 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 120 | 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] | 121 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 124 | 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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 136 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 138 | 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] | 139 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 144 | 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 | |
| 150 | static void |
| 151 | registration_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 | |
| 160 | static void |
| 161 | local_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 | |
| 175 | static void |
| 176 | same_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 | |
| 189 | static void |
| 190 | published_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 | |
| 198 | static void |
| 199 | published_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 | |
| 208 | static void |
| 209 | stun_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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 219 | gtk_widget_set_sensitive(priv->grid_stun, use_stun); |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | static void |
| 223 | stun_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 | |
| 231 | static void |
| 232 | turn_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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 242 | gtk_widget_set_sensitive(priv->grid_turn, use_turn); |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static void |
| 246 | turn_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 | |
| 254 | static void |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 255 | turn_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 | |
| 263 | static void |
| 264 | turn_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 | |
| 272 | static void |
| 273 | turn_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 | |
| 281 | static void |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 282 | audio_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 | |
| 291 | static void |
| 292 | audio_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 | |
| 301 | static void |
| 302 | video_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 | |
| 311 | static void |
| 312 | video_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 | |
| 321 | static void |
Stepan Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 322 | allow_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 | |
| 332 | static void |
| 333 | allow_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 | |
| 343 | static void |
| 344 | allow_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 | |
| 354 | static void |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 355 | build_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 Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 363 | /* if account is IP2IP we don't need the registration box */ |
| 364 | if (strcmp(alias.constData(), "IP2IP") == 0) { |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 365 | gtk_container_remove(GTK_CONTAINER(priv->vbox_main), priv->frame_registration); |
| 366 | priv->frame_registration = NULL; |
Stepan Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 367 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 372 | } else { |
Stepan Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 373 | /* 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 406 | } |
| 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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 452 | gtk_entry_set_text(GTK_ENTRY(priv->entry_stunserver), |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 453 | priv->account->sipStunServer().toUtf8().constData()); |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 454 | gtk_widget_set_sensitive(priv->grid_stun, |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 455 | priv->account->isSipStunEnabled()); |
| 456 | g_signal_connect(priv->checkbutton_use_stun, |
| 457 | "toggled", G_CALLBACK(stun_enabled_toggled), self); |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 458 | g_signal_connect(priv->entry_stunserver, |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 459 | "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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 464 | gtk_entry_set_text(GTK_ENTRY(priv->entry_turnserver), |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 465 | priv->account->turnServer().toUtf8().constData()); |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 466 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 473 | priv->account->isTurnEnabled()); |
| 474 | g_signal_connect(priv->checkbutton_use_turn, |
| 475 | "toggled", G_CALLBACK(turn_enabled_toggled), self); |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 476 | g_signal_connect(priv->entry_turnserver, |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 477 | "changed", G_CALLBACK(turn_server_changed), self); |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 478 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 484 | |
| 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 Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 509 | if ( priv->box_registration_expire ) { |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 510 | gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_registration_timeout), |
| 511 | priv->account->registrationExpire()); |
| 512 | } |
| 513 | |
Stepan Salenikovich | 2371a89 | 2015-07-23 17:17:00 -0400 | [diff] [blame] | 514 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 526 | /* 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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 548 | gtk_widget_set_sensitive(priv->grid_stun, priv->account->isSipStunEnabled()); |
| 549 | gtk_entry_set_text(GTK_ENTRY(priv->entry_stunserver), |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 550 | 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 Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 555 | gtk_widget_set_sensitive(priv->grid_turn, priv->account->isTurnEnabled()); |
| 556 | gtk_entry_set_text(GTK_ENTRY(priv->entry_turnserver), |
Stepan Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 557 | priv->account->turnServer().toUtf8().constData()); |
Stepan Salenikovich | 28c1f0c | 2015-08-06 11:42:41 -0400 | [diff] [blame] | 558 | 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 Salenikovich | b7e6a73 | 2015-05-04 17:13:22 -0400 | [diff] [blame] | 564 | |
| 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 | |
| 578 | GtkWidget * |
| 579 | account_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 | } |