2 * empathy-invite-participant-dialog.c
4 * EmpathyInviteParticipantDialog
6 * (c) 2009, Collabora Ltd.
9 * Danielle Madeley <danielle.madeley@collabora.co.uk>
13 #include "empathy-invite-participant-dialog.h"
15 #include <glib/gi18n.h>
17 #include "empathy-contact-chooser.h"
18 #include "empathy-utils.h"
20 G_DEFINE_TYPE (EmpathyInviteParticipantDialog,
21 empathy_invite_participant_dialog, GTK_TYPE_DIALOG);
28 struct _EmpathyInviteParticipantDialogPrivate
30 EmpathyTpChat *tp_chat;
33 GtkWidget *invite_button;
37 invite_participant_dialog_get_property (GObject *object,
42 EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
48 g_value_set_object (value, self->priv->tp_chat);
51 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
57 invite_participant_dialog_set_property (GObject *object,
62 EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
68 g_assert (self->priv->tp_chat == NULL); /* construct-only */
69 self->priv->tp_chat = g_value_dup_object (value);
72 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
78 invite_participant_dialog_dispose (GObject *object)
80 EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
83 tp_clear_object (&self->priv->tp_chat);
85 G_OBJECT_CLASS (empathy_invite_participant_dialog_parent_class)->dispose (
90 selection_changed_cb (GtkWidget *treeview,
91 FolksIndividual *selected,
92 EmpathyInviteParticipantDialog *self)
94 gtk_widget_set_sensitive (self->priv->invite_button, selected != NULL);
98 activate_cb (GtkWidget *chooser,
99 EmpathyInviteParticipantDialog *self)
101 gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_ACCEPT);
104 /* Return the TpContact of @individual which is on the same connection as the
107 get_tp_contact_for_chat (EmpathyInviteParticipantDialog *self,
108 FolksIndividual *individual)
110 TpConnection *chat_conn;
112 chat_conn = tp_channel_get_connection (TP_CHANNEL (self->priv->tp_chat));
113 if (chat_conn == NULL)
116 return empathy_get_tp_contact_for_individual (individual, chat_conn);
120 filter_individual (EmpathyContactChooser *chooser,
121 FolksIndividual *individual,
126 EmpathyInviteParticipantDialog *self = user_data;
129 gboolean display = TRUE;
131 /* Filter out offline contacts if we are not searching */
132 if (!searching && !is_online)
135 /* Filter out individuals not having a persona on the same connection as the
137 contact = get_tp_contact_for_chat (self, individual);
142 /* Filter out contacts which are already in the chat */
143 members = empathy_tp_chat_get_members (self->priv->tp_chat);
145 for (l = members; l != NULL; l = g_list_next (l))
147 EmpathyContact *member = l->data;
150 /* Try to get the non-channel specific contact. */
151 owner = tp_channel_group_get_contact_owner (
152 TP_CHANNEL (self->priv->tp_chat),
153 empathy_contact_get_tp_contact (member));
156 owner = empathy_contact_get_tp_contact (member);
158 if (owner == contact)
165 g_list_free_full (members, g_object_unref);
171 has_contact_list (EmpathyInviteParticipantDialog *self)
175 conn = tp_channel_get_connection (TP_CHANNEL (self->priv->tp_chat));
177 return tp_proxy_has_interface_by_id (conn,
178 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_LIST);
182 invite_participant_dialog_constructed (GObject *object)
184 EmpathyInviteParticipantDialog *self =
185 (EmpathyInviteParticipantDialog *) object;
186 GtkDialog *dialog = GTK_DIALOG (self);
191 content = gtk_dialog_get_content_area (dialog);
193 label = gtk_label_new (NULL);
194 str = g_strdup_printf (
195 "<span size=\"x-large\" weight=\"bold\">%s</span>\n\n%s",
196 _("Invite Participant"),
197 _("Choose a contact to invite into the conversation:"));
198 gtk_label_set_markup (GTK_LABEL (label), str);
201 gtk_box_pack_start (GTK_BOX (content), label, FALSE, TRUE, 6);
202 gtk_widget_show (label);
204 gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
206 /* contact chooser */
207 self->priv->chooser = empathy_contact_chooser_new ();
209 empathy_contact_chooser_set_filter_func (
210 EMPATHY_CONTACT_CHOOSER (self->priv->chooser), filter_individual, self);
212 gtk_box_pack_start (GTK_BOX (content), self->priv->chooser, TRUE, TRUE, 6);
213 gtk_widget_show (self->priv->chooser);
215 g_signal_connect (self->priv->chooser, "selection-changed",
216 G_CALLBACK (selection_changed_cb), self);
217 g_signal_connect (self->priv->chooser, "activate",
218 G_CALLBACK (activate_cb), self);
220 self->priv->invite_button = gtk_dialog_add_button (dialog, _("Invite"),
221 GTK_RESPONSE_ACCEPT);
222 gtk_widget_set_sensitive (self->priv->invite_button, FALSE);
224 gtk_window_set_title (GTK_WINDOW (self), _("Invite Participant"));
225 gtk_window_set_role (GTK_WINDOW (self), "invite_participant");
227 if (has_contact_list (self))
229 /* Set a default height so a few contacts are displayed */
230 gtk_window_set_default_size (GTK_WINDOW (self), -1, 400);
234 /* No need to display an empty treeview (ie IRC) */
235 empathy_contact_chooser_show_tree_view (
236 EMPATHY_CONTACT_CHOOSER (self->priv->chooser), FALSE);
241 empathy_invite_participant_dialog_class_init (
242 EmpathyInviteParticipantDialogClass *klass)
244 GObjectClass *object_class = G_OBJECT_CLASS (klass);
246 object_class->get_property = invite_participant_dialog_get_property;
247 object_class->set_property = invite_participant_dialog_set_property;
248 object_class->constructed = invite_participant_dialog_constructed;
249 object_class->dispose = invite_participant_dialog_dispose;
251 g_type_class_add_private (object_class,
252 sizeof (EmpathyInviteParticipantDialogPrivate));
254 g_object_class_install_property (object_class,
256 g_param_spec_object ("tp-chat", "EmpathyTpChat", "EmpathyTpChat",
257 EMPATHY_TYPE_TP_CHAT,
258 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
262 empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
264 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (
265 self, EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
266 EmpathyInviteParticipantDialogPrivate);
270 empathy_invite_participant_dialog_new (GtkWindow *parent,
271 EmpathyTpChat *tp_chat)
273 GtkWidget *self = g_object_new (EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
279 gtk_window_set_transient_for (GTK_WINDOW (self), parent);
286 empathy_invite_participant_dialog_get_selected (
287 EmpathyInviteParticipantDialog *self)
289 FolksIndividual *individual;
292 individual = empathy_contact_chooser_dup_selected (
293 EMPATHY_CONTACT_CHOOSER (self->priv->chooser));
294 if (individual == NULL)
297 contact = get_tp_contact_for_chat (self, individual);
299 g_object_unref (individual);