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);
57 if (response == GTK_RESPONSE_YES) {
58 empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager),
60 _("I would like to add you to my contact list."));
62 else if (response == GTK_RESPONSE_NO) {
63 empathy_contact_list_remove (EMPATHY_CONTACT_LIST (manager),
65 _("Sorry, I don't want you in my contact list."));
68 g_hash_table_remove (subscription_dialogs, contact);
69 g_object_unref (manager);
73 empathy_subscription_dialog_show (GossipContact *contact,
77 GtkWidget *hbox_subscription;
78 GtkWidget *contact_widget;
80 g_return_if_fail (GOSSIP_IS_CONTACT (contact));
82 if (!subscription_dialogs) {
83 subscription_dialogs = g_hash_table_new_full (gossip_contact_hash,
85 (GDestroyNotify) g_object_unref,
86 (GDestroyNotify) gtk_widget_destroy);
89 dialog = g_hash_table_lookup (subscription_dialogs, contact);
91 gtk_window_present (GTK_WINDOW (dialog));
95 gossip_glade_get_file_simple ("empathy-contact-dialogs.glade",
96 "subscription_request_dialog",
98 "subscription_request_dialog", &dialog,
99 "hbox_subscription", &hbox_subscription,
102 g_hash_table_insert (subscription_dialogs, g_object_ref (contact), dialog);
104 contact_widget = empathy_contact_widget_new (contact, TRUE);
105 gtk_box_pack_end (GTK_BOX (hbox_subscription),
110 g_signal_connect (dialog, "response",
111 G_CALLBACK (subscription_dialog_response_cb),
115 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
118 gtk_widget_show (dialog);
126 contact_information_response_cb (GtkDialog *dialog,
128 GtkWidget *contact_widget)
130 GossipContact *contact;
132 contact = empathy_contact_widget_get_contact (contact_widget);
133 g_hash_table_remove (information_dialogs, contact);
137 empathy_contact_information_dialog_show (GossipContact *contact,
143 GtkWidget *contact_widget;
145 g_return_if_fail (GOSSIP_IS_CONTACT (contact));
147 if (!information_dialogs) {
148 information_dialogs = g_hash_table_new_full (gossip_contact_hash,
149 gossip_contact_equal,
150 (GDestroyNotify) g_object_unref,
151 (GDestroyNotify) gtk_widget_destroy);
154 dialog = g_hash_table_lookup (information_dialogs, contact);
156 gtk_window_present (GTK_WINDOW (dialog));
161 dialog = gtk_dialog_new ();
162 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
163 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
166 button = gtk_button_new_with_label (GTK_STOCK_CLOSE);
167 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
168 gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
171 gtk_widget_show (button);
173 /* Contact infor widget */
174 contact_widget = empathy_contact_widget_new (contact, edit);
175 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
179 g_signal_connect (dialog, "response",
180 G_CALLBACK (contact_information_response_cb),
183 g_hash_table_insert (information_dialogs, g_object_ref (contact), dialog);
186 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
189 gtk_widget_show (dialog);