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