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) EMPATHY_GET_PRIV (obj, EmpathyThemeManager)
42 gboolean show_avatars;
43 guint show_avatars_notify_id;
45 EmpathyTheme *clean_theme;
46 EmpathyTheme *simple_theme;
47 EmpathyTheme *blue_theme;
48 EmpathyTheme *classic_theme;
50 GtkSettings *settings;
51 } EmpathyThemeManagerPriv;
53 static void theme_manager_finalize (GObject *object);
54 static void theme_manager_notify_name_cb (EmpathyConf *conf,
58 static void theme_manager_notify_show_avatars_cb (EmpathyConf *conf,
61 static void theme_manager_apply_theme (EmpathyThemeManager *manager,
62 EmpathyChatView *view,
70 static guint signals[LAST_SIGNAL] = { 0 };
72 static const gchar *themes[] = {
73 "classic", N_("Classic"),
74 "simple", N_("Simple"),
80 G_DEFINE_TYPE (EmpathyThemeManager, empathy_theme_manager, G_TYPE_OBJECT);
83 theme_manager_gdk_color_to_hex (GdkColor *gdk_color, gchar *str_color)
85 g_snprintf (str_color, 10,
88 gdk_color->green >> 8,
89 gdk_color->blue >> 8);
93 theme_manager_color_hash_notify_cb (EmpathyThemeManager *manager)
95 EmpathyThemeManagerPriv *priv;
99 priv = GET_PRIV (manager);
101 style = gtk_widget_get_default_style ();
103 g_object_freeze_notify (G_OBJECT (priv->simple_theme));
105 theme_manager_gdk_color_to_hex (&style->base[GTK_STATE_SELECTED], color);
106 g_object_set (priv->simple_theme,
107 "action-foreground", color,
108 "link-foreground", color,
111 theme_manager_gdk_color_to_hex (&style->bg[GTK_STATE_SELECTED], color);
112 g_object_set (priv->simple_theme,
113 "header-background", color,
116 theme_manager_gdk_color_to_hex (&style->dark[GTK_STATE_SELECTED], color);
117 g_object_set (priv->simple_theme,
118 "header-line-background", color,
121 theme_manager_gdk_color_to_hex (&style->fg[GTK_STATE_SELECTED], color);
122 g_object_set (priv->simple_theme,
123 "header-foreground", color,
126 g_object_thaw_notify (G_OBJECT (priv->simple_theme));
130 FIXME: Make that work, it should update color when theme changes but it
131 doesnt seems to work with all themes.
133 g_object_get (priv->settings,
134 "color-hash", &color_hash,
138 * base_color: #ffffffffffff
139 * fg_color: #000000000000
140 * bg_color: #e6e6e7e7e8e8
141 * text_color: #000000000000
142 * selected_bg_color: #58589a9adbdb
143 * selected_fg_color: #ffffffffffff
146 color = g_hash_table_lookup (color_hash, "base_color");
148 theme_manager_gdk_color_to_hex (color, color_str);
149 g_object_set (priv->simple_theme,
150 "action-foreground", color_str,
151 "link-foreground", color_str,
155 color = g_hash_table_lookup (color_hash, "selected_bg_color");
157 theme_manager_gdk_color_to_hex (color, color_str);
158 g_object_set (priv->simple_theme,
159 "header-background", color_str,
163 color = g_hash_table_lookup (color_hash, "bg_color");
171 theme_manager_gdk_color_to_hex (&tmp, color_str);
172 g_object_set (priv->simple_theme,
173 "header-line-background", color_str,
177 color = g_hash_table_lookup (color_hash, "selected_fg_color");
179 theme_manager_gdk_color_to_hex (color, color_str);
180 g_object_set (priv->simple_theme,
181 "header-foreground", color_str,
185 g_hash_table_unref (color_hash);
191 empathy_theme_manager_class_init (EmpathyThemeManagerClass *klass)
193 GObjectClass *object_class = G_OBJECT_CLASS (klass);
195 signals[THEME_CHANGED] =
196 g_signal_new ("theme-changed",
197 G_OBJECT_CLASS_TYPE (object_class),
201 g_cclosure_marshal_VOID__VOID,
205 g_type_class_add_private (object_class, sizeof (EmpathyThemeManagerPriv));
207 object_class->finalize = theme_manager_finalize;
211 empathy_theme_manager_init (EmpathyThemeManager *manager)
213 EmpathyThemeManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
214 EMPATHY_TYPE_THEME_MANAGER, EmpathyThemeManagerPriv);
216 manager->priv = priv;
217 priv->name_notify_id =
218 empathy_conf_notify_add (empathy_conf_get (),
219 EMPATHY_PREFS_CHAT_THEME,
220 theme_manager_notify_name_cb,
223 empathy_conf_get_string (empathy_conf_get (),
224 EMPATHY_PREFS_CHAT_THEME,
227 /* Unused right now, but will be used soon. */
228 priv->show_avatars_notify_id =
229 empathy_conf_notify_add (empathy_conf_get (),
230 EMPATHY_PREFS_UI_SHOW_AVATARS,
231 theme_manager_notify_show_avatars_cb,
234 empathy_conf_get_bool (empathy_conf_get (),
235 EMPATHY_PREFS_UI_SHOW_AVATARS,
236 &priv->show_avatars);
238 priv->settings = gtk_settings_get_default ();
239 g_signal_connect_swapped (priv->settings, "notify::color-hash",
240 G_CALLBACK (theme_manager_color_hash_notify_cb),
243 priv->simple_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES, NULL);
244 theme_manager_color_hash_notify_cb (manager);
246 priv->clean_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES,
247 "header-foreground", "black",
248 "header-background", "#efefdf",
249 "header_line_background", "#e3e3d3",
250 "action_foreground", "brown4",
251 "time_foreground", "darkgrey",
252 "event_foreground", "darkgrey",
253 "invite_foreground", "sienna",
254 "link_foreground","#49789e",
257 priv->blue_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES,
258 "header_foreground", "black",
259 "header_background", "#88a2b4",
260 "header_line_background", "#7f96a4",
261 "text_foreground", "black",
262 "text_background", "#adbdc8",
263 "highlight_foreground", "black",
264 "action_foreground", "brown4",
265 "time_foreground", "darkgrey",
266 "event_foreground", "#7f96a4",
267 "invite_foreground", "sienna",
268 "link_foreground", "#49789e",
271 priv->classic_theme = g_object_new (EMPATHY_TYPE_THEME_IRC, NULL);
275 theme_manager_finalize (GObject *object)
277 EmpathyThemeManagerPriv *priv;
279 priv = GET_PRIV (object);
281 empathy_conf_notify_remove (empathy_conf_get (), priv->name_notify_id);
282 empathy_conf_notify_remove (empathy_conf_get (), priv->show_avatars_notify_id);
286 g_object_unref (priv->clean_theme);
287 g_object_unref (priv->simple_theme);
288 g_object_unref (priv->blue_theme);
289 g_object_unref (priv->classic_theme);
291 G_OBJECT_CLASS (empathy_theme_manager_parent_class)->finalize (object);
295 theme_manager_notify_name_cb (EmpathyConf *conf,
299 EmpathyThemeManager *manager;
300 EmpathyThemeManagerPriv *priv;
304 priv = GET_PRIV (manager);
309 if (!empathy_conf_get_string (conf, key, &name) ||
310 name == NULL || name[0] == 0) {
311 priv->name = g_strdup ("classic");
317 g_signal_emit (manager, signals[THEME_CHANGED], 0, NULL);
321 theme_manager_notify_show_avatars_cb (EmpathyConf *conf,
325 EmpathyThemeManager *manager;
326 EmpathyThemeManagerPriv *priv;
330 priv = GET_PRIV (manager);
332 if (!empathy_conf_get_bool (conf, key, &value)) {
333 priv->show_avatars = FALSE;
335 priv->show_avatars = value;
340 theme_manager_ensure_theme_exists (const gchar *name)
344 if (G_STR_EMPTY (name)) {
348 for (i = 0; themes[i]; i += 2) {
349 if (strcmp (themes[i], name) == 0) {
358 theme_manager_apply_theme (EmpathyThemeManager *manager,
359 EmpathyChatView *view,
362 EmpathyThemeManagerPriv *priv;
365 priv = GET_PRIV (manager);
367 /* Make sure all tags are present. Note: not useful now but when we have
368 * user defined theme it will be.
370 if (theme_manager_ensure_theme_exists (name)) {
371 if (strcmp (name, "clean") == 0) {
372 theme = priv->clean_theme;
374 else if (strcmp (name, "simple") == 0) {
375 theme = priv->simple_theme;
377 else if (strcmp (name, "blue") == 0) {
378 theme = priv->blue_theme;
380 theme = priv->classic_theme;
383 theme = priv->classic_theme;
386 empathy_chat_view_set_theme (view, theme);
389 EmpathyThemeManager *
390 empathy_theme_manager_get (void)
392 static EmpathyThemeManager *manager = NULL;
395 manager = g_object_new (EMPATHY_TYPE_THEME_MANAGER, NULL);
402 empathy_theme_manager_get_themes (void)
408 empathy_theme_manager_apply (EmpathyThemeManager *manager,
409 EmpathyChatView *view,
412 EmpathyThemeManagerPriv *priv;
414 priv = GET_PRIV (manager);
416 theme_manager_apply_theme (manager, view, name);
420 empathy_theme_manager_apply_saved (EmpathyThemeManager *manager,
421 EmpathyChatView *view)
423 EmpathyThemeManagerPriv *priv;
425 priv = GET_PRIV (manager);
427 theme_manager_apply_theme (manager, view, priv->name);