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-preferences.h"
33 #include "empathy-theme.h"
34 #include "empathy-theme-boxes.h"
35 #include "empathy-theme-irc.h"
36 #include "empathy-theme-manager.h"
38 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_THEME_MANAGER, EmpathyThemeManagerPriv))
45 gboolean show_avatars;
46 guint show_avatars_notify_id;
48 EmpathyTheme *clean_theme;
49 EmpathyTheme *simple_theme;
50 EmpathyTheme *blue_theme;
51 EmpathyTheme *classic_theme;
53 GtkSettings *settings;
54 } EmpathyThemeManagerPriv;
56 static void theme_manager_finalize (GObject *object);
57 static void theme_manager_notify_name_cb (EmpathyConf *conf,
60 static void theme_manager_notify_room_cb (EmpathyConf *conf,
63 static void theme_manager_notify_show_avatars_cb (EmpathyConf *conf,
66 static void theme_manager_apply_theme (EmpathyThemeManager *manager,
67 EmpathyChatView *view,
75 static guint signals[LAST_SIGNAL] = { 0 };
77 static const gchar *themes[] = {
78 "classic", N_("Classic"),
79 "simple", N_("Simple"),
85 G_DEFINE_TYPE (EmpathyThemeManager, empathy_theme_manager, G_TYPE_OBJECT);
88 theme_manager_gdk_color_to_hex (GdkColor *gdk_color, gchar *str_color)
90 g_snprintf (str_color, 10,
93 gdk_color->green >> 8,
94 gdk_color->blue >> 8);
98 theme_manager_color_hash_notify_cb (EmpathyThemeManager *manager)
100 EmpathyThemeManagerPriv *priv;
104 priv = GET_PRIV (manager);
106 style = gtk_widget_get_default_style ();
108 g_object_freeze_notify (G_OBJECT (priv->simple_theme));
110 theme_manager_gdk_color_to_hex (&style->base[GTK_STATE_SELECTED], color);
111 g_object_set (priv->simple_theme,
112 "action-foreground", color,
113 "link-foreground", color,
116 theme_manager_gdk_color_to_hex (&style->bg[GTK_STATE_SELECTED], color);
117 g_object_set (priv->simple_theme,
118 "header-background", color,
121 theme_manager_gdk_color_to_hex (&style->dark[GTK_STATE_SELECTED], color);
122 g_object_set (priv->simple_theme,
123 "header-line-background", color,
126 theme_manager_gdk_color_to_hex (&style->fg[GTK_STATE_SELECTED], color);
127 g_object_set (priv->simple_theme,
128 "header-foreground", color,
131 g_object_thaw_notify (G_OBJECT (priv->simple_theme));
135 FIXME: Make that work, it should update color when theme changes but it
136 doesnt seems to work with all themes.
138 g_object_get (priv->settings,
139 "color-hash", &color_hash,
143 * base_color: #ffffffffffff
144 * fg_color: #000000000000
145 * bg_color: #e6e6e7e7e8e8
146 * text_color: #000000000000
147 * selected_bg_color: #58589a9adbdb
148 * selected_fg_color: #ffffffffffff
151 color = g_hash_table_lookup (color_hash, "base_color");
153 theme_manager_gdk_color_to_hex (color, color_str);
154 g_object_set (priv->simple_theme,
155 "action-foreground", color_str,
156 "link-foreground", color_str,
160 color = g_hash_table_lookup (color_hash, "selected_bg_color");
162 theme_manager_gdk_color_to_hex (color, color_str);
163 g_object_set (priv->simple_theme,
164 "header-background", color_str,
168 color = g_hash_table_lookup (color_hash, "bg_color");
176 theme_manager_gdk_color_to_hex (&tmp, color_str);
177 g_object_set (priv->simple_theme,
178 "header-line-background", color_str,
182 color = g_hash_table_lookup (color_hash, "selected_fg_color");
184 theme_manager_gdk_color_to_hex (color, color_str);
185 g_object_set (priv->simple_theme,
186 "header-foreground", color_str,
190 g_hash_table_unref (color_hash);
196 empathy_theme_manager_class_init (EmpathyThemeManagerClass *klass)
198 GObjectClass *object_class = G_OBJECT_CLASS (klass);
200 signals[THEME_CHANGED] =
201 g_signal_new ("theme-changed",
202 G_OBJECT_CLASS_TYPE (object_class),
206 g_cclosure_marshal_VOID__VOID,
210 g_type_class_add_private (object_class, sizeof (EmpathyThemeManagerPriv));
212 object_class->finalize = theme_manager_finalize;
216 empathy_theme_manager_init (EmpathyThemeManager *manager)
218 EmpathyThemeManagerPriv *priv;
220 priv = GET_PRIV (manager);
222 priv->name_notify_id =
223 empathy_conf_notify_add (empathy_conf_get (),
224 EMPATHY_PREFS_CHAT_THEME,
225 theme_manager_notify_name_cb,
228 priv->room_notify_id =
229 empathy_conf_notify_add (empathy_conf_get (),
230 EMPATHY_PREFS_CHAT_THEME_CHAT_ROOM,
231 theme_manager_notify_room_cb,
234 empathy_conf_get_string (empathy_conf_get (),
235 EMPATHY_PREFS_CHAT_THEME,
238 /* Unused right now, but will be used soon. */
239 priv->show_avatars_notify_id =
240 empathy_conf_notify_add (empathy_conf_get (),
241 EMPATHY_PREFS_UI_SHOW_AVATARS,
242 theme_manager_notify_show_avatars_cb,
245 empathy_conf_get_bool (empathy_conf_get (),
246 EMPATHY_PREFS_UI_SHOW_AVATARS,
247 &priv->show_avatars);
249 priv->settings = gtk_settings_get_default ();
250 g_signal_connect_swapped (priv->settings, "notify::color-hash",
251 G_CALLBACK (theme_manager_color_hash_notify_cb),
254 priv->simple_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES, NULL);
255 theme_manager_color_hash_notify_cb (manager);
257 priv->clean_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES,
258 "header-foreground", "black",
259 "header-background", "#efefdf",
260 "header_line_background", "#e3e3d3",
261 "action_foreground", "brown4",
262 "time_foreground", "darkgrey",
263 "event_foreground", "darkgrey",
264 "invite_foreground", "sienna",
265 "link_foreground","#49789e",
268 priv->blue_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES,
269 "header_foreground", "black",
270 "header_background", "#88a2b4",
271 "header_line_background", "#7f96a4",
272 "text_foreground", "black",
273 "text_background", "#adbdc8",
274 "highlight_foreground", "black",
275 "action_foreground", "brown4",
276 "time_foreground", "darkgrey",
277 "event_foreground", "#7f96a4",
278 "invite_foreground", "sienna",
279 "link_foreground", "#49789e",
282 priv->classic_theme = g_object_new (EMPATHY_TYPE_THEME_IRC, NULL);
286 theme_manager_finalize (GObject *object)
288 EmpathyThemeManagerPriv *priv;
290 priv = GET_PRIV (object);
292 empathy_conf_notify_remove (empathy_conf_get (), priv->name_notify_id);
293 empathy_conf_notify_remove (empathy_conf_get (), priv->room_notify_id);
294 empathy_conf_notify_remove (empathy_conf_get (), priv->show_avatars_notify_id);
298 g_object_unref (priv->clean_theme);
299 g_object_unref (priv->simple_theme);
300 g_object_unref (priv->blue_theme);
301 g_object_unref (priv->classic_theme);
303 G_OBJECT_CLASS (empathy_theme_manager_parent_class)->finalize (object);
307 theme_manager_notify_name_cb (EmpathyConf *conf,
311 EmpathyThemeManager *manager;
312 EmpathyThemeManagerPriv *priv;
316 priv = GET_PRIV (manager);
321 if (!empathy_conf_get_string (conf, key, &name) ||
322 name == NULL || name[0] == 0) {
323 priv->name = g_strdup ("classic");
329 g_signal_emit (manager, signals[THEME_CHANGED], 0, NULL);
333 theme_manager_notify_room_cb (EmpathyConf *conf,
337 g_signal_emit (user_data, signals[THEME_CHANGED], 0, NULL);
341 theme_manager_notify_show_avatars_cb (EmpathyConf *conf,
345 EmpathyThemeManager *manager;
346 EmpathyThemeManagerPriv *priv;
350 priv = GET_PRIV (manager);
352 if (!empathy_conf_get_bool (conf, key, &value)) {
353 priv->show_avatars = FALSE;
355 priv->show_avatars = value;
360 theme_manager_ensure_theme_exists (const gchar *name)
364 if (G_STR_EMPTY (name)) {
368 for (i = 0; themes[i]; i += 2) {
369 if (strcmp (themes[i], name) == 0) {
378 theme_manager_apply_theme (EmpathyThemeManager *manager,
379 EmpathyChatView *view,
382 EmpathyThemeManagerPriv *priv;
385 priv = GET_PRIV (manager);
387 /* Make sure all tags are present. Note: not useful now but when we have
388 * user defined theme it will be.
390 if (theme_manager_ensure_theme_exists (name)) {
391 if (strcmp (name, "clean") == 0) {
392 theme = priv->clean_theme;
394 else if (strcmp (name, "simple") == 0) {
395 theme = priv->simple_theme;
397 else if (strcmp (name, "blue") == 0) {
398 theme = priv->blue_theme;
400 theme = priv->classic_theme;
403 theme = priv->classic_theme;
406 empathy_chat_view_set_theme (view, theme);
409 EmpathyThemeManager *
410 empathy_theme_manager_get (void)
412 static EmpathyThemeManager *manager = NULL;
415 manager = g_object_new (EMPATHY_TYPE_THEME_MANAGER, NULL);
422 empathy_theme_manager_get_themes (void)
428 empathy_theme_manager_apply (EmpathyThemeManager *manager,
429 EmpathyChatView *view,
432 EmpathyThemeManagerPriv *priv;
434 priv = GET_PRIV (manager);
436 theme_manager_apply_theme (manager, view, name);
440 empathy_theme_manager_apply_saved (EmpathyThemeManager *manager,
441 EmpathyChatView *view)
443 EmpathyThemeManagerPriv *priv;
445 priv = GET_PRIV (manager);
447 theme_manager_apply_theme (manager, view, priv->name);