Пример #1
0
static void
add_reference (GString           *str,
               GParamSpec        *pspec)
{
   const gchar *table_name;
   const gchar *property_name;

   table_name = g_param_spec_get_qdata(pspec, GOM_RESOURCE_REF_TABLE_CLASS);
   if (!table_name)
      return;
   property_name = g_param_spec_get_qdata(pspec, GOM_RESOURCE_REF_PROPERTY_NAME);
   g_assert(property_name);

   g_string_append_printf(str, " REFERENCES [%s]([%s]) ", table_name, property_name);
}
Пример #2
0
static inline void
tidy_stylable_get_property_internal (TidyStylable *stylable,
                                     GParamSpec   *pspec,
                                     GValue       *value)
{
  TidyStyle *style;
  GValue real_value = { 0, };
  gchar *real_name;

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

  style = tidy_stylable_get_style (stylable);
  if (!tidy_style_has_property (style, real_name))
    {
      /* the style has no property set, use the default value
       * from the GParamSpec
       */
      g_param_value_set_default (pspec, value);
      g_free (real_name);
      return;
    }

  tidy_style_get_property (style, real_name, &real_value);

  g_value_copy (&real_value, value);
  g_value_unset (&real_value);

  g_free (real_name);
}
Пример #3
0
static void
resource_get_property(GObject     *object,
                      const gchar *property_name,
                      GValue      *value)
{
   GValue real_value = { 0, };
   GomResourceToBytesFunc to_bytes;
   GParamSpec *pspec;
   GBytes *bytes;

   pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(object), property_name);
   g_assert(pspec);

   g_value_init(&real_value, pspec->value_type);
   g_object_get_property(object, property_name, &real_value);

   to_bytes = g_param_spec_get_qdata(pspec, GOM_RESOURCE_TO_BYTES_FUNC);
   if (!to_bytes) {
      *value = real_value;
      return;
   }

   bytes = (* to_bytes) (&real_value);
   g_value_init(value, G_TYPE_BYTES);
   g_value_take_boxed(value, bytes);

   g_value_unset(&real_value);
}
Пример #4
0
static void
gst_xvidenc_init (GstXvidEnc * xvidenc)
{
  GParamSpec **pspecs;
  guint i, num_props;

  /* create the sink pad */
  xvidenc->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink");
  gst_element_add_pad (GST_ELEMENT (xvidenc), xvidenc->sinkpad);

  gst_pad_set_chain_function (xvidenc->sinkpad,
      GST_DEBUG_FUNCPTR (gst_xvidenc_chain));
  gst_pad_set_setcaps_function (xvidenc->sinkpad,
      GST_DEBUG_FUNCPTR (gst_xvidenc_setcaps));
  gst_pad_set_getcaps_function (xvidenc->sinkpad,
      GST_DEBUG_FUNCPTR (gst_xvidenc_getcaps));
  gst_pad_set_event_function (xvidenc->sinkpad,
      GST_DEBUG_FUNCPTR (gst_xvidenc_handle_sink_event));

  /* create the src pad */
  xvidenc->srcpad = gst_pad_new_from_static_template (&src_template, "src");
  gst_element_add_pad (GST_ELEMENT (xvidenc), xvidenc->srcpad);
  gst_pad_use_fixed_caps (xvidenc->srcpad);

  /* init properties. */
  xvidenc->width = xvidenc->height = xvidenc->csp = -1;
  xvidenc->par_width = xvidenc->par_height = 1;

  /* set defaults for user properties */
  pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (xvidenc),
      &num_props);

  for (i = 0; i < num_props; ++i) {
    GValue val = { 0, };
    GParamSpec *pspec = pspecs[i];

    /* only touch those that are really ours; i.e. should have some qdata */
    if (!g_param_spec_get_qdata (pspec, xvidenc_pspec_quark))
      continue;
    g_value_init (&val, G_PARAM_SPEC_VALUE_TYPE (pspec));
    g_param_value_set_default (pspec, &val);
    g_object_set_property (G_OBJECT (xvidenc), g_param_spec_get_name (pspec),
        &val);
    g_value_unset (&val);
  }

  g_free (pspecs);

  /* set xvid handle to NULL */
  xvidenc->handle = NULL;

  /* get a queue to keep time info if frames get delayed */
  xvidenc->delay = NULL;

  /* cache some xvid data so need not rebuild for each frame */
  xvidenc->xframe_cache = NULL;
}
Пример #5
0
static gboolean
is_new_in_version (GParamSpec *pspec,
                   guint       version)
{
   /* This is a bit ugly, but this allows us to consider
    * an unset value to be new in version 1. Version 0
    * is for "pre-GOM" SQLite usage. */
   return (GPOINTER_TO_INT(g_param_spec_get_qdata(pspec, GOM_RESOURCE_NEW_IN_VERSION)) + 1) == version;
}
Пример #6
0
/**
 * uca_camera_is_writable_during_acquisition:
 * @camera: A #UcaCamera object
 * @prop_name: Name of property
 *
 * Check if @prop_name can be written at run-time. This is %FALSE if the
 * property is read-only, if uca_camera_set_writable() has not been called or
 * uca_camera_set_writable() was called with %FALSE.
 *
 * Returns: %TRUE if the property can be written at acquisition time.
 * Since: 1.6
 */
gboolean
uca_camera_is_writable_during_acquisition (UcaCamera *camera,
                                           const gchar *prop_name)
{
    GParamSpec *pspec;

    pspec = get_param_spec_by_name (camera, prop_name);

    return (pspec->flags & G_PARAM_WRITABLE) &&
            g_param_spec_get_qdata (pspec, UCA_WRITABLE_QUARK);
}
Пример #7
0
/**
 * uca_camera_pspec_set_writable: (skip)
 * @pspec: A #GParamSpec
 * @writable: %TRUE if property can be written during acquisition
 *
 * Sets a flag that defines if the property defined by @pspec can be written
 * during an acquisition. This can be used during UcaCamera class
 * initialization.
 *
 * Since: 2.1
 */
