2 * Copyright (C) 2007-2008 Guillaume Desmottes
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.
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.
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
18 * Authors: Guillaume Desmottes <gdesmott@gnome.org>
27 #include <glib/gi18n-lib.h>
30 #include <libempathy/empathy-utils.h>
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"
39 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT | EMPATHY_DEBUG_IRC
40 #include <libempathy/empathy-debug.h>
43 EmpathyAccountWidget *self;
45 GtkWidget *vbox_settings;
47 GtkWidget *network_chooser;
48 } EmpathyAccountWidgetIrc;
51 account_widget_irc_destroy_cb (GtkWidget *widget,
52 EmpathyAccountWidgetIrc *settings)
54 g_slice_free (EmpathyAccountWidgetIrc, settings);
58 account_widget_irc_setup (EmpathyAccountWidgetIrc *settings)
61 gchar *fullname = NULL;
62 EmpathyAccountSettings *ac_settings;
64 g_object_get (settings->self, "settings", &ac_settings, NULL);
66 nick = empathy_account_settings_dup_string (ac_settings, "account");
67 fullname = empathy_account_settings_dup_string (ac_settings,
72 nick = g_strdup (g_get_user_name ());
74 empathy_account_settings_set (ac_settings,
75 "account", g_variant_new_string (nick));
80 fullname = g_strdup (g_get_real_name ());
83 fullname = g_strdup (nick);
85 empathy_account_settings_set (ac_settings,
86 "fullname", g_variant_new_string (fullname));
94 network_changed_cb (EmpathyIrcNetworkChooser *chooser,
95 EmpathyAccountWidgetIrc *settings)
97 empathy_account_widget_changed (settings->self);
101 * set_password_prompt_if_needed:
103 * If @password is not empty, this function sets the 'password-prompt' param
104 * on @ac_settings. This will ensure that Idle actually asks for the password
107 * Return: %TRUE if the password-prompt param has been changed
110 set_password_prompt_if_needed (EmpathyAccountSettings *ac_settings,
111 const gchar *password)
115 prompt = !tp_str_empty (password);
117 if (prompt == empathy_account_settings_get_boolean (ac_settings,
121 empathy_account_settings_set (ac_settings, "password-prompt",
122 g_variant_new_boolean (prompt));
128 entry_password_changed_cb (GtkEntry *entry,
129 EmpathyAccountWidgetIrc *settings)
131 const gchar *password;
132 EmpathyAccountSettings *ac_settings;
134 g_object_get (settings->self, "settings", &ac_settings, NULL);
136 password = gtk_entry_get_text (entry);
138 set_password_prompt_if_needed (ac_settings, password);
140 g_object_unref (ac_settings);
143 EmpathyIrcNetworkChooser *
144 empathy_account_widget_irc_build (EmpathyAccountWidget *self,
145 const char *filename,
146 GtkWidget **table_common_settings,
149 EmpathyAccountWidgetIrc *settings;
150 EmpathyAccountSettings *ac_settings;
151 GtkWidget *entry_password;
154 settings = g_slice_new0 (EmpathyAccountWidgetIrc);
155 settings->self = self;
157 self->ui_details->gui = empathy_builder_get_file (filename,
158 "table_irc_settings", table_common_settings,
160 "table_irc_settings", &settings->vbox_settings,
161 "entry_password", &entry_password,
164 /* Add network chooser button */
165 g_object_get (settings->self, "settings", &ac_settings, NULL);
167 settings->network_chooser = empathy_irc_network_chooser_new (ac_settings);
169 g_signal_connect (settings->network_chooser, "changed",
170 G_CALLBACK (network_changed_cb), settings);
172 gtk_grid_attach (GTK_GRID (*table_common_settings),
173 settings->network_chooser, 1, 0, 1, 1);
175 gtk_widget_show (settings->network_chooser);
177 account_widget_irc_setup (settings);
179 empathy_account_widget_handle_params (self,
180 "entry_nick", "account",
181 "entry_fullname", "fullname",
182 "entry_password", "password",
183 "entry_quit_message", "quit-message",
184 "entry_username", "username",
187 empathy_builder_connect (self->ui_details->gui, settings,
188 "table_irc_settings", "destroy", account_widget_irc_destroy_cb,
191 self->ui_details->default_focus = g_strdup ("entry_nick");
193 g_object_unref (ac_settings);
195 /* Automatically set password-prompt when needed */
196 password = empathy_account_settings_dup_string (ac_settings, "password");
198 if (set_password_prompt_if_needed (ac_settings, password))
200 /* Apply right now to save password-prompt */
201 empathy_account_settings_apply_async (ac_settings, NULL, NULL);
206 g_signal_connect (entry_password, "changed",
207 G_CALLBACK (entry_password_changed_cb), settings);
209 return EMPATHY_IRC_NETWORK_CHOOSER (settings->network_chooser);
212 EmpathyIrcNetworkChooser *
213 empathy_account_widget_irc_build_simple (EmpathyAccountWidget *self,
214 const char *filename,
217 EmpathyAccountWidgetIrc *settings;
218 EmpathyAccountSettings *ac_settings;
219 GtkAlignment *alignment;
221 settings = g_slice_new0 (EmpathyAccountWidgetIrc);
222 settings->self = self;
224 self->ui_details->gui = empathy_builder_get_file (filename,
225 "vbox_irc_simple", box,
226 "alignment_network_simple", &alignment,
229 /* Add network chooser button */
230 g_object_get (settings->self, "settings", &ac_settings, NULL);
232 settings->network_chooser = empathy_irc_network_chooser_new (ac_settings);
234 g_signal_connect (settings->network_chooser, "changed",
235 G_CALLBACK (network_changed_cb), settings);
237 gtk_container_add (GTK_CONTAINER (alignment), settings->network_chooser);
239 gtk_widget_show (settings->network_chooser);
241 empathy_account_widget_handle_params (self,
242 "entry_nick_simple", "account",
245 empathy_builder_connect (self->ui_details->gui, settings,
246 "vbox_irc_simple", "destroy", account_widget_irc_destroy_cb,
249 self->ui_details->default_focus = g_strdup ("entry_nick_simple");
251 g_object_unref (ac_settings);
253 return EMPATHY_IRC_NETWORK_CHOOSER (settings->network_chooser);