]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-account-widget-irc.c
Merge branch 'sasl'
[empathy.git] / libempathy-gtk / empathy-account-widget-irc.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  */
20
21 #include "config.h"
22
23 #include <stdlib.h>
24 #include <string.h>
25 #include <sys/stat.h>
26
27 #include <glib/gi18n-lib.h>
28 #include <gtk/gtk.h>
29
30 #include <libempathy/empathy-utils.h>
31
32 #include "empathy-irc-network-dialog.h"
33 #include "empathy-irc-network-chooser.h"
34 #include "empathy-account-widget.h"
35 #include "empathy-account-widget-private.h"
36 #include "empathy-account-widget-irc.h"
37 #include "empathy-ui-utils.h"
38
39 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT | EMPATHY_DEBUG_IRC
40 #include <libempathy/empathy-debug.h>
41
42 typedef struct {
43   EmpathyAccountWidget *self;
44
45   GtkWidget *vbox_settings;
46
47   GtkWidget *network_chooser;
48 } EmpathyAccountWidgetIrc;
49
50 static void
51 account_widget_irc_destroy_cb (GtkWidget *widget,
52                                EmpathyAccountWidgetIrc *settings)
53 {
54   g_slice_free (EmpathyAccountWidgetIrc, settings);
55 }
56
57 static void
58 account_widget_irc_setup (EmpathyAccountWidgetIrc *settings)
59 {
60   const gchar *nick = NULL;
61   const gchar *fullname = NULL;
62   gint port = 6667;
63   const gchar *charset;
64   gboolean ssl = FALSE;
65   EmpathyAccountSettings *ac_settings;
66
67   g_object_get (settings->self, "settings", &ac_settings, NULL);
68
69   nick = empathy_account_settings_get_string (ac_settings, "account");
70   fullname = empathy_account_settings_get_string (ac_settings,
71       "fullname");
72   charset = empathy_account_settings_get_string (ac_settings, "charset");
73   port = empathy_account_settings_get_uint32 (ac_settings, "port");
74   ssl = empathy_account_settings_get_boolean (ac_settings, "use-ssl");
75
76   if (!nick)
77     {
78       nick = g_strdup (g_get_user_name ());
79       empathy_account_settings_set_string (ac_settings,
80         "account", nick);
81     }
82
83   if (!fullname)
84     {
85       fullname = g_strdup (g_get_real_name ());
86       if (!fullname)
87         {
88           fullname = g_strdup (nick);
89         }
90       empathy_account_settings_set_string (ac_settings,
91           "fullname", fullname);
92     }
93 }
94
95 static void
96 network_changed_cb (EmpathyIrcNetworkChooser *chooser,
97     EmpathyAccountWidgetIrc *settings)
98 {
99   empathy_account_widget_changed (settings->self);
100 }
101
102 EmpathyIrcNetworkChooser *
103 empathy_account_widget_irc_build (EmpathyAccountWidget *self,
104     const char *filename,
105     GtkWidget **table_common_settings)
106 {
107   EmpathyAccountWidgetIrc *settings;
108   EmpathyAccountSettings *ac_settings;
109
110   settings = g_slice_new0 (EmpathyAccountWidgetIrc);
111   settings->self = self;
112
113   self->ui_details->gui = empathy_builder_get_file (filename,
114       "table_irc_settings", table_common_settings,
115       "vbox_irc", &self->ui_details->widget,
116       "table_irc_settings", &settings->vbox_settings,
117       NULL);
118
119   /* Add network chooser button */
120   g_object_get (settings->self, "settings", &ac_settings, NULL);
121
122   settings->network_chooser = empathy_irc_network_chooser_new (ac_settings);
123
124   g_signal_connect (settings->network_chooser, "changed",
125       G_CALLBACK (network_changed_cb), settings);
126
127   gtk_table_attach (GTK_TABLE (*table_common_settings),
128       settings->network_chooser, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
129
130   gtk_widget_show (settings->network_chooser);
131
132   account_widget_irc_setup (settings);
133
134   empathy_account_widget_handle_params (self,
135       "entry_nick", "account",
136       "entry_fullname", "fullname",
137       "entry_password", "password",
138       "entry_quit_message", "quit-message",
139       NULL);
140
141   empathy_builder_connect (self->ui_details->gui, settings,
142       "table_irc_settings", "destroy", account_widget_irc_destroy_cb,
143       NULL);
144
145   self->ui_details->default_focus = g_strdup ("entry_nick");
146
147   g_object_unref (ac_settings);
148
149   return EMPATHY_IRC_NETWORK_CHOOSER (settings->network_chooser);
150 }
151
152 EmpathyIrcNetworkChooser *
153 empathy_account_widget_irc_build_simple (EmpathyAccountWidget *self,
154     const char *filename)
155 {
156   EmpathyAccountWidgetIrc *settings;
157   EmpathyAccountSettings *ac_settings;
158   GtkAlignment *alignment;
159
160   settings = g_slice_new0 (EmpathyAccountWidgetIrc);
161   settings->self = self;
162
163   self->ui_details->gui = empathy_builder_get_file (filename,
164       "vbox_irc_simple", &self->ui_details->widget,
165       "alignment_network_simple", &alignment,
166       NULL);
167
168   /* Add network chooser button */
169   g_object_get (settings->self, "settings", &ac_settings, NULL);
170
171   settings->network_chooser = empathy_irc_network_chooser_new (ac_settings);
172
173   g_signal_connect (settings->network_chooser, "changed",
174       G_CALLBACK (network_changed_cb), settings);
175
176   gtk_container_add (GTK_CONTAINER (alignment), settings->network_chooser);
177
178   gtk_widget_show (settings->network_chooser);
179
180   empathy_account_widget_handle_params (self,
181       "entry_nick_simple", "account",
182       NULL);
183
184   empathy_builder_connect (self->ui_details->gui, settings,
185       "vbox_irc_simple", "destroy", account_widget_irc_destroy_cb,
186       NULL);
187
188   self->ui_details->default_focus = g_strdup ("entry_nick_simple");
189
190   g_object_unref (ac_settings);
191
192   return EMPATHY_IRC_NETWORK_CHOOSER (settings->network_chooser);
193 }