void
uca_camera_pspec_set_writable (GParamSpec *pspec,
                               gboolean writable)
{
    if (pspec != NULL) {
        if (g_param_spec_get_qdata (pspec, UCA_WRITABLE_QUARK) != NULL)
            g_warning ("::%s is already fixed", pspec->name);
        else
            g_param_spec_set_qdata (pspec, UCA_WRITABLE_QUARK, GINT_TO_POINTER (writable));
    }
}
Пример #8
0
static void
add_notnull (GString           *str,
             GParamSpec        *pspec)
{
   gboolean notnull;
   notnull = GPOINTER_TO_UINT(g_param_spec_get_qdata(pspec, GOM_RESOURCE_NOTNULL));

   if (!notnull)
       return;

   g_string_append_printf(str, " NOT NULL ");
}
Пример #9
0
static void
add_unique (GString           *str,
            GParamSpec        *pspec)
{
   gboolean unique;
   unique = GPOINTER_TO_UINT(g_param_spec_get_qdata(pspec, GOM_RESOURCE_UNIQUE));

   if (!unique)
       return;

   g_string_append_printf(str, " UNIQUE ");
}
Пример #10
0
static void
uca_camera_set_property_unit (GParamSpec *pspec, UcaUnit unit)
{
    UcaUnit old_unit;

    old_unit = (UcaUnit) GPOINTER_TO_INT (g_param_spec_get_qdata (pspec, UCA_UNIT_QUARK));

    if (old_unit != unit && old_unit != UCA_UNIT_NA)
        g_warning ("::%s already has a different unit", pspec->name);
    else
        g_param_spec_set_qdata (pspec, UCA_UNIT_QUARK, GINT_TO_POINTER (unit));
}
Пример #11
0
static void
gst_fameenc_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec)
{
  GstFameEnc *fameenc;

  g_return_if_fail (GST_IS_FAMEENC (object));
  fameenc = GST_FAMEENC (object);

  switch (prop_id) {
    case ARG_BITRATE:
      g_value_set_int (value, fameenc->fp.bitrate);
      break;
    case ARG_QUALITY:
      g_value_set_int (value, fameenc->fp.quality);
      break;
    case ARG_PATTERN:
      g_value_set_string (value, fameenc->pattern);
      break;
    case ARG_FAME_VERBOSE:
      g_value_set_boolean (value, fameenc->verbose);
      break;
    case ARG_BUFFER_SIZE:
      g_value_set_int (value, fameenc->buffer_size);
      break;
    case ARG_FRAMES_PER_SEQUENCE:
      g_value_set_int (value, fameenc->fp.frames_per_sequence);
      break;
    default:
      if (prop_id >= ARG_FAME_PROPS_START) {
        gchar *name;
        gint index = 0;
        GEnumValue *values;
        fame_object_t *f_object;

        values = G_ENUM_CLASS (g_type_class_ref (pspec->value_type))->values;
        name = (gchar *) g_param_spec_get_qdata (pspec, fame_object_name);

        f_object = fame_get_object (fameenc->fc, name);

        while (values[index].value_name) {
          if (!strcmp (values[index].value_nick, f_object->name)) {
            g_value_set_enum (value, index);
            return;
          }
          index++;
        }
      }
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
Пример #12
0
VALUE
rbgobj_get_ruby_object_from_param_spec(GParamSpec* pspec, gboolean alloc)
{
    gpointer data = g_param_spec_get_qdata(pspec, qparamspec);
    if (data)
        return (VALUE)data;
    else if (alloc) {
        VALUE result = pspec_s_allocate(GTYPE2CLASS(G_PARAM_SPEC_TYPE(pspec)));
        rbgobj_param_spec_initialize(result, pspec);
        return result;
    } else
        return Qnil;
}
Пример #13
0
static void
gst_fameenc_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
{
  GstFameEnc *fameenc;

  g_return_if_fail (GST_IS_FAMEENC (object));
  fameenc = GST_FAMEENC (object);

  if (fameenc->initialized) {
    GST_DEBUG
        ("error: fameenc encoder already initialized, cannot set properties !");
    return;
  }

  switch (prop_id) {
    case ARG_BITRATE:
      fameenc->fp.bitrate = g_value_get_int (value);
      break;
    case ARG_QUALITY:
      fameenc->fp.quality = CLAMP (g_value_get_int (value), 0, 100);
      break;
    case ARG_PATTERN:
      g_free (fameenc->pattern);
      fameenc->pattern = g_strdup (g_value_get_string (value));
      break;
    case ARG_FAME_VERBOSE:
      fameenc->verbose = g_value_get_boolean (value);
      break;
    case ARG_BUFFER_SIZE:
      fameenc->buffer_size = g_value_get_int (value);
      break;
    case ARG_FRAMES_PER_SEQUENCE:
      fameenc->fp.frames_per_sequence = g_value_get_int (value);
      break;
    default:
      if (prop_id >= ARG_FAME_PROPS_START) {
        gchar *name;
        gint index = g_value_get_enum (value);
        GEnumValue *values;

        values = G_ENUM_CLASS (g_type_class_ref (pspec->value_type))->values;
        name = (gchar *) g_param_spec_get_qdata (pspec, fame_object_name);

        fame_register (fameenc->fc, name, fame_get_object (fameenc->fc,
                values[index].value_name));
      } else
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
Пример #14
0
static inline void
tidy_stylable_set_property_internal (TidyStylable       *stylable,
                                     GParamSpec         *pspec,
                                     const GValue       *value,
                                     GObjectNotifyQueue *nqueue)
{
  GValue tmp_value = { 0, };

  g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));

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

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

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

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

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

      g_free (real_name);
    }

  g_value_unset (&tmp_value);
}
Пример #15
0
/**
 * uca_camera_get_unit:
 * @camera: A #UcaCamera object
 * @prop_name: Name of a property
 *
 * Returns the unit associated with @prop_name of @camera.
 *
 * Returns: A #UcaUnit value associated with @prop_name. If there is none, the
 * value will be #UCA_UNIT_NA.
 * Since: 1.1
 */
UcaUnit
uca_camera_get_unit (UcaCamera *camera,
                     const gchar *prop_name)
{
    GParamSpec *pspec;
    gpointer data;

    pspec  = get_param_spec_by_name (camera, prop_name);

    if (pspec == NULL)
        return UCA_UNIT_NA;

    data = g_param_spec_get_qdata (pspec, UCA_UNIT_QUARK);
    return data == NULL ? UCA_UNIT_NA : GPOINTER_TO_INT (data);
}
Пример #16
0
static GVariant *
serialize_pspec(GvsSerializer *self, GParamSpec *pspec, const GValue *value)
{
    GvsPropertySerializeFunc func = NULL;
    GVariant *variant = NULL;
    GType type = pspec->value_type;

    /* Try to find the right serialization function */
    func = g_param_spec_get_qdata(pspec, gvs_property_serialize_func_quark());

    if (func == NULL)
    {
        if (G_TYPE_IS_FUNDAMENTAL(type))
        {
            func = serialize_fundamental;
        }
        else if (G_TYPE_IS_ENUM(type))
        {
            func = serialize_enum;
        }
        else if (G_TYPE_IS_FLAGS(type))
        {
            func = serialize_flags;
        }
        else if (G_TYPE_IS_OBJECT(type) || G_TYPE_IS_INTERFACE (type))
        {
            func = serialize_object_property;
        }
        else if (g_type_is_a(type, G_TYPE_BOXED))
        {
            func = serialize_boxed_property;
        }
    }

    if (func)
    {
        variant = func(self, value, NULL);
    }
    else
    {
        g_warning("Could not serialize property %s of type %s\n"
                  "Use gvs_register_property_serialize_func() in your class_init function\n",
                  pspec->name, g_type_name(pspec->value_type));
    }

    return variant;
}
Пример #17
0
static void
gst_xvidenc_get_property (GObject * object,
    guint prop_id, GValue * value, GParamSpec * pspec)
{
  GstXvidEnc *xvidenc;
  guint offset;

  xvidenc = GST_XVIDENC (object);

  if (prop_id > xvidenc_prop_count) {
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    return;
  }

  /* our param specs should have such qdata */
  offset =
      GPOINTER_TO_UINT (g_param_spec_get_qdata (pspec, xvidenc_pspec_quark));

  if (offset == 0)
    return;

  switch (G_PARAM_SPEC_VALUE_TYPE (pspec)) {
    case G_TYPE_BOOLEAN:
      g_value_set_boolean (value, G_STRUCT_MEMBER (gboolean, xvidenc, offset));
      break;
    case G_TYPE_INT:
      g_value_set_int (value, G_STRUCT_MEMBER (gint, xvidenc, offset));
      break;
    case G_TYPE_STRING:
      g_value_take_string (value,
          g_strdup (G_STRUCT_MEMBER (gchar *, xvidenc, offset)));
      break;
    default:                   /* must be enum, given the check above */
      if (G_IS_PARAM_SPEC_ENUM (pspec)) {
        g_value_set_enum (value, G_STRUCT_MEMBER (gint, xvidenc, offset));
      } else if (G_IS_PARAM_SPEC_FLAGS (pspec)) {
        g_value_set_flags (value, G_STRUCT_MEMBER (guint, xvidenc, offset));
      } else {                  /* oops, bit lazy we don't cover this case yet */
        g_critical ("%s does not yet support type %s", GST_FUNCTION,
            g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
      }
      break;
  }
}
Пример #18
0
static gboolean
is_mapped (GParamSpec *pspec)
{
   gboolean ret;

   ret = (pspec->owner_type != GOM_TYPE_RESOURCE);
   if (!ret)
     return FALSE;

   ret = (sql_type_for_column(pspec) != NULL);
   if (!ret) {
     g_debug("Property %s not mapped because type is unsupported (%s)",
             pspec->name, g_type_name(pspec->value_type));
     return FALSE;
   }

   ret = !GPOINTER_TO_INT(g_param_spec_get_qdata(pspec, GOM_RESOURCE_NOT_MAPPED));

   return ret;
}
static void
terminal_profile_notify (GObject *object,
                         GParamSpec *pspec)
{
	TerminalProfilePrivate *priv = TERMINAL_PROFILE (object)->priv;
	void (* notify) (GObject *, GParamSpec *) = G_OBJECT_CLASS (terminal_profile_parent_class)->notify;

	_terminal_debug_print (TERMINAL_DEBUG_PROFILE,
	                       "Property notification for prop %s\n",
	                       pspec->name);

	if (notify)
		notify (object, pspec);

	if (pspec->owner_type == TERMINAL_TYPE_PROFILE &&
	        (pspec->flags & G_PARAM_WRITABLE) &&
	        g_param_spec_get_qdata (pspec, gsettings_key_quark) != NULL &&
	        pspec != priv->gsettings_notification_pspec)
		terminal_profile_schedule_save (TERMINAL_PROFILE (object), pspec);
}
Пример #20
0
static void
gst_xvidenc_set_property (GObject * object,
    guint prop_id, const GValue * value, GParamSpec * pspec)
{
  GstXvidEnc *xvidenc;
  guint offset;

  xvidenc = GST_XVIDENC (object);

  if (prop_id > xvidenc_prop_count) {
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    return;
  }

  /* our param specs should have such qdata */
  offset =
      GPOINTER_TO_UINT (g_param_spec_get_qdata (pspec, xvidenc_pspec_quark));

  if (offset == 0)
    return;

  switch (G_PARAM_SPEC_VALUE_TYPE (pspec)) {
    case G_TYPE_BOOLEAN:
      G_STRUCT_MEMBER (gboolean, xvidenc, offset) = g_value_get_boolean (value);
      break;
    case G_TYPE_INT:
      G_STRUCT_MEMBER (gint, xvidenc, offset) = g_value_get_int (value);
      break;
    case G_TYPE_STRING:
      g_free (G_STRUCT_MEMBER (gchar *, xvidenc, offset));
      G_STRUCT_MEMBER (gchar *, xvidenc, offset) = g_value_dup_string (value);
      break;
    default:                   /* must be enum, given the check above */
      if (G_IS_PARAM_SPEC_ENUM (pspec)) {
        G_STRUCT_MEMBER (gint, xvidenc, offset) = g_value_get_enum (value);
      } else {
        G_STRUCT_MEMBER (guint, xvidenc, offset) = g_value_get_flags (value);
      }
      break;
  }
}
Пример #21
0
// FIXME: use rb_protect
static void
set_prop_func(GObject* object,
              guint property_id,
              const GValue* value,
              GParamSpec* pspec)
{
    ID ruby_setter = (ID)g_param_spec_get_qdata(pspec, q_ruby_setter);
    if (!ruby_setter) {
        gchar* name = g_strconcat(g_param_spec_get_name(pspec), "=", NULL);
        gchar* p;
        for (p = name; *p; p++) {
          if (*p == '-')
            *p = '_';
        }
        ruby_setter = rb_intern(name);
        g_param_spec_set_qdata(pspec, q_ruby_setter, (gpointer)ruby_setter);
        g_free(name);
    }

    rb_funcall(GOBJ2RVAL(object), ruby_setter, 1, GVAL2RVAL(value));
}
Пример #22
0
static const char *
sql_type_for_column (GParamSpec *pspec)
{
   GType parent_type;

   switch (pspec->value_type) {
   case G_TYPE_CHAR:
   case G_TYPE_INT:
   case G_TYPE_INT64:
   case G_TYPE_LONG:
   case G_TYPE_UCHAR:
   case G_TYPE_UINT:
   case G_TYPE_UINT64:
   case G_TYPE_ULONG:
   case G_TYPE_BOOLEAN:
      return "INTEGER";
   case G_TYPE_STRING:
      return "TEXT";
   case G_TYPE_FLOAT:
   case G_TYPE_DOUBLE:
      return "FLOAT";
   default:
      if (pspec->value_type == G_TYPE_STRV ||
          pspec->value_type == G_TYPE_DATE_TIME)
        return "BLOB";
      parent_type = g_type_parent(pspec->value_type);
      if (parent_type == G_TYPE_ENUM ||
          parent_type == G_TYPE_FLAGS)
        return "INTEGER";
      if (g_param_spec_get_qdata(pspec, GOM_RESOURCE_FROM_BYTES_FUNC) != NULL)
        return "BLOB";

      g_warning("Ignoring column %s of invalid type %s\n",
                pspec->name, g_type_name(pspec->value_type));
      return NULL;
   }
}
Пример #23
0
// FIXME: use rb_protect
static void
get_prop_func(GObject* object,
              guint property_id,
              GValue* value,
              GParamSpec* pspec)
{
    ID ruby_getter = (ID)g_param_spec_get_qdata(pspec, q_ruby_getter);
    if (!ruby_getter) {
        gchar* name = g_strdup(g_param_spec_get_name(pspec));
        gchar* p;
        for (p = name; *p; p++) {
          if (*p == '-')
            *p = '_';
        }
        ruby_getter = rb_intern(name);
        g_param_spec_set_qdata(pspec, q_ruby_getter, (gpointer)ruby_getter);
        g_free(name);
    }

    {
        VALUE ret = rb_funcall(GOBJ2RVAL(object), ruby_getter, 0);
        rbgobj_rvalue_to_gvalue(ret, value);
    }
}
static void
terminal_profile_gsettings_changeset_add (TerminalProfile *profile,
        GSettings *changeset,
        GParamSpec *pspec)
{
	TerminalProfilePrivate *priv = profile->priv;
	char *key;
	const GValue *value;

	/* FIXME: do this? */
#if 0
	if (priv->locked[pspec->param_id])
		return;

	if (!g_settings_is_writable (priv->settings, gsettings_key, NULL))
		return;
#endif

	key = g_param_spec_get_qdata (pspec, gsettings_key_quark);
	if (!key)
		return;

	value = g_value_array_get_nth (priv->properties, pspec->param_id);

	_terminal_debug_print (TERMINAL_DEBUG_PROFILE,
	                       "Adding pspec %s with value %s to the GSettings changeset\n",
	                       pspec->name, g_strdup_value_contents (value));

	if (G_IS_PARAM_SPEC_BOOLEAN (pspec))
		g_settings_set_boolean (changeset, key, g_value_get_boolean (value));
	else if (G_IS_PARAM_SPEC_STRING (pspec))
	{
		const char *str;

		str = g_value_get_string (value);
		g_settings_set_string (changeset, key, str ? str : "");
	}
	else if (G_IS_PARAM_SPEC_ENUM (pspec))
	{
		const GEnumValue *eval;

		eval = g_enum_get_value (G_PARAM_SPEC_ENUM (pspec)->enum_class, g_value_get_enum (value));

		g_settings_set_enum (changeset, key, eval->value);
	}
	else if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_COLOR)
	{
		GdkColor *color;
		char str[16];

		color = g_value_get_boxed (value);
		if (!color)
			goto cleanup;

		g_snprintf (str, sizeof (str),
		            "#%04X%04X%04X",
		            color->red,
		            color->green,
		            color->blue);

		g_settings_set_string (changeset, key, str);
	}
	else if (G_PARAM_SPEC_VALUE_TYPE (pspec) == PANGO_TYPE_FONT_DESCRIPTION)
	{
		PangoFontDescription *font_desc;
		char *font;

		font_desc = g_value_get_boxed (value);
		if (!font_desc)
			goto cleanup;

		font = pango_font_description_to_string (font_desc);
		g_settings_set_string (changeset, key, font);
		g_free (font);
	}
	else if (G_IS_PARAM_SPEC_DOUBLE (pspec))
		g_settings_set_double (changeset, key, g_value_get_double (value));
	else if (G_IS_PARAM_SPEC_INT (pspec))
		g_settings_set_int (changeset, key, g_value_get_int (value));
	else if (G_IS_PARAM_SPEC_VALUE_ARRAY (pspec) &&
	         G_PARAM_SPEC_VALUE_TYPE (G_PARAM_SPEC_VALUE_ARRAY (pspec)->element_spec) == GDK_TYPE_COLOR)
	{
		GValueArray *array;
		GString *string;
		guint n_colors, i;

		/* We need to do this ourselves, because the gtk_color_selection_palette_to_string
		 * does not carry all the bytes, and xterm's palette is messed up...
		 */

		array = g_value_get_boxed (value);
		if (!array)
			goto cleanup;

		n_colors = array->n_values;
		string = g_string_sized_new (n_colors * (1 /* # */ + 3 * 4) + n_colors /* : separators and terminating \0 */);
		for (i = 0; i < n_colors; ++i)
		{
			GdkColor *color;

			if (i > 0)
				g_string_append_c (string, ':');

			color = g_value_get_boxed (g_value_array_get_nth (array, i));
			if (!color)
				continue;

			g_string_append_printf (string,
			                        "#%04X%04X%04X",
			                        color->red,
			                        color->green,
			                        color->blue);
		}

		g_settings_set_string (changeset, key, string->str);
		g_string_free (string, TRUE);
	}
	else
		g_printerr ("Unhandled value type %s of pspec %s\n", g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)), pspec->name);

