コード例 #1
0
static gboolean
check_write_uint_param (GParamSpec * paramspec, GObject * toCheck)
{
  guint check1, check2;

  check1 = G_PARAM_SPEC_UINT (paramspec)->minimum;
  g_object_set (toCheck, paramspec->name, check1, NULL);

  check2 = G_PARAM_SPEC_UINT (paramspec)->maximum;
  g_object_set (toCheck, paramspec->name, check2, NULL);

  return TRUE;
}
コード例 #2
0
static gboolean
check_readwrite_uint_param (GParamSpec * paramspec, GObject * toCheck)
{
  guint ival, oval;
  gboolean ret = TRUE;

  ival = G_PARAM_SPEC_UINT (paramspec)->minimum;
  g_object_set (toCheck, paramspec->name, ival, NULL);
  g_object_get (toCheck, paramspec->name, &oval, NULL);
  if (ival != oval) {
    GST_WARNING ("property read/write minimum check failed for : %s : %u != %u",
        paramspec->name, ival, oval);
    ret = FALSE;
  }
  /*
     ival=G_PARAM_SPEC_UINT(paramspec)->maximum;
     g_object_set(toCheck,paramspec->name, ival,NULL);
     g_object_get(toCheck,paramspec->name,&oval,NULL);
     if(ival!=oval) {
     GST_WARNING("property read/write maximum check failed for : %s : %u != %u",
     paramspec->name,
     ival,oval
     );
     ret=FALSE;
     }
   */
  return ret;
}
コード例 #3
0
ファイル: json.c プロジェクト: GNOME/gegl
static GParamSpec *
copy_param_spec(GParamSpec *in, const gchar *name) {

  const gchar * blurb = g_param_spec_get_blurb(in);
  GParamSpec *out = NULL;

  GParamFlags flags = G_PARAM_READWRITE;

  // TODO: handle more things
  if (G_IS_PARAM_SPEC_FLOAT(in)) {
    GParamSpecFloat *f = G_PARAM_SPEC_FLOAT(in);
    out = g_param_spec_double(name, name, blurb, f->minimum, f->maximum, f->default_value, flags);
  } else if (G_IS_PARAM_SPEC_DOUBLE(in)) {
    GParamSpecDouble *d = G_PARAM_SPEC_DOUBLE(in);
    out = g_param_spec_double(name, name, blurb, d->minimum, d->maximum, d->default_value, flags);
  } else if (G_IS_PARAM_SPEC_INT(in)) {
    GParamSpecInt *i = G_PARAM_SPEC_INT(in);
    out = g_param_spec_int(name, name, blurb, i->minimum, i->maximum, i->default_value, flags);
  } else if (G_IS_PARAM_SPEC_UINT(in)) {
    GParamSpecUInt *u = G_PARAM_SPEC_UINT(in);
    out = g_param_spec_int(name, name, blurb, u->minimum, u->maximum, u->default_value, flags);
  } else if (G_IS_PARAM_SPEC_LONG(in)) {
    GParamSpecLong *l = G_PARAM_SPEC_LONG(in);
    out = g_param_spec_int(name, name, blurb, l->minimum, l->maximum, l->default_value, flags);
  } else if (GEGL_IS_PARAM_SPEC_COLOR(in)) {
    GeglColor *default_value = gegl_param_spec_color_get_default(in);
    out = gegl_param_spec_color(name, name, blurb, default_value, flags);
  } else {
    g_critical("json: Unknown param spec type for property %s", g_param_spec_get_nick(in));
  }
  return out;
}
コード例 #4
0
ファイル: paramspec.c プロジェクト: UIKit0/stetic
gboolean
stetic_param_spec_get_default (GParamSpec *pspec, GValue *value)
{
	g_value_init (value, pspec->value_type);

	if (G_IS_PARAM_SPEC_CHAR (pspec))
		g_value_set_char (value, G_PARAM_SPEC_CHAR (pspec)->default_value);
	else if (G_IS_PARAM_SPEC_UCHAR (pspec))
		g_value_set_uchar (value, G_PARAM_SPEC_UCHAR (pspec)->default_value);
	else if (G_IS_PARAM_SPEC_INT (pspec))
		g_value_set_int (value, G_PARAM_SPEC_INT (pspec)->default_value);
	else if (G_IS_PARAM_SPEC_UINT (pspec))
		g_value_set_uint (value, G_PARAM_SPEC_UINT (pspec)->default_value);
	else if (G_IS_PARAM_SPEC_LONG (pspec))
		g_value_set_long (value, G_PARAM_SPEC_LONG (pspec)->default_value);
	else if (G_IS_PARAM_SPEC_ULONG (pspec))
		g_value_set_ulong (value, G_PARAM_SPEC_ULONG (pspec)->default_value);
	else if (G_IS_PARAM_SPEC_INT64 (pspec))
		g_value_set_int64 (value, G_PARAM_SPEC_INT64 (pspec)->default_value);
	else if (G_IS_PARAM_SPEC_UINT64 (pspec))
		g_value_set_uint64 (value, G_PARAM_SPEC_UINT64 (pspec)->default_value);
	else if (G_IS_PARAM_SPEC_FLOAT (pspec))
		g_value_set_float (value, G_PARAM_SPEC_FLOAT (pspec)->default_value);
	else if (G_IS_PARAM_SPEC_DOUBLE (pspec))
		g_value_set_double (value, G_PARAM_SPEC_DOUBLE (pspec)->default_value);
	else if (G_IS_PARAM_SPEC_BOOLEAN (pspec))
		g_value_set_boolean (value, G_PARAM_SPEC_BOOLEAN (pspec)->default_value);
	else if (G_IS_PARAM_SPEC_UNICHAR (pspec))
		g_value_set_uint (value, G_PARAM_SPEC_UNICHAR (pspec)->default_value);
	else if (G_IS_PARAM_SPEC_STRING (pspec))
		g_value_set_static_string (value, G_PARAM_SPEC_STRING (pspec)->default_value);
	else
		return FALSE;
	return TRUE;
}
コード例 #5
0
ファイル: paramspec.c プロジェクト: UIKit0/stetic
gboolean
stetic_param_spec_get_maximum (GParamSpec *pspec, GValue *value)
{
	g_value_init (value, pspec->value_type);

	if (G_IS_PARAM_SPEC_CHAR (pspec))
		g_value_set_char (value, G_PARAM_SPEC_CHAR (pspec)->maximum);
	else if (G_IS_PARAM_SPEC_UCHAR (pspec))
		g_value_set_uchar (value, G_PARAM_SPEC_UCHAR (pspec)->maximum);
	else if (G_IS_PARAM_SPEC_INT (pspec))
		g_value_set_int (value, G_PARAM_SPEC_INT (pspec)->maximum);
	else if (G_IS_PARAM_SPEC_UINT (pspec))
		g_value_set_uint (value, G_PARAM_SPEC_UINT (pspec)->maximum);
	else if (G_IS_PARAM_SPEC_LONG (pspec))
		g_value_set_long (value, G_PARAM_SPEC_LONG (pspec)->maximum);
	else if (G_IS_PARAM_SPEC_ULONG (pspec))
		g_value_set_ulong (value, G_PARAM_SPEC_ULONG (pspec)->maximum);
	else if (G_IS_PARAM_SPEC_INT64 (pspec))
		g_value_set_int64 (value, G_PARAM_SPEC_INT64 (pspec)->maximum);
	else if (G_IS_PARAM_SPEC_UINT64 (pspec))
		g_value_set_uint64 (value, G_PARAM_SPEC_UINT64 (pspec)->maximum);
	else if (G_IS_PARAM_SPEC_FLOAT (pspec))
		g_value_set_float (value, G_PARAM_SPEC_FLOAT (pspec)->maximum);
	else if (G_IS_PARAM_SPEC_DOUBLE (pspec))
		g_value_set_double (value, G_PARAM_SPEC_DOUBLE (pspec)->maximum);
	else
		return FALSE;
	return TRUE;
}
コード例 #6
0
static gboolean
check_read_uint_param (GParamSpec * paramspec, GObject * toCheck)
{
  guint check;
  gboolean ret = FALSE;

  g_object_get (toCheck, paramspec->name, &check, NULL);
  if ((check >= G_PARAM_SPEC_UINT (paramspec)->minimum) &&
      (check <= G_PARAM_SPEC_UINT (paramspec)->maximum)) {
    ret = TRUE;
  } else {
    GST_WARNING ("property read range check failed for : %s : %u <= %u <= %u",
        paramspec->name,
        G_PARAM_SPEC_UINT (paramspec)->minimum,
        check, G_PARAM_SPEC_UINT (paramspec)->maximum);
  }
  return ret;
}
コード例 #7
0
static void
param_uint_init (GParamSpec *pspec)
{
  GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
  
  uspec->minimum = 0;
  uspec->maximum = 0xffffffff;
  uspec->default_value = 0;
}
コード例 #8
0
ファイル: qtcamiso.cpp プロジェクト: ballock/cameraplus
unsigned int QtCamIso::defaultValue() {
  GParamSpec *p = d_ptr->paramSpec();

  if (p && G_IS_PARAM_SPEC_UINT(p)) {
    return G_PARAM_SPEC_UINT(p)->default_value;
  }

  return 0;
}
コード例 #9
0
ファイル: qtcamiso.cpp プロジェクト: ballock/cameraplus
unsigned int QtCamIso::maximumValue() {
  GParamSpec *p = d_ptr->paramSpec();

  if (p && G_IS_PARAM_SPEC_UINT(p)) {
    return G_PARAM_SPEC_UINT(p)->maximum;
  }

  return 0;
}
コード例 #10
0
ファイル: uca-pco-camera.c プロジェクト: MariaMatveeva/libuca
static void
property_override_default_guint_value (GObjectClass *oclass, const gchar *property_name, guint new_default)
{
    GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (g_object_class_find_property (oclass, property_name));

    if (pspec != NULL)
        pspec->default_value = new_default;
    else
        g_warning ("pspec for %s not found\n", property_name);
}
コード例 #11
0
static gboolean
param_uint_validate (GParamSpec *pspec,
		     GValue     *value)
{
  GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
  guint oval = value->data[0].v_uint;
  
  value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
  
  return value->data[0].v_uint != oval;
}
コード例 #12
0
ファイル: property.cpp プロジェクト: dulton/switcher
// make json formated description
void Property::make_description() {
  if (nullptr == property_) {
    g_warning("%s: cannot make description from a nullptr property",
              __PRETTY_FUNCTION__);
    return;
  }
  GValue value = G_VALUE_INIT;
  g_value_init(&value, property_->value_type);

  g_object_get_property(object_, property_->name, &value);
  json_description_->reset();
  json_description_->begin_object();
  // long name
  json_description_->add_string_member("name", long_name_.c_str());
  // name
  json_description_->add_string_member("id", name_.c_str());
  // nickname
  // json_description_->add_string_member ("nickname", g_param_spec_get_nick (property_));

  // short description
  json_description_->add_string_member("description",
                                       g_param_spec_get_blurb(property_));
  json_description_->add_string_member("parent",
                                       get_category().c_str());
  json_description_->add_int_member("order",
                                    get_position_weight());
  // name
  // json_description_->add_string_member ("internal name", g_param_spec_get_name (property_));
  if (property_->flags &G_PARAM_WRITABLE)
    json_description_->add_string_member("writable", "true");
  else
    json_description_->add_string_member("writable", "false");
  switch (G_VALUE_TYPE(&value)) {
    case G_TYPE_STRING:
      {
        const char *string_val = g_value_get_string(&value);
        json_description_->add_string_member("type", "string");
        if (string_val == nullptr)
          json_description_->add_string_member("default value", "");
        else
          json_description_->add_string_member("default value", string_val);
        break;
      }
    case G_TYPE_BOOLEAN:
      {
        gboolean bool_val = g_value_get_boolean(&value);
        json_description_->add_string_member("type", "boolean");
        if (bool_val)
          json_description_->add_string_member("default value", "true");
        else
          json_description_->add_string_member("default value", "false");
        break;
      }
    case G_TYPE_ULONG:
      {
        GParamSpecULong *pulong = G_PARAM_SPEC_ULONG(property_);

        json_description_->add_string_member("type", "ulong");
        gchar *min = g_strdup_printf("%lu", pulong->minimum);
        gchar *max = g_strdup_printf("%lu", pulong->maximum);
        gchar *default_value =
            g_strdup_printf("%lu", g_value_get_ulong(&value));
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_LONG:
      {
        GParamSpecLong *plong = G_PARAM_SPEC_LONG(property_);
        gchar *min = g_strdup_printf("%ld", plong->minimum);
        gchar *max = g_strdup_printf("%ld", plong->maximum);
        gchar *default_value =
            g_strdup_printf("%ld", g_value_get_ulong(&value));
        json_description_->add_string_member("type", "long");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_UINT:
      {
        GParamSpecUInt *puint = G_PARAM_SPEC_UINT(property_);
        gchar *min = g_strdup_printf("%u", puint->minimum);
        gchar *max = g_strdup_printf("%u", puint->maximum);
        gchar *default_value =
            g_strdup_printf("%u", g_value_get_uint(&value));
        json_description_->add_string_member("type", "uint");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_INT:
      {
        GParamSpecInt *pint = G_PARAM_SPEC_INT(property_);
        gchar *min = g_strdup_printf("%d", pint->minimum);
        gchar *max = g_strdup_printf("%d", pint->maximum);
        gchar *default_value = g_strdup_printf("%d", g_value_get_int(&value));
        json_description_->add_string_member("type", "int");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_UINT64:
      {
        GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64(property_);
        gchar *min = g_strdup_printf("%" G_GUINT64_FORMAT, puint64->minimum);
        gchar *max = g_strdup_printf("%" G_GUINT64_FORMAT, puint64->maximum);
        gchar *default_value = g_strdup_printf("%" G_GUINT64_FORMAT,
                                               g_value_get_uint64(&value));
        json_description_->add_string_member("type", "uint64");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_INT64:
      {
        GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64(property_);
        gchar *min = g_strdup_printf("%" G_GINT64_FORMAT, pint64->minimum);
        gchar *max = g_strdup_printf("%" G_GINT64_FORMAT, pint64->maximum);
        gchar *default_value =
            g_strdup_printf("%" G_GINT64_FORMAT, g_value_get_int64(&value));
        json_description_->add_string_member("type", "int64");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_FLOAT:
      {
        GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT(property_);
        gchar *min = g_strdup_printf("%.7g", pfloat->minimum);
        gchar *max = g_strdup_printf("%.7g", pfloat->maximum);
        gchar *default_value =
            g_strdup_printf("%.7g", g_value_get_float(&value));
        json_description_->add_string_member("type", "float");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_DOUBLE:
      {
        GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE(property_);
        gchar *min = g_strdup_printf("%.7g", pdouble->minimum);
        gchar *max = g_strdup_printf("%.7g", pdouble->maximum);
        gchar *default_value =
            g_strdup_printf("%.7g", g_value_get_double(&value));
        json_description_->add_string_member("type", "double");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    default:
      if (property_->value_type == GST_TYPE_CAPS) {
        const GstCaps *caps = gst_value_get_caps(&value);
        json_description_->add_string_member("type", "caps");
        if (!caps)
          json_description_->add_string_member("default value", "");
        else
          json_description_->add_string_member("default value",
                                               gst_caps_to_string(caps));
      } else if (G_IS_PARAM_SPEC_ENUM(property_)) {
        GEnumValue *values;
        guint j = 0;
        gint enum_value;
        const gchar *value_nick = "";
        const gchar *value_name = "";
        json_description_->add_string_member("type", "enum");
        values =
            G_ENUM_CLASS(g_type_class_ref(property_->value_type))->values;
        enum_value = g_value_get_enum(&value);
        while (values[j].value_name) {
          if (values[j].value == enum_value) {
            value_nick = values[j].value_nick;
            value_name = values[j].value_name;
          }
          j++;
        }

        json_description_->set_member_name("default value");
        json_description_->begin_object();
        gchar *value = g_strdup_printf("%d", enum_value);
        json_description_->add_string_member("value", value);
        g_free(value);
        json_description_->add_string_member("nick", value_nick);
        json_description_->add_string_member("name", value_name);
        json_description_->end_object();

        // g_debug ("Enum \"%s\" Default: %d, \"%s\" \"%s\"",
        //  g_type_name (G_VALUE_TYPE (&value)),
        //  enum_value,
        //  value_nick,
        //  value_name);

        j = 0;

        json_description_->set_member_name("values");
        json_description_->begin_array();
        while (values[j].value_name) {
          json_description_->begin_object();
          json_description_->add_string_member("name", values[j].value_name);
          json_description_->add_string_member("nick", values[j].value_nick);
          gchar *values_value = g_strdup_printf("%d", values[j].value);
          json_description_->add_string_member("value", values_value);
          g_free(values_value);
          json_description_->end_object();
          j++;
        }
        json_description_->end_array();

        /* g_type_class_unref (ec); */
      } else if (G_IS_PARAM_SPEC_FLAGS(property_)) {
        g_debug("warning: param spec flags not handled");
        // GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (property_);
        // GFlagsValue *vals;
        // gchar *cur;

        // vals = pflags->flags_class->values;

        // cur = flags_to_string (vals, g_value_get_flags (&value));

        // g_debug ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
        //    g_type_name (G_VALUE_TYPE (&value)),
        //    g_value_get_flags (&value), cur);

        // while (vals[0].value_name) {
        //   g_debug ("");
        //   if (_name)
        //     g_debug ("%s", _name);
        //   g_debug ("%-23.23s    (0x%08x): %-16s - %s", "",
        //      vals[0].value, vals[0].value_nick, vals[0].value_name);
        //   ++vals;
        // }

        // g_free (cur);
      } else if (G_IS_PARAM_SPEC_OBJECT(property_)) {
        g_debug("warning: param spec object not handled");
        // g_debug ("%-23.23s Object of type \"%s\"", "",
        //  g_type_name (property_->value_type));
      } else if (G_IS_PARAM_SPEC_BOXED(property_)) {
        g_debug("warning: param spec boxed not handled");
        // g_debug ("%-23.23s Boxed pointer of type \"%s\"", "",
        //  g_type_name (property_->value_type));
      } else if (G_IS_PARAM_SPEC_POINTER(property_)) {
        g_debug("warning: param spec pointer not handled");
        // if (property_->value_type != G_TYPE_POINTER) {
        //   g_debug ("%-23.23s Pointer of type \"%s\".", "",
        //    g_type_name (property_->value_type));
        // } else if (property_->value_type == G_TYPE_VALUE_ARRAY) {
        // GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (property_);
        // g_debug ("warning: array not handled");
        // if (pvarray->element_spec) {
        //   g_debug ("%-23.23s Array of GValues of type \"%s\"", "",
        //    g_type_name (pvarray->element_spec->value_type));
        // } else {
        //   g_debug ("%-23.23s Array of GValues", "");
        // }
      } else if (GST_IS_PARAM_SPEC_FRACTION(property_)) {
        GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION(property_);
        json_description_->add_string_member("type", "fraction");
        gchar *minnum = g_strdup_printf("%d", pfraction->min_num);
        gchar *minden = g_strdup_printf("%d", pfraction->min_den);
        gchar *maxnum = g_strdup_printf("%d", pfraction->max_num);
        gchar *maxden = g_strdup_printf("%d", pfraction->max_den);
        gchar *defaultnum = g_strdup_printf("%d",
                                            gst_value_get_fraction_numerator
                                            (&value));
        gchar *defaultden = g_strdup_printf("%d",
                                            gst_value_get_fraction_denominator
                                            (&value));
        json_description_->add_string_member("minimum numerator", minnum);
        json_description_->add_string_member("maximum numerator", minden);
        json_description_->add_string_member("minimum denominator", maxnum);
        json_description_->add_string_member("maximum denominator", maxden);
        json_description_->add_string_member("default numerator", defaultnum);
        json_description_->add_string_member("default denominator",
                                             defaultden);
        g_free(minnum);
        g_free(minden);
        g_free(maxnum);
        g_free(maxden);
        g_free(defaultnum);
        g_free(defaultden);
        // g_debug ("Range: %d/%d - %d/%d Default: %d/%d ",
        //  pfraction->min_num, pfraction->min_den,
        //  pfraction->max_num, pfraction->max_den,
        //  gst_value_get_fraction_numerator (&value),
        //  gst_value_get_fraction_denominator (&value));
      } else {
        g_warning("warning: unknown type");
        // g_debug ("%-23.23s Unknown type %ld \"%s\"", "", property_->value_type,
        //  g_type_name (property_->value_type));
      }
      break;
  }
  g_value_reset(&value);
  json_description_->end_object();
}
コード例 #13
0
static gboolean
gst_interpolation_control_source_bind (GstControlSource * source,
    GParamSpec * pspec)
{
  GType type, base;
  GstInterpolationControlSource *self =
      GST_INTERPOLATION_CONTROL_SOURCE (source);
  gboolean ret = TRUE;

  /* get the fundamental base type */
  self->priv->type = base = type = G_PARAM_SPEC_VALUE_TYPE (pspec);
  while ((type = g_type_parent (type)))
    base = type;

  self->priv->base = base;
  /* restore type */
  type = self->priv->type;

  if (!gst_interpolation_control_source_set_interpolation_mode (self,
          self->priv->interpolation_mode))
    return FALSE;

  switch (base) {
    case G_TYPE_INT:{
      GParamSpecInt *tpspec = G_PARAM_SPEC_INT (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_int (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_int (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_int (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_UINT:{
      GParamSpecUInt *tpspec = G_PARAM_SPEC_UINT (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_uint (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_uint (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_uint (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_LONG:{
      GParamSpecLong *tpspec = G_PARAM_SPEC_LONG (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_long (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_long (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_long (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_ULONG:{
      GParamSpecULong *tpspec = G_PARAM_SPEC_ULONG (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_ulong (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_ulong (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_ulong (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_INT64:{
      GParamSpecInt64 *tpspec = G_PARAM_SPEC_INT64 (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_int64 (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_int64 (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_int64 (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_UINT64:{
      GParamSpecUInt64 *tpspec = G_PARAM_SPEC_UINT64 (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_uint64 (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_uint64 (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_uint64 (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_FLOAT:{
      GParamSpecFloat *tpspec = G_PARAM_SPEC_FLOAT (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_float (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_float (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_float (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_DOUBLE:{
      GParamSpecDouble *tpspec = G_PARAM_SPEC_DOUBLE (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_double (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_double (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_double (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_BOOLEAN:{
      GParamSpecBoolean *tpspec = G_PARAM_SPEC_BOOLEAN (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_boolean (&self->priv->default_value, tpspec->default_value);
      break;
    }
    case G_TYPE_ENUM:{
      GParamSpecEnum *tpspec = G_PARAM_SPEC_ENUM (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_enum (&self->priv->default_value, tpspec->default_value);
      break;
    }
    case G_TYPE_STRING:{
      GParamSpecString *tpspec = G_PARAM_SPEC_STRING (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_string (&self->priv->default_value, tpspec->default_value);
      break;
    }
    default:
      GST_WARNING ("incomplete implementation for paramspec type '%s'",
          G_PARAM_SPEC_TYPE_NAME (pspec));
      ret = FALSE;
      break;
  }

  if (ret) {
    self->priv->valid_cache = FALSE;
    self->priv->nvalues = 0;
  } else {
    gst_interpolation_control_source_reset (self);
  }

  return ret;
}
コード例 #14
0
static void
dvb_base_bin_class_init (DvbBaseBinClass * klass)
{
  GObjectClass *gobject_class;
  GstElementClass *element_class;
  GstBinClass *bin_class;
  DvbBaseBinClass *dvbbasebin_class;
  GstElementFactory *dvbsrc_factory;
  GObjectClass *dvbsrc_class;
  typedef struct
  {
    guint prop_id;
    const gchar *prop_name;
  } ProxyedProperty;
  ProxyedProperty *walk;
  ProxyedProperty proxyed_properties[] = {
    {PROP_ADAPTER, "adapter"},
    {PROP_FRONTEND, "frontend"},
    {PROP_DISEQC_SRC, "diseqc-source"},
    {PROP_FREQUENCY, "frequency"},
    {PROP_POLARITY, "polarity"},
    {PROP_SYMBOL_RATE, "symbol-rate"},
#ifndef GST_REMOVE_DEPRECATED
    {PROP_BANDWIDTH, "bandwidth"},
#endif
    {PROP_CODE_RATE_HP, "code-rate-hp"},
    {PROP_CODE_RATE_LP, "code-rate-lp"},
    {PROP_GUARD, "guard"},
    {PROP_MODULATION, "modulation"},
    {PROP_TRANS_MODE, "trans-mode"},
    {PROP_HIERARCHY, "hierarchy"},
    {PROP_INVERSION, "inversion"},
    {PROP_STATS_REPORTING_INTERVAL, "stats-reporting-interval"},
    {PROP_TUNING_TIMEOUT, "tuning-timeout"},
    {PROP_DELSYS, "delsys"},
    {PROP_PILOT, "pilot"},
    {PROP_ROLLOFF, "rolloff"},
    {PROP_STREAM_ID, "stream-id"},
    {PROP_BANDWIDTH_HZ, "bandwidth-hz"},
    {PROP_ISDBT_LAYER_ENABLED, "isdbt-layer-enabled"},
    {PROP_ISDBT_PARTIAL_RECEPTION, "isdbt-partial-reception"},
    {PROP_ISDBT_SOUND_BROADCASTING, "isdbt-sound-broadcasting"},
    {PROP_ISDBT_SB_SUBCHANNEL_ID, "isdbt-sb-subchannel-id"},
    {PROP_ISDBT_SB_SEGMENT_IDX, "isdbt-sb-segment-idx"},
    {PROP_ISDBT_SB_SEGMENT_COUNT, "isdbt-sb-segment-count"},
    {PROP_ISDBT_LAYERA_FEC, "isdbt-layera-fec"},
    {PROP_ISDBT_LAYERA_MODULATION, "isdbt-layera-modulation"},
    {PROP_ISDBT_LAYERA_SEGMENT_COUNT, "isdbt-layera-segment-count"},
    {PROP_ISDBT_LAYERA_TIME_INTERLEAVING, "isdbt-layera-time-interleaving"},
    {PROP_ISDBT_LAYERB_FEC, "isdbt-layerb-fec"},
    {PROP_ISDBT_LAYERB_MODULATION, "isdbt-layerb-modulation"},
    {PROP_ISDBT_LAYERB_SEGMENT_COUNT, "isdbt-layerb-segment-count"},
    {PROP_ISDBT_LAYERB_TIME_INTERLEAVING, "isdbt-layerb-time-interleaving"},
    {PROP_ISDBT_LAYERC_FEC, "isdbt-layerc-fec"},
    {PROP_ISDBT_LAYERC_MODULATION, "isdbt-layerc-modulation"},
    {PROP_ISDBT_LAYERC_SEGMENT_COUNT, "isdbt-layerc-segment-count"},
    {PROP_ISDBT_LAYERC_TIME_INTERLEAVING, "isdbt-layerc-time-interleaving"},
    {PROP_LNB_SLOF, "lnb-slof"},
    {PROP_LNB_LOF1, "lnb-lof1"},
    {PROP_LNB_LOF2, "lnb-lof2"},
    {PROP_INTERLEAVING, "interleaving"},
    {0, NULL}
  };

  bin_class = GST_BIN_CLASS (klass);
  bin_class->handle_message = dvb_base_bin_handle_message;

  element_class = GST_ELEMENT_CLASS (klass);

  element_class->change_state = dvb_base_bin_change_state;
  element_class->request_new_pad = dvb_base_bin_request_new_pad;
  element_class->release_pad = dvb_base_bin_release_pad;

  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&program_template));
  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&src_template));

  gst_element_class_set_static_metadata (element_class, "DVB bin",
      "Source/Bin/Video",
      "Access descramble and split DVB streams",
      "Alessandro Decina <*****@*****.**>\n"
      "Reynaldo H. Verdejo Pinochet <*****@*****.**>");

  gobject_class = G_OBJECT_CLASS (klass);
  gobject_class->set_property = dvb_base_bin_set_property;
  gobject_class->get_property = dvb_base_bin_get_property;
  gobject_class->dispose = dvb_base_bin_dispose;
  gobject_class->finalize = dvb_base_bin_finalize;

  dvbbasebin_class = (DvbBaseBinClass *) klass;
  dvbbasebin_class->do_tune = dvb_base_bin_do_tune;

  /* install dvbsrc properties */
  dvbsrc_factory = gst_element_factory_find ("dvbsrc");
  dvbsrc_class =
      g_type_class_ref (gst_element_factory_get_element_type (dvbsrc_factory));
  walk = proxyed_properties;
  while (walk->prop_name != NULL) {
    GParamSpec *pspec;
    GParamSpec *our_pspec;

    pspec = g_object_class_find_property (dvbsrc_class, walk->prop_name);
    if (pspec != NULL) {
      GType param_type = G_PARAM_SPEC_TYPE (pspec);

      if (param_type == G_TYPE_PARAM_INT) {
        GParamSpecInt *src_pspec = G_PARAM_SPEC_INT (pspec);

        our_pspec = g_param_spec_int (g_param_spec_get_name (pspec),
            g_param_spec_get_nick (pspec), g_param_spec_get_blurb (pspec),
            src_pspec->minimum, src_pspec->maximum, src_pspec->default_value,
            pspec->flags);
      } else if (param_type == G_TYPE_PARAM_UINT) {
        GParamSpecUInt *src_pspec = G_PARAM_SPEC_UINT (pspec);

        our_pspec = g_param_spec_uint (g_param_spec_get_name (pspec),
            g_param_spec_get_nick (pspec), g_param_spec_get_blurb (pspec),
            src_pspec->minimum, src_pspec->maximum, src_pspec->default_value,
            pspec->flags);
      } else if (param_type == G_TYPE_PARAM_UINT64) {
        GParamSpecUInt64 *src_pspec = G_PARAM_SPEC_UINT64 (pspec);

        our_pspec = g_param_spec_uint64 (g_param_spec_get_name (pspec),
            g_param_spec_get_nick (pspec), g_param_spec_get_blurb (pspec),
            src_pspec->minimum, src_pspec->maximum, src_pspec->default_value,
            pspec->flags);
      } else if (param_type == G_TYPE_PARAM_STRING) {
        GParamSpecString *src_pspec = G_PARAM_SPEC_STRING (pspec);

        our_pspec = g_param_spec_string (g_param_spec_get_name (pspec),
            g_param_spec_get_nick (pspec), g_param_spec_get_blurb (pspec),
            src_pspec->default_value, pspec->flags);
      } else if (param_type == G_TYPE_PARAM_ENUM) {
        GParamSpecEnum *src_pspec = G_PARAM_SPEC_ENUM (pspec);

        our_pspec = g_param_spec_enum (g_param_spec_get_name (pspec),
            g_param_spec_get_nick (pspec), g_param_spec_get_blurb (pspec),
            pspec->value_type, src_pspec->default_value, pspec->flags);
      } else {
        GST_ERROR ("Unsupported property type %s for property %s",
            g_type_name (param_type), g_param_spec_get_name (pspec));
        ++walk;
        continue;
      }

      g_object_class_install_property (gobject_class, walk->prop_id, our_pspec);
    } else {
      g_warning ("dvbsrc has no property named %s", walk->prop_name);
    }
    ++walk;
  }
  g_type_class_unref (dvbsrc_class);

  g_object_class_install_property (gobject_class, PROP_PROGRAM_NUMBERS,
      g_param_spec_string ("program-numbers",
          "Program Numbers",
          "Colon separated list of programs", "", G_PARAM_READWRITE));
  /**
   * DvbBaseBin::tuning-start:
   * @dvbbasebin: the element on which the signal is emitted
   *
   * Signal emited when the element first attempts to tune the
   * frontend tunner to a given frequency.
   */
  dvb_base_bin_signals[SIGNAL_TUNING_START] =
      g_signal_new ("tuning-start", G_TYPE_FROM_CLASS (klass),
      G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
  /**
   * DvbBaseBin::tuning-done:
   * @dvbbasebin: the element on which the signal is emitted
   *
   * Signal emited when the tunner has successfully got a lock on a signal.
   */
  dvb_base_bin_signals[SIGNAL_TUNING_DONE] =
      g_signal_new ("tuning-done", G_TYPE_FROM_CLASS (klass),
      G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
  /**
   * DvbBaseBin::tuning-fail:
   * @dvbbasebin: the element on which the signal is emitted
   *
   * Signal emited when the tunner failed to get a lock on the
   * signal.
   */
  dvb_base_bin_signals[SIGNAL_TUNING_FAIL] =
      g_signal_new ("tuning-fail", G_TYPE_FROM_CLASS (klass),
      G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);

  /**
   * DvbBaseBin::tune:
   * @dvbbasesink: the element on which the signal is emitted
   *
   * Signal emited from the application to the element, instructing it
   * to tune.
   */
  dvb_base_bin_signals[SIGNAL_TUNE] =
      g_signal_new ("tune", G_TYPE_FROM_CLASS (klass),
      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
      G_STRUCT_OFFSET (DvbBaseBinClass, do_tune),
      NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}
コード例 #15
0
ファイル: prop-editor.c プロジェクト: 3v1n0/gtk
static GtkWidget *
property_editor (GObject                *object,
                 GParamSpec             *spec,
                 GtkInspectorPropEditor *editor)
{
  GtkWidget *prop_edit;
  GtkAdjustment *adj;
  gchar *msg;
  GType type = G_PARAM_SPEC_TYPE (spec);

  if (type == G_TYPE_PARAM_INT)
    {
      adj = gtk_adjustment_new (G_PARAM_SPEC_INT (spec)->default_value,
                                G_PARAM_SPEC_INT (spec)->minimum,
                                G_PARAM_SPEC_INT (spec)->maximum,
                                1,
                                MAX ((G_PARAM_SPEC_INT (spec)->maximum - G_PARAM_SPEC_INT (spec)->minimum) / 10, 1),
                                0.0);

      prop_edit = gtk_spin_button_new (adj, 1.0, 0);

      g_object_connect_property (object, spec, G_CALLBACK (int_changed), adj, G_OBJECT (adj)); 

      connect_controller (G_OBJECT (adj), "value_changed",
                          object, spec, G_CALLBACK (int_modified));
    }
  else if (type == G_TYPE_PARAM_UINT)
    {
      adj = gtk_adjustment_new (G_PARAM_SPEC_UINT (spec)->default_value,
                                G_PARAM_SPEC_UINT (spec)->minimum,
                                G_PARAM_SPEC_UINT (spec)->maximum,
                                1,
                                MAX ((G_PARAM_SPEC_UINT (spec)->maximum - G_PARAM_SPEC_UINT (spec)->minimum) / 10, 1),
                                0.0);

      prop_edit = gtk_spin_button_new (adj, 1.0, 0);

      g_object_connect_property (object, spec,
                                 G_CALLBACK (uint_changed),
                                 adj, G_OBJECT (adj));

      connect_controller (G_OBJECT (adj), "value_changed",
                          object, spec, G_CALLBACK (uint_modified));
    }
  else if (type == G_TYPE_PARAM_FLOAT)
    {
      adj = gtk_adjustment_new (G_PARAM_SPEC_FLOAT (spec)->default_value,
                                G_PARAM_SPEC_FLOAT (spec)->minimum,
                                G_PARAM_SPEC_FLOAT (spec)->maximum,
                                0.1,
                                MAX ((G_PARAM_SPEC_FLOAT (spec)->maximum - G_PARAM_SPEC_FLOAT (spec)->minimum) / 10, 0.1),
                                0.0);

      prop_edit = gtk_spin_button_new (adj, 0.1, 2);

      g_object_connect_property (object, spec,
                                 G_CALLBACK (float_changed),
                                 adj, G_OBJECT (adj));

      connect_controller (G_OBJECT (adj), "value_changed",
                          object, spec, G_CALLBACK (float_modified));
    }
  else if (type == G_TYPE_PARAM_DOUBLE)
    {
      adj = gtk_adjustment_new (G_PARAM_SPEC_DOUBLE (spec)->default_value,
                                G_PARAM_SPEC_DOUBLE (spec)->minimum,
                                G_PARAM_SPEC_DOUBLE (spec)->maximum,
                                0.1,
                                MAX ((G_PARAM_SPEC_DOUBLE (spec)->maximum - G_PARAM_SPEC_DOUBLE (spec)->minimum) / 10, 0.1),
                                0.0);

      prop_edit = gtk_spin_button_new (adj, 0.1, 2);

      g_object_connect_property (object, spec,
                                 G_CALLBACK (double_changed),
                                 adj, G_OBJECT (adj));

      connect_controller (G_OBJECT (adj), "value_changed",
                          object, spec, G_CALLBACK (double_modified));
    }
  else if (type == G_TYPE_PARAM_STRING)
    {
      prop_edit = gtk_entry_new ();

      g_object_connect_property (object, spec,
                                 G_CALLBACK (string_changed),
                                 prop_edit, G_OBJECT (prop_edit));

      connect_controller (G_OBJECT (prop_edit), "changed",
                          object, spec, G_CALLBACK (string_modified));
    }
  else if (type == G_TYPE_PARAM_BOOLEAN)
    {
      prop_edit = gtk_toggle_button_new_with_label ("");

      g_object_connect_property (object, spec,
                                 G_CALLBACK (bool_changed),
                                 prop_edit, G_OBJECT (prop_edit));

      connect_controller (G_OBJECT (prop_edit), "toggled",
                          object, spec, G_CALLBACK (bool_modified));
    }
  else if (type == G_TYPE_PARAM_ENUM)
    {
      {
        GtkWidget *box;
        GEnumClass *eclass;
        GtkWidget *first;
        gint j;

        prop_edit = gtk_scrolled_window_new (NULL, NULL);
        g_object_set (prop_edit,
                      "expand", TRUE,
                      "hscrollbar-policy", GTK_POLICY_NEVER,
                      "vscrollbar-policy", GTK_POLICY_NEVER,
                      NULL);
        box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
        gtk_widget_show (box);
        gtk_container_add (GTK_CONTAINER (prop_edit), box);

        eclass = G_ENUM_CLASS (g_type_class_ref (spec->value_type));

        j = 0;
        first = NULL;
        while (j < eclass->n_values)
          {
            GtkWidget *b;

            b = gtk_radio_button_new_with_label_from_widget ((GtkRadioButton*)first, eclass->values[j].value_name);
            if (first == NULL)
              first = b;
            g_object_set_data (G_OBJECT (b), "index", GINT_TO_POINTER (j));
            gtk_widget_show (b);
            gtk_box_pack_start (GTK_BOX (box), b, FALSE, FALSE, 0);
            connect_controller (G_OBJECT (b), "toggled",
                                object, spec, G_CALLBACK (enum_modified));
            ++j;
          }

        if (j >= 10)
          g_object_set (prop_edit, "vscrollbar-policy", GTK_POLICY_AUTOMATIC, NULL);

        g_type_class_unref (eclass);

        g_object_connect_property (object, spec,
                                   G_CALLBACK (enum_changed),
                                   prop_edit, G_OBJECT (prop_edit));
      }
    }
  else if (type == G_TYPE_PARAM_FLAGS)
    {
      {
        GtkWidget *box;
        GFlagsClass *fclass;
        gint j;

        prop_edit = gtk_scrolled_window_new (NULL, NULL);
        g_object_set (prop_edit,
                      "expand", TRUE,
                      "hscrollbar-policy", GTK_POLICY_NEVER,
                      "vscrollbar-policy", GTK_POLICY_NEVER,
                      NULL);
        box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
        gtk_widget_show (box);
        gtk_container_add (GTK_CONTAINER (prop_edit), box);

        fclass = G_FLAGS_CLASS (g_type_class_ref (spec->value_type));

        for (j = 0; j < fclass->n_values; j++)
          {
            GtkWidget *b;

            b = gtk_check_button_new_with_label (fclass->values[j].value_name);
            g_object_set_data (G_OBJECT (b), "index", GINT_TO_POINTER (j));
            gtk_widget_show (b);
            gtk_box_pack_start (GTK_BOX (box), b, FALSE, FALSE, 0);
            connect_controller (G_OBJECT (b), "toggled",
                                object, spec, G_CALLBACK (flags_modified));
          }

        if (j >= 10)
          g_object_set (prop_edit, "vscrollbar-policy", GTK_POLICY_AUTOMATIC, NULL);

        g_type_class_unref (fclass);

        g_object_connect_property (object, spec,
                                   G_CALLBACK (flags_changed),
                                   prop_edit, G_OBJECT (prop_edit));
      }
    }
  else if (type == G_TYPE_PARAM_UNICHAR)
    {
      prop_edit = gtk_entry_new ();
      gtk_entry_set_max_length (GTK_ENTRY (prop_edit), 1);

      g_object_connect_property (object, spec,
                                 G_CALLBACK (unichar_changed),
                                 prop_edit, G_OBJECT (prop_edit));

      connect_controller (G_OBJECT (prop_edit), "changed",
                          object, spec, G_CALLBACK (unichar_modified));
    }
  else if (type == G_TYPE_PARAM_POINTER)
    {
      prop_edit = gtk_label_new ("");

      g_object_connect_property (object, spec,
                                 G_CALLBACK (pointer_changed),
                                 prop_edit, G_OBJECT (prop_edit));
    }
  else if (type == G_TYPE_PARAM_OBJECT)
    {
      GtkWidget *label, *button;

      prop_edit = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);

      label = gtk_label_new ("");
      button = gtk_button_new_with_label (_("Properties"));
      g_signal_connect_swapped (button, "clicked",
                                G_CALLBACK (object_properties),
                                editor);
      gtk_container_add (GTK_CONTAINER (prop_edit), label);
      gtk_container_add (GTK_CONTAINER (prop_edit), button);
      gtk_widget_show (label);
      gtk_widget_show (button);

      g_object_connect_property (object, spec,
                                 G_CALLBACK (object_changed),
                                 prop_edit, G_OBJECT (label));
    }
  else if (type == G_TYPE_PARAM_BOXED &&
           G_PARAM_SPEC_VALUE_TYPE (spec) == GDK_TYPE_RGBA)
    {
      prop_edit = gtk_color_chooser_widget_new ();
      gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (prop_edit), TRUE);

      g_object_connect_property (object, spec,
                                 G_CALLBACK (rgba_changed),
                                 prop_edit, G_OBJECT (prop_edit));

      connect_controller (G_OBJECT (prop_edit), "notify::rgba",
                          object, spec, G_CALLBACK (rgba_modified));
    }
  else if (type == G_TYPE_PARAM_BOXED &&
           G_PARAM_SPEC_VALUE_TYPE (spec) == g_type_from_name ("GdkColor"))
    {
      prop_edit = gtk_color_chooser_widget_new ();
      gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (prop_edit), FALSE);

      g_object_connect_property (object, spec,
                                 G_CALLBACK (color_changed),
                                 prop_edit, G_OBJECT (prop_edit));

      connect_controller (G_OBJECT (prop_edit), "notify::rgba",
                          object, spec, G_CALLBACK (color_modified));
    }
  else if (type == G_TYPE_PARAM_BOXED &&
           G_PARAM_SPEC_VALUE_TYPE (spec) == PANGO_TYPE_FONT_DESCRIPTION)
    {
      prop_edit = gtk_font_chooser_widget_new ();

      g_object_connect_property (object, spec,
                                 G_CALLBACK (font_changed),
                                 prop_edit, G_OBJECT (prop_edit));

      connect_controller (G_OBJECT (prop_edit), "notify::font-desc",
                          object, spec, G_CALLBACK (font_modified));
    }
  else
    {
      msg = g_strdup_printf (_("Uneditable property type: %s"),
                             g_type_name (G_PARAM_SPEC_TYPE (spec)));
      prop_edit = gtk_label_new (msg);
      g_free (msg);
      gtk_widget_set_halign (prop_edit, GTK_ALIGN_START);
      gtk_widget_set_valign (prop_edit, GTK_ALIGN_CENTER);
    }

  if (g_param_spec_get_blurb (spec))
    gtk_widget_set_tooltip_text (prop_edit, g_param_spec_get_blurb (spec));

  notify_property (object, spec);

  return prop_edit;
}
コード例 #16
0
/* XXX Historical note, originally I tried (ab)using override properties
 *     in ESourceCamel, which redirected to the equivalent CamelSettings
 *     property.  Seemed to work at first, and I was proud of my clever
 *     hack, but it turns out g_object_class_list_properties() excludes
 *     override properties.  So the ESourceCamel properties were being
 *     skipped in source_load_from_key_file() (e-source.c). */
static GParamSpec *
param_spec_clone (GParamSpec *pspec)
{
	GParamSpec *clone;
	GParamFlags flags;
	const gchar *name, *nick, *blurb;

	name = g_param_spec_get_name (pspec);
	nick = g_param_spec_get_nick (pspec);
	blurb = g_param_spec_get_blurb (pspec);
	flags = (pspec->flags & ~(G_PARAM_STATIC_STRINGS));

	if (G_IS_PARAM_SPEC_BOOLEAN (pspec)) {
		GParamSpecBoolean *pspec_boolean = G_PARAM_SPEC_BOOLEAN (pspec);

		clone = g_param_spec_boolean (name, nick, blurb,
			pspec_boolean->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_CHAR (pspec)) {
		GParamSpecChar *pspec_char = G_PARAM_SPEC_CHAR (pspec);

		clone = g_param_spec_char (name, nick, blurb,
			pspec_char->minimum,
			pspec_char->maximum,
			pspec_char->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_UCHAR (pspec)) {
		GParamSpecUChar *pspec_uchar = G_PARAM_SPEC_UCHAR (pspec);

		clone = g_param_spec_uchar (name, nick, blurb,
			pspec_uchar->minimum,
			pspec_uchar->maximum,
			pspec_uchar->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_INT (pspec)) {
		GParamSpecInt *pspec_int = G_PARAM_SPEC_INT (pspec);

		clone = g_param_spec_int (name, nick, blurb,
			pspec_int->minimum,
			pspec_int->maximum,
			pspec_int->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_UINT (pspec)) {
		GParamSpecUInt *pspec_uint = G_PARAM_SPEC_UINT (pspec);

		clone = g_param_spec_uint (name, nick, blurb,
			pspec_uint->minimum,
			pspec_uint->maximum,
			pspec_uint->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_LONG (pspec)) {
		GParamSpecLong *pspec_long = G_PARAM_SPEC_LONG (pspec);

		clone = g_param_spec_long (name, nick, blurb,
			pspec_long->minimum,
			pspec_long->maximum,
			pspec_long->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_ULONG (pspec)) {
		GParamSpecULong *pspec_ulong = G_PARAM_SPEC_ULONG (pspec);

		clone = g_param_spec_ulong (name, nick, blurb,
			pspec_ulong->minimum,
			pspec_ulong->maximum,
			pspec_ulong->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_INT64 (pspec)) {
		GParamSpecInt64 *pspec_int64 = G_PARAM_SPEC_INT64 (pspec);

		clone = g_param_spec_int64 (name, nick, blurb,
			pspec_int64->minimum,
			pspec_int64->maximum,
			pspec_int64->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_UINT64 (pspec)) {
		GParamSpecUInt64 *pspec_uint64 = G_PARAM_SPEC_UINT64 (pspec);

		clone = g_param_spec_uint64 (name, nick, blurb,
			pspec_uint64->minimum,
			pspec_uint64->maximum,
			pspec_uint64->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_FLOAT (pspec)) {
		GParamSpecFloat *pspec_float = G_PARAM_SPEC_FLOAT (pspec);

		clone = g_param_spec_float (name, nick, blurb,
			pspec_float->minimum,
			pspec_float->maximum,
			pspec_float->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_DOUBLE (pspec)) {
		GParamSpecDouble *pspec_double = G_PARAM_SPEC_DOUBLE (pspec);

		clone = g_param_spec_double (name, nick, blurb,
			pspec_double->minimum,
			pspec_double->maximum,
			pspec_double->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_ENUM (pspec)) {
		GParamSpecEnum *pspec_enum = G_PARAM_SPEC_ENUM (pspec);

		clone = g_param_spec_enum (name, nick, blurb,
			pspec->value_type,
			pspec_enum->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_FLAGS (pspec)) {
		GParamSpecFlags *pspec_flags = G_PARAM_SPEC_FLAGS (pspec);

		clone = g_param_spec_flags (name, nick, blurb,
			pspec->value_type,
			pspec_flags->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_STRING (pspec)) {
		GParamSpecString *pspec_string = G_PARAM_SPEC_STRING (pspec);

		clone = g_param_spec_string (name, nick, blurb,
			pspec_string->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_PARAM (pspec)) {
		clone = g_param_spec_param (name, nick, blurb,
			pspec->value_type,
			flags);
	} else if (G_IS_PARAM_SPEC_BOXED (pspec)) {
		clone = g_param_spec_boxed (name, nick, blurb,
			pspec->value_type,
			flags);
	} else if (G_IS_PARAM_SPEC_POINTER (pspec)) {
		clone = g_param_spec_pointer (name, nick, blurb, flags);
	} else if (G_IS_PARAM_SPEC_OBJECT (pspec)) {
		clone = g_param_spec_object (name, nick, blurb,
			pspec->value_type,
			flags);
	} else if (G_IS_PARAM_SPEC_UNICHAR (pspec)) {
		GParamSpecUnichar *pspec_unichar = G_PARAM_SPEC_UNICHAR (pspec);

		clone = g_param_spec_unichar (name, nick, blurb,
			pspec_unichar->default_value,
			flags);
	} else if (G_IS_PARAM_SPEC_GTYPE (pspec)) {
		GParamSpecGType *pspec_gtype = G_PARAM_SPEC_GTYPE (pspec);

		clone = g_param_spec_gtype (name, nick, blurb,
			pspec_gtype->is_a_type,
			flags);
	} else if (G_IS_PARAM_SPEC_VARIANT (pspec)) {
		GParamSpecVariant *pspec_variant = G_PARAM_SPEC_VARIANT (pspec);

		clone = g_param_spec_variant (name, nick, blurb,
			pspec_variant->type,
			pspec_variant->default_value,
			flags);
	} else {
		g_warn_if_reached ();
	}

	return clone;
}
コード例 #17
0
ファイル: gst-inspect.c プロジェクト: Kurento/gstreamer
static void
print_element_properties_info (GstElement * element)
{
  GParamSpec **property_specs;
  guint num_properties, i;
  gboolean readable;
  gboolean first_flag;

  property_specs = g_object_class_list_properties
      (G_OBJECT_GET_CLASS (element), &num_properties);
  n_print ("\n");
  n_print ("Element Properties:\n");

  for (i = 0; i < num_properties; i++) {
    GValue value = { 0, };
    GParamSpec *param = property_specs[i];

    readable = FALSE;

    g_value_init (&value, param->value_type);

    n_print ("  %-20s: %s\n", g_param_spec_get_name (param),
        g_param_spec_get_blurb (param));

    first_flag = TRUE;
    n_print ("%-23.23s flags: ", "");
    if (param->flags & G_PARAM_READABLE) {
      g_object_get_property (G_OBJECT (element), param->name, &value);
      readable = TRUE;
      g_print ("%s%s", (first_flag) ? "" : ", ", _("readable"));
      first_flag = FALSE;
    } else {
      /* if we can't read the property value, assume it's set to the default
       * (which might not be entirely true for sub-classes, but that's an
       * unlikely corner-case anyway) */
      g_param_value_set_default (param, &value);
    }
    if (param->flags & G_PARAM_WRITABLE) {
      g_print ("%s%s", (first_flag) ? "" : ", ", _("writable"));
      first_flag = FALSE;
    }
    if (param->flags & G_PARAM_DEPRECATED) {
      g_print ("%s%s", (first_flag) ? "" : ", ", _("deprecated"));
      first_flag = FALSE;
    }
    if (param->flags & GST_PARAM_CONTROLLABLE) {
      g_print (", %s", _("controllable"));
      first_flag = FALSE;
    }
    if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
      g_print (", %s", _("changeable in NULL, READY, PAUSED or PLAYING state"));
    } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
      g_print (", %s", _("changeable only in NULL, READY or PAUSED state"));
    } else if (param->flags & GST_PARAM_MUTABLE_READY) {
      g_print (", %s", _("changeable only in NULL or READY state"));
    }
    if (param->flags & ~KNOWN_PARAM_FLAGS) {
      g_print ("%s0x%0x", (first_flag) ? "" : ", ",
          param->flags & ~KNOWN_PARAM_FLAGS);
    }
    n_print ("\n");

    switch (G_VALUE_TYPE (&value)) {
      case G_TYPE_STRING:
      {
        const char *string_val = g_value_get_string (&value);

        n_print ("%-23.23s String. ", "");

        if (string_val == NULL)
          g_print ("Default: null");
        else
          g_print ("Default: \"%s\"", string_val);
        break;
      }
      case G_TYPE_BOOLEAN:
      {
        gboolean bool_val = g_value_get_boolean (&value);

        n_print ("%-23.23s Boolean. ", "");

        g_print ("Default: %s", bool_val ? "true" : "false");
        break;
      }
      case G_TYPE_ULONG:
      {
        GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);

        n_print ("%-23.23s Unsigned Long. ", "");
        g_print ("Range: %lu - %lu Default: %lu ",
            pulong->minimum, pulong->maximum, g_value_get_ulong (&value));

        GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
            "uint/uint64", GST_OBJECT_NAME (element),
            g_param_spec_get_name (param));
        break;
      }
      case G_TYPE_LONG:
      {
        GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);

        n_print ("%-23.23s Long. ", "");
        g_print ("Range: %ld - %ld Default: %ld ",
            plong->minimum, plong->maximum, g_value_get_long (&value));

        GST_ERROR ("%s: property '%s' of type long: consider changing to "
            "int/int64", GST_OBJECT_NAME (element),
            g_param_spec_get_name (param));
        break;
      }
      case G_TYPE_UINT:
      {
        GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);

        n_print ("%-23.23s Unsigned Integer. ", "");
        g_print ("Range: %u - %u Default: %u ",
            puint->minimum, puint->maximum, g_value_get_uint (&value));
        break;
      }
      case G_TYPE_INT:
      {
        GParamSpecInt *pint = G_PARAM_SPEC_INT (param);

        n_print ("%-23.23s Integer. ", "");
        g_print ("Range: %d - %d Default: %d ",
            pint->minimum, pint->maximum, g_value_get_int (&value));
        break;
      }
      case G_TYPE_UINT64:
      {
        GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);

        n_print ("%-23.23s Unsigned Integer64. ", "");
        g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
            " Default: %" G_GUINT64_FORMAT " ",
            puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
        break;
      }
      case G_TYPE_INT64:
      {
        GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);

        n_print ("%-23.23s Integer64. ", "");
        g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
            " Default: %" G_GINT64_FORMAT " ",
            pint64->minimum, pint64->maximum, g_value_get_int64 (&value));
        break;
      }
      case G_TYPE_FLOAT:
      {
        GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);

        n_print ("%-23.23s Float. ", "");
        g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
            pfloat->minimum, pfloat->maximum, g_value_get_float (&value));
        break;
      }
      case G_TYPE_DOUBLE:
      {
        GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);

        n_print ("%-23.23s Double. ", "");
        g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
            pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
        break;
      }
      case G_TYPE_CHAR:
      case G_TYPE_UCHAR:
        GST_ERROR ("%s: property '%s' of type char: consider changing to "
            "int/string", GST_OBJECT_NAME (element),
            g_param_spec_get_name (param));
        /* fall through */
      default:
        if (param->value_type == GST_TYPE_CAPS) {
          const GstCaps *caps = gst_value_get_caps (&value);

          if (!caps)
            n_print ("%-23.23s Caps (NULL)", "");
          else {
            print_caps (caps, "                           ");
          }
        } else if (G_IS_PARAM_SPEC_ENUM (param)) {
          GEnumValue *values;
          guint j = 0;
          gint enum_value;
          const gchar *value_nick = "";

          values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
          enum_value = g_value_get_enum (&value);

          while (values[j].value_name) {
            if (values[j].value == enum_value)
              value_nick = values[j].value_nick;
            j++;
          }

          n_print ("%-23.23s Enum \"%s\" Default: %d, \"%s\"", "",
              g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick);

          j = 0;
          while (values[j].value_name) {
            g_print ("\n");
            if (_name)
              g_print ("%s", _name);
            g_print ("%-23.23s    (%d): %-16s - %s", "",
                values[j].value, values[j].value_nick, values[j].value_name);
            j++;
          }
          /* g_type_class_unref (ec); */
        } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
          GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
          GFlagsValue *vals;
          gchar *cur;

          vals = pflags->flags_class->values;

          cur = flags_to_string (vals, g_value_get_flags (&value));

          n_print ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
              g_type_name (G_VALUE_TYPE (&value)),
              g_value_get_flags (&value), cur);

          while (vals[0].value_name) {
            g_print ("\n");
            if (_name)
              g_print ("%s", _name);
            g_print ("%-23.23s    (0x%08x): %-16s - %s", "",
                vals[0].value, vals[0].value_nick, vals[0].value_name);
            ++vals;
          }

          g_free (cur);
        } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
          n_print ("%-23.23s Object of type \"%s\"", "",
              g_type_name (param->value_type));
        } else if (G_IS_PARAM_SPEC_BOXED (param)) {
          n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
              g_type_name (param->value_type));
          if (param->value_type == GST_TYPE_STRUCTURE) {
            const GstStructure *s = gst_value_get_structure (&value);
            if (s)
              gst_structure_foreach (s, print_field,
                  (gpointer) "                           ");
          }
        } else if (G_IS_PARAM_SPEC_POINTER (param)) {
          if (param->value_type != G_TYPE_POINTER) {
            n_print ("%-23.23s Pointer of type \"%s\".", "",
                g_type_name (param->value_type));
          } else {
            n_print ("%-23.23s Pointer.", "");
          }
        } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
          GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);

          if (pvarray->element_spec) {
            n_print ("%-23.23s Array of GValues of type \"%s\"", "",
                g_type_name (pvarray->element_spec->value_type));
          } else {
            n_print ("%-23.23s Array of GValues", "");
          }
        } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
          GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);

          n_print ("%-23.23s Fraction. ", "");

          g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
              pfraction->min_num, pfraction->min_den,
              pfraction->max_num, pfraction->max_den,
              gst_value_get_fraction_numerator (&value),
              gst_value_get_fraction_denominator (&value));
        } else {
          n_print ("%-23.23s Unknown type %ld \"%s\"", "",
              (glong) param->value_type, g_type_name (param->value_type));
        }
        break;
    }
    if (!readable)
      g_print (" Write only\n");
    else
      g_print ("\n");

    g_value_reset (&value);
  }
  if (num_properties == 0)
    n_print ("  none\n");

  g_free (property_specs);
}
コード例 #18
0
static gboolean
clutter_interval_real_validate (ClutterInterval *interval,
                                GParamSpec      *pspec)
{
  GType pspec_gtype = G_PARAM_SPEC_VALUE_TYPE (pspec);

  /* check the GTypes we provide first */
  if (pspec_gtype == COGL_TYPE_FIXED)
    {
      ClutterParamSpecFixed *pspec_fixed = CLUTTER_PARAM_SPEC_FIXED (pspec);
      CoglFixed a, b;

      a = b = 0;
      clutter_interval_get_interval (interval, &a, &b);
      if ((a >= pspec_fixed->minimum && a <= pspec_fixed->maximum) &&
          (b >= pspec_fixed->minimum && b <= pspec_fixed->maximum))
        return TRUE;
      else
        return FALSE;
    }

  /* then check the fundamental types */
  switch (G_TYPE_FUNDAMENTAL (pspec_gtype))
    {
    case G_TYPE_INT:
      {
        GParamSpecInt *pspec_int = G_PARAM_SPEC_INT (pspec);
        gint a, b;

        a = b = 0;
        clutter_interval_get_interval (interval, &a, &b);
        if ((a >= pspec_int->minimum && a <= pspec_int->maximum) &&
            (b >= pspec_int->minimum && b <= pspec_int->maximum))
          return TRUE;
        else
          return FALSE;
      }
      break;

    case G_TYPE_UINT:
      {
        GParamSpecUInt *pspec_uint = G_PARAM_SPEC_UINT (pspec);
        guint a, b;

        a = b = 0;
        clutter_interval_get_interval (interval, &a, &b);
        if ((a >= pspec_uint->minimum && a <= pspec_uint->maximum) &&
            (b >= pspec_uint->minimum && b <= pspec_uint->maximum))
          return TRUE;
        else
          return FALSE;
      }
      break;

    case G_TYPE_UCHAR:
      {
        GParamSpecUChar *pspec_uchar = G_PARAM_SPEC_UCHAR (pspec);
        guchar a, b;

        a = b = 0;
        clutter_interval_get_interval (interval, &a, &b);
        if ((a >= pspec_uchar->minimum && a <= pspec_uchar->maximum) &&
            (b >= pspec_uchar->minimum && b <= pspec_uchar->maximum))
          return TRUE;
        else
          return FALSE;
      }
      break;

    case G_TYPE_BOOLEAN:
      return TRUE;

    default:
      break;
    }

  return TRUE;
}
コード例 #19
0
static void
param_uint_set_default (GParamSpec *pspec,
			GValue     *value)
{
  value->data[0].v_uint = G_PARAM_SPEC_UINT (pspec)->default_value;
}
コード例 #20
0
ファイル: adjustment.c プロジェクト: svn2github/gwyddion
/**
 * gwy_adjustment_new_for_property:
 * @object: (transfer none):
 *          An object.
 * @propname: Name of property to create adjustment for.  The property must be
 *            of integral or double type.
 *
 * Creates a new adjustment with ranges, default and current value given by
 * the property of an object.
 *
 * Changes to the property value are reflected by changes in the adjustment
 * value and vice versa.  The adjustment does not take a reference to @object.
 * If @object ceases to exist before the adjustment does the adjustment will
 * remain configured the same way, just the value will not be synchronised with
 * anything.
 *
 * You can limit the adjustment range further than what is permitted by the
 * property after the construction.  Extending it is not allowed.
 *
 * Returns: A newly created adjustment.
 **/
GwyAdjustment*
gwy_adjustment_new_for_property(GObject *object,
                                const gchar *propname)
{
    GwyAdjustment *adj = gwy_adjustment_new();
    g_return_val_if_fail(G_IS_OBJECT(object), adj);
    Adjustment *priv = adj->priv;

    g_return_val_if_fail(propname, adj);
    GObjectClass *klass = G_OBJECT_GET_CLASS(object);
    GParamSpec *property = g_object_class_find_property(klass, propname);
    g_return_val_if_fail(property, adj);

    gdouble lower, upper, defaultval;
    gboolean is_integral = TRUE;

    // Try the types by descending probability.
    if (G_IS_PARAM_SPEC_DOUBLE(property)) {
        GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE(property);
        lower = pspec->minimum;
        upper = pspec->maximum;
        defaultval = pspec->default_value;
        is_integral = FALSE;
    }
    else if (G_IS_PARAM_SPEC_UINT(property)) {
        GParamSpecUInt *pspec = G_PARAM_SPEC_UINT(property);
        lower = pspec->minimum;
        upper = pspec->maximum;
        defaultval = pspec->default_value;
    }
    else if (G_IS_PARAM_SPEC_INT(property)) {
        GParamSpecInt *pspec = G_PARAM_SPEC_INT(property);
        lower = pspec->minimum;
        upper = pspec->maximum;
        defaultval = pspec->default_value;
    }
    else if (G_IS_PARAM_SPEC_LONG(property)) {
        GParamSpecLong *pspec = G_PARAM_SPEC_LONG(property);
        lower = pspec->minimum;
        upper = pspec->maximum;
        defaultval = pspec->default_value;
    }
    else if (G_IS_PARAM_SPEC_ULONG(property)) {
        GParamSpecULong *pspec = G_PARAM_SPEC_ULONG(property);
        lower = pspec->minimum;
        upper = pspec->maximum;
        defaultval = pspec->default_value;
    }
    else if (G_IS_PARAM_SPEC_FLOAT(property)) {
        GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT(property);
        lower = pspec->minimum;
        upper = pspec->maximum;
        defaultval = pspec->default_value;
        is_integral = FALSE;
    }
    else {
        g_critical("Cannot create adjustment for value type %s.",
                   g_type_name(property->value_type));
        return adj;
    }

    // Construct a harmless value for the gtk_adjustment_configure() call.
    gdouble step_increment, page_increment, value;
    // XXX: This needs more elaboration.
    if (is_integral) {
        value = gwy_round(0.5*(lower + upper));
        step_increment = 1.0;
        page_increment = MIN(upper - lower, 10.0);
    }
    else {
        value = 0.5*(lower + upper);
        step_increment = MAX((upper - lower)/100000.0, fabs(lower));
        step_increment = gwy_powi(10.0, gwy_round(log10(step_increment)));
        page_increment = sqrt(step_increment*(upper - lower));
        page_increment = gwy_powi(10.0, gwy_round(log10(page_increment)));
    }

    gtk_adjustment_configure(GTK_ADJUSTMENT(adj),
                             value, lower, upper,
                             step_increment, page_increment, 0.0);
    priv->defaultval = defaultval;
    // This takes care of value synchronisation from the property to us.
    priv->binding = g_object_bind_property(object, propname,
                                           adj, "value",
                                           G_BINDING_BIDIRECTIONAL
                                           | G_BINDING_SYNC_CREATE);
    g_object_add_weak_pointer(G_OBJECT(priv->binding),
                              (gpointer*)&priv->binding);

    return adj;
}
コード例 #21
0
GParamSpec *
gimp_param_spec_duplicate (GParamSpec *pspec)
{
  GParamSpec  *copy = NULL;
  GParamFlags  flags;

  g_return_val_if_fail (pspec != NULL, NULL);

  flags = pspec->flags | GIMP_CONFIG_PARAM_SERIALIZE;

  if (G_IS_PARAM_SPEC_STRING (pspec))
    {
      GParamSpecString *spec = G_PARAM_SPEC_STRING (pspec);

      if (GEGL_IS_PARAM_SPEC_FILE_PATH (pspec))
        {
          copy = gimp_param_spec_config_path (pspec->name,
                                              g_param_spec_get_nick (pspec),
                                              g_param_spec_get_blurb (pspec),
                                              GIMP_CONFIG_PATH_FILE,
                                              spec->default_value,
                                              flags);
        }
      else
        {
          static GQuark multiline_quark = 0;

          if (! multiline_quark)
            multiline_quark = g_quark_from_static_string ("multiline");

          copy = g_param_spec_string (pspec->name,
                                      g_param_spec_get_nick (pspec),
                                      g_param_spec_get_blurb (pspec),
                                      spec->default_value,
                                      flags);

          if (GEGL_IS_PARAM_SPEC_MULTILINE (pspec))
            {
              g_param_spec_set_qdata (copy, multiline_quark,
                                      GINT_TO_POINTER (TRUE));
            }
        }
    }
  else if (G_IS_PARAM_SPEC_BOOLEAN (pspec))
    {
      GParamSpecBoolean *spec = G_PARAM_SPEC_BOOLEAN (pspec);

      copy = g_param_spec_boolean (pspec->name,
                                   g_param_spec_get_nick (pspec),
                                   g_param_spec_get_blurb (pspec),
                                   spec->default_value,
                                   flags);
    }
  else if (G_IS_PARAM_SPEC_ENUM (pspec))
    {
      GParamSpecEnum *spec = G_PARAM_SPEC_ENUM (pspec);

      copy = g_param_spec_enum (pspec->name,
                                g_param_spec_get_nick (pspec),
                                g_param_spec_get_blurb (pspec),
                                G_TYPE_FROM_CLASS (spec->enum_class),
                                spec->default_value,
                                flags);
    }
  else if (GEGL_IS_PARAM_SPEC_DOUBLE (pspec))
    {
      GeglParamSpecDouble *gspec = GEGL_PARAM_SPEC_DOUBLE (pspec);
      GParamSpecDouble    *spec = G_PARAM_SPEC_DOUBLE (pspec);

      copy = gegl_param_spec_double (pspec->name,
                                     g_param_spec_get_nick (pspec),
                                     g_param_spec_get_blurb (pspec),
                                     spec->minimum,
                                     spec->maximum,
                                     spec->default_value,
                                     gspec->ui_minimum,
                                     gspec->ui_maximum,
                                     gspec->ui_gamma,
                                     flags);
    }
  else if (G_IS_PARAM_SPEC_DOUBLE (pspec))
    {
      GParamSpecDouble *spec = G_PARAM_SPEC_DOUBLE (pspec);

      copy = g_param_spec_double (pspec->name,
                                  g_param_spec_get_nick (pspec),
                                  g_param_spec_get_blurb (pspec),
                                  spec->minimum,
                                  spec->maximum,
                                  spec->default_value,
                                  flags);
    }
  else if (G_IS_PARAM_SPEC_FLOAT (pspec))
    {
      GParamSpecFloat *spec = G_PARAM_SPEC_FLOAT (pspec);

      copy = g_param_spec_float (pspec->name,
                                 g_param_spec_get_nick (pspec),
                                 g_param_spec_get_blurb (pspec),
                                 spec->minimum,
                                 spec->maximum,
                                 spec->default_value,
                                 flags);
    }
  else if (GEGL_IS_PARAM_SPEC_INT (pspec))
    {
      GeglParamSpecInt *gspec = GEGL_PARAM_SPEC_INT (pspec);
      GParamSpecInt    *spec  = G_PARAM_SPEC_INT (pspec);

      copy = gegl_param_spec_int (pspec->name,
                                  g_param_spec_get_nick (pspec),
                                  g_param_spec_get_blurb (pspec),
                                  spec->minimum,
                                  spec->maximum,
                                  spec->default_value,
                                  gspec->ui_minimum,
                                  gspec->ui_maximum,
                                  gspec->ui_gamma,
                                  flags);
    }
  else if (GEGL_IS_PARAM_SPEC_SEED (pspec))
    {
      copy = gegl_param_spec_seed (pspec->name,
                                   g_param_spec_get_nick (pspec),
                                   g_param_spec_get_blurb (pspec),
                                   pspec->flags |
                                   GIMP_CONFIG_PARAM_SERIALIZE);
    }
  else if (G_IS_PARAM_SPEC_INT (pspec))
    {
      GParamSpecInt *spec = G_PARAM_SPEC_INT (pspec);

      copy = g_param_spec_int (pspec->name,
                               g_param_spec_get_nick (pspec),
                               g_param_spec_get_blurb (pspec),
                               spec->minimum,
                               spec->maximum,
                               spec->default_value,
                               flags);
    }
  else if (G_IS_PARAM_SPEC_UINT (pspec))
    {
      GParamSpecUInt *spec = G_PARAM_SPEC_UINT (pspec);

      copy = g_param_spec_uint (pspec->name,
                                g_param_spec_get_nick (pspec),
                                g_param_spec_get_blurb (pspec),
                                spec->minimum,
                                spec->maximum,
                                spec->default_value,
                                flags);
    }
  else if (GIMP_IS_PARAM_SPEC_RGB (pspec))
    {
      GValue  value = G_VALUE_INIT;
      GimpRGB color;

      g_value_init (&value, GIMP_TYPE_RGB);
      g_param_value_set_default (pspec, &value);
      gimp_value_get_rgb (&value, &color);
      g_value_unset (&value);

      copy = gimp_param_spec_rgb (pspec->name,
                                  g_param_spec_get_nick (pspec),
                                  g_param_spec_get_blurb (pspec),
                                  gimp_param_spec_rgb_has_alpha (pspec),
                                  &color,
                                  flags);
    }
  else if (GEGL_IS_PARAM_SPEC_COLOR (pspec))
    {
      GeglColor *gegl_color;
      GimpRGB    gimp_color;
      gdouble    r = 0.0;
      gdouble    g = 0.0;
      gdouble    b = 0.0;
      gdouble    a = 1.0;
      GValue     value = { 0, };

      g_value_init (&value, GEGL_TYPE_COLOR);
      g_param_value_set_default (pspec, &value);

      gegl_color = g_value_get_object (&value);
      if (gegl_color)
        gegl_color_get_rgba (gegl_color, &r, &g, &b, &a);

      gimp_rgba_set (&gimp_color, r, g, b, a);

      g_value_unset (&value);

      copy = gimp_param_spec_rgb (pspec->name,
                                  g_param_spec_get_nick (pspec),
                                  g_param_spec_get_blurb (pspec),
                                  TRUE,
                                  &gimp_color,
                                  flags);
    }
  else if (G_IS_PARAM_SPEC_OBJECT (pspec) ||
           G_IS_PARAM_SPEC_POINTER (pspec))
    {
      /*  silently ignore object properties  */
    }
  else
    {
      g_warning ("%s: not supported: %s (%s)\n", G_STRFUNC,
                 g_type_name (G_TYPE_FROM_INSTANCE (pspec)), pspec->name);
    }

  if (copy)
    {
      GQuark      quark = g_quark_from_static_string ("gegl-property-keys");
      GHashTable *keys  = g_param_spec_get_qdata (pspec, quark);

      if (keys)
        g_param_spec_set_qdata (copy, quark, g_hash_table_ref (keys));
    }

  return copy;
}
コード例 #22
0
static gboolean
gst_lfo_control_source_bind (GstControlSource * source, GParamSpec * pspec)
{
  GType type, base;
  GstLFOControlSource *self = GST_LFO_CONTROL_SOURCE (source);
  gboolean ret = TRUE;

  /* get the fundamental base type */
  self->priv->type = base = type = G_PARAM_SPEC_VALUE_TYPE (pspec);
  while ((type = g_type_parent (type)))
    base = type;

  self->priv->base = base;
  /* restore type */
  type = self->priv->type;

  switch (base) {
    case G_TYPE_INT:{
      GParamSpecInt *tpspec = G_PARAM_SPEC_INT (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_int (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_int (&self->priv->maximum_value, tpspec->maximum);

      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_int (&self->priv->amplitude, 0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_int (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    case G_TYPE_UINT:{
      GParamSpecUInt *tpspec = G_PARAM_SPEC_UINT (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_uint (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_uint (&self->priv->maximum_value, tpspec->maximum);

      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_uint (&self->priv->amplitude, 0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_uint (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    case G_TYPE_LONG:{
      GParamSpecLong *tpspec = G_PARAM_SPEC_LONG (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_long (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_long (&self->priv->maximum_value, tpspec->maximum);
      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_long (&self->priv->amplitude, 0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_long (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    case G_TYPE_ULONG:{
      GParamSpecULong *tpspec = G_PARAM_SPEC_ULONG (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_ulong (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_ulong (&self->priv->maximum_value, tpspec->maximum);
      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_ulong (&self->priv->amplitude, 0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_ulong (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    case G_TYPE_INT64:{
      GParamSpecInt64 *tpspec = G_PARAM_SPEC_INT64 (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_int64 (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_int64 (&self->priv->maximum_value, tpspec->maximum);
      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_int64 (&self->priv->amplitude, 0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_int64 (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    case G_TYPE_UINT64:{
      GParamSpecUInt64 *tpspec = G_PARAM_SPEC_UINT64 (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_uint64 (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_uint64 (&self->priv->maximum_value, tpspec->maximum);
      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_uint64 (&self->priv->amplitude, 0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_uint64 (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    case G_TYPE_FLOAT:{
      GParamSpecFloat *tpspec = G_PARAM_SPEC_FLOAT (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_float (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_float (&self->priv->maximum_value, tpspec->maximum);
      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_float (&self->priv->amplitude, 0.0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_float (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    case G_TYPE_DOUBLE:{
      GParamSpecDouble *tpspec = G_PARAM_SPEC_DOUBLE (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_double (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_double (&self->priv->maximum_value, tpspec->maximum);
      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_float (&self->priv->amplitude, 0.0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_float (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    default:
      GST_WARNING ("incomplete implementation for paramspec type '%s'",
          G_PARAM_SPEC_TYPE_NAME (pspec));
      ret = FALSE;
      break;
  }

  if (ret) {
    GValue amp = { 0, }
    , off = {
    0,};

    /* This should never fail unless the user already set amplitude or offset
     * with an incompatible type before _bind () */
    if (!g_value_type_transformable (G_VALUE_TYPE (&self->priv->amplitude),
            base)
        || !g_value_type_transformable (G_VALUE_TYPE (&self->priv->offset),
            base)) {
      GST_WARNING ("incompatible types for amplitude or offset");
      gst_lfo_control_source_reset (self);
      return FALSE;
    }

    /* Generate copies and transform to the correct type */
    g_value_init (&amp, base);
    g_value_transform (&self->priv->amplitude, &amp);
    g_value_init (&off, base);
    g_value_transform (&self->priv->offset, &off);

    ret = gst_lfo_control_source_set_waveform (self, self->priv->waveform);

    g_value_unset (&self->priv->amplitude);
    g_value_init (&self->priv->amplitude, self->priv->base);
    g_value_transform (&amp, &self->priv->amplitude);

    g_value_unset (&self->priv->offset);
    g_value_init (&self->priv->offset, self->priv->base);
    g_value_transform (&off, &self->priv->offset);

    g_value_unset (&amp);
    g_value_unset (&off);
  }

  if (!ret)
    gst_lfo_control_source_reset (self);

  return ret;
}
コード例 #23
0
static void
dvb_base_bin_class_init (DvbBaseBinClass * klass)
{
  GObjectClass *gobject_class;
  GstElementClass *element_class;
  GstBinClass *bin_class;
  GstElementFactory *dvbsrc_factory;
  GObjectClass *dvbsrc_class;
  typedef struct
  {
    guint prop_id;
    const gchar *prop_name;
  } ProxyedProperty;
  ProxyedProperty *walk;
  ProxyedProperty proxyed_properties[] = {
    {PROP_ADAPTER, "adapter"},
    {PROP_FRONTEND, "frontend"},
    {PROP_DISEQC_SRC, "diseqc-source"},
    {PROP_FREQUENCY, "frequency"},
    {PROP_POLARITY, "polarity"},
    {PROP_SYMBOL_RATE, "symbol-rate"},
    {PROP_BANDWIDTH, "bandwidth"},
    {PROP_CODE_RATE_HP, "code-rate-hp"},
    {PROP_CODE_RATE_LP, "code-rate-lp"},
    {PROP_GUARD, "guard"},
    {PROP_MODULATION, "modulation"},
    {PROP_TRANS_MODE, "trans-mode"},
    {PROP_HIERARCHY, "hierarchy"},
    {PROP_INVERSION, "inversion"},
    {PROP_STATS_REPORTING_INTERVAL, "stats-reporting-interval"},
    {0, NULL}
  };

  bin_class = GST_BIN_CLASS (klass);
  bin_class->handle_message = dvb_base_bin_handle_message;

  element_class = GST_ELEMENT_CLASS (klass);
  element_class->change_state = dvb_base_bin_change_state;

  gobject_class = G_OBJECT_CLASS (klass);
  gobject_class->set_property = dvb_base_bin_set_property;
  gobject_class->get_property = dvb_base_bin_get_property;
  gobject_class->dispose = dvb_base_bin_dispose;
  gobject_class->finalize = dvb_base_bin_finalize;

  /* install dvbsrc properties */
  dvbsrc_factory = gst_element_factory_find ("dvbsrc");
  dvbsrc_class = g_type_class_ref (dvbsrc_factory->type);
  walk = proxyed_properties;
  while (walk->prop_name != NULL) {
    GParamSpec *pspec;
    GParamSpec *our_pspec;

    pspec = g_object_class_find_property (dvbsrc_class, walk->prop_name);
    if (pspec != NULL) {
      GType param_type = G_PARAM_SPEC_TYPE (pspec);

      if (param_type == G_TYPE_PARAM_INT) {
        GParamSpecInt *src_pspec = G_PARAM_SPEC_INT (pspec);

        our_pspec = g_param_spec_int (g_param_spec_get_name (pspec),
            g_param_spec_get_nick (pspec), g_param_spec_get_blurb (pspec),
            src_pspec->minimum, src_pspec->maximum, src_pspec->default_value,
            pspec->flags);
      } else if (param_type == G_TYPE_PARAM_UINT) {
        GParamSpecUInt *src_pspec = G_PARAM_SPEC_UINT (pspec);

        our_pspec = g_param_spec_uint (g_param_spec_get_name (pspec),
            g_param_spec_get_nick (pspec), g_param_spec_get_blurb (pspec),
            src_pspec->minimum, src_pspec->maximum, src_pspec->default_value,
            pspec->flags);
      } else if (param_type == G_TYPE_PARAM_STRING) {
        GParamSpecString *src_pspec = G_PARAM_SPEC_STRING (pspec);

        our_pspec = g_param_spec_string (g_param_spec_get_name (pspec),
            g_param_spec_get_nick (pspec), g_param_spec_get_blurb (pspec),
            src_pspec->default_value, pspec->flags);
      } else if (param_type == G_TYPE_PARAM_ENUM) {
        GParamSpecEnum *src_pspec = G_PARAM_SPEC_ENUM (pspec);

        our_pspec = g_param_spec_enum (g_param_spec_get_name (pspec),
            g_param_spec_get_nick (pspec), g_param_spec_get_blurb (pspec),
            pspec->value_type, src_pspec->default_value, pspec->flags);
      } else {
        GST_ERROR ("Unsupported property type %d for property %s",
            param_type, g_param_spec_get_name (pspec));
        ++walk;
        continue;
      }

      g_object_class_install_property (gobject_class, walk->prop_id, our_pspec);
    } else {
      g_warning ("dvbsrc has no property named %s", walk->prop_name);
    }
    ++walk;
  }
  g_type_class_unref (dvbsrc_class);

  g_object_class_install_property (gobject_class, PROP_PROGRAM_NUMBERS,
      g_param_spec_string ("program-numbers",
          "Program Numbers",
          "Colon separated list of programs", "", G_PARAM_READWRITE));
}
コード例 #24
0
ファイル: gst-inspect.c プロジェクト: wosigh/gstreamer
static void
print_element_properties_info (GstElement * element)
{
  GParamSpec **property_specs;
  guint num_properties, i;
  gboolean readable;
  gboolean first_flag;

  property_specs = g_object_class_list_properties
      (G_OBJECT_GET_CLASS (element), &num_properties);
  n_print ("\n");
  n_print ("Element Properties:\n");

  for (i = 0; i < num_properties; i++) {
    GValue value = { 0, };
    GParamSpec *param = property_specs[i];

    readable = FALSE;

    g_value_init (&value, param->value_type);

    n_print ("  %-20s: %s\n", g_param_spec_get_name (param),
        g_param_spec_get_blurb (param));

    first_flag = TRUE;
    n_print ("%-23.23s flags: ", "");
    if (param->flags & G_PARAM_READABLE) {
      g_object_get_property (G_OBJECT (element), param->name, &value);
      readable = TRUE;
      if (!first_flag)
        g_print (", ");
      else
        first_flag = FALSE;
      g_print (_("readable"));
    }
    if (param->flags & G_PARAM_WRITABLE) {
      if (!first_flag)
        g_print (", ");
      else
        first_flag = FALSE;
      g_print (_("writable"));
    }
    if (param->flags & GST_PARAM_CONTROLLABLE) {
      if (!first_flag)
        g_print (", ");
      else
        first_flag = FALSE;
      g_print (_("controllable"));
    }
    n_print ("\n");

    switch (G_VALUE_TYPE (&value)) {
      case G_TYPE_STRING:
      {
        GParamSpecString *pstring = G_PARAM_SPEC_STRING (param);

        n_print ("%-23.23s String. ", "");

        if (pstring->default_value == NULL)
          g_print ("Default: null ");
        else
          g_print ("Default: \"%s\" ", pstring->default_value);

        if (readable) {
          const char *string_val = g_value_get_string (&value);

          if (string_val == NULL)
            g_print ("Current: null");
          else
            g_print ("Current: \"%s\"", string_val);
        }
        break;
      }
      case G_TYPE_BOOLEAN:
      {
        GParamSpecBoolean *pboolean = G_PARAM_SPEC_BOOLEAN (param);

        n_print ("%-23.23s Boolean. ", "");
        g_print ("Default: %s ", (pboolean->default_value ? "true" : "false"));
        if (readable)
          g_print ("Current: %s",
              (g_value_get_boolean (&value) ? "true" : "false"));
        break;
      }
      case G_TYPE_ULONG:
      {
        GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);

        n_print ("%-23.23s Unsigned Long. ", "");
        g_print ("Range: %lu - %lu Default: %lu ",
            pulong->minimum, pulong->maximum, pulong->default_value);
        if (readable)
          g_print ("Current: %lu", g_value_get_ulong (&value));
        break;
      }
      case G_TYPE_LONG:
      {
        GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);

        n_print ("%-23.23s Long. ", "");
        g_print ("Range: %ld - %ld Default: %ld ",
            plong->minimum, plong->maximum, plong->default_value);
        if (readable)
          g_print ("Current: %ld", g_value_get_long (&value));
        break;
      }
      case G_TYPE_UINT:
      {
        GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);

        n_print ("%-23.23s Unsigned Integer. ", "");
        g_print ("Range: %u - %u Default: %u ",
            puint->minimum, puint->maximum, puint->default_value);
        if (readable)
          g_print ("Current: %u", g_value_get_uint (&value));
        break;
      }
      case G_TYPE_INT:
      {
        GParamSpecInt *pint = G_PARAM_SPEC_INT (param);

        n_print ("%-23.23s Integer. ", "");
        g_print ("Range: %d - %d Default: %d ",
            pint->minimum, pint->maximum, pint->default_value);
        if (readable)
          g_print ("Current: %d", g_value_get_int (&value));
        break;
      }
      case G_TYPE_UINT64:
      {
        GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);

        n_print ("%-23.23s Unsigned Integer64. ", "");
        g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
            " Default: %" G_GUINT64_FORMAT " ",
            puint64->minimum, puint64->maximum, puint64->default_value);
        if (readable)
          g_print ("Current: %" G_GUINT64_FORMAT, g_value_get_uint64 (&value));
        break;
      }
      case G_TYPE_INT64:
      {
        GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);

        n_print ("%-23.23s Integer64. ", "");
        g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
            " Default: %" G_GINT64_FORMAT " ",
            pint64->minimum, pint64->maximum, pint64->default_value);
        if (readable)
          g_print ("Current: %" G_GINT64_FORMAT, g_value_get_int64 (&value));
        break;
      }
      case G_TYPE_FLOAT:
      {
        GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);

        n_print ("%-23.23s Float. ", "");
        g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
            pfloat->minimum, pfloat->maximum, pfloat->default_value);
        if (readable)
          g_print ("Current: %15.7g", g_value_get_float (&value));
        break;
      }
      case G_TYPE_DOUBLE:
      {
        GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);

        n_print ("%-23.23s Double. ", "");
        g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
            pdouble->minimum, pdouble->maximum, pdouble->default_value);
        if (readable)
          g_print ("Current: %15.7g", g_value_get_double (&value));
        break;
      }
      default:
        if (param->value_type == GST_TYPE_CAPS) {
          const GstCaps *caps = gst_value_get_caps (&value);

          if (!caps)
            n_print ("%-23.23s Caps (NULL)", "");
          else {
            print_caps (caps, "                           ");
          }
        } else if (G_IS_PARAM_SPEC_ENUM (param)) {
          GParamSpecEnum *penum = G_PARAM_SPEC_ENUM (param);
          GEnumValue *values;
          guint j = 0;
          gint enum_value;
          const gchar *def_val_nick = "", *cur_val_nick = "";

          values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
          enum_value = g_value_get_enum (&value);

          while (values[j].value_name) {
            if (values[j].value == enum_value)
              cur_val_nick = values[j].value_nick;
            if (values[j].value == penum->default_value)
              def_val_nick = values[j].value_nick;
            j++;
          }

          n_print
              ("%-23.23s Enum \"%s\" Default: %d, \"%s\" Current: %d, \"%s\"",
              "", g_type_name (G_VALUE_TYPE (&value)), penum->default_value,
              def_val_nick, enum_value, cur_val_nick);

          j = 0;
          while (values[j].value_name) {
            g_print ("\n");
            if (_name)
              g_print ("%s", _name);
            g_print ("%-23.23s    (%d): %-16s - %s", "",
                values[j].value, values[j].value_nick, values[j].value_name);
            j++;
          }
          /* g_type_class_unref (ec); */
        } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
          GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
          GFlagsValue *values;
          guint j = 0;
          gint flags_value;
          GString *cur_flags = NULL, *def_flags = NULL;

          values = G_FLAGS_CLASS (g_type_class_ref (param->value_type))->values;
          flags_value = g_value_get_flags (&value);

          while (values[j].value_name) {
            if (values[j].value & flags_value) {
              if (cur_flags) {
                g_string_append_printf (cur_flags, " | %s",
                    values[j].value_nick);
              } else {
                cur_flags = g_string_new (values[j].value_nick);
              }
            }
            if (values[j].value & pflags->default_value) {
              if (def_flags) {
                g_string_append_printf (def_flags, " | %s",
                    values[j].value_nick);
              } else {
                def_flags = g_string_new (values[j].value_nick);
              }
            }
            j++;
          }

          n_print
              ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\" Current: 0x%08x, \"%s\"",
              "", g_type_name (G_VALUE_TYPE (&value)), pflags->default_value,
              (def_flags ? def_flags->str : "(none)"), flags_value,
              (cur_flags ? cur_flags->str : "(none)"));

          j = 0;
          while (values[j].value_name) {
            g_print ("\n");
            if (_name)
              g_print ("%s", _name);
            g_print ("%-23.23s    (0x%08x): %-16s - %s", "",
                values[j].value, values[j].value_nick, values[j].value_name);
            j++;
          }

          if (cur_flags)
            g_string_free (cur_flags, TRUE);
          if (def_flags)
            g_string_free (def_flags, TRUE);
        } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
          n_print ("%-23.23s Object of type \"%s\"", "",
              g_type_name (param->value_type));
        } else if (G_IS_PARAM_SPEC_BOXED (param)) {
          n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
              g_type_name (param->value_type));
        } else if (G_IS_PARAM_SPEC_POINTER (param)) {
          if (param->value_type != G_TYPE_POINTER) {
            n_print ("%-23.23s Pointer of type \"%s\".", "",
                g_type_name (param->value_type));
          } else {
            n_print ("%-23.23s Pointer.", "");
          }
        } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
          GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);

          if (pvarray->element_spec) {
            n_print ("%-23.23s Array of GValues of type \"%s\"", "",
                g_type_name (pvarray->element_spec->value_type));
          } else {
            n_print ("%-23.23s Array of GValues", "");
          }
        } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
          GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);

          n_print ("%-23.23s Fraction. ", "");

          g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
              pfraction->min_num, pfraction->min_den,
              pfraction->max_num, pfraction->max_den,
              pfraction->def_num, pfraction->def_den);
          if (readable)
            g_print ("Current: %d/%d",
                gst_value_get_fraction_numerator (&value),
                gst_value_get_fraction_denominator (&value));

        } else if (GST_IS_PARAM_SPEC_MINI_OBJECT (param)) {
          n_print ("%-23.23s MiniObject of type \"%s\"", "",
              g_type_name (param->value_type));
        } else {
          n_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type,
              g_type_name (param->value_type));
        }
        break;
    }
    if (!readable)
      g_print (" Write only\n");
    else
      g_print ("\n");

    g_value_reset (&value);
  }
  if (num_properties == 0)
    n_print ("  none\n");

  g_free (property_specs);
}
コード例 #25
0
ファイル: fs-utils.c プロジェクト: shadeslayer/farstream
void
fs_utils_set_bitrate (GstElement *element, glong bitrate)
{
  GParamSpec *spec;
  const char *elements_in_kbps[] = { "lamemp3enc", "lame", "x264enc", "twolame",
    "mpeg2enc", NULL
  };
  int i;
  GstElementFactory *factory;
  const gchar *factory_name = NULL;

  g_return_if_fail (GST_IS_ELEMENT (element));

  spec = g_object_class_find_property (G_OBJECT_GET_CLASS (element), "bitrate");
  g_return_if_fail (spec != NULL);

  factory = gst_element_get_factory (element);
  if (factory)
    factory_name = gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory));

  /* divide by 1000 for elements that are known to use kbs */
  for (i = 0; elements_in_kbps[i]; i++)
    if (factory_name && !strcmp (factory_name, elements_in_kbps[i]))
    {
      bitrate /= 1000;
      break;
    }

  if (G_PARAM_SPEC_TYPE (spec) == G_TYPE_LONG)
  {
    g_object_set (element, "bitrate", (glong) CLAMP (bitrate,
            G_PARAM_SPEC_LONG (spec)->minimum,
            G_PARAM_SPEC_LONG (spec)->maximum), NULL);
  }
  else if (G_PARAM_SPEC_VALUE_TYPE (spec) == G_TYPE_ULONG)
  {
    g_object_set (element, "bitrate", (gulong) CLAMP (bitrate,
            G_PARAM_SPEC_ULONG (spec)->minimum,
            G_PARAM_SPEC_ULONG (spec)->maximum), NULL);
  }
  else if (G_PARAM_SPEC_VALUE_TYPE (spec) == G_TYPE_INT)
  {
    gint tmp = MIN (bitrate, G_MAXINT);

    g_object_set (element, "bitrate", (gint)  CLAMP (tmp,
            G_PARAM_SPEC_INT (spec)->minimum,
            G_PARAM_SPEC_INT (spec)->maximum), NULL);
  }
  else if (G_PARAM_SPEC_VALUE_TYPE (spec) == G_TYPE_UINT)
  {
    guint tmp = MIN (bitrate, G_MAXUINT);

    g_object_set (element, "bitrate", (guint) CLAMP (tmp,
            G_PARAM_SPEC_UINT (spec)->minimum,
            G_PARAM_SPEC_UINT (spec)->maximum), NULL);
  }
  else
  {
    g_warning ("bitrate parameter of unknown type");
  }
}
コード例 #26
0
static GtkCellEditable *
parasite_property_cell_renderer_start_editing(GtkCellRenderer *renderer,
        GdkEvent *event,
        GtkWidget *widget,
        const gchar *path,
        GdkRectangle *background_area,
        GdkRectangle *cell_area,
        GtkCellRendererState flags)
{
    PangoFontDescription *font_desc;
    GtkCellEditable *editable = NULL;
    GObject *object;
    const char *name;
    GValue gvalue = {0};
    GParamSpec *prop;

    g_object_get(renderer,
                 "object", &object,
                 "name", &name,
                 NULL);

    prop = g_object_class_find_property(G_OBJECT_GET_CLASS(object), name);

    if (!(prop->flags & G_PARAM_WRITABLE))
        return NULL;

    g_value_init(&gvalue, prop->value_type);
    g_object_get_property(object, name, &gvalue);

    if (G_VALUE_HOLDS_ENUM(&gvalue) || G_VALUE_HOLDS_BOOLEAN(&gvalue))
    {
        GtkWidget *combobox = gtk_combo_box_new_text();
        gtk_widget_show(combobox);
        g_object_set(G_OBJECT(combobox), "has-frame", FALSE, NULL);
        GList *renderers;

        if (G_VALUE_HOLDS_BOOLEAN(&gvalue))
        {
            gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), "FALSE");
            gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), "TRUE");

            gtk_combo_box_set_active(GTK_COMBO_BOX(combobox),
                                     g_value_get_boolean(&gvalue) ? 1 : 0);
        }
        else if (G_VALUE_HOLDS_ENUM(&gvalue))
        {
            gint value = g_value_get_enum(&gvalue);
            GEnumClass *enum_class = G_PARAM_SPEC_ENUM(prop)->enum_class;
            guint i;

            for (i = 0; i < enum_class->n_values; i++)
            {
                GEnumValue *enum_value = &enum_class->values[i];

                gtk_combo_box_append_text(GTK_COMBO_BOX(combobox),
                                          enum_value->value_name);

                if (enum_value->value == value)
                    gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), i);
            }

        }

        renderers = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(combobox));
        g_object_set(G_OBJECT(renderers->data), "scale", TREE_TEXT_SCALE, NULL);
        g_list_free(renderers);

        editable = GTK_CELL_EDITABLE(combobox);
    }
    else if (G_VALUE_HOLDS_STRING(&gvalue))
    {
        GtkWidget *entry = gtk_entry_new();
        gtk_widget_show(entry);
        gtk_entry_set_text(GTK_ENTRY(entry), g_value_get_string(&gvalue));

        editable = GTK_CELL_EDITABLE(entry);
    }
    else if (G_VALUE_HOLDS_INT(&gvalue)    ||
             G_VALUE_HOLDS_UINT(&gvalue)   ||
             G_VALUE_HOLDS_INT64(&gvalue)  ||
             G_VALUE_HOLDS_UINT64(&gvalue) ||
             G_VALUE_HOLDS_LONG(&gvalue)   ||
             G_VALUE_HOLDS_ULONG(&gvalue)  ||
             G_VALUE_HOLDS_DOUBLE(&gvalue))
    {
        double min, max, value;
        GtkWidget *spinbutton;
        guint digits = 0;

        if (G_VALUE_HOLDS_INT(&gvalue))
        {
            GParamSpecInt *paramspec = G_PARAM_SPEC_INT(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_int(&gvalue);
        }
        else if (G_VALUE_HOLDS_UINT(&gvalue))
        {
            GParamSpecUInt *paramspec = G_PARAM_SPEC_UINT(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_uint(&gvalue);
        }
        else if (G_VALUE_HOLDS_INT64(&gvalue))
        {
            GParamSpecInt64 *paramspec = G_PARAM_SPEC_INT64(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_int64(&gvalue);
        }
        else if (G_VALUE_HOLDS_UINT64(&gvalue))
        {
            GParamSpecUInt64 *paramspec = G_PARAM_SPEC_UINT64(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_uint64(&gvalue);
        }
        else if (G_VALUE_HOLDS_LONG(&gvalue))
        {
            GParamSpecLong *paramspec = G_PARAM_SPEC_LONG(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_long(&gvalue);
        }
        else if (G_VALUE_HOLDS_ULONG(&gvalue))
        {
            GParamSpecULong *paramspec = G_PARAM_SPEC_ULONG(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_ulong(&gvalue);
        }
        else if (G_VALUE_HOLDS_DOUBLE(&gvalue))
        {
            GParamSpecDouble *paramspec = G_PARAM_SPEC_DOUBLE(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_double(&gvalue);
            digits = 2;
        }
        else
        {
            // Shouldn't really be able to happen.
            return NULL;
        }

        spinbutton = gtk_spin_button_new_with_range(min, max, 1);
        gtk_widget_show(spinbutton);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton), value);
        gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinbutton), digits);

        editable = GTK_CELL_EDITABLE(spinbutton);
    }

    font_desc = pango_font_description_new();
    pango_font_description_set_size(font_desc, 8 * PANGO_SCALE);
    gtk_widget_modify_font(GTK_WIDGET(editable), font_desc);
    pango_font_description_free(font_desc);

    g_value_unset(&gvalue);

    g_signal_connect(G_OBJECT(editable), "editing_done",
                     G_CALLBACK(parasite_property_cell_renderer_stop_editing),
                     renderer);

    g_object_set_data_full(G_OBJECT(editable), "_prop_name", g_strdup(name),
                           g_free);
    g_object_set_data(G_OBJECT(editable), "_prop_object", object);

    return editable;
}
コード例 #27
0
ファイル: gst-xmlinspect.c プロジェクト: AlerIl/gstreamer0.10
static void
print_element_properties (GstElement * element, gint pfx)
{
  GParamSpec **property_specs;
  guint num_properties;
  gint i;
  gboolean readable;

  property_specs = g_object_class_list_properties
      (G_OBJECT_GET_CLASS (element), &num_properties);

  PUT_START_TAG (pfx, "element-properties");

  for (i = 0; i < num_properties; i++) {
    GValue value = { 0, };
    GParamSpec *param = property_specs[i];

    readable = FALSE;

    g_value_init (&value, param->value_type);
    if (param->flags & G_PARAM_READABLE) {
      g_object_get_property (G_OBJECT (element), param->name, &value);
      readable = TRUE;
    }
    PUT_START_TAG (pfx + 1, "element-property");
    PUT_ESCAPED (pfx + 2, "name", g_param_spec_get_name (param));
    PUT_ESCAPED (pfx + 2, "type", g_type_name (param->value_type));
    PUT_ESCAPED (pfx + 2, "nick", g_param_spec_get_nick (param));
    PUT_ESCAPED (pfx + 2, "blurb", g_param_spec_get_blurb (param));
    if (readable) {
      PUT_ESCAPED (pfx + 2, "flags", "RW");
    } else {
      PUT_ESCAPED (pfx + 2, "flags", "W");
    }

    switch (G_VALUE_TYPE (&value)) {
      case G_TYPE_STRING:
        PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
        break;
      case G_TYPE_BOOLEAN:
        PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
        break;
      case G_TYPE_ULONG:
      {
        GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);

        PUT_STRING (pfx + 2, "<range min=\"%lu\" max=\"%lu\"/>",
            pulong->minimum, pulong->maximum);
        PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
        break;
      }
      case G_TYPE_LONG:
      {
        GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);

        PUT_STRING (pfx + 2, "<range min=\"%ld\" max=\"%ld\"/>",
            plong->minimum, plong->maximum);
        PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
        break;
      }
      case G_TYPE_UINT:
      {
        GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);

        PUT_STRING (pfx + 2, "<range min=\"%u\" max=\"%u\"/>",
            puint->minimum, puint->maximum);
        PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
        break;
      }
      case G_TYPE_INT:
      {
        GParamSpecInt *pint = G_PARAM_SPEC_INT (param);

        PUT_STRING (pfx + 2, "<range min=\"%d\" max=\"%d\"/>",
            pint->minimum, pint->maximum);
        PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
        break;
      }
      case G_TYPE_UINT64:
      {
        GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);

        PUT_STRING (pfx + 2,
            "<range min=\"%" G_GUINT64_FORMAT "\" max=\"%" G_GUINT64_FORMAT
            "\"/>", puint64->minimum, puint64->maximum);
        PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
        break;
      }
      case G_TYPE_INT64:
      {
        GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);

        PUT_STRING (pfx + 2,
            "<range min=\"%" G_GINT64_FORMAT "\" max=\"%" G_GINT64_FORMAT
            "\"/>", pint64->minimum, pint64->maximum);
        PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
        break;
      }
      case G_TYPE_FLOAT:
      {
        GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);

        PUT_STRING (pfx + 2, "<range min=\"%f\" max=\"%f\"/>",
            pfloat->minimum, pfloat->maximum);
        PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
        break;
      }
      case G_TYPE_DOUBLE:
      {
        GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);

        PUT_STRING (pfx + 2, "<range min=\"%g\" max=\"%g\"/>",
            pdouble->minimum, pdouble->maximum);
        PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
        break;
      }
      default:
        if (param->value_type == GST_TYPE_CAPS) {
          GstCaps *caps = g_value_peek_pointer (&value);

          if (!caps)
            PUT_ESCAPED (pfx + 2, "default", "NULL");
          else {
            print_caps (caps, 2);
          }
        } else if (G_IS_PARAM_SPEC_ENUM (param)) {
          GEnumValue *values;
          guint j = 0;
          gint enum_value;

          values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
          enum_value = g_value_get_enum (&value);

          while (values[j].value_name) {
            if (values[j].value == enum_value)
              break;
            j++;
          }
          PUT_STRING (pfx + 2, "<default>%d</default>", values[j].value);

          PUT_START_TAG (pfx + 2, "enum-values");
          j = 0;
          while (values[j].value_name) {
            PUT_STRING (pfx + 3, "<value value=\"%d\" nick=\"%s\"/>",
                values[j].value, values[j].value_nick);
            j++;
          }
          PUT_END_TAG (pfx + 2, "enum-values");
        } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
          GFlagsValue *values;
          guint j = 0;
          gint flags_value;

          values = G_FLAGS_CLASS (g_type_class_ref (param->value_type))->values;
          flags_value = g_value_get_flags (&value);

          PUT_STRING (pfx + 2, "<default>%d</default>", flags_value);

          PUT_START_TAG (pfx + 2, "flags");
          j = 0;
          while (values[j].value_name) {
            PUT_STRING (pfx + 3, "<flag value=\"%d\" nick=\"%s\"/>",
                values[j].value, values[j].value_nick);
            j++;
          }
          PUT_END_TAG (pfx + 2, "flags");
        } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
          PUT_ESCAPED (pfx + 2, "object-type", g_type_name (param->value_type));
        }
        break;
    }

    PUT_END_TAG (pfx + 1, "element-property");
  }
  PUT_END_TAG (pfx, "element-properties");
  g_free (property_specs);
}