2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU Lesser General Public License as published by
4 * the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful, but
7 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 * Chris Toshok <toshok@ximian.com>
18 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
22 #include "evolution-config.h"
24 #include <glib/gi18n.h>
26 #include "e-util/e-util.h"
27 #include "e-util/e-util-private.h"
29 #include "e-contact-editor-fullname.h"
31 static void fill_in_info (EContactEditorFullname
*editor
);
32 static void extract_info (EContactEditorFullname
*editor
);
41 EContactEditorFullname
,
42 e_contact_editor_fullname
,
46 e_contact_editor_fullname_set_property (GObject
*object
,
51 EContactEditorFullname
*e_contact_editor_fullname
;
53 e_contact_editor_fullname
= E_CONTACT_EDITOR_FULLNAME (object
);
55 switch (property_id
) {
57 e_contact_name_free (e_contact_editor_fullname
->name
);
59 if (g_value_get_pointer (value
) != NULL
) {
60 e_contact_editor_fullname
->name
=
62 g_value_get_pointer (value
));
63 fill_in_info (e_contact_editor_fullname
);
66 e_contact_editor_fullname
->name
= NULL
;
73 const gchar
*widget_names
[] = {
87 editable
= g_value_get_boolean (value
);
88 e_contact_editor_fullname
->editable
= editable
;
90 for (i
= 0; widget_names
[i
] != NULL
; i
++) {
93 widget
= e_builder_get_widget (
94 e_contact_editor_fullname
->builder
,
97 if (GTK_IS_ENTRY (widget
)) {
98 gtk_editable_set_editable (
99 GTK_EDITABLE (widget
), editable
);
101 } else if (GTK_IS_COMBO_BOX (widget
)) {
104 child
= gtk_bin_get_child (GTK_BIN (widget
));
106 gtk_editable_set_editable (
107 GTK_EDITABLE (child
), editable
);
108 gtk_widget_set_sensitive (widget
, editable
);
110 } else if (GTK_IS_LABEL (widget
)) {
111 gtk_widget_set_sensitive (widget
, editable
);
117 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
123 e_contact_editor_fullname_get_property (GObject
*object
,
128 EContactEditorFullname
*e_contact_editor_fullname
;
130 e_contact_editor_fullname
= E_CONTACT_EDITOR_FULLNAME (object
);
132 switch (property_id
) {
134 extract_info (e_contact_editor_fullname
);
135 g_value_set_pointer (
136 value
, e_contact_name_copy (
137 e_contact_editor_fullname
->name
));
140 g_value_set_boolean (
141 value
, e_contact_editor_fullname
->editable
);
144 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
150 e_contact_editor_fullname_dispose (GObject
*object
)
152 EContactEditorFullname
*e_contact_editor_fullname
;
154 e_contact_editor_fullname
= E_CONTACT_EDITOR_FULLNAME (object
);
156 if (e_contact_editor_fullname
->builder
) {
157 g_object_unref (e_contact_editor_fullname
->builder
);
158 e_contact_editor_fullname
->builder
= NULL
;
161 if (e_contact_editor_fullname
->name
) {
162 e_contact_name_free (e_contact_editor_fullname
->name
);
163 e_contact_editor_fullname
->name
= NULL
;
166 /* Chain up to parent's dispose() method. */
167 G_OBJECT_CLASS (e_contact_editor_fullname_parent_class
)->dispose (object
);
171 e_contact_editor_fullname_class_init (EContactEditorFullnameClass
*class)
173 GObjectClass
*object_class
;
175 object_class
= G_OBJECT_CLASS (class);
176 object_class
->set_property
= e_contact_editor_fullname_set_property
;
177 object_class
->get_property
= e_contact_editor_fullname_get_property
;
178 object_class
->dispose
= e_contact_editor_fullname_dispose
;
180 g_object_class_install_property (
183 g_param_spec_pointer (
189 g_object_class_install_property (
192 g_param_spec_boolean (
201 e_contact_editor_fullname_init (EContactEditorFullname
*e_contact_editor_fullname
)
207 GtkWidget
*action_area
;
208 GtkWidget
*content_area
;
211 dialog
= GTK_DIALOG (e_contact_editor_fullname
);
212 action_area
= gtk_dialog_get_action_area (dialog
);
213 content_area
= gtk_dialog_get_content_area (dialog
);
215 gtk_container_set_border_width (GTK_CONTAINER (action_area
), 12);
216 gtk_container_set_border_width (GTK_CONTAINER (content_area
), 0);
218 gtk_dialog_add_buttons (
220 _("_Cancel"), GTK_RESPONSE_CANCEL
,
221 _("_OK"), GTK_RESPONSE_OK
, NULL
);
223 gtk_window_set_resizable (GTK_WINDOW (dialog
), TRUE
);
225 e_contact_editor_fullname
->name
= NULL
;
227 builder
= gtk_builder_new ();
228 e_load_ui_builder_definition (builder
, "fullname.ui");
230 e_contact_editor_fullname
->builder
= builder
;
232 widget
= e_builder_get_widget (builder
, "dialog-checkfullname");
233 title
= gtk_window_get_title (GTK_WINDOW (widget
));
234 gtk_window_set_title (GTK_WINDOW (e_contact_editor_fullname
), title
);
236 widget
= e_builder_get_widget (builder
, "table-checkfullname");
237 parent
= gtk_widget_get_parent (widget
);
238 g_object_ref (widget
);
239 gtk_container_remove (GTK_CONTAINER (parent
), widget
);
240 gtk_box_pack_start (GTK_BOX (content_area
), widget
, TRUE
, TRUE
, 0);
241 g_object_unref (widget
);
243 gtk_dialog_set_default_response (dialog
, GTK_RESPONSE_OK
);
245 gtk_window_set_icon_name (
246 GTK_WINDOW (e_contact_editor_fullname
), "contact-new");
250 e_contact_editor_fullname_new (GtkWindow
*parent
,
251 const EContactName
*name
)
253 GtkWidget
*widget
= g_object_new (E_TYPE_CONTACT_EDITOR_FULLNAME
,
254 "transient-for", parent
,
265 fill_in_field (EContactEditorFullname
*editor
,
269 GtkWidget
*widget
= e_builder_get_widget (editor
->builder
, field
);
270 GtkEntry
*entry
= NULL
;
272 if (GTK_IS_ENTRY (widget
))
273 entry
= GTK_ENTRY (widget
);
274 else if (GTK_IS_COMBO_BOX (widget
))
275 entry
= GTK_ENTRY (gtk_bin_get_child (GTK_BIN (widget
)));
279 gtk_entry_set_text (entry
, string
);
281 gtk_entry_set_text (entry
, "");
286 fill_in_info (EContactEditorFullname
*editor
)
288 EContactName
*name
= editor
->name
;
290 fill_in_field (editor
, "comboentry-title", name
->prefixes
);
291 fill_in_field (editor
, "entry-first", name
->given
);
292 fill_in_field (editor
, "entry-middle", name
->additional
);
293 fill_in_field (editor
, "entry-last", name
->family
);
294 fill_in_field (editor
, "comboentry-suffix", name
->suffixes
);
299 extract_field (EContactEditorFullname
*editor
,
302 GtkWidget
*widget
= e_builder_get_widget (editor
->builder
, field
);
303 GtkEntry
*entry
= NULL
;
305 if (GTK_IS_ENTRY (widget
))
306 entry
= GTK_ENTRY (widget
);
307 else if (GTK_IS_COMBO_BOX (widget
))
308 entry
= GTK_ENTRY (gtk_bin_get_child (GTK_BIN (widget
)));
311 return g_strdup (gtk_entry_get_text (entry
));
317 extract_info (EContactEditorFullname
*editor
)
319 EContactName
*name
= editor
->name
;
321 name
= e_contact_name_new ();
325 name
->prefixes
= extract_field (editor
, "comboentry-title");
326 name
->given
= extract_field (editor
, "entry-first");
327 name
->additional
= extract_field (editor
, "entry-middle");
328 name
->family
= extract_field (editor
, "entry-last");
329 name
->suffixes
= extract_field (editor
, "comboentry-suffix");