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