aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-chat-view.c
blob: f38ab17508923820578928eeb962b1136a97eabb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2008 Collabora Ltd.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 * 
 * Authors: Xavier Claessens <xclaesse@gmail.com>
 */

#include "config.h"

#include "empathy-chat-view.h"
#include "empathy-smiley-manager.h"

static void chat_view_base_init (gpointer klass);

GType
empathy_chat_view_get_type (void)
{
    static GType type = 0;
    
    if (!type) {
        static const GTypeInfo type_info = {
            sizeof (EmpathyChatViewIface),
            chat_view_base_init,
            NULL,
        };
        
        type = g_type_register_static (G_TYPE_INTERFACE,
                           "EmpathyChatView",
                           &type_info, 0);
        
        g_type_interface_add_prerequisite (type, GTK_TYPE_WIDGET);
    }
    
    return type;
}

static void
chat_view_base_init (gpointer klass)
{
    static gboolean initialized = FALSE;
    
    if (!initialized) {
        initialized = TRUE;
    }
}

void
empathy_chat_view_scroll_down (EmpathyChatView *view)
{
    g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->scroll_down) {
        EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->scroll_down (view);
    }
}

void
empathy_chat_view_append_message (EmpathyChatView *view,
                  EmpathyMessage  *msg)
{
    g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->append_message) {
        EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->append_message (view, 
                                     msg);
    }
}

void
empathy_chat_view_append_event (EmpathyChatView *view,
                const gchar    *str)
{
    g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->append_event) {
        EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->append_event (view,
                                       str);
    }
}

void
empathy_chat_view_scroll (EmpathyChatView *view,
              gboolean        allow_scrolling)
{
    g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->scroll) {
        EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->scroll (view, 
                                 allow_scrolling);
    }
}

gboolean
empathy_chat_view_get_has_selection (EmpathyChatView *view)
{
    g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), FALSE);
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_has_selection) {
        return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_has_selection (view);
    }
    return FALSE;
}

void
empathy_chat_view_clear (EmpathyChatView *view)
{
    g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->clear) {
        EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->clear (view);
    }
}

gboolean
empathy_chat_view_find_previous (EmpathyChatView *view,
                 const gchar    *search_criteria,
                 gboolean        new_search)
{
    g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), FALSE);
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_previous) {
        return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_previous (view, 
                                           search_criteria, 
                                           new_search);
    }
    return FALSE;
}

gboolean
empathy_chat_view_find_next (EmpathyChatView *view,
                 const gchar    *search_criteria,
                 gboolean        new_search)
{
    g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), FALSE);
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_next) {
        return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_next (view, 
                                       search_criteria, 
                                       new_search);
    }
    return FALSE;
}


void
empathy_chat_view_find_abilities (EmpathyChatView *view,
                  const gchar    *search_criteria,
                  gboolean       *can_do_previous,
                  gboolean       *can_do_next)
{
    g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_abilities) {
        EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_abilities (view, 
                                     search_criteria, 
                                     can_do_previous, 
                                     can_do_next);
    }
}

void
empathy_chat_view_highlight (EmpathyChatView *view,
                 const gchar     *text)
{
    g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->highlight) {
        EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->highlight (view, text);
    }
}

void
empathy_chat_view_copy_clipboard (EmpathyChatView *view)
{
    g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->copy_clipboard) {
        EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->copy_clipboard (view);
    }
}

EmpathyTheme *
empathy_chat_view_get_theme (EmpathyChatView *view)
{
    g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), NULL);
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_theme) {
        return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_theme (view);
    }
    return NULL;
}

void
empathy_chat_view_set_theme (EmpathyChatView *view, EmpathyTheme *theme)
{
    g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->set_theme) {
        EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->set_theme (view, theme);
    }
}

void
empathy_chat_view_set_margin (EmpathyChatView *view,
                  gint            margin)
{
    g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->set_margin) {
        EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->set_margin (view, margin);
    }
}

time_t
empathy_chat_view_get_last_timestamp (EmpathyChatView *view)
{
    g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), 0);
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_last_timestamp) {
        return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_last_timestamp (view);
    }
    return 0;
}

void
empathy_chat_view_set_last_timestamp (EmpathyChatView *view,
                      time_t          timestamp)
{
    g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->set_last_timestamp) {
        EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->set_last_timestamp (view, timestamp);
    }
}

EmpathyContact *
empathy_chat_view_get_last_contact (EmpathyChatView *view)
{
    g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), NULL);
    
    if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_last_contact) {
        return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_last_contact (view);
    }
    return NULL;
}

GtkWidget *
empathy_chat_view_get_smiley_menu (GCallback    callback,
                   gpointer     user_data)
{
    EmpathySmileyManager *smiley_manager;
    GSList               *smileys, *l;
    GtkWidget            *menu;
    gint                  x = 0;
    gint                  y = 0;

    g_return_val_if_fail (callback != NULL, NULL);

    menu = gtk_menu_new ();

    smiley_manager = empathy_smiley_manager_new ();
    smileys = empathy_smiley_manager_get_all (smiley_manager);
    for (l = smileys; l; l = l->next) {
        EmpathySmiley *smiley;
        GtkWidget     *item;
        GtkWidget     *image;

        smiley = l->data;
        image = gtk_image_new_from_pixbuf (smiley->pixbuf);

        item = gtk_image_menu_item_new_with_label ("");
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);

        gtk_menu_attach (GTK_MENU (menu), item,
                 x, x + 1, y, y + 1);

        gtk_widget_set_tooltip_text (item, smiley->str);

        g_object_set_data  (G_OBJECT (item), "smiley_text", smiley->str);
        g_signal_connect (item, "activate", callback, user_data);

        if (x > 3) {
            y++;
            x = 0;
        } else {
            x++;
        }
    }
    g_object_unref (smiley_manager);

    gtk_widget_show_all (menu);

    return menu;
}