]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-chat-view.c
EmpathyChatView interface can only be implemented by a GtkWidget subclass
[empathy.git] / libempathy-gtk / empathy-chat-view.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 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 "empathy-chat-view.h"
26 #include "empathy-smiley-manager.h"
27
28 static void chat_view_base_init (gpointer klass);
29
30 GType
31 empathy_chat_view_get_type (void)
32 {
33         static GType type = 0;
34         
35         if (!type) {
36                 static const GTypeInfo type_info = {
37                         sizeof (EmpathyChatViewIface),
38                         chat_view_base_init,
39                         NULL,
40                 };
41                 
42                 type = g_type_register_static (G_TYPE_INTERFACE,
43                                                "EmpathyChatView",
44                                                &type_info, 0);
45                 
46                 g_type_interface_add_prerequisite (type, GTK_TYPE_WIDGET);
47         }
48         
49         return type;
50 }
51
52 static void
53 chat_view_base_init (gpointer klass)
54 {
55         static gboolean initialized = FALSE;
56         
57         if (!initialized) {
58                 initialized = TRUE;
59         }
60 }
61
62 void
63 empathy_chat_view_scroll_down (EmpathyChatView *view)
64 {
65         g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
66         
67         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->scroll_down) {
68                 EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->scroll_down (view);
69         }
70 }
71
72 void
73 empathy_chat_view_append_message (EmpathyChatView *view,
74                                   EmpathyMessage  *msg)
75 {
76         g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
77         
78         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->append_message) {
79                 EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->append_message (view, 
80                                                                          msg);
81         }
82 }
83
84 void
85 empathy_chat_view_append_event (EmpathyChatView *view,
86                                 const gchar    *str)
87 {
88         g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
89         
90         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->append_event) {
91                 EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->append_event (view,
92                                                                        str);
93         }
94 }
95
96 void
97 empathy_chat_view_scroll (EmpathyChatView *view,
98                           gboolean        allow_scrolling)
99 {
100         g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
101         
102         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->scroll) {
103                 EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->scroll (view, 
104                                                                  allow_scrolling);
105         }
106 }
107
108 gboolean
109 empathy_chat_view_get_has_selection (EmpathyChatView *view)
110 {
111         g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), FALSE);
112         
113         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_has_selection) {
114                 return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_has_selection (view);
115         }
116         return FALSE;
117 }
118
119 void
120 empathy_chat_view_clear (EmpathyChatView *view)
121 {
122         g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
123         
124         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->clear) {
125                 EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->clear (view);
126         }
127 }
128
129 gboolean
130 empathy_chat_view_find_previous (EmpathyChatView *view,
131                                  const gchar    *search_criteria,
132                                  gboolean        new_search)
133 {
134         g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), FALSE);
135         
136         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_previous) {
137                 return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_previous (view, 
138                                                                                search_criteria, 
139                                                                                new_search);
140         }
141         return FALSE;
142 }
143
144 gboolean
145 empathy_chat_view_find_next (EmpathyChatView *view,
146                              const gchar    *search_criteria,
147                              gboolean        new_search)
148 {
149         g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), FALSE);
150         
151         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_next) {
152                 return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_next (view, 
153                                                                            search_criteria, 
154                                                                            new_search);
155         }
156         return FALSE;
157 }
158
159
160 void
161 empathy_chat_view_find_abilities (EmpathyChatView *view,
162                                   const gchar    *search_criteria,
163                                   gboolean       *can_do_previous,
164                                   gboolean       *can_do_next)
165 {
166         g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
167         
168         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_abilities) {
169                 EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_abilities (view, 
170                                                                          search_criteria, 
171                                                                          can_do_previous, 
172                                                                          can_do_next);
173         }
174 }
175
176 void
177 empathy_chat_view_highlight (EmpathyChatView *view,
178                              const gchar     *text)
179 {
180         g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
181         
182         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->highlight) {
183                 EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->highlight (view, text);
184         }
185 }
186
187 void
188 empathy_chat_view_copy_clipboard (EmpathyChatView *view)
189 {
190         g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
191         
192         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->copy_clipboard) {
193                 EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->copy_clipboard (view);
194         }
195 }
196
197 EmpathyTheme *
198 empathy_chat_view_get_theme (EmpathyChatView *view)
199 {
200         g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), NULL);
201         
202         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_theme) {
203                 return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_theme (view);
204         }
205         return NULL;
206 }
207
208 void
209 empathy_chat_view_set_theme (EmpathyChatView *view, EmpathyTheme *theme)
210 {
211         g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
212         
213         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->set_theme) {
214                 EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->set_theme (view, theme);
215         }
216 }
217
218 void
219 empathy_chat_view_set_margin (EmpathyChatView *view,
220                               gint            margin)
221 {
222         g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
223         
224         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->set_margin) {
225                 EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->set_margin (view, margin);
226         }
227 }
228
229 time_t
230 empathy_chat_view_get_last_timestamp (EmpathyChatView *view)
231 {
232         g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), 0);
233         
234         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_last_timestamp) {
235                 return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_last_timestamp (view);
236         }
237         return 0;
238 }
239
240 void
241 empathy_chat_view_set_last_timestamp (EmpathyChatView *view,
242                                       time_t          timestamp)
243 {
244         g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
245         
246         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->set_last_timestamp) {
247                 EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->set_last_timestamp (view, timestamp);
248         }
249 }
250
251 EmpathyContact *
252 empathy_chat_view_get_last_contact (EmpathyChatView *view)
253 {
254         g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), NULL);
255         
256         if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_last_contact) {
257                 return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_last_contact (view);
258         }
259         return NULL;
260 }
261
262 GtkWidget *
263 empathy_chat_view_get_smiley_menu (GCallback    callback,
264                                    gpointer     user_data)
265 {
266         EmpathySmileyManager *smiley_manager;
267         GSList               *smileys, *l;
268         GtkWidget            *menu;
269         gint                  x = 0;
270         gint                  y = 0;
271
272         g_return_val_if_fail (callback != NULL, NULL);
273
274         menu = gtk_menu_new ();
275
276         smiley_manager = empathy_smiley_manager_new ();
277         smileys = empathy_smiley_manager_get_all (smiley_manager);
278         for (l = smileys; l; l = l->next) {
279                 EmpathySmiley *smiley;
280                 GtkWidget     *item;
281                 GtkWidget     *image;
282
283                 smiley = l->data;
284                 image = gtk_image_new_from_pixbuf (smiley->pixbuf);
285
286                 item = gtk_image_menu_item_new_with_label ("");
287                 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
288
289                 gtk_menu_attach (GTK_MENU (menu), item,
290                                  x, x + 1, y, y + 1);
291
292                 gtk_widget_set_tooltip_text (item, smiley->str);
293
294                 g_object_set_data  (G_OBJECT (item), "smiley_text", smiley->str);
295                 g_signal_connect (item, "activate", callback, user_data);
296
297                 if (x > 3) {
298                         y++;
299                         x = 0;
300                 } else {
301                         x++;
302                 }
303         }
304         g_object_unref (smiley_manager);
305
306         gtk_widget_show_all (menu);
307
308         return menu;
309 }
310