]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-account-widget-salut.c
78dce23127710cd3c1ca126cd68eb1e2f4e2aecf
[empathy.git] / libempathy-gtk / empathy-account-widget-salut.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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
18  * 
19  * Authors: Xavier Claessens <xclaesse@gmail.com>
20  *          Cosimo Cecchi <anarki@lilik.it>
21  */
22  
23 #include "config.h"
24
25 #include <stdlib.h>
26
27 #include <glib/gi18n.h>
28 #include <gtk/gtk.h>
29 #include <glade/glade.h>
30
31 #include <libmissioncontrol/mc-profile.h>
32
33 #include <libempathy/empathy-utils.h>
34 #include <libempathy/empathy-debug.h>
35
36 #include "empathy-account-widget-salut.h"
37 #include "empathy-ui-utils.h"
38
39 #define DEBUG_DOMAIN "AccountWidgetMSN"
40
41 typedef struct {
42         McAccount *account;
43         
44         GtkWidget *vbox_settings;
45         GtkWidget *entry_nickname;
46         GtkWidget *entry_published;
47         GtkWidget *entry_first_name;
48         GtkWidget *entry_last_name;
49         GtkWidget *entry_email;
50         GtkWidget *entry_jid;
51 } EmpathyAccountWidgetSalut;
52
53 static gboolean
54 account_widget_salut_entry_focus_cb (GtkWidget               *widget,
55                                      GdkEventFocus           *event,
56                                      EmpathyAccountWidgetSalut *settings)
57 {
58         const gchar *param;
59         const gchar *str;
60         
61         if (widget == settings->entry_nickname) {
62                 param = "nickname";
63         }
64         else if (widget == settings->entry_published) {
65                 param = "published-name";
66         }
67         else if (widget == settings->entry_first_name) {
68                 param = "first-name";
69         }
70         else if (widget == settings->entry_last_name) {
71                 param = "last-name";
72         }
73         else if (widget == settings->entry_email) {
74                 param = "email";
75         }
76         else if (widget == settings->entry_jid) {
77                 param = "jid";
78         }
79         else {
80                 return FALSE;
81         }
82         
83         str = gtk_entry_get_text (GTK_ENTRY (widget));
84         if (G_STR_EMPTY (str)) {
85                 gchar *value = NULL;
86
87                 mc_account_unset_param (settings->account, param);
88                 mc_account_get_param_string (settings->account, param, &value);
89                 empathy_debug (DEBUG_DOMAIN, "Unset %s and restore to %s", param, value);
90                 gtk_entry_set_text (GTK_ENTRY (widget), value ? value : "");
91                 g_free (value);
92         } else {
93                 empathy_debug (DEBUG_DOMAIN, "Setting %s to %s", param, str);
94                 mc_account_set_param_string (settings->account, param, str);
95         }
96
97         return FALSE;
98 }
99
100 static void
101 account_widget_salut_destroy_cb (GtkWidget               *widget,
102                                  EmpathyAccountWidgetSalut *settings)
103 {
104         g_object_unref (settings->account);
105         g_free (settings);
106 }
107
108 static void
109 account_widget_salut_setup (EmpathyAccountWidgetSalut *settings)
110 {
111         gchar *nickname = NULL;
112         gchar *published_name = NULL;
113         gchar *first_name = NULL;
114         gchar *last_name = NULL;
115         gchar *email = NULL;
116         gchar *jid = NULL;
117
118         mc_account_get_param_string (settings->account, "nickname", &nickname);
119         mc_account_get_param_string (settings->account, "published-name", &published_name);
120         mc_account_get_param_string (settings->account, "first-name", &first_name);
121         mc_account_get_param_string (settings->account, "last-name", &last_name);
122         mc_account_get_param_string (settings->account, "email", &email);
123         mc_account_get_param_string (settings->account, "jid", &jid);
124         
125         gtk_entry_set_text (GTK_ENTRY (settings->entry_nickname), nickname ? nickname : "");
126         gtk_entry_set_text (GTK_ENTRY (settings->entry_published), published_name ? published_name : "");
127         gtk_entry_set_text (GTK_ENTRY (settings->entry_first_name), first_name ? first_name : "");
128         gtk_entry_set_text (GTK_ENTRY (settings->entry_last_name), last_name ? last_name : "");
129         gtk_entry_set_text (GTK_ENTRY (settings->entry_email), email ? email : "");
130         gtk_entry_set_text (GTK_ENTRY (settings->entry_jid), jid ? jid : "");
131
132         g_free (nickname);
133         g_free (published_name);
134         g_free (first_name);
135         g_free (last_name);
136         g_free (email);
137         g_free (jid);
138 }
139
140
141 GtkWidget *
142 empathy_account_widget_salut_new (McAccount *account)
143 {
144         EmpathyAccountWidgetSalut *settings;
145         GladeXML                  *glade;
146
147         settings = g_new0 (EmpathyAccountWidgetSalut, 1);
148         settings->account = g_object_ref (account);
149
150         glade = empathy_glade_get_file ("empathy-account-widget-salut.glade",
151                                         "vbox_salut_settings",
152                                         NULL,
153                                         "vbox_salut_settings", &settings->vbox_settings,
154                                         "entry_published", &settings->entry_published,
155                                         "entry_nickname", &settings->entry_nickname,
156                                         "entry_first_name", &settings->entry_first_name,
157                                         "entry_last_name", &settings->entry_last_name,
158                                         "entry_email", &settings->entry_email,
159                                         "entry_jid", &settings->entry_jid,
160                                         NULL);
161
162         account_widget_salut_setup (settings);
163
164         empathy_glade_connect (glade,
165                                settings,
166                                "vbox_salut_settings", "destroy", account_widget_salut_destroy_cb,
167                                "entry_nickname", "focus-out-event", account_widget_salut_entry_focus_cb,
168                                "entry_published", "focus-out-event", account_widget_salut_entry_focus_cb,
169                                "entry_first_name", "focus-out-event", account_widget_salut_entry_focus_cb,
170                                "entry_last_name", "focus-out-event", account_widget_salut_entry_focus_cb,
171                                "entry_email", "focus-out-event", account_widget_salut_entry_focus_cb,
172                                "entry_jid", "focus-out-event", account_widget_salut_entry_focus_cb,
173                               NULL);
174
175         g_object_unref (glade);
176
177         gtk_widget_show (settings->vbox_settings);
178
179         return settings->vbox_settings;
180 }