aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-theme-manager.c
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2008-12-16 17:24:35 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2008-12-16 17:24:35 +0800
commit109f46a8278fc797ba526f69f44335063903066c (patch)
treee65ec3672e6c2df4ede307296d81adf348c7e560 /libempathy-gtk/empathy-theme-manager.c
parent031e66bd2b0b63a6d33d3242e24392e2109a82e2 (diff)
downloadgsoc2013-empathy-109f46a8278fc797ba526f69f44335063903066c.tar
gsoc2013-empathy-109f46a8278fc797ba526f69f44335063903066c.tar.gz
gsoc2013-empathy-109f46a8278fc797ba526f69f44335063903066c.tar.bz2
gsoc2013-empathy-109f46a8278fc797ba526f69f44335063903066c.tar.lz
gsoc2013-empathy-109f46a8278fc797ba526f69f44335063903066c.tar.xz
gsoc2013-empathy-109f46a8278fc797ba526f69f44335063903066c.tar.zst
gsoc2013-empathy-109f46a8278fc797ba526f69f44335063903066c.zip
Completely rework the theming system to make easy implementing themes based on other classes like webkit.
svn path=/trunk/; revision=1993
Diffstat (limited to 'libempathy-gtk/empathy-theme-manager.c')
-rw-r--r--libempathy-gtk/empathy-theme-manager.c543
1 files changed, 345 insertions, 198 deletions
diff --git a/libempathy-gtk/empathy-theme-manager.c b/libempathy-gtk/empathy-theme-manager.c
index 98694af2d..e053bd45a 100644
--- a/libempathy-gtk/empathy-theme-manager.c
+++ b/libempathy-gtk/empathy-theme-manager.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2005-2007 Imendio AB
+ * Copyright (C) 2008 Collabora Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -16,6 +17,8 @@
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
+ *
+ * Authors: Xavier Claessens <xclaesse@gmail.com>
*/
#include "config.h"
@@ -27,41 +30,23 @@
#include <libempathy/empathy-utils.h>
+#include "empathy-theme-manager.h"
#include "empathy-chat-view.h"
#include "empathy-conf.h"
-#include "empathy-theme.h"
+#include "empathy-chat-text-view.h"
#include "empathy-theme-boxes.h"
#include "empathy-theme-irc.h"
-#include "empathy-theme-manager.h"
+
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include <libempathy/empathy-debug.h>
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeManager)
typedef struct {
gchar *name;
guint name_notify_id;
-
- gboolean show_avatars;
- guint show_avatars_notify_id;
-
- EmpathyTheme *clean_theme;
- EmpathyTheme *simple_theme;
- EmpathyTheme *blue_theme;
- EmpathyTheme *classic_theme;
-
- GtkSettings *settings;
+ GtkSettings *settings;
} EmpathyThemeManagerPriv;
-static void theme_manager_finalize (GObject *object);
-static void theme_manager_notify_name_cb (EmpathyConf *conf,
- const gchar *key,
- gpointer user_data);
-
-static void theme_manager_notify_show_avatars_cb (EmpathyConf *conf,
- const gchar *key,
- gpointer user_data);
-static void theme_manager_apply_theme (EmpathyThemeManager *manager,
- EmpathyChatView *view,
- const gchar *name);
-
enum {
THEME_CHANGED,
LAST_SIGNAL
@@ -78,7 +63,7 @@ static const gchar *themes[] = {
};
G_DEFINE_TYPE (EmpathyThemeManager, empathy_theme_manager, G_TYPE_OBJECT);
-
+/*
static void
theme_manager_gdk_color_to_hex (GdkColor *gdk_color, gchar *str_color)
{
@@ -88,10 +73,15 @@ theme_manager_gdk_color_to_hex (GdkColor *gdk_color, gchar *str_color)
gdk_color->green >> 8,
gdk_color->blue >> 8);
}
-
- static void
+*/
+static void
theme_manager_color_hash_notify_cb (EmpathyThemeManager *manager)
{
+#if 0
+
+FIXME: Make that work, it should update color when theme changes but it
+ doesnt seems to work with all themes.
+
EmpathyThemeManagerPriv *priv;
GtkStyle *style;
gchar color[10];
@@ -100,8 +90,6 @@ theme_manager_color_hash_notify_cb (EmpathyThemeManager *manager)
style = gtk_widget_get_default_style ();
- g_object_freeze_notify (G_OBJECT (priv->simple_theme));
-
theme_manager_gdk_color_to_hex (&style->base[GTK_STATE_SELECTED], color);
g_object_set (priv->simple_theme,
"action-foreground", color,
@@ -122,14 +110,9 @@ theme_manager_color_hash_notify_cb (EmpathyThemeManager *manager)
g_object_set (priv->simple_theme,
"header-foreground", color,
NULL);
-
- g_object_thaw_notify (G_OBJECT (priv->simple_theme));
-
-#if 0
-
-FIXME: Make that work, it should update color when theme changes but it
- doesnt seems to work with all themes.
+--------
+
g_object_get (priv->settings,
"color-hash", &color_hash,
NULL);
@@ -187,6 +170,58 @@ FIXME: Make that work, it should update color when theme changes but it
#endif
}
+static gboolean
+theme_manager_ensure_theme_exists (const gchar *name)
+{
+ gint i;
+
+ if (G_STR_EMPTY (name)) {
+ return FALSE;
+ }
+
+ for (i = 0; themes[i]; i += 2) {
+ if (strcmp (themes[i], name) == 0) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static void
+theme_manager_notify_name_cb (EmpathyConf *conf,
+ const gchar *key,
+ gpointer user_data)
+{
+ EmpathyThemeManager *manager = EMPATHY_THEME_MANAGER (user_data);
+ EmpathyThemeManagerPriv *priv = GET_PRIV (manager);
+ gchar *name;
+
+ g_free (priv->name);
+
+ name = NULL;
+ if (!empathy_conf_get_string (conf, key, &name) ||
+ !theme_manager_ensure_theme_exists (name)) {
+ priv->name = g_strdup ("classic");
+ g_free (name);
+ } else {
+ priv->name = name;
+ }
+
+ g_signal_emit (manager, signals[THEME_CHANGED], 0, NULL);
+}
+
+static void
+theme_manager_finalize (GObject *object)
+{
+ EmpathyThemeManagerPriv *priv = GET_PRIV (object);
+
+ empathy_conf_notify_remove (empathy_conf_get (), priv->name_notify_id);
+ g_free (priv->name);
+
+ G_OBJECT_CLASS (empathy_theme_manager_parent_class)->finalize (object);
+}
+
static void
empathy_theme_manager_class_init (EmpathyThemeManagerClass *klass)
{
@@ -214,176 +249,193 @@ empathy_theme_manager_init (EmpathyThemeManager *manager)
EMPATHY_TYPE_THEME_MANAGER, EmpathyThemeManagerPriv);
manager->priv = priv;
- priv->name_notify_id =
- empathy_conf_notify_add (empathy_conf_get (),
- EMPATHY_PREFS_CHAT_THEME,
- theme_manager_notify_name_cb,
- manager);
-
- empathy_conf_get_string (empathy_conf_get (),
- EMPATHY_PREFS_CHAT_THEME,
- &priv->name);
- /* Unused right now, but will be used soon. */
- priv->show_avatars_notify_id =
+ /* Take the theme name and track changes */
+ priv->name_notify_id =
empathy_conf_notify_add (empathy_conf_get (),
- EMPATHY_PREFS_UI_SHOW_AVATARS,
- theme_manager_notify_show_avatars_cb,
- manager);
-
- empathy_conf_get_bool (empathy_conf_get (),
- EMPATHY_PREFS_UI_SHOW_AVATARS,
- &priv->show_avatars);
-
+ EMPATHY_PREFS_CHAT_THEME,
+ theme_manager_notify_name_cb,
+ manager);
+ theme_manager_notify_name_cb (empathy_conf_get (),
+ EMPATHY_PREFS_CHAT_THEME,
+ manager);
+
+ /* Track GTK color changes */
priv->settings = gtk_settings_get_default ();
g_signal_connect_swapped (priv->settings, "notify::color-hash",
G_CALLBACK (theme_manager_color_hash_notify_cb),
manager);
-
- priv->simple_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES, NULL);
- theme_manager_color_hash_notify_cb (manager);
-
- priv->clean_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES,
- "header-foreground", "black",
- "header-background", "#efefdf",
- "header_line_background", "#e3e3d3",
- "action_foreground", "brown4",
- "time_foreground", "darkgrey",
- "event_foreground", "darkgrey",
- "invite_foreground", "sienna",
- "link_foreground","#49789e",
- NULL);
-
- priv->blue_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES,
- "header_foreground", "black",
- "header_background", "#88a2b4",
- "header_line_background", "#7f96a4",
- "text_foreground", "black",
- "text_background", "#adbdc8",
- "highlight_foreground", "black",
- "action_foreground", "brown4",
- "time_foreground", "darkgrey",
- "event_foreground", "#7f96a4",
- "invite_foreground", "sienna",
- "link_foreground", "#49789e",
- NULL);
-
- priv->classic_theme = g_object_new (EMPATHY_TYPE_THEME_IRC, NULL);
}
-static void
-theme_manager_finalize (GObject *object)
+static EmpathyChatView *
+theme_manager_create_irc_view (EmpathyThemeManager *manager)
{
- EmpathyThemeManagerPriv *priv;
-
- priv = GET_PRIV (object);
-
- empathy_conf_notify_remove (empathy_conf_get (), priv->name_notify_id);
- empathy_conf_notify_remove (empathy_conf_get (), priv->show_avatars_notify_id);
-
- g_free (priv->name);
-
- g_object_unref (priv->clean_theme);
- g_object_unref (priv->simple_theme);
- g_object_unref (priv->blue_theme);
- g_object_unref (priv->classic_theme);
-
- G_OBJECT_CLASS (empathy_theme_manager_parent_class)->finalize (object);
+ EmpathyChatTextView *view;
+
+ view = EMPATHY_CHAT_TEXT_VIEW (empathy_theme_irc_new ());
+
+ /* Define base tags */
+ /* FIXME: Missing define for highlight */
+ empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_SPACING,
+ "size", 2000,
+ NULL);
+ empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_TIME,
+ "foreground", "darkgrey",
+ "justification", GTK_JUSTIFY_CENTER,
+ NULL);
+ empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_ACTION,
+ "foreground", "brown4",
+ "style", PANGO_STYLE_ITALIC,
+ NULL);
+ empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_BODY,
+ "foreground-set", FALSE,
+ NULL);
+ empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_EVENT,
+ "foreground", "PeachPuff4",
+ "justification", GTK_JUSTIFY_LEFT,
+ NULL);
+ empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_LINK,
+ "foreground", "steelblue",
+ "underline", PANGO_UNDERLINE_SINGLE,
+ NULL);
+
+ /* Define IRC tags */
+ empathy_chat_text_view_tag_set (view, EMPATHY_THEME_IRC_TAG_NICK_SELF,
+ "foreground", "sea green",
+ NULL);
+ empathy_chat_text_view_tag_set (view, EMPATHY_THEME_IRC_TAG_NICK_OTHER,
+ "foreground", "skyblue4",
+ NULL);
+ empathy_chat_text_view_tag_set (view, EMPATHY_THEME_IRC_TAG_NICK_HIGHLIGHT,
+ "foreground", "indian red",
+ "weight", PANGO_WEIGHT_BOLD,
+ NULL);
+
+ return EMPATHY_CHAT_VIEW (view);
}
-static void
-theme_manager_notify_name_cb (EmpathyConf *conf,
- const gchar *key,
- gpointer user_data)
-{
- EmpathyThemeManager *manager;
- EmpathyThemeManagerPriv *priv;
- gchar *name;
+static EmpathyChatView *
+theme_manager_create_boxes_view (EmpathyThemeManager *manager,
+ const gchar *header_foreground,
+ const gchar *header_background,
+ const gchar *header_line_background,
+ const gchar *action_foreground,
+ const gchar *time_foreground,
+ const gchar *event_foreground,
+ const gchar *link_foreground,
+ const gchar *text_foreground,
+ const gchar *text_background,
+ const gchar *highlight_foreground)
- manager = user_data;
- priv = GET_PRIV (manager);
+{
+ EmpathyChatTextView *view;
+ GtkTextTag *tag;
- g_free (priv->name);
+ view = EMPATHY_CHAT_TEXT_VIEW (empathy_theme_boxes_new ());
- name = NULL;
- if (!empathy_conf_get_string (conf, key, &name) ||
- name == NULL || name[0] == 0) {
- priv->name = g_strdup ("classic");
- g_free (name);
- } else {
- priv->name = name;
- }
+ #define TAG_SET(prop, value) \
+ if (value != NULL) { \
+ g_object_set (tag, prop, value, NULL); \
+ }
- g_signal_emit (manager, signals[THEME_CHANGED], 0, NULL);
+ /* Define base tags */
+ tag = empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_HIGHLIGHT,
+ "weight", PANGO_WEIGHT_BOLD,
+ "pixels-above-lines", 4,
+ NULL);
+ TAG_SET ("paragraph-background", text_background);
+ TAG_SET ("foreground", highlight_foreground);
+
+ empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_SPACING,
+ "size", 3000,
+ "pixels-above-lines", 8,
+ NULL);
+ tag = empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_TIME,
+ "justification", GTK_JUSTIFY_CENTER,
+ NULL);
+ TAG_SET ("foreground", time_foreground);
+ tag = empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_ACTION,
+ "style", PANGO_STYLE_ITALIC,
+ "pixels-above-lines", 4,
+ NULL);
+ TAG_SET ("paragraph-background", text_background);
+ TAG_SET ("foreground", action_foreground);
+ tag = empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_BODY,
+ "pixels-above-lines", 4,
+ NULL);
+ TAG_SET ("paragraph-background", text_background);
+ TAG_SET ("foreground", text_foreground);
+ tag = empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_EVENT,
+ "justification", GTK_JUSTIFY_LEFT,
+ NULL);
+ TAG_SET ("foreground", event_foreground);
+ tag = empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_LINK,
+ "underline", PANGO_UNDERLINE_SINGLE,
+ NULL);
+ TAG_SET ("foreground", link_foreground);
+
+ /* Define BOXES tags */
+ tag = empathy_chat_text_view_tag_set (view, EMPATHY_THEME_BOXES_TAG_HEADER,
+ "weight", PANGO_WEIGHT_BOLD,
+ "foreground", header_foreground,
+ "paragraph-background", header_background,
+ NULL);
+ TAG_SET ("foreground", header_foreground);
+ TAG_SET ("paragraph-background", header_background);
+ tag = empathy_chat_text_view_tag_set (view, EMPATHY_THEME_BOXES_TAG_HEADER_LINE,
+ "size", 1,
+ "paragraph-background", header_line_background,
+ NULL);
+ TAG_SET ("paragraph-background", header_line_background);
+
+ #undef TAG_SET
+
+ return EMPATHY_CHAT_VIEW (view);
}
-static void
-theme_manager_notify_show_avatars_cb (EmpathyConf *conf,
- const gchar *key,
- gpointer user_data)
+EmpathyChatView *
+empathy_theme_manager_create_view (EmpathyThemeManager *manager)
{
- EmpathyThemeManager *manager;
- EmpathyThemeManagerPriv *priv;
- gboolean value;
-
- manager = user_data;
- priv = GET_PRIV (manager);
+ EmpathyThemeManagerPriv *priv = GET_PRIV (manager);
- if (!empathy_conf_get_bool (conf, key, &value)) {
- priv->show_avatars = FALSE;
- } else {
- priv->show_avatars = value;
- }
-}
+ g_return_val_if_fail (EMPATHY_IS_THEME_MANAGER (manager), NULL);
-static gboolean
-theme_manager_ensure_theme_exists (const gchar *name)
-{
- gint i;
+ DEBUG ("Using theme %s", priv->name);
- if (G_STR_EMPTY (name)) {
- return FALSE;
+ if (strcmp (priv->name, "classic") == 0) {
+ return theme_manager_create_irc_view (manager);
}
-
- for (i = 0; themes[i]; i += 2) {
- if (strcmp (themes[i], name) == 0) {
- return TRUE;
- }
+ else if (strcmp (priv->name, "simple") == 0) {
+ return theme_manager_create_irc_view (manager);
}
-
- return FALSE;
-}
-
-static void
-theme_manager_apply_theme (EmpathyThemeManager *manager,
- EmpathyChatView *view,
- const gchar *name)
-{
- EmpathyThemeManagerPriv *priv;
- EmpathyTheme *theme;
-
- priv = GET_PRIV (manager);
-
- /* Make sure all tags are present. Note: not useful now but when we have
- * user defined theme it will be.
- */
- if (theme_manager_ensure_theme_exists (name)) {
- if (strcmp (name, "clean") == 0) {
- theme = priv->clean_theme;
- }
- else if (strcmp (name, "simple") == 0) {
- theme = priv->simple_theme;
- }
- else if (strcmp (name, "blue") == 0) {
- theme = priv->blue_theme;
- } else {
- theme = priv->classic_theme;
- }
- } else {
- theme = priv->classic_theme;
+ else if (strcmp (priv->name, "clean") == 0) {
+ return theme_manager_create_boxes_view (manager,
+ "black", /* header_foreground */
+ "#efefdf", /* header_background */
+ "#e3e3d3", /* header_line_background */
+ "brown4", /* action_foreground */
+ "darkgrey", /* time_foreground */
+ "darkgrey", /* event_foreground */
+ "#49789e", /* link_foreground */
+ NULL, /* text_foreground */
+ NULL, /* text_background */
+ NULL); /* highlight_foreground */
+ }
+ else if (strcmp (priv->name, "blue") == 0) {
+ return theme_manager_create_boxes_view (manager,
+ "black", /* header_foreground */
+ "#88a2b4", /* header_background */
+ "#7f96a4", /* header_line_background */
+ "brown4", /* action_foreground */
+ "darkgrey", /* time_foreground */
+ "#7f96a4", /* event_foreground */
+ "#49789e", /* link_foreground */
+ "black", /* text_foreground */
+ "#adbdc8", /* text_background */
+ "black"); /* highlight_foreground */
}
- empathy_chat_view_set_theme (view, theme);
+ return NULL;
}
EmpathyThemeManager *
@@ -404,26 +456,121 @@ empathy_theme_manager_get_themes (void)
return themes;
}
-void
-empathy_theme_manager_apply (EmpathyThemeManager *manager,
- EmpathyChatView *view,
- const gchar *name)
-{
- EmpathyThemeManagerPriv *priv;
- priv = GET_PRIV (manager);
+#if 0
+// theme boxes
+ empathy_text_buffer_tag_set (buffer, "fancy-spacing",
+ "size", 3000,
+ "pixels-above-lines", 8,
+ NULL);
+
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-header",
+ "weight", PANGO_WEIGHT_BOLD,
+ "pixels-above-lines", HEADER_PADDING,
+ "pixels-below-lines", HEADER_PADDING,
+ NULL);
+ if (priv->header_foreground) {
+ g_object_set (tag,
+ "foreground", priv->header_foreground,
+ "paragraph-background", priv->header_background,
+ NULL);
+ }
- theme_manager_apply_theme (manager, view, name);
-}
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-header-line",
+ "size", 1,
+ NULL);
+ if (priv->header_line_background) {
+ g_object_set (tag,
+ "paragraph-background", priv->header_line_background,
+ NULL);
+ }
-void
-empathy_theme_manager_apply_saved (EmpathyThemeManager *manager,
- EmpathyChatView *view)
-{
- EmpathyThemeManagerPriv *priv;
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-body",
+ "pixels-above-lines", 4,
+ NULL);
+ if (priv->text_background) {
+ g_object_set (tag,
+ "paragraph-background", priv->text_background,
+ NULL);
+ }
- priv = GET_PRIV (manager);
+ if (priv->text_foreground) {
+ g_object_set (tag,
+ "foreground", priv->text_foreground,
+ NULL);
+ }
- theme_manager_apply_theme (manager, view, priv->name);
-}
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-action",
+ "style", PANGO_STYLE_ITALIC,
+ "pixels-above-lines", 4,
+ NULL);
+
+ if (priv->text_background) {
+ g_object_set (tag,
+ "paragraph-background", priv->text_background,
+ NULL);
+ }
+
+ if (priv->action_foreground) {
+ g_object_set (tag,
+ "foreground", priv->action_foreground,
+ NULL);
+ }
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-highlight",
+ "weight", PANGO_WEIGHT_BOLD,
+ "pixels-above-lines", 4,
+ NULL);
+ if (priv->text_background) {
+ g_object_set (tag,
+ "paragraph-background", priv->text_background,
+ NULL);
+ }
+
+
+ if (priv->highlight_foreground) {
+ g_object_set (tag,
+ "foreground", priv->highlight_foreground,
+ NULL);
+ }
+
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-time",
+ "justification", GTK_JUSTIFY_CENTER,
+ NULL);
+ if (priv->time_foreground) {
+ g_object_set (tag,
+ "foreground", priv->time_foreground,
+ NULL);
+ }
+
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-event",
+ "justification", GTK_JUSTIFY_LEFT,
+ NULL);
+ if (priv->event_foreground) {
+ g_object_set (tag,
+ "foreground", priv->event_foreground,
+ NULL);
+ }
+
+ tag = empathy_text_buffer_tag_set (buffer, "invite", NULL);
+ if (priv->invite_foreground) {
+ g_object_set (tag,
+ "foreground", priv->invite_foreground,
+ NULL);
+ }
+
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-link",
+ "underline", PANGO_UNDERLINE_SINGLE,
+ NULL);
+ if (priv->link_foreground) {
+ g_object_set (tag,
+ "foreground", priv->link_foreground,
+ NULL);
+ }
+ empathy_chat_view_set_margin (view, MARGIN);
+
+
+
+ priv->simple_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES, NULL);
+ theme_manager_color_hash_notify_cb (manager);
+#endif