]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-theme-boxes.c
Move modules that make no sense to be used in other applicaton from libempathy-gtk...
[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         GdkPixbuf            *avatar = NULL;
531         GtkTextBuffer        *buffer;
532         const gchar          *name;
533         gboolean              header;
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         gboolean              from_self;
545
546         priv = GET_PRIV (theme);
547
548         contact = empathy_message_get_sender (msg);
549         from_self = empathy_contact_is_user (contact);
550         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
551
552         empathy_debug (DEBUG_DOMAIN, "Maybe add fancy header");
553
554         name = empathy_contact_get_name (contact);
555
556         header = FALSE;
557
558         /* Only insert a header if the previously inserted block is not the same
559          * as this one. This catches all the different cases:
560          */
561         if (empathy_chat_view_get_last_block_type (view) != EMPATHY_CHAT_VIEW_BLOCK_SELF &&
562             empathy_chat_view_get_last_block_type (view) != EMPATHY_CHAT_VIEW_BLOCK_OTHER) {
563                 header = TRUE;
564         }
565         else if (from_self &&
566                  empathy_chat_view_get_last_block_type (view) == EMPATHY_CHAT_VIEW_BLOCK_OTHER) {
567                 header = TRUE;
568         }
569         else if (!from_self && 
570                  empathy_chat_view_get_last_block_type (view) == EMPATHY_CHAT_VIEW_BLOCK_SELF) {
571                 header = TRUE;
572         }
573         else if (!from_self &&
574                  (!empathy_chat_view_get_last_contact (view) ||
575                   contact != empathy_chat_view_get_last_contact (view))) {
576                 header = TRUE;
577         }
578
579         if (!header) {
580                 return;
581         }
582
583         empathy_theme_append_spacing (theme, view);
584
585         gtk_text_buffer_get_end_iter (buffer, &iter);
586         gtk_text_buffer_insert_with_tags_by_name (buffer,
587                                                   &iter,
588                                                   "\n",
589                                                   -1,
590                                                   "fancy-header-line",
591                                                   NULL);
592
593         gtk_text_buffer_get_end_iter (buffer, &iter);
594         anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
595
596         box = gtk_hbox_new (FALSE, 0);
597
598
599         if (empathy_theme_get_show_avatars (theme)) {
600                 avatar = empathy_chat_view_get_avatar_pixbuf_with_cache (contact);
601                 if (avatar) {
602                         GtkWidget *image;
603
604                         image = gtk_image_new_from_pixbuf (avatar);
605
606                         gtk_box_pack_start (GTK_BOX (box), image,
607                                             FALSE, TRUE, 2);
608                 }
609         }
610
611         g_signal_connect_object (view, "size-allocate",
612                                  G_CALLBACK (table_size_allocate_cb),
613                                  box, 0);
614
615         str = g_strdup_printf ("<b>%s</b>", name);
616
617         label1 = g_object_new (GTK_TYPE_LABEL,
618                                "label", str,
619                                "use-markup", TRUE,
620                                "xalign", 0.0,
621                                NULL);
622
623         parse_success = priv->header_foreground &&
624                         gdk_color_parse (priv->header_foreground, &color);
625
626         if (parse_success) {
627                 gtk_widget_modify_fg (label1, GTK_STATE_NORMAL, &color);
628         }
629
630         g_free (str);
631
632         time = empathy_message_get_timestamp (msg);
633
634         tmp = empathy_time_to_string_local (time, 
635                                            EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
636         str = g_strdup_printf ("<i>%s</i>", tmp);
637         g_free (tmp);
638
639         label2 = g_object_new (GTK_TYPE_LABEL,
640                                "label", str,
641                                "use-markup", TRUE,
642                                "xalign", 1.0,
643                                NULL);
644         
645         if (parse_success) {
646                 gtk_widget_modify_fg (label2, GTK_STATE_NORMAL, &color);
647         }
648
649         g_free (str);
650
651         gtk_misc_set_alignment (GTK_MISC (label1), 0.0, 0.5);
652         gtk_misc_set_alignment (GTK_MISC (label2), 1.0, 0.5);
653
654         gtk_box_pack_start (GTK_BOX (box), label1, TRUE, TRUE, 0);
655         gtk_box_pack_start (GTK_BOX (box), label2, TRUE, TRUE, 0);
656
657         gtk_text_view_add_child_at_anchor (GTK_TEXT_VIEW (view),
658                                            box,
659                                            anchor);
660
661         gtk_widget_show_all (box);
662
663         gtk_text_buffer_get_end_iter (buffer, &iter);
664         start = iter;
665         gtk_text_iter_backward_char (&start);
666         gtk_text_buffer_apply_tag_by_name (buffer,
667                                            "fancy-header",
668                                            &start, &iter);
669
670         gtk_text_buffer_insert_with_tags_by_name (buffer,
671                                                   &iter,
672                                                   "\n",
673                                                   -1,
674                                                   "fancy-header",
675                                                   NULL);
676
677         gtk_text_buffer_get_end_iter (buffer, &iter);
678         gtk_text_buffer_insert_with_tags_by_name (buffer,
679                                                   &iter,
680                                                   "\n",
681                                                   -1,
682                                                   "fancy-header-line",
683                                                   NULL);
684 }
685
686 static void
687 theme_boxes_append_message (EmpathyTheme        *theme,
688                             EmpathyChatView     *view,
689                             EmpathyMessage      *message)
690 {
691         EmpathyContact *sender;
692
693         empathy_theme_maybe_append_date_and_time (theme, view, message);
694         theme_boxes_maybe_append_header (theme, view, message);
695
696         sender = empathy_message_get_sender (message);
697
698         if (empathy_message_get_type (message) == EMPATHY_MESSAGE_TYPE_ACTION) {
699                 gchar *body;
700
701                 body = g_strdup_printf (" * %s %s", 
702                                         empathy_contact_get_name (sender),
703                                         empathy_message_get_body (message));
704                 empathy_theme_append_text (theme, view, body,
705                                            "fancy-action", "fancy-link");
706         } else {
707                 empathy_theme_append_text (theme, view,
708                                            empathy_message_get_body (message),
709                                            "fancy-body", "fancy-link");
710         }
711         
712         if (empathy_contact_is_user (sender)) {
713                 empathy_chat_view_set_last_block_type (view, EMPATHY_CHAT_VIEW_BLOCK_SELF);
714                 empathy_chat_view_set_last_contact (view, NULL);
715         } else {
716                 empathy_chat_view_set_last_block_type (view, EMPATHY_CHAT_VIEW_BLOCK_OTHER);
717                 empathy_chat_view_set_last_contact (view, sender);
718         }
719 }
720
721 static void
722 theme_boxes_append_event (EmpathyTheme        *theme,
723                           EmpathyChatView     *view,
724                           const gchar        *str)
725 {
726         GtkTextBuffer *buffer;
727         GtkTextIter    iter;
728         gchar         *msg;
729
730         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
731
732         empathy_theme_maybe_append_date_and_time (theme, view, NULL);
733
734         gtk_text_buffer_get_end_iter (buffer, &iter);
735
736         msg = g_strdup_printf (" - %s\n", str);
737
738         gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
739                                                   msg, -1,
740                                                   "fancy-event",
741                                                   NULL);
742         g_free (msg);
743
744         empathy_chat_view_set_last_block_type (view, EMPATHY_CHAT_VIEW_BLOCK_EVENT);
745 }
746
747 static void
748 theme_boxes_append_timestamp (EmpathyTheme        *theme,
749                               EmpathyChatView     *view,
750                               EmpathyMessage      *message,
751                               gboolean            show_date,
752                               gboolean            show_time)
753 {
754         GtkTextBuffer *buffer;
755         time_t         timestamp;
756         GDate         *date;
757         GtkTextIter    iter;
758         GString       *str;
759         
760         if (!show_date) {
761                 return;
762         }
763
764         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
765
766         date = empathy_message_get_date_and_time (message, &timestamp);
767
768         str = g_string_new (NULL);
769
770         if (show_time || show_date) {
771                 empathy_theme_append_spacing (theme, view);
772
773                 g_string_append (str, "- ");
774         }
775
776         if (show_date) {
777                 gchar buf[256];
778
779                 g_date_strftime (buf, 256, _("%A %d %B %Y"), date);
780                 g_string_append (str, buf);
781
782                 if (show_time) {
783                         g_string_append (str, ", ");
784                 }
785         }
786
787         g_date_free (date);
788
789         if (show_time) {
790                 gchar *tmp;
791
792                 tmp = empathy_time_to_string_local (timestamp, EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
793                 g_string_append (str, tmp);
794                 g_free (tmp);
795         }
796
797         if (show_time || show_date) {
798                 g_string_append (str, " -\n");
799
800                 gtk_text_buffer_get_end_iter (buffer, &iter);
801                 gtk_text_buffer_insert_with_tags_by_name (buffer,
802                                                           &iter,
803                                                           str->str, -1,
804                                                           "fancy-time",
805                                                           NULL);
806
807                 empathy_chat_view_set_last_block_type (view, EMPATHY_CHAT_VIEW_BLOCK_TIME);
808                 empathy_chat_view_set_last_timestamp (view, timestamp);
809         }
810
811         g_string_free (str, TRUE);
812         
813 }
814
815 static void
816 theme_boxes_append_spacing (EmpathyTheme        *theme,
817                             EmpathyChatView     *view)
818 {
819         GtkTextBuffer *buffer;
820         GtkTextIter    iter;
821
822         g_return_if_fail (EMPATHY_IS_THEME (theme));
823         g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
824
825         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
826
827         gtk_text_buffer_get_end_iter (buffer, &iter);
828         gtk_text_buffer_insert_with_tags_by_name (buffer,
829                                                   &iter,
830                                                   "\n",
831                                                   -1,
832                                                   "cut",
833                                                   "fancy-spacing",
834                                                   NULL);
835 }
836