1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program 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 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Xavier Claessens <xclaesse@gmail.com>
29 #include <glade/glade.h>
30 #include <glib/gi18n.h>
32 #include <libempathy/empathy-contact-manager.h>
33 #include <libempathy/empathy-contact-list.h>
35 #include "empathy-contact-dialogs.h"
36 #include "empathy-contact-widget.h"
37 #include "empathy-ui-utils.h"
39 static GList *subscription_dialogs = NULL;
40 static GList *information_dialogs = NULL;
41 static GtkWidget *new_contact_dialog = NULL;
45 contact_dialogs_find (GtkDialog *dialog,
46 EmpathyContact *contact)
48 GtkWidget *contact_widget;
49 EmpathyContact *this_contact;
51 contact_widget = g_object_get_data (G_OBJECT (dialog), "contact_widget");
52 this_contact = empathy_contact_widget_get_contact (contact_widget);
54 return !empathy_contact_equal (contact, this_contact);
62 subscription_dialog_response_cb (GtkDialog *dialog,
64 GtkWidget *contact_widget)
66 EmpathyContactManager *manager;
67 EmpathyContact *contact;
69 manager = empathy_contact_manager_new ();
70 contact = empathy_contact_widget_get_contact (contact_widget);
72 if (response == GTK_RESPONSE_YES) {
73 empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager),
76 else if (response == GTK_RESPONSE_NO) {
77 empathy_contact_list_remove (EMPATHY_CONTACT_LIST (manager),
81 subscription_dialogs = g_list_remove (subscription_dialogs, dialog);
82 gtk_widget_destroy (GTK_WIDGET (dialog));
83 g_object_unref (manager);
87 empathy_subscription_dialog_show (EmpathyContact *contact,
91 GtkWidget *hbox_subscription;
92 GtkWidget *contact_widget;
95 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
97 l = g_list_find_custom (subscription_dialogs,
99 (GCompareFunc) contact_dialogs_find);
101 gtk_window_present (GTK_WINDOW (l->data));
105 empathy_glade_get_file_simple ("empathy-contact-dialogs.glade",
106 "subscription_request_dialog",
108 "subscription_request_dialog", &dialog,
109 "hbox_subscription", &hbox_subscription,
112 contact_widget = empathy_contact_widget_new (contact,
113 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
114 EMPATHY_CONTACT_WIDGET_EDIT_GROUPS);
115 gtk_box_pack_end (GTK_BOX (hbox_subscription),
120 g_object_set_data (G_OBJECT (dialog), "contact_widget", contact_widget);
121 subscription_dialogs = g_list_prepend (subscription_dialogs, dialog);
123 g_signal_connect (dialog, "response",
124 G_CALLBACK (subscription_dialog_response_cb),
128 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
131 gtk_widget_show (dialog);
139 contact_information_response_cb (GtkDialog *dialog,
141 GtkWidget *contact_widget)
143 information_dialogs = g_list_remove (information_dialogs, dialog);
144 gtk_widget_destroy (GTK_WIDGET (dialog));
148 empathy_contact_information_dialog_show (EmpathyContact *contact,
151 gboolean edit_groups)
155 GtkWidget *contact_widget;
157 EmpathyContactWidgetFlags flags = 0;
159 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
161 l = g_list_find_custom (information_dialogs,
163 (GCompareFunc) contact_dialogs_find);
165 gtk_window_present (GTK_WINDOW (l->data));
170 dialog = gtk_dialog_new ();
171 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
172 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
173 gtk_window_set_title (GTK_WINDOW (dialog), _("Contact information"));
176 button = gtk_button_new_with_label (GTK_STOCK_CLOSE);
177 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
178 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
181 gtk_widget_show (button);
183 /* Contact info widget */
185 flags |= EMPATHY_CONTACT_WIDGET_EDIT_ALIAS;
186 if (empathy_contact_is_user (contact)) {
187 flags |= EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT |
188 EMPATHY_CONTACT_WIDGET_EDIT_AVATAR;
192 flags |= EMPATHY_CONTACT_WIDGET_EDIT_GROUPS;
194 contact_widget = empathy_contact_widget_new (contact, flags);
195 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
199 g_object_set_data (G_OBJECT (dialog), "contact_widget", contact_widget);
200 information_dialogs = g_list_prepend (information_dialogs, dialog);
202 g_signal_connect (dialog, "response",
203 G_CALLBACK (contact_information_response_cb),
207 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
210 gtk_widget_show (dialog);
218 new_contact_response_cb (GtkDialog *dialog,
220 GtkWidget *contact_widget)
222 EmpathyContactManager *manager;
223 EmpathyContact *contact;
225 manager = empathy_contact_manager_new ();
226 contact = empathy_contact_widget_get_contact (contact_widget);
228 if (contact && response == GTK_RESPONSE_OK) {
229 empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager),
231 _("I would like to add you to my contact list."));
234 new_contact_dialog = NULL;
235 gtk_widget_destroy (GTK_WIDGET (dialog));
236 g_object_unref (manager);
240 empathy_new_contact_dialog_show (GtkWindow *parent)
244 GtkWidget *contact_widget;
246 if (new_contact_dialog) {
247 gtk_window_present (GTK_WINDOW (new_contact_dialog));
252 dialog = gtk_dialog_new ();
253 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
254 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
255 gtk_window_set_title (GTK_WINDOW (dialog), _("New contact"));
258 button = gtk_button_new_with_label (GTK_STOCK_CANCEL);
259 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
260 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
262 GTK_RESPONSE_CANCEL);
263 gtk_widget_show (button);
266 button = gtk_button_new_with_label (GTK_STOCK_ADD);
267 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
268 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
271 gtk_widget_show (button);
273 /* Contact info widget */
274 contact_widget = empathy_contact_widget_new (NULL,
275 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
276 EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT |
277 EMPATHY_CONTACT_WIDGET_EDIT_ID |
278 EMPATHY_CONTACT_WIDGET_EDIT_GROUPS);
279 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
283 new_contact_dialog = dialog;
285 g_signal_connect (dialog, "response",
286 G_CALLBACK (new_contact_response_cb),
290 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
293 gtk_widget_show (dialog);