示例#1
0
/* 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 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);
}
示例#3
0
文件: xml-entry.c 项目: GNOME/gconf
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));
    }
}