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>
29 #include <glib/gi18n-lib.h>
31 #include <telepathy-glib/util.h>
32 #include <folks/folks.h>
33 #include <folks/folks-telepathy.h>
35 #include <libempathy/empathy-individual-manager.h>
36 #include <libempathy/empathy-utils.h>
38 #include "empathy-individual-edit-dialog.h"
39 #include "empathy-individual-widget.h"
40 #include "empathy-ui-utils.h"
42 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualEditDialog)
45 FolksIndividual
*individual
; /* owned */
46 } EmpathyIndividualEditDialogPriv
;
52 /* Edit dialogs currently open.
53 * Each dialog contains a referenced pointer to its Individual */
54 static GList
*edit_dialogs
= NULL
;
56 G_DEFINE_TYPE (EmpathyIndividualEditDialog
, empathy_individual_edit_dialog
,
59 /* Fairly arbitrary response ID for the "Unlink" button */
60 #define RESPONSE_UNLINK 5
63 individual_dialogs_response_cb (GtkDialog
*dialog
,
67 if (response
== RESPONSE_UNLINK
)
69 EmpathyIndividualEditDialogPriv
*priv
= GET_PRIV (dialog
);
70 EmpathyIndividualManager
*manager
=
71 empathy_individual_manager_dup_singleton ();
73 empathy_individual_manager_unlink_individual (manager
, priv
->individual
);
75 g_object_unref (manager
);
78 *dialogs
= g_list_remove (*dialogs
, dialog
);
79 gtk_widget_destroy (GTK_WIDGET (dialog
));
83 individual_dialogs_find (GObject
*object
,
84 FolksIndividual
*individual
)
86 EmpathyIndividualEditDialogPriv
*priv
= GET_PRIV (object
);
88 return individual
!= priv
->individual
;
92 empathy_individual_edit_dialog_show (FolksIndividual
*individual
,
98 g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual
));
99 g_return_if_fail (parent
== NULL
|| GTK_IS_WINDOW (parent
));
101 l
= g_list_find_custom (edit_dialogs
, individual
,
102 (GCompareFunc
) individual_dialogs_find
);
106 gtk_window_present (GTK_WINDOW (l
->data
));
111 dialog
= g_object_new (EMPATHY_TYPE_INDIVIDUAL_EDIT_DIALOG
,
112 "individual", individual
,
115 edit_dialogs
= g_list_prepend (edit_dialogs
, dialog
);
116 gtk_widget_show (dialog
);
120 individual_edit_dialog_set_individual (
121 EmpathyIndividualEditDialog
*dialog
,
122 FolksIndividual
*individual
)
124 EmpathyIndividualEditDialogPriv
*priv
;
125 GtkWidget
*individual_widget
;
127 guint num_personas
= 0;
129 g_return_if_fail (EMPATHY_INDIVIDUAL_EDIT_DIALOG (dialog
));
130 g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual
));
132 priv
= GET_PRIV (dialog
);
134 /* Individual info widget */
135 individual_widget
= empathy_individual_widget_new (individual
,
136 EMPATHY_INDIVIDUAL_WIDGET_EDIT_ALIAS
|
137 EMPATHY_INDIVIDUAL_WIDGET_EDIT_GROUPS
|
138 EMPATHY_INDIVIDUAL_WIDGET_EDIT_FAVOURITE
);
139 gtk_container_set_border_width (GTK_CONTAINER (individual_widget
), 8);
140 gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (
141 GTK_DIALOG (dialog
))), individual_widget
, TRUE
, TRUE
, 0);
142 gtk_widget_show (individual_widget
);
144 /* Count how many Telepathy personas we have, to see whether we can
146 personas
= folks_individual_get_personas (individual
);
147 for (l
= personas
; l
!= NULL
; l
= l
->next
)
149 if (TPF_IS_PERSONA (l
->data
))
153 priv
->individual
= g_object_ref (individual
);
155 /* Only make the "Unlink" button sensitive if we have enough personas */
156 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog
), RESPONSE_UNLINK
,
157 (num_personas
> 1) ? TRUE
: FALSE
);
161 individual_edit_dialog_get_property (GObject
*object
,
166 EmpathyIndividualEditDialogPriv
*priv
= GET_PRIV (object
);
169 case PROP_INDIVIDUAL
:
170 g_value_set_object (value
, priv
->individual
);
173 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
179 individual_edit_dialog_set_property (GObject
*object
,
184 EmpathyIndividualEditDialog
*dialog
=
185 EMPATHY_INDIVIDUAL_EDIT_DIALOG (object
);
188 case PROP_INDIVIDUAL
:
189 individual_edit_dialog_set_individual (dialog
,
190 FOLKS_INDIVIDUAL (g_value_get_object (value
)));
193 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
199 individual_edit_dialog_dispose (GObject
*object
)
201 EmpathyIndividualEditDialogPriv
*priv
= GET_PRIV (object
);
203 if (priv
->individual
!= NULL
)
204 g_object_unref (priv
->individual
);
205 priv
->individual
= NULL
;
208 empathy_individual_edit_dialog_parent_class
)->dispose (object
);
212 empathy_individual_edit_dialog_class_init (
213 EmpathyIndividualEditDialogClass
*klass
)
215 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
217 object_class
->get_property
= individual_edit_dialog_get_property
;
218 object_class
->set_property
= individual_edit_dialog_set_property
;
219 object_class
->dispose
= individual_edit_dialog_dispose
;
221 g_object_class_install_property (object_class
,
223 g_param_spec_object ("individual",
225 "Folks Individual to edit using the dialog.",
226 FOLKS_TYPE_INDIVIDUAL
,
227 G_PARAM_CONSTRUCT_ONLY
|
229 G_PARAM_STATIC_STRINGS
));
231 g_type_class_add_private (object_class
,
232 sizeof (EmpathyIndividualEditDialogPriv
));
236 empathy_individual_edit_dialog_init (
237 EmpathyIndividualEditDialog
*dialog
)
239 GtkWidget
*button
, *action_area
;
240 EmpathyIndividualEditDialogPriv
*priv
= G_TYPE_INSTANCE_GET_PRIVATE (
241 dialog
, EMPATHY_TYPE_INDIVIDUAL_EDIT_DIALOG
,
242 EmpathyIndividualEditDialogPriv
);
245 priv
->individual
= NULL
;
247 gtk_dialog_set_has_separator (GTK_DIALOG (dialog
), FALSE
);
248 gtk_window_set_resizable (GTK_WINDOW (dialog
), FALSE
);
249 gtk_window_set_title (GTK_WINDOW (dialog
), _("Edit Contact Information"));
252 button
= gtk_button_new_with_mnemonic (
253 C_("Unlink individual (button)", "_Unlink"));
254 gtk_dialog_add_action_widget (GTK_DIALOG (dialog
), button
, RESPONSE_UNLINK
);
256 action_area
= gtk_dialog_get_action_area (GTK_DIALOG (dialog
));
257 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area
), button
,
260 gtk_widget_show (button
);
263 button
= gtk_button_new_with_label (GTK_STOCK_CLOSE
);
264 gtk_button_set_use_stock (GTK_BUTTON (button
), TRUE
);
265 gtk_dialog_add_action_widget (GTK_DIALOG (dialog
), button
,
267 gtk_widget_set_can_default (button
, TRUE
);
268 gtk_window_set_default (GTK_WINDOW (dialog
), button
);
269 gtk_widget_show (button
);
271 g_signal_connect (dialog
, "response",
272 G_CALLBACK (individual_dialogs_response_cb
), &edit_dialogs
);