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))
44 gboolean show_avatars;
45 guint show_avatars_notify_id;
47 EmpathyTheme *clean_theme;
48 EmpathyTheme *simple_theme;
49 EmpathyTheme *blue_theme;
50 EmpathyTheme *classic_theme;
52 GtkSettings *settings;
53 } EmpathyThemeManagerPriv;
55 static void theme_manager_finalize (GObject *object);
56 static void theme_manager_notify_name_cb (EmpathyConf *conf,
59 static void theme_manager_notify_room_cb (EmpathyConf *conf,
62 static void theme_manager_notify_show_avatars_cb (EmpathyConf *conf,
65 static void theme_manager_apply_theme (EmpathyThemeManager *manager,
66 EmpathyChatView *view,
74 static guint signals[LAST_SIGNAL] = { 0 };
76 static const gchar *themes[] = {
77 "classic", N_("Classic"),
78 "simple", N_("Simple"),
84 G_DEFINE_TYPE (EmpathyThemeManager, empathy_theme_manager, G_TYPE_OBJECT);
87 theme_manager_gdk_color_to_hex (GdkColor *gdk_color, gchar *str_color)
89 g_snprintf (str_color, 10,
92 gdk_color->green >> 8,
93 gdk_color->blue >> 8);
97 theme_manager_color_hash_notify_cb (EmpathyThemeManager *manager)
99 EmpathyThemeManagerPriv *priv;
103 priv = GET_PRIV (manager);
105 style = gtk_widget_get_default_style ();
107 g_object_freeze_notify (G_OBJECT (priv->simple_theme));
109 theme_manager_gdk_color_to_hex (&style->base[GTK_STATE_SELECTED], color);
110 g_object_set (priv->simple_theme,
111 "action-foreground", color,
112 "link-foreground", color,
115 theme_manager_gdk_color_to_hex (&style->bg[GTK_STATE_SELECTED], color);
116 g_object_set (priv->simple_theme,
117 "header-background", color,
120 theme_manager_gdk_color_to_hex (&style->dark[GTK_STATE_SELECTED], color);
121 g_object_set (priv->simple_theme,
122 "header-line-background", color,
125 theme_manager_gdk_color_to_hex (&style->fg[GTK_STATE_SELECTED], color);
126 g_object_set (priv->simple_theme,
127 "header-foreground", color,
130 g_object_thaw_notify (G_OBJECT (priv->simple_theme));
134 FIXME: Make that work, it should update color when theme changes but it
135 doesnt seems to work with all themes.
137 g_object_get (priv->settings,
138 "color-hash", &color_hash,
142 * base_color: #ffffffffffff
143 * fg_color: #000000000000
144 * bg_color: #e6e6e7e7e8e8
145 * text_color: #000000000000
146 * selected_bg_color: #58589a9adbdb
147 * selected_fg_color: #ffffffffffff
150 color = g_hash_table_lookup (color_hash, "base_color");
152 theme_manager_gdk_color_to_hex (color, color_str);
153 g_object_set (priv->simple_theme,
154 "action-foreground", color_str,
155 "link-foreground", color_str,
159 color = g_hash_table_lookup (color_hash, "selected_bg_color");
161 theme_manager_gdk_color_to_hex (color, color_str);
162 g_object_set (priv->simple_theme,
163 "header-background", color_str,
167 color = g_hash_table_lookup (color_hash, "bg_color");
175 theme_manager_gdk_color_to_hex (&tmp, color_str);
176 g_object_set (priv->simple_theme,
177 "header-line-background", color_str,
181 color = g_hash_table_lookup (color_hash, "selected_fg_color");
183 theme_manager_gdk_color_to_hex (color, color_str);
184 g_object_set (priv->simple_theme,
185 "header-foreground", color_str,
189 g_hash_table_unref (color_hash);
195 empathy_theme_manager_class_init (EmpathyThemeManagerClass *klass)
197 GObjectClass *object_class = G_OBJECT_CLASS (klass);
199 signals[THEME_CHANGED] =
200 g_signal_new ("theme-changed",
201 G_OBJECT_CLASS_TYPE (object_class),
205 g_cclosure_marshal_VOID__VOID,
209 g_type_class_add_private (object_class, sizeof (EmpathyThemeManagerPriv));
211 object_class->finalize = theme_manager_finalize;
215 empathy_theme_manager_init (EmpathyThemeManager *manager)
217 EmpathyThemeManagerPriv *priv;
219 priv = GET_PRIV (manager);
221 priv->name_notify_id =
222 empathy_conf_notify_add (empathy_conf_get (),
223 EMPATHY_PREFS_CHAT_THEME,
224 theme_manager_notify_name_cb,
227 priv->room_notify_id =
228 empathy_conf_notify_add (empathy_conf_get (),
229 EMPATHY_PREFS_CHAT_THEME_CHAT_ROOM,
230 theme_manager_notify_room_cb,
233 empathy_conf_get_string (empathy_conf_get (),
234 EMPATHY_PREFS_CHAT_THEME,
237 /* Unused right now, but will be used soon. */
238 priv->show_avatars_notify_id =
239 empathy_conf_notify_add (empathy_conf_get (),
240 EMPATHY_PREFS_UI_SHOW_AVATARS,
241 theme_manager_notify_show_avatars_cb,
244 empathy_conf_get_bool (empathy_conf_get (),
245 EMPATHY_PREFS_UI_SHOW_AVATARS,
246 &priv->show_avatars);
248 priv->settings = gtk_settings_get_default ();
249 g_signal_connect_swapped (priv->settings, "notify::color-hash",
250 G_CALLBACK (theme_manager_color_hash_notify_cb),
253 priv->simple_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES, NULL);
254 theme_manager_color_hash_notify_cb (manager);
256 priv->clean_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES,
257 "header-foreground", "black",
258 "header-background", "#efefdf",
259 "header_line_background", "#e3e3d3",
260 "action_foreground", "brown4",
261 "time_foreground", "darkgrey",
262 "event_foreground", "darkgrey",
263 "invite_foreground", "sienna",
264 "link_foreground","#49789e",
267 priv->blue_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES,
268 "header_foreground", "black",
269 "header_background", "#88a2b4",
270 "header_line_background", "#7f96a4",
271 "text_foreground", "black",
272 "text_background", "#adbdc8",
273 "highlight_foreground", "black",
274 "action_foreground", "brown4",
275 "time_foreground", "darkgrey",
276 "event_foreground", "#7f96a4",
277 "invite_foreground", "sienna",
278 "link_foreground", "#49789e",
281 priv->classic_theme = g_object_new (EMPATHY_TYPE_THEME_IRC, NULL);
285 theme_manager_finalize (GObject *object)
287 EmpathyThemeManagerPriv *priv;
289 priv = GET_PRIV (object);
291 empathy_conf_notify_remove (empathy_conf_get (), priv->name_notify_id);
292 empathy_conf_notify_remove (empathy_conf_get (), priv->room_notify_id);
293 empathy_conf_notify_remove (empathy_conf_get (), priv->show_avatars_notify_id);
297 g_object_unref (priv->clean_theme);
298 g_object_unref (priv->simple_theme);
299 g_object_unref (priv->blue_theme);
300 g_object_unref (priv->classic_theme);
302 G_OBJECT_CLASS (empathy_theme_manager_parent_class)->finalize (object);
306 theme_manager_notify_name_cb (EmpathyConf *conf,
310 EmpathyThemeManager *manager;
311 EmpathyThemeManagerPriv *priv;
315 priv = GET_PRIV (manager);
320 if (!empathy_conf_get_string (conf, key, &name) ||
321 name == NULL || name[0] == 0) {
322 priv->name = g_strdup ("classic");
328 g_signal_emit (manager, signals[THEME_CHANGED], 0, NULL);
332 theme_manager_notify_room_cb (EmpathyConf *conf,
336 g_signal_emit (user_data, signals[THEME_CHANGED], 0, NULL);
340 theme_manager_notify_show_avatars_cb (EmpathyConf *conf,
344 EmpathyThemeManager *manager;
345 EmpathyThemeManagerPriv *priv;
349 priv = GET_PRIV (manager);
351 if (!empathy_conf_get_bool (conf, key, &value)) {
352 priv->show_avatars = FALSE;
354 priv->show_avatars = value;
359 theme_manager_ensure_theme_exists (const gchar *name)
363 if (G_STR_EMPTY (name)) {
367 for (i = 0; themes[i]; i += 2) {
368 if (strcmp (themes[i], name) == 0) {
377 theme_manager_apply_theme (EmpathyThemeManager *manager,
378 EmpathyChatView *view,
381 EmpathyThemeManagerPriv *priv;
384 priv = GET_PRIV (manager);
386 /* Make sure all tags are present. Note: not useful now but when we have
387 * user defined theme it will be.
389 if (theme_manager_ensure_theme_exists (name)) {
390 if (strcmp (name, "clean") == 0) {
391 theme = priv->clean_theme;
393 else if (strcmp (name, "simple") == 0) {
394 theme = priv->simple_theme;
396 else if (strcmp (name, "blue") == 0) {
397 theme = priv->blue_theme;
399 theme = priv->classic_theme;
402 theme = priv->classic_theme;
405 empathy_chat_view_set_theme (view, theme);
408 EmpathyThemeManager *
409 empathy_theme_manager_get (void)
411 static EmpathyThemeManager *manager = NULL;
414 manager = g_object_new (EMPATHY_TYPE_THEME_MANAGER, NULL);
421 empathy_theme_manager_get_themes (void)
427 empathy_theme_manager_apply (EmpathyThemeManager *manager,
428 EmpathyChatView *view,
431 EmpathyThemeManagerPriv *priv;
433 priv = GET_PRIV (manager);
435 theme_manager_apply_theme (manager, view, name);
439 empathy_theme_manager_apply_saved (EmpathyThemeManager *manager,
440 EmpathyChatView *view)
442 EmpathyThemeManagerPriv *priv;
444 priv = GET_PRIV (manager);
446 theme_manager_apply_theme (manager, view, priv->name);