]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-account-widget-sip.c
Merge branch 'part-reasons'
[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-protocol.h>
32
33 #include <libempathy/empathy-utils.h>
34
35 #include "empathy-account-widget.h"
36 #include "empathy-account-widget-sip.h"
37 #include "empathy-ui-utils.h"
38
39 typedef struct {
40   EmpathyAccount *account;
41
42   GtkWidget *vbox_settings;
43
44   GtkWidget *entry_stun_server;
45   GtkWidget *spinbutton_stun_part;
46   GtkWidget *checkbutton_discover_stun;
47 } EmpathyAccountWidgetSip;
48
49 static void
50 account_widget_sip_destroy_cb (GtkWidget *widget,
51                                EmpathyAccountWidgetSip *settings)
52 {
53   g_object_unref (settings->account);
54   g_slice_free (EmpathyAccountWidgetSip, settings);
55 }
56
57 static void
58 account_widget_sip_discover_stun_toggled_cb (
59     GtkWidget *checkbox,
60     EmpathyAccountWidgetSip *settings)
61 {
62   gboolean active;
63
64   active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox));
65   gtk_widget_set_sensitive (settings->entry_stun_server, !active);
66   gtk_widget_set_sensitive (settings->spinbutton_stun_part, !active);
67 }
68
69 /**
70  * empathy_account_widget_sip_new:
71  * @account: the #EmpathyAccount to configure
72  *
73  * Creates a new SIP account widget to configure a given #EmpathyAccount
74  *
75  * Returns: The toplevel container of the configuration widget
76  */
77 GtkWidget *
78 empathy_account_widget_sip_new (EmpathyAccount *account)
79 {
80   EmpathyAccountWidgetSip *settings;
81   GtkBuilder *gui;
82   gchar *filename;
83
84   settings = g_slice_new0 (EmpathyAccountWidgetSip);
85   settings->account = g_object_ref (account);
86
87   filename = empathy_file_lookup ("empathy-account-widget-sip.ui",
88       "libempathy-gtk");
89   gui = empathy_builder_get_file (filename,
90       "vbox_sip_settings", &settings->vbox_settings,
91       "entry_stun-server", &settings->entry_stun_server,
92       "spinbutton_stun-port", &settings->spinbutton_stun_part,
93       "checkbutton_discover-stun", &settings->checkbutton_discover_stun,
94       NULL);
95   g_free (filename);
96
97   empathy_account_widget_handle_params (account, gui,
98       "entry_userid", "account",
99       "entry_password", "password",
100       "checkbutton_discover-stun", "discover-stun",
101       "entry_stun-server", "stun-server",
102       "spinbutton_stun-port", "stun-port",
103       NULL);
104
105   empathy_account_widget_add_forget_button (account, gui,
106                                             "button_forget",
107                                             "entry_password");
108
109   account_widget_sip_discover_stun_toggled_cb (settings->checkbutton_discover_stun,
110                                                settings);
111
112   empathy_builder_connect (gui, settings,
113       "vbox_sip_settings", "destroy", account_widget_sip_destroy_cb,
114       "checkbutton_discover-stun", "toggled", account_widget_sip_discover_stun_toggled_cb,
115       NULL);
116
117   empathy_account_widget_set_default_focus (gui, "entry_userid");
118
119   return empathy_builder_unref_and_keep_widget (gui, settings->vbox_settings);
120 }