]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-dialogs.c
Do not save when closing the dialog. Update information in real-time and
[empathy.git] / libempathy-gtk / empathy-contact-dialogs.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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.
19  *
20  * Authors: Xavier Claessens <xclaesse@gmail.com>
21  */
22
23 #include <config.h>
24
25 #include <string.h>
26 #include <stdlib.h>
27
28 #include <gtk/gtk.h>
29 #include <glade/glade.h>
30 #include <glib/gi18n.h>
31
32 #include <libempathy/empathy-contact-manager.h>
33 #include <libempathy/empathy-contact-list.h>
34
35 #include "empathy-contact-dialogs.h"
36 #include "empathy-contact-widget.h"
37 #include "gossip-ui-utils.h"
38
39 static GHashTable *subscription_dialogs = NULL;
40 static GHashTable *information_dialogs = NULL;
41
42 /*
43  *  Subscription dialog
44  */
45
46 static void
47 subscription_dialog_response_cb (GtkDialog *dialog,
48                                  gint       response,
49                                  GtkWidget *contact_widget)
50 {
51         EmpathyContactManager *manager;
52         GossipContact         *contact;
53
54         manager = empathy_contact_manager_new ();
55         contact = empathy_contact_widget_get_contact (contact_widget);
56
57         if (response == GTK_RESPONSE_YES) {
58                 empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager),
59                                           contact,
60                                           _("I would like to add you to my contact list."));
61         }
62         else if (response == GTK_RESPONSE_NO) {
63                 empathy_contact_list_remove (EMPATHY_CONTACT_LIST (manager),
64                                              contact,
65                                              _("Sorry, I don't want you in my contact list."));
66         }
67
68         g_hash_table_remove (subscription_dialogs, contact);
69         g_object_unref (manager);
70 }
71
72 void
73 empathy_subscription_dialog_show (GossipContact *contact,
74                                   GtkWindow     *parent)
75 {
76         GtkWidget *dialog;
77         GtkWidget *hbox_subscription;
78         GtkWidget *contact_widget;
79
80         g_return_if_fail (GOSSIP_IS_CONTACT (contact));
81
82         if (!subscription_dialogs) {
83                 subscription_dialogs = g_hash_table_new_full (gossip_contact_hash,
84                                                               gossip_contact_equal,
85                                                               (GDestroyNotify) g_object_unref,
86                                                               (GDestroyNotify) gtk_widget_destroy);
87         }
88
89         dialog = g_hash_table_lookup (subscription_dialogs, contact);
90         if (dialog) {
91                 gtk_window_present (GTK_WINDOW (dialog));
92                 return;
93         }
94
95         gossip_glade_get_file_simple ("empathy-contact-dialogs.glade",
96                                       "subscription_request_dialog",
97                                       NULL,
98                                       "subscription_request_dialog", &dialog,
99                                       "hbox_subscription", &hbox_subscription,
100                                       NULL);
101
102         g_hash_table_insert (subscription_dialogs, g_object_ref (contact), dialog);
103
104         contact_widget = empathy_contact_widget_new (contact, TRUE);
105         gtk_box_pack_end (GTK_BOX (hbox_subscription),
106                           contact_widget,
107                           TRUE, TRUE,
108                           0);
109
110         g_signal_connect (dialog, "response",
111                           G_CALLBACK (subscription_dialog_response_cb),
112                           contact_widget);
113
114         if (parent) {
115                 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
116         }
117
118         gtk_widget_show (dialog);
119 }
120
121 /*
122  *  Information dialog
123  */
124
125 static void
126 contact_information_response_cb (GtkDialog *dialog,
127                                  gint       response,
128                                  GtkWidget *contact_widget)
129 {
130         GossipContact *contact;
131
132         contact = empathy_contact_widget_get_contact (contact_widget);
133         g_hash_table_remove (information_dialogs, contact);
134 }
135
136 void
137 empathy_contact_information_dialog_show (GossipContact *contact,
138                                          GtkWindow     *parent,
139                                          gboolean       edit)
140 {
141         GtkWidget *dialog;
142         GtkWidget *button;
143         GtkWidget *contact_widget;
144
145         g_return_if_fail (GOSSIP_IS_CONTACT (contact));
146
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);
152         }
153
154         dialog = g_hash_table_lookup (information_dialogs, contact);
155         if (dialog) {
156                 gtk_window_present (GTK_WINDOW (dialog));
157                 return;
158         }
159
160         /* Create 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);
164
165         /* Close button */
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),
169                                       button,
170                                       GTK_RESPONSE_CLOSE);
171         gtk_widget_show (button);
172         
173         /* Contact infor widget */
174         contact_widget = empathy_contact_widget_new (contact, edit);
175         gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
176                             contact_widget,
177                             TRUE, TRUE, 0);
178
179         g_signal_connect (dialog, "response",
180                           G_CALLBACK (contact_information_response_cb),
181                           contact_widget);
182
183         g_hash_table_insert (information_dialogs, g_object_ref (contact), dialog);
184
185         if (parent) {
186                 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
187         }
188
189         gtk_widget_show (dialog);
190 }
191