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>
18 #include <libempathy/empathy-contact-list.h>
20 #include <libempathy-gtk/empathy-contact-chooser.h>
21 #include <libempathy-gtk/empathy-individual-view.h>
22 #include <libempathy-gtk/empathy-ui-utils.h>
24 G_DEFINE_TYPE (EmpathyInviteParticipantDialog,
25 empathy_invite_participant_dialog, GTK_TYPE_DIALOG);
32 struct _EmpathyInviteParticipantDialogPrivate
34 EmpathyTpChat *tp_chat;
37 GtkWidget *invite_button;
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);
89 G_OBJECT_CLASS (empathy_invite_participant_dialog_parent_class)->dispose (
94 selection_changed_cb (GtkWidget *treeview,
95 FolksIndividual *selected,
96 EmpathyInviteParticipantDialog *self)
98 gtk_widget_set_sensitive (self->priv->invite_button, selected != NULL);
102 activate_cb (GtkWidget *chooser,
103 EmpathyInviteParticipantDialog *self)
105 gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_ACCEPT);
108 /* Return the TpContact of @individual which is on the same connection as the
111 get_tp_contact_for_chat (EmpathyInviteParticipantDialog *self,
112 FolksIndividual *individual)
114 TpConnection *chat_conn;
116 chat_conn = tp_channel_borrow_connection (TP_CHANNEL (self->priv->tp_chat));
117 if (chat_conn == NULL)
120 return empathy_get_tp_contact_for_individual (individual, chat_conn);
124 filter_individual (EmpathyContactChooser *chooser,
125 FolksIndividual *individual,
130 EmpathyInviteParticipantDialog *self = user_data;
133 gboolean display = TRUE;
135 /* Filter out offline contacts if we are not searching */
136 if (!searching && !is_online)
139 /* Filter out individuals not having a persona on the same connection as the
141 contact = get_tp_contact_for_chat (self, individual);
146 /* Filter out contacts which are already in the chat */
147 members = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (
148 self->priv->tp_chat));
150 for (l = members; l != NULL; l = g_list_next (l))
152 EmpathyContact *member = l->data;
155 /* Try to get the non-channel specific handle. */
156 handle = tp_channel_group_get_handle_owner (
157 TP_CHANNEL (self->priv->tp_chat),
158 empathy_contact_get_handle (member));
160 handle = empathy_contact_get_handle (member);
162 if (handle == tp_contact_get_handle (contact))
169 g_list_free_full (members, g_object_unref);
175 has_contact_list (EmpathyInviteParticipantDialog *self)
179 conn = tp_channel_borrow_connection (TP_CHANNEL (self->priv->tp_chat));
181 return tp_proxy_has_interface_by_id (conn,
182 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_LIST);
186 invite_participant_dialog_constructed (GObject *object)
188 EmpathyInviteParticipantDialog *self =
189 (EmpathyInviteParticipantDialog *) object;
190 GtkDialog *dialog = GTK_DIALOG (self);
195 content = gtk_dialog_get_content_area (dialog);
197 label = gtk_label_new (NULL);
198 str = g_strdup_printf (
199 "<span size=\"x-large\" weight=\"bold\">%s</span>\n\n%s",
200 _("Invite Participant"),
201 _("Choose a contact to invite into the conversation:"));
202 gtk_label_set_markup (GTK_LABEL (label), str);
205 gtk_box_pack_start (GTK_BOX (content), label, FALSE, TRUE, 6);
206 gtk_widget_show (label);
208 gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
210 /* contact chooser */
211 self->priv->chooser = empathy_contact_chooser_new ();
213 empathy_contact_chooser_set_filter_func (
214 EMPATHY_CONTACT_CHOOSER (self->priv->chooser), filter_individual, self);
216 gtk_box_pack_start (GTK_BOX (content), self->priv->chooser, TRUE, TRUE, 6);
217 gtk_widget_show (self->priv->chooser);
219 g_signal_connect (self->priv->chooser, "selection-changed",
220 G_CALLBACK (selection_changed_cb), self);
221 g_signal_connect (self->priv->chooser, "activate",
222 G_CALLBACK (activate_cb), self);
224 self->priv->invite_button = gtk_dialog_add_button (dialog, _("Invite"),
225 GTK_RESPONSE_ACCEPT);
226 gtk_widget_set_sensitive (self->priv->invite_button, FALSE);
228 gtk_window_set_title (GTK_WINDOW (self), _("Invite Participant"));
229 gtk_window_set_role (GTK_WINDOW (self), "invite_participant");
231 if (has_contact_list (self))
233 /* Set a default height so a few contacts are displayed */
234 gtk_window_set_default_size (GTK_WINDOW (self), -1, 400);
238 /* No need to display an empty treeview (ie IRC) */
239 empathy_contact_chooser_show_tree_view (
240 EMPATHY_CONTACT_CHOOSER (self->priv->chooser), FALSE);
245 empathy_invite_participant_dialog_class_init (
246 EmpathyInviteParticipantDialogClass *klass)
248 GObjectClass *object_class = G_OBJECT_CLASS (klass);
250 object_class->get_property = invite_participant_dialog_get_property;
251 object_class->set_property = invite_participant_dialog_set_property;
252 object_class->constructed = invite_participant_dialog_constructed;
253 object_class->dispose = invite_participant_dialog_dispose;
255 g_type_class_add_private (object_class,
256 sizeof (EmpathyInviteParticipantDialogPrivate));
258 g_object_class_install_property (object_class,
260 g_param_spec_object ("tp-chat", "EmpathyTpChat", "EmpathyTpChat",
261 EMPATHY_TYPE_TP_CHAT,
262 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
266 empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
268 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (
269 self, EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
270 EmpathyInviteParticipantDialogPrivate);
274 empathy_invite_participant_dialog_new (GtkWindow *parent,
275 EmpathyTpChat *tp_chat)
277 GtkWidget *self = g_object_new (EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
283 gtk_window_set_transient_for (GTK_WINDOW (self), parent);
290 empathy_invite_participant_dialog_get_selected (
291 EmpathyInviteParticipantDialog *self)
293 FolksIndividual *individual;
296 individual = empathy_contact_chooser_dup_selected (
297 EMPATHY_CONTACT_CHOOSER (self->priv->chooser));
298 if (individual == NULL)
301 contact = get_tp_contact_for_chat (self, individual);
303 g_object_unref (individual);