Beispiel #1
0
static gpointer
value_as_pointer (GValue *value)
{
  if (g_value_fits_pointer (value))
    return g_value_peek_pointer (value);
  if (G_VALUE_HOLDS_BOOLEAN (value))
    return (void*) g_value_get_boolean (value);
  if (G_VALUE_HOLDS_CHAR (value))
    return (void*) (gssize) g_value_get_char (value);
  if (G_VALUE_HOLDS_UCHAR (value))
    return (void*) (gsize) g_value_get_uchar (value);
  if (G_VALUE_HOLDS_INT (value))
    return (void*) g_value_get_int (value);
  if (G_VALUE_HOLDS_UINT (value))
    return (void*) g_value_get_uint (value);
  if (G_VALUE_HOLDS_LONG (value))
    return (void*) g_value_get_long (value);
  if (G_VALUE_HOLDS_ULONG (value))
    return (void*) g_value_get_ulong (value);
  if (G_VALUE_HOLDS_FLOAT (value))
    return (void*) (gssize) g_value_get_float (value);
  if (G_VALUE_HOLDS_DOUBLE (value))
    return (void*) (gssize) g_value_get_double (value);
  if (G_VALUE_HOLDS_ENUM (value))
    return (void*) (gssize) g_value_get_enum (value);
  if (G_VALUE_HOLDS_FLAGS (value))
    return (void*) (gsize) g_value_get_flags (value);
  return (void*) 0x1373babe;
}
Beispiel #2
0
static void
value_text_edited (GtkCellRendererText * cell,
                   const gchar * path,
                   const gchar * new_text, GladeEditorProperty * eprop)
{
  GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop);
  GtkTreeIter iter;
  gint colnum = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column-number"));
  gint row;
  GNode *data_tree = NULL;
  GladeModelData *data;
  GValue *value;
  GladeProperty *property = glade_editor_property_get_property (eprop);

  if (!gtk_tree_model_get_iter_from_string
      (GTK_TREE_MODEL (eprop_data->store), &iter, path))
    return;

  gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter,
                      COLUMN_ROW, &row, -1);

  glade_property_get (property, &data_tree);

  /* if we are editing, then there is data in the datatree */
  g_assert (data_tree);

  data_tree = glade_model_data_tree_copy (data_tree);

  data = glade_model_data_tree_get_data (data_tree, row, colnum);

  /* Untranslate string and update value in tree. */
  if (G_VALUE_HOLDS_ENUM (&data->value) || G_VALUE_HOLDS_FLAGS (&data->value))
    value = glade_utils_value_from_string (G_VALUE_TYPE (&data->value),
                                           glade_get_value_from_displayable
                                           (G_VALUE_TYPE (&data->value),
                                            new_text),
                                           glade_widget_get_project (glade_property_get_widget (property)));
  else
    value =
        glade_utils_value_from_string (G_VALUE_TYPE (&data->value), new_text,
                                       glade_widget_get_project (glade_property_get_widget (property)));


  g_value_copy (value, &data->value);
  g_value_unset (value);
  g_free (value);

  eprop_data->editing_row = row;
  eprop_data->editing_column = colnum;
  if (eprop_data->pending_data_tree)
    glade_model_data_tree_free (eprop_data->pending_data_tree);

  eprop_data->pending_data_tree = data_tree;
  g_idle_add ((GSourceFunc) update_and_focus_data_tree_idle, eprop);
}
Beispiel #3
0
static GObject *
g_local_file_monitor_constructor (GType                  type,
                                  guint                  n_construct_properties,
                                  GObjectConstructParam *construct_properties)
{
  GObject *obj;
  GLocalFileMonitorClass *klass;
  GObjectClass *parent_class;
  GLocalFileMonitor *local_monitor;
  const gchar *filename = NULL;
  GFileMonitorFlags flags = 0;
  gint i;
  
  klass = G_LOCAL_FILE_MONITOR_CLASS (g_type_class_peek (G_TYPE_LOCAL_FILE_MONITOR));
  parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
  obj = parent_class->constructor (type,
                                   n_construct_properties,
                                   construct_properties);

  local_monitor = G_LOCAL_FILE_MONITOR (obj);

  for (i = 0; i < n_construct_properties; i++)
    {
      if (strcmp ("filename", g_param_spec_get_name (construct_properties[i].pspec)) == 0)
        {
          g_warn_if_fail (G_VALUE_HOLDS_STRING (construct_properties[i].value));
          filename = g_value_get_string (construct_properties[i].value);
        }
      else if (strcmp ("flags", g_param_spec_get_name (construct_properties[i].pspec)) == 0)
        {
          g_warn_if_fail (G_VALUE_HOLDS_FLAGS (construct_properties[i].value));
          flags = g_value_get_flags (construct_properties[i].value);
        }
    }

  g_warn_if_fail (filename != NULL);

  local_monitor->filename = g_strdup (filename);
  local_monitor->flags = flags;
  return obj;
}
Beispiel #4
0
/* This function really ought not to be part of Amanda. In my (Ian's) opinion,
   serialization and deserialization should be a part of the GValue
   interface. But it's not, and here we are. */
