示例#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;
}
示例#2
0
文件: gvaluetypes.c 项目: zsx/glib
/**
 * g_value_get_uchar:
 * @value: a valid #GValue of type %G_TYPE_UCHAR
 *
 * Get the contents of a %G_TYPE_UCHAR #GValue.
 *
 * Returns: unsigned character contents of @value
 */
guchar
g_value_get_uchar (const GValue *value)
{
  g_return_val_if_fail (G_VALUE_HOLDS_UCHAR (value), 0);
  
  return value->data[0].v_uint;
}
示例#3
0
int
ce_get_property_default (NMSetting *setting, const char *property_name)
{
	GParamSpec *spec;
	GValue value = { 0, };

	g_return_val_if_fail (NM_IS_SETTING (setting), -1);

	spec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), property_name);
	g_return_val_if_fail (spec != NULL, -1);

	g_value_init (&value, spec->value_type);
	g_param_value_set_default (spec, &value);

	if (G_VALUE_HOLDS_CHAR (&value))
		return (int) g_value_get_schar (&value);
	else if (G_VALUE_HOLDS_INT (&value))
		return g_value_get_int (&value);
	else if (G_VALUE_HOLDS_INT64 (&value))
		return (int) g_value_get_int64 (&value);
	else if (G_VALUE_HOLDS_LONG (&value))
		return (int) g_value_get_long (&value);
	else if (G_VALUE_HOLDS_UINT (&value))
		return (int) g_value_get_uint (&value);
	else if (G_VALUE_HOLDS_UINT64 (&value))
		return (int) g_value_get_uint64 (&value);
	else if (G_VALUE_HOLDS_ULONG (&value))
		return (int) g_value_get_ulong (&value);
	else if (G_VALUE_HOLDS_UCHAR (&value))
		return (int) g_value_get_uchar (&value);
	g_return_val_if_fail (FALSE, 0);
	return 0;
}
示例#4
0
文件: gvaluetypes.c 项目: zsx/glib
/**
 * g_value_set_uchar:
 * @value: a valid #GValue of type %G_TYPE_UCHAR
 * @v_uchar: unsigned character value to be set
 *
 * Set the contents of a %G_TYPE_UCHAR #GValue to @v_uchar.
 */
void
g_value_set_uchar (GValue *value,
		   guchar  v_uchar)
{
  g_return_if_fail (G_VALUE_HOLDS_UCHAR (value));
  
  value->data[0].v_uint = v_uchar;
}
void set_notification_hints(GtkWindow* nw, GHashTable* hints)
{
	WindowData* windata = g_object_get_data(G_OBJECT(nw), "windata");

	g_assert(windata != NULL);

	GValue* value = (GValue*) g_hash_table_lookup(hints, "urgency");

	if (value != NULL && G_VALUE_HOLDS_UCHAR(value))
	{
		windata->urgency = g_value_get_uchar(value);

		if (windata->urgency == URGENCY_CRITICAL)
		{
			gtk_window_set_title(GTK_WINDOW(nw), "Critical Notification");
		}
		else
		{
			gtk_window_set_title(GTK_WINDOW(nw), "Notification");
		}
	}
}
// les proprietes d'un AccessPoint sont :
// Flags - u - (read)  (NM_802_11_AP_FLAGS)
//     Flags describing the capabilities of the access point.
// WpaFlags - u - (read) (NM_802_11_AP_SEC)
//     Flags describing the access point's capabilities according to WPA (Wifi Protected Access).
// RsnFlags - u - (read) (NM_802_11_AP_SEC)
//     Flags describing the access point's capabilities according to the RSN (Robust Secure Network) protocol.
// Ssid - ay - (read)
//     The Service Set Identifier identifying the access point.
// Frequency - u - (read)
//     The radio channel frequency in use by the access point, in MHz.
// HwAddress - s - (read)
//     The hardware address (BSSID) of the access point.
// Mode - u - (read) (NM_802_11_MODE)
//     Describes the operating mode of the access point.
// MaxBitrate - u - (read)
//     The maximum bitrate this access point is capable of, in kilobits/second (Kb/s).
// Strength - y - (read)
//     The current signal quality of the access point, in percent.
void cd_NetworkMonitor_fetch_access_point_properties (GHashTable *hProperties)
{
	GValue *v;
	v = (GValue *)g_hash_table_lookup (hProperties, "Strength");
	if (v != NULL && G_VALUE_HOLDS_UCHAR (v))
	{
		myData.iPercent = MIN (100, (gint) g_value_get_uchar (v));  // pas clair si c'est deja des % ou s'il faut convertir par 100/255, des fois on se chope des 255 ...
		cd_debug ("Network-Monitor : Force du signal : %d %%", myData.iPercent);
		cd_NetworkMonitor_quality ();
		cd_NetworkMonitor_draw_icon ();
	}
	
	v = (GValue *)g_hash_table_lookup (hProperties, "HwAddress");
	if (v != NULL && G_VALUE_HOLDS_STRING (v))
	{
		myData.cAccessPointHwAdress = g_strdup(g_value_get_string (v));
		cd_debug ("Network-Monitor : Adresse physique de l'AP active : %s", myData.cAccessPointHwAdress);
	}
	
	v = (GValue *)g_hash_table_lookup (hProperties, "Ssid");
	if (v != NULL && G_VALUE_HOLDS_BOXED (v))
	{
		GByteArray *a = g_value_get_boxed (v);
		myData.cESSID = g_new0 (gchar, a->len+1);
		for (uint i = 0; i < a->len; i ++)
		{
			myData.cESSID[i] = a->data[i];
		}
		cd_debug ("Network-Monitor : SSID : %s", myData.cESSID);
	}

	v = (GValue *)g_hash_table_lookup (hProperties, "MaxBitrate");  // in kilobits/second (Kb/s).
	if (v != NULL && G_VALUE_HOLDS_UINT (v))
	{
		myData.iSpeed = (gint) g_value_get_uint (v) / 8;  // Ko/s
		cd_debug("Network-Monitor : Max Bitrate au demarrage : %d",myData.iSpeed);
	}
}
示例#7
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;
}
示例#8
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;
}