]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-theme-boxes.c
Always set urgency hint on p2p chat windows when receiving a message.
[empathy.git] / libempathy-gtk / empathy-theme-boxes.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Imendio AB
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
21 #include <config.h>
22
23 #include <string.h>
24
25 #include <glib/gi18n.h>
26 #include <gtk/gtk.h>
27
28 #include <libempathy/empathy-debug.h>
29
30 #include "empathy-ui-utils.h"
31 #include "empathy-theme-boxes.h"
32
33 #define DEBUG_DOMAIN "FancyTheme"
34
35 #define MARGIN 4
36 #define HEADER_PADDING 2
37
38 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_THEME_BOXES, EmpathyThemeBoxesPriv))
39
40 typedef struct _EmpathyThemeBoxesPriv EmpathyThemeBoxesPriv;
41
42 struct _EmpathyThemeBoxesPriv {
43         gchar *header_foreground;
44         gchar *header_background;
45         gchar *header_line_background;
46         gchar *text_foreground;
47         gchar *text_background;
48         gchar *action_foreground;
49         gchar *highlight_foreground;
50         gchar *time_foreground;
51         gchar *event_foreground;
52         gchar *invite_foreground;
53         gchar *link_foreground;
54 };
55
56 static void     theme_boxes_finalize          (GObject            *object);
57 static void     theme_boxes_get_property      (GObject            *object,
58                                                guint               param_id,
59                                                GValue             *value,
60                                                GParamSpec         *pspec);
61 static void     theme_boxes_set_property      (GObject            *object,
62                                                guint               param_id,
63                                                const GValue       *value,
64                                                GParamSpec         *pspec);
65 static void     theme_boxes_define_theme_tags (EmpathyTheme        *theme,
66                                                EmpathyChatView     *view);
67 static void     theme_boxes_update_view       (EmpathyTheme        *theme,
68                                                EmpathyChatView     *view);
69 static void     theme_boxes_append_message    (EmpathyTheme        *theme,
70                                                EmpathyChatView     *view,
71                                                EmpathyMessage      *message);
72 static void     theme_boxes_append_event      (EmpathyTheme        *theme,
73                                                EmpathyChatView     *view,
74                                                const gchar        *str);
75 static void     theme_boxes_append_timestamp  (EmpathyTheme        *theme,
76                                                EmpathyChatView     *view,
77                                                EmpathyMessage      *message,
78                                                gboolean            show_date,
79                                                gboolean            show_time);
80 static void     theme_boxes_append_spacing    (EmpathyTheme        *theme,
81                                                EmpathyChatView     *view);
82
83 enum {
84         PROP_0,
85         PROP_HEADER_FOREGROUND,
86         PROP_HEADER_BACKGROUND,
87         PROP_HEADER_LINE_BACKGROUND,
88         PROP_TEXT_FOREGROUND,
89         PROP_TEXT_BACKGROUND,
90         PROP_ACTION_FOREGROUND,
91         PROP_HIGHLIGHT_FOREGROUND,
92         PROP_TIME_FOREGROUND,
93         PROP_EVENT_FOREGROUND,
94         PROP_INVITE_FOREGROUND,
95         PROP_LINK_FOREGROUND
96 };
97
98 enum {
99         PROP_FLOP,
100         PROP_MY_PROP
101 };
102
103 G_DEFINE_TYPE (EmpathyThemeBoxes, empathy_theme_boxes, EMPATHY_TYPE_THEME);
104
105 static void
106 empathy_theme_boxes_class_init (EmpathyThemeBoxesClass *class)
107 {
108         GObjectClass     *object_class;
109         EmpathyThemeClass *theme_class;
110
111         object_class = G_OBJECT_CLASS (class);
112         theme_class  = EMPATHY_THEME_CLASS (class);
113
114         object_class->finalize       = theme_boxes_finalize;
115         object_class->get_property   = theme_boxes_get_property;
116         object_class->set_property   = theme_boxes_set_property;
117
118         theme_class->update_view      = theme_boxes_update_view;
119         theme_class->append_message   = theme_boxes_append_message;
120         theme_class->append_event     = theme_boxes_append_event;
121         theme_class->append_timestamp = theme_boxes_append_timestamp;
122         theme_class->append_spacing   = theme_boxes_append_spacing;
123
124         g_object_class_install_property (object_class,
125                                          PROP_HEADER_FOREGROUND,
126                                          g_param_spec_string ("header-foreground",
127                                                               "",
128                                                               "",
129                                                               NULL,
130                                                               G_PARAM_READWRITE));
131
132         g_object_class_install_property (object_class,
133                                          PROP_HEADER_BACKGROUND,
134                                          g_param_spec_string ("header-background",
135                                                               "",
136                                                               "",
137                                                               NULL,
138                                                               G_PARAM_READWRITE));
139
140         g_object_class_install_property (object_class,
141                                          PROP_HEADER_LINE_BACKGROUND,
142                                          g_param_spec_string ("header-line-background",
143                                                               "",
144                                                               "",
145                                                               NULL,
146                                                               G_PARAM_READWRITE));
147
148
149         g_object_class_install_property (object_class,
150                                          PROP_TEXT_FOREGROUND,
151                                          g_param_spec_string ("text-foreground",
152                                                               "",
153                                                               "",
154                                                               NULL,
155                                                               G_PARAM_READWRITE));
156
157         g_object_class_install_property (object_class,
158                                          PROP_TEXT_BACKGROUND,
159                                          g_param_spec_string ("text-background",
160                                                               "",
161                                                               "",
162                                                               NULL,
163                                                               G_PARAM_READWRITE));
164
165         g_object_class_install_property (object_class,
166                                          PROP_ACTION_FOREGROUND,
167                                          g_param_spec_string ("action-foreground",
168                                                               "",
169                                                               "",
170                                                               NULL,
171                                                               G_PARAM_READWRITE));
172
173         g_object_class_install_property (object_class,
174                                          PROP_HIGHLIGHT_FOREGROUND,
175                                          g_param_spec_string ("highlight-foreground",
176                                                               "",
177                                                               "",
178                                                               NULL,
179                                                               G_PARAM_READWRITE));
180
181         g_object_class_install_property (object_class,
182                                          PROP_TIME_FOREGROUND,
183                                          g_param_spec_string ("time-foreground",
184                                                               "",
185                                                               "",
186                                                               NULL,
187                                                               G_PARAM_READWRITE));
188
189         g_object_class_install_property (object_class,
190                                          PROP_EVENT_FOREGROUND,
191                                          g_param_spec_string ("event-foreground",
192                                                               "",
193                                                               "",
194                                                               NULL,
195                                                               G_PARAM_READWRITE));
196
197         g_object_class_install_property (object_class,
198                                          PROP_INVITE_FOREGROUND,
199                                          g_param_spec_string ("invite-foreground",
200                                                               "",
201                                                               "",
202                                                               NULL,
203                                                               G_PARAM_READWRITE));
204
205         g_object_class_install_property (object_class,
206                                          PROP_LINK_FOREGROUND,
207                                          g_param_spec_string ("link-foreground",
208                                                               "",
209                                                               "",
210                                                               NULL,
211                                                               G_PARAM_READWRITE));
212
213         g_type_class_add_private (object_class, sizeof (EmpathyThemeBoxesPriv));
214 }
215
216 static void
217 empathy_theme_boxes_init (EmpathyThemeBoxes *theme)
218 {
219         EmpathyThemeBoxesPriv *priv;
220
221         priv = GET_PRIV (theme);
222 }
223
224 static void
225 theme_boxes_finalize (GObject *object)
226 {
227         EmpathyThemeBoxesPriv *priv;
228
229         priv = GET_PRIV (object);
230
231         g_free (priv->header_foreground);
232         g_free (priv->header_background);
233         g_free (priv->header_line_background);
234         g_free (priv->text_foreground);
235         g_free (priv->text_background);
236         g_free (priv->action_foreground);
237         g_free (priv->highlight_foreground);
238         g_free (priv->time_foreground);
239         g_free (priv->event_foreground);
240         g_free (priv->invite_foreground);
241         g_free (priv->link_foreground);
242         
243         (G_OBJECT_CLASS (empathy_theme_boxes_parent_class)->finalize) (object);
244 }
245
246 static void
247 theme_boxes_get_property (GObject    *object,
248                           guint       param_id,
249                           GValue     *value,
250                           GParamSpec *pspec)
251 {
252         EmpathyThemeBoxesPriv *priv;
253
254         priv = GET_PRIV (object);
255
256         switch (param_id) {
257         case PROP_HEADER_FOREGROUND:
258                 g_value_set_string (value, priv->header_foreground);
259                 break;
260         case PROP_HEADER_BACKGROUND:
261                 g_value_set_string (value, priv->header_background);
262                 break;
263         case PROP_HEADER_LINE_BACKGROUND:
264                 g_value_set_string (value, priv->header_line_background);
265                 break;
266         case PROP_TEXT_FOREGROUND:
267                 g_value_set_string (value, priv->text_foreground);
268                 break;
269         case PROP_TEXT_BACKGROUND:
270                 g_value_set_string (value, priv->text_background);
271                 break;
272         case PROP_ACTION_FOREGROUND:
273                 g_value_set_string (value, priv->action_foreground);
274                 break;
275         case PROP_HIGHLIGHT_FOREGROUND:
276                 g_value_set_string (value, priv->highlight_foreground);
277                 break;
278         case PROP_TIME_FOREGROUND:
279                 g_value_set_string (value, priv->time_foreground);
280                 break;
281         case PROP_EVENT_FOREGROUND:
282                 g_value_set_string (value, priv->event_foreground);
283                 break;
284         case PROP_INVITE_FOREGROUND:
285                 g_value_set_string (value, priv->invite_foreground);
286                 break;
287         case PROP_LINK_FOREGROUND:
288                 g_value_set_string (value, priv->link_foreground);
289                 break;
290         default:
291                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
292                 break;
293         }
294 }
295 static void
296 theme_boxes_set_property (GObject      *object,
297                           guint         param_id,
298                           const GValue *value,
299                           GParamSpec   *pspec)
300 {
301         EmpathyThemeBoxesPriv *priv;
302
303         priv = GET_PRIV (object);
304
305         switch (param_id) {
306         case PROP_HEADER_FOREGROUND:
307                 g_free (priv->header_foreground);
308                 priv->header_foreground = g_value_dup_string (value);
309                 g_object_notify (object, "header-foreground");
310                 break;
311         case PROP_HEADER_BACKGROUND:
312                 g_free (priv->header_background);
313                 priv->header_background = g_value_dup_string (value);
314                 g_object_notify (object, "header-background");
315                 break;
316         case PROP_HEADER_LINE_BACKGROUND:
317                 g_free (priv->header_line_background);
318                 priv->header_line_background = g_value_dup_string (value);
319                 g_object_notify (object, "header-line_background");
320                 break;
321         case PROP_TEXT_FOREGROUND:
322                 g_free (priv->text_foreground);
323                 priv->text_foreground = g_value_dup_string (value);
324                 g_object_notify (object, "text-foreground");
325                 break;
326         case PROP_TEXT_BACKGROUND:
327                 g_free (priv->text_background);
328                 priv->text_background = g_value_dup_string (value);
329                 g_object_notify (object, "text-background");
330                 break;
331         case PROP_ACTION_FOREGROUND:
332                 g_free (priv->action_foreground);
333                 priv->action_foreground = g_value_dup_string (value);
334                 g_object_notify (object, "action-foreground");
335                 break;
336         case PROP_HIGHLIGHT_FOREGROUND:
337                 g_free (priv->highlight_foreground);
338                 priv->highlight_foreground = g_value_dup_string (value);
339                 g_object_notify (object, "highlight-foreground");
340                 break;
341         case PROP_TIME_FOREGROUND:
342                 g_free (priv->time_foreground);
343                 priv->time_foreground = g_value_dup_string (value);
344                 g_object_notify (object, "time-foreground");
345                 break;
346         case PROP_EVENT_FOREGROUND:
347                 g_free (priv->event_foreground);
348                 priv->event_foreground = g_value_dup_string (value);
349                 g_object_notify (object, "event-foreground");
350                 break;
351         case PROP_INVITE_FOREGROUND:
352                 g_free (priv->invite_foreground);
353                 priv->invite_foreground = g_value_dup_string (value);
354                 g_object_notify (object, "invite-foreground");
355                 break;
356         case PROP_LINK_FOREGROUND:
357                 g_free (priv->link_foreground);
358                 priv->link_foreground = g_value_dup_string (value);
359                 g_object_notify (object, "link-foreground");
360                 break;
361         default:
362                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
363                 break;
364         }
365 }
366
367 static void
368 theme_boxes_define_theme_tags (EmpathyTheme *theme, EmpathyChatView *view)
369 {
370         EmpathyThemeBoxesPriv *priv;
371         GtkTextBuffer         *buffer;
372         GtkTextTag            *tag;
373
374         priv = GET_PRIV (theme);
375
376         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
377
378         empathy_text_buffer_tag_set (buffer, "fancy-spacing",
379                                      "size", 3000,
380                                      "pixels-above-lines", 8,
381                                      NULL);
382
383         tag = empathy_text_buffer_tag_set (buffer, "fancy-header",
384                                            "weight", PANGO_WEIGHT_BOLD,
385                                            "pixels-above-lines", HEADER_PADDING,
386                                            "pixels-below-lines", HEADER_PADDING,
387                                            NULL);
388         if (priv->header_foreground) {
389                 g_object_set (tag,
390                               "foreground", priv->header_foreground,
391                               "paragraph-background", priv->header_background,
392                               NULL);
393         }
394
395         tag = empathy_text_buffer_tag_set (buffer, "fancy-header-line",
396                                            "size", 1,
397                                            NULL);
398         if (priv->header_line_background) {
399                 g_object_set (tag,
400                               "paragraph-background", priv->header_line_background,
401                               NULL);
402         }
403
404         tag = empathy_text_buffer_tag_set (buffer, "fancy-body",
405                                            "pixels-above-lines", 4,
406                                            NULL);
407         if (priv->text_background) {
408                 g_object_set (tag,
409                               "paragraph-background", priv->text_background,
410                               NULL);
411         }
412
413         if (priv->text_foreground) {
414                 g_object_set (tag,
415                               "foreground", priv->text_foreground,
416                               NULL);
417         }
418
419         tag = empathy_text_buffer_tag_set (buffer, "fancy-action",
420                                            "style", PANGO_STYLE_ITALIC,
421                                            "pixels-above-lines", 4,
422                                            NULL);
423
424         if (priv->text_background) {
425                 g_object_set (tag,
426                               "paragraph-background", priv->text_background,
427                               NULL);
428         }
429
430         if (priv->action_foreground) {
431                 g_object_set (tag,
432                               "foreground", priv->action_foreground,
433                               NULL);
434         }
435
436         tag = empathy_text_buffer_tag_set (buffer, "fancy-highlight",
437                                            "weight", PANGO_WEIGHT_BOLD,
438                                            "pixels-above-lines", 4,
439                                            NULL);
440         if (priv->text_background) {
441                 g_object_set (tag,
442                               "paragraph-background", priv->text_background,
443                               NULL);
444         }
445
446
447         if (priv->highlight_foreground) {
448                 g_object_set (tag,
449                               "foreground", priv->highlight_foreground,
450                               NULL);
451         }
452
453         tag = empathy_text_buffer_tag_set (buffer, "fancy-time",
454                                            "justification", GTK_JUSTIFY_CENTER,
455                                            NULL);
456         if (priv->time_foreground) {
457                 g_object_set (tag,
458                               "foreground", priv->time_foreground,
459                               NULL);
460         }
461
462         tag = empathy_text_buffer_tag_set (buffer, "fancy-event",
463                                            "justification", GTK_JUSTIFY_LEFT,
464                                            NULL);
465         if (priv->event_foreground) {
466                 g_object_set (tag,
467                               "foreground", priv->event_foreground,
468                               NULL);
469         }
470
471         tag = empathy_text_buffer_tag_set (buffer, "invite", NULL);
472         if (priv->invite_foreground) {
473                 g_object_set (tag,
474                               "foreground", priv->invite_foreground,
475                               NULL);
476         }
477
478         tag = empathy_text_buffer_tag_set (buffer, "fancy-link",
479                                            "underline", PANGO_UNDERLINE_SINGLE,
480                                            NULL);
481         if (priv->link_foreground) {
482                 g_object_set (tag,
483                               "foreground", priv->link_foreground,
484                               NULL);
485         } 
486 }
487
488 static void
489 theme_boxes_update_view (EmpathyTheme *theme, EmpathyChatView *view)
490 {
491         EmpathyThemeBoxesPriv *priv;
492
493         g_return_if_fail (EMPATHY_IS_THEME_BOXES (theme));
494         g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
495
496         priv = GET_PRIV (theme);
497
498         theme_boxes_define_theme_tags (theme, view);
499         
500         empathy_chat_view_set_margin (view, MARGIN);
501 }
502
503 static void
504 table_size_allocate_cb (GtkWidget     *view,
505                         GtkAllocation *allocation,
506                         GtkWidget     *box)
507 {
508         gint width, height;
509
510         gtk_widget_get_size_request (box, NULL, &height);
511
512         width = allocation->width;
513         
514         width -= \
515                 gtk_text_view_get_right_margin (GTK_TEXT_VIEW (view)) - \
516                 gtk_text_view_get_left_margin (GTK_TEXT_VIEW (view));
517         width -= 2 * MARGIN;
518         width -= 2 * HEADER_PADDING;
519
520         gtk_widget_set_size_request (box, width, height);
521 }
522
523 static void
524 theme_boxes_maybe_append_header (EmpathyTheme        *theme,
525                                  EmpathyChatView     *view,
526                                  EmpathyMessage      *msg)
527 {
528         EmpathyThemeBoxesPriv *priv;
529         EmpathyContact        *contact;
530         EmpathyContact        *last_contact;
531         GdkPixbuf            *avatar = NULL;
532         GtkTextBuffer        *buffer;
533         const gchar          *name;
534         GtkTextIter           iter;
535         GtkWidget            *label1, *label2;
536         GtkTextChildAnchor   *anchor;
537         GtkWidget            *box;
538         gchar                *str;
539         time_t                time;
540         gchar                *tmp;
541         GtkTextIter           start;
542         GdkColor              color;
543         gboolean              parse_success;
544
545         priv = GET_PRIV (theme);
546
547         contact = empathy_message_get_sender (msg);
548         name = empathy_contact_get_name (contact);
549         last_contact = empathy_chat_view_get_last_contact (view);
550         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
551
552         empathy_debug (DEBUG_DOMAIN, "Maybe add fancy header");
553
554         /* Only insert a header if the previously inserted block is not the same
555          * as this one. This catches all the different cases:
556          */
557         if (last_contact && empathy_contact_equal (last_contact, contact)) {
558                 return;
559         }
560
561         empathy_theme_append_spacing (theme, view);
562
563         gtk_text_buffer_get_end_iter (buffer, &iter);
564         gtk_text_buffer_insert_with_tags_by_name (buffer,
565                                                   &iter,
566                                                   "\n",
567                                                   -1,
568                                                   "fancy-header-line",
569                                                   NULL);
570
571         gtk_text_buffer_get_end_iter (buffer, &iter);
572         anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
573
574         box = gtk_hbox_new (FALSE, 0);
575
576
577         if (empathy_theme_get_show_avatars (theme)) {
578                 avatar = empathy_chat_view_get_avatar_pixbuf_with_cache (contact);
579                 if (avatar) {
580                         GtkWidget *image;
581
582                         image = gtk_image_new_from_pixbuf (avatar);
583
584                         gtk_box_pack_start (GTK_BOX (box), image,
585                                             FALSE, TRUE, 2);
586                 }
587         }
588
589         g_signal_connect_object (view, "size-allocate",
590                                  G_CALLBACK (table_size_allocate_cb),
591                                  box, 0);
592
593         str = g_markup_printf_escaped ("<b>%s</b>", name);
594
595         label1 = g_object_new (GTK_TYPE_LABEL,
596                                "label", str,
597                                "use-markup", TRUE,
598                                "xalign", 0.0,
599                                NULL);
600
601         parse_success = priv->header_foreground &&
602                         gdk_color_parse (priv->header_foreground, &color);
603
604         if (parse_success) {
605                 gtk_widget_modify_fg (label1, GTK_STATE_NORMAL, &color);
606         }
607
608         g_free (str);
609
610         time = empathy_message_get_timestamp (msg);
611
612         tmp = empathy_time_to_string_local (time, 
613                                            EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
614         str = g_strdup_printf ("<i>%s</i>", tmp);
615         g_free (tmp);
616
617         label2 = g_object_new (GTK_TYPE_LABEL,
618                                "label", str,
619                                "use-markup", TRUE,
620                                "xalign", 1.0,
621                                NULL);
622         
623         if (parse_success) {
624                 gtk_widget_modify_fg (label2, GTK_STATE_NORMAL, &color);
625         }
626
627         g_free (str);
628
629         gtk_misc_set_alignment (GTK_MISC (label1), 0.0, 0.5);
630         gtk_misc_set_alignment (GTK_MISC (label2), 1.0, 0.5);
631
632         gtk_box_pack_start (GTK_BOX (box), label1, TRUE, TRUE, 0);
633         gtk_box_pack_start (GTK_BOX (box), label2, TRUE, TRUE, 0);
634
635         gtk_text_view_add_child_at_anchor (GTK_TEXT_VIEW (view),
636                                            box,
637                                            anchor);
638
639         gtk_widget_show_all (box);
640
641         gtk_text_buffer_get_end_iter (buffer, &iter);
642         start = iter;
643         gtk_text_iter_backward_char (&start);
644         gtk_text_buffer_apply_tag_by_name (buffer,
645                                            "fancy-header",
646                                            &start, &iter);
647
648         gtk_text_buffer_insert_with_tags_by_name (buffer,
649                                                   &iter,
650                                                   "\n",
651                                                   -1,
652                                                   "fancy-header",
653                                                   NULL);
654
655         gtk_text_buffer_get_end_iter (buffer, &iter);
656         gtk_text_buffer_insert_with_tags_by_name (buffer,
657                                                   &iter,
658                                                   "\n",
659                                                   -1,
660                                                   "fancy-header-line",
661                                                   NULL);
662 }
663
664 static void
665 theme_boxes_append_message (EmpathyTheme        *theme,
666                             EmpathyChatView     *view,
667                             EmpathyMessage      *message)
668 {
669         EmpathyContact *sender;
670
671         empathy_theme_maybe_append_date_and_time (theme, view, message);
672         theme_boxes_maybe_append_header (theme, view, message);
673
674         sender = empathy_message_get_sender (message);
675
676         if (empathy_message_get_type (message) == EMPATHY_MESSAGE_TYPE_ACTION) {
677                 gchar *body;
678
679                 body = g_strdup_printf (" * %s %s", 
680                                         empathy_contact_get_name (sender),
681                                         empathy_message_get_body (message));
682                 empathy_theme_append_text (theme, view, body,
683                                            "fancy-action", "fancy-link");
684         } else {
685                 empathy_theme_append_text (theme, view,
686                                            empathy_message_get_body (message),
687                                            "fancy-body", "fancy-link");
688         }
689 }
690
691 static void
692 theme_boxes_append_event (EmpathyTheme        *theme,
693                           EmpathyChatView     *view,
694                           const gchar        *str)
695 {
696         GtkTextBuffer *buffer;
697         GtkTextIter    iter;
698         gchar         *msg;
699
700         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
701
702         empathy_theme_maybe_append_date_and_time (theme, view, NULL);
703
704         gtk_text_buffer_get_end_iter (buffer, &iter);
705
706         msg = g_strdup_printf (" - %s\n", str);
707
708         gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
709                                                   msg, -1,
710                                                   "fancy-event",
711                                                   NULL);
712         g_free (msg);
713 }
714
715 static void
716 theme_boxes_append_timestamp (EmpathyTheme        *theme,
717                               EmpathyChatView     *view,
718                               EmpathyMessage      *message,
719                               gboolean            show_date,
720                               gboolean            show_time)
721 {
722         GtkTextBuffer *buffer;
723         time_t         timestamp;
724         GDate         *date;
725         GtkTextIter    iter;
726         GString       *str;
727         
728         if (!show_date) {
729                 return;
730         }
731
732         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
733
734         date = empathy_message_get_date_and_time (message, &timestamp);
735
736         str = g_string_new (NULL);
737
738         if (show_time || show_date) {
739                 empathy_theme_append_spacing (theme, view);
740
741                 g_string_append (str, "- ");
742         }
743
744         if (show_date) {
745                 gchar buf[256];
746
747                 g_date_strftime (buf, 256, _("%A %d %B %Y"), date);
748                 g_string_append (str, buf);
749
750                 if (show_time) {
751                         g_string_append (str, ", ");
752                 }
753         }
754
755         g_date_free (date);
756
757         if (show_time) {
758                 gchar *tmp;
759
760                 tmp = empathy_time_to_string_local (timestamp, EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
761                 g_string_append (str, tmp);
762                 g_free (tmp);
763         }
764
765         if (show_time || show_date) {
766                 g_string_append (str, " -\n");
767
768                 gtk_text_buffer_get_end_iter (buffer, &iter);
769                 gtk_text_buffer_insert_with_tags_by_name (buffer,
770                                                           &iter,
771                                                           str->str, -1,
772                                                           "fancy-time",
773                                                           NULL);
774
775                 empathy_chat_view_set_last_timestamp (view, timestamp);
776         }
777
778         g_string_free (str, TRUE);
779         
780 }
781
782 static void
783 theme_boxes_append_spacing (EmpathyTheme        *theme,
784                             EmpathyChatView     *view)
785 {
786         GtkTextBuffer *buffer;
787         GtkTextIter    iter;
788
789         g_return_if_fail (EMPATHY_IS_THEME (theme));
790         g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
791
792         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
793
794         gtk_text_buffer_get_end_iter (buffer, &iter);
795         gtk_text_buffer_insert_with_tags_by_name (buffer,
796                                                   &iter,
797                                                   "\n",
798                                                   -1,
799                                                   "cut",
800                                                   "fancy-spacing",
801                                                   NULL);
802 }
803