1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
20 * Cosimo Cecchi <anarki@lilik.it>
29 #include <glib/gi18n.h>
31 #include <glade/glade.h>
33 #include <libmissioncontrol/mc-profile.h>
35 #include <libempathy/empathy-utils.h>
37 #include "empathy-account-widget-msn.h"
38 #include "empathy-ui-utils.h"
43 GtkWidget *vbox_settings;
44 GtkWidget *button_forget;
46 GtkWidget *entry_password;
47 GtkWidget *entry_server;
48 GtkWidget *spinbutton_port;
49 } EmpathyAccountWidgetMSN;
51 static gboolean account_widget_msn_entry_focus_cb (GtkWidget *widget,
53 EmpathyAccountWidgetMSN *settings);
54 static void account_widget_msn_entry_changed_cb (GtkWidget *widget,
55 EmpathyAccountWidgetMSN *settings);
56 static void account_widget_msn_value_changed_cb (GtkWidget *spinbutton,
57 EmpathyAccountWidgetMSN *settings);
58 static void account_widget_msn_button_forget_clicked_cb (GtkWidget *button,
59 EmpathyAccountWidgetMSN *settings);
60 static void account_widget_msn_destroy_cb (GtkWidget *widget,
61 EmpathyAccountWidgetMSN *settings);
62 static void account_widget_msn_setup (EmpathyAccountWidgetMSN *settings);
65 account_widget_msn_entry_focus_cb (GtkWidget *widget,
67 EmpathyAccountWidgetMSN *settings)
72 if (widget == settings->entry_password) {
75 else if (widget == settings->entry_server) {
78 else if (widget == settings->entry_id) {
84 str = gtk_entry_get_text (GTK_ENTRY (widget));
86 if (G_STR_EMPTY (str)) {
89 mc_account_get_param_string (settings->account, param, &value);
90 gtk_entry_set_text (GTK_ENTRY (widget), value ? value : "");
93 mc_account_set_param_string (settings->account, param, str);
100 account_widget_msn_entry_changed_cb (GtkWidget *widget,
101 EmpathyAccountWidgetMSN *settings)
103 if (widget == settings->entry_password) {
106 str = gtk_entry_get_text (GTK_ENTRY (widget));
107 gtk_widget_set_sensitive (settings->button_forget, !G_STR_EMPTY (str));
112 account_widget_msn_value_changed_cb (GtkWidget *spinbutton,
113 EmpathyAccountWidgetMSN *settings)
115 if (spinbutton == settings->spinbutton_port) {
118 value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinbutton));
119 mc_account_set_param_int (settings->account, "port", (gint) value);
124 account_widget_msn_button_forget_clicked_cb (GtkWidget *button,
125 EmpathyAccountWidgetMSN *settings)
127 mc_account_set_param_string (settings->account, "password", "");
128 gtk_entry_set_text (GTK_ENTRY (settings->entry_password), "");
132 account_widget_msn_destroy_cb (GtkWidget *widget,
133 EmpathyAccountWidgetMSN *settings)
135 g_object_unref (settings->account);
140 account_widget_msn_setup (EmpathyAccountWidgetMSN *settings)
144 gchar *server = NULL;
145 gchar *password = NULL;
147 mc_account_get_param_int (settings->account, "port", &port);
148 mc_account_get_param_string (settings->account, "account", &id);
149 mc_account_get_param_string (settings->account, "server", &server);
150 mc_account_get_param_string (settings->account, "password", &password);
152 gtk_entry_set_text (GTK_ENTRY (settings->entry_id), id ? id : "");
153 gtk_entry_set_text (GTK_ENTRY (settings->entry_password), password ? password : "");
154 gtk_entry_set_text (GTK_ENTRY (settings->entry_server), server ? server : "");
155 gtk_spin_button_set_value (GTK_SPIN_BUTTON (settings->spinbutton_port), port);
157 gtk_widget_set_sensitive (settings->button_forget, !G_STR_EMPTY (password));
165 empathy_account_widget_msn_new (McAccount *account)
167 EmpathyAccountWidgetMSN *settings;
170 settings = g_new0 (EmpathyAccountWidgetMSN, 1);
171 settings->account = g_object_ref (account);
173 glade = empathy_glade_get_file ("empathy-account-widget-msn.glade",
176 "vbox_msn_settings", &settings->vbox_settings,
177 "button_forget", &settings->button_forget,
178 "entry_id", &settings->entry_id,
179 "entry_password", &settings->entry_password,
180 "entry_server", &settings->entry_server,
181 "spinbutton_port", &settings->spinbutton_port,
184 account_widget_msn_setup (settings);
186 empathy_glade_connect (glade,
188 "vbox_msn_settings", "destroy", account_widget_msn_destroy_cb,
189 "button_forget", "clicked", account_widget_msn_button_forget_clicked_cb,
190 "entry_id", "changed", account_widget_msn_entry_changed_cb,
191 "entry_password", "changed", account_widget_msn_entry_changed_cb,
192 "entry_server", "changed", account_widget_msn_entry_changed_cb,
193 "entry_id", "focus-out-event", account_widget_msn_entry_focus_cb,
194 "entry_password", "focus-out-event", account_widget_msn_entry_focus_cb,
195 "entry_server", "focus-out-event", account_widget_msn_entry_focus_cb,
196 "spinbutton_port", "value-changed", account_widget_msn_value_changed_cb,
199 g_object_unref (glade);
201 gtk_widget_show (settings->vbox_settings);
203 return settings->vbox_settings;