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>
16 #include <telepathy-glib/telepathy-glib-dbus.h>
18 #include "empathy-contact-chooser.h"
19 #include "empathy-utils.h"
21 G_DEFINE_TYPE (EmpathyInviteParticipantDialog
,
22 empathy_invite_participant_dialog
, GTK_TYPE_DIALOG
);
29 struct _EmpathyInviteParticipantDialogPrivate
31 EmpathyTpChat
*tp_chat
;
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
);
86 G_OBJECT_CLASS (empathy_invite_participant_dialog_parent_class
)->dispose (
91 selection_changed_cb (GtkWidget
*treeview
,
92 FolksIndividual
*selected
,
93 EmpathyInviteParticipantDialog
*self
)
95 gtk_widget_set_sensitive (self
->priv
->invite_button
, selected
!= NULL
);
99 activate_cb (GtkWidget
*chooser
,
100 EmpathyInviteParticipantDialog
*self
)
102 gtk_dialog_response (GTK_DIALOG (self
), GTK_RESPONSE_ACCEPT
);
105 /* Return the TpContact of @individual which is on the same connection as the
108 get_tp_contact_for_chat (EmpathyInviteParticipantDialog
*self
,
109 FolksIndividual
*individual
)
111 TpConnection
*chat_conn
;
113 chat_conn
= tp_channel_get_connection (TP_CHANNEL (self
->priv
->tp_chat
));
114 if (chat_conn
== NULL
)
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_tp_chat_get_members (self
->priv
->tp_chat
);
146 for (l
= members
; l
!= NULL
; l
= g_list_next (l
))
148 EmpathyContact
*member
= l
->data
;
151 /* Try to get the non-channel specific contact. */
152 owner
= tp_channel_group_get_contact_owner (
153 TP_CHANNEL (self
->priv
->tp_chat
),
154 empathy_contact_get_tp_contact (member
));
157 owner
= empathy_contact_get_tp_contact (member
);
159 if (owner
== contact
)
166 g_list_free_full (members
, g_object_unref
);
172 has_contact_list (EmpathyInviteParticipantDialog
*self
)
176 conn
= tp_channel_get_connection (TP_CHANNEL (self
->priv
->tp_chat
));
178 return tp_proxy_has_interface_by_id (conn
,
179 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_LIST
);
183 invite_participant_dialog_constructed (GObject
*object
)
185 EmpathyInviteParticipantDialog
*self
=
186 (EmpathyInviteParticipantDialog
*) object
;
187 GtkDialog
*dialog
= GTK_DIALOG (self
);
192 content
= gtk_dialog_get_content_area (dialog
);
194 label
= gtk_label_new (NULL
);
195 str
= g_strdup_printf (
196 "<span size=\"x-large\" weight=\"bold\">%s</span>\n\n%s",
197 _("Invite Participant"),
198 _("Choose a contact to invite into the conversation:"));
199 gtk_label_set_markup (GTK_LABEL (label
), str
);
202 gtk_box_pack_start (GTK_BOX (content
), label
, FALSE
, TRUE
, 6);
203 gtk_widget_show (label
);
205 gtk_dialog_add_button (dialog
, GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
);
207 /* contact chooser */
208 self
->priv
->chooser
= empathy_contact_chooser_new ();
210 empathy_contact_chooser_set_filter_func (
211 EMPATHY_CONTACT_CHOOSER (self
->priv
->chooser
), filter_individual
, self
);
213 gtk_box_pack_start (GTK_BOX (content
), self
->priv
->chooser
, TRUE
, TRUE
, 6);
214 gtk_widget_show (self
->priv
->chooser
);
216 g_signal_connect (self
->priv
->chooser
, "selection-changed",
217 G_CALLBACK (selection_changed_cb
), self
);
218 g_signal_connect (self
->priv
->chooser
, "activate",
219 G_CALLBACK (activate_cb
), self
);
221 self
->priv
->invite_button
= gtk_dialog_add_button (dialog
, _("Invite"),
222 GTK_RESPONSE_ACCEPT
);
223 gtk_widget_set_sensitive (self
->priv
->invite_button
, FALSE
);
225 gtk_window_set_title (GTK_WINDOW (self
), _("Invite Participant"));
226 gtk_window_set_role (GTK_WINDOW (self
), "invite_participant");
228 if (has_contact_list (self
))
230 /* Set a default height so a few contacts are displayed */
231 gtk_window_set_default_size (GTK_WINDOW (self
), -1, 400);
235 /* No need to display an empty treeview (ie IRC) */
236 empathy_contact_chooser_show_tree_view (
237 EMPATHY_CONTACT_CHOOSER (self
->priv
->chooser
), FALSE
);
242 empathy_invite_participant_dialog_class_init (
243 EmpathyInviteParticipantDialogClass
*klass
)
245 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
247 object_class
->get_property
= invite_participant_dialog_get_property
;
248 object_class
->set_property
= invite_participant_dialog_set_property
;
249 object_class
->constructed
= invite_participant_dialog_constructed
;
250 object_class
->dispose
= invite_participant_dialog_dispose
;
252 g_type_class_add_private (object_class
,
253 sizeof (EmpathyInviteParticipantDialogPrivate
));
255 g_object_class_install_property (object_class
,
257 g_param_spec_object ("tp-chat", "EmpathyTpChat", "EmpathyTpChat",
258 EMPATHY_TYPE_TP_CHAT
,
259 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS
));
263 empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog
*self
)
265 self
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (
266 self
, EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG
,
267 EmpathyInviteParticipantDialogPrivate
);
271 empathy_invite_participant_dialog_new (GtkWindow
*parent
,
272 EmpathyTpChat
*tp_chat
)
274 GtkWidget
*self
= g_object_new (EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG
,
280 gtk_window_set_transient_for (GTK_WINDOW (self
), parent
);
287 empathy_invite_participant_dialog_get_selected (
288 EmpathyInviteParticipantDialog
*self
)
290 FolksIndividual
*individual
;
293 individual
= empathy_contact_chooser_dup_selected (
294 EMPATHY_CONTACT_CHOOSER (self
->priv
->chooser
));
295 if (individual
== NULL
)
298 contact
= get_tp_contact_for_chat (self
, individual
);
300 g_object_unref (individual
);