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 <libmissioncontrol/mission-control.h>
34 #include <libempathy/empathy-contact-manager.h>
35 #include <libempathy/empathy-contact-list.h>
36 #include <libempathy/empathy-utils.h>
38 #include "empathy-contact-dialogs.h"
39 #include "empathy-contact-widget.h"
40 #include "empathy-ui-utils.h"
42 static GList *subscription_dialogs = NULL;
43 static GList *information_dialogs = NULL;
44 static GtkWidget *new_contact_dialog = NULL;
48 contact_dialogs_find (GtkDialog *dialog,
49 EmpathyContact *contact)
51 GtkWidget *contact_widget;
52 EmpathyContact *this_contact;
54 contact_widget = g_object_get_data (G_OBJECT (dialog), "contact_widget");
55 this_contact = empathy_contact_widget_get_contact (contact_widget);
57 return !empathy_contact_equal (contact, this_contact);
65 subscription_dialog_response_cb (GtkDialog *dialog,
67 GtkWidget *contact_widget)
69 EmpathyContactManager *manager;
70 EmpathyContact *contact;
72 manager = empathy_contact_manager_new ();
73 contact = empathy_contact_widget_get_contact (contact_widget);
75 if (response == GTK_RESPONSE_YES) {
76 empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager),
79 else if (response == GTK_RESPONSE_NO) {
80 empathy_contact_list_remove (EMPATHY_CONTACT_LIST (manager),
84 subscription_dialogs = g_list_remove (subscription_dialogs, dialog);
85 gtk_widget_destroy (GTK_WIDGET (dialog));
86 g_object_unref (manager);
90 empathy_subscription_dialog_show (EmpathyContact *contact,
94 GtkWidget *hbox_subscription;
95 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 empathy_glade_get_file_simple ("empathy-contact-dialogs.glade",
109 "subscription_request_dialog",
111 "subscription_request_dialog", &dialog,
112 "hbox_subscription", &hbox_subscription,
115 contact_widget = empathy_contact_widget_new (contact,
116 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
117 EMPATHY_CONTACT_WIDGET_EDIT_GROUPS);
118 gtk_box_pack_end (GTK_BOX (hbox_subscription),
123 g_object_set_data (G_OBJECT (dialog), "contact_widget", contact_widget);
124 subscription_dialogs = g_list_prepend (subscription_dialogs, dialog);
126 g_signal_connect (dialog, "response",
127 G_CALLBACK (subscription_dialog_response_cb),
131 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
134 gtk_widget_show (dialog);
142 contact_information_response_cb (GtkDialog *dialog,
144 GtkWidget *contact_widget)
146 information_dialogs = g_list_remove (information_dialogs, dialog);
147 gtk_widget_destroy (GTK_WIDGET (dialog));
151 empathy_contact_information_dialog_show (EmpathyContact *contact,
154 gboolean edit_groups)
158 GtkWidget *contact_widget;
160 EmpathyContactWidgetFlags flags = 0;
162 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
164 l = g_list_find_custom (information_dialogs,
166 (GCompareFunc) contact_dialogs_find);
168 gtk_window_present (GTK_WINDOW (l->data));
173 dialog = gtk_dialog_new ();
174 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
175 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
176 gtk_window_set_title (GTK_WINDOW (dialog), _("Contact information"));
179 button = gtk_button_new_with_label (GTK_STOCK_CLOSE);
180 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
181 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
184 gtk_widget_show (button);
186 /* Contact info widget */
188 flags |= EMPATHY_CONTACT_WIDGET_EDIT_ALIAS;
189 if (empathy_contact_is_user (contact)) {
190 flags |= EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT |
191 EMPATHY_CONTACT_WIDGET_EDIT_AVATAR;
195 flags |= EMPATHY_CONTACT_WIDGET_EDIT_GROUPS;
197 contact_widget = empathy_contact_widget_new (contact, flags);
198 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
201 if (flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT) {
202 empathy_contact_widget_set_account_filter (contact_widget,
203 empathy_account_chooser_filter_is_connected,
207 g_object_set_data (G_OBJECT (dialog), "contact_widget", contact_widget);
208 information_dialogs = g_list_prepend (information_dialogs, dialog);
210 g_signal_connect (dialog, "response",
211 G_CALLBACK (contact_information_response_cb),
215 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
218 gtk_widget_show (dialog);
226 can_add_contact_to_account (McAccount *account,
230 TelepathyConnectionStatus status;
232 const gchar *protocol_name;
234 mc = empathy_mission_control_new ();
235 status = mission_control_get_connection_status (mc, account, NULL);
237 if (status != TP_CONN_STATUS_CONNECTED) {
238 /* Account is disconnected */
242 profile = mc_account_get_profile (account);
243 protocol_name = mc_profile_get_protocol_name (profile);
244 if (strcmp (protocol_name, "local-xmpp") == 0) {
245 /* We can't add accounts to a XMPP LL connection
246 * FIXME: We should inspect the flags of the contact list group interface
248 g_object_unref (profile);
252 g_object_unref (profile);
257 new_contact_response_cb (GtkDialog *dialog,
259 GtkWidget *contact_widget)
261 EmpathyContactManager *manager;
262 EmpathyContact *contact;
264 manager = empathy_contact_manager_new ();
265 contact = empathy_contact_widget_get_contact (contact_widget);
267 if (contact && response == GTK_RESPONSE_OK) {
268 empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager),
270 _("I would like to add you to my contact list."));
273 new_contact_dialog = NULL;
274 gtk_widget_destroy (GTK_WIDGET (dialog));
275 g_object_unref (manager);
279 empathy_new_contact_dialog_show (GtkWindow *parent)
283 GtkWidget *contact_widget;
285 if (new_contact_dialog) {
286 gtk_window_present (GTK_WINDOW (new_contact_dialog));
291 dialog = gtk_dialog_new ();
292 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
293 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
294 gtk_window_set_title (GTK_WINDOW (dialog), _("New contact"));
297 button = gtk_button_new_with_label (GTK_STOCK_CANCEL);
298 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
299 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
301 GTK_RESPONSE_CANCEL);
302 gtk_widget_show (button);
305 button = gtk_button_new_with_label (GTK_STOCK_ADD);
306 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
307 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
310 gtk_widget_show (button);
312 /* Contact info widget */
313 contact_widget = empathy_contact_widget_new (NULL,
314 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
315 EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT |
316 EMPATHY_CONTACT_WIDGET_EDIT_ID |
317 EMPATHY_CONTACT_WIDGET_EDIT_GROUPS);
318 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
321 empathy_contact_widget_set_account_filter (contact_widget,
322 can_add_contact_to_account,
325 new_contact_dialog = dialog;
327 g_signal_connect (dialog, "response",
328 G_CALLBACK (new_contact_response_cb),
332 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
335 gtk_widget_show (dialog);