gboolean g_value_set_from_string(GValue * val, char * string) {
    g_return_val_if_fail(val != NULL, FALSE);
    g_return_val_if_fail(G_IS_VALUE(val), FALSE);

    if (G_VALUE_HOLDS_BOOLEAN(val)) {
        return g_value_set_boolean_from_string(val, string);
    } else if (G_VALUE_HOLDS_INT(val)) {
        return g_value_set_int_from_string(val, string);
    } else if (G_VALUE_HOLDS_UINT(val)) {
        return g_value_set_uint_from_string(val, string);
    } else if (G_VALUE_HOLDS_UINT64(val)) {
        return g_value_set_uint64_from_string(val, string);
    } else if (G_VALUE_HOLDS_STRING(val)) {
        g_value_set_string(val, string);
        return TRUE;
    } else if (G_VALUE_HOLDS_FLAGS(val)) {
        return g_value_set_flags_from_string(val, string);
    }

    return TRUE;
}
Beispiel #5
0
/**
 * Implements
 *   org.gnome.glib.GValue.g_value_get_flags(long value)
 * called from
 *   org.gnome.glib.GValue.getFlags(Value value)
 * called from
 *   org.gnome.glib.Object.getPropertyFlags(String name)
 *
 * Extract the ordinal of an flag stored in a GValue of type G_TYPE_FLAGS.
 */
