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);
100 /* Return the TpContact of @individual which is on the same connection as the
103 get_tp_contact_for_chat (EmpathyInviteParticipantDialog *self,
104 FolksIndividual *individual)
106 TpConnection *chat_conn;
108 chat_conn = tp_channel_borrow_connection (TP_CHANNEL (self->priv->tp_chat));
110 return empathy_get_tp_contact_for_individual (individual, chat_conn);
114 filter_individual (EmpathyContactChooser *chooser,
115 FolksIndividual *individual,
120 EmpathyInviteParticipantDialog *self = user_data;
123 gboolean display = TRUE;
125 /* Filter out offline contacts if we are not searching */
126 if (!searching && !is_online)
129 /* Filter out individuals not having a persona on the same connection as the
131 contact = get_tp_contact_for_chat (self, individual);
136 /* Filter out contacts which are already in the chat */
137 members = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (
138 self->priv->tp_chat));
140 for (l = members; l != NULL; l = g_list_next (l))
142 EmpathyContact *member = l->data;
145 /* Try to get the non-channel specific handle. */
146 handle = tp_channel_group_get_handle_owner (
147 TP_CHANNEL (self->priv->tp_chat),
148 empathy_contact_get_handle (member));
150 handle = empathy_contact_get_handle (member);
152 if (handle == tp_contact_get_handle (contact))
159 g_list_free_full (members, g_object_unref);
165 invite_participant_dialog_constructed (GObject *object)
167 EmpathyInviteParticipantDialog *self =
168 (EmpathyInviteParticipantDialog *) object;
169 GtkDialog *dialog = GTK_DIALOG (self);
174 content = gtk_dialog_get_content_area (dialog);
176 label = gtk_label_new (NULL);
177 str = g_strdup_printf (
178 "<span size=\"x-large\" weight=\"bold\">%s</span>\n\n%s",
179 _("Invite Participant"),
180 _("Choose a contact to invite into the conversation:"));
181 gtk_label_set_markup (GTK_LABEL (label), str);
184 gtk_box_pack_start (GTK_BOX (content), label, FALSE, TRUE, 6);
185 gtk_widget_show (label);
187 gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
189 /* contact chooser */
190 self->priv->chooser = empathy_contact_chooser_new ();
192 empathy_contact_chooser_set_filter_func (
193 EMPATHY_CONTACT_CHOOSER (self->priv->chooser), filter_individual, self);
195 gtk_box_pack_start (GTK_BOX (content), self->priv->chooser, TRUE, TRUE, 6);
196 gtk_widget_show (self->priv->chooser);
198 g_signal_connect (self->priv->chooser, "selection-changed",
199 G_CALLBACK (selection_changed_cb), self);
201 self->priv->invite_button = gtk_dialog_add_button (dialog, _("Invite"),
202 GTK_RESPONSE_ACCEPT);
203 gtk_widget_set_sensitive (self->priv->invite_button, FALSE);
205 gtk_window_set_title (GTK_WINDOW (self), _("Invite Participant"));
206 gtk_window_set_role (GTK_WINDOW (self), "invite_participant");
208 /* Set a default height so a few contacts are displayed */
209 gtk_window_set_default_size (GTK_WINDOW (self), -1, 400);
213 empathy_invite_participant_dialog_class_init (
214 EmpathyInviteParticipantDialogClass *klass)
216 GObjectClass *object_class = G_OBJECT_CLASS (klass);
218 object_class->get_property = invite_participant_dialog_get_property;
219 object_class->set_property = invite_participant_dialog_set_property;
220 object_class->constructed = invite_participant_dialog_constructed;
221 object_class->dispose = invite_participant_dialog_dispose;
223 g_type_class_add_private (object_class,
224 sizeof (EmpathyInviteParticipantDialogPrivate));
226 g_object_class_install_property (object_class,
228 g_param_spec_object ("tp-chat", "EmpathyTpChat", "EmpathyTpChat",
229 EMPATHY_TYPE_TP_CHAT,
230 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
234 empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
236 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (
237 self, EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
238 EmpathyInviteParticipantDialogPrivate);
242 empathy_invite_participant_dialog_new (GtkWindow *parent,
243 EmpathyTpChat *tp_chat)
245 GtkWidget *self = g_object_new (EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
251 gtk_window_set_transient_for (GTK_WINDOW (self), parent);
258 empathy_invite_participant_dialog_get_selected (
259 EmpathyInviteParticipantDialog *self)
261 FolksIndividual *individual;
264 individual = empathy_contact_chooser_dup_selected (
265 EMPATHY_CONTACT_CHOOSER (self->priv->chooser));
266 if (individual == NULL)
269 contact = get_tp_contact_for_chat (self, individual);
271 g_object_unref (individual);