]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-menu.c
275729f985c5f8ba11fee51bccaf548854c44626
[empathy.git] / libempathy-gtk / empathy-contact-menu.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2008 Collabora Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  * 
19  * Authors: Xavier Claessens <xclaesse@gmail.com>
20  */
21
22 #include "config.h"
23
24 #include <string.h>
25
26 #include <glib/gi18n.h>
27 #include <gtk/gtk.h>
28
29 #include <libempathy/empathy-utils.h>
30 #include <libempathy/empathy-log-manager.h>
31
32 #include "empathy-contact-menu.h"
33 #include "empathy-images.h"
34 #include "empathy-log-window.h"
35 #include "empathy-contact-dialogs.h"
36
37 GtkWidget *
38 empathy_contact_menu_new (EmpathyContact             *contact,
39                           EmpathyContactFeatureFlags  features)
40 {
41         GtkWidget    *menu;
42         GtkMenuShell *shell;
43         GtkWidget    *item;
44
45         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
46
47         if (features == EMPATHY_CONTACT_FEATURE_NONE) {
48                 return NULL;
49         }
50
51         menu = gtk_menu_new ();
52         shell = GTK_MENU_SHELL (menu);
53
54         /* Chat */
55         if (features & EMPATHY_CONTACT_FEATURE_CHAT) {
56                 item = empathy_contact_chat_menu_item_new (contact);
57                 gtk_menu_shell_append (shell, item);
58                 gtk_widget_show (item);
59         }
60
61         /* Call */
62         if (features & EMPATHY_CONTACT_FEATURE_CALL) {
63                 item = empathy_contact_call_menu_item_new (contact);
64                 gtk_menu_shell_append (shell, item);
65                 gtk_widget_show (item);
66         }
67
68         /* Log */
69         if (features & EMPATHY_CONTACT_FEATURE_LOG) {
70                 item = empathy_contact_log_menu_item_new (contact);
71                 gtk_menu_shell_append (shell, item);
72                 gtk_widget_show (item);
73         }
74
75         /* Separator */
76         if (features & (EMPATHY_CONTACT_FEATURE_EDIT |
77                         EMPATHY_CONTACT_FEATURE_INFO)) {
78                 item = gtk_separator_menu_item_new ();
79                 gtk_menu_shell_append (shell, item);
80                 gtk_widget_show (item);
81         }
82
83         /* Edit */
84         if (features & EMPATHY_CONTACT_FEATURE_EDIT) {
85                 item = empathy_contact_edit_menu_item_new (contact);
86                 gtk_menu_shell_append (shell, item);
87                 gtk_widget_show (item);
88         }
89
90         /* Info */
91         if (features & EMPATHY_CONTACT_FEATURE_INFO) {
92                 item = empathy_contact_info_menu_item_new (contact);
93                 gtk_menu_shell_append (shell, item);
94                 gtk_widget_show (item);
95         }
96
97         return menu;
98 }
99
100 GtkWidget *
101 empathy_contact_chat_menu_item_new (EmpathyContact *contact)
102 {
103         GtkWidget *item;
104         GtkWidget *image;
105
106         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
107
108         item = gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
109         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE,
110                                               GTK_ICON_SIZE_MENU);
111         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
112         gtk_widget_show (image);
113
114         g_signal_connect_swapped (item, "activate",
115                                   G_CALLBACK (empathy_chat_with_contact),
116                                   contact);
117         
118         return item;
119 }
120
121 GtkWidget *
122 empathy_contact_call_menu_item_new (EmpathyContact *contact)
123 {
124         GtkWidget *item;
125         GtkWidget *image;
126
127         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
128
129         item = gtk_image_menu_item_new_with_mnemonic (_("_Call"));
130         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
131                                               GTK_ICON_SIZE_MENU);
132         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
133         gtk_widget_set_sensitive (item, empathy_contact_can_voip (contact));
134         gtk_widget_show (image);
135
136         g_signal_connect_swapped (item, "activate",
137                                   G_CALLBACK (empathy_call_with_contact),
138                                   contact);
139         
140         return item;
141 }
142
143 static void
144 contact_log_menu_item_activate_cb (EmpathyContact *contact)
145 {
146         empathy_log_window_show (empathy_contact_get_account (contact),
147                                  empathy_contact_get_id (contact),
148                                  FALSE, NULL);
149 }
150
151 GtkWidget *
152 empathy_contact_log_menu_item_new (EmpathyContact *contact)
153 {
154         EmpathyLogManager *manager;
155         gboolean           have_log;
156         GtkWidget         *item;
157         GtkWidget         *image;
158
159         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
160
161         manager = empathy_log_manager_new ();
162         have_log = empathy_log_manager_exists (manager,
163                                                empathy_contact_get_account (contact),
164                                                empathy_contact_get_id (contact),
165                                                FALSE);
166         g_object_unref (manager);
167
168         item = gtk_image_menu_item_new_with_mnemonic (_("_View Previous Conversations"));
169         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG,
170                                               GTK_ICON_SIZE_MENU);
171         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
172         gtk_widget_set_sensitive (item, have_log);
173         gtk_widget_show (image);
174
175         g_signal_connect_swapped (item, "activate",
176                                   G_CALLBACK (contact_log_menu_item_activate_cb),
177                                   contact);
178         
179         return item;
180 }
181
182 static void
183 contact_info_menu_item_activate_cb (EmpathyContact *contact)
184 {
185         empathy_contact_information_dialog_show (contact, NULL, FALSE, FALSE);
186 }
187
188 GtkWidget *
189 empathy_contact_info_menu_item_new (EmpathyContact *contact)
190 {
191         GtkWidget *item;
192         GtkWidget *image;
193
194         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
195
196         item = gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
197         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION,
198                                               GTK_ICON_SIZE_MENU);
199         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
200         gtk_widget_show (image);
201
202         g_signal_connect_swapped (item, "activate",
203                                   G_CALLBACK (contact_info_menu_item_activate_cb),
204                                   contact);
205         
206         return item;
207 }
208
209 static void
210 contact_edit_menu_item_activate_cb (EmpathyContact *contact)
211 {
212         empathy_contact_information_dialog_show (contact, NULL, TRUE, FALSE);
213 }
214
215 GtkWidget *
216 empathy_contact_edit_menu_item_new (EmpathyContact *contact)
217 {
218         GtkWidget *item;
219         GtkWidget *image;
220
221         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
222
223         item = gtk_image_menu_item_new_with_mnemonic (_("_Edit"));
224         image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT,
225                                               GTK_ICON_SIZE_MENU);
226         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
227         gtk_widget_show (image);
228
229         g_signal_connect_swapped (item, "activate",
230                                   G_CALLBACK (contact_edit_menu_item_activate_cb),
231                                   contact);
232         
233         return item;
234 }
235