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/empathy-utils.h>
19 #include <libempathy-gtk/empathy-contact-chooser.h>
20 #include <libempathy-gtk/empathy-individual-view.h>
21 #include <libempathy-gtk/empathy-ui-utils.h>
23 G_DEFINE_TYPE (EmpathyInviteParticipantDialog,
24 empathy_invite_participant_dialog, GTK_TYPE_DIALOG);
31 struct _EmpathyInviteParticipantDialogPrivate
33 EmpathyTpChat *tp_chat;
36 GtkWidget *invite_button;
40 invite_participant_dialog_get_property (GObject *object,
45 EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
51 g_value_set_object (value, self->priv->tp_chat);
54 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
60 invite_participant_dialog_set_property (GObject *object,
65 EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
71 g_assert (self->priv->tp_chat == NULL); /* construct-only */
72 self->priv->tp_chat = g_value_dup_object (value);
75 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
81 invite_participant_dialog_dispose (GObject *object)
83 EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
86 tp_clear_object (&self->priv->tp_chat);
88 G_OBJECT_CLASS (empathy_invite_participant_dialog_parent_class)->dispose (
93 selection_changed_cb (GtkWidget *treeview,
94 FolksIndividual *selected,
95 EmpathyInviteParticipantDialog *self)
97 gtk_widget_set_sensitive (self->priv->invite_button, selected != NULL);
101 activate_cb (GtkWidget *chooser,
102 EmpathyInviteParticipantDialog *self)
104 gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_ACCEPT);
107 /* Return the TpContact of @individual which is on the same connection as the
110 get_tp_contact_for_chat (EmpathyInviteParticipantDialog *self,
111 FolksIndividual *individual)
113 TpConnection *chat_conn;
115 chat_conn = tp_channel_borrow_connection (TP_CHANNEL (self->priv->tp_chat));
117 return empathy_get_tp_contact_for_individual (individual, chat_conn);
121 filter_individual (EmpathyContactChooser *chooser,
122 FolksIndividual *individual,
127 EmpathyInviteParticipantDialog *self = user_data;
130 gboolean display = TRUE;
132 /* Filter out offline contacts if we are not searching */
133 if (!searching && !is_online)
136 /* Filter out individuals not having a persona on the same connection as the
138 contact = get_tp_contact_for_chat (self, individual);
143 /* Filter out contacts which are already in the chat */
144 members = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (
145 self->priv->tp_chat));
147 for (l = members; l != NULL; l = g_list_next (l))
149 EmpathyContact *member = l->data;
152 /* Try to get the non-channel specific handle. */
153 handle = tp_channel_group_get_handle_owner (
154 TP_CHANNEL (self->priv->tp_chat),
155 empathy_contact_get_handle (member));
157 handle = empathy_contact_get_handle (member);
159 if (handle == tp_contact_get_handle (contact))
166 g_list_free_full (members, g_object_unref);
172 invite_participant_dialog_constructed (GObject *object)
174 EmpathyInviteParticipantDialog *self =
175 (EmpathyInviteParticipantDialog *) object;
176 GtkDialog *dialog = GTK_DIALOG (self);
181 content = gtk_dialog_get_content_area (dialog);
183 label = gtk_label_new (NULL);
184 str = g_strdup_printf (
185 "<span size=\"x-large\" weight=\"bold\">%s</span>\n\n%s",
186 _("Invite Participant"),
187 _("Choose a contact to invite into the conversation:"));
188 gtk_label_set_markup (GTK_LABEL (label), str);
191 gtk_box_pack_start (GTK_BOX (content), label, FALSE, TRUE, 6);
192 gtk_widget_show (label);
194 gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
196 /* contact chooser */
197 self->priv->chooser = empathy_contact_chooser_new ();
199 empathy_contact_chooser_set_filter_func (
200 EMPATHY_CONTACT_CHOOSER (self->priv->chooser), filter_individual, self);
202 gtk_box_pack_start (GTK_BOX (content), self->priv->chooser, TRUE, TRUE, 6);
203 gtk_widget_show (self->priv->chooser);
205 g_signal_connect (self->priv->chooser, "selection-changed",
206 G_CALLBACK (selection_changed_cb), self);
207 g_signal_connect (self->priv->chooser, "activate",
208 G_CALLBACK (activate_cb), self);
210 self->priv->invite_button = gtk_dialog_add_button (dialog, _("Invite"),
211 GTK_RESPONSE_ACCEPT);
212 gtk_widget_set_sensitive (self->priv->invite_button, FALSE);
214 gtk_window_set_title (GTK_WINDOW (self), _("Invite Participant"));
215 gtk_window_set_role (GTK_WINDOW (self), "invite_participant");
217 /* Set a default height so a few contacts are displayed */
218 gtk_window_set_default_size (GTK_WINDOW (self), -1, 400);
222 empathy_invite_participant_dialog_class_init (
223 EmpathyInviteParticipantDialogClass *klass)
225 GObjectClass *object_class = G_OBJECT_CLASS (klass);
227 object_class->get_property = invite_participant_dialog_get_property;
228 object_class->set_property = invite_participant_dialog_set_property;
229 object_class->constructed = invite_participant_dialog_constructed;
230 object_class->dispose = invite_participant_dialog_dispose;
232 g_type_class_add_private (object_class,
233 sizeof (EmpathyInviteParticipantDialogPrivate));
235 g_object_class_install_property (object_class,
237 g_param_spec_object ("tp-chat", "EmpathyTpChat", "EmpathyTpChat",
238 EMPATHY_TYPE_TP_CHAT,
239 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
243 empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
245 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (
246 self, EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
247 EmpathyInviteParticipantDialogPrivate);
251 empathy_invite_participant_dialog_new (GtkWindow *parent,
252 EmpathyTpChat *tp_chat)
254 GtkWidget *self = g_object_new (EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
260 gtk_window_set_transient_for (GTK_WINDOW (self), parent);
267 empathy_invite_participant_dialog_get_selected (
268 EmpathyInviteParticipantDialog *self)
270 FolksIndividual *individual;
273 individual = empathy_contact_chooser_dup_selected (
274 EMPATHY_CONTACT_CHOOSER (self->priv->chooser));
275 if (individual == NULL)
278 contact = get_tp_contact_for_chat (self, individual);
280 g_object_unref (individual);