1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2008 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 <libmissioncontrol/mission-control.h>
32 #include <libempathy/empathy-contact-manager.h>
33 #include <libempathy/empathy-contact-list.h>
34 #include <libempathy/empathy-utils.h>
36 #include "empathy-contact-dialogs.h"
37 #include "empathy-contact-widget.h"
38 #include "empathy-ui-utils.h"
40 static GList *subscription_dialogs = NULL;
41 static GList *information_dialogs = NULL;
42 static GtkWidget *new_contact_dialog = NULL;
46 contact_dialogs_find (GtkDialog *dialog,
47 EmpathyContact *contact)
49 GtkWidget *contact_widget;
50 EmpathyContact *this_contact;
52 contact_widget = g_object_get_data (G_OBJECT (dialog), "contact_widget");
53 this_contact = empathy_contact_widget_get_contact (contact_widget);
55 return contact != this_contact;
63 subscription_dialog_response_cb (GtkDialog *dialog,
65 GtkWidget *contact_widget)
67 EmpathyContactManager *manager;
68 EmpathyContact *contact;
70 manager = empathy_contact_manager_dup_singleton ();
71 contact = empathy_contact_widget_get_contact (contact_widget);
73 if (response == GTK_RESPONSE_YES) {
74 empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager),
77 else if (response == GTK_RESPONSE_NO) {
78 empathy_contact_list_remove (EMPATHY_CONTACT_LIST (manager),
82 subscription_dialogs = g_list_remove (subscription_dialogs, dialog);
83 gtk_widget_destroy (GTK_WIDGET (dialog));
84 g_object_unref (manager);
88 empathy_subscription_dialog_show (EmpathyContact *contact,
93 GtkWidget *hbox_subscription;
94 GtkWidget *contact_widget;
98 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
100 l = g_list_find_custom (subscription_dialogs,
102 (GCompareFunc) contact_dialogs_find);
104 gtk_window_present (GTK_WINDOW (l->data));
108 filename = empathy_file_lookup ("empathy-contact-dialogs.ui",
110 gui = empathy_builder_get_file (filename,
111 "subscription_request_dialog", &dialog,
112 "hbox_subscription", &hbox_subscription,
115 g_object_unref (gui);
117 contact_widget = empathy_contact_widget_new (contact,
118 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
119 EMPATHY_CONTACT_WIDGET_EDIT_GROUPS);
120 gtk_box_pack_end (GTK_BOX (hbox_subscription),
125 g_object_set_data (G_OBJECT (dialog), "contact_widget", contact_widget);
126 subscription_dialogs = g_list_prepend (subscription_dialogs, dialog);
128 g_signal_connect (dialog, "response",
129 G_CALLBACK (subscription_dialog_response_cb),
133 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
136 gtk_widget_show (dialog);
144 contact_information_response_cb (GtkDialog *dialog,
146 GtkWidget *contact_widget)
148 information_dialogs = g_list_remove (information_dialogs, dialog);
149 gtk_widget_destroy (GTK_WIDGET (dialog));
153 empathy_contact_information_dialog_show (EmpathyContact *contact,
160 GtkWidget *contact_widget;
162 EmpathyContactWidgetFlags flags = 0;
164 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
166 l = g_list_find_custom (information_dialogs,
168 (GCompareFunc) contact_dialogs_find);
170 gtk_window_present (GTK_WINDOW (l->data));
175 dialog = gtk_dialog_new ();
176 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
177 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
179 gtk_window_set_title (GTK_WINDOW (dialog), _("Personal Information"));
182 gtk_window_set_title (GTK_WINDOW (dialog), _("Edit Contact Information"));
185 gtk_window_set_title (GTK_WINDOW (dialog), _("Contact Information"));
189 button = gtk_button_new_with_label (GTK_STOCK_CLOSE);
190 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
191 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
194 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
195 gtk_window_set_default (GTK_WINDOW (dialog), button);
196 gtk_widget_show (button);
198 /* Contact info widget */
200 flags |= EMPATHY_CONTACT_WIDGET_EDIT_ALIAS;
203 flags |= EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT;
204 flags |= EMPATHY_CONTACT_WIDGET_EDIT_AVATAR;
206 if (!is_user && edit) {
207 flags |= EMPATHY_CONTACT_WIDGET_EDIT_GROUPS;
209 contact_widget = empathy_contact_widget_new (contact, flags);
210 gtk_container_set_border_width (GTK_CONTAINER (contact_widget), 8);
211 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
214 if (flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT) {
215 empathy_contact_widget_set_account_filter (contact_widget,
216 empathy_account_chooser_filter_is_connected,
220 g_object_set_data (G_OBJECT (dialog), "contact_widget", contact_widget);
221 information_dialogs = g_list_prepend (information_dialogs, dialog);
223 g_signal_connect (dialog, "response",
224 G_CALLBACK (contact_information_response_cb),
228 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
231 gtk_widget_show (dialog);
239 can_add_contact_to_account (McAccount *account,
242 EmpathyContactManager *mgr;
245 mgr = empathy_contact_manager_dup_singleton ();
246 result = empathy_contact_manager_can_add (mgr, account);
247 g_object_unref (mgr);
253 new_contact_response_cb (GtkDialog *dialog,
255 GtkWidget *contact_widget)
257 EmpathyContactManager *manager;
258 EmpathyContact *contact;
260 manager = empathy_contact_manager_dup_singleton ();
261 contact = empathy_contact_widget_get_contact (contact_widget);
263 if (contact && response == GTK_RESPONSE_OK) {
264 empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager),
266 _("I would like to add you to my contact list."));
269 new_contact_dialog = NULL;
270 gtk_widget_destroy (GTK_WIDGET (dialog));
271 g_object_unref (manager);
275 empathy_new_contact_dialog_show (GtkWindow *parent)
279 GtkWidget *contact_widget;
281 if (new_contact_dialog) {
282 gtk_window_present (GTK_WINDOW (new_contact_dialog));
287 dialog = gtk_dialog_new ();
288 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
289 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
290 gtk_window_set_title (GTK_WINDOW (dialog), _("New Contact"));
293 button = gtk_button_new_with_label (GTK_STOCK_CANCEL);
294 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
295 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
297 GTK_RESPONSE_CANCEL);
298 gtk_widget_show (button);
301 button = gtk_button_new_with_label (GTK_STOCK_ADD);
302 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
303 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
306 gtk_widget_show (button);
308 /* Contact info widget */
309 contact_widget = empathy_contact_widget_new (NULL,
310 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
311 EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT |
312 EMPATHY_CONTACT_WIDGET_EDIT_ID |
313 EMPATHY_CONTACT_WIDGET_EDIT_GROUPS);
314 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
317 empathy_contact_widget_set_account_filter (contact_widget,
318 can_add_contact_to_account,
321 new_contact_dialog = dialog;
323 g_signal_connect (dialog, "response",
324 G_CALLBACK (new_contact_response_cb),
328 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
331 gtk_widget_show (dialog);