예제 #1
0
파일: defaultvalue.c 프로젝트: GYGit/gtk
static void
check_property (const char *output,
	        GParamSpec *pspec,
		GValue *value)
{
  GValue default_value = G_VALUE_INIT;
  char *v, *dv, *msg;

  if (g_param_value_defaults (pspec, value))
      return;

  g_value_init (&default_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
  g_param_value_set_default (pspec, &default_value);

  v = g_strdup_value_contents (value);
  dv = g_strdup_value_contents (&default_value);

  msg = g_strdup_printf ("%s %s.%s: %s != %s\n",
			 output,
			 g_type_name (pspec->owner_type),
			 pspec->name,
			 dv, v);
  g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__,
		       G_STRFUNC, msg);
  g_free (msg);

  g_free (v);
  g_free (dv);
  g_value_unset (&default_value);
}
예제 #2
0
gboolean g_value_compare(GValue * a, GValue * b) {
    if (a == NULL && b == NULL)
        return TRUE;
    if (a == NULL || b == NULL)
        return FALSE;
    if (G_VALUE_TYPE(a) != G_VALUE_TYPE(b))
        return FALSE;
    if (g_value_fits_pointer(a) && g_value_fits_pointer(b)) {
        return g_value_peek_pointer(a) == g_value_peek_pointer(b);
    } else {
        /* Since there is no builtin comparison function, we resort to
           comparing serialized strings. Yuck. */
        char * a_str;
        char * b_str;
        gboolean rval;
        a_str = g_strdup_value_contents(a);
        b_str = g_strdup_value_contents(b);
        rval = (0 == strcmp(a_str, b_str));
        amfree(a_str);
        amfree(b_str);
        return rval;
    }
    
    g_assert_not_reached();
}
static void
test_defaults (GType type, const char *name)
{
	GParamSpec **property_specs;
	guint n_property_specs;
	GObject *setting;
	int i;

	setting = g_object_new (type, NULL);

	property_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (setting), &n_property_specs);
	ASSERT (property_specs != NULL,
	        name, "couldn't find property specs for object of type '%s'",
	        g_type_name (G_OBJECT_TYPE (setting)));

	for (i = 0; i < n_property_specs; i++) {
		GParamSpec *prop_spec = property_specs[i];
		GValue value = G_VALUE_INIT;
		GValue defvalue = G_VALUE_INIT;
		char *actual, *expected;
		gboolean ok = FALSE;

		/* Ignore non-fundamental types since they won't really have
		 * defaults.
		 */
		if (!G_TYPE_IS_FUNDAMENTAL (prop_spec->value_type))
			continue;

		g_value_init (&value, prop_spec->value_type);
		g_object_get_property (G_OBJECT (setting), prop_spec->name, &value);

		g_value_init (&defvalue, prop_spec->value_type);
		g_param_value_set_default (prop_spec, &defvalue);

		actual = g_strdup_value_contents (&value);
		expected = g_strdup_value_contents (&defvalue);

		if (!strcmp (prop_spec->name, NM_SETTING_NAME)) {
			/* 'name' is always the setting name, not the default value */
			ok = !strcmp (nm_setting_get_name (NM_SETTING (setting)), name);
			g_free (expected);
			expected = g_strdup (name);
		} else
			ok = g_param_value_defaults (prop_spec, &value);

		ASSERT (ok,
		        name, "property '%s' value '%s' not the expected default value '%s'",
		        prop_spec->name, actual, expected);

		g_free (actual);
		g_free (expected);
		g_value_unset (&value);
		g_value_unset (&defvalue);
	}

	g_free (property_specs);
	g_object_unref (setting);
}
예제 #4
0
static void *
print_field_fn( IMAGE *im, const char *field, GValue *value )
{
	const char *extra;
	char *str_value;

	str_value = g_strdup_value_contents( value );
	printf( "%s: %s", field, str_value );
	g_free( str_value );

	/* Replace NULL static strings with "(null)".
	 */
#define NN( X ) ((X) ? (X) : "(null)")

	/* Look for known enums and decode them.
	 */
	extra = NULL;
	if( strcmp( field, "Coding" ) == 0 )
		extra = NN( im_Coding2char( g_value_get_int( value ) ) );
	else if( strcmp( field, "BandFmt" ) == 0 )
		extra = NN( im_BandFmt2char( g_value_get_int( value ) ) );
	else if( strcmp( field, "Type" ) == 0 )
		extra = NN( im_Type2char( g_value_get_int( value ) ) );
	else if( strcmp( field, "Compression" ) == 0 )
		extra = NN( im_Compression2char( g_value_get_int( value ) ) );

	if( extra )
		printf( " - %s", extra );

	printf( "\n" );

	return( NULL );
}
예제 #5
0
파일: header.c 프로젝트: alon/libvips
static void *
print_field_fn( VipsImage *image, const char *field, GValue *value, void *a )
{
	gboolean *many = (gboolean *) a;
	const char *extra;
	char *str_value;

	/* Look for known enums and decode them.
	 */
	extra = NULL;
	if( strcmp( field, "coding" ) == 0 )
		extra = vips_enum_nick( 
			VIPS_TYPE_CODING, g_value_get_int( value ) );
	else if( strcmp( field, "format" ) == 0 )
		extra = vips_enum_nick( 
			VIPS_TYPE_BAND_FORMAT, g_value_get_int( value ) );
	else if( strcmp( field, "interpretation" ) == 0 )
		extra = vips_enum_nick( 
			VIPS_TYPE_INTERPRETATION, g_value_get_int( value ) );

	if( *many ) 
		printf( "%s: ", image->filename );

	str_value = g_strdup_value_contents( value );
	printf( "%s: %s", field, str_value );
	g_free( str_value );

	if( extra )
		printf( " - %s", extra );

	printf( "\n" );

	return( NULL );
}
예제 #6
0
파일: main.c 프로젝트: yootaejong/ibaz
void print_properties(GObject *object)
{
	GObjectClass *oclass;
	GParamSpec **specs;
	guint n;
	guint i;

	oclass = G_OBJECT_GET_CLASS(object);
	specs = g_object_class_list_properties(oclass, &n);
	for (i = 0; i < n; i++) {
		GParamSpec *spec = specs[i];
		GValue value = { 0 };
		gchar *str;

		g_value_init(&value, spec->value_type);
		g_object_get_property(object, spec->name, &value);
		str = g_strdup_value_contents(&value);

		g_print("property '%s' is '%s'\n", spec->name, str);

		g_value_unset(&value);
		g_free(str);
	}

	g_free(specs);
}
예제 #7
0
void parole_debug_enum_full (const gchar *func, const gchar *file, gint line,
                 gint v_enum, GType type, const gchar *format, ...)
{
    va_list args;
    gchar *buffer;
    
    gchar *content = NULL;
    GValue __value__ = { 0, };
    
    g_value_init (&__value__, type);
    g_value_set_enum (&__value__, v_enum);
    
    content = g_strdup_value_contents (&__value__);
    
    va_start (args, format);
    g_vasprintf (&buffer, format, args);
    va_end (args);
    
    fprintf(stdout, "TRACE[%s:%d] %s(): ", file, line, func);
    fprintf(stdout, "%s: %s", buffer, content);
    fprintf(stdout, "\n");
    
    g_value_unset (&__value__); 
    g_free (content);
    g_free (buffer);
}
예제 #8
0
파일: header.c 프로젝트: zmack/libvips
static VipsMeta *
meta_new( VipsImage *image, const char *field, GValue *value )
{
    VipsMeta *meta;

    meta = g_new( VipsMeta, 1 );
    meta->im = image;
    meta->field = NULL;
    memset( &meta->value, 0, sizeof( GValue ) );
    meta->field = g_strdup( field );

    g_value_init( &meta->value, G_VALUE_TYPE( value ) );
    g_value_copy( value, &meta->value );

    image->meta_traverse = g_slist_append( image->meta_traverse, meta );
    g_hash_table_replace( image->meta, meta->field, meta );

#ifdef DEBUG
    {
        char *str_value;

        str_value = g_strdup_value_contents( value );
        printf( "meta_new: field %s, value = %s\n",
                field, str_value );
        g_free( str_value );
    }
#endif /*DEBUG*/

    return( meta );
}
예제 #9
0
static GObject *point3d_constructor (GType                  type,
                                     guint                  n_construct_properties,
                                     GObjectConstructParam *construct_properties) {
    GObject *obj;
    PointClass *parent_class = g_type_class_peek(TYPE_POINT);
    
    obj = G_OBJECT_CLASS(parent_class)->constructor(type,
                                        n_construct_properties,
                                        construct_properties);

    {
        int i;
        g_print("point3d_constructor(type=%s", g_type_name(type));
        for (i = 0; i < n_construct_properties; i++) {
            GParamSpec *pspec = construct_properties[i].pspec;
            GValue *value = construct_properties[i].value;
            gchar *contents = g_strdup_value_contents(value);
            g_print(", %s => %s", g_param_spec_get_name(pspec), contents);
            g_free(contents);
        }
        g_print(")\n");
    }
    
    return obj;
}
예제 #10
0
파일: header.c 프로젝트: alon/libvips
/* Print header, or parts of header.
 */
