2 * Copyright (C) 2012 Collabora Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.com>
22 #include "empathy-subscription-dialog.h"
24 #include <glib/gi18n-lib.h>
25 #include <telepathy-glib/telepathy-glib-dbus.h>
27 #include "empathy-individual-widget.h"
28 #include "empathy-utils.h"
30 G_DEFINE_TYPE (EmpathySubscriptionDialog
, empathy_subscription_dialog
, GTK_TYPE_MESSAGE_DIALOG
)
45 static guint signals[LAST_SIGNAL];
48 struct _EmpathySubscriptionDialogPriv
50 FolksIndividual
*individual
;
55 empathy_subscription_dialog_get_property (GObject
*object
,
60 EmpathySubscriptionDialog
*self
= EMPATHY_SUBSCRIPTION_DIALOG (object
);
65 g_value_set_object (value
, self
->priv
->individual
);
68 g_value_set_string (value
, self
->priv
->message
);
71 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
77 empathy_subscription_dialog_set_property (GObject
*object
,
82 EmpathySubscriptionDialog
*self
= EMPATHY_SUBSCRIPTION_DIALOG (object
);
87 g_assert (self
->priv
->individual
== NULL
); /* construct only */
88 self
->priv
->individual
= g_value_dup_object (value
);
91 g_assert (self
->priv
->message
== NULL
); /* construct only */
92 self
->priv
->message
= g_value_dup_string (value
);
95 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
101 * block_contact_dialog_show:
102 * @parent: the parent of this dialog (or %NULL)
103 * @contact: the contact for this dialog
104 * @abusive: a pointer to store the value of the abusive contact check box
107 * Returns: %TRUE if the user wishes to block the contact
110 block_contact_dialog_show (GtkWindow
*parent
,
111 EmpathyContact
*contact
,
116 GtkWidget
*abusive_check
= NULL
;
120 dialog
= gtk_message_dialog_new (parent
, GTK_DIALOG_MODAL
,
121 GTK_MESSAGE_QUESTION
, GTK_BUTTONS_NONE
, _("Block %s?"),
122 empathy_contact_get_alias (contact
));
124 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog
),
125 _("Are you sure you want to block '%s' from contacting you again?"),
126 empathy_contact_get_alias (contact
));
128 gtk_dialog_add_buttons (GTK_DIALOG (dialog
),
129 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
130 _("_Block"), GTK_RESPONSE_REJECT
,
135 GtkWidget
*image
= gtk_image_new_from_pixbuf (avatar
);
136 gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog
), image
);
137 gtk_widget_show (image
);
140 conn
= empathy_contact_get_connection (contact
);
142 /* ask the user if they want to also report the contact as abusive */
143 if (tp_connection_can_report_abusive (conn
))
147 vbox
= gtk_message_dialog_get_message_area (
148 GTK_MESSAGE_DIALOG (dialog
));
149 abusive_check
= gtk_check_button_new_with_mnemonic (
150 _("_Report this contact as abusive"));
152 gtk_box_pack_start (GTK_BOX (vbox
), abusive_check
,
154 gtk_widget_show (abusive_check
);
157 res
= gtk_dialog_run (GTK_DIALOG (dialog
));
160 if (abusive_check
!= NULL
)
161 *abusive
= gtk_toggle_button_get_active (
162 GTK_TOGGLE_BUTTON (abusive_check
));
167 gtk_widget_destroy (dialog
);
169 return res
== GTK_RESPONSE_REJECT
;
173 response_cb (GtkDialog
*dialog
,
175 EmpathySubscriptionDialog
*self
)
177 EmpathyContact
*contact
;
179 contact
= empathy_contact_dup_from_folks_individual (self
->priv
->individual
);
181 if (reponse
== GTK_RESPONSE_YES
)
183 empathy_contact_add_to_contact_list (contact
, "");
185 else if (reponse
== GTK_RESPONSE_NO
)
187 empathy_contact_remove_from_contact_list (contact
);
189 else if (reponse
== GTK_RESPONSE_REJECT
)
193 /* confirm the blocking */
194 if (block_contact_dialog_show (GTK_WINDOW (dialog
), contact
,
197 TpContact
*tp_contact
;
199 empathy_contact_remove_from_contact_list (contact
);
201 tp_contact
= empathy_contact_get_tp_contact (contact
);
203 tp_contact_block_async (tp_contact
, abusive
, NULL
, NULL
);
207 /* if they don't confirm, return back to the
213 gtk_widget_destroy (GTK_WIDGET (self
));
217 empathy_subscription_dialog_constructed (GObject
*object
)
219 EmpathySubscriptionDialog
*self
= EMPATHY_SUBSCRIPTION_DIALOG (object
);
220 void (*chain_up
) (GObject
*) =
221 ((GObjectClass
*) empathy_subscription_dialog_parent_class
)->constructed
;
223 GtkWidget
*individual_widget
;
226 EmpathyContact
*contact
;
229 if (chain_up
!= NULL
)
232 g_assert (self
->priv
->individual
!= NULL
);
234 gtk_window_set_title (GTK_WINDOW (self
), _("Subscription Request"));
236 alias
= folks_alias_details_get_alias (
237 FOLKS_ALIAS_DETAILS (self
->priv
->individual
));
239 tmp
= g_strdup_printf (
240 _("%s would like permission to see when you are online"), alias
);
242 /* Why is there no gtk_message_dialog_set_text()? */
243 g_object_set (self
, "text", tmp
, NULL
);
246 if (self
->priv
->message
!= NULL
)
248 tmp
= g_strdup_printf ("<i>%s</i>", self
->priv
->message
);
249 gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (self
),
254 /* Individual widget */
255 individual_widget
= empathy_individual_widget_new (self
->priv
->individual
,
256 EMPATHY_INDIVIDUAL_WIDGET_EDIT_ALIAS
|
257 EMPATHY_INDIVIDUAL_WIDGET_EDIT_GROUPS
|
258 EMPATHY_INDIVIDUAL_WIDGET_SHOW_DETAILS
);
260 gtk_container_set_border_width (GTK_CONTAINER (individual_widget
), 8);
262 content
= gtk_dialog_get_content_area (GTK_DIALOG (self
));
264 gtk_box_pack_start (GTK_BOX (content
), individual_widget
, TRUE
, TRUE
, 0);
265 gtk_widget_show (individual_widget
);
267 /* Add 'Block' button if supported */
268 contact
= empathy_contact_dup_from_folks_individual (self
->priv
->individual
);
269 conn
= empathy_contact_get_connection (contact
);
271 if (tp_proxy_has_interface_by_id (conn
,
272 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING
))
274 gtk_dialog_add_button (GTK_DIALOG (self
),
275 _("_Block"), GTK_RESPONSE_REJECT
);
278 g_object_unref (contact
);
280 gtk_dialog_add_buttons (GTK_DIALOG (self
),
281 _("_Decline"), GTK_RESPONSE_NO
,
282 _("_Accept"), GTK_RESPONSE_YES
,
285 g_signal_connect (self
, "response",
286 G_CALLBACK (response_cb
), self
);
290 empathy_subscription_dialog_dispose (GObject
*object
)
292 EmpathySubscriptionDialog
*self
= EMPATHY_SUBSCRIPTION_DIALOG (object
);
293 void (*chain_up
) (GObject
*) =
294 ((GObjectClass
*) empathy_subscription_dialog_parent_class
)->dispose
;
296 g_clear_object (&self
->priv
->individual
);
298 if (chain_up
!= NULL
)
303 empathy_subscription_dialog_finalize (GObject
*object
)
305 EmpathySubscriptionDialog
*self
= EMPATHY_SUBSCRIPTION_DIALOG (object
);
306 void (*chain_up
) (GObject
*) =
307 ((GObjectClass
*) empathy_subscription_dialog_parent_class
)->finalize
;
309 g_free (self
->priv
->message
);
311 if (chain_up
!= NULL
)
316 empathy_subscription_dialog_class_init (
317 EmpathySubscriptionDialogClass
*klass
)
319 GObjectClass
*oclass
= G_OBJECT_CLASS (klass
);
322 oclass
->get_property
= empathy_subscription_dialog_get_property
;
323 oclass
->set_property
= empathy_subscription_dialog_set_property
;
324 oclass
->constructed
= empathy_subscription_dialog_constructed
;
325 oclass
->dispose
= empathy_subscription_dialog_dispose
;
326 oclass
->finalize
= empathy_subscription_dialog_finalize
;
328 spec
= g_param_spec_object ("individual", "individual",
330 FOLKS_TYPE_INDIVIDUAL
,
331 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS
);
332 g_object_class_install_property (oclass
, PROP_INDIVIDUAL
, spec
);
334 spec
= g_param_spec_string ("message", "message",
337 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS
);
338 g_object_class_install_property (oclass
, PROP_MESSAGE
, spec
);
340 g_type_class_add_private (klass
, sizeof (EmpathySubscriptionDialogPriv
));
344 empathy_subscription_dialog_init (EmpathySubscriptionDialog
*self
)
346 self
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (self
,
347 EMPATHY_TYPE_SUBSCRIPTION_DIALOG
, EmpathySubscriptionDialogPriv
);
351 empathy_subscription_dialog_new (FolksIndividual
*individual
,
352 const gchar
*message
)
354 return g_object_new (EMPATHY_TYPE_SUBSCRIPTION_DIALOG
,
355 "individual", individual
,
357 "message-type", GTK_MESSAGE_QUESTION
,