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 "gossip-ui-utils.h"
39 static GHashTable *subscription_dialogs = NULL;
40 static GHashTable *information_dialogs = NULL;
47 subscription_dialog_response_cb (GtkDialog *dialog,
49 GtkWidget *contact_widget)
51 EmpathyContactManager *manager;
52 GossipContact *contact;
54 manager = empathy_contact_manager_new ();
55 contact = empathy_contact_widget_get_contact (contact_widget);
56 empathy_contact_widget_save (contact_widget);
58 if (response == GTK_RESPONSE_YES) {
59 empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager),
61 _("I would like to add you to my contact list."));
63 else if (response == GTK_RESPONSE_NO) {
64 empathy_contact_list_remove (EMPATHY_CONTACT_LIST (manager),
66 _("Sorry, I don't want you in my contact list."));
69 g_hash_table_remove (subscription_dialogs, contact);
70 g_object_unref (manager);
74 empathy_subscription_dialog_show (GossipContact *contact,
78 GtkWidget *hbox_subscription;
79 GtkWidget *contact_widget;
81 g_return_if_fail (GOSSIP_IS_CONTACT (contact));
83 if (!subscription_dialogs) {
84 subscription_dialogs = g_hash_table_new_full (gossip_contact_hash,
86 (GDestroyNotify) g_object_unref,
87 (GDestroyNotify) gtk_widget_destroy);
90 dialog = g_hash_table_lookup (subscription_dialogs, contact);
92 gtk_window_present (GTK_WINDOW (dialog));
96 gossip_glade_get_file_simple ("empathy-contact-dialogs.glade",
97 "subscription_request_dialog",
99 "subscription_request_dialog", &dialog,
100 "hbox_subscription", &hbox_subscription,
103 g_hash_table_insert (subscription_dialogs, g_object_ref (contact), dialog);
105 contact_widget = empathy_contact_widget_new (contact, TRUE);
106 gtk_box_pack_end (GTK_BOX (hbox_subscription),
111 g_signal_connect (dialog, "response",
112 G_CALLBACK (subscription_dialog_response_cb),
116 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
119 gtk_widget_show (dialog);
127 contact_information_response_cb (GtkDialog *dialog,
129 GtkWidget *contact_widget)
131 GossipContact *contact;
133 contact = empathy_contact_widget_get_contact (contact_widget);
135 if (response == GTK_RESPONSE_OK) {
136 empathy_contact_widget_save (contact_widget);
139 g_hash_table_remove (information_dialogs, contact);
143 empathy_contact_information_dialog_show (GossipContact *contact,
149 GtkWidget *contact_widget;
151 g_return_if_fail (GOSSIP_IS_CONTACT (contact));
153 if (!information_dialogs) {
154 information_dialogs = g_hash_table_new_full (gossip_contact_hash,
155 gossip_contact_equal,
156 (GDestroyNotify) g_object_unref,
157 (GDestroyNotify) gtk_widget_destroy);
160 dialog = g_hash_table_lookup (information_dialogs, contact);
162 gtk_window_present (GTK_WINDOW (dialog));
166 dialog = gtk_dialog_new ();
167 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
168 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
172 button = gtk_button_new_with_label (GTK_STOCK_CANCEL);
173 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
174 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
176 GTK_RESPONSE_CANCEL);
177 gtk_widget_show (button);
179 button = gtk_button_new_with_label (GTK_STOCK_SAVE);
180 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
181 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
184 gtk_widget_show (button);
187 button = gtk_button_new_with_label (GTK_STOCK_CLOSE);
188 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
189 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
192 gtk_widget_show (button);
195 contact_widget = empathy_contact_widget_new (contact, edit);
196 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
200 g_signal_connect (dialog, "response",
201 G_CALLBACK (contact_information_response_cb),
204 g_hash_table_insert (information_dialogs, g_object_ref (contact), dialog);
207 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
210 gtk_widget_show (dialog);