Ejemplo n.º 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");
}
Ejemplo n.º 2
0
static void
gnc_reset_warnings_add_one (GConfEntry *entry, GtkWidget *box)
{
    const gchar *name, *schema_name, *desc, *long_desc = NULL;
    GtkWidget *checkbox;
    GConfSchema *schema = NULL;

    ENTER(" ");
    name = strrchr(entry->key, '/') + 1;
    schema_name = gconf_entry_get_schema_name(entry);
    if (schema_name)
        schema = gnc_gconf_get_schema(NULL, schema_name, NULL);
    if (schema)
    {
        DEBUG("found schema %p", schema);
        desc = gconf_schema_get_short_desc(schema);
        DEBUG("description %s", desc);
        long_desc = gconf_schema_get_long_desc(schema);
        checkbox = gtk_check_button_new_with_label(desc ? desc : name);
        if (long_desc)
        {
            GtkTooltips *tips;
            tips = g_object_get_data(G_OBJECT(box), TIPS_STRING);
            if (!tips)
            {
                tips = gtk_tooltips_new();
                g_object_set_data(G_OBJECT(box), TIPS_STRING, tips);
            }
            gtk_tooltips_set_tip(tips, checkbox, long_desc, NULL);
        }
        gconf_schema_free(schema);
    }
    else
    {
        DEBUG("no schema");
        checkbox = gtk_check_button_new_with_label(name);
    }

    gtk_widget_set_name(checkbox, entry->key);
    g_signal_connect_swapped(G_OBJECT(checkbox), "toggled",
                             (GCallback)gnc_reset_warnings_update_widgets,
                             box);
    gtk_box_pack_start_defaults(GTK_BOX(box), checkbox);
    LEAVE(" ");
}
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;
}
Ejemplo n.º 4
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));
    }
}