2 * empathy-invite-participant-dialog.c
4 * EmpathyInviteParticipantDialog
6 * (c) 2009, Collabora Ltd.
9 * Danielle Madeley <danielle.madeley@collabora.co.uk>
12 #include <glib/gi18n.h>
13 #include <folks/folks-telepathy.h>
15 #include "empathy-invite-participant-dialog.h"
17 #include <libempathy-gtk/empathy-contact-chooser.h>
18 #include <libempathy-gtk/empathy-individual-view.h>
19 #include <libempathy-gtk/empathy-ui-utils.h>
21 G_DEFINE_TYPE (EmpathyInviteParticipantDialog,
22 empathy_invite_participant_dialog, GTK_TYPE_DIALOG);
29 struct _EmpathyInviteParticipantDialogPrivate
31 EmpathyTpChat *tp_chat;
34 GtkWidget *invite_button;
38 invite_participant_dialog_get_property (GObject *object,
43 EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
49 g_value_set_object (value, self->priv->tp_chat);
52 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
58 invite_participant_dialog_set_property (GObject *object,
63 EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
69 g_assert (self->priv->tp_chat == NULL); /* construct-only */
70 self->priv->tp_chat = g_value_dup_object (value);
73 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
79 invite_participant_dialog_dispose (GObject *object)
81 EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
84 tp_clear_object (&self->priv->tp_chat);
86 G_OBJECT_CLASS (empathy_invite_participant_dialog_parent_class)->dispose (
91 selection_changed_cb (GtkWidget *treeview,
92 FolksIndividual *selected,
93 EmpathyInviteParticipantDialog *self)
95 gtk_widget_set_sensitive (self->priv->invite_button, selected != NULL);
98 /* Return the TpContact of @individual which is on the same connection as the
101 get_tp_contact_for_chat (EmpathyInviteParticipantDialog *self,
102 FolksIndividual *individual)
104 TpContact *contact = NULL;
105 TpConnection *chat_conn;
109 chat_conn = tp_channel_borrow_connection (TP_CHANNEL (self->priv->tp_chat));
111 personas = folks_individual_get_personas (individual);
112 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
113 while (contact == FALSE && gee_iterator_next (iter))
115 TpfPersona *persona = gee_iterator_get (iter);
116 TpConnection *contact_conn;
117 TpContact *contact_cur = NULL;
119 if (TPF_IS_PERSONA (persona))
121 contact_cur = tpf_persona_get_contact (persona);
122 if (contact_cur != NULL)
124 contact_conn = tp_contact_get_connection (contact_cur);
126 if (!tp_strdiff (tp_proxy_get_object_path (contact_conn),
127 tp_proxy_get_object_path (chat_conn)))
128 contact = contact_cur;
132 g_clear_object (&persona);
134 g_clear_object (&iter);
140 filter_individual (EmpathyContactChooser *chooser,
141 FolksIndividual *individual,
146 EmpathyInviteParticipantDialog *self = user_data;
149 gboolean display = TRUE;
151 /* Filter out offline contacts if we are not searching */
152 if (!searching && !is_online)
155 /* Filter out individuals not having a persona on the same connection as the
157 contact = get_tp_contact_for_chat (self, individual);
162 /* Filter out contacts which are already in the chat */
163 members = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (
164 self->priv->tp_chat));
166 for (l = members; l != NULL; l = g_list_next (l))
168 EmpathyContact *member = l->data;
171 /* Try to get the non-channel specific handle. */
172 handle = tp_channel_group_get_handle_owner (
173 TP_CHANNEL (self->priv->tp_chat),
174 empathy_contact_get_handle (member));
176 handle = empathy_contact_get_handle (member);
178 if (handle == tp_contact_get_handle (contact))
185 g_list_free_full (members, g_object_unref);
191 invite_participant_dialog_constructed (GObject *object)
193 EmpathyInviteParticipantDialog *self =
194 (EmpathyInviteParticipantDialog *) object;
195 GtkDialog *dialog = GTK_DIALOG (self);
200 content = gtk_dialog_get_content_area (dialog);
202 label = gtk_label_new (NULL);
203 str = g_strdup_printf (
204 "<span size=\"x-large\" weight=\"bold\">%s</span>\n\n%s",
205 _("Invite Participant"),
206 _("Choose a contact to invite into the conversation:"));
207 gtk_label_set_markup (GTK_LABEL (label), str);
210 gtk_box_pack_start (GTK_BOX (content), label, FALSE, TRUE, 6);
211 gtk_widget_show (label);
213 gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
215 /* contact chooser */
216 self->priv->chooser = empathy_contact_chooser_new ();
218 empathy_contact_chooser_set_filter_func (
219 EMPATHY_CONTACT_CHOOSER (self->priv->chooser), filter_individual, self);
221 gtk_box_pack_start (GTK_BOX (content), self->priv->chooser, TRUE, TRUE, 6);
222 gtk_widget_show (self->priv->chooser);
224 g_signal_connect (self->priv->chooser, "selection-changed",
225 G_CALLBACK (selection_changed_cb), self);
227 self->priv->invite_button = gtk_dialog_add_button (dialog, _("Invite"),
228 GTK_RESPONSE_ACCEPT);
229 gtk_widget_set_sensitive (self->priv->invite_button, FALSE);
231 gtk_window_set_title (GTK_WINDOW (self), _("Invite Participant"));
232 gtk_window_set_role (GTK_WINDOW (self), "invite_participant");
234 /* Set a default height so a few contacts are displayed */
235 gtk_window_set_default_size (GTK_WINDOW (self), -1, 400);
239 empathy_invite_participant_dialog_class_init (
240 EmpathyInviteParticipantDialogClass *klass)
242 GObjectClass *object_class = G_OBJECT_CLASS (klass);
244 object_class->get_property = invite_participant_dialog_get_property;
245 object_class->set_property = invite_participant_dialog_set_property;
246 object_class->constructed = invite_participant_dialog_constructed;
247 object_class->dispose = invite_participant_dialog_dispose;
249 g_type_class_add_private (object_class,
250 sizeof (EmpathyInviteParticipantDialogPrivate));
252 g_object_class_install_property (object_class,
254 g_param_spec_object ("tp-chat", "EmpathyTpChat", "EmpathyTpChat",
255 EMPATHY_TYPE_TP_CHAT,
256 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
260 empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
262 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (
263 self, EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
264 EmpathyInviteParticipantDialogPrivate);
268 empathy_invite_participant_dialog_new (GtkWindow *parent,
269 EmpathyTpChat *tp_chat)
271 GtkWidget *self = g_object_new (EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
277 gtk_window_set_transient_for (GTK_WINDOW (self), parent);
284 empathy_invite_participant_dialog_get_selected (
285 EmpathyInviteParticipantDialog *self)
287 FolksIndividual *individual;
290 individual = empathy_contact_chooser_dup_selected (
291 EMPATHY_CONTACT_CHOOSER (self->priv->chooser));
292 if (individual == NULL)
295 contact = get_tp_contact_for_chat (self, individual);
297 g_object_unref (individual);