]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-theme-boxes.c
87eac87d5551ff2201884b14c7c5de66a53e3d39
[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) != BLOCK_TYPE_SELF &&
563             empathy_chat_view_get_last_block_type (view) != BLOCK_TYPE_OTHER) {
564                 header = TRUE;
565         }
566         else if (from_self &&
567                  empathy_chat_view_get_last_block_type (view) == BLOCK_TYPE_OTHER) {
568                 header = TRUE;
569         }
570         else if (!from_self && 
571                  empathy_chat_view_get_last_block_type (view) == BLOCK_TYPE_SELF) {
572                 header = TRUE;
573         }
574         else if (!from_self &&
575                  (!empathy_chat_view_get_last_contact (view) ||
576                   !empathy_contact_equal (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         avatar = empathy_chat_view_get_avatar_pixbuf_with_cache (contact);
601         if (avatar && empathy_theme_get_show_avatars (theme)) {
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, BLOCK_TYPE_SELF);
714                 empathy_chat_view_set_last_contact (view, NULL);
715         } else {
716                 empathy_chat_view_set_last_block_type (view, BLOCK_TYPE_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, BLOCK_TYPE_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, BLOCK_TYPE_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