/* Writes a schema, which is a struct. */
static void
utils_append_schema (DBusMessageIter   *main_iter,
		     const GConfSchema *schema)
{
  DBusMessageIter  struct_iter;
  gint32           i;
  const gchar     *s;
  GConfValue      *default_value;

  dbus_message_iter_open_container (main_iter,
				    DBUS_TYPE_STRUCT,
				    NULL, /* for structs */
				    &struct_iter);
  
  i = gconf_schema_get_type (schema);
  dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_INT32, &i);

  i = gconf_schema_get_list_type (schema);
  dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_INT32, &i);

  i = gconf_schema_get_car_type (schema);
  dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_INT32, &i);
  
  i = gconf_schema_get_cdr_type (schema);
  dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_INT32, &i);

  s = gconf_schema_get_locale (schema);
  utils_append_optional_string (&struct_iter, s);
  
  s = gconf_schema_get_short_desc (schema);
  utils_append_optional_string (&struct_iter, s);

  s = gconf_schema_get_long_desc (schema);
  utils_append_optional_string (&struct_iter, s);

  s = gconf_schema_get_owner (schema);
  utils_append_optional_string (&struct_iter, s);
  
  default_value = gconf_schema_get_default_value (schema);

  /* We don't need to do this, but it's much simpler */
  if (default_value)
    {
      gchar *encoded;
      
      encoded = gconf_value_encode (default_value);
      g_assert (encoded != NULL);

      dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_STRING, &encoded);
      g_free (encoded);
    }
  else
    {
      s = "";
      dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_STRING, &s);
    }
  
  if (!dbus_message_iter_close_container (main_iter, &struct_iter))
    g_error ("Out of memory");
}
static void
install_default_macros_list (GConfClient *client,
			     const char  *key,
			     int          offset)
{
	GConfSchema *schema;
	GConfValue  *value;
	GSList      *list = NULL;
	GError      *error;
	int          i;

	error = NULL;
	schema = gconf_client_get_schema (client, key, &error);
	if (error) {
		g_warning (_("Cannot get schema for %s: %s"), key, error->message);
		g_error_free (error);
		return;
	}

	/* gconf has started to return NULL with no error set. */
	g_return_if_fail (schema != NULL);

	/* Some sanity checks */
	g_assert (gconf_schema_get_type (schema) == GCONF_VALUE_LIST);
	g_assert (gconf_schema_get_list_type (schema) == GCONF_VALUE_STRING);

	value = gconf_value_new (GCONF_VALUE_LIST);
	gconf_value_set_list_type (value, GCONF_VALUE_STRING);

	for (i = 0; i < G_N_ELEMENTS (mc_default_macros); i++)
		list = g_slist_prepend (list,
					gconf_value_new_from_string (GCONF_VALUE_STRING,
								     G_STRUCT_MEMBER (char *, &mc_default_macros [i], offset),
								     NULL));
	list = g_slist_reverse (list);

	gconf_value_set_list_nocopy (value, list);
	list = NULL;

	gconf_schema_set_default_value_nocopy (schema, value);
	value = NULL;

	error = NULL;
	gconf_client_set_schema (client, key, schema, &error);
	if (error) {
		g_warning (_("Cannot set schema for %s: %s"), key, error->message);
		g_error_free (error);
	}

	gconf_schema_free (schema);

	printf (_("Set default list value for %s\n"), key);
}
Exemple #3
0
void*
nsvn_gconf_read_config_entry (const char *key,
                              const char *schema,
                              GConfClient *gcc)
{
  GConfSchema *gcs;
  GConfValueType gct;
  GError *err=NULL;
  void *ret=NULL;
  gboolean *bval = NULL;

  if (gcc == NULL || key == NULL)
    return NULL;

  /* Check for the presense of schema, if not return fail. */
  /* Get key details from schema. */
  /* Check for the presense of dir, if not create it. */
  /* if already present update it with new value. */
  gcs = gconf_client_get_schema (gcc, schema, &err);
  if (!gcs) return NULL;

  gct = gconf_schema_get_type (gcs);
  switch (gct)
    {
      case GCONF_VALUE_STRING:
        ret = (void*) gconf_client_get_string (gcc, key, &err);
        break;
      case GCONF_VALUE_INT:
        break;
      case GCONF_VALUE_FLOAT:
        break;
      case GCONF_VALUE_BOOL:
        bval = (gboolean*)g_malloc0(sizeof(gboolean));
        *bval = gconf_client_get_bool (gcc, key, &err);
        ret = (void*)bval;
        break;
      case GCONF_VALUE_LIST:
        break;
      case GCONF_VALUE_PAIR:
        break;
      default:
        break;
    }

  return ret;
}
Exemple #4
0
int
nsvn_gconf_write_config_entry (const char *key,
                               const char *schema,
                               void *value,
                               GConfClient *gcc)
{
  GConfSchema *gcs;
  GConfValueType gct;

  if (gcc == NULL || key == NULL)
    return 0;

  /* Check for the presense of schema, if not return fail. */
  /* Get key details from schema. */
  /* Check for the presense of dir, if not create it. */
  /* if already present update it with new value. */
  gcs = gconf_client_get_schema (gcc, schema, NULL);
  if (!gcs) return TRUE;

  gct = gconf_schema_get_type (gcs);
  switch (gct)
    {
      case GCONF_VALUE_STRING:
        gconf_client_set_string (gcc, key, (const char*)value, NULL);
        break;
      case GCONF_VALUE_INT:
        break;
      case GCONF_VALUE_FLOAT:
        break;
      case GCONF_VALUE_BOOL:
        gconf_client_set_bool (gcc, key, *((gboolean*)value), NULL);
        break;
      case GCONF_VALUE_LIST:
        break;
      case GCONF_VALUE_PAIR:
        break;
      default:
        break;
    }
  return 1;
}
static void gconf_dialog_onResetButtonPressed (GConfDialog* self, GtkButton* widget) {
	GConfSchema* schema;
	GConfValue* default_value;
	GtkWidget* target;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	schema = (GConfSchema*) g_object_get_data ((GObject*) widget, "gconf-schema");
	default_value = gconf_schema_get_default_value (schema);
	target = _g_object_ref0 ((GtkWidget*) g_object_get_data ((GObject*) widget, "target"));
	switch (gconf_schema_get_type (schema)) {
		case GCONF_VALUE_BOOL:
		{
			GtkWidget* _tmp0_;
			GtkCheckButton* checkbutton;
			checkbutton = _g_object_ref0 ((_tmp0_ = target, GTK_IS_CHECK_BUTTON (_tmp0_) ? ((GtkCheckButton*) _tmp0_) : NULL));
			gtk_toggle_button_set_active ((GtkToggleButton*) checkbutton, gconf_value_get_bool (default_value));
			_g_object_unref0 (checkbutton);
			break;
		}
		case GCONF_VALUE_STRING:
		{
			GtkWidget* _tmp1_;
			GtkEntry* entrybox;
			entrybox = _g_object_ref0 ((_tmp1_ = target, GTK_IS_ENTRY (_tmp1_) ? ((GtkEntry*) _tmp1_) : NULL));
			gtk_entry_set_text (entrybox, gconf_value_get_string (default_value));
			_g_object_unref0 (entrybox);
			break;
		}
		case GCONF_VALUE_INT:
		{
			GtkWidget* _tmp2_;
			GtkSpinButton* spin;
			spin = _g_object_ref0 ((_tmp2_ = target, GTK_IS_SPIN_BUTTON (_tmp2_) ? ((GtkSpinButton*) _tmp2_) : NULL));
			gtk_spin_button_set_value (spin, (double) gconf_value_get_int (default_value));
			_g_object_unref0 (spin);
			break;
		}
	}
	_g_object_unref0 (target);
}
static GtkWidget* gconf_dialog_create_proxy_widget (GConfDialog* self, const char* key, GError** error) {
	GtkWidget* result = NULL;
	GError * _inner_error_;
	GConfEntry* entry;
	GConfSchema* schema;
	const char* tooltip;
	GtkBox* row;
	GtkLabel* label;
	GtkWidget* action_widget;
	GtkWidget* render_widget;
	GConfEntry* _tmp10_;
	GtkButton* reset;
	GConfEntry* _tmp11_;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	_inner_error_ = NULL;
	entry = gconf_client_get_entry (self->priv->_default_client, key, NULL, TRUE, &_inner_error_);
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	schema = gconf_dialog_safely_get_schema (self, entry);
	tooltip = gconf_schema_get_long_desc (schema);
	row = (GtkBox*) g_object_ref_sink ((GtkHBox*) gtk_hbox_new (FALSE, 0));
	label = g_object_ref_sink ((GtkLabel*) gtk_label_new (gconf_schema_get_short_desc (schema)));
	gtk_label_set_justify (label, GTK_JUSTIFY_LEFT);
	gtk_widget_set_tooltip_text ((GtkWidget*) label, tooltip);
	action_widget = NULL;
	render_widget = NULL;
	switch (gconf_schema_get_type (schema)) {
		case GCONF_VALUE_BOOL:
		{
			GtkCheckButton* checkbox;
			gboolean _tmp0_;
			GtkWidget* _tmp1_;
			GtkWidget* _tmp2_;
			checkbox = g_object_ref_sink ((GtkCheckButton*) gtk_check_button_new ());
			_tmp0_ = gconf_client_get_bool (self->priv->_default_client, entry->key, &_inner_error_);
			if (_inner_error_ != NULL) {
				g_propagate_error (error, _inner_error_);
				_g_object_unref0 (checkbox);
				_g_object_unref0 (render_widget);
				_g_object_unref0 (action_widget);
				_g_object_unref0 (label);
				_g_object_unref0 (row);
				_gconf_schema_free0 (schema);
				_gconf_entry_unref0 (entry);
				return NULL;
			}
			gtk_toggle_button_set_active ((GtkToggleButton*) checkbox, _tmp0_);
			g_signal_connect_object ((GtkButton*) checkbox, "clicked", (GCallback) _gconf_dialog_onCheckButtonActivated_gtk_button_clicked, self, 0);
			gtk_container_add ((GtkContainer*) checkbox, (GtkWidget*) label);
			render_widget = (_tmp1_ = _g_object_ref0 ((GtkWidget*) checkbox), _g_object_unref0 (render_widget), _tmp1_);
			action_widget = (_tmp2_ = _g_object_ref0 (render_widget), _g_object_unref0 (action_widget), _tmp2_);
			_g_object_unref0 (checkbox);
			break;
		}
		case GCONF_VALUE_STRING:
		{
			GtkEntry* entrybox;
			GtkHBox* box;
			char* _tmp3_;
			char* _tmp4_;
			GtkWidget* _tmp5_;
			GtkWidget* _tmp6_;
			entrybox = g_object_ref_sink ((GtkEntry*) gtk_entry_new ());
			box = g_object_ref_sink ((GtkHBox*) gtk_hbox_new (FALSE, 0));
			_tmp3_ = gconf_client_get_string (self->priv->_default_client, entry->key, &_inner_error_);
			if (_inner_error_ != NULL) {
				g_propagate_error (error, _inner_error_);
				_g_object_unref0 (box);
				_g_object_unref0 (entrybox);
				_g_object_unref0 (render_widget);
				_g_object_unref0 (action_widget);
				_g_object_unref0 (label);
				_g_object_unref0 (row);
				_gconf_schema_free0 (schema);
				_gconf_entry_unref0 (entry);
				return NULL;
			}
			gtk_entry_set_text (entrybox, _tmp4_ = _tmp3_);
			_g_free0 (_tmp4_);
			gtk_box_pack_start ((GtkBox*) box, (GtkWidget*) label, FALSE, FALSE, (guint) 2);
			gtk_box_pack_start ((GtkBox*) box, (GtkWidget*) entrybox, FALSE, FALSE, (guint) 2);
			action_widget = (_tmp5_ = _g_object_ref0 ((GtkWidget*) entrybox), _g_object_unref0 (action_widget), _tmp5_);
			render_widget = (_tmp6_ = _g_object_ref0 ((GtkWidget*) box), _g_object_unref0 (render_widget), _tmp6_);
			_g_object_unref0 (box);
			_g_object_unref0 (entrybox);
			break;
		}
		case GCONF_VALUE_INT:
		{
			GtkHBox* box;
			GtkSpinButton* spin;
			gint _tmp7_;
			GtkWidget* _tmp8_;
			GtkWidget* _tmp9_;
			box = g_object_ref_sink ((GtkHBox*) gtk_hbox_new (FALSE, 0));
			spin = g_object_ref_sink ((GtkSpinButton*) gtk_spin_button_new_with_range ((double) (-100), (double) 200, (double) 1));
			_tmp7_ = gconf_client_get_int (self->priv->_default_client, entry->key, &_inner_error_);
			if (_inner_error_ != NULL) {
				g_propagate_error (error, _inner_error_);
				_g_object_unref0 (spin);
				_g_object_unref0 (box);
				_g_object_unref0 (render_widget);
				_g_object_unref0 (action_widget);
				_g_object_unref0 (label);
				_g_object_unref0 (row);
				_gconf_schema_free0 (schema);
				_gconf_entry_unref0 (entry);
				return NULL;
			}
			gtk_spin_button_set_value (spin, (double) _tmp7_);
			g_signal_connect_object (spin, "value-changed", (GCallback) _gconf_dialog_onSpinButtonValueChanged_gtk_spin_button_value_changed, self, 0);
			gtk_box_pack_start ((GtkBox*) box, (GtkWidget*) label, FALSE, FALSE, (guint) 2);
			gtk_box_pack_start ((GtkBox*) box, (GtkWidget*) spin, FALSE, FALSE, (guint) 2);
			action_widget = (_tmp8_ = _g_object_ref0 ((GtkWidget*) spin), _g_object_unref0 (action_widget), _tmp8_);
			render_widget = (_tmp9_ = _g_object_ref0 ((GtkWidget*) box), _g_object_unref0 (render_widget), _tmp9_);
			_g_object_unref0 (spin);
			_g_object_unref0 (box);
			break;
		}
		default:
		{
			result = (GtkWidget*) g_object_ref_sink ((GtkEventBox*) gtk_event_box_new ());
			_g_object_unref0 (render_widget);
			_g_object_unref0 (action_widget);
			_g_object_unref0 (label);
			_g_object_unref0 (row);
			_gconf_schema_free0 (schema);
			_gconf_entry_unref0 (entry);
			return result;
		}
	}
	gtk_widget_set_tooltip_text (action_widget, tooltip);
	g_object_set_data_full ((GObject*) action_widget, "gconf-entry", (_tmp10_ = entry, (_tmp10_ == NULL) ? NULL : gconf_entry_ref (_tmp10_), _tmp10_), gconf_entry_unref);
	g_object_set_data_full ((GObject*) action_widget, "gconf-schema", gconf_schema_copy (schema), gconf_schema_free);
	reset = g_object_ref_sink ((GtkButton*) gtk_button_new_from_stock (GTK_STOCK_CLEAR));
	gtk_widget_set_tooltip_text ((GtkWidget*) reset, _ ("Reset to the default value"));
	g_object_set_data_full ((GObject*) reset, "gconf-entry", (_tmp11_ = entry, (_tmp11_ == NULL) ? NULL : gconf_entry_ref (_tmp11_), _tmp11_), gconf_entry_unref);
	g_object_set_data_full ((GObject*) reset, "gconf-schema", gconf_schema_copy (schema), gconf_schema_free);
	g_object_set_data_full ((GObject*) reset, "target", _g_object_ref0 (action_widget), g_object_unref);
	g_signal_connect_object (reset, "clicked", (GCallback) _gconf_dialog_onResetButtonPressed_gtk_button_clicked, self, 0);
	gtk_box_pack_start (row, render_widget, FALSE, FALSE, (guint) 2);
	gtk_box_pack_end (row, (GtkWidget*) reset, FALSE, FALSE, (guint) 2);
	result = (GtkWidget*) row;
	_g_object_unref0 (reset);
	_g_object_unref0 (render_widget);
	_g_object_unref0 (action_widget);
	_g_object_unref0 (label);
	_gconf_schema_free0 (schema);
	_gconf_entry_unref0 (entry);
	return result;
}
Exemple #7
0
static void
node_set_schema_value(xmlNodePtr node,
                      GConfValue* value)
{
  GConfSchema* sc;
  const gchar* locale;
  const gchar* type;
  xmlNodePtr found = NULL;

  sc = gconf_value_get_schema (value);

  /* Set the types */
  if (gconf_schema_get_list_type (sc) != GCONF_VALUE_INVALID)
    {
      type = gconf_value_type_to_string(gconf_schema_get_list_type (sc));
      g_assert(type != NULL);
      my_xmlSetProp(node, "list_type", type);
    }
  if (gconf_schema_get_car_type (sc) != GCONF_VALUE_INVALID)
    {
      type = gconf_value_type_to_string(gconf_schema_get_car_type (sc));
      g_assert(type != NULL);
      my_xmlSetProp(node, "car_type", type);
    }
  if (gconf_schema_get_cdr_type (sc) != GCONF_VALUE_INVALID)
    {
      type = gconf_value_type_to_string(gconf_schema_get_cdr_type (sc));
      g_assert(type != NULL);
      my_xmlSetProp(node, "cdr_type", type);
    }
  
  /* unset this in case the node was previously a different type */
  my_xmlSetProp(node, "value", NULL);

  /* set the cross-locale attributes */
  my_xmlSetProp(node, "stype", gconf_value_type_to_string(gconf_schema_get_type (sc)));
  my_xmlSetProp(node, "owner", gconf_schema_get_owner (sc));

  locale = gconf_schema_get_locale(sc);

  gconf_log(GCL_DEBUG, "Setting XML node to schema with locale `%s'",
            locale);
  
  /* Find the node for this locale */

  found = find_schema_subnode_by_locale(node, locale);
  
  if (found == NULL)
    found = xmlNewChild(node, NULL, (xmlChar *)"local_schema", NULL);
  
  /* OK if these are set to NULL, since that unsets the property */
  my_xmlSetProp(found, "locale", gconf_schema_get_locale (sc));
  my_xmlSetProp(found, "short_desc", gconf_schema_get_short_desc (sc));

  free_childs(found);
  
  if (gconf_schema_get_default_value (sc) != NULL)
    {
      xmlNodePtr default_value_node;
      default_value_node = xmlNewChild(found, NULL, (xmlChar *)"default", NULL);
      node_set_value(default_value_node, gconf_schema_get_default_value (sc));
    }
  
  if (gconf_schema_get_long_desc (sc))
    {
      xmlNewChild(found, NULL, (xmlChar *)"longdesc",
                  (xmlChar *)gconf_schema_get_long_desc (sc));
    }
}