JNIEXPORT jint JNICALL
Java_org_gnome_glib_GValue_g_1value_1get_1flags
(
	JNIEnv* env,
	jclass cls,
	jlong _value
)
{
	GValue* value;
	guint num; 

	// translate value
	value =	(GValue*) _value;
	if (!G_VALUE_HOLDS_FLAGS(value)) {
		bindings_java_throw(env, "You've asked for the flags ordinal value of a GValue, but it's not a G_TYPE_FLAGS!");
		return 0;
	}

	// call function
	num = g_value_get_flags(value); 

	// and return	
	return (jint) num;
}
static GObject *
g_local_directory_monitor_constructor (GType                  type,
                                       guint                  n_construct_properties,
                                       GObjectConstructParam *construct_properties)
{
  GObject *obj;
  GLocalDirectoryMonitorClass *klass;
  GObjectClass *parent_class;
  GLocalDirectoryMonitor *local_monitor;
  GFileMonitorFlags  flags = 0;
  const gchar *dirname = NULL;
  gint i;
  
  klass = G_LOCAL_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_LOCAL_DIRECTORY_MONITOR));
  parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
  obj = parent_class->constructor (type,
                                   n_construct_properties,
                                   construct_properties);

  local_monitor = G_LOCAL_DIRECTORY_MONITOR (obj);

  for (i = 0; i < n_construct_properties; i++)
    {
      if (strcmp ("dirname", g_param_spec_get_name (construct_properties[i].pspec)) == 0)
        {
          g_warn_if_fail (G_VALUE_HOLDS_STRING (construct_properties[i].value));
          dirname = g_value_get_string (construct_properties[i].value);
        }
      if (strcmp ("flags", g_param_spec_get_name (construct_properties[i].pspec)) == 0)
        {
          g_warn_if_fail (G_VALUE_HOLDS_FLAGS (construct_properties[i].value));
          flags = g_value_get_flags (construct_properties[i].value);
        }
    }

  local_monitor->dirname = g_strdup (dirname);
  local_monitor->flags = flags;

  if (!klass->mount_notify &&
      (flags & G_FILE_MONITOR_WATCH_MOUNTS))
    {
#ifdef G_OS_WIN32
      /*claim everything was mounted */
      local_monitor->was_mounted = TRUE;
#else
      GUnixMountEntry *mount;
      
      /* Emulate unmount detection */
      
      mount = g_unix_mount_at (local_monitor->dirname, NULL);
      
      local_monitor->was_mounted = mount != NULL;
      
      if (mount)
        g_unix_mount_free (mount);

      local_monitor->mount_monitor = g_unix_mount_monitor_new ();
      g_signal_connect_object (local_monitor->mount_monitor, "mounts-changed",
			       G_CALLBACK (mounts_changed), local_monitor, 0);
#endif
    }

  return obj;
}
Beispiel #7
0
gboolean _flags_in_gvalue(GValue* v) {
    return G_VALUE_HOLDS_FLAGS(v);
}
Beispiel #8
0
gboolean
glibsharp_value_holds_flags (GValue *value)
{
	return G_VALUE_HOLDS_FLAGS (value);
}
Beispiel #9
0
/**
 * g_strdup_value_contents:
 * @value: #GValue which contents are to be described.
 *
 * Return a newly allocated string, which describes the contents of a
 * #GValue.  The main purpose of this function is to describe #GValue
 * contents for debugging output, the way in which the contents are
 * described may change between different GLib versions.
 *
 * Returns: Newly allocated string.
 */
