[monet/monet-xml] monet-gtk: load the configuration file from the current gtkrc directory
- From: Thomas Wood <thos src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [monet/monet-xml] monet-gtk: load the configuration file from the current gtkrc directory
- Date: Wed, 1 Sep 2010 21:50:29 +0000 (UTC)
commit 24bc090e1a16f5e76e04ed36032bbabe356cfb43
Author: Thomas Wood <thos gnome org>
Date: Wed Sep 1 22:45:45 2010 +0100
monet-gtk: load the configuration file from the current gtkrc directory
monet-gtk/rcstyle.c | 63 +++++++++++++++++++++++++++--
monet-gtk/rcstyle.h | 2 +
monet-gtk/style.c | 111 +++++++++++++++++++++++++++++++++++++++++++++------
monet-gtk/style.h | 1 +
4 files changed, 160 insertions(+), 17 deletions(-)
---
diff --git a/monet-gtk/rcstyle.c b/monet-gtk/rcstyle.c
index 3771a7a..25d16da 100644
--- a/monet-gtk/rcstyle.c
+++ b/monet-gtk/rcstyle.c
@@ -63,20 +63,38 @@ monet_gtk_rc_style_init (MonetGtkRcStyle *style)
}
static void
-monet_gtk_rc_style_finalize (MonetGtkRcStyle *style)
+monet_gtk_rc_style_finalize (GObject *object)
{
+ MonetGtkRcStyle *style = MONET_GTK_RC_STYLE (object);
/* Clean up any data from the RC style in here. */
+
+ if (style->config_filename)
+ {
+ g_free (style->config_filename);
+ style->config_filename = NULL;
+ }
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
monet_gtk_rc_style_merge (GtkRcStyle *dest,
GtkRcStyle *src)
{
+ MonetGtkRcStyle *mn_dest = (MonetGtkRcStyle *) dest;
+ MonetGtkRcStyle *mn_src = (MonetGtkRcStyle *) src;
+
parent_class->merge (dest, src);
if (!MONET_GTK_IS_RC_STYLE (src))
return;
+ if (!MONET_GTK_IS_RC_STYLE (dest))
+ return;
+
+ if (!mn_dest->config_filename && mn_src->config_filename)
+ mn_dest->config_filename = g_strdup (mn_src->config_filename);
+
/* This function "merges" two RC styles. All matched styles from the
* gtkrc are merged together to form the final style.
*
@@ -94,6 +112,36 @@ monet_gtk_rc_style_parse (GtkRcStyle *rc_style,
GScanner *scanner)
{
MonetGtkRcStyle *monet_gtk_rc_style = MONET_GTK_RC_STYLE (rc_style);
+ GTokenType token;
+ gchar *basename;
+
+#if 0
+ guint old_scope;
+ static GQuark scope_id = 0;
+
+ if (!scope_id)
+ g_quark_from_string ("monet-gtk-engine");
+
+ /* set the new scope and store the old scope id */
+ old_scope = g_scanner_get_scope (scanner, scope_id);
+
+ /* register the symbols if we haven't already done so */
+ if (!g_scanner_lookup_symbol (scanner,
+#endif
+
+ while (token != G_TOKEN_RIGHT_CURLY)
+ {
+ token = g_scanner_peek_next_token (scanner);
+ }
+ g_scanner_get_next_token (scanner);
+
+ basename = g_path_get_dirname (scanner->input_name);
+
+ g_free (monet_gtk_rc_style->config_filename);
+ monet_gtk_rc_style->config_filename = g_build_filename (basename,
+ "/monet.xml", NULL);
+
+ g_free (basename);
return G_TOKEN_NONE;
}
@@ -110,10 +158,10 @@ monet_gtk_rc_style_class_init (MonetGtkRcStyleClass *klass)
* We need to override at least create_style. (Uncomment the other
* two to override them) */
rc_style_class->create_style = monet_gtk_rc_style_create_style;
- /*rc_style_class->merge = monet_gtk_rc_style_merge;
+ rc_style_class->merge = monet_gtk_rc_style_merge;
rc_style_class->parse = monet_gtk_rc_style_parse;
- g_object_class->finalize = monet_gtk_rc_style_finalize;*/
+ g_object_class->finalize = monet_gtk_rc_style_finalize;
}
/* Create an empty style suitable to this RC style
@@ -121,7 +169,14 @@ monet_gtk_rc_style_class_init (MonetGtkRcStyleClass *klass)
static GtkStyle *
monet_gtk_rc_style_create_style (GtkRcStyle *rc_style)
{
- return GTK_STYLE (g_object_new (MONET_GTK_TYPE_STYLE, NULL));
+ MonetGtkRcStyle *monet_rc_style = MONET_GTK_RC_STYLE (rc_style);
+ MonetGtkStyle *style;
+
+ style = g_object_new (MONET_GTK_TYPE_STYLE,
+ "config-filename", monet_rc_style->config_filename,
+ NULL);
+
+ return GTK_STYLE (style);
}
diff --git a/monet-gtk/rcstyle.h b/monet-gtk/rcstyle.h
index b61fca4..5d86344 100644
--- a/monet-gtk/rcstyle.h
+++ b/monet-gtk/rcstyle.h
@@ -39,6 +39,8 @@ GType monet_gtk_type_rc_style G_GNUC_INTERNAL;
struct _MonetGtkRcStyle
{
GtkRcStyle parent_instance;
+
+ gchar *config_filename;
};
struct _MonetGtkRcStyleClass
diff --git a/monet-gtk/style.c b/monet-gtk/style.c
index 3930bac..df6d89b 100644
--- a/monet-gtk/style.c
+++ b/monet-gtk/style.c
@@ -23,6 +23,11 @@
#define DETAIL(x) (detail && (x) && !strcmp (detail, x))
+enum
+{
+ PROP_CONFIG_FILENAME = 1
+};
+
static GtkStyleClass *monet_gtk_style_parent_class;
static void
@@ -567,14 +572,101 @@ monet_gtk_draw_resize_grip (GtkStyle *style,
monet_gtk_style_parent_class->draw_resize_grip (style, window, state_type, area, widget, detail, edge, x, y, width, height);
}
+static void
+monet_gtk_style_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MonetGtkStyle *style = (MonetGtkStyle *) object;
+
+ switch (property_id)
+ {
+ case PROP_CONFIG_FILENAME:
+ g_free (style->config_filename);
+ style->config_filename = g_value_dup_string (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+monet_gtk_style_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ MonetGtkStyle *style = (MonetGtkStyle *) object;
+
+ switch (property_id)
+ {
+ case PROP_CONFIG_FILENAME:
+ g_value_set_string (value, style->config_filename);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+monet_gtk_style_constructed (GObject *object)
+{
+ GError *err = NULL;
+ gchar *config_file;
+
+ MonetGtkStyle *mn_gtk_style = MONET_GTK_STYLE (object);
+
+ config_file = mn_gtk_style->config_filename;
+
+ if (!config_file)
+ {
+ g_warning ("No configuration file loaded");
+ return;
+ }
+
+ mn_gtk_style->mn_style = mn_style_new ();
+
+ mn_style_load_config (mn_gtk_style->mn_style, config_file, &err);
+
+ if (err)
+ {
+ g_warning ("Error loading theme config: %s", err->message);
+
+ g_error_free (err);
+ }
+}
+
+static void
+monet_gtk_style_finalize (GObject *object)
+{
+ MonetGtkStyle *mn_gtk_style = MONET_GTK_STYLE (object);
+
+ if (mn_gtk_style->config_filename)
+ {
+ g_free (mn_gtk_style->config_filename);
+ mn_gtk_style->config_filename = NULL;
+ }
+
+ G_OBJECT_CLASS (monet_gtk_style_parent_class)->finalize (object);
+}
static void
monet_gtk_style_class_init (MonetGtkStyleClass * klass)
{
GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GParamSpec *pspec;
monet_gtk_style_parent_class = g_type_class_peek_parent (klass);
+ object_class->set_property = monet_gtk_style_set_property;
+ object_class->get_property = monet_gtk_style_get_property;
+ object_class->constructed = monet_gtk_style_constructed;
+ object_class->finalize = monet_gtk_style_finalize;
+
/* All functions that have prototypes here are not commented out. */
style_class->draw_hline = monet_gtk_draw_hline;
style_class->draw_vline = monet_gtk_draw_vline;
@@ -598,25 +690,18 @@ monet_gtk_style_class_init (MonetGtkStyleClass * klass)
/* There are some more functions in GtkStyleClass that may be overridden.
* See gtkstyle.h in the GTK+ sources for a list and help for most of them. */
+
+ pspec = g_param_spec_string ("config-filename", "config filename",
+ "Filename of the Monet configuration file", "",
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
+ | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property (object_class, PROP_CONFIG_FILENAME, pspec);
}
static void
monet_gtk_style_init (GObject *self)
{
- GError *err = NULL;
-
- MonetGtkStyle *mn_gtk = MONET_GTK_STYLE (self);
-
- mn_gtk->mn_style = mn_style_new ();
- mn_style_load_config (mn_gtk->mn_style, THEMEDIR"/monet.xml", &err);
-
- if (err)
- {
- g_warning ("Error loading theme config: %s", err->message);
-
- g_error_free (err);
- }
}
void
diff --git a/monet-gtk/style.h b/monet-gtk/style.h
index 19b2c5c..11e500b 100644
--- a/monet-gtk/style.h
+++ b/monet-gtk/style.h
@@ -39,6 +39,7 @@ struct _MonetGtkStyle
GtkStyle parent_instance;
MnStyle *mn_style;
+ gchar *config_filename;
};
struct _MonetGtkStyleClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]