1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2005-2007 Imendio AB
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.
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.
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.
20 * Authors: Richard Hult <richard@imendio.com>
27 #include <glib/gi18n.h>
30 #include <libempathy/empathy-conf.h>
31 #include <libempathy/empathy-utils.h>
33 #include "empathy-chat-view.h"
34 #include "empathy-preferences.h"
35 #include "empathy-theme-manager.h"
37 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_THEME_MANAGER, EmpathyThemeManagerPriv))
44 gboolean show_avatars;
45 guint show_avatars_notify_id;
48 } EmpathyThemeManagerPriv;
50 static void theme_manager_finalize (GObject *object);
51 static void theme_manager_notify_name_cb (EmpathyConf *conf,
54 static void theme_manager_notify_room_cb (EmpathyConf *conf,
57 static void theme_manager_notify_show_avatars_cb (EmpathyConf *conf,
60 static void theme_manager_ensure_tag_by_name (GtkTextBuffer *buffer,
62 static gboolean theme_manager_ensure_theme_exists (const gchar *name);
63 static GtkTextTag *theme_manager_init_tag_by_name (GtkTextTagTable *table,
65 static void theme_manager_add_tag (GtkTextTagTable *table,
67 static void theme_manager_fixup_tag_table (EmpathyThemeManager *theme_manager,
68 EmpathyChatView *view);
69 static void theme_manager_apply_theme_classic (EmpathyThemeManager *manager,
70 EmpathyChatView *view);
71 static void theme_manager_apply_theme_clean (EmpathyThemeManager *manager,
72 EmpathyChatView *view);
73 static void theme_manager_apply_theme_blue (EmpathyThemeManager *manager,
74 EmpathyChatView *view);
75 static void theme_manager_apply_theme (EmpathyThemeManager *manager,
76 EmpathyChatView *view,
84 static guint signals[LAST_SIGNAL] = { 0 };
86 static const gchar *themes[] = {
87 "classic", N_("Classic"),
88 "simple", N_("Simple"),
94 G_DEFINE_TYPE (EmpathyThemeManager, empathy_theme_manager, G_TYPE_OBJECT);
97 empathy_theme_manager_class_init (EmpathyThemeManagerClass *klass)
99 GObjectClass *object_class = G_OBJECT_CLASS (klass);
101 signals[THEME_CHANGED] =
102 g_signal_new ("theme-changed",
103 G_OBJECT_CLASS_TYPE (object_class),
107 g_cclosure_marshal_VOID__VOID,
111 g_type_class_add_private (object_class, sizeof (EmpathyThemeManagerPriv));
113 object_class->finalize = theme_manager_finalize;
117 empathy_theme_manager_init (EmpathyThemeManager *manager)
119 EmpathyThemeManagerPriv *priv;
121 priv = GET_PRIV (manager);
123 priv->name_notify_id =
124 empathy_conf_notify_add (empathy_conf_get (),
125 EMPATHY_PREFS_CHAT_THEME,
126 theme_manager_notify_name_cb,
129 priv->room_notify_id =
130 empathy_conf_notify_add (empathy_conf_get (),
131 EMPATHY_PREFS_CHAT_THEME_CHAT_ROOM,
132 theme_manager_notify_room_cb,
135 empathy_conf_get_string (empathy_conf_get (),
136 EMPATHY_PREFS_CHAT_THEME,
139 /* Unused right now, but will be used soon. */
140 priv->show_avatars_notify_id =
141 empathy_conf_notify_add (empathy_conf_get (),
142 EMPATHY_PREFS_UI_SHOW_AVATARS,
143 theme_manager_notify_show_avatars_cb,
146 empathy_conf_get_bool (empathy_conf_get (),
147 EMPATHY_PREFS_UI_SHOW_AVATARS,
148 &priv->show_avatars);
152 theme_manager_finalize (GObject *object)
154 EmpathyThemeManagerPriv *priv;
156 priv = GET_PRIV (object);
158 empathy_conf_notify_remove (empathy_conf_get (), priv->name_notify_id);
159 empathy_conf_notify_remove (empathy_conf_get (), priv->room_notify_id);
160 empathy_conf_notify_remove (empathy_conf_get (), priv->show_avatars_notify_id);
164 G_OBJECT_CLASS (empathy_theme_manager_parent_class)->finalize (object);
168 theme_manager_notify_name_cb (EmpathyConf *conf,
172 EmpathyThemeManager *manager;
173 EmpathyThemeManagerPriv *priv;
177 priv = GET_PRIV (manager);
182 if (!empathy_conf_get_string (conf, key, &name) ||
183 name == NULL || name[0] == 0) {
184 priv->name = g_strdup ("classic");
190 g_signal_emit (manager, signals[THEME_CHANGED], 0, NULL);
194 theme_manager_notify_room_cb (EmpathyConf *conf,
198 g_signal_emit (user_data, signals[THEME_CHANGED], 0, NULL);
202 theme_manager_notify_show_avatars_cb (EmpathyConf *conf,
206 EmpathyThemeManager *manager;
207 EmpathyThemeManagerPriv *priv;
211 priv = GET_PRIV (manager);
213 if (!empathy_conf_get_bool (conf, key, &value)) {
214 priv->show_avatars = FALSE;
216 priv->show_avatars = value;
221 theme_manager_ensure_tag_by_name (GtkTextBuffer *buffer,
224 GtkTextTagTable *table;
227 table = gtk_text_buffer_get_tag_table (buffer);
228 tag = gtk_text_tag_table_lookup (table, name);
231 gtk_text_buffer_create_tag (buffer,
238 theme_manager_ensure_theme_exists (const gchar *name)
242 if (G_STR_EMPTY (name)) {
246 for (i = 0; themes[i]; i += 2) {
247 if (strcmp (themes[i], name) == 0) {
256 theme_manager_init_tag_by_name (GtkTextTagTable *table,
261 tag = gtk_text_tag_table_lookup (table, name);
264 return gtk_text_tag_new (name);
267 /* Clear the old values so that we don't affect the new theme. */
269 "background-set", FALSE,
270 "foreground-set", FALSE,
271 "invisible-set", FALSE,
272 "justification-set", FALSE,
273 "paragraph-background-set", FALSE,
274 "pixels-above-lines-set", FALSE,
275 "pixels-below-lines-set", FALSE,
287 theme_manager_add_tag (GtkTextTagTable *table,
291 GtkTextTag *check_tag;
293 g_object_get (tag, "name", &name, NULL);
294 check_tag = gtk_text_tag_table_lookup (table, name);
300 gtk_text_tag_table_add (table, tag);
302 g_object_unref (tag);
306 theme_manager_fixup_tag_table (EmpathyThemeManager *theme_manager,
307 EmpathyChatView *view)
309 GtkTextBuffer *buffer;
311 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
313 /* "Fancy" style tags. */
314 theme_manager_ensure_tag_by_name (buffer, "fancy-header-self");
315 theme_manager_ensure_tag_by_name (buffer, "fancy-header-self-avatar");
316 theme_manager_ensure_tag_by_name (buffer, "fancy-avatar-self");
317 theme_manager_ensure_tag_by_name (buffer, "fancy-line-top-self");
318 theme_manager_ensure_tag_by_name (buffer, "fancy-line-bottom-self");
319 theme_manager_ensure_tag_by_name (buffer, "fancy-body-self");
320 theme_manager_ensure_tag_by_name (buffer, "fancy-action-self");
321 theme_manager_ensure_tag_by_name (buffer, "fancy-highlight-self");
323 theme_manager_ensure_tag_by_name (buffer, "fancy-header-other");
324 theme_manager_ensure_tag_by_name (buffer, "fancy-header-other-avatar");
325 theme_manager_ensure_tag_by_name (buffer, "fancy-avatar-other");
326 theme_manager_ensure_tag_by_name (buffer, "fancy-line-top-other");
327 theme_manager_ensure_tag_by_name (buffer, "fancy-line-bottom-other");
328 theme_manager_ensure_tag_by_name (buffer, "fancy-body-other");
329 theme_manager_ensure_tag_by_name (buffer, "fancy-action-other");
330 theme_manager_ensure_tag_by_name (buffer, "fancy-highlight-other");
332 theme_manager_ensure_tag_by_name (buffer, "fancy-spacing");
333 theme_manager_ensure_tag_by_name (buffer, "fancy-time");
334 theme_manager_ensure_tag_by_name (buffer, "fancy-event");
335 theme_manager_ensure_tag_by_name (buffer, "fancy-invite");
336 theme_manager_ensure_tag_by_name (buffer, "fancy-link");
338 /* IRC style tags. */
339 theme_manager_ensure_tag_by_name (buffer, "irc-nick-self");
340 theme_manager_ensure_tag_by_name (buffer, "irc-body-self");
341 theme_manager_ensure_tag_by_name (buffer, "irc-action-self");
343 theme_manager_ensure_tag_by_name (buffer, "irc-nick-other");
344 theme_manager_ensure_tag_by_name (buffer, "irc-body-other");
345 theme_manager_ensure_tag_by_name (buffer, "irc-action-other");
347 theme_manager_ensure_tag_by_name (buffer, "irc-nick-highlight");
348 theme_manager_ensure_tag_by_name (buffer, "irc-spacing");
349 theme_manager_ensure_tag_by_name (buffer, "irc-time");
350 theme_manager_ensure_tag_by_name (buffer, "irc-event");
351 theme_manager_ensure_tag_by_name (buffer, "irc-invite");
352 theme_manager_ensure_tag_by_name (buffer, "irc-link");
356 theme_manager_apply_theme_classic (EmpathyThemeManager *manager,
357 EmpathyChatView *view)
359 EmpathyThemeManagerPriv *priv;
360 GtkTextBuffer *buffer;
361 GtkTextTagTable *table;
364 priv = GET_PRIV (manager);
366 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
367 table = gtk_text_buffer_get_tag_table (buffer);
369 priv->irc_style = TRUE;
371 tag = theme_manager_init_tag_by_name (table, "irc-spacing");
375 theme_manager_add_tag (table, tag);
377 tag = theme_manager_init_tag_by_name (table, "irc-nick-self");
379 "foreground", "sea green",
381 theme_manager_add_tag (table, tag);
383 tag = theme_manager_init_tag_by_name (table, "irc-body-self");
385 /* To get the default theme color: */
386 "foreground-set", FALSE,
388 theme_manager_add_tag (table, tag);
390 tag = theme_manager_init_tag_by_name (table, "irc-action-self");
392 "foreground", "brown4",
393 "style", PANGO_STYLE_ITALIC,
395 theme_manager_add_tag (table, tag);
397 tag = theme_manager_init_tag_by_name (table, "irc-nick-highlight");
399 "foreground", "indian red",
400 "weight", PANGO_WEIGHT_BOLD,
402 theme_manager_add_tag (table, tag);
404 tag = theme_manager_init_tag_by_name (table, "irc-nick-other");
406 "foreground", "skyblue4",
408 theme_manager_add_tag (table, tag);
410 tag = theme_manager_init_tag_by_name (table, "irc-body-other");
412 /* To get the default theme color: */
413 "foreground-set", FALSE,
415 theme_manager_add_tag (table, tag);
417 tag = theme_manager_init_tag_by_name (table, "irc-action-other");
419 "foreground", "brown4",
420 "style", PANGO_STYLE_ITALIC,
422 theme_manager_add_tag (table, tag);
424 tag = theme_manager_init_tag_by_name (table, "irc-time");
426 "foreground", "darkgrey",
427 "justification", GTK_JUSTIFY_CENTER,
429 theme_manager_add_tag (table, tag);
431 tag = theme_manager_init_tag_by_name (table, "irc-event");
433 "foreground", "PeachPuff4",
434 "justification", GTK_JUSTIFY_LEFT,
436 theme_manager_add_tag (table, tag);
438 tag = theme_manager_init_tag_by_name (table, "irc-invite");
440 "foreground", "sienna",
442 theme_manager_add_tag (table, tag);
444 tag = theme_manager_init_tag_by_name (table, "irc-link");
446 "foreground", "steelblue",
447 "underline", PANGO_UNDERLINE_SINGLE,
449 theme_manager_add_tag (table, tag);
453 theme_manager_apply_theme_simple (EmpathyThemeManager *manager,
454 EmpathyChatView *view)
456 EmpathyThemeManagerPriv *priv;
457 GtkTextBuffer *buffer;
458 GtkTextTagTable *table;
463 priv = GET_PRIV (manager);
465 widget = gtk_entry_new ();
466 style = gtk_widget_get_style (widget);
467 gtk_widget_destroy (widget);
469 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
470 table = gtk_text_buffer_get_tag_table (buffer);
472 priv->irc_style = FALSE;
474 tag = theme_manager_init_tag_by_name (table, "fancy-spacing");
478 theme_manager_add_tag (table, tag);
480 tag = theme_manager_init_tag_by_name (table, "fancy-header-self");
482 "weight", PANGO_WEIGHT_BOLD,
484 theme_manager_add_tag (table, tag);
486 tag = theme_manager_init_tag_by_name (table, "fancy-header-self-avatar");
487 theme_manager_add_tag (table, tag);
489 tag = theme_manager_init_tag_by_name (table, "fancy-avatar-self");
490 theme_manager_add_tag (table, tag);
492 tag = theme_manager_init_tag_by_name (table, "fancy-line-top-self");
494 "size", 6 * PANGO_SCALE,
496 theme_manager_add_tag (table, tag);
498 tag = theme_manager_init_tag_by_name (table, "fancy-line-bottom-self");
502 theme_manager_add_tag (table, tag);
504 tag = theme_manager_init_tag_by_name (table, "fancy-body-self");
506 "pixels-above-lines", 2,
507 "pixels-below-lines", 2,
509 theme_manager_add_tag (table, tag);
511 tag = theme_manager_init_tag_by_name (table, "fancy-action-self");
513 "foreground-gdk", &style->base[GTK_STATE_SELECTED],
514 "style", PANGO_STYLE_ITALIC,
515 "pixels-above-lines", 2,
516 "pixels-below-lines", 2,
518 theme_manager_add_tag (table, tag);
520 tag = theme_manager_init_tag_by_name (table, "fancy-highlight-self");
522 "weight", PANGO_WEIGHT_BOLD,
523 "pixels-above-lines", 2,
524 "pixels-below-lines", 2,
526 theme_manager_add_tag (table, tag);
528 tag = theme_manager_init_tag_by_name (table, "fancy-header-other");
530 "weight", PANGO_WEIGHT_BOLD,
532 theme_manager_add_tag (table, tag);
534 tag = theme_manager_init_tag_by_name (table, "fancy-header-other-avatar");
535 theme_manager_add_tag (table, tag);
537 tag = theme_manager_init_tag_by_name (table, "fancy-avatar-other");
538 theme_manager_add_tag (table, tag);
540 tag = theme_manager_init_tag_by_name (table, "fancy-line-top-other");
542 "size", 6 * PANGO_SCALE,
544 theme_manager_add_tag (table, tag);
546 tag = theme_manager_init_tag_by_name (table, "fancy-line-bottom-other");
550 theme_manager_add_tag (table, tag);
552 tag = theme_manager_init_tag_by_name (table, "fancy-body-other");
554 "pixels-above-lines", 2,
555 "pixels-below-lines", 2,
557 theme_manager_add_tag (table, tag);
559 tag = theme_manager_init_tag_by_name (table, "fancy-action-other");
561 "foreground-gdk", &style->base[GTK_STATE_SELECTED],
562 "style", PANGO_STYLE_ITALIC,
563 "pixels-above-lines", 2,
564 "pixels-below-lines", 2,
566 theme_manager_add_tag (table, tag);
568 tag = theme_manager_init_tag_by_name (table, "fancy-highlight-other");
570 "weight", PANGO_WEIGHT_BOLD,
571 "pixels-above-lines", 2,
572 "pixels-below-lines", 2,
574 theme_manager_add_tag (table, tag);
576 tag = theme_manager_init_tag_by_name (table, "fancy-time");
578 "foreground", "darkgrey",
579 "justification", GTK_JUSTIFY_CENTER,
581 theme_manager_add_tag (table, tag);
583 tag = theme_manager_init_tag_by_name (table, "fancy-event");
585 "foreground", "darkgrey",
586 "justification", GTK_JUSTIFY_LEFT,
588 theme_manager_add_tag (table, tag);
590 tag = theme_manager_init_tag_by_name (table, "fancy-invite");
592 "foreground", "darkgrey",
594 theme_manager_add_tag (table, tag);
596 tag = theme_manager_init_tag_by_name (table, "fancy-link");
598 "foreground-gdk", &style->base[GTK_STATE_SELECTED],
599 "underline", PANGO_UNDERLINE_SINGLE,
601 theme_manager_add_tag (table, tag);
605 theme_manager_apply_theme_clean (EmpathyThemeManager *manager,
606 EmpathyChatView *view)
608 EmpathyThemeManagerPriv *priv;
609 GtkTextBuffer *buffer;
610 GtkTextTagTable *table;
613 priv = GET_PRIV (manager);
615 /* Inherit the simple theme. */
616 theme_manager_apply_theme_simple (manager, view);
618 #define ELEGANT_HEAD "#efefdf"
619 #define ELEGANT_LINE "#e3e3d3"
621 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
622 table = gtk_text_buffer_get_tag_table (buffer);
624 tag = theme_manager_init_tag_by_name (table, "fancy-spacing");
626 "size", PANGO_SCALE * 10,
629 tag = theme_manager_init_tag_by_name (table, "fancy-header-self");
631 "foreground", "black",
632 "weight", PANGO_WEIGHT_BOLD,
633 "paragraph-background", ELEGANT_HEAD,
634 "pixels-above-lines", 2,
635 "pixels-below-lines", 2,
638 tag = theme_manager_init_tag_by_name (table, "fancy-avatar-self");
640 "paragraph-background", ELEGANT_HEAD,
641 "pixels-above-lines", 2,
642 "pixels-below-lines", 2,
645 tag = theme_manager_init_tag_by_name (table, "fancy-line-top-self");
647 "size", 1 * PANGO_SCALE,
648 "paragraph-background", ELEGANT_LINE,
651 tag = theme_manager_init_tag_by_name (table, "fancy-line-bottom-self");
653 "size", 1 * PANGO_SCALE,
656 tag = theme_manager_init_tag_by_name (table, "fancy-action-self");
658 "foreground", "brown4",
659 "style", PANGO_STYLE_ITALIC,
662 tag = theme_manager_init_tag_by_name (table, "fancy-highlight-self");
664 "foreground", "black",
665 "weight", PANGO_WEIGHT_BOLD,
668 tag = theme_manager_init_tag_by_name (table, "fancy-header-other");
670 "foreground", "black",
671 "weight", PANGO_WEIGHT_BOLD,
672 "paragraph-background", ELEGANT_HEAD,
673 "pixels-above-lines", 2,
674 "pixels-below-lines", 2,
677 tag = theme_manager_init_tag_by_name (table, "fancy-avatar-other");
679 "paragraph-background", ELEGANT_HEAD,
680 "pixels-above-lines", 2,
681 "pixels-below-lines", 2,
684 tag = theme_manager_init_tag_by_name (table, "fancy-line-top-other");
686 "size", 1 * PANGO_SCALE,
687 "paragraph-background", ELEGANT_LINE,
690 tag = theme_manager_init_tag_by_name (table, "fancy-line-bottom-other");
692 "size", 1 * PANGO_SCALE,
695 tag = theme_manager_init_tag_by_name (table, "fancy-action-other");
697 "foreground", "brown4",
698 "style", PANGO_STYLE_ITALIC,
701 tag = theme_manager_init_tag_by_name (table, "fancy-time");
703 "foreground", "darkgrey",
704 "justification", GTK_JUSTIFY_CENTER,
707 tag = theme_manager_init_tag_by_name (table, "fancy-event");
709 "foreground", "darkgrey",
710 "justification", GTK_JUSTIFY_LEFT,
713 tag = theme_manager_init_tag_by_name (table, "fancy-invite");
715 "foreground", "sienna",
718 tag = theme_manager_init_tag_by_name (table, "fancy-link");
720 "foreground", "#49789e",
721 "underline", PANGO_UNDERLINE_SINGLE,
726 theme_manager_apply_theme_blue (EmpathyThemeManager *manager,
727 EmpathyChatView *view)
729 EmpathyThemeManagerPriv *priv;
730 GtkTextBuffer *buffer;
731 GtkTextTagTable *table;
734 priv = GET_PRIV (manager);
736 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
737 table = gtk_text_buffer_get_tag_table (buffer);
739 priv->irc_style = FALSE;
741 #define BLUE_BODY_SELF "#dcdcdc"
742 #define BLUE_HEAD_SELF "#b9b9b9"
743 #define BLUE_LINE_SELF "#aeaeae"
745 #define BLUE_BODY_OTHER "#adbdc8"
746 #define BLUE_HEAD_OTHER "#88a2b4"
747 #define BLUE_LINE_OTHER "#7f96a4"
749 tag = theme_manager_init_tag_by_name (table, "fancy-spacing");
753 theme_manager_add_tag (table, tag);
755 tag = theme_manager_init_tag_by_name (table, "fancy-header-self");
757 "foreground", "black",
758 "paragraph-background", BLUE_HEAD_SELF,
759 "weight", PANGO_WEIGHT_BOLD,
760 "pixels-above-lines", 2,
761 "pixels-below-lines", 2,
763 theme_manager_add_tag (table, tag);
765 tag = theme_manager_init_tag_by_name (table, "fancy-header-self-avatar");
766 theme_manager_add_tag (table, tag);
768 tag = theme_manager_init_tag_by_name (table, "fancy-avatar-self");
770 "paragraph-background", BLUE_HEAD_SELF,
772 theme_manager_add_tag (table, tag);
774 tag = theme_manager_init_tag_by_name (table, "fancy-line-top-self");
777 "paragraph-background", BLUE_LINE_SELF,
779 theme_manager_add_tag (table, tag);
781 tag = theme_manager_init_tag_by_name (table, "fancy-line-bottom-self");
784 "paragraph-background", BLUE_LINE_SELF,
786 theme_manager_add_tag (table, tag);
788 tag = theme_manager_init_tag_by_name (table, "fancy-body-self");
790 "foreground", "black",
791 "paragraph-background", BLUE_BODY_SELF,
792 "pixels-above-lines", 4,
794 theme_manager_add_tag (table, tag);
796 tag = theme_manager_init_tag_by_name (table, "fancy-action-self");
798 "foreground", "brown4",
799 "style", PANGO_STYLE_ITALIC,
800 "paragraph-background", BLUE_BODY_SELF,
801 "pixels-above-lines", 4,
803 theme_manager_add_tag (table, tag);
805 tag = theme_manager_init_tag_by_name (table, "fancy-highlight-self");
807 "foreground", "black",
808 "weight", PANGO_WEIGHT_BOLD,
809 "paragraph-background", BLUE_BODY_SELF,
810 "pixels-above-lines", 4,
812 theme_manager_add_tag (table, tag);
814 tag = theme_manager_init_tag_by_name (table, "fancy-header-other");
816 "foreground", "black",
817 "paragraph-background", BLUE_HEAD_OTHER,
818 "weight", PANGO_WEIGHT_BOLD,
819 "pixels-above-lines", 2,
820 "pixels-below-lines", 2,
822 theme_manager_add_tag (table, tag);
824 tag = theme_manager_init_tag_by_name (table, "fancy-header-other-avatar");
825 theme_manager_add_tag (table, tag);
827 tag = theme_manager_init_tag_by_name (table, "fancy-avatar-other");
829 "paragraph-background", BLUE_HEAD_OTHER,
831 theme_manager_add_tag (table, tag);
833 tag = theme_manager_init_tag_by_name (table, "fancy-line-top-other");
836 "paragraph-background", BLUE_LINE_OTHER,
838 theme_manager_add_tag (table, tag);
840 tag = theme_manager_init_tag_by_name (table, "fancy-line-bottom-other");
843 "paragraph-background", BLUE_LINE_OTHER,
845 theme_manager_add_tag (table, tag);
847 tag = theme_manager_init_tag_by_name (table, "fancy-body-other");
849 "foreground", "black",
850 "paragraph-background", BLUE_BODY_OTHER,
851 "pixels-above-lines", 4,
853 theme_manager_add_tag (table, tag);
855 tag = theme_manager_init_tag_by_name (table, "fancy-action-other");
857 "foreground", "brown4",
858 "style", PANGO_STYLE_ITALIC,
859 "paragraph-background", BLUE_BODY_OTHER,
860 "pixels-above-lines", 4,
862 theme_manager_add_tag (table, tag);
864 tag = theme_manager_init_tag_by_name (table, "fancy-highlight-other");
866 "foreground", "black",
867 "weight", PANGO_WEIGHT_BOLD,
868 "paragraph-background", BLUE_BODY_OTHER,
869 "pixels-above-lines", 4,
871 theme_manager_add_tag (table, tag);
873 tag = theme_manager_init_tag_by_name (table, "fancy-time");
875 "foreground", "darkgrey",
876 "justification", GTK_JUSTIFY_CENTER,
878 theme_manager_add_tag (table, tag);
880 tag = theme_manager_init_tag_by_name (table, "fancy-event");
882 "foreground", BLUE_LINE_OTHER,
883 "justification", GTK_JUSTIFY_LEFT,
885 theme_manager_add_tag (table, tag);
887 tag = theme_manager_init_tag_by_name (table, "fancy-invite");
889 "foreground", "sienna",
891 theme_manager_add_tag (table, tag);
893 tag = theme_manager_init_tag_by_name (table, "fancy-link");
895 "foreground", "#49789e",
896 "underline", PANGO_UNDERLINE_SINGLE,
898 theme_manager_add_tag (table, tag);
902 theme_manager_apply_theme (EmpathyThemeManager *manager,
903 EmpathyChatView *view,
906 EmpathyThemeManagerPriv *priv;
909 priv = GET_PRIV (manager);
911 /* Make sure all tags are present. Note: not useful now but when we have
912 * user defined theme it will be.
914 theme_manager_fixup_tag_table (manager, view);
916 if (theme_manager_ensure_theme_exists (name)) {
917 if (strcmp (name, "clean") == 0) {
918 theme_manager_apply_theme_clean (manager, view);
921 else if (strcmp (name, "simple") == 0) {
922 theme_manager_apply_theme_simple (manager, view);
925 else if (strcmp (name, "blue") == 0) {
926 theme_manager_apply_theme_blue (manager, view);
929 theme_manager_apply_theme_classic (manager, view);
933 theme_manager_apply_theme_classic (manager, view);
937 empathy_chat_view_set_margin (view, margin);
938 empathy_chat_view_set_irc_style (view, priv->irc_style);
941 EmpathyThemeManager *
942 empathy_theme_manager_get (void)
944 static EmpathyThemeManager *manager = NULL;
947 manager = g_object_new (EMPATHY_TYPE_THEME_MANAGER, NULL);
954 empathy_theme_manager_get_themes (void)
960 empathy_theme_manager_apply (EmpathyThemeManager *manager,
961 EmpathyChatView *view,
964 EmpathyThemeManagerPriv *priv;
966 priv = GET_PRIV (manager);
968 theme_manager_apply_theme (manager, view, name);
972 empathy_theme_manager_apply_saved (EmpathyThemeManager *manager,
973 EmpathyChatView *view)
975 EmpathyThemeManagerPriv *priv;
977 priv = GET_PRIV (manager);
979 theme_manager_apply_theme (manager, view, priv->name);
982 /* FIXME: A bit ugly. We should probably change the scheme so that instead of
983 * the manager signalling, views are registered and applied to automatically.
986 empathy_theme_manager_update_show_avatars (EmpathyThemeManager *manager,
987 EmpathyChatView *view,
990 EmpathyThemeManagerPriv *priv;
991 GtkTextBuffer *buffer;
992 GtkTextTagTable *table;
993 GtkTextTag *tag_text_self, *tag_text_other;
994 GtkTextTag *tag_image_self, *tag_image_other;
996 priv = GET_PRIV (manager);
998 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
999 table = gtk_text_buffer_get_tag_table (buffer);
1001 tag_text_self = gtk_text_tag_table_lookup (table, "fancy-header-self-avatar");
1002 tag_text_other = gtk_text_tag_table_lookup (table, "fancy-header-other-avatar");
1004 tag_image_self = gtk_text_tag_table_lookup (table, "fancy-avatar-self");
1005 tag_image_other = gtk_text_tag_table_lookup (table, "fancy-avatar-other");
1008 g_object_set (tag_text_self,
1011 g_object_set (tag_text_other,
1014 g_object_set (tag_image_self,
1017 g_object_set (tag_image_other,
1021 GtkTextAttributes *attrs;
1025 attrs = gtk_text_view_get_default_attributes (GTK_TEXT_VIEW (view));
1026 size = pango_font_description_get_size (attrs->font);
1027 rise = MAX (0, (32 * PANGO_SCALE - size) / 2.0);
1029 g_object_set (tag_text_self,
1032 g_object_set (tag_text_other,
1035 g_object_set (tag_image_self,
1038 g_object_set (tag_image_other,
1042 gtk_text_attributes_unref (attrs);