gchar*
g_strdup_value_contents (const GValue *value)
{
  const gchar *src;
  gchar *contents;

  g_return_val_if_fail (G_IS_VALUE (value), NULL);
  
  if (G_VALUE_HOLDS_STRING (value))
    {
      src = g_value_get_string (value);
      
      if (!src)
	contents = g_strdup ("NULL");
      else
	{
	  gchar *s = g_strescape (src, NULL);

	  contents = g_strdup_printf ("\"%s\"", s);
	  g_free (s);
	}
    }
  else if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING))
    {
      GValue tmp_value = { 0, };
      gchar *s;

      g_value_init (&tmp_value, G_TYPE_STRING);
      g_value_transform (value, &tmp_value);
      s = g_strescape (g_value_get_string (&tmp_value), NULL);
      g_value_unset (&tmp_value);
      if (G_VALUE_HOLDS_ENUM (value) || G_VALUE_HOLDS_FLAGS (value))
	contents = g_strdup_printf ("((%s) %s)",
				    g_type_name (G_VALUE_TYPE (value)),
				    s);
      else
	contents = g_strdup (s ? s : "NULL");
      g_free (s);
    }
  else if (g_value_fits_pointer (value))
    {
      gpointer p = g_value_peek_pointer (value);

      if (!p)
	contents = g_strdup ("NULL");
      else if (G_VALUE_HOLDS_OBJECT (value))
	contents = g_strdup_printf ("((%s*) %p)", G_OBJECT_TYPE_NAME (p), p);
      else if (G_VALUE_HOLDS_PARAM (value))
	contents = g_strdup_printf ("((%s*) %p)", G_PARAM_SPEC_TYPE_NAME (p), p);
      else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
        {
          GStrv strv = g_value_get_boxed (value);
          GString *tmp = g_string_new ("[");

          while (*strv != NULL)
            {
              gchar *escaped = g_strescape (*strv, NULL);

              g_string_append_printf (tmp, "\"%s\"", escaped);
              g_free (escaped);

              if (*++strv != NULL)
                g_string_append (tmp, ", ");
            }

          g_string_append (tmp, "]");
          contents = g_string_free (tmp, FALSE);
        }
      else if (G_VALUE_HOLDS_BOXED (value))
	contents = g_strdup_printf ("((%s*) %p)", g_type_name (G_VALUE_TYPE (value)), p);
      else if (G_VALUE_HOLDS_POINTER (value))
	contents = g_strdup_printf ("((gpointer) %p)", p);
      else
	contents = g_strdup ("???");
    }
  else
    contents = g_strdup ("???");

  return contents;
}
Beispiel #10
0
gboolean
g_settings_get_mapping (GValue   *value,
                        GVariant *variant,
                        gpointer  user_data)
{
  if (g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN))
    {
      if (!G_VALUE_HOLDS_BOOLEAN (value))
        return FALSE;
      g_value_set_boolean (value, g_variant_get_boolean (variant));
      return TRUE;
    }

  else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_BYTE))
    {
      if (G_VALUE_HOLDS_UCHAR (value))
        g_value_set_uchar (value, g_variant_get_byte (variant));
      else if (G_VALUE_HOLDS_CHAR (value))
        g_value_set_char (value, (gchar) g_variant_get_byte (variant));
      else
        return FALSE;
      return TRUE;
    }

  else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_INT16)  ||
           g_variant_is_of_type (variant, G_VARIANT_TYPE_INT32)  ||
           g_variant_is_of_type (variant, G_VARIANT_TYPE_INT64))
    return g_settings_get_mapping_int (value, variant);

  else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_DOUBLE))
    return g_settings_get_mapping_float (value, variant);

  else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT16) ||
           g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT32) ||
           g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT64) ||
           g_variant_is_of_type (variant, G_VARIANT_TYPE_HANDLE))
    return g_settings_get_mapping_unsigned_int (value, variant);

  else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING)      ||
           g_variant_is_of_type (variant, G_VARIANT_TYPE_OBJECT_PATH) ||
           g_variant_is_of_type (variant, G_VARIANT_TYPE_SIGNATURE))
    {
      if (G_VALUE_HOLDS_STRING (value))
        {
          g_value_set_string (value, g_variant_get_string (variant, NULL));
          return TRUE;
        }

      else if (G_VALUE_HOLDS_ENUM (value))
        {
          GEnumClass *eclass;
          GEnumValue *evalue;
          const gchar *nick;

          /* GParamSpecEnum holds a ref on the class so we just peek... */
          eclass = g_type_class_peek (G_VALUE_TYPE (value));
          nick = g_variant_get_string (variant, NULL);
          evalue = g_enum_get_value_by_nick (eclass, nick);

          if (evalue)
            {
             g_value_set_enum (value, evalue->value);
             return TRUE;
            }

          g_warning ("Unable to lookup enum nick '%s' via GType\n", nick);
          return FALSE;
        }
    }
  else if (g_variant_is_of_type (variant, G_VARIANT_TYPE ("as")))
    {
      if (G_VALUE_HOLDS (value, G_TYPE_STRV))
        {
          g_value_take_boxed (value, g_variant_dup_strv (variant, NULL));
          return TRUE;
        }

      else if (G_VALUE_HOLDS_FLAGS (value))
        {
          GFlagsClass *fclass;
          GFlagsValue *fvalue;
          const gchar *nick;
          GVariantIter iter;
          guint flags = 0;

          fclass = g_type_class_peek (G_VALUE_TYPE (value));

          g_variant_iter_init (&iter, variant);
          while (g_variant_iter_next (&iter, "&s", &nick))
            {
              fvalue = g_flags_get_value_by_nick (fclass, nick);

              if (fvalue)
                flags |= fvalue->value;

              else
                {
                  g_warning ("Unable to lookup flags nick '%s' via GType\n",
                             nick);
                  return FALSE;
                }
            }

          g_value_set_flags (value, flags);
          return TRUE;
        }
    }
  else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_BYTESTRING))
    {
      g_value_set_string (value, g_variant_get_bytestring (variant));
      return TRUE;
    }

  g_critical ("No GSettings bind handler for type \"%s\".",
              g_variant_get_type_string (variant));

  return FALSE;
}
Beispiel #11
0
GVariant *
g_settings_set_mapping (const GValue       *value,
                        const GVariantType *expected_type,
                        gpointer            user_data)
{
  gchar *type_string;

  if (G_VALUE_HOLDS_BOOLEAN (value))
    {
      if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_BOOLEAN))
        return g_variant_new_boolean (g_value_get_boolean (value));
    }

  else if (G_VALUE_HOLDS_CHAR (value)  ||
           G_VALUE_HOLDS_UCHAR (value))
    {
      if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_BYTE))
        {
          if (G_VALUE_HOLDS_CHAR (value))
            return g_variant_new_byte (g_value_get_char (value));
          else
            return g_variant_new_byte (g_value_get_uchar (value));
        }
    }

  else if (G_VALUE_HOLDS_INT (value)   ||
           G_VALUE_HOLDS_INT64 (value))
    return g_settings_set_mapping_int (value, expected_type);

  else if (G_VALUE_HOLDS_DOUBLE (value))
    return g_settings_set_mapping_float (value, expected_type);

  else if (G_VALUE_HOLDS_UINT (value)  ||
           G_VALUE_HOLDS_UINT64 (value))
    return g_settings_set_mapping_unsigned_int (value, expected_type);

  else if (G_VALUE_HOLDS_STRING (value))
    {
      if (g_value_get_string (value) == NULL)
        return NULL;
      else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_STRING))
        return g_variant_new_string (g_value_get_string (value));
      else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_BYTESTRING))
        return g_variant_new_bytestring (g_value_get_string (value));
      else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_OBJECT_PATH))
        return g_variant_new_object_path (g_value_get_string (value));
      else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_SIGNATURE))
        return g_variant_new_signature (g_value_get_string (value));
    }

  else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
    {
      if (g_value_get_boxed (value) == NULL)
        return NULL;
      return g_variant_new_strv ((const gchar **) g_value_get_boxed (value),
                                 -1);
    }

  else if (G_VALUE_HOLDS_ENUM (value))
    {
      GEnumValue *enumval;
      GEnumClass *eclass;

      /* GParamSpecEnum holds a ref on the class so we just peek... */
      eclass = g_type_class_peek (G_VALUE_TYPE (value));
      enumval = g_enum_get_value (eclass, g_value_get_enum (value));

      if (enumval)
        return g_variant_new_string (enumval->value_nick);
      else
        return NULL;
    }

  else if (G_VALUE_HOLDS_FLAGS (value))
    {
      GVariantBuilder builder;
      GFlagsValue *flagsval;
      GFlagsClass *fclass;
      guint flags;

      fclass = g_type_class_peek (G_VALUE_TYPE (value));
      flags = g_value_get_flags (value);

      g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
      while (flags)
        {
          flagsval = g_flags_get_first_value (fclass, flags);

          if (flagsval == NULL)
            {
              g_variant_builder_clear (&builder);
              return NULL;
            }

          g_variant_builder_add (&builder, "s", flagsval->value_nick);
          flags &= ~flagsval->value;
        }

      return g_variant_builder_end (&builder);
    }

  type_string = g_variant_type_dup_string (expected_type);
  g_critical ("No GSettings bind handler for type \"%s\".", type_string);
  g_free (type_string);

  return NULL;
}