#include <string.h>
#include <glib/gi18n-lib.h>
+#include <telepathy-glib/dbus.h>
#include <gtk/gtk.h>
#include <telepathy-glib/util.h>
#include "empathy-theme-boxes.h"
#include "empathy-theme-irc.h"
+#ifdef HAVE_WEBKIT
+#include "empathy-theme-adium.h"
+#endif
+
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
#include <libempathy/empathy-debug.h>
typedef struct {
gchar *name;
guint name_notify_id;
+ gchar *adium_path;
+ guint adium_path_notify_id;
GtkSettings *settings;
GList *boxes_views;
} EmpathyThemeManagerPriv;
"foreground", "steelblue",
"underline", PANGO_UNDERLINE_SINGLE,
NULL);
+ empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_HIGHLIGHT,
+ "background", "yellow",
+ NULL);
/* Define IRC tags */
empathy_chat_text_view_tag_set (view, EMPATHY_THEME_IRC_TAG_NICK_SELF,
/* FIXME: GtkTextTag don't support to set color properties to NULL.
* See bug #542523 */
-
+
#define TAG_SET(prop, prop_set, value) \
if (value != NULL) { \
g_object_set (tag, prop, value, NULL); \
"pixels-above-lines", 4,
NULL);
TAG_SET ("paragraph-background", "paragraph-background-set", text_background);
- TAG_SET ("foreground", "foreground-set",highlight_foreground);
+ TAG_SET ("foreground", "foreground-set", highlight_foreground);
empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_SPACING,
"size", 3000,
}
static void
-theme_manager_update_simple_tags (EmpathyThemeBoxes *theme)
+on_style_set_cb (GtkWidget *widget, GtkStyle *previous_style, gpointer data)
{
GtkStyle *style;
gchar color1[10];
gchar color3[10];
gchar color4[10];
- style = gtk_widget_get_default_style ();
+ style = gtk_widget_get_style (GTK_WIDGET (widget));
theme_manager_gdk_color_to_hex (&style->base[GTK_STATE_SELECTED], color1);
theme_manager_gdk_color_to_hex (&style->bg[GTK_STATE_SELECTED], color2);
theme_manager_gdk_color_to_hex (&style->dark[GTK_STATE_SELECTED], color3);
theme_manager_gdk_color_to_hex (&style->fg[GTK_STATE_SELECTED], color4);
- theme_manager_update_boxes_tags (theme,
+ theme_manager_update_boxes_tags (EMPATHY_THEME_BOXES (widget),
color4, /* header_foreground */
color2, /* header_background */
color3, /* header_line_background */
EmpathyThemeManagerPriv *priv = GET_PRIV (manager);
if (strcmp (priv->name, "simple") == 0) {
- theme_manager_update_simple_tags (theme);
+ g_signal_connect (G_OBJECT (theme), "style-set",
+ G_CALLBACK (on_style_set_cb), theme);
}
else if (strcmp (priv->name, "clean") == 0) {
theme_manager_update_boxes_tags (theme,
DEBUG ("Using theme %s", priv->name);
+#ifdef HAVE_WEBKIT
+ if (strcmp (priv->name, "adium") == 0) {
+ if (empathy_adium_path_is_valid (priv->adium_path)) {
+ static EmpathyAdiumData *data = NULL;
+ EmpathyThemeAdium *theme_adium;
+
+ if (data &&
+ !tp_strdiff (empathy_adium_data_get_path (data),
+ priv->adium_path)) {
+ /* Theme did not change, reuse data */
+ theme_adium = empathy_theme_adium_new (data);
+ return EMPATHY_CHAT_VIEW (theme_adium);
+ }
+
+ /* Theme changed, drop old data if any and
+ * load a new one */
+ if (data) {
+ empathy_adium_data_unref (data);
+ data = NULL;
+ }
+
+ data = empathy_adium_data_new (priv->adium_path);
+ theme_adium = empathy_theme_adium_new (data);
+ return EMPATHY_CHAT_VIEW (theme_adium);
+ } else {
+ /* The adium path is not valid, fallback to classic theme */
+ return EMPATHY_CHAT_VIEW (theme_manager_create_irc_view (manager));
+ }
+ }
+#endif
+
if (strcmp (priv->name, "classic") == 0) {
return EMPATHY_CHAT_VIEW (theme_manager_create_irc_view (manager));
}
return EMPATHY_CHAT_VIEW (theme);
}
-static void
-theme_manager_color_hash_notify_cb (EmpathyThemeManager *manager)
-{
- EmpathyThemeManagerPriv *priv = GET_PRIV (manager);
-
- /* FIXME: Make that work, it should update color when theme changes but
- * it doesnt seems to work with all themes. */
-
- if (strcmp (priv->name, "simple") == 0) {
- GList *l;
-
- /* We are using the simple theme which use the GTK theme color,
- * Update views to use the new color. */
- for (l = priv->boxes_views; l; l = l->next) {
- theme_manager_update_simple_tags (EMPATHY_THEME_BOXES (l->data));
- }
- }
-}
-
static gboolean
theme_manager_ensure_theme_exists (const gchar *name)
{
return FALSE;
}
+ if (strcmp ("adium", name) == 0) {
+ return TRUE;
+ }
+
for (i = 0; themes[i]; i += 2) {
if (strcmp (themes[i], name) == 0) {
return TRUE;
g_signal_emit (manager, signals[THEME_CHANGED], 0, NULL);
}
+static void
+theme_manager_notify_adium_path_cb (EmpathyConf *conf,
+ const gchar *key,
+ gpointer user_data)
+{
+ EmpathyThemeManager *manager = EMPATHY_THEME_MANAGER (user_data);
+ EmpathyThemeManagerPriv *priv = GET_PRIV (manager);
+ gchar *adium_path = NULL;
+
+ if (!empathy_conf_get_string (conf, key, &adium_path) ||
+ !tp_strdiff (priv->adium_path, adium_path)) {
+ g_free (adium_path);
+ return;
+ }
+
+ g_free (priv->adium_path);
+ priv->adium_path = adium_path;
+
+ g_signal_emit (manager, signals[THEME_CHANGED], 0, NULL);
+}
+
static void
theme_manager_finalize (GObject *object)
{
empathy_conf_notify_remove (empathy_conf_get (), priv->name_notify_id);
g_free (priv->name);
+ empathy_conf_notify_remove (empathy_conf_get (), priv->adium_path_notify_id);
+ g_free (priv->adium_path);
for (l = priv->boxes_views; l; l = l->next) {
g_object_weak_unref (G_OBJECT (l->data),
EMPATHY_PREFS_CHAT_THEME,
manager);
- /* Track GTK color changes */
- priv->settings = gtk_settings_get_default ();
- g_signal_connect_swapped (priv->settings, "notify::color-hash",
- G_CALLBACK (theme_manager_color_hash_notify_cb),
- manager);
+ /* Take the adium path and track changes */
+ priv->adium_path_notify_id =
+ empathy_conf_notify_add (empathy_conf_get (),
+ EMPATHY_PREFS_CHAT_ADIUM_PATH,
+ theme_manager_notify_adium_path_cb,
+ manager);
+ theme_manager_notify_adium_path_cb (empathy_conf_get (),
+ EMPATHY_PREFS_CHAT_ADIUM_PATH,
+ manager);
}
EmpathyThemeManager *
return themes;
}
+#ifdef HAVE_WEBKIT
+static void
+find_themes (GList **list, const gchar *dirpath)
+{
+ GDir *dir;
+ GError *error = NULL;
+ const gchar *name = NULL;
+ GHashTable *info = NULL;
+
+ dir = g_dir_open (dirpath, 0, &error);
+ if (dir != NULL) {
+ name = g_dir_read_name (dir);
+ while (name != NULL) {
+ gchar *path;
+
+ path = g_build_path (G_DIR_SEPARATOR_S, dirpath, name, NULL);
+ if (empathy_adium_path_is_valid (path)) {
+ info = empathy_adium_info_new (path);
+ if (info != NULL) {
+ *list = g_list_prepend (*list, info);
+ }
+ }
+ g_free (path);
+ name = g_dir_read_name (dir);
+ }
+ g_dir_close (dir);
+ } else {
+ DEBUG ("Error opening %s: %s\n", dirpath, error->message);
+ g_error_free (error);
+ }
+}
+#endif /* HAVE_WEBKIT */
+
+GList *
+empathy_theme_manager_get_adium_themes (void)
+{
+#ifdef HAVE_WEBKIT
+ GList *themes_list = NULL;
+ gchar *userpath = NULL;
+ const gchar *const *paths = NULL;
+ gint i = 0;
+
+ userpath = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (), "adium/message-styles", NULL);
+ find_themes (&themes_list, userpath);
+ g_free (userpath);
+
+ paths = g_get_system_data_dirs ();
+ for (i = 0; paths[i] != NULL; i++) {
+ userpath = g_build_path (G_DIR_SEPARATOR_S, paths[i],
+ "adium/message-styles", NULL);
+ find_themes (&themes_list, userpath);
+ g_free (userpath);
+ }
+
+ return themes_list;
+#else
+ return NULL;
+#endif /* HAVE_WEBKIT */
+}