diff options
author | Xavier Claessens <xclaesse@gmail.com> | 2008-07-19 02:59:59 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2009-06-12 00:06:30 +0800 |
commit | eb48fbaf322604ee57888165242acd97efd8decc (patch) | |
tree | 866f37a0789e30ce4b0d66ff9d03cd281f181216 /libempathy-gtk | |
parent | 80f5d332a5a531f8d5b96d9ea50f2384bf515324 (diff) | |
download | gsoc2013-empathy-eb48fbaf322604ee57888165242acd97efd8decc.tar gsoc2013-empathy-eb48fbaf322604ee57888165242acd97efd8decc.tar.gz gsoc2013-empathy-eb48fbaf322604ee57888165242acd97efd8decc.tar.bz2 gsoc2013-empathy-eb48fbaf322604ee57888165242acd97efd8decc.tar.lz gsoc2013-empathy-eb48fbaf322604ee57888165242acd97efd8decc.tar.xz gsoc2013-empathy-eb48fbaf322604ee57888165242acd97efd8decc.tar.zst gsoc2013-empathy-eb48fbaf322604ee57888165242acd97efd8decc.zip |
Add a path property on EmpathyThemeAdium and ge the adium-path gconf key in EmpathyThemeManager.
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-theme-adium.c | 82 | ||||
-rw-r--r-- | libempathy-gtk/empathy-theme-adium.h | 2 | ||||
-rw-r--r-- | libempathy-gtk/empathy-theme-manager.c | 49 |
3 files changed, 117 insertions, 16 deletions
diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index 84a023956..fdeabfb4f 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -44,6 +44,7 @@ typedef struct { EmpathyContact *last_contact; gboolean page_loaded; GList *message_queue; + gchar *path; gchar *default_avatar_filename; gchar *in_content_html; gsize in_content_len; @@ -57,14 +58,18 @@ typedef struct { static void theme_adium_iface_init (EmpathyChatViewIface *iface); +enum { + PROP_0, + PROP_PATH, +}; + G_DEFINE_TYPE_WITH_CODE (EmpathyThemeAdium, empathy_theme_adium, WEBKIT_TYPE_WEB_VIEW, G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CHAT_VIEW, theme_adium_iface_init)); static void -theme_adium_load (EmpathyThemeAdium *theme, - const gchar *path) +theme_adium_load (EmpathyThemeAdium *theme) { EmpathyThemeAdiumPriv *priv = GET_PRIV (theme); gchar *basedir; @@ -76,7 +81,7 @@ theme_adium_load (EmpathyThemeAdium *theme, gchar *content; gchar *css_path; - basedir = g_build_filename (path, "Contents", "Resources", NULL); + basedir = g_build_filename (priv->path, "Contents", "Resources", NULL); /* Load html files */ file = g_build_filename (basedir, "Template.html", NULL); @@ -536,6 +541,7 @@ theme_adium_finalize (GObject *object) g_free (priv->out_content_html); g_free (priv->out_nextcontent_html); g_free (priv->default_avatar_filename); + g_free (priv->path); g_object_unref (priv->smiley_manager); if (priv->last_contact) { @@ -546,11 +552,67 @@ theme_adium_finalize (GObject *object) } static void +theme_adium_constructed (GObject *object) +{ + theme_adium_load (EMPATHY_THEME_ADIUM (object)); +} + +static void +theme_adium_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyThemeAdiumPriv *priv = GET_PRIV (object); + + switch (param_id) { + case PROP_PATH: + g_value_set_string (value, priv->path); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +static void +theme_adium_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyThemeAdiumPriv *priv = GET_PRIV (object); + + switch (param_id) { + case PROP_PATH: + g_free (priv->path); + priv->path = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +static void empathy_theme_adium_class_init (EmpathyThemeAdiumClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = theme_adium_finalize; + object_class->constructed = theme_adium_constructed; + object_class->get_property = theme_adium_get_property; + object_class->set_property = theme_adium_set_property; + + g_object_class_install_property (object_class, + PROP_PATH, + g_param_spec_string ("path", + "The theme path", + "Path to the adium theme", + g_get_home_dir (), + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_READWRITE)); + g_type_class_add_private (object_class, sizeof (EmpathyThemeAdiumPriv)); } @@ -560,7 +622,6 @@ empathy_theme_adium_init (EmpathyThemeAdium *theme) { EmpathyThemeAdiumPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme, EMPATHY_TYPE_THEME_ADIUM, EmpathyThemeAdiumPriv); - gchar *path = NULL; theme->priv = priv; @@ -572,17 +633,16 @@ empathy_theme_adium_init (EmpathyThemeAdium *theme) g_signal_connect (theme, "navigation-requested", G_CALLBACK (theme_adium_navigation_requested_cb), NULL); - - empathy_conf_get_string (empathy_conf_get (), - EMPATHY_PREFS_CHAT_ADIUM_PATH, - &path); - theme_adium_load (theme, path); } EmpathyThemeAdium * -empathy_theme_adium_new (void) +empathy_theme_adium_new (const gchar *path) { - return g_object_new (EMPATHY_TYPE_THEME_ADIUM, NULL); + g_return_val_if_fail (empathy_theme_adium_is_valid (path), NULL); + + return g_object_new (EMPATHY_TYPE_THEME_ADIUM, + "path", path, + NULL); } gboolean diff --git a/libempathy-gtk/empathy-theme-adium.h b/libempathy-gtk/empathy-theme-adium.h index 24fe986f6..437edfe2b 100644 --- a/libempathy-gtk/empathy-theme-adium.h +++ b/libempathy-gtk/empathy-theme-adium.h @@ -48,7 +48,7 @@ struct _EmpathyThemeAdiumClass { }; GType empathy_theme_adium_get_type (void) G_GNUC_CONST; -EmpathyThemeAdium *empathy_theme_adium_new (void); +EmpathyThemeAdium *empathy_theme_adium_new (const gchar *path); gboolean empathy_theme_adium_is_valid (const gchar *path); G_END_DECLS diff --git a/libempathy-gtk/empathy-theme-manager.c b/libempathy-gtk/empathy-theme-manager.c index eebbd3105..12f04d0bd 100644 --- a/libempathy-gtk/empathy-theme-manager.c +++ b/libempathy-gtk/empathy-theme-manager.c @@ -49,6 +49,8 @@ typedef struct { gchar *name; guint name_notify_id; + gchar *adium_path; + guint adium_path_notify_id; GtkSettings *settings; GList *boxes_views; } EmpathyThemeManagerPriv; @@ -325,15 +327,21 @@ empathy_theme_manager_create_view (EmpathyThemeManager *manager) DEBUG ("Using theme %s", priv->name); - if (strcmp (priv->name, "classic") == 0) { - return EMPATHY_CHAT_VIEW (theme_manager_create_irc_view (manager)); - } #ifdef HAVE_WEBKIT if (strcmp (priv->name, "adium") == 0) { - return EMPATHY_CHAT_VIEW (empathy_theme_adium_new ()); + if (empathy_theme_adium_is_valid (priv->adium_path)) { + return EMPATHY_CHAT_VIEW (empathy_theme_adium_new (priv->adium_path)); + } 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)); + } + theme = theme_manager_create_boxes_view (manager); theme_manager_update_boxes_theme (manager, theme); @@ -416,6 +424,27 @@ theme_manager_notify_name_cb (EmpathyConf *conf, } 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) { EmpathyThemeManagerPriv *priv = GET_PRIV (object); @@ -423,6 +452,8 @@ 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), @@ -472,6 +503,16 @@ empathy_theme_manager_init (EmpathyThemeManager *manager) EMPATHY_PREFS_CHAT_THEME, 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); + /* Track GTK color changes */ priv->settings = gtk_settings_get_default (); g_signal_connect_swapped (priv->settings, "notify::color-hash", |