EmpathyContact *last_contact;
gboolean page_loaded;
GList *message_queue;
+ gchar *path;
gchar *default_avatar_filename;
gchar *in_content_html;
gsize in_content_len;
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;
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);
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) {
G_OBJECT_CLASS (empathy_theme_adium_parent_class)->finalize (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));
}
{
EmpathyThemeAdiumPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme,
EMPATHY_TYPE_THEME_ADIUM, EmpathyThemeAdiumPriv);
- gchar *path = NULL;
theme->priv = priv;
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
typedef struct {
gchar *name;
guint name_notify_id;
+ gchar *adium_path;
+ guint adium_path_notify_id;
GtkSettings *settings;
GList *boxes_views;
} EmpathyThemeManagerPriv;
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);
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);
+ /* 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",