]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-menu.c
Move contact menu code to its own module.
[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_chat_menu_item_new (EmpathyContact *contact)
41 {
42         GtkWidget *item;
43         GtkWidget *image;
44
45         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
46
47         item = gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
48         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE,
49                                               GTK_ICON_SIZE_MENU);
50         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
51         gtk_widget_show (image);
52
53         g_signal_connect_swapped (item, "activate",
54                                   G_CALLBACK (empathy_chat_with_contact),
55                                   contact);
56         
57         return item;
58 }
59
60 GtkWidget *
61 empathy_contact_call_menu_item_new (EmpathyContact *contact)
62 {
63         GtkWidget *item;
64         GtkWidget *image;
65
66         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
67
68         item = gtk_image_menu_item_new_with_mnemonic (_("_Call"));
69         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
70                                               GTK_ICON_SIZE_MENU);
71         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
72         gtk_widget_set_sensitive (item, empathy_contact_can_voip (contact));
73         gtk_widget_show (image);
74
75         g_signal_connect_swapped (item, "activate",
76                                   G_CALLBACK (empathy_call_with_contact),
77                                   contact);
78         
79         return item;
80 }
81
82 static void
83 contact_log_menu_item_activate_cb (EmpathyContact *contact)
84 {
85         empathy_log_window_show (empathy_contact_get_account (contact),
86                                  empathy_contact_get_id (contact),
87                                  FALSE, NULL);
88 }
89
90 GtkWidget *
91 empathy_contact_log_menu_item_new (EmpathyContact *contact)
92 {
93         EmpathyLogManager *manager;
94         gboolean           have_log;
95         GtkWidget         *item;
96         GtkWidget         *image;
97
98         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
99
100         manager = empathy_log_manager_new ();
101         have_log = empathy_log_manager_exists (manager,
102                                                empathy_contact_get_account (contact),
103                                                empathy_contact_get_id (contact),
104                                                FALSE);
105         g_object_unref (manager);
106
107         item = gtk_image_menu_item_new_with_mnemonic (_("_View Previous Conversations"));
108         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG,
109                                               GTK_ICON_SIZE_MENU);
110         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
111         gtk_widget_set_sensitive (item, have_log);
112         gtk_widget_show (image);
113
114         g_signal_connect_swapped (item, "activate",
115                                   G_CALLBACK (contact_log_menu_item_activate_cb),
116                                   contact);
117         
118         return item;
119 }
120
121 static void
122 contact_info_menu_item_activate_cb (EmpathyContact *contact)
123 {
124         empathy_contact_information_dialog_show (contact, NULL, FALSE, FALSE);
125 }
126
127 GtkWidget *
128 empathy_contact_info_menu_item_new (EmpathyContact *contact)
129 {
130         GtkWidget *item;
131         GtkWidget *image;
132
133         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
134
135         item = gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
136         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION,
137                                               GTK_ICON_SIZE_MENU);
138         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
139         gtk_widget_show (image);
140
141         g_signal_connect_swapped (item, "activate",
142                                   G_CALLBACK (contact_info_menu_item_activate_cb),
143                                   contact);
144         
145         return item;
146 }
147
148 static void
149 contact_edit_menu_item_activate_cb (EmpathyContact *contact)
150 {
151         empathy_contact_information_dialog_show (contact, NULL, TRUE, FALSE);
152 }
153
154 GtkWidget *
155 empathy_contact_edit_menu_item_new (EmpathyContact *contact)
156 {
157         GtkWidget *item;
158         GtkWidget *image;
159
160         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
161
162         item = gtk_image_menu_item_new_with_mnemonic (_("_Edit"));
163         image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT,
164                                               GTK_ICON_SIZE_MENU);
165         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
166         gtk_widget_show (image);
167
168         g_signal_connect_swapped (item, "activate",
169                                   G_CALLBACK (contact_edit_menu_item_activate_cb),
170                                   contact);
171         
172         return item;
173 }
174