static int
print_header( IMAGE *im, gboolean many )
{
	if( !main_option_field ) {
		printf( "%s: ", im->filename );

		vips_object_print_summary( VIPS_OBJECT( im ) );

		if( main_option_all )
			(void) vips_image_map( im, print_field_fn, &many );
	}
	else if( strcmp( main_option_field, "getext" ) == 0 ) {
		if( im__has_extension_block( im ) ) {
			void *buf;
			int size;

			if( !(buf = im__read_extension_block( im, &size )) )
				return( -1 );
			printf( "%s", (char *) buf );
			im_free( buf );
		}
	}
	else if( strcmp( main_option_field, "Hist" ) == 0 ) 
		printf( "%s", im_history_get( im ) );
	else {
		GValue value = { 0 };
		GType type;

		if( im_header_get( im, main_option_field, &value ) )
			return( -1 );

		/* Display the save form, if there is one. This way we display
		 * something useful for ICC profiles, xml fields, etc.
		 */
		type = G_VALUE_TYPE( &value );
		if( g_value_type_transformable( type, IM_TYPE_SAVE_STRING ) ) {
			GValue save_value = { 0 };

			g_value_init( &save_value, IM_TYPE_SAVE_STRING );
			if( !g_value_transform( &value, &save_value ) ) 
				return( -1 );
			printf( "%s\n", im_save_string_get( &save_value ) );
			g_value_unset( &save_value );
		}
		else {
			char *str_value;

			str_value = g_strdup_value_contents( &value );
			printf( "%s\n", str_value );
			g_free( str_value );
		}

		g_value_unset( &value );
	}

	return( 0 );
}
예제 #11
0
CAMLprim value ocaml_gstreamer_message_parse_tag(value _msg)
{
  CAMLparam1(_msg);
  CAMLlocal4(v,s,t,ans);
  GstMessage *msg = Message_val(_msg);
  GstTagList *tags = NULL;
  const GValue *val;
  const gchar *tag;
  int taglen;
  int i, j, n;

  caml_release_runtime_system();
  gst_message_parse_tag(msg, &tags);
  taglen = gst_tag_list_n_tags(tags);
  caml_acquire_runtime_system();

  ans = caml_alloc_tuple(taglen);
  for(i = 0; i < taglen; i++)
    {
      t = caml_alloc_tuple(2);

      // Tag name
      tag = gst_tag_list_nth_tag_name(tags, i);
      Store_field(t, 0, caml_copy_string(tag));

      // Tag fields
      n = gst_tag_list_get_tag_size(tags, tag);
      v = caml_alloc_tuple(n);
      for (j = 0; j < n; j++)
        {
          val = gst_tag_list_get_value_index(tags, tag, j);
          if (G_VALUE_HOLDS_STRING(val)) {
              s = caml_copy_string(g_value_get_string(val));
            }
          else if (GST_VALUE_HOLDS_DATE_TIME(val)) {
              GstDateTime *dt = g_value_get_boxed(val);
              gchar *dt_str = gst_date_time_to_iso8601_string(dt);
              s = caml_copy_string(dt_str);
              g_free(dt_str);
            }
          else {
              //TODO: better typed handling of non-string values?
              char *vc = g_strdup_value_contents(val);
              s = caml_copy_string(vc);
              free(vc);
            }
          Store_field(v, j, s);
        }
      Store_field(t, 1, v);

      Store_field(ans, i, t);
    }

  gst_tag_list_unref(tags);

  CAMLreturn(ans);
}
예제 #12
0
static void
metadata_changed_cb (MafwRenderer *renderer,
		     gchar *key,
		     GValueArray *value,
		     gpointer user_data)
{
	g_print ("  Got metadata %s: %s\n",
		 key,
		 g_strdup_value_contents (&(value->values[0])));
}
예제 #13
0
static VALUE
rg_to_s(VALUE self)
{
    GValue *value;
    gchar *string_value;

    value = _SELF(self);
    string_value = g_strdup_value_contents(value);
    return CSTR2RVAL_FREE(string_value);
}
예제 #14
0
static void
print_value(const GValue *value, const gchar *name)
{
    gchar *value_string;

    value_string = g_strdup_value_contents(value);
    if (!value_string)
        return;
    g_print("  %s: %s\n", name, value_string);
    g_free(value_string);
}
예제 #15
0
// walk the options and fetch any requested outputs
void 
VOption::get_operation( VipsOperation *operation )
{
	std::list<Pair *>::iterator i;

	for( i = options.begin(); i != options.end(); ++i ) 
		if( ! (*i)->input ) {
			const char *name = (*i)->name;

			g_object_get_property( G_OBJECT( operation ),
				name, &(*i)->value );

#ifdef VIPS_DEBUG_VERBOSE
			printf( "get_operation: " );
			vips_object_print_name( VIPS_OBJECT( operation ) );
			char *str_value = g_strdup_value_contents( 
				&(*i)->value );
			printf( ".%s = %s\n", name, str_value );
			g_free( str_value );
#endif /*VIPS_DEBUG_VERBOSE*/

			GValue *value = &(*i)->value;
			GType type = G_VALUE_TYPE( value );

			if( type == VIPS_TYPE_IMAGE ) {
				// rebox object
				VipsImage *image = VIPS_IMAGE( 
					g_value_get_object( value ) );  
				*((*i)->vimage) = VImage( image ); 
			}
			else if( type == G_TYPE_INT ) 
				*((*i)->vint) = g_value_get_int( value ); 
			else if( type == G_TYPE_BOOLEAN ) 
				*((*i)->vbool) = g_value_get_boolean( value ); 
			else if( type == G_TYPE_DOUBLE ) 
				*((*i)->vdouble) = g_value_get_double( value ); 
			else if( type == VIPS_TYPE_ARRAY_DOUBLE ) {
				int length;
				double *array = 
					vips_value_get_array_double( value, 
					&length );
				int j;

				((*i)->vvector)->resize( length ); 
				for( j = 0; j < length; j++ )
					(*((*i)->vvector))[j] = array[j];
			}
			else if( type == VIPS_TYPE_BLOB ) {
				// our caller gets a reference
				*((*i)->vblob) = 
					(VipsBlob *) g_value_dup_boxed( value );
			}
		}
}
예제 #16
0
int
im__gprint( im_object obj )
{
	GValue *value = obj;
	char *str_value;

	str_value = g_strdup_value_contents( value );
	printf( "%s\n", str_value );
	g_free( str_value );

	return( 0 );
}
예제 #17
0
/**
 * gsf_doc_prop_dump:
 * @prop: #GsfDocProp
 *
 * A debugging utility to dump @prop as text via g_print
 * New in 1.14.2
 **/
