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>
29 #include <libempathy/empathy-conf.h>
31 #include "empathy-chat-view.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;
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 empathy_theme_manager_class_init (EmpathyThemeManagerClass *klass)
90 GObjectClass *object_class = G_OBJECT_CLASS (klass);
92 signals[THEME_CHANGED] =
93 g_signal_new ("theme-changed",
94 G_OBJECT_CLASS_TYPE (object_class),
98 g_cclosure_marshal_VOID__VOID,
102 g_type_class_add_private (object_class, sizeof (EmpathyThemeManagerPriv));
104 object_class->finalize = theme_manager_finalize;
108 empathy_theme_manager_init (EmpathyThemeManager *manager)
110 EmpathyThemeManagerPriv *priv;
112 priv = GET_PRIV (manager);
114 priv->name_notify_id =
115 empathy_conf_notify_add (empathy_conf_get (),
116 EMPATHY_PREFS_CHAT_THEME,
117 theme_manager_notify_name_cb,
120 priv->room_notify_id =
121 empathy_conf_notify_add (empathy_conf_get (),
122 EMPATHY_PREFS_CHAT_THEME_CHAT_ROOM,
123 theme_manager_notify_room_cb,
126 empathy_conf_get_string (empathy_conf_get (),
127 EMPATHY_PREFS_CHAT_THEME,
130 /* Unused right now, but will be used soon. */
131 priv->show_avatars_notify_id =
132 empathy_conf_notify_add (empathy_conf_get (),
133 EMPATHY_PREFS_UI_SHOW_AVATARS,
134 theme_manager_notify_show_avatars_cb,
137 empathy_conf_get_bool (empathy_conf_get (),
138 EMPATHY_PREFS_UI_SHOW_AVATARS,
139 &priv->show_avatars);
141 priv->clean_theme = empathy_theme_boxes_new ("clean");
142 priv->simple_theme = empathy_theme_boxes_new ("simple");
143 priv->blue_theme = empathy_theme_boxes_new ("blue");
144 priv->classic_theme = g_object_new (EMPATHY_TYPE_THEME_IRC, NULL);
148 theme_manager_finalize (GObject *object)
150 EmpathyThemeManagerPriv *priv;
152 priv = GET_PRIV (object);
154 empathy_conf_notify_remove (empathy_conf_get (), priv->name_notify_id);
155 empathy_conf_notify_remove (empathy_conf_get (), priv->room_notify_id);
156 empathy_conf_notify_remove (empathy_conf_get (), priv->show_avatars_notify_id);
160 g_object_unref (priv->clean_theme);
161 g_object_unref (priv->simple_theme);
162 g_object_unref (priv->blue_theme);
163 g_object_unref (priv->classic_theme);
165 G_OBJECT_CLASS (empathy_theme_manager_parent_class)->finalize (object);
169 theme_manager_notify_name_cb (EmpathyConf *conf,
173 EmpathyThemeManager *manager;
174 EmpathyThemeManagerPriv *priv;
178 priv = GET_PRIV (manager);
183 if (!empathy_conf_get_string (conf, key, &name) ||
184 name == NULL || name[0] == 0) {
185 priv->name = g_strdup ("classic");
191 g_signal_emit (manager, signals[THEME_CHANGED], 0, NULL);
195 theme_manager_notify_room_cb (EmpathyConf *conf,
199 g_signal_emit (user_data, signals[THEME_CHANGED], 0, NULL);
203 theme_manager_notify_show_avatars_cb (EmpathyConf *conf,
207 EmpathyThemeManager *manager;
208 EmpathyThemeManagerPriv *priv;
212 priv = GET_PRIV (manager);
214 if (!empathy_conf_get_bool (conf, key, &value)) {
215 priv->show_avatars = FALSE;
217 priv->show_avatars = value;
222 theme_manager_ensure_theme_exists (const gchar *name)
226 if (G_STR_EMPTY (name)) {
230 for (i = 0; themes[i]; i += 2) {
231 if (strcmp (themes[i], name) == 0) {
240 theme_manager_apply_theme (EmpathyThemeManager *manager,
241 EmpathyChatView *view,
244 EmpathyThemeManagerPriv *priv;
247 priv = GET_PRIV (manager);
249 /* Make sure all tags are present. Note: not useful now but when we have
250 * user defined theme it will be.
252 if (theme_manager_ensure_theme_exists (name)) {
253 if (strcmp (name, "clean") == 0) {
254 theme = priv->clean_theme;
256 else if (strcmp (name, "simple") == 0) {
257 theme = priv->simple_theme;
259 else if (strcmp (name, "blue") == 0) {
260 theme = priv->blue_theme;
262 theme = priv->classic_theme;
265 theme = priv->classic_theme;
268 empathy_chat_view_set_theme (view, theme);
271 EmpathyThemeManager *
272 empathy_theme_manager_get (void)
274 static EmpathyThemeManager *manager = NULL;
277 manager = g_object_new (EMPATHY_TYPE_THEME_MANAGER, NULL);
284 empathy_theme_manager_get_themes (void)
290 empathy_theme_manager_apply (EmpathyThemeManager *manager,
291 EmpathyChatView *view,
294 EmpathyThemeManagerPriv *priv;
296 priv = GET_PRIV (manager);
298 theme_manager_apply_theme (manager, view, name);
302 empathy_theme_manager_apply_saved (EmpathyThemeManager *manager,
303 EmpathyChatView *view)
305 EmpathyThemeManagerPriv *priv;
307 priv = GET_PRIV (manager);
309 theme_manager_apply_theme (manager, view, priv->name);