2 * Copyright (C) 2007-2010 Collabora Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Xavier Claessens <xclaesse@gmail.com>
19 * Philip Withnall <philip.withnall@collabora.co.uk>
20 * Travis Reitter <travis.reitter@collabora.co.uk>
24 #include "empathy-individual-edit-dialog.h"
26 #include <glib/gi18n-lib.h>
28 #include "empathy-individual-widget.h"
29 #include "empathy-utils.h"
31 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualEditDialog)
34 FolksIndividual
*individual
; /* owned */
35 GtkWidget
*individual_widget
; /* child widget */
36 } EmpathyIndividualEditDialogPriv
;
42 /* Edit dialogs currently open.
43 * Each dialog contains a referenced pointer to its Individual */
44 static GList
*edit_dialogs
= NULL
;
46 static void individual_edit_dialog_set_individual (
47 EmpathyIndividualEditDialog
*dialog
,
48 FolksIndividual
*individual
);
50 G_DEFINE_TYPE (EmpathyIndividualEditDialog
, empathy_individual_edit_dialog
,
54 individual_dialogs_response_cb (GtkDialog
*dialog
,
58 *dialogs
= g_list_remove (*dialogs
, dialog
);
59 gtk_widget_destroy (GTK_WIDGET (dialog
));
63 individual_dialogs_find (GObject
*object
,
64 FolksIndividual
*individual
)
66 EmpathyIndividualEditDialogPriv
*priv
= GET_PRIV (object
);
68 return individual
!= priv
->individual
;
72 empathy_individual_edit_dialog_show (FolksIndividual
*individual
,
78 g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual
));
79 g_return_if_fail (parent
== NULL
|| GTK_IS_WINDOW (parent
));
81 l
= g_list_find_custom (edit_dialogs
, individual
,
82 (GCompareFunc
) individual_dialogs_find
);
86 gtk_window_present (GTK_WINDOW (l
->data
));
91 dialog
= g_object_new (EMPATHY_TYPE_INDIVIDUAL_EDIT_DIALOG
,
92 "individual", individual
,
95 edit_dialogs
= g_list_prepend (edit_dialogs
, dialog
);
96 gtk_widget_show (dialog
);
100 individual_removed_cb (FolksIndividual
*individual
,
101 FolksIndividual
*replacement_individual
,
102 EmpathyIndividualEditDialog
*self
)
104 /* Update to show the new Individual (this will close the dialogue if there
105 * is no new Individual). */
106 individual_edit_dialog_set_individual (self
, replacement_individual
);
108 /* Destroy the dialogue */
109 if (replacement_individual
== NULL
)
111 individual_dialogs_response_cb (GTK_DIALOG (self
),
112 GTK_RESPONSE_DELETE_EVENT
, &edit_dialogs
);
117 individual_edit_dialog_set_individual (
118 EmpathyIndividualEditDialog
*dialog
,
119 FolksIndividual
*individual
)
121 EmpathyIndividualEditDialogPriv
*priv
;
123 g_return_if_fail (EMPATHY_INDIVIDUAL_EDIT_DIALOG (dialog
));
124 g_return_if_fail (individual
== NULL
|| FOLKS_IS_INDIVIDUAL (individual
));
126 priv
= GET_PRIV (dialog
);
128 /* Remove the old Individual */
129 if (priv
->individual
!= NULL
)
131 g_signal_handlers_disconnect_by_func (priv
->individual
,
132 (GCallback
) individual_removed_cb
, dialog
);
135 tp_clear_object (&priv
->individual
);
137 /* Add the new Individual */
138 priv
->individual
= individual
;
140 if (individual
!= NULL
)
142 g_object_ref (individual
);
143 g_signal_connect (individual
, "removed",
144 (GCallback
) individual_removed_cb
, dialog
);
147 empathy_individual_widget_set_individual (
148 EMPATHY_INDIVIDUAL_WIDGET (priv
->individual_widget
), individual
);
153 individual_edit_dialog_get_property (GObject
*object
,
158 EmpathyIndividualEditDialogPriv
*priv
= GET_PRIV (object
);
161 case PROP_INDIVIDUAL
:
162 g_value_set_object (value
, priv
->individual
);
165 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
171 individual_edit_dialog_set_property (GObject
*object
,
176 EmpathyIndividualEditDialog
*dialog
=
177 EMPATHY_INDIVIDUAL_EDIT_DIALOG (object
);
180 case PROP_INDIVIDUAL
:
181 individual_edit_dialog_set_individual (dialog
,
182 FOLKS_INDIVIDUAL (g_value_get_object (value
)));
185 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
191 individual_edit_dialog_dispose (GObject
*object
)
193 individual_edit_dialog_set_individual (
194 EMPATHY_INDIVIDUAL_EDIT_DIALOG (object
), NULL
);
197 empathy_individual_edit_dialog_parent_class
)->dispose (object
);
201 empathy_individual_edit_dialog_class_init (
202 EmpathyIndividualEditDialogClass
*klass
)
204 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
206 object_class
->get_property
= individual_edit_dialog_get_property
;
207 object_class
->set_property
= individual_edit_dialog_set_property
;
208 object_class
->dispose
= individual_edit_dialog_dispose
;
210 g_object_class_install_property (object_class
,
212 g_param_spec_object ("individual",
214 "Folks Individual to edit using the dialog.",
215 FOLKS_TYPE_INDIVIDUAL
,
216 G_PARAM_CONSTRUCT_ONLY
|
218 G_PARAM_STATIC_STRINGS
));
220 g_type_class_add_private (object_class
,
221 sizeof (EmpathyIndividualEditDialogPriv
));
225 empathy_individual_edit_dialog_init (
226 EmpathyIndividualEditDialog
*dialog
)
229 EmpathyIndividualEditDialogPriv
*priv
= G_TYPE_INSTANCE_GET_PRIVATE (
230 dialog
, EMPATHY_TYPE_INDIVIDUAL_EDIT_DIALOG
,
231 EmpathyIndividualEditDialogPriv
);
234 priv
->individual
= NULL
;
236 gtk_window_set_resizable (GTK_WINDOW (dialog
), FALSE
);
237 gtk_window_set_title (GTK_WINDOW (dialog
), _("Edit Contact Information"));
239 /* Individual widget */
240 priv
->individual_widget
= empathy_individual_widget_new (priv
->individual
,
241 EMPATHY_INDIVIDUAL_WIDGET_EDIT_ALIAS
|
242 EMPATHY_INDIVIDUAL_WIDGET_EDIT_GROUPS
|
243 EMPATHY_INDIVIDUAL_WIDGET_EDIT_FAVOURITE
);
244 gtk_container_set_border_width (GTK_CONTAINER (priv
->individual_widget
), 8);
245 gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (
246 GTK_DIALOG (dialog
))), priv
->individual_widget
, TRUE
, TRUE
, 0);
247 gtk_widget_show (priv
->individual_widget
);
250 button
= gtk_button_new_with_label (GTK_STOCK_CLOSE
);
251 gtk_button_set_use_stock (GTK_BUTTON (button
), TRUE
);
252 gtk_dialog_add_action_widget (GTK_DIALOG (dialog
), button
,
254 gtk_widget_set_can_default (button
, TRUE
);
255 gtk_window_set_default (GTK_WINDOW (dialog
), button
);
256 gtk_widget_show (button
);
258 g_signal_connect (dialog
, "response",
259 G_CALLBACK (individual_dialogs_response_cb
), &edit_dialogs
);