void
gsf_doc_prop_dump (GsfDocProp const *prop)
{
	GValue const *val = gsf_doc_prop_get_val (prop);
	char *tmp;
	if (VAL_IS_GSF_DOCPROP_VECTOR ((GValue *)val)) {
		GValueArray *va = gsf_value_get_docprop_varray (val);
		unsigned i;

		for (i = 0 ; i < va->n_values; i++) {
			tmp = g_strdup_value_contents (
				g_value_array_get_nth (va, i));
			g_print ("\t[%u] = %s\n", i, tmp);
			g_free (tmp);
		}
	} else {
		tmp = g_strdup_value_contents (val);
		g_print ("\t= %s\n", tmp);
		g_free (tmp);
	}
}
예제 #18
0
static gboolean
print_factory_details_meta_data (GQuark field_id, const GValue * value,
    gpointer user_data)
{
  gchar *val = g_strdup_value_contents (value);
  gchar *key = g_strdup (g_quark_to_string (field_id));

  key[0] = g_ascii_toupper (key[0]);
  n_print ("  %s:\t\t%s\n", key, val);
  g_free (val);
  g_free (key);
  return TRUE;
}
예제 #19
0
파일: main.c 프로젝트: yootaejong/ibaz
void property_notified(GObject *object, GParamSpec *spec, gpointer data)
{
	GValue value = { 0 };
	gchar *str;

	g_value_init(&value, spec->value_type);
	g_object_get_property(object, spec->name, &value);
	str = g_strdup_value_contents(&value);

	g_print("property '%s' is set to '%s'\n", spec->name, str);

	g_value_unset(&value);
	g_free(str);
}
예제 #20
0
파일: wvSummary.c 프로젝트: gxf/heigong
static void
cb_print_property (char const *name, GsfDocProp const *prop, GHashTable * human_readable_names)
{
  GValue const *val = gsf_doc_prop_get_val  (prop);
  char *tmp;
  char const * _name;

  if((_name = g_hash_table_lookup(human_readable_names, name)) == NULL)
    _name = name;
  
  if (gsf_doc_prop_get_link (prop) != NULL)
    fprintf (stdout, "\t%s LINKED TO  -> '%s'\n",
	     _name, gsf_doc_prop_get_link (prop));
  else
    fprintf (stdout, "\t%s = ", _name);
  
  if (VAL_IS_GSF_DOCPROP_VECTOR ((GValue *)val)) {
    GValueArray *va = gsf_value_get_docprop_varray (val);
    unsigned i;
    
    fprintf(stdout, "[");
    for (i = 0 ; i < va->n_values; i++) {
      tmp = g_strdup_value_contents (g_value_array_get_nth (va, i));
      if(i != 0)
	fprintf(stdout, ", ");
      fprintf (stdout, "(%u, %s)", i, tmp);
      g_free (tmp);
    }
    fprintf(stdout, "]");
  } else {
    tmp = g_strdup_value_contents (val);
    fprintf (stdout, "%s", tmp);
    g_free (tmp);
  }

  fprintf (stdout, "\n");
}
예제 #21
0
static inline void
tidy_stylable_set_property_internal (TidyStylable       *stylable,
                                     GParamSpec         *pspec,
                                     const GValue       *value,
                                     GObjectNotifyQueue *nqueue)
{
  GValue tmp_value = { 0, };

  g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));

  if (!g_value_transform (value, &tmp_value))
    g_warning ("unable to set property `%s' of type `%s' from value of type `%s'",
               pspec->name,
               g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
               G_VALUE_TYPE_NAME (value));
  else if (g_param_value_validate (pspec, &tmp_value) &&
           !(pspec->flags & G_PARAM_LAX_VALIDATION))
    {
      gchar *contents = g_strdup_value_contents (value);

      g_warning ("value \"%s\" of type `%s' is invalid or out of range for property `%s' of type `%s'",
                 contents,
                 G_VALUE_TYPE_NAME (value),
                 pspec->name,
                 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
      g_free (contents);
    }
  else
    {
      TidyStyle *style = tidy_stylable_get_style (stylable);
      gchar *real_name;

      real_name = g_strconcat (g_param_spec_get_qdata (pspec, quark_real_owner),
                               "::",
                               pspec->name,
                               NULL);

      if (!tidy_style_has_property (style, real_name))
        tidy_style_add_property (style, real_name,
                                 G_PARAM_SPEC_VALUE_TYPE (pspec));

      tidy_style_set_property (style, real_name, &tmp_value);
      g_object_notify_queue_add (G_OBJECT (stylable), nqueue, pspec);

      g_free (real_name);
    }

  g_value_unset (&tmp_value);
}
static void
dump_message_dict (GHashTable *dict)
{
  char *key;
  GValue *value;
  GHashTableIter iter[1];

  g_hash_table_iter_init (iter, dict);
  while (g_hash_table_iter_next (iter, (gpointer)&key, (gpointer)&value))
    {
      char *s = g_strdup_value_contents (value);
      DEBUG ("%s = %s", key, s);
      g_free (s);
    }
}
예제 #23
0
static void renderer_metadata_changed_cb(MafwRenderer *self, const gchar *key,
        GValueArray *value)
{
    gint i;
    for (i = 0; i < value->n_values; i++)
    {
        gchar* contents = g_strdup_value_contents (&(value->values[i]));
        mtg_print_signal (MAFW_EXTENSION (self),
                          "Renderer::metadata-changed",
                          "Key: %s, Value:%s\n", key, contents);
        g_free (contents);
    }

    mdata_view_update(key, value);
}
예제 #24
0
void parole_debug_enum (const gchar *func, const gchar *file, gint line, 
                const gchar *text, gint v_enum, GType type)
{
    gchar *content = NULL;
    GValue __value__ = { 0, };

    g_value_init (&__value__, type);
    g_value_set_enum (&__value__, v_enum);
    
    content = g_strdup_value_contents (&__value__);
    
    fprintf(stdout, "TRACE[%s:%d] %s(): %s : %s", file, line , func, text, content);
    fprintf(stdout, "\n");
    
    g_value_unset (&__value__);                     
    g_free (content);
}
예제 #25
0
EXPORT_C
#endif

