Update Greek translation
[empathy-mirror.git] / libempathy-gtk / empathy-individual-dialogs.c
blobeedd1e7ebca5c991d3d56f6bf2d2b66b601abb1c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * Copyright (C) 2007-2010 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
22 #include "config.h"
23 #include "empathy-individual-dialogs.h"
25 #include <glib/gi18n-lib.h>
26 #include <telepathy-glib/telepathy-glib-dbus.h>
28 #include "empathy-contact-widget.h"
29 #include "empathy-individual-manager.h"
30 #include "empathy-utils.h"
32 #define BULLET_POINT "\342\200\242"
34 static GtkWidget *new_individual_dialog = NULL;
37 * New contact dialog
40 static void
41 can_add_contact_to_account (TpAccount *account,
42 EmpathyAccountChooserFilterResultCallback callback,
43 gpointer callback_data,
44 gpointer user_data)
46 EmpathyIndividualManager *individual_manager;
47 TpConnection *connection;
48 gboolean result;
50 connection = tp_account_get_connection (account);
51 if (connection == NULL)
53 callback (FALSE, callback_data);
54 return;
57 individual_manager = empathy_individual_manager_dup_singleton ();
58 result = empathy_connection_can_add_personas (connection);
59 g_object_unref (individual_manager);
61 callback (result, callback_data);
64 static void
65 new_individual_response_cb (GtkDialog *dialog,
66 gint response,
67 GtkWidget *contact_widget)
69 EmpathyIndividualManager *individual_manager;
70 EmpathyContact *contact;
72 individual_manager = empathy_individual_manager_dup_singleton ();
73 contact = empathy_contact_widget_get_contact (contact_widget);
75 if (contact && response == GTK_RESPONSE_OK)
76 empathy_individual_manager_add_from_contact (individual_manager, contact);
78 new_individual_dialog = NULL;
79 gtk_widget_destroy (GTK_WIDGET (dialog));
80 g_object_unref (individual_manager);
83 void
84 empathy_new_individual_dialog_show (GtkWindow *parent)
86 empathy_new_individual_dialog_show_with_individual (parent, NULL);
89 void
90 empathy_new_individual_dialog_show_with_individual (GtkWindow *parent,
91 FolksIndividual *individual)
93 GtkWidget *dialog;
94 GtkWidget *button;
95 EmpathyContact *contact = NULL;
96 GtkWidget *contact_widget;
98 g_return_if_fail (individual == NULL || FOLKS_IS_INDIVIDUAL (individual));
100 if (new_individual_dialog)
102 gtk_window_present (GTK_WINDOW (new_individual_dialog));
103 return;
106 /* Create dialog */
107 dialog = gtk_dialog_new ();
108 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
109 gtk_window_set_title (GTK_WINDOW (dialog), _("New Contact"));
111 /* Cancel button */
112 button = gtk_button_new_with_label (GTK_STOCK_CANCEL);
113 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
114 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
115 GTK_RESPONSE_CANCEL);
116 gtk_widget_show (button);
118 /* Add button */
119 button = gtk_button_new_with_label (GTK_STOCK_ADD);
120 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
121 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, GTK_RESPONSE_OK);
122 gtk_widget_show (button);
124 /* Contact info widget */
125 if (individual != NULL)
126 contact = empathy_contact_dup_from_folks_individual (individual);
128 contact_widget = empathy_contact_widget_new (contact);
129 gtk_container_set_border_width (GTK_CONTAINER (contact_widget), 8);
130 gtk_box_pack_start (
131 GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
132 contact_widget, TRUE, TRUE, 0);
133 empathy_contact_widget_set_account_filter (contact_widget,
134 can_add_contact_to_account, NULL);
135 gtk_widget_show (contact_widget);
137 new_individual_dialog = dialog;
139 g_signal_connect (dialog, "response", G_CALLBACK (new_individual_response_cb),
140 contact_widget);
142 if (parent != NULL)
143 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
145 gtk_widget_show (dialog);
147 tp_clear_object (&contact);
150 static char *
151 contact_pretty_name (TpContact *contact)
153 const char *alias = tp_contact_get_alias (contact);
154 const char *identifier = tp_contact_get_identifier (contact);
156 if (tp_strdiff (alias, identifier))
157 return g_strdup_printf ("%s (%s)", alias, identifier);
158 else
159 return g_strdup (alias);
163 * Block contact dialog
165 gboolean
166 empathy_block_individual_dialog_show (GtkWindow *parent,
167 FolksIndividual *individual,
168 GdkPixbuf *avatar,
169 gboolean *abusive)
171 GtkWidget *dialog;
172 GtkWidget *abusive_check = NULL;
173 GeeSet *personas;
174 GeeIterator *iter;
175 GString *text = g_string_new ("");
176 GString *blocked_str = g_string_new ("");
177 GString *notblocked_str = g_string_new ("");
178 guint npersonas_blocked = 0, npersonas_notblocked = 0;
179 gboolean can_report_abuse = FALSE;
180 int res;
182 dialog = gtk_message_dialog_new (parent,
183 GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
184 _("Block %s?"),
185 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
187 if (avatar != NULL)
189 GtkWidget *image = gtk_image_new_from_pixbuf (avatar);
190 gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
191 gtk_widget_show (image);
194 /* build a list of personas that support blocking */
195 personas = folks_individual_get_personas (individual);
196 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
197 while (gee_iterator_next (iter))
199 TpfPersona *persona = gee_iterator_get (iter);
200 TpContact *contact;
201 GString *s;
202 char *str;
203 TpConnection *conn;
205 if (!TPF_IS_PERSONA (persona))
206 goto while_finish;
208 contact = tpf_persona_get_contact (persona);
209 if (contact == NULL)
210 goto while_finish;
212 conn = tp_contact_get_connection (contact);
214 if (tp_proxy_has_interface_by_id (conn,
215 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
217 s = blocked_str;
218 npersonas_blocked++;
220 else
222 s = notblocked_str;
223 npersonas_notblocked++;
226 if (tp_connection_can_report_abusive (conn))
227 can_report_abuse = TRUE;
229 str = contact_pretty_name (contact);
230 g_string_append_printf (s, "\n " BULLET_POINT " %s", str);
231 g_free (str);
233 while_finish:
234 g_clear_object (&persona);
236 g_clear_object (&iter);
238 g_string_append_printf (text,
239 _("Are you sure you want to block ā€œ%sā€ from contacting you again?"),
240 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
242 if (npersonas_blocked > 0)
243 g_string_append_printf (text, "\n\n%s\n%s",
244 ngettext ("The following identity will be blocked:",
245 "The following identities will be blocked:",
246 npersonas_blocked),
247 blocked_str->str);
249 if (npersonas_notblocked > 0)
250 g_string_append_printf (text, "\n\n%s\n%s",
251 ngettext ("The following identity can not be blocked:",
252 "The following identities can not be blocked:",
253 npersonas_notblocked),
254 notblocked_str->str);
256 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
257 "%s", text->str);
259 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
260 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
261 _("_Block"), GTK_RESPONSE_REJECT,
262 NULL);
264 if (can_report_abuse)
266 GtkWidget *vbox;
268 vbox = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog));
269 abusive_check = gtk_check_button_new_with_mnemonic (
270 ngettext ("_Report this contact as abusive",
271 "_Report these contacts as abusive",
272 npersonas_blocked));
274 gtk_box_pack_start (GTK_BOX (vbox), abusive_check, FALSE, TRUE, 0);
275 gtk_widget_show (abusive_check);
278 g_string_free (text, TRUE);
279 g_string_free (blocked_str, TRUE);
280 g_string_free (notblocked_str, TRUE);
282 res = gtk_dialog_run (GTK_DIALOG (dialog));
284 if (abusive != NULL)
286 if (abusive_check != NULL)
287 *abusive = gtk_toggle_button_get_active (
288 GTK_TOGGLE_BUTTON (abusive_check));
289 else
290 *abusive = FALSE;
293 gtk_widget_destroy (dialog);
295 return res == GTK_RESPONSE_REJECT;