]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-account-widget-sip.c
ffac231d6a819fccff73e579e29ffd9ca124c209
[empathy.git] / libempathy-gtk / empathy-account-widget-sip.c
1 /*
2  * Copyright (C) 2007-2008 Guillaume Desmottes
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Authors: Guillaume Desmottes <gdesmott@gnome.org>
19  *          Frederic Peters <fpeters@0d.be>
20  */
21
22 #include "config.h"
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/stat.h>
27
28 #include <glib/gi18n-lib.h>
29 #include <gtk/gtk.h>
30
31 #include <libmissioncontrol/mc-account.h>
32 #include <libmissioncontrol/mc-protocol.h>
33
34 #include <libempathy/empathy-utils.h>
35
36 #include "empathy-account-widget.h"
37 #include "empathy-account-widget-sip.h"
38 #include "empathy-ui-utils.h"
39
40 typedef struct {
41   McAccount *account;
42
43   GtkWidget *vbox_settings;
44
45   GtkWidget *entry_stun_server;
46   GtkWidget *spinbutton_stun_part;
47   GtkWidget *checkbutton_discover_stun;
48 } EmpathyAccountWidgetSip;
49
50 static void
51 account_widget_sip_destroy_cb (GtkWidget *widget,
52                                EmpathyAccountWidgetSip *settings)
53 {
54   g_object_unref (settings->account);
55   g_slice_free (EmpathyAccountWidgetSip, settings);
56 }
57
58 static void
59 account_widget_sip_discover_stun_toggled_cb (
60     GtkWidget *checkbox,
61     EmpathyAccountWidgetSip *settings)
62 {
63   gboolean active;
64
65   active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox));
66   gtk_widget_set_sensitive(settings->entry_stun_server, !active);
67   gtk_widget_set_sensitive(settings->spinbutton_stun_part, !active);
68 }
69
70 /**
71  * empathy_account_widget_sip_new:
72  * @account: the #McAccount to configure
73  *
74  * Creates a new SIP account widget to configure a given #McAccount
75  *
76  * Returns: The toplevel container of the configuration widget
77  */
78 GtkWidget *
79 empathy_account_widget_sip_new (McAccount *account)
80 {
81   EmpathyAccountWidgetSip *settings;
82   GtkBuilder *gui;
83   gchar *filename;
84
85   settings = g_slice_new0 (EmpathyAccountWidgetSip);
86   settings->account = g_object_ref (account);
87
88   filename = empathy_file_lookup ("empathy-account-widget-sip.ui",
89       "libempathy-gtk");
90   gui = empathy_builder_get_file (filename,
91       "vbox_sip_settings", &settings->vbox_settings,
92       "entry_stun-server", &settings->entry_stun_server,
93       "spinbutton_stun-port", &settings->spinbutton_stun_part,
94       "checkbutton_discover-stun", &settings->checkbutton_discover_stun,
95       NULL);
96   g_free (filename);
97
98   empathy_account_widget_handle_params (account, gui,
99       "entry_userid", "account",
100       "entry_password", "password",
101       "checkbutton_discover-stun", "discover-stun",
102       "entry_stun-server", "stun-server",
103       "spinbutton_stun-port", "stun-port",
104       NULL);
105
106   empathy_account_widget_add_forget_button (account, gui,
107                                             "button_forget",
108                                             "entry_password");
109
110   account_widget_sip_discover_stun_toggled_cb (settings->checkbutton_discover_stun,
111                                                settings);
112
113   empathy_builder_connect (gui, settings,
114       "vbox_sip_settings", "destroy", account_widget_sip_destroy_cb,
115       "checkbutton_discover-stun", "toggled", account_widget_sip_discover_stun_toggled_cb,
116       NULL);
117
118   g_object_ref (settings->vbox_settings);
119   g_object_force_floating (G_OBJECT (settings->vbox_settings));
120   g_object_unref (gui);
121
122   return settings->vbox_settings;
123 }