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.
25 #include <glib/gi18n.h>
28 #include <libempathy/empathy-utils.h>
30 #include "empathy-chat-view.h"
31 #include "empathy-conf.h"
32 #include "empathy-theme.h"
33 #include "empathy-theme-boxes.h"
34 #include "empathy-theme-irc.h"
35 #include "empathy-theme-manager.h"
37 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_THEME_MANAGER, EmpathyThemeManagerPriv))
43 gboolean show_avatars;
44 guint show_avatars_notify_id;
46 EmpathyTheme *clean_theme;
47 EmpathyTheme *simple_theme;
48 EmpathyTheme *blue_theme;
49 EmpathyTheme *classic_theme;
51 GtkSettings *settings;
52 } EmpathyThemeManagerPriv;
54 static void theme_manager_finalize (GObject *object);
55 static void theme_manager_notify_name_cb (EmpathyConf *conf,
59 static void theme_manager_notify_show_avatars_cb (EmpathyConf *conf,
62 static void theme_manager_apply_theme (EmpathyThemeManager *manager,
63 EmpathyChatView *view,
71 static guint signals[LAST_SIGNAL] = { 0 };
73 static const gchar *themes[] = {
74 "classic", N_("Classic"),
75 "simple", N_("Simple"),
81 G_DEFINE_TYPE (EmpathyThemeManager, empathy_theme_manager, G_TYPE_OBJECT);
84 theme_manager_gdk_color_to_hex (GdkColor *gdk_color, gchar *str_color)
86 g_snprintf (str_color, 10,
89 gdk_color->green >> 8,
90 gdk_color->blue >> 8);
94 theme_manager_color_hash_notify_cb (EmpathyThemeManager *manager)
96 EmpathyThemeManagerPriv *priv;
100 priv = GET_PRIV (manager);
102 style = gtk_widget_get_default_style ();
104 g_object_freeze_notify (G_OBJECT (priv->simple_theme));
106 theme_manager_gdk_color_to_hex (&style->base[GTK_STATE_SELECTED], color);
107 g_object_set (priv->simple_theme,
108 "action-foreground", color,
109 "link-foreground", color,
112 theme_manager_gdk_color_to_hex (&style->bg[GTK_STATE_SELECTED], color);
113 g_object_set (priv->simple_theme,
114 "header-background", color,
117 theme_manager_gdk_color_to_hex (&style->dark[GTK_STATE_SELECTED], color);
118 g_object_set (priv->simple_theme,
119 "header-line-background", color,
122 theme_manager_gdk_color_to_hex (&style->fg[GTK_STATE_SELECTED], color);
123 g_object_set (priv->simple_theme,
124 "header-foreground", color,
127 g_object_thaw_notify (G_OBJECT (priv->simple_theme));
131 FIXME: Make that work, it should update color when theme changes but it
132 doesnt seems to work with all themes.
134 g_object_get (priv->settings,
135 "color-hash", &color_hash,
139 * base_color: #ffffffffffff
140 * fg_color: #000000000000
141 * bg_color: #e6e6e7e7e8e8
142 * text_color: #000000000000
143 * selected_bg_color: #58589a9adbdb
144 * selected_fg_color: #ffffffffffff
147 color = g_hash_table_lookup (color_hash, "base_color");
149 theme_manager_gdk_color_to_hex (color, color_str);
150 g_object_set (priv->simple_theme,
151 "action-foreground", color_str,
152 "link-foreground", color_str,
156 color = g_hash_table_lookup (color_hash, "selected_bg_color");
158 theme_manager_gdk_color_to_hex (color, color_str);
159 g_object_set (priv->simple_theme,
160 "header-background", color_str,
164 color = g_hash_table_lookup (color_hash, "bg_color");
172 theme_manager_gdk_color_to_hex (&tmp, color_str);
173 g_object_set (priv->simple_theme,
174 "header-line-background", color_str,
178 color = g_hash_table_lookup (color_hash, "selected_fg_color");
180 theme_manager_gdk_color_to_hex (color, color_str);
181 g_object_set (priv->simple_theme,
182 "header-foreground", color_str,
186 g_hash_table_unref (color_hash);
192 empathy_theme_manager_class_init (EmpathyThemeManagerClass *klass)
194 GObjectClass *object_class = G_OBJECT_CLASS (klass);
196 signals[THEME_CHANGED] =
197 g_signal_new ("theme-changed",
198 G_OBJECT_CLASS_TYPE (object_class),
202 g_cclosure_marshal_VOID__VOID,
206 g_type_class_add_private (object_class, sizeof (EmpathyThemeManagerPriv));
208 object_class->finalize = theme_manager_finalize;
212 empathy_theme_manager_init (EmpathyThemeManager *manager)
214 EmpathyThemeManagerPriv *priv;
216 priv = GET_PRIV (manager);
218 priv->name_notify_id =
219 empathy_conf_notify_add (empathy_conf_get (),
220 EMPATHY_PREFS_CHAT_THEME,
221 theme_manager_notify_name_cb,
224 empathy_conf_get_string (empathy_conf_get (),
225 EMPATHY_PREFS_CHAT_THEME,
228 /* Unused right now, but will be used soon. */
229 priv->show_avatars_notify_id =
230 empathy_conf_notify_add (empathy_conf_get (),
231 EMPATHY_PREFS_UI_SHOW_AVATARS,
232 theme_manager_notify_show_avatars_cb,
235 empathy_conf_get_bool (empathy_conf_get (),
236 EMPATHY_PREFS_UI_SHOW_AVATARS,
237 &priv->show_avatars);
239 priv->settings = gtk_settings_get_default ();
240 g_signal_connect_swapped (priv->settings, "notify::color-hash",
241 G_CALLBACK (theme_manager_color_hash_notify_cb),
244 priv->simple_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES, NULL);
245 theme_manager_color_hash_notify_cb (manager);
247 priv->clean_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES,
248 "header-foreground", "black",
249 "header-background", "#efefdf",
250 "header_line_background", "#e3e3d3",
251 "action_foreground", "brown4",
252 "time_foreground", "darkgrey",
253 "event_foreground", "darkgrey",
254 "invite_foreground", "sienna",
255 "link_foreground","#49789e",
258 priv->blue_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES,
259 "header_foreground", "black",
260 "header_background", "#88a2b4",
261 "header_line_background", "#7f96a4",
262 "text_foreground", "black",
263 "text_background", "#adbdc8",
264 "highlight_foreground", "black",
265 "action_foreground", "brown4",
266 "time_foreground", "darkgrey",
267 "event_foreground", "#7f96a4",
268 "invite_foreground", "sienna",
269 "link_foreground", "#49789e",
272 priv->classic_theme = g_object_new (EMPATHY_TYPE_THEME_IRC, NULL);
276 theme_manager_finalize (GObject *object)
278 EmpathyThemeManagerPriv *priv;
280 priv = GET_PRIV (object);
282 empathy_conf_notify_remove (empathy_conf_get (), priv->name_notify_id);
283 empathy_conf_notify_remove (empathy_conf_get (), priv->show_avatars_notify_id);
287 g_object_unref (priv->clean_theme);
288 g_object_unref (priv->simple_theme);
289 g_object_unref (priv->blue_theme);
290 g_object_unref (priv->classic_theme);
292 G_OBJECT_CLASS (empathy_theme_manager_parent_class)->finalize (object);
296 theme_manager_notify_name_cb (EmpathyConf *conf,
300 EmpathyThemeManager *manager;
301 EmpathyThemeManagerPriv *priv;
305 priv = GET_PRIV (manager);
310 if (!empathy_conf_get_string (conf, key, &name) ||
311 name == NULL || name[0] == 0) {
312 priv->name = g_strdup ("classic");
318 g_signal_emit (manager, signals[THEME_CHANGED], 0, NULL);
322 theme_manager_notify_show_avatars_cb (EmpathyConf *conf,
326 EmpathyThemeManager *manager;
327 EmpathyThemeManagerPriv *priv;
331 priv = GET_PRIV (manager);
333 if (!empathy_conf_get_bool (conf, key, &value)) {
334 priv->show_avatars = FALSE;
336 priv->show_avatars = value;
341 theme_manager_ensure_theme_exists (const gchar *name)
345 if (G_STR_EMPTY (name)) {
349 for (i = 0; themes[i]; i += 2) {
350 if (strcmp (themes[i], name) == 0) {
359 theme_manager_apply_theme (EmpathyThemeManager *manager,
360 EmpathyChatView *view,
363 EmpathyThemeManagerPriv *priv;
366 priv = GET_PRIV (manager);
368 /* Make sure all tags are present. Note: not useful now but when we have
369 * user defined theme it will be.
371 if (theme_manager_ensure_theme_exists (name)) {
372 if (strcmp (name, "clean") == 0) {
373 theme = priv->clean_theme;
375 else if (strcmp (name, "simple") == 0) {
376 theme = priv->simple_theme;
378 else if (strcmp (name, "blue") == 0) {
379 theme = priv->blue_theme;
381 theme = priv->classic_theme;
384 theme = priv->classic_theme;
387 empathy_chat_view_set_theme (view, theme);
390 EmpathyThemeManager *
391 empathy_theme_manager_get (void)
393 static EmpathyThemeManager *manager = NULL;
396 manager = g_object_new (EMPATHY_TYPE_THEME_MANAGER, NULL);
403 empathy_theme_manager_get_themes (void)
409 empathy_theme_manager_apply (EmpathyThemeManager *manager,
410 EmpathyChatView *view,
413 EmpathyThemeManagerPriv *priv;
415 priv = GET_PRIV (manager);
417 theme_manager_apply_theme (manager, view, name);
421 empathy_theme_manager_apply_saved (EmpathyThemeManager *manager,
422 EmpathyChatView *view)
424 EmpathyThemeManagerPriv *priv;
426 priv = GET_PRIV (manager);
428 theme_manager_apply_theme (manager, view, priv->name);