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