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>
19 G_DEFINE_TYPE (EmpathyInviteParticipantDialog,
20 empathy_invite_participant_dialog, GTK_TYPE_DIALOG);
27 struct _EmpathyInviteParticipantDialogPrivate
29 EmpathyTpChat *tp_chat;
31 EmpathyIndividualStore *store;
32 EmpathyIndividualView *view;
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);
85 tp_clear_object (&self->priv->store);
87 G_OBJECT_CLASS (empathy_invite_participant_dialog_parent_class)->dispose (
92 empathy_invite_participant_dialog_class_init (
93 EmpathyInviteParticipantDialogClass *klass)
95 GObjectClass *object_class = G_OBJECT_CLASS (klass);
97 object_class->get_property = invite_participant_dialog_get_property;
98 object_class->set_property = invite_participant_dialog_set_property;
99 object_class->dispose = invite_participant_dialog_dispose;
101 g_type_class_add_private (object_class,
102 sizeof (EmpathyInviteParticipantDialogPrivate));
104 g_object_class_install_property (object_class,
106 g_param_spec_object ("tp-chat", "EmpathyTpChat", "EmpathyTpChat",
107 EMPATHY_TYPE_TP_CHAT,
108 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
112 view_selection_changed_cb (GtkWidget *treeview,
113 EmpathyInviteParticipantDialog *self)
115 FolksIndividual *individual;
117 individual = empathy_individual_view_dup_selected (self->priv->view);
119 gtk_widget_set_sensitive (self->priv->invite_button, individual != NULL);
121 g_object_unref (individual);
124 /* Return the TpContact of @individual which is on the same connection as the
127 get_tp_contact_for_chat (EmpathyInviteParticipantDialog *self,
128 FolksIndividual *individual)
131 TpConnection *chat_conn;
133 chat_conn = empathy_tp_chat_get_connection (self->priv->tp_chat);
135 personas = folks_individual_get_personas (individual);
137 for (l = personas; l != NULL; l = g_list_next (l))
139 TpfPersona *persona = l->data;
141 TpConnection *contact_conn;
143 if (!TPF_IS_PERSONA (persona))
146 contact = tpf_persona_get_contact (persona);
150 contact_conn = tp_contact_get_connection (contact);
152 if (!tp_strdiff (tp_proxy_get_object_path (contact_conn),
153 tp_proxy_get_object_path (chat_conn)))
161 filter_func (GtkTreeModel *model,
165 EmpathyInviteParticipantDialog *self = user_data;
166 FolksIndividual *individual;
170 gboolean display = FALSE;
173 gtk_tree_model_get (model, iter,
174 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
175 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &is_online,
178 if (individual == NULL || !is_online)
181 /* Filter out individuals not having a persona on the same connection as the
183 contact = get_tp_contact_for_chat (self, individual);
188 /* Filter out contacts which are already in the chat */
189 members = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (
190 self->priv->tp_chat));
193 channel = empathy_tp_chat_get_channel (self->priv->tp_chat);
195 for (l = members; l != NULL; l = g_list_next (l))
197 EmpathyContact *member = l->data;
200 /* Try to get the non-channel specific handle. */
201 handle = tp_channel_group_get_handle_owner (channel,
202 empathy_contact_get_handle (member));
204 handle = empathy_contact_get_handle (member);
206 if (handle == tp_contact_get_handle (contact))
213 g_list_free_full (members, g_object_unref);
216 tp_clear_object (&individual);
221 empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
223 GtkDialog *dialog = GTK_DIALOG (self);
227 EmpathyIndividualManager *mgr;
228 GtkTreeSelection *selection;
231 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (
232 self, EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
233 EmpathyInviteParticipantDialogPrivate);
235 content = gtk_dialog_get_content_area (dialog);
237 label = gtk_label_new (NULL);
238 str = g_strdup_printf (
239 "<span size=\"x-large\" weight=\"bold\">%s</span>\n\n%s",
240 _("Invite Participant"),
241 _("Choose a contact to invite into the conversation:"));
242 gtk_label_set_markup (GTK_LABEL (label), str);
245 gtk_box_pack_start (GTK_BOX (content), label, FALSE, TRUE, 6);
246 gtk_widget_show (label);
248 gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
250 /* Add the treeview */
251 mgr = empathy_individual_manager_dup_singleton ();
252 self->priv->store = empathy_individual_store_new (mgr);
253 g_object_unref (mgr);
255 empathy_individual_store_set_show_groups (self->priv->store, FALSE);
257 self->priv->view = empathy_individual_view_new (self->priv->store,
258 EMPATHY_INDIVIDUAL_VIEW_FEATURE_NONE, EMPATHY_INDIVIDUAL_FEATURE_NONE);
260 empathy_individual_view_set_custom_filter (self->priv->view,
263 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->priv->view));
265 g_signal_connect (selection, "changed",
266 G_CALLBACK (view_selection_changed_cb), self);
268 scroll = gtk_scrolled_window_new (NULL, NULL);
270 gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (self->priv->view));
272 gtk_box_pack_start (GTK_BOX (content), scroll, TRUE, TRUE, 6);
273 gtk_widget_show (GTK_WIDGET (self->priv->view));
274 gtk_widget_show (scroll);
276 self->priv->invite_button = gtk_dialog_add_button (dialog, _("Invite"),
277 GTK_RESPONSE_ACCEPT);
278 gtk_widget_set_sensitive (self->priv->invite_button, FALSE);
280 gtk_window_set_title (GTK_WINDOW (self), _("Invite Participant"));
281 gtk_window_set_role (GTK_WINDOW (self), "invite_participant");
283 /* Set a default height so a few contacts are displayed */
284 gtk_window_set_default_size (GTK_WINDOW (self), -1, 400);
288 empathy_invite_participant_dialog_new (GtkWindow *parent,
289 EmpathyTpChat *tp_chat)
291 GtkWidget *self = g_object_new (EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
297 gtk_window_set_transient_for (GTK_WINDOW (self), parent);
304 empathy_invite_participant_dialog_get_selected (
305 EmpathyInviteParticipantDialog *self)
307 FolksIndividual *individual;
310 individual = empathy_individual_view_dup_selected (self->priv->view);
311 if (individual == NULL)
314 contact = get_tp_contact_for_chat (self, individual);
316 g_object_unref (individual);