1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2010 Collabora Ltd.
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.
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.
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
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
20 * Philip Withnall <philip.withnall@collabora.co.uk>
21 * Travis Reitter <travis.reitter@collabora.co.uk>
30 #include <glib/gi18n-lib.h>
32 #include <telepathy-glib/util.h>
33 #include <folks/folks.h>
34 #include <folks/folks-telepathy.h>
36 #include <libempathy/empathy-individual-manager.h>
37 #include <libempathy/empathy-utils.h>
39 #include "empathy-individual-information-dialog.h"
40 #include "empathy-individual-widget.h"
41 #include "empathy-ui-utils.h"
43 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualInformationDialog)
45 FolksIndividual
*individual
;
46 GtkWidget
*individual_widget
; /* child widget */
47 GtkWidget
*label
; /* child widget */
48 } EmpathyIndividualInformationDialogPriv
;
55 /* Info dialogs currently open.
56 * Each dialog contains a referenced pointer to its Individual */
57 static GList
*information_dialogs
= NULL
;
59 static void individual_information_dialog_set_individual (
60 EmpathyIndividualInformationDialog
*dialog
,
61 FolksIndividual
*individual
);
63 G_DEFINE_TYPE (EmpathyIndividualInformationDialog
,
64 empathy_individual_information_dialog
, GTK_TYPE_DIALOG
);
67 individual_dialogs_response_cb (GtkDialog
*dialog
,
71 *dialogs
= g_list_remove (*dialogs
, dialog
);
72 gtk_widget_destroy (GTK_WIDGET (dialog
));
76 individual_dialogs_find (GObject
*object
,
77 FolksIndividual
*individual
)
79 EmpathyIndividualInformationDialogPriv
*priv
= GET_PRIV (object
);
81 return individual
!= priv
->individual
;
85 empathy_individual_information_dialog_show (FolksIndividual
*individual
,
91 g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual
));
92 g_return_if_fail (parent
== NULL
|| GTK_IS_WINDOW (parent
));
94 l
= g_list_find_custom (information_dialogs
, individual
,
95 (GCompareFunc
) individual_dialogs_find
);
99 gtk_window_present (GTK_WINDOW (l
->data
));
104 dialog
= g_object_new (EMPATHY_TYPE_INDIVIDUAL_INFORMATION_DIALOG
,
105 "individual", individual
,
108 information_dialogs
= g_list_prepend (information_dialogs
, dialog
);
109 gtk_widget_show (dialog
);
113 individual_removed_cb (FolksIndividual
*individual
,
114 FolksIndividual
*replacement_individual
,
115 EmpathyIndividualInformationDialog
*self
)
117 individual_information_dialog_set_individual (self
,
118 replacement_individual
);
120 /* Destroy the dialogue */
121 if (replacement_individual
== NULL
)
123 individual_dialogs_response_cb (GTK_DIALOG (self
),
124 GTK_RESPONSE_DELETE_EVENT
, &information_dialogs
);
129 set_label_visibility (EmpathyIndividualInformationDialog
*dialog
)
131 EmpathyIndividualInformationDialogPriv
*priv
= GET_PRIV (dialog
);
132 guint num_personas
= 0;
134 /* Count how many Telepathy personas we have, to see whether we can
136 if (priv
->individual
!= NULL
)
141 personas
= folks_individual_get_personas (priv
->individual
);
142 iter
= gee_iterable_iterator (GEE_ITERABLE (personas
));
143 while (gee_iterator_next (iter
))
145 FolksPersona
*persona
= gee_iterator_get (iter
);
146 if (empathy_folks_persona_is_interesting (persona
))
149 g_clear_object (&persona
);
151 g_clear_object (&iter
);
154 /* Only make the label visible if we have enough personas */
155 gtk_widget_set_visible (priv
->label
, (num_personas
> 1) ? TRUE
: FALSE
);
159 individual_information_dialog_set_individual (
160 EmpathyIndividualInformationDialog
*dialog
,
161 FolksIndividual
*individual
)
163 EmpathyIndividualInformationDialogPriv
*priv
;
165 g_return_if_fail (EMPATHY_INDIVIDUAL_INFORMATION_DIALOG (dialog
));
166 g_return_if_fail (individual
== NULL
|| FOLKS_IS_INDIVIDUAL (individual
));
168 priv
= GET_PRIV (dialog
);
170 /* Remove the old Individual */
171 if (priv
->individual
!= NULL
)
173 g_signal_handlers_disconnect_by_func (priv
->individual
,
174 (GCallback
) individual_removed_cb
, dialog
);
177 tp_clear_object (&priv
->individual
);
179 /* Add the new Individual */
180 priv
->individual
= individual
;
182 if (individual
!= NULL
)
184 g_object_ref (individual
);
185 g_signal_connect (individual
, "removed",
186 (GCallback
) individual_removed_cb
, dialog
);
189 gtk_window_set_title (GTK_WINDOW (dialog
),
190 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual
)));
191 empathy_individual_widget_set_individual (
192 EMPATHY_INDIVIDUAL_WIDGET (priv
->individual_widget
), individual
);
193 set_label_visibility (dialog
);
198 individual_information_dialog_get_property (GObject
*object
,
203 EmpathyIndividualInformationDialogPriv
*priv
= GET_PRIV (object
);
206 case PROP_INDIVIDUAL
:
207 g_value_set_object (value
, priv
->individual
);
210 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
216 individual_information_dialog_set_property (GObject
*object
,
221 EmpathyIndividualInformationDialog
*dialog
=
222 EMPATHY_INDIVIDUAL_INFORMATION_DIALOG (object
);
225 case PROP_INDIVIDUAL
:
226 individual_information_dialog_set_individual (dialog
,
227 FOLKS_INDIVIDUAL (g_value_get_object (value
)));
230 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
236 individual_information_dialog_dispose (GObject
*object
)
238 individual_information_dialog_set_individual (
239 EMPATHY_INDIVIDUAL_INFORMATION_DIALOG (object
), NULL
);
242 empathy_individual_information_dialog_parent_class
)->dispose (object
);
246 empathy_individual_information_dialog_class_init (
247 EmpathyIndividualInformationDialogClass
*klass
)
249 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
251 object_class
->dispose
= individual_information_dialog_dispose
;
252 object_class
->get_property
= individual_information_dialog_get_property
;
253 object_class
->set_property
= individual_information_dialog_set_property
;
255 g_object_class_install_property (object_class
,
257 g_param_spec_object ("individual",
259 "Folks Individual to base the dialog upon",
260 FOLKS_TYPE_INDIVIDUAL
,
263 G_PARAM_STATIC_STRINGS
));
265 g_type_class_add_private (object_class
,
266 sizeof (EmpathyIndividualInformationDialogPriv
));
270 empathy_individual_information_dialog_init (
271 EmpathyIndividualInformationDialog
*dialog
)
274 GtkBox
*content_area
;
276 EmpathyIndividualInformationDialogPriv
*priv
= G_TYPE_INSTANCE_GET_PRIVATE (
277 dialog
, EMPATHY_TYPE_INDIVIDUAL_INFORMATION_DIALOG
,
278 EmpathyIndividualInformationDialogPriv
);
281 priv
->individual
= NULL
;
283 gtk_window_set_resizable (GTK_WINDOW (dialog
), TRUE
);
285 content_area
= GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog
)));
287 /* Translators: the heading at the top of the Information dialogue */
288 label_string
= g_strdup_printf ("<b>%s</b>", _("Linked Contacts"));
289 priv
->label
= gtk_label_new (NULL
);
290 gtk_label_set_markup (GTK_LABEL (priv
->label
), label_string
);
291 g_free (label_string
);
293 gtk_misc_set_alignment (GTK_MISC (priv
->label
), 0.0, 0.5);
294 gtk_misc_set_padding (GTK_MISC (priv
->label
), 6, 6);
295 gtk_box_pack_start (content_area
, priv
->label
, FALSE
, TRUE
, 0);
296 gtk_widget_show (priv
->label
);
298 /* Individual widget */
299 priv
->individual_widget
= empathy_individual_widget_new (priv
->individual
,
300 EMPATHY_INDIVIDUAL_WIDGET_SHOW_LOCATION
|
301 EMPATHY_INDIVIDUAL_WIDGET_SHOW_DETAILS
|
302 EMPATHY_INDIVIDUAL_WIDGET_SHOW_PERSONAS
);
303 gtk_container_set_border_width (GTK_CONTAINER (priv
->individual_widget
), 6);
304 gtk_box_pack_start (content_area
, priv
->individual_widget
, TRUE
, TRUE
, 0);
305 gtk_widget_show (priv
->individual_widget
);
308 button
= gtk_button_new_with_label (GTK_STOCK_CLOSE
);
309 gtk_button_set_use_stock (GTK_BUTTON (button
), TRUE
);
310 gtk_dialog_add_action_widget (GTK_DIALOG (dialog
), button
,
312 gtk_widget_set_can_default (button
, TRUE
);
313 gtk_window_set_default (GTK_WINDOW (dialog
), button
);
314 gtk_widget_show (button
);
316 g_signal_connect (dialog
, "response",
317 G_CALLBACK (individual_dialogs_response_cb
), &information_dialogs
);