cleanup:
	return;
}
Пример #25
0
/* Invalidate style to recompute styles */
static void _xfdashboard_actor_stylable_invalidate(XfdashboardStylable *inStylable)
{
	XfdashboardActor			*self;
	XfdashboardActorPrivate		*priv;
	XfdashboardActorClass		*klass;
	XfdashboardTheme			*theme;
	XfdashboardThemeCSS			*themeCSS;
	GHashTable					*possibleStyleSet;
	GParamSpec					*paramSpec;
	GHashTableIter				hashIter;
	GHashTable					*themeStyleSet;
	gchar						*styleName;
	XfdashboardThemeCSSValue	*styleValue;
	gboolean					didChange;
#ifdef DEBUG
	gboolean					doDebug=FALSE;
#endif

	g_return_if_fail(XFDASHBOARD_IS_ACTOR(inStylable));

	self=XFDASHBOARD_ACTOR(inStylable);
	priv=self->priv;
	klass=XFDASHBOARD_ACTOR_GET_CLASS(self);
	didChange=FALSE;

	/* Only recompute style for mapped actors or if revalidation was forced */
	if(!priv->forceStyleRevalidation && !clutter_actor_is_mapped(CLUTTER_ACTOR(self))) return;

	/* Get theme CSS */
	theme=xfdashboard_application_get_theme(NULL);
	themeCSS=xfdashboard_theme_get_css(theme);

	/* First get list of all stylable properties of this and parent classes.
	 * It is used to determine if key in theme style sets are valid.
	 */
	possibleStyleSet=xfdashboard_actor_get_stylable_properties_full(klass);

#ifdef DEBUG
	if(doDebug)
	{
		gint					i=0;
		gchar					*defaultsKey;
		GValue					defaultsVal=G_VALUE_INIT;
		gchar					*defaultsValStr;
		GParamSpec				*realParamSpec;

		XFDASHBOARD_DEBUG(self, STYLE,
							"Got param specs for %p (%s) with class '%s' and pseudo-class '%s'",
							self,
							G_OBJECT_TYPE_NAME(self),
							priv->styleClasses,
							priv->stylePseudoClasses);

		g_hash_table_iter_init(&hashIter, possibleStyleSet);
		while(g_hash_table_iter_next(&hashIter, (gpointer*)&defaultsKey, (gpointer*)&paramSpec))
		{
			realParamSpec=(GParamSpec*)g_param_spec_get_qdata(paramSpec, XFDASHBOARD_ACTOR_PARAM_SPEC_REF);

			g_value_init(&defaultsVal, G_PARAM_SPEC_VALUE_TYPE(realParamSpec));
			g_param_value_set_default(realParamSpec, &defaultsVal);

			defaultsValStr=g_strdup_value_contents(&defaultsVal);
			XFDASHBOARD_DEBUG(self, STYLE,
								"%d: param spec [%s] %s=%s\n",
								++i,
								G_OBJECT_CLASS_NAME(klass),
								defaultsKey,
								defaultsValStr);
			g_free(defaultsValStr);

			g_value_unset(&defaultsVal);
		}

		XFDASHBOARD_DEBUG(self, STYLE, "End of param specs");
	}
#endif

	/* Get style information from theme */
	themeStyleSet=xfdashboard_theme_css_get_properties(themeCSS, XFDASHBOARD_STYLABLE(self));

#ifdef DEBUG
	if(doDebug)
	{
		gint					i=0;

		XFDASHBOARD_DEBUG(self, STYLE,
							"Got styles from theme for %p (%s) with class '%s' and pseudo-class '%s'",
							self,
							G_OBJECT_TYPE_NAME(self),
							priv->styleClasses,
							priv->stylePseudoClasses);

		g_hash_table_iter_init(&hashIter, themeStyleSet);
		while(g_hash_table_iter_next(&hashIter, (gpointer*)&styleName, (gpointer*)&styleValue))
		{
			XFDASHBOARD_DEBUG(self, STYLE,
								"%d: [%s] %s=%s\n",
								++i,
								styleValue->source,
								(gchar*)styleName,
								styleValue->string);
		}

		XFDASHBOARD_DEBUG(self, STYLE, "End of styles from theme");
	}
#endif

	/* The 'property-changed' notification will be freezed and thawed
	 * (fired at once) after all stylable properties of this instance are set.
	 */
	g_object_freeze_notify(G_OBJECT(self));

	/* Iterate through style information retrieved from theme and
	 * set the corresponding property in object instance if key
	 * is valid.
	 */
	g_hash_table_iter_init(&hashIter, themeStyleSet);
	while(g_hash_table_iter_next(&hashIter, (gpointer*)&styleName, (gpointer*)&styleValue))
	{
		GValue					cssValue=G_VALUE_INIT;
		GValue					propertyValue=G_VALUE_INIT;
		GParamSpec				*realParamSpec;

		/* Check if key is a valid object property name */
		if(!g_hash_table_lookup_extended(possibleStyleSet, styleName, NULL, (gpointer*)&paramSpec)) continue;

		/* Get original referenced parameter specification. It does not need
		 * to be referenced while converting because it is valid as this
		 * value is stored in hashtable.
		 */
		realParamSpec=(GParamSpec*)g_param_spec_get_qdata(paramSpec, XFDASHBOARD_ACTOR_PARAM_SPEC_REF);

		/* Convert style value to type of object property and set value
		 * if conversion was successful. Otherwise do nothing.
		 */
		g_value_init(&cssValue, G_TYPE_STRING);
		g_value_set_string(&cssValue, styleValue->string);

		g_value_init(&propertyValue, G_PARAM_SPEC_VALUE_TYPE(realParamSpec));

		if(g_param_value_convert(realParamSpec, &cssValue, &propertyValue, FALSE))
		{
			g_object_set_property(G_OBJECT(self), styleName, &propertyValue);
			didChange=TRUE;
#ifdef DEBUG
			if(doDebug)
			{
				gchar					*valstr;

				valstr=g_strdup_value_contents(&propertyValue);
				XFDASHBOARD_DEBUG(self, STYLE,
									"Setting theme value of style property [%s] %s=%s\n",
									G_OBJECT_CLASS_NAME(klass),
									styleName,
									valstr);
				g_free(valstr);
			}
#endif
		}
			else
			{
				g_warning(_("Could not transform CSS string value for property '%s' to type %s of class %s"),
							styleName, g_type_name(G_PARAM_SPEC_VALUE_TYPE(realParamSpec)), G_OBJECT_CLASS_NAME(klass));
			}

		/* Release allocated resources */
		g_value_unset(&propertyValue);
		g_value_unset(&cssValue);
	}

	/* Now remove all duplicate keys in set of properties changed we set the last
	 * time. The remaining keys determine the properties which were set the last
	 * time but not this time and should be restored to their default values.
	 */
	if(priv->lastThemeStyleSet)
	{
		/* Remove duplicate keys from set of last changed properties */
		g_hash_table_foreach_remove(priv->lastThemeStyleSet, (GHRFunc)_xfdashboard_actor_hashtable_is_duplicate_key, themeStyleSet);

		/* Iterate through remaining key and restore corresponding object properties
		 * to their default values.
		 */
		g_hash_table_iter_init(&hashIter, priv->lastThemeStyleSet);
		while(g_hash_table_iter_next(&hashIter, (gpointer*)&styleName, (gpointer*)&paramSpec))
		{
			GValue				propertyValue=G_VALUE_INIT;
			GParamSpec			*realParamSpec;

			/* Check if key is a valid object property name */
			if(!g_hash_table_lookup_extended(possibleStyleSet, styleName, NULL, (gpointer*)&paramSpec)) continue;

			/* Get original referenced parameter specification. It does not need
			 * to be referenced while converting because it is valid as this
			 * value is stored in hashtable.
			 */
			realParamSpec=(GParamSpec*)g_param_spec_get_qdata(paramSpec, XFDASHBOARD_ACTOR_PARAM_SPEC_REF);

			/* Initialize property value to its type and default value */
			g_value_init(&propertyValue, G_PARAM_SPEC_VALUE_TYPE(realParamSpec));
			g_param_value_set_default(realParamSpec, &propertyValue);

			/* Set value at object property */
			g_object_set_property(G_OBJECT(self), styleName, &propertyValue);
			didChange=TRUE;
#ifdef DEBUG
			if(doDebug)
			{
				gchar					*valstr;

				valstr=g_strdup_value_contents(&propertyValue);
				XFDASHBOARD_DEBUG(self, STYLE,
									"Restoring default value of style property [%s] %s=%s\n",
									G_OBJECT_CLASS_NAME(klass),
									styleName,
									valstr);
				g_free(valstr);
			}
#endif

			/* Release allocated resources */
			g_value_unset(&propertyValue);
		}

		/* Release resources of set of last changed properties as we do not need
		 * it anymore.
		 */
		g_hash_table_destroy(priv->lastThemeStyleSet);
		priv->lastThemeStyleSet=NULL;
	}

	/* Remember this set of changed properties for next time to determine properties
	 * which need to be restored to their default value.
	 */
	priv->lastThemeStyleSet=themeStyleSet;

	/* Release allocated resources */
	g_hash_table_destroy(possibleStyleSet);

	/* Force a redraw if any change was made at this actor */
	if(didChange) clutter_actor_queue_redraw(CLUTTER_ACTOR(self));

	/* Reset force style revalidation flag because it's done now */
	priv->forceStyleRevalidation=FALSE;

	/* All stylable properties are set now. So thaw 'property-changed'
	 * notification now and fire all notifications at once.
	 */
	g_object_thaw_notify(G_OBJECT(self));
}
Пример #26
0
GtkWidget *
gimp_prop_table_new (GObject              *config,
                     GType                 owner_type,
                     GimpContext          *context,
                     GimpCreatePickerFunc  create_picker_func,
                     gpointer              picker_creator)
{
  GtkWidget     *table;
  GtkSizeGroup  *size_group;
  GParamSpec   **param_specs;
  guint          n_param_specs;
  gint           i;
  gint           row = 0;
  GParamSpec    *last_pspec = NULL;
  GtkAdjustment *last_x_adj = NULL;
  gint           last_x_row = 0;

  g_return_val_if_fail (G_IS_OBJECT (config), NULL);
  g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL);

  param_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (config),
                                                &n_param_specs);

  size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);

  table = gtk_table_new (3, 1, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);

  for (i = 0; i < n_param_specs; i++)
    {
      GParamSpec  *pspec  = param_specs[i];
      GtkWidget   *widget = NULL;
      const gchar *label  = NULL;

      /*  ignore properties of parent classes of owner_type  */
      if (! g_type_is_a (pspec->owner_type, owner_type))
        continue;

      if (G_IS_PARAM_SPEC_STRING (pspec))
        {
          static GQuark multiline_quark = 0;

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

          if (GIMP_IS_PARAM_SPEC_CONFIG_PATH (pspec))
            {
              widget = gimp_prop_file_chooser_button_new (config,
                                                          pspec->name,
                                                          g_param_spec_get_nick (pspec),
                                                          GTK_FILE_CHOOSER_ACTION_OPEN);
            }
          else if (g_param_spec_get_qdata (pspec, multiline_quark))
            {
              GtkTextBuffer *buffer;
              GtkWidget     *view;

              buffer = gimp_prop_text_buffer_new (config, pspec->name, -1);
              view = gtk_text_view_new_with_buffer (buffer);

              widget = gtk_scrolled_window_new (NULL, NULL);
              gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (widget),
                                                   GTK_SHADOW_IN);
              gtk_container_add (GTK_CONTAINER (widget), view);
              gtk_widget_show (view);
            }
          else
            {
              widget = gimp_prop_entry_new (config, pspec->name, -1);
            }

          label  = g_param_spec_get_nick (pspec);
        }
      else if (G_IS_PARAM_SPEC_BOOLEAN (pspec))
        {
          widget = gimp_prop_check_button_new (config, pspec->name,
                                               g_param_spec_get_nick (pspec));
        }
      else if (G_IS_PARAM_SPEC_ENUM (pspec))
        {
          widget = gimp_prop_enum_combo_box_new (config, pspec->name, 0, 0);
          gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (widget),
                                        g_param_spec_get_nick (pspec));
        }
      else if (GEGL_IS_PARAM_SPEC_SEED (pspec))
        {
          GtkAdjustment *adj;
          GtkWidget     *scale;
          GtkWidget     *button;

          widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);

          scale = gimp_prop_spin_scale_new (config, pspec->name,
                                            g_param_spec_get_nick (pspec),
                                            1.0, 10.0, 0);
          gtk_box_pack_start (GTK_BOX (widget), scale, TRUE, TRUE, 0);
          gtk_widget_show (scale);

          button = gtk_button_new_with_label (_("New Seed"));
          gtk_box_pack_start (GTK_BOX (widget), button, FALSE, FALSE, 0);
          gtk_widget_show (button);

          adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (scale));

          g_signal_connect (button, "clicked",
                            G_CALLBACK (gimp_prop_table_new_seed_clicked),
                            adj);
        }
      else if (G_IS_PARAM_SPEC_INT (pspec)   ||
               G_IS_PARAM_SPEC_UINT (pspec)  ||
               G_IS_PARAM_SPEC_FLOAT (pspec) ||
               G_IS_PARAM_SPEC_DOUBLE (pspec))
        {
          GtkAdjustment *adj;
          gdouble        value;
          gdouble        lower;
          gdouble        upper;
          gdouble        step   = 1.0;
          gdouble        page   = 10.0;
          gint           digits = (G_IS_PARAM_SPEC_FLOAT (pspec) ||
                                   G_IS_PARAM_SPEC_DOUBLE (pspec)) ? 2 : 0;

          if (GEGL_IS_PARAM_SPEC_DOUBLE (pspec))
            {
              GeglParamSpecDouble *gspec = GEGL_PARAM_SPEC_DOUBLE (pspec);

              lower = gspec->ui_minimum;
              upper = gspec->ui_maximum;
            }
          else if (GEGL_IS_PARAM_SPEC_INT (pspec))
            {
              GeglParamSpecInt *gspec = GEGL_PARAM_SPEC_INT (pspec);

              lower = gspec->ui_minimum;
              upper = gspec->ui_maximum;
            }
          else
            {
              _gimp_prop_widgets_get_numeric_values (config, pspec,
                                                     &value, &lower, &upper,
                                                     G_STRFUNC);
            }

          if ((upper - lower < 10.0) &&
              (G_IS_PARAM_SPEC_FLOAT (pspec) ||
               G_IS_PARAM_SPEC_DOUBLE (pspec)))
            {
              step   = 0.1;
              page   = 1.0;
              digits = 3;
            }

          widget = gimp_prop_spin_scale_new (config, pspec->name,
                                             g_param_spec_get_nick (pspec),
                                             step, page, digits);

          adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));

          if (g_str_has_suffix (pspec->name, "x") ||
              g_str_has_suffix (pspec->name, "width"))
            {
              last_pspec = pspec;
              last_x_adj = adj;
              last_x_row = row;
            }
          else if ((g_str_has_suffix (pspec->name, "y") ||
                    g_str_has_suffix (pspec->name, "height")) &&
                   last_pspec != NULL &&
                   last_x_adj != NULL &&
                   last_x_row == row - 1)
            {
              GtkWidget *chain = gimp_chain_button_new (GIMP_CHAIN_RIGHT);

              gtk_table_attach (GTK_TABLE (table), chain,
                                3, 4, last_x_row, row + 1,
                                GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL,
                                0, 0);
              gtk_widget_show (chain);

              if (gtk_adjustment_get_value (last_x_adj) ==
                  gtk_adjustment_get_value (adj))
                {
                  GBinding *binding;

                  gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain), TRUE);

                  binding = g_object_bind_property (last_x_adj, "value",
                                                    adj,        "value",
                                                    G_BINDING_BIDIRECTIONAL);

                  g_object_set_data (G_OBJECT (chain), "binding", binding);
                }

              g_signal_connect (chain, "toggled",
                                G_CALLBACK (gimp_prop_table_chain_toggled),
                                last_x_adj);

              g_object_set_data (G_OBJECT (last_x_adj), "y-adjustment", adj);

              if (create_picker_func)
                {
                  GtkWidget *button;
                  gchar     *pspec_name;

                  pspec_name = g_strconcat (last_pspec->name, ":",
                                            pspec->name, NULL);

                  button = create_picker_func (picker_creator,
                                               pspec_name,
                                               GIMP_STOCK_CURSOR,
                                               _("Pick coordinates from the image"));
                  gtk_table_attach (GTK_TABLE (table), button,
                                    4, 5, last_x_row, row + 1,
                                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL,
                                    0, 0);
                  gtk_widget_show (button);

                  g_object_weak_ref (G_OBJECT (button),
                                     (GWeakNotify) g_free, pspec_name);
                }
            }
        }
      else if (GIMP_IS_PARAM_SPEC_RGB (pspec))
        {
          GtkWidget *button;

          widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);

          button = gimp_prop_color_button_new (config, pspec->name,
                                               g_param_spec_get_nick (pspec),
                                               128, 24,
                                               GIMP_COLOR_AREA_SMALL_CHECKS);
          gimp_color_button_set_update (GIMP_COLOR_BUTTON (button), TRUE);
          gimp_color_panel_set_context (GIMP_COLOR_PANEL (button), context);
          gtk_box_pack_start (GTK_BOX (widget), button, TRUE, TRUE, 0);
          gtk_widget_show (button);

          if (create_picker_func)
            {
              button = create_picker_func (picker_creator,
                                           pspec->name,
                                           GIMP_STOCK_COLOR_PICKER_GRAY,
                                           _("Pick color from the image"));
              gtk_box_pack_start (GTK_BOX (widget), button, FALSE, FALSE, 0);
              gtk_widget_show (button);
            }

          label = g_param_spec_get_nick (pspec);
        }
      else
        {
          g_warning ("%s: not supported: %s (%s)\n", G_STRFUNC,
                     g_type_name (G_TYPE_FROM_INSTANCE (pspec)), pspec->name);
        }

      if (widget)
        {
          if (label)
            {
              gimp_table_attach_aligned (GTK_TABLE (table), 0, row,
                                         label, 0.0, 0.5,
                                         widget, 2, FALSE);
            }
          else
            {
              gtk_table_attach_defaults (GTK_TABLE (table), widget,
                                         0, 3, row, row + 1);
              gtk_widget_show (widget);
            }

          row++;
        }
    }

  g_object_unref (size_group);

  g_free (param_specs);

  return table;
}
Пример #27
0
GtkWidget *
gimp_prop_widget_new_from_pspec (GObject               *config,
                                 GParamSpec            *pspec,
                                 GimpContext           *context,
                                 GimpCreatePickerFunc   create_picker_func,
                                 gpointer               picker_creator,
                                 const gchar          **label)
{
  GtkWidget *widget = NULL;

  g_return_val_if_fail (G_IS_OBJECT (config), NULL);
  g_return_val_if_fail (pspec != NULL, NULL);
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
  g_return_val_if_fail (label != NULL, NULL);

  *label = NULL;

  if (GEGL_IS_PARAM_SPEC_SEED (pspec))
    {
      GtkAdjustment *adj;
      GtkWidget     *spin;
      GtkWidget     *button;

      widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);

      spin = gimp_prop_spin_button_new (config, pspec->name,
                                        1.0, 10.0, 0);
      gtk_box_pack_start (GTK_BOX (widget), spin, TRUE, TRUE, 0);
      gtk_widget_show (spin);

      button = gtk_button_new_with_label (_("New Seed"));
      gtk_box_pack_start (GTK_BOX (widget), button, FALSE, FALSE, 0);
      gtk_widget_show (button);

      adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));

      g_signal_connect (button, "clicked",
                        G_CALLBACK (gimp_prop_widget_new_seed_clicked),
                        adj);

      *label = g_param_spec_get_nick (pspec);
    }
  else if (G_IS_PARAM_SPEC_INT (pspec)   ||
           G_IS_PARAM_SPEC_UINT (pspec)  ||
           G_IS_PARAM_SPEC_FLOAT (pspec) ||
           G_IS_PARAM_SPEC_DOUBLE (pspec))
    {
      gdouble lower;
      gdouble upper;
      gdouble step;
      gdouble page;
      gint    digits;

      if (GEGL_IS_PARAM_SPEC_DOUBLE (pspec))
        {
          GeglParamSpecDouble *gspec = GEGL_PARAM_SPEC_DOUBLE (pspec);

          lower  = gspec->ui_minimum;
          upper  = gspec->ui_maximum;
          step   = gspec->ui_step_small;
          page   = gspec->ui_step_big;
          digits = gspec->ui_digits;
        }
      else if (GEGL_IS_PARAM_SPEC_INT (pspec))
        {
          GeglParamSpecInt *gspec = GEGL_PARAM_SPEC_INT (pspec);

          lower  = gspec->ui_minimum;
          upper  = gspec->ui_maximum;
          step   = gspec->ui_step_small;
          page   = gspec->ui_step_big;
          digits = 0;
        }
      else
        {
          gdouble value;

          _gimp_prop_widgets_get_numeric_values (config, pspec,
                                                 &value, &lower, &upper,
                                                 G_STRFUNC);

          if ((upper - lower <= 1.0) &&
              (G_IS_PARAM_SPEC_FLOAT (pspec) ||
               G_IS_PARAM_SPEC_DOUBLE (pspec)))
            {
              step   = 0.01;
              page   = 0.1;
              digits = 4;
            }
          else if ((upper - lower <= 10.0) &&
                   (G_IS_PARAM_SPEC_FLOAT (pspec) ||
                    G_IS_PARAM_SPEC_DOUBLE (pspec)))
            {
              step   = 0.1;
              page   = 1.0;
              digits = 3;
            }
          else
            {
              step   = 1.0;
              page   = 10.0;
              digits = (G_IS_PARAM_SPEC_FLOAT (pspec) ||
                        G_IS_PARAM_SPEC_DOUBLE (pspec)) ? 2 : 0;
            }
        }

      widget = gimp_prop_spin_scale_new (config, pspec->name, NULL,
                                         step, page, digits);

      if (HAS_KEY (pspec, "unit", "degree") &&
          (upper - lower) == 360.0)
        {
          GtkWidget *hbox;
          GtkWidget *dial;

          gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (widget), TRUE);

          hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);

          gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
          gtk_widget_show (widget);

          dial = gimp_prop_angle_dial_new (config, pspec->name);
          gtk_box_pack_start (GTK_BOX (hbox), dial, FALSE, FALSE, 0);
          gtk_widget_show (dial);

          widget = hbox;
        }
      else if (HAS_KEY (pspec, "unit", "kelvin"))
        {
          GtkWidget *hbox;
          GtkWidget *button;

          hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);

          gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
          gtk_widget_show (widget);

          button = gimp_prop_kelvin_presets_new (config, pspec->name);
          gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
          gtk_widget_show (button);

          widget = hbox;
        }
    }
  else if (G_IS_PARAM_SPEC_STRING (pspec))
    {
      static GQuark multiline_quark = 0;

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

      if (GIMP_IS_PARAM_SPEC_CONFIG_PATH (pspec))
        {
          widget =
            gimp_prop_file_chooser_button_new (config, pspec->name,
                                               g_param_spec_get_nick (pspec),
                                               GTK_FILE_CHOOSER_ACTION_OPEN);
        }
      else if (g_param_spec_get_qdata (pspec, multiline_quark))
        {
          GtkTextBuffer *buffer;
          GtkWidget     *view;

          buffer = gimp_prop_text_buffer_new (config, pspec->name, -1);
          view = gtk_text_view_new_with_buffer (buffer);
          g_object_unref (buffer);

          widget = gtk_scrolled_window_new (NULL, NULL);
          gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (widget),
                                               GTK_SHADOW_IN);
          gtk_container_add (GTK_CONTAINER (widget), view);
          gtk_widget_show (view);
        }
      else
        {
          widget = gimp_prop_entry_new (config, pspec->name, -1);
        }

      *label = g_param_spec_get_nick (pspec);
    }
  else if (G_IS_PARAM_SPEC_BOOLEAN (pspec))
    {
      widget = gimp_prop_check_button_new (config, pspec->name,
                                           g_param_spec_get_nick (pspec));
    }
  else if (G_IS_PARAM_SPEC_ENUM (pspec))
    {
      widget = gimp_prop_enum_combo_box_new (config, pspec->name, 0, 0);
      gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (widget),
                                    g_param_spec_get_nick (pspec));
    }
  else if (GIMP_IS_PARAM_SPEC_RGB (pspec))
    {
      GtkWidget *button;

      widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);

      button = gimp_prop_color_button_new (config, pspec->name,
                                           g_param_spec_get_nick (pspec),
                                           128, 24,
                                           GIMP_COLOR_AREA_SMALL_CHECKS);
      gimp_color_button_set_update (GIMP_COLOR_BUTTON (button), TRUE);
      gimp_color_panel_set_context (GIMP_COLOR_PANEL (button), context);
      gtk_box_pack_start (GTK_BOX (widget), button, TRUE, TRUE, 0);
      gtk_widget_show (button);

      if (create_picker_func)
        {
          button = create_picker_func (picker_creator,
                                       pspec->name,
                                       GIMP_STOCK_COLOR_PICKER_GRAY,
                                       _("Pick color from the image"));
          gtk_box_pack_start (GTK_BOX (widget), button, FALSE, FALSE, 0);
          gtk_widget_show (button);
        }

      *label = g_param_spec_get_nick (pspec);
    }
  else
    {
      g_warning ("%s: not supported: %s (%s)\n", G_STRFUNC,
                 g_type_name (G_TYPE_FROM_INSTANCE (pspec)), pspec->name);
    }

  return widget;
}
Пример #28
0
static gboolean
is_child_property (GParamSpec *pspec)
{
  return g_param_spec_get_qdata (pspec, g_quark_from_string ("is-child-prop")) != NULL;
}
Пример #29
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;
}
static GObject *
terminal_profile_constructor (GType type,
                              guint n_construct_properties,
                              GObjectConstructParam *construct_params)
{
	GObject *object;
	TerminalProfile *profile;
	TerminalProfilePrivate *priv;
	const char *name;
	GParamSpec **pspecs;
	guint n_pspecs, i;

	object = G_OBJECT_CLASS (terminal_profile_parent_class)->constructor
	         (type, n_construct_properties, construct_params);

	profile = TERMINAL_PROFILE (object);
	priv = profile->priv;

	name = g_value_get_string (g_value_array_get_nth (priv->properties, PROP_NAME));
	g_assert (name != NULL);

	priv->settings = g_settings_new_with_path (CONF_PROFILE_SCHEMA,
		g_strconcat (CONF_PROFILE_PREFIX, name, "/", NULL));
	g_assert (priv->settings != NULL);
	g_signal_connect (priv->settings,
			  g_strconcat("changed::", priv->profile_dir, "/", NULL),
			  G_CALLBACK(terminal_profile_gsettings_notify_cb),
			  profile);

	/* Now load those properties from GSettings that were not set as construction params */
	pspecs = g_object_class_list_properties (G_OBJECT_CLASS (TERMINAL_PROFILE_GET_CLASS (profile)), &n_pspecs);
	for (i = 0; i < n_pspecs; ++i)
	{
		GParamSpec *pspec = pspecs[i];
		guint j;
		gboolean is_construct = FALSE;
		char *key;

		if (pspec->owner_type != TERMINAL_TYPE_PROFILE)
			continue;

		if ((pspec->flags & G_PARAM_WRITABLE) == 0 ||
		        (pspec->flags & G_PARAM_CONSTRUCT_ONLY) != 0)
			continue;

		for (j = 0; j < n_construct_properties; ++j)
			if (pspec == construct_params[j].pspec)
			{
				is_construct = TRUE;
				break;
			}

		if (is_construct)
			continue;

		key = g_param_spec_get_qdata (pspec, gsettings_key_quark);
		if (!key)
			continue;

		terminal_profile_gsettings_notify_cb (priv->settings, key,  profile);
	}

	g_free (pspecs);

	return object;
}