2 * Copyright (C) 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: Philip Withnall <philip.withnall@collabora.co.uk>
27 #include <glib/gi18n-lib.h>
29 #include <telepathy-glib/util.h>
31 #include <libempathy/empathy-utils.h>
33 #include <folks/folks-telepathy.h>
35 #include "empathy-individual-widget.h"
36 #include "empathy-gtk-enum-types.h"
39 * SECTION:empathy-individual-widget
40 * @title:EmpathyIndividualWidget
41 * @short_description: A widget used to display and edit details about an
43 * @include: libempathy-empathy-individual-widget.h
45 * #EmpathyIndividualWidget is a widget which displays appropriate widgets
46 * with details about an individual, also allowing changing these details,
51 * EmpathyIndividualWidget:
52 * @parent: parent object
54 * Widget which displays appropriate widgets with details about an individual,
55 * also allowing changing these details, if desired.
57 * Currently, it's just a thin wrapper around #EmpathyContactWidget, and
58 * displays the details of the first eligible persona found in the individual.
61 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualWidget)
64 FolksIndividual
*individual
;
65 EmpathyIndividualWidgetFlags flags
;
66 } EmpathyIndividualWidgetPriv
;
68 G_DEFINE_TYPE (EmpathyIndividualWidget
, empathy_individual_widget
,
77 empathy_individual_widget_init (EmpathyIndividualWidget
*self
)
79 self
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (self
,
80 EMPATHY_TYPE_INDIVIDUAL_WIDGET
, EmpathyIndividualWidgetPriv
);
82 gtk_orientable_set_orientation (GTK_ORIENTABLE (self
),
83 GTK_ORIENTATION_VERTICAL
);
87 get_property (GObject
*object
,
92 EmpathyIndividualWidgetPriv
*priv
= GET_PRIV (object
);
97 g_value_set_object (value
, priv
->individual
);
100 g_value_set_flags (value
, priv
->flags
);
103 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
109 set_property (GObject
*object
,
114 EmpathyIndividualWidgetPriv
*priv
= GET_PRIV (object
);
118 case PROP_INDIVIDUAL
:
119 empathy_individual_widget_set_individual (
120 EMPATHY_INDIVIDUAL_WIDGET (object
), g_value_get_object (value
));
123 priv
->flags
= g_value_get_flags (value
);
126 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
132 dispose (GObject
*object
)
134 EmpathyIndividualWidgetPriv
*priv
= GET_PRIV (object
);
136 tp_clear_object (&priv
->individual
);
138 G_OBJECT_CLASS (empathy_individual_widget_parent_class
)->dispose (object
);
142 empathy_individual_widget_class_init (EmpathyIndividualWidgetClass
*klass
)
144 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
146 object_class
->get_property
= get_property
;
147 object_class
->set_property
= set_property
;
148 object_class
->dispose
= dispose
;
151 * EmpathyIndividualWidget:individual:
153 * The #FolksIndividual to display in the widget.
155 g_object_class_install_property (object_class
, PROP_INDIVIDUAL
,
156 g_param_spec_object ("individual",
158 "The #FolksIndividual to display in the widget.",
159 FOLKS_TYPE_INDIVIDUAL
,
160 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
163 * EmpathyIndividualWidget:flags:
165 * A set of flags which affect the widget's behaviour.
167 g_object_class_install_property (object_class
, PROP_FLAGS
,
168 g_param_spec_flags ("flags",
170 "A set of flags which affect the widget's behaviour.",
171 EMPATHY_TYPE_INDIVIDUAL_WIDGET_FLAGS
,
172 EMPATHY_INDIVIDUAL_WIDGET_EDIT_NONE
,
173 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT_ONLY
));
175 g_type_class_add_private (object_class
, sizeof (EmpathyIndividualWidgetPriv
));
179 * empathy_individual_widget_new:
180 * @individual: the #FolksIndividual to display
181 * @flags: flags affecting how the widget behaves and what it displays
183 * Creates a new #EmpathyIndividualWidget.
185 * Return value: a new #EmpathyIndividualWidget
188 empathy_individual_widget_new (FolksIndividual
*individual
,
189 EmpathyIndividualWidgetFlags flags
)
191 g_return_val_if_fail (individual
== NULL
|| FOLKS_IS_INDIVIDUAL (individual
),
194 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_WIDGET
,
195 "individual", individual
, "flags", flags
, NULL
);
199 empathy_individual_widget_get_individual (EmpathyIndividualWidget
*self
)
201 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_WIDGET (self
), NULL
);
203 return GET_PRIV (self
)->individual
;
207 empathy_individual_widget_set_individual (EmpathyIndividualWidget
*self
,
208 FolksIndividual
*individual
)
210 EmpathyIndividualWidgetPriv
*priv
;
211 GList
*personas
= NULL
, *l
;
213 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_WIDGET (self
));
214 g_return_if_fail (individual
== NULL
|| FOLKS_IS_INDIVIDUAL (individual
));
216 priv
= GET_PRIV (self
);
218 /* Out with the old… */
219 gtk_container_foreach (GTK_CONTAINER (self
), (GtkCallback
) gtk_widget_destroy
,
221 tp_clear_object (&priv
->individual
);
223 /* …and in with the new. */
224 priv
->individual
= individual
;
225 if (individual
!= NULL
)
227 g_object_ref (individual
);
228 personas
= folks_individual_get_personas (individual
);
231 for (l
= personas
; l
!= NULL
; l
= l
->next
)
233 GtkWidget
*contact_widget
;
234 TpContact
*tp_contact
;
235 EmpathyContact
*contact
;
236 TpfPersona
*persona
= l
->data
;
238 if (!TPF_IS_PERSONA (persona
))
241 tp_contact
= tpf_persona_get_contact (persona
);
242 contact
= empathy_contact_dup_from_tp_contact (tp_contact
);
244 /* Contact info widget */
245 contact_widget
= empathy_contact_widget_new (contact
, priv
->flags
);
246 gtk_container_set_border_width (GTK_CONTAINER (contact_widget
), 8);
247 gtk_box_pack_start (GTK_BOX (self
), contact_widget
, TRUE
, TRUE
, 0);
248 gtk_widget_show (contact_widget
);
250 g_object_unref (contact
);
252 /* If we're not meant to display all of the personas, bail after the first
254 if (!(priv
->flags
& EMPATHY_INDIVIDUAL_WIDGET_SHOW_PERSONAS
))