1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
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>
28 #include <glib/gi18n-lib.h>
30 #include <telepathy-glib/util.h>
31 #include <folks/folks.h>
32 #include <folks/folks-telepathy.h>
34 #include <libempathy/empathy-individual-manager.h>
35 #include <libempathy/empathy-utils.h>
37 #include "empathy-individual-dialogs.h"
38 #include "empathy-contact-widget.h"
39 #include "empathy-ui-utils.h"
41 #define BULLET_POINT "\342\200\242"
43 static GtkWidget *new_individual_dialog = NULL;
50 can_add_contact_to_account (TpAccount *account,
51 EmpathyAccountChooserFilterResultCallback callback,
52 gpointer callback_data,
55 EmpathyIndividualManager *individual_manager;
56 TpConnection *connection;
59 connection = tp_account_get_connection (account);
60 if (connection == NULL)
62 callback (FALSE, callback_data);
66 individual_manager = empathy_individual_manager_dup_singleton ();
67 result = empathy_connection_can_add_personas (connection);
68 g_object_unref (individual_manager);
70 callback (result, callback_data);
74 new_individual_response_cb (GtkDialog *dialog,
76 GtkWidget *contact_widget)
78 EmpathyIndividualManager *individual_manager;
79 EmpathyContact *contact;
81 individual_manager = empathy_individual_manager_dup_singleton ();
82 contact = empathy_contact_widget_get_contact (contact_widget);
84 if (contact && response == GTK_RESPONSE_OK)
85 empathy_individual_manager_add_from_contact (individual_manager, contact);
87 new_individual_dialog = NULL;
88 gtk_widget_destroy (GTK_WIDGET (dialog));
89 g_object_unref (individual_manager);
93 empathy_new_individual_dialog_show (GtkWindow *parent)
95 empathy_new_individual_dialog_show_with_individual (parent, NULL);
99 empathy_new_individual_dialog_show_with_individual (GtkWindow *parent,
100 FolksIndividual *individual)
104 EmpathyContact *contact = NULL;
105 GtkWidget *contact_widget;
107 g_return_if_fail (individual == NULL || FOLKS_IS_INDIVIDUAL (individual));
109 if (new_individual_dialog)
111 gtk_window_present (GTK_WINDOW (new_individual_dialog));
116 dialog = gtk_dialog_new ();
117 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
118 gtk_window_set_title (GTK_WINDOW (dialog), _("New Contact"));
121 button = gtk_button_new_with_label (GTK_STOCK_CANCEL);
122 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
123 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
124 GTK_RESPONSE_CANCEL);
125 gtk_widget_show (button);
128 button = gtk_button_new_with_label (GTK_STOCK_ADD);
129 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
130 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, GTK_RESPONSE_OK);
131 gtk_widget_show (button);
133 /* Contact info widget */
134 if (individual != NULL)
135 contact = empathy_contact_dup_from_folks_individual (individual);
137 contact_widget = empathy_contact_widget_new (contact,
138 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
139 EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT |
140 EMPATHY_CONTACT_WIDGET_EDIT_ID |
141 EMPATHY_CONTACT_WIDGET_EDIT_GROUPS);
142 gtk_container_set_border_width (GTK_CONTAINER (contact_widget), 8);
144 GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
145 contact_widget, TRUE, TRUE, 0);
146 empathy_contact_widget_set_account_filter (contact_widget,
147 can_add_contact_to_account, NULL);
148 gtk_widget_show (contact_widget);
150 new_individual_dialog = dialog;
152 g_signal_connect (dialog, "response", G_CALLBACK (new_individual_response_cb),
156 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
158 gtk_widget_show (dialog);
160 tp_clear_object (&contact);
164 * Block contact dialog
167 empathy_block_individual_dialog_show (GtkWindow *parent,
168 FolksIndividual *individual,
171 EmpathyIndividualManager *manager =
172 empathy_individual_manager_dup_singleton ();
174 GtkWidget *abusive_check = NULL;
176 GString *str = g_string_new ("");
178 gboolean can_report_abuse = FALSE;
181 dialog = gtk_message_dialog_new (parent,
182 GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
184 folks_aliasable_get_alias (FOLKS_ALIASABLE (individual)));
186 /* build a list of personas that support blocking */
187 personas = folks_individual_get_personas (individual);
189 for (l = personas; l != NULL; l = l->next)
191 TpfPersona *persona = l->data;
193 EmpathyIndividualManagerFlags flags;
195 if (!TPF_IS_PERSONA (persona))
198 contact = tpf_persona_get_contact (persona);
199 flags = empathy_individual_manager_get_flags_for_connection (manager,
200 tp_contact_get_connection (contact));
202 if (!(flags & EMPATHY_INDIVIDUAL_MANAGER_CAN_BLOCK))
204 else if (flags & EMPATHY_INDIVIDUAL_MANAGER_CAN_REPORT_ABUSIVE)
205 can_report_abuse = TRUE;
207 g_string_append_printf (str, "\n " BULLET_POINT " %s",
208 tp_contact_get_identifier (contact));
212 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
214 ngettext ("Are you sure you want to block the following contact?",
215 "Are you sure you want to block the following contacts?",
219 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
220 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
221 _("_Block"), GTK_RESPONSE_REJECT,
224 if (can_report_abuse)
228 vbox = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog));
229 abusive_check = gtk_check_button_new_with_mnemonic (
230 ngettext ("_Report this contact as abusive",
231 "_Report these contacts as abusive",
234 gtk_box_pack_start (GTK_BOX (vbox), abusive_check, FALSE, TRUE, 0);
235 gtk_widget_show (abusive_check);
238 g_object_unref (manager);
239 g_string_free (str, TRUE);
241 res = gtk_dialog_run (GTK_DIALOG (dialog));
242 gtk_widget_destroy (dialog);
246 if (abusive_check != NULL)
247 *abusive = gtk_toggle_button_get_active (
248 GTK_TOGGLE_BUTTON (abusive_check));
253 return res == GTK_RESPONSE_REJECT;