void
gst_object_default_deep_notify (GObject * object, GstObject * orig,
    GParamSpec * pspec, gchar ** excluded_props)
{
  GValue value = { 0, };        /* the important thing is that value.type = 0 */
  gchar *str = NULL;
  gchar *name = NULL;

  if (pspec->flags & G_PARAM_READABLE) {
    /* let's not print these out for excluded properties... */
    while (excluded_props != NULL && *excluded_props != NULL) {
      if (strcmp (pspec->name, *excluded_props) == 0)
        return;
      excluded_props++;
    }
    g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
    g_object_get_property (G_OBJECT (orig), pspec->name, &value);

    /* FIXME: handle flags */
    if (G_IS_PARAM_SPEC_ENUM (pspec)) {
      GEnumValue *enum_value;
      GEnumClass *klass = G_ENUM_CLASS (g_type_class_ref (pspec->value_type));

      enum_value = g_enum_get_value (klass, g_value_get_enum (&value));

      str = g_strdup_printf ("%s (%d)", enum_value->value_nick,
          enum_value->value);
      g_type_class_unref (klass);
    } else {
      str = g_strdup_value_contents (&value);
    }
    name = gst_object_get_path_string (orig);
    g_print ("%s: %s = %s\n", name, pspec->name, str);
    g_free (name);
    g_free (str);
    g_value_unset (&value);
  } else {
    name = gst_object_get_path_string (orig);
    g_warning ("Parameter %s not readable in %s.", pspec->name, name);
    g_free (name);
  }
}
예제 #26
0
static gchar *
debug_dump_get_element_params (GstElement * element)
{
  gchar *param_name = NULL;
  GParamSpec **properties, *property;
  GValue value = { 0, };
  guint i, number_of_properties;
  gchar *tmp, *value_str;

  /* get paramspecs and show non-default properties */
  properties =
      g_object_class_list_properties (G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS
          (element)), &number_of_properties);
  if (properties) {
    for (i = 0; i < number_of_properties; i++) {
      property = properties[i];

      /* ski some properties */
      if (!(property->flags & G_PARAM_READABLE))
        continue;
      if (!strcmp (property->name, "name"))
        continue;

      g_value_init (&value, property->value_type);
      g_object_get_property (G_OBJECT (element), property->name, &value);
      if (!(g_param_value_defaults (property, &value))) {
        tmp = g_strdup_value_contents (&value);
        value_str = g_strescape (tmp, NULL);
        g_free (tmp);
        if (param_name) {
          tmp = param_name;
          param_name = g_strdup_printf ("%s\\n%s=%s",
              tmp, property->name, value_str);
          g_free (tmp);
        } else {
          param_name = g_strdup_printf ("\\n%s=%s", property->name, value_str);
        }
        g_free (value_str);
      }
      g_value_unset (&value);
    }
    g_free (properties);
  }
  return param_name;
}
예제 #27
0
char *
_gtk_css_value_to_string (const GValue *value)
{
  ToStringFunc func;

  css_string_funcs_init ();

  func = g_hash_table_lookup (to_string_funcs,
                              GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
  if (func == NULL)
    func = g_hash_table_lookup (to_string_funcs,
                                GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));

  if (func)
    return func (value);

  return g_strdup_value_contents (value);
}
예제 #28
0
static void 
gnac_properties_set_entry(const gchar  *entry_name, 
                          const GValue *entry_value)
{
  GtkWidget *widget = gnac_properties_get_widget(entry_name);
  if (!widget) {
    gnac_properties_set_property(entry_name, entry_value);
    return;
  }

  if (!entry_value) {
    gnac_properties_reset_field(widget);
    return;
  }

  if (LIBGNAC_METADATA_TAG_IS_IMAGE(entry_name)) {
    gnac_properties_set_image(widget, entry_value);
    return;
  }

  GType type = G_VALUE_TYPE(entry_value);
  switch (type) {

    case G_TYPE_STRING:
      gtk_entry_set_text(GTK_ENTRY(widget), g_value_get_string(entry_value));
      return;

    case G_TYPE_UINT: {
      gdouble value;
      value = (gdouble) g_value_get_uint(entry_value);
      gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), value);
      gtk_spin_button_set_range(GTK_SPIN_BUTTON(widget), value, value);
      return;
    }
    
    default:
      gtk_entry_set_text(GTK_ENTRY(widget),
          g_strdup_value_contents(entry_value));
      libgnac_debug("%s has an unknown type: %s",
          entry_name, g_type_name(type));
      return;
  }
}
예제 #29
0
파일: header.c 프로젝트: Fasjul/libvips
static VipsMeta *
meta_new( VipsImage *image, const char *field, GValue *value )
{
	VipsMeta *meta;

	meta = g_new( VipsMeta, 1 );
	meta->im = image;
	meta->field = NULL;
	memset( &meta->value, 0, sizeof( GValue ) );
	meta->field = g_strdup( field );

	/* Special case: we don't want to have G_STRING on meta. They will be
	 * copied down pipelines, plus some of our API (like
	 * vips_image_get_string()) assumes that the GValue is a refstring and
	 * that read-only pointers can be handed out.
	 *
	 * Turn G_TYPE_STRING into VIPS_TYPE_REF_STRING.
	 */
	if( G_VALUE_TYPE( value ) == G_TYPE_STRING )
		g_value_init( &meta->value, VIPS_TYPE_REF_STRING );
	else
		g_value_init( &meta->value, G_VALUE_TYPE( value ) );

	/* We don't do any conversions that can fail.
	 */
	(void) g_value_transform( value, &meta->value );

	image->meta_traverse = g_slist_append( image->meta_traverse, meta );
	g_hash_table_replace( image->meta, meta->field, meta ); 

#ifdef DEBUG
{
	char *str_value;

	str_value = g_strdup_value_contents( value );
	printf( "meta_new: field %s, value = %s\n", 
		field, str_value );
	g_free( str_value );
}
#endif /*DEBUG*/

	return( meta );
}
예제 #30
0
// walk the options and set props on the operation 
void 
VOption::set_operation( VipsOperation *operation )
{
	std::list<Pair *>::iterator i;

	for( i = options.begin(); i != options.end(); ++i ) 
		if( (*i)->input ) {
#ifdef VIPS_DEBUG_VERBOSE
			printf( "set_operation: " );
			vips_object_print_name( VIPS_OBJECT( operation ) );
			char *str_value = g_strdup_value_contents( &(*i)->value );
			printf( ".%s = %s\n", (*i)->name, str_value );
			g_free( str_value );
#endif /*VIPS_DEBUG_VERBOSE*/

			set_property( VIPS_OBJECT( operation ),
				(*i)->name, &(*i)->value );
		}
}