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 gtk_tree_model_get (model, iter,
171 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
172 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &is_online,
175 if (individual == NULL || !is_online)
178 /* Filter out individuals not having a persona on the same connection as the
180 contact = get_tp_contact_for_chat (self, individual);
188 empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
190 EmpathyInviteParticipantDialogPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (
191 self, EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
192 EmpathyInviteParticipantDialogPrivate);
193 GtkDialog *dialog = GTK_DIALOG (self);
197 EmpathyIndividualManager *mgr;
198 GtkTreeSelection *selection;
202 content = gtk_dialog_get_content_area (dialog);
204 label = gtk_label_new (NULL);
205 str = g_strdup_printf (
206 "<span size=\"x-large\" weight=\"bold\">%s</span>\n\n%s",
207 _("Invite Participant"),
208 _("Choose a contact to invite into the conversation:"));
209 gtk_label_set_markup (GTK_LABEL (label), str);
212 gtk_box_pack_start (GTK_BOX (content), label, FALSE, TRUE, 0);
213 gtk_widget_show (label);
215 gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
217 /* Add the treeview */
218 mgr = empathy_individual_manager_dup_singleton ();
219 self->priv->store = empathy_individual_store_new (mgr);
220 g_object_unref (mgr);
222 empathy_individual_store_set_show_groups (self->priv->store, FALSE);
224 self->priv->view = empathy_individual_view_new (self->priv->store,
225 EMPATHY_INDIVIDUAL_VIEW_FEATURE_NONE , EMPATHY_INDIVIDUAL_FEATURE_NONE);
227 empathy_individual_view_set_custom_filter (self->priv->view,
230 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->priv->view));
232 g_signal_connect (selection, "changed",
233 G_CALLBACK (view_selection_changed_cb), self);
235 gtk_box_pack_start (GTK_BOX (content), GTK_WIDGET (self->priv->view),
237 gtk_widget_show (GTK_WIDGET (self->priv->view));
239 self->priv->invite_button = gtk_dialog_add_button (dialog, _("Invite"),
240 GTK_RESPONSE_ACCEPT);
241 gtk_widget_set_sensitive (self->priv->invite_button, FALSE);
243 gtk_window_set_title (GTK_WINDOW (self), _("Invite Participant"));
244 gtk_window_set_role (GTK_WINDOW (self), "invite_participant");
248 empathy_invite_participant_dialog_new (GtkWindow *parent,
249 EmpathyTpChat *tp_chat)
251 GtkWidget *self = g_object_new (EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
257 gtk_window_set_transient_for (GTK_WINDOW (self), parent);
264 empathy_invite_participant_dialog_get_selected (
265 EmpathyInviteParticipantDialog *self)
267 FolksIndividual *individual;
270 individual = empathy_individual_view_dup_selected (self->priv->view);
271 if (individual == NULL)
274 contact = get_tp_contact_for_chat (self, individual);
276 g_object_unref (individual);