]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-account-widget-salut.c
63131e773dec634f09f8bee1ed12c56a9e3a8bc7
[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
35 #include "empathy-account-widget-salut.h"
36 #include "empathy-ui-utils.h"
37
38 typedef struct {
39         McAccount *account;
40         
41         GtkWidget *vbox_settings;
42         GtkWidget *entry_nickname;
43         GtkWidget *entry_published;
44         GtkWidget *entry_first_name;
45         GtkWidget *entry_last_name;
46         GtkWidget *entry_email;
47         GtkWidget *entry_jid;
48 } EmpathyAccountWidgetSalut;
49
50 static gboolean account_widget_salut_entry_focus_cb (GtkWidget                 *widget,
51                                                      GdkEventFocus             *event,
52                                                      EmpathyAccountWidgetSalut *settings);
53 static void     account_widget_salut_destroy_cb     (GtkWidget                 *widget,
54                                                      EmpathyAccountWidgetSalut *settings);
55 static void     account_widget_salut_setup          (EmpathyAccountWidgetSalut *settings);
56
57
58
59 static gboolean
60 account_widget_salut_entry_focus_cb (GtkWidget               *widget,
61                                      GdkEventFocus           *event,
62                                      EmpathyAccountWidgetSalut *settings)
63 {
64         const gchar *param;
65         const gchar *str;
66         
67         if (widget == settings->entry_nickname) {
68                 param = "nickname";
69         }
70         else if (widget == settings->entry_published) {
71                 param = "published-name";
72         }
73         else if (widget == settings->entry_first_name) {
74                 param = "first-name";
75         }
76         else if (widget == settings->entry_last_name) {
77                 param = "last-name";
78         }
79         else if (widget == settings->entry_email) {
80                 param = "email";
81         }
82         else if (widget == settings->entry_jid) {
83                 param = "jid";
84         }
85         else {
86                 return FALSE;
87         }
88         
89         str = gtk_entry_get_text (GTK_ENTRY (widget));
90         
91         if (G_STR_EMPTY (str)) {
92                 gchar *value = NULL;
93
94                 mc_account_get_param_string (settings->account, param, &value);
95                 gtk_entry_set_text (GTK_ENTRY (widget), value ? value : "");
96                 g_free (value);
97         } else {
98                 mc_account_set_param_string (settings->account, param, str);
99         }
100
101         return FALSE;
102 }
103
104 static void
105 account_widget_salut_destroy_cb (GtkWidget               *widget,
106                                  EmpathyAccountWidgetSalut *settings)
107 {
108         g_object_unref (settings->account);
109         g_free (settings);
110 }
111
112 static void
113 account_widget_salut_setup (EmpathyAccountWidgetSalut *settings)
114 {
115         gchar *nickname = NULL;
116         gchar *published_name = NULL;
117         gchar *first_name = NULL;
118         gchar *last_name = NULL;
119         gchar *email = NULL;
120         gchar *jid = NULL;
121
122         mc_account_get_param_string (settings->account, "nickname", &nickname);
123         mc_account_get_param_string (settings->account, "published-name", &published_name);
124         mc_account_get_param_string (settings->account, "first-name", &first_name);
125         mc_account_get_param_string (settings->account, "last-name", &last_name);
126         mc_account_get_param_string (settings->account, "email", &email);
127         mc_account_get_param_string (settings->account, "jid", &jid);
128         
129         gtk_entry_set_text (GTK_ENTRY (settings->entry_nickname), nickname ? nickname : "");
130         gtk_entry_set_text (GTK_ENTRY (settings->entry_published), published_name ? published_name : "");
131         gtk_entry_set_text (GTK_ENTRY (settings->entry_first_name), first_name ? first_name : "");
132         gtk_entry_set_text (GTK_ENTRY (settings->entry_last_name), last_name ? last_name : "");
133         gtk_entry_set_text (GTK_ENTRY (settings->entry_email), email ? email : "");
134         gtk_entry_set_text (GTK_ENTRY (settings->entry_jid), jid ? jid : "");
135
136         g_free (nickname);
137         g_free (published_name);
138         g_free (first_name);
139         g_free (last_name);
140         g_free (email);
141         g_free (jid);
142 }
143
144
145 GtkWidget *
146 empathy_account_widget_salut_new (McAccount *account)
147 {
148         EmpathyAccountWidgetSalut *settings;
149         GladeXML                  *glade;
150
151         settings = g_new0 (EmpathyAccountWidgetSalut, 1);
152         settings->account = g_object_ref (account);
153
154         glade = empathy_glade_get_file ("empathy-account-widget-salut.glade",
155                                         "vbox_salut_settings",
156                                         NULL,
157                                         "vbox_salut_settings", &settings->vbox_settings,
158                                         "entry_published", &settings->entry_published,
159                                         "entry_nickname", &settings->entry_nickname,
160                                         "entry_first_name", &settings->entry_first_name,
161                                         "entry_last_name", &settings->entry_last_name,
162                                         "entry_email", &settings->entry_email,
163                                         "entry_jid", &settings->entry_jid,
164                                         NULL);
165
166         account_widget_salut_setup (settings);
167
168         empathy_glade_connect (glade,
169                                settings,
170                                "vbox_salut_settings", "destroy", account_widget_salut_destroy_cb,
171                                "entry_nickname", "focus-out-event", account_widget_salut_entry_focus_cb,
172                                "entry_published", "focus-out-event", account_widget_salut_entry_focus_cb,
173                                "entry_first_name", "focus-out-event", account_widget_salut_entry_focus_cb,
174                                "entry_last_name", "focus-out-event", account_widget_salut_entry_focus_cb,
175                                "entry_email", "focus-out-event", account_widget_salut_entry_focus_cb,
176                                "entry_jid", "focus-out-event", account_widget_salut_entry_focus_cb,
177                               NULL);
178
179         g_object_unref (glade);
180
181         gtk_widget_show (settings->vbox_settings);
182
183         return settings->vbox_settings;
184 }