]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-menu.c
Updated Basque translation.
[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-log-manager.h>
30 #include <libempathy/empathy-dispatcher.h>
31 #include <libempathy/empathy-utils.h>
32
33 #include "empathy-contact-menu.h"
34 #include "empathy-images.h"
35 #include "empathy-log-window.h"
36 #include "empathy-contact-dialogs.h"
37
38 GtkWidget *
39 empathy_contact_menu_new (EmpathyContact             *contact,
40                           EmpathyContactFeatureFlags  features)
41 {
42         GtkWidget    *menu;
43         GtkMenuShell *shell;
44         GtkWidget    *item;
45
46         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
47
48         if (features == EMPATHY_CONTACT_FEATURE_NONE) {
49                 return NULL;
50         }
51
52         menu = gtk_menu_new ();
53         shell = GTK_MENU_SHELL (menu);
54
55         /* Chat */
56         if (features & EMPATHY_CONTACT_FEATURE_CHAT) {
57                 item = empathy_contact_chat_menu_item_new (contact);
58                 gtk_menu_shell_append (shell, item);
59                 gtk_widget_show (item);
60         }
61
62         /* Call */
63         if (features & EMPATHY_CONTACT_FEATURE_CALL) {
64                 item = empathy_contact_call_menu_item_new (contact);
65                 gtk_menu_shell_append (shell, item);
66                 gtk_widget_show (item);
67         }
68
69         /* Log */
70         if (features & EMPATHY_CONTACT_FEATURE_LOG) {
71                 item = empathy_contact_log_menu_item_new (contact);
72                 gtk_menu_shell_append (shell, item);
73                 gtk_widget_show (item);
74         }
75
76         /* Separator */
77         if (features & (EMPATHY_CONTACT_FEATURE_EDIT |
78                         EMPATHY_CONTACT_FEATURE_INFO)) {
79                 item = gtk_separator_menu_item_new ();
80                 gtk_menu_shell_append (shell, item);
81                 gtk_widget_show (item);
82         }
83
84         /* Edit */
85         if (features & EMPATHY_CONTACT_FEATURE_EDIT) {
86                 item = empathy_contact_edit_menu_item_new (contact);
87                 gtk_menu_shell_append (shell, item);
88                 gtk_widget_show (item);
89         }
90
91         /* Info */
92         if (features & EMPATHY_CONTACT_FEATURE_INFO) {
93                 item = empathy_contact_info_menu_item_new (contact);
94                 gtk_menu_shell_append (shell, item);
95                 gtk_widget_show (item);
96         }
97
98         return menu;
99 }
100
101 GtkWidget *
102 empathy_contact_chat_menu_item_new (EmpathyContact *contact)
103 {
104         GtkWidget *item;
105         GtkWidget *image;
106
107         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
108
109         item = gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
110         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE,
111                                               GTK_ICON_SIZE_MENU);
112         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
113         gtk_widget_show (image);
114
115         g_signal_connect_swapped (item, "activate",
116                                   G_CALLBACK (empathy_dispatcher_chat_with_contact),
117                                   contact);
118         
119         return item;
120 }
121
122 GtkWidget *
123 empathy_contact_call_menu_item_new (EmpathyContact *contact)
124 {
125         GtkWidget *item;
126         GtkWidget *image;
127
128         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
129
130         item = gtk_image_menu_item_new_with_mnemonic (_("_Call"));
131         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
132                                               GTK_ICON_SIZE_MENU);
133         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
134         gtk_widget_set_sensitive (item, empathy_contact_can_voip (contact));
135         gtk_widget_show (image);
136
137         g_signal_connect_swapped (item, "activate",
138                                   G_CALLBACK (empathy_dispatcher_call_with_contact),
139                                   contact);
140         
141         return item;
142 }
143
144 static void
145 contact_log_menu_item_activate_cb (EmpathyContact *contact)
146 {
147         empathy_log_window_show (empathy_contact_get_account (contact),
148                                  empathy_contact_get_id (contact),
149                                  FALSE, NULL);
150 }
151
152 GtkWidget *
153 empathy_contact_log_menu_item_new (EmpathyContact *contact)
154 {
155         EmpathyLogManager *manager;
156         gboolean           have_log;
157         GtkWidget         *item;
158         GtkWidget         *image;
159
160         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
161
162         manager = empathy_log_manager_new ();
163         have_log = empathy_log_manager_exists (manager,
164                                                empathy_contact_get_account (contact),
165                                                empathy_contact_get_id (contact),
166                                                FALSE);
167         g_object_unref (manager);
168
169         item = gtk_image_menu_item_new_with_mnemonic (_("_View Previous Conversations"));
170         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG,
171                                               GTK_ICON_SIZE_MENU);
172         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
173         gtk_widget_set_sensitive (item, have_log);
174         gtk_widget_show (image);
175
176         g_signal_connect_swapped (item, "activate",
177                                   G_CALLBACK (contact_log_menu_item_activate_cb),
178                                   contact);
179         
180         return item;
181 }
182
183 static void
184 contact_info_menu_item_activate_cb (EmpathyContact *contact)
185 {
186         empathy_contact_information_dialog_show (contact, NULL, FALSE, FALSE);
187 }
188
189 GtkWidget *
190 empathy_contact_info_menu_item_new (EmpathyContact *contact)
191 {
192         GtkWidget *item;
193         GtkWidget *image;
194
195         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
196
197         item = gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
198         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION,
199                                               GTK_ICON_SIZE_MENU);
200         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
201         gtk_widget_show (image);
202
203         g_signal_connect_swapped (item, "activate",
204                                   G_CALLBACK (contact_info_menu_item_activate_cb),
205                                   contact);
206         
207         return item;
208 }
209
210 static void
211 contact_edit_menu_item_activate_cb (EmpathyContact *contact)
212 {
213         empathy_contact_information_dialog_show (contact, NULL, TRUE, FALSE);
214 }
215
216 GtkWidget *
217 empathy_contact_edit_menu_item_new (EmpathyContact *contact)
218 {
219         GtkWidget *item;
220         GtkWidget *image;
221
222         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
223
224         item = gtk_image_menu_item_new_with_mnemonic (_("_Edit"));
225         image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT,
226                                               GTK_ICON_SIZE_MENU);
227         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
228         gtk_widget_show (image);
229
230         g_signal_connect_swapped (item, "activate",
231                                   G_CALLBACK (contact_edit_menu_item_activate_cb),
232                                   contact);
233         
234         return item;
235 }
236