static void
g_application_command_line_set_property (GObject      *object,
        guint         prop_id,
        const GValue *value,
        GParamSpec   *pspec)
{
    GApplicationCommandLine *cmdline = G_APPLICATION_COMMAND_LINE (object);

    switch (prop_id)
    {
    case PROP_ARGUMENTS:
        g_assert (cmdline->priv->arguments == NULL);
        cmdline->priv->arguments = g_value_dup_variant (value);
        break;

    case PROP_PLATFORM_DATA:
        g_assert (cmdline->priv->platform_data == NULL);
        cmdline->priv->platform_data = g_value_dup_variant (value);
        if (cmdline->priv->platform_data != NULL)
            grok_platform_data (cmdline);
        break;

    default:
        g_assert_not_reached ();
    }
}
Esempio n. 2
0
static void
setting_set_property (GObject *object,
                      guint prop_id,
                      const GValue *value,
                      GParamSpec *pspec)
{
  Setting *setting = SETTING (object);

  switch (prop_id)
    {
    case PROP_DAEMON:
      g_assert (setting->daemon == NULL);
      setting->daemon = g_value_get_object (value);
      break;

    case PROP_CONFIGURATION:
      g_assert (setting->configuration == NULL);
      setting->configuration = g_value_dup_variant (value);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}
Esempio n. 3
0
static void
gb_color_picker_prefs_palette_row_set_property (GObject      *object,
                                                guint         prop_id,
                                                const GValue *value,
                                                GParamSpec   *pspec)
{
  GbColorPickerPrefsPaletteRow *self = GB_COLOR_PICKER_PREFS_PALETTE_ROW (object);

  switch (prop_id)
    {
    case PROP_KEY:
      self->key = g_value_dup_string (value);
      break;

    case PROP_NEEDS_ATTENTION:
      gb_color_picker_prefs_palette_row_set_needs_attention (self, g_value_get_boolean (value));
      break;

    case PROP_IS_EDITING:
      gb_color_picker_prefs_palette_row_set_edit (self, g_value_get_boolean (value));
      break;

    case PROP_TARGET:
      self->target = g_value_dup_variant (value);
      break;

    case PROP_PALETTE_NAME:
      gb_color_picker_prefs_palette_row_set_palette_name (self, g_value_get_string (value));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}
static void
tp_tls_certificate_rejection_set_property (GObject *object,
    guint property_id,
    const GValue *value,
    GParamSpec *pspec)
{
  TpTLSCertificateRejection *self = TP_TLS_CERTIFICATE_REJECTION (object);

  switch (property_id)
    {
      case PROP_REASON:
        self->priv->reason = g_value_get_uint (value);
        break;
      case PROP_DBUS_ERROR:
        g_assert (self->priv->dbus_error == NULL); /* construct only */
        self->priv->dbus_error = g_value_dup_string (value);
        break;
      case PROP_DETAILS:
        self->priv->details = g_value_dup_variant (value);
        break;
      case PROP_ERROR:
        self->priv->error = g_value_dup_boxed (value);
        break;
      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
        break;
    }
}
Esempio n. 5
0
static GVariant*
_settings_map_set_variant (const GValue       *value,
                           const GVariantType *expected_type,
                           gpointer            user_data)
{
	g_return_val_if_fail (g_variant_is_of_type (g_value_get_variant (value), expected_type), NULL);

	return g_value_dup_variant (value);
}
static void
g_simple_action_set_property (GObject      *object,
                              guint         prop_id,
                              const GValue *value,
                              GParamSpec   *pspec)
{
  GSimpleAction *simple = G_SIMPLE_ACTION (object);

  switch (prop_id)
    {
    case PROP_NAME:
      g_assert (simple->priv->name == NULL);
      simple->priv->name = g_value_dup_string (value);
      break;

    case PROP_PARAMETER_TYPE:
      g_assert (simple->priv->parameter_type == NULL);
      simple->priv->parameter_type = g_value_dup_boxed (value);
      break;

    case PROP_ENABLED:
      g_simple_action_set_enabled (simple, g_value_get_boolean (value));
      break;

    case PROP_STATE:
      /* PROP_STATE is marked as G_PARAM_CONSTRUCT so we always get a
       * call during object construction, even if it is NULL.  We treat
       * that first call differently, for a number of reasons.
       *
       * First, we don't want the value to be rejected by the
       * possibly-overridden .set_state() function.  Second, we don't
       * want to be tripped by the assertions in g_simple_action_set_state()
       * that would enforce the catch22 that we only provide a value of
       * the same type as the existing value (when there is not yet an
       * existing value).
       */
      if (simple->priv->state_set)
        g_simple_action_set_state (G_ACTION (simple),
                                   g_value_get_variant (value));

      else /* this is the special case */
        {
          /* only do it the first time. */
          simple->priv->state_set = TRUE;

          /* blindly set it. */
          simple->priv->state = g_value_dup_variant (value);
        }
      break;

    default:
      g_assert_not_reached ();
    }
}
Esempio n. 7
0
void scp_tree_data_from_value(ScpTreeData *data, GValue *value, gboolean copy)
{
	switch (scp_tree_data_get_fundamental_type(G_VALUE_TYPE(value)))
	{
		case G_TYPE_INT     : data->v_int = g_value_get_int(value); break;
		case G_TYPE_UINT    : data->v_uint = g_value_get_uint(value); break;
		case G_TYPE_STRING  :
		{
			data->v_string = copy ? g_value_dup_string(value) :
				(char *) g_value_get_string(value);
			break;
		}
		case G_TYPE_BOOLEAN : data->v_int = g_value_get_boolean(value); break;
		case G_TYPE_LONG    : data->v_long = g_value_get_long(value); break;
		case G_TYPE_ULONG   : data->v_ulong = g_value_get_ulong(value); break;
		case G_TYPE_FLOAT   : data->v_float = g_value_get_float(value); break;
		case G_TYPE_DOUBLE  : data->v_double = g_value_get_double(value); break;
	#if GLIB_CHECK_VERSION(2, 32, 0)
		case G_TYPE_CHAR    : data->v_char = g_value_get_schar(value); break;
	#else
		case G_TYPE_CHAR    : data->v_char = g_value_get_char(value); break;
	#endif
		case G_TYPE_UCHAR   : data->v_uchar = g_value_get_uchar(value); break;
		case G_TYPE_INT64   : data->v_int64 = g_value_get_int64(value); break;
		case G_TYPE_UINT64  : data->v_uint64 = g_value_get_uint64(value); break;
		case G_TYPE_ENUM    : data->v_int = g_value_get_enum(value); break;
		case G_TYPE_FLAGS   : data->v_uint = g_value_get_flags(value); break;
		case G_TYPE_POINTER : data->v_pointer = g_value_get_pointer(value); break;
		case G_TYPE_OBJECT  :
		{
			data->v_pointer = copy ? g_value_dup_object(value) :
				g_value_get_object(value);
			break;
		}
		case G_TYPE_BOXED :
		{
			data->v_pointer = copy ? g_value_dup_boxed(value) :
				g_value_get_boxed(value);
			break;
		}
	#if GLIB_CHECK_VERSION(2, 26, 0)
		case G_TYPE_VARIANT :
		{
			data->v_pointer = copy ? g_value_dup_variant(value) :
				g_value_get_variant(value);
			break;
		}
	#endif
		default : scp_tree_data_warn_unsupported_type(G_STRFUNC, G_VALUE_TYPE(value));
	}
}
Esempio n. 8
0
/*
 *
 * Fundemental type transformations
 *
 */
static GVariant *
serialize_fundamental(GvsSerializer *self, const GValue *value, gpointer unused)
{
    GVariant *variant;

    switch (G_VALUE_TYPE(value))
    {
        case G_TYPE_BOOLEAN:
            variant = g_variant_new_boolean(g_value_get_boolean(value));
            break;
        case G_TYPE_CHAR:
            variant = g_variant_new_byte(g_value_get_schar(value));
            break;
        case G_TYPE_DOUBLE:
            variant = g_variant_new_double(g_value_get_double(value));
            break;
        case G_TYPE_FLOAT:
            variant = g_variant_new_double(g_value_get_float(value));
            break;
        case G_TYPE_INT:
            variant = g_variant_new_int32(g_value_get_int(value));
            break;
        case G_TYPE_INT64:
        case G_TYPE_LONG:
            variant = g_variant_new_int64(g_value_get_int64(value));
            break;
        case G_TYPE_STRING:
            variant = g_variant_new("ms", g_value_get_string(value));
            break;
        case G_TYPE_UCHAR:
            variant = g_variant_new_byte(g_value_get_uchar(value));
            break;
        case G_TYPE_UINT:
            variant = g_variant_new_uint32(g_value_get_uint(value));
            break;
        case G_TYPE_UINT64:
        case G_TYPE_ULONG:
            variant = g_variant_new_uint64(g_value_get_uint64(value));
            break;
        case G_TYPE_VARIANT:
            variant = g_value_dup_variant(value);
            break;
        default:
            g_assert_not_reached();
            break;
      }

    return variant;
}
static void
replay_edge_create_event_set_property(GObject      *object,
                                   guint         property_id,
                                   const GValue *value,
                                   GParamSpec   *pspec)
{
  ReplayEdgeCreateEvent *self;

  g_return_if_fail(REPLAY_IS_EDGE_CREATE_EVENT(object));

  self = REPLAY_EDGE_CREATE_EVENT(object);

  switch (property_id) {
    case PROP_ID:
      self->priv->id = g_value_dup_string(value);
      break;

    case PROP_DIRECTED:
      self->priv->directed = g_value_get_boolean(value);
      break;

    case PROP_TAIL:
      self->priv->tail = g_value_dup_string(value);
      break;

    case PROP_HEAD:
      self->priv->head = g_value_dup_string(value);
      break;

    case PROP_PROPS:
      self->priv->props = g_value_dup_variant(value);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
  }
}
Esempio n. 10
0
static void
ol_lyric_source_candidate_set_property (GObject *object,
                                        guint property_id,
                                        const GValue *value,
                                        GParamSpec *pspec)
{
  OlLyricSourceCandidatePrivate *priv;
  priv = OL_LYRIC_SOURCE_CANDIDATE_GET_PRIVATE (object);
  switch (property_id)
  {
  case CANDIDATE_PROP_TITLE:
    g_free (priv->title);
    priv->title = g_value_dup_string (value);
    break;
  case CANDIDATE_PROP_ARTIST:
    g_free (priv->artist);
    priv->artist = g_value_dup_string (value);
    break;
  case CANDIDATE_PROP_ALBUM:
    g_free (priv->album);
    priv->album = g_value_dup_string (value);
    break;
  case CANDIDATE_PROP_COMMENT:
    g_free (priv->comment);
    priv->comment = g_value_dup_string (value);
    break;
  case CANDIDATE_PROP_SOURCEID:
    g_free (priv->sourceid);
    priv->sourceid = g_value_dup_string (value);
    break;
  case CANDIDATE_PROP_DOWNLOADINFO:
    if (priv->downloadinfo != NULL)
      g_variant_unref (priv->downloadinfo);
    priv->downloadinfo = g_value_dup_variant (value);
    break;
  }
}
Esempio n. 11
0
void
_gtk_tree_data_list_value_to_node (GtkTreeDataList *list,
				   GValue          *value)
{
  switch (get_fundamental_type (G_VALUE_TYPE (value)))
    {
    case G_TYPE_BOOLEAN:
      list->data.v_int = g_value_get_boolean (value);
      break;
    case G_TYPE_CHAR:
      list->data.v_char = g_value_get_schar (value);
      break;
    case G_TYPE_UCHAR:
      list->data.v_uchar = g_value_get_uchar (value);
      break;
    case G_TYPE_INT:
      list->data.v_int = g_value_get_int (value);
      break;
    case G_TYPE_UINT:
      list->data.v_uint = g_value_get_uint (value);
      break;
    case G_TYPE_LONG:
      list->data.v_long = g_value_get_long (value);
      break;
    case G_TYPE_ULONG:
      list->data.v_ulong = g_value_get_ulong (value);
      break;
    case G_TYPE_INT64:
      list->data.v_int64 = g_value_get_int64 (value);
      break;
    case G_TYPE_UINT64:
      list->data.v_uint64 = g_value_get_uint64 (value);
      break;
    case G_TYPE_ENUM:
      list->data.v_int = g_value_get_enum (value);
      break;
    case G_TYPE_FLAGS:
      list->data.v_uint = g_value_get_flags (value);
      break;
    case G_TYPE_POINTER:
      list->data.v_pointer = g_value_get_pointer (value);
      break;
    case G_TYPE_FLOAT:
      list->data.v_float = g_value_get_float (value);
      break;
    case G_TYPE_DOUBLE:
      list->data.v_double = g_value_get_double (value);
      break;
    case G_TYPE_STRING:
      g_free (list->data.v_pointer);
      list->data.v_pointer = g_value_dup_string (value);
      break;
    case G_TYPE_OBJECT:
      if (list->data.v_pointer)
	g_object_unref (list->data.v_pointer);
      list->data.v_pointer = g_value_dup_object (value);
      break;
    case G_TYPE_BOXED:
      if (list->data.v_pointer)
	g_boxed_free (G_VALUE_TYPE (value), list->data.v_pointer);
      list->data.v_pointer = g_value_dup_boxed (value);
      break;
    case G_TYPE_VARIANT:
      if (list->data.v_pointer)
	g_variant_unref (list->data.v_pointer);
      list->data.v_pointer = g_value_dup_variant (value);
      break;
    default:
      g_warning ("%s: Unsupported type (%s) stored.", G_STRLOC, g_type_name (G_VALUE_TYPE (value)));
      break;
    }
}
Esempio n. 12
0
/**
 * g_dbus_gvalue_to_gvariant:
 * @gvalue: A #GValue to convert to a #GVariant
 * @type: A #GVariantType
 *
 * Converts a #GValue to a #GVariant of the type indicated by the @type
 * parameter.
 *
 * The conversion is using the following rules:
 *
 * - #G_TYPE_STRING: 's', 'o', 'g' or 'ay'
 * - #G_TYPE_STRV: 'as', 'ao' or 'aay'
 * - #G_TYPE_BOOLEAN: 'b'
 * - #G_TYPE_UCHAR: 'y'
 * - #G_TYPE_INT: 'i', 'n'
 * - #G_TYPE_UINT: 'u', 'q'
 * - #G_TYPE_INT64 'x'
 * - #G_TYPE_UINT64: 't'
 * - #G_TYPE_DOUBLE: 'd'
 * - #G_TYPE_VARIANT: Any #GVariantType
 *
 * This can fail if e.g. @gvalue is of type #G_TYPE_STRING and @type
 * is ['i'][G-VARIANT-TYPE-INT32:CAPS]. It will also fail for any #GType
 * (including e.g. #G_TYPE_OBJECT and #G_TYPE_BOXED derived-types) not
 * in the table above.
 *
 * Note that if @gvalue is of type #G_TYPE_VARIANT and its value is
 * %NULL, the empty #GVariant instance (never %NULL) for @type is
 * returned (e.g. 0 for scalar types, the empty string for string types,
 * '/' for object path types, the empty array for any array type and so on).
 *
 * See the g_dbus_gvariant_to_gvalue() function for how to convert a
 * #GVariant to a #GValue.
 *
 * Returns: A #GVariant (never floating) of #GVariantType @type holding
 *     the data from @gvalue or %NULL in case of failure. Free with
 *     g_variant_unref().
 *
 * Since: 2.30
 */
GVariant *
g_dbus_gvalue_to_gvariant (const GValue       *gvalue,
                           const GVariantType *type)
{
  GVariant *ret;
  const gchar *s;
  const gchar * const *as;
  const gchar *empty_strv[1] = {NULL};

  g_return_val_if_fail (gvalue != NULL, NULL);
  g_return_val_if_fail (type != NULL, NULL);

  ret = NULL;

  /* @type can easily be e.g. "s" with the GValue holding a GVariant - for example this
   * can happen when using the org.gtk.GDBus.C.ForceGVariant annotation with the
   * gdbus-codegen(1) tool.
   */
  if (G_VALUE_TYPE (gvalue) == G_TYPE_VARIANT)
    {
      ret = g_value_dup_variant (gvalue);
    }
  else
    {
      switch (g_variant_type_peek_string (type)[0])
        {
        case G_VARIANT_CLASS_BOOLEAN:
          ret = g_variant_ref_sink (g_variant_new_boolean (g_value_get_boolean (gvalue)));
          break;

        case G_VARIANT_CLASS_BYTE:
          ret = g_variant_ref_sink (g_variant_new_byte (g_value_get_uchar (gvalue)));
          break;

        case G_VARIANT_CLASS_INT16:
          ret = g_variant_ref_sink (g_variant_new_int16 (g_value_get_int (gvalue)));
          break;

        case G_VARIANT_CLASS_UINT16:
          ret = g_variant_ref_sink (g_variant_new_uint16 (g_value_get_uint (gvalue)));
          break;

        case G_VARIANT_CLASS_INT32:
          ret = g_variant_ref_sink (g_variant_new_int32 (g_value_get_int (gvalue)));
          break;

        case G_VARIANT_CLASS_UINT32:
          ret = g_variant_ref_sink (g_variant_new_uint32 (g_value_get_uint (gvalue)));
          break;

        case G_VARIANT_CLASS_INT64:
          ret = g_variant_ref_sink (g_variant_new_int64 (g_value_get_int64 (gvalue)));
          break;

        case G_VARIANT_CLASS_UINT64:
          ret = g_variant_ref_sink (g_variant_new_uint64 (g_value_get_uint64 (gvalue)));
          break;

        case G_VARIANT_CLASS_DOUBLE:
          ret = g_variant_ref_sink (g_variant_new_double (g_value_get_double (gvalue)));
          break;

        case G_VARIANT_CLASS_STRING:
          s = g_value_get_string (gvalue);
          if (s == NULL)
            s = "";
          ret = g_variant_ref_sink (g_variant_new_string (s));
          break;

        case G_VARIANT_CLASS_OBJECT_PATH:
          s = g_value_get_string (gvalue);
          if (s == NULL)
            s = "/";
          ret = g_variant_ref_sink (g_variant_new_object_path (s));
          break;

        case G_VARIANT_CLASS_SIGNATURE:
          s = g_value_get_string (gvalue);
          if (s == NULL)
            s = "";
          ret = g_variant_ref_sink (g_variant_new_signature (s));
          break;

        case G_VARIANT_CLASS_ARRAY:
          switch (g_variant_type_peek_string (type)[1])
            {
            case G_VARIANT_CLASS_BYTE:
              s = g_value_get_string (gvalue);
              if (s == NULL)
                s = "";
              ret = g_variant_ref_sink (g_variant_new_bytestring (s));
              break;

            case G_VARIANT_CLASS_STRING:
              as = g_value_get_boxed (gvalue);
              if (as == NULL)
                as = empty_strv;
              ret = g_variant_ref_sink (g_variant_new_strv (as, -1));
              break;

            case G_VARIANT_CLASS_OBJECT_PATH:
              as = g_value_get_boxed (gvalue);
              if (as == NULL)
                as = empty_strv;
              ret = g_variant_ref_sink (g_variant_new_objv (as, -1));
              break;

            case G_VARIANT_CLASS_ARRAY:
              switch (g_variant_type_peek_string (type)[2])
                {
                case G_VARIANT_CLASS_BYTE:
                  as = g_value_get_boxed (gvalue);
                  if (as == NULL)
                    as = empty_strv;
                  ret = g_variant_ref_sink (g_variant_new_bytestring_array (as, -1));
                  break;

                default:
                  ret = g_value_dup_variant (gvalue);
                  break;
                }
              break;

            default:
              ret = g_value_dup_variant (gvalue);
              break;
            }
          break;

        case G_VARIANT_CLASS_HANDLE:
        case G_VARIANT_CLASS_VARIANT:
        case G_VARIANT_CLASS_MAYBE:
        case G_VARIANT_CLASS_TUPLE:
        case G_VARIANT_CLASS_DICT_ENTRY:
          ret = g_value_dup_variant (gvalue);
          break;
        }
    }

  /* Could be that the GValue is holding a NULL GVariant - in that case,
   * we return an "empty" GVariant instead of a NULL GVariant
   */
  if (ret == NULL)
    {
      GVariant *untrusted_empty;
      untrusted_empty = g_variant_new_from_data (type, NULL, 0, FALSE, NULL, NULL);
      ret = g_variant_ref_sink (g_variant_get_normal_form (untrusted_empty));
      g_variant_unref (untrusted_empty);
    }

  g_assert (!g_variant_is_floating (ret));

  return ret;
}