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-individual-view.h>
18 #include <libempathy-gtk/empathy-ui-utils.h>
20 G_DEFINE_TYPE (EmpathyInviteParticipantDialog,
21 empathy_invite_participant_dialog, GTK_TYPE_DIALOG);
28 struct _EmpathyInviteParticipantDialogPrivate
30 EmpathyTpChat *tp_chat;
32 EmpathyIndividualStore *store;
33 EmpathyIndividualView *view;
35 GtkWidget *invite_button;
37 GPtrArray *search_words;
41 invite_participant_dialog_get_property (GObject *object,
46 EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
52 g_value_set_object (value, self->priv->tp_chat);
55 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
61 invite_participant_dialog_set_property (GObject *object,
66 EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
72 g_assert (self->priv->tp_chat == NULL); /* construct-only */
73 self->priv->tp_chat = g_value_dup_object (value);
76 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
82 invite_participant_dialog_dispose (GObject *object)
84 EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
87 tp_clear_object (&self->priv->tp_chat);
88 tp_clear_object (&self->priv->store);
89 tp_clear_pointer (&self->priv->search_words, g_ptr_array_unref);
91 G_OBJECT_CLASS (empathy_invite_participant_dialog_parent_class)->dispose (
96 empathy_invite_participant_dialog_class_init (
97 EmpathyInviteParticipantDialogClass *klass)
99 GObjectClass *object_class = G_OBJECT_CLASS (klass);
101 object_class->get_property = invite_participant_dialog_get_property;
102 object_class->set_property = invite_participant_dialog_set_property;
103 object_class->dispose = invite_participant_dialog_dispose;
105 g_type_class_add_private (object_class,
106 sizeof (EmpathyInviteParticipantDialogPrivate));
108 g_object_class_install_property (object_class,
110 g_param_spec_object ("tp-chat", "EmpathyTpChat", "EmpathyTpChat",
111 EMPATHY_TYPE_TP_CHAT,
112 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
116 view_selection_changed_cb (GtkWidget *treeview,
117 EmpathyInviteParticipantDialog *self)
119 FolksIndividual *individual;
121 individual = empathy_individual_view_dup_selected (self->priv->view);
123 gtk_widget_set_sensitive (self->priv->invite_button, individual != NULL);
125 tp_clear_object (&individual);
128 /* Return the TpContact of @individual which is on the same connection as the
131 get_tp_contact_for_chat (EmpathyInviteParticipantDialog *self,
132 FolksIndividual *individual)
135 TpConnection *chat_conn;
137 chat_conn = tp_channel_borrow_connection ((TpChannel *) self->priv->tp_chat);
139 personas = folks_individual_get_personas (individual);
141 for (l = personas; l != NULL; l = g_list_next (l))
143 TpfPersona *persona = l->data;
145 TpConnection *contact_conn;
147 if (!TPF_IS_PERSONA (persona))
150 contact = tpf_persona_get_contact (persona);
154 contact_conn = tp_contact_get_connection (contact);
156 if (!tp_strdiff (tp_proxy_get_object_path (contact_conn),
157 tp_proxy_get_object_path (chat_conn)))
165 filter_func (GtkTreeModel *model,
169 EmpathyInviteParticipantDialog *self = user_data;
170 FolksIndividual *individual;
174 gboolean display = FALSE;
176 gtk_tree_model_get (model, iter,
177 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
178 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &is_online,
181 if (individual == NULL)
184 if (self->priv->search_words == NULL)
186 /* Not searching, display online contacts */
192 if (!empathy_individual_match_words (individual,
193 self->priv->search_words))
197 /* Filter out individuals not having a persona on the same connection as the
199 contact = get_tp_contact_for_chat (self, individual);
204 /* Filter out contacts which are already in the chat */
205 members = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (
206 self->priv->tp_chat));
210 for (l = members; l != NULL; l = g_list_next (l))
212 EmpathyContact *member = l->data;
215 /* Try to get the non-channel specific handle. */
216 handle = tp_channel_group_get_handle_owner (
217 TP_CHANNEL (self->priv->tp_chat),
218 empathy_contact_get_handle (member));
220 handle = empathy_contact_get_handle (member);
222 if (handle == tp_contact_get_handle (contact))
229 g_list_free_full (members, g_object_unref);
232 tp_clear_object (&individual);
237 search_text_changed (GtkEntry *entry,
238 EmpathyInviteParticipantDialog *self)
240 tp_clear_pointer (&self->priv->search_words, g_ptr_array_unref);
242 self->priv->search_words = empathy_live_search_strip_utf8_string (
243 gtk_entry_get_text (entry));
245 empathy_individual_view_refilter (self->priv->view);
249 empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
251 GtkDialog *dialog = GTK_DIALOG (self);
255 EmpathyIndividualManager *mgr;
256 GtkTreeSelection *selection;
258 GtkWidget *search_entry;
260 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (
261 self, EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
262 EmpathyInviteParticipantDialogPrivate);
264 content = gtk_dialog_get_content_area (dialog);
266 label = gtk_label_new (NULL);
267 str = g_strdup_printf (
268 "<span size=\"x-large\" weight=\"bold\">%s</span>\n\n%s",
269 _("Invite Participant"),
270 _("Choose a contact to invite into the conversation:"));
271 gtk_label_set_markup (GTK_LABEL (label), str);
274 gtk_box_pack_start (GTK_BOX (content), label, FALSE, TRUE, 6);
275 gtk_widget_show (label);
277 gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
280 search_entry = gtk_entry_new ();
281 gtk_box_pack_start (GTK_BOX (content), search_entry, FALSE, TRUE, 6);
282 gtk_widget_show (search_entry);
284 g_signal_connect (search_entry, "changed",
285 G_CALLBACK (search_text_changed), self);
287 /* Add the treeview */
288 mgr = empathy_individual_manager_dup_singleton ();
289 self->priv->store = empathy_individual_store_new (mgr);
290 g_object_unref (mgr);
292 empathy_individual_store_set_show_groups (self->priv->store, FALSE);
294 self->priv->view = empathy_individual_view_new (self->priv->store,
295 EMPATHY_INDIVIDUAL_VIEW_FEATURE_NONE, EMPATHY_INDIVIDUAL_FEATURE_NONE);
297 empathy_individual_view_set_custom_filter (self->priv->view,
300 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->priv->view));
302 g_signal_connect (selection, "changed",
303 G_CALLBACK (view_selection_changed_cb), self);
305 scroll = gtk_scrolled_window_new (NULL, NULL);
307 gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (self->priv->view));
309 gtk_box_pack_start (GTK_BOX (content), scroll, TRUE, TRUE, 6);
310 gtk_widget_show (GTK_WIDGET (self->priv->view));
311 gtk_widget_show (scroll);
313 self->priv->invite_button = gtk_dialog_add_button (dialog, _("Invite"),
314 GTK_RESPONSE_ACCEPT);
315 gtk_widget_set_sensitive (self->priv->invite_button, FALSE);
317 gtk_window_set_title (GTK_WINDOW (self), _("Invite Participant"));
318 gtk_window_set_role (GTK_WINDOW (self), "invite_participant");
320 /* Set a default height so a few contacts are displayed */
321 gtk_window_set_default_size (GTK_WINDOW (self), -1, 400);
325 empathy_invite_participant_dialog_new (GtkWindow *parent,
326 EmpathyTpChat *tp_chat)
328 GtkWidget *self = g_object_new (EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
334 gtk_window_set_transient_for (GTK_WINDOW (self), parent);
341 empathy_invite_participant_dialog_get_selected (
342 EmpathyInviteParticipantDialog *self)
344 FolksIndividual *individual;
347 individual = empathy_individual_view_dup_selected (self->priv->view);
348 if (individual == NULL)
351 contact = get_tp_contact_for_chat (self, individual);
353 g_object_unref (individual);