gconstpointer
terminal_profile_get_property_boxed (TerminalProfile *profile,
                                     const char *prop_name)
{
	const GValue *value;

	value = get_prop_value_from_prop_name (profile, prop_name);
	g_return_val_if_fail (value != NULL && G_VALUE_HOLDS_BOXED (value), NULL);
	if (!value || !G_VALUE_HOLDS_BOXED (value))
		return NULL;

	return g_value_get_boxed (value);
}
Пример #2
0
/* Attempts to get the backdrop colors from the xfdesktop pre-4.11 format */
static void
xfce_workspace_migrate_backdrop_color_style(XfceWorkspace *workspace,
                                            XfceBackdrop *backdrop,
                                            guint monitor)
{
    XfconfChannel *channel = workspace->priv->channel;
    char buf[1024];
    gint pp_len;
    GValue value = { 0, };

    TRACE("entering");

    /* Use the old property format */
    g_snprintf(buf, sizeof(buf), "%smonitor%d/",
               workspace->priv->property_prefix, monitor);
    pp_len = strlen(buf);

    /* Color style */
    buf[pp_len] = 0;
    g_strlcat(buf, "color-style", sizeof(buf));
    xfconf_channel_get_property(channel, buf, &value);

    if(G_VALUE_HOLDS_INT(&value)) {
        xfce_backdrop_set_color_style(backdrop, g_value_get_int(&value));
        g_value_unset(&value);
    }

    /* first color */
    buf[pp_len] = 0;
    g_strlcat(buf, "color1", sizeof(buf));
    xfconf_channel_get_property(channel, buf, &value);

    if(G_VALUE_HOLDS_BOXED(&value)) {
        xfce_backdrop_set_first_color(backdrop, g_value_get_boxed(&value));
        g_value_unset(&value);
    }

    /* second color */
    buf[pp_len] = 0;
    g_strlcat(buf, "color2", sizeof(buf));
    xfconf_channel_get_property(channel, buf, &value);

    if(G_VALUE_HOLDS_BOXED(&value)) {
        xfce_backdrop_set_second_color(backdrop, g_value_get_boxed(&value));
        g_value_unset(&value);
    }

    /* Fallback to solid if nothing was set anywhere */
    if(xfce_backdrop_get_color_style(backdrop) == XFCE_BACKDROP_COLOR_INVALID)
        xfce_backdrop_set_color_style(backdrop, XFCE_BACKDROP_COLOR_SOLID);
}
Пример #3
0
Файл: table.c Проект: gbl/vte
/* Print the contents of a GValueArray. */
static void
print_array(GValueArray *array)
{
	int i;
	GValue *value;
	if (array != NULL) {
		printf(" (");
		for (i = 0; i < array->n_values; i++) {
			value = g_value_array_get_nth(array, i);
			if (i > 0) {
				printf(", ");
			}
			if (G_VALUE_HOLDS_LONG(value)) {
				printf("%ld", g_value_get_long(value));
			} else
			if (G_VALUE_HOLDS_STRING(value)) {
				printf("\"%s\"", g_value_get_string(value));
			} else
			if (G_VALUE_HOLDS_POINTER(value)) {
				printf("\"%ls\"",
				       (wchar_t*) g_value_get_pointer(value));
			}
			if (G_VALUE_HOLDS_BOXED(value)) {
				print_array(g_value_get_boxed(value));
			}
		}
		printf(")");
		/* _vte_matcher_free_params_array(array); */
	}
}
Пример #4
0
/**
 * g_value_get_boxed:
 * @value: a valid #GValue of %G_TYPE_BOXED derived type
 *
 * Get the contents of a %G_TYPE_BOXED derived #GValue.
 *
 * Returns: boxed contents of @value
 */
gpointer
g_value_get_boxed (const GValue *value)
{
  g_return_val_if_fail (G_VALUE_HOLDS_BOXED (value), NULL);
  g_return_val_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)), NULL);

  return value->data[0].v_pointer;
}
Пример #5
0
/**
 * g_value_dup_boxed:
 * @value: a valid #GValue of %G_TYPE_BOXED derived type
 *
 * Get the contents of a %G_TYPE_BOXED derived #GValue.  Upon getting,
 * the boxed value is duplicated and needs to be later freed with
 * g_boxed_free(), e.g. like: g_boxed_free (G_VALUE_TYPE (@value),
 * return_value);
 *
 * Returns: boxed contents of @value
 */
gpointer
g_value_dup_boxed (const GValue *value)
{
  g_return_val_if_fail (G_VALUE_HOLDS_BOXED (value), NULL);
  g_return_val_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)), NULL);

  return value->data[0].v_pointer ? g_boxed_copy (G_VALUE_TYPE (value), value->data[0].v_pointer) : NULL;
}
static void on_properties_changed (DBusGProxy *player_proxy, const gchar *cInterface, GHashTable *pChangedProps, const gchar **cInvalidProps, gpointer data)
{
	g_return_if_fail (cInterface != NULL);
	cd_debug ("");
	GValue *v;
	if (strcmp (cInterface, "org.mpris.MediaPlayer2.Player") == 0)
	{
		v = g_hash_table_lookup (pChangedProps, "PlaybackStatus");
		if (v != NULL && G_VALUE_HOLDS_STRING (v))  // status has changed
		{
			const gchar *cStatus = g_value_get_string (v);  // "Playing", "Paused" or "Stopped"
			myData.iPlayingStatus = _extract_status (cStatus);
			cd_debug ("PlaybackStatus: Status: %s, %d", cStatus, myData.iPlayingStatus);
			
			if (myData.iPlayingStatus == PLAYER_PLAYING)  // le handler est stoppe lorsque le lecteur ne joue rien.
				cd_musicplayer_relaunch_handler ();
			
			cd_musicplayer_update_icon ();
		}
		
		v = g_hash_table_lookup (pChangedProps, "Metadata");
		if (v != NULL && G_VALUE_HOLDS_BOXED (v))
		{
			GHashTable *pMetadata = g_value_get_boxed (v);
			gboolean bTrackHasChanged = _extract_metadata (pMetadata);
			
			if (bTrackHasChanged)  // new song (song changed or started playing)
			{
				myData.iPlayingStatus = PLAYER_PLAYING;  // pour les lecteurs bugues comme Exaile qui envoit un statut "stop" au changement de musique sans envoyer de status "play" par la suite. On considere donc que si le lecteur joue une nouvelle musique, c'est qu'il est en "play".
				cd_musicplayer_update_icon ();
			}
		}
		
		v = g_hash_table_lookup (pChangedProps, "LoopStatus");
		if (v != NULL && G_VALUE_HOLDS_STRING (v))  // loop status has changed
		{
			const gchar *cStatus = g_value_get_string (v);  // "Playlist", "None"
			s_bIsLoop = (cStatus && strcmp (cStatus, "Playlist") == 0);
			cd_debug ("LoopStatus: %s, %d", cStatus, s_bIsLoop);
			s_bGotLoopStatus = TRUE;
		}
		
		v = g_hash_table_lookup (pChangedProps, "Shuffle");
		if (v != NULL && G_VALUE_HOLDS_BOOLEAN (v))  // Shuffle status has changed
		{
			s_bIsShuffle = g_value_get_boolean (v);
			cd_debug ("Shuffle: %d", s_bIsShuffle);
			s_bGotShuffleStatus = TRUE;
		}
	}
	/*else if (strcmp (cInterface, "org.mpris.MediaPlayer2.TrackList") == 0)
	{
		
	}*/
	else
		cd_debug ("Another interface: %s", cInterface);
}
Пример #7
0
/**
 * g_value_take_boxed:
 * @value: a valid #GValue of %G_TYPE_BOXED derived type
 * @v_boxed: duplicated unowned boxed value to be set
 *
 * Sets the contents of a %G_TYPE_BOXED derived #GValue to @v_boxed
 * and takes over the ownership of the callers reference to @v_boxed;
 * the caller doesn't have to unref it any more.
 *
 * Since: 2.4
 */
void
g_value_take_boxed (GValue       *value,
		    gconstpointer boxed)
{
  g_return_if_fail (G_VALUE_HOLDS_BOXED (value));
  g_return_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)));

  value_set_boxed_internal (value, boxed, FALSE, TRUE);
}
static void _on_got_song_infos (DBusGProxy *proxy, DBusGProxyCall *call_id, GldiModuleInstance *myApplet)
{
	cd_debug ("=== %s ()", __func__);
	CD_APPLET_ENTER;
	s_pGetSongInfosCall = NULL;
	
	GHashTable *pMetadata = NULL;
	GValue v = G_VALUE_INIT;
	GError *erreur = NULL;
	dbus_g_proxy_end_call (proxy,
		call_id,
		&erreur,
		G_TYPE_VALUE, &v,
		G_TYPE_INVALID);
	if (erreur != NULL)
	{
		cd_warning ("couldn't get MPRIS song infos (%s)\n", erreur->message);
		g_error_free (erreur);
		pMetadata = NULL;
	}
	else
	{
		if (G_VALUE_HOLDS_BOXED (&v))
		{
			pMetadata = g_value_get_boxed (&v);  // since we don't destroy the value, we'll take care of the hash-table when we're done with it.
		}
	}
	if (pMetadata != NULL)
	{
		_extract_metadata (pMetadata);
		
		g_hash_table_destroy (pMetadata);
	}
	else
	{
		cd_warning ("  can't get song properties");
		g_free (myData.cPlayingUri);
		myData.cPlayingUri = NULL;
		g_free (myData.cTitle);
		myData.cTitle = NULL;
		g_free (myData.cAlbum);
		myData.cAlbum = NULL;
		g_free (myData.cArtist);
		myData.cArtist = NULL;
		g_free (myData.cCoverPath);
		myData.cCoverPath = NULL;
		myData.iSongLength = 0;
		myData.iTrackNumber = 0;
		myData.cover_exist = FALSE;
	}
	
	cd_musicplayer_update_icon ();
	cd_musicplayer_relaunch_handler ();
	
	CD_APPLET_LEAVE ();
}
gint
_gvalues_compare (const GValue *value1, const GValue *value2)
{
	GType type1;
	GType type2;
	gint ret;

	if (value1 == value2)
		return 0;
	if (!value1)
		return 1;
	if (!value2)
		return -1;

	type1 = G_VALUE_TYPE (value1);
	type2 = G_VALUE_TYPE (value2);

	if (type1 != type2)
		return type1 < type2 ? -1 : type1 > type2;

	if (type_is_fixed_size (type1, NULL))
		ret = _gvalues_compare_fixed (value1, value2);
	else if (type1 == G_TYPE_STRING) 
		ret = _gvalues_compare_string (value1, value2);
	else if (G_VALUE_HOLDS_BOXED (value1)) {
		gpointer p1 = g_value_get_boxed (value1);
		gpointer p2 = g_value_get_boxed (value2);

		if (p1 == p2)
			ret = 0; /* Exactly the same values */
		else if (!p1)
			ret = 1; /* The comparision functions below don't handle NULLs */
		else if (!p2)
			ret = -1; /* The comparision functions below don't handle NULLs */
		else if (type1 == G_TYPE_STRV)
			ret = _gvalues_compare_strv (value1, value2);
		else if (dbus_g_type_is_collection (type1))
			ret = _gvalues_compare_collection (value1, value2);
		else if (dbus_g_type_is_map (type1))
			ret = _gvalues_compare_map (value1, value2);
		else if (dbus_g_type_is_struct (type1))
			ret = _gvalues_compare_struct (value1, value2);
		else if (type1 == G_TYPE_VALUE)
			ret = _gvalues_compare ((GValue *) g_value_get_boxed (value1), (GValue *) g_value_get_boxed (value2));
		else {
			g_warning ("Don't know how to compare boxed types '%s'", g_type_name (type1));
			ret = value1 == value2;
		}
	} else {
		g_warning ("Don't know how to compare types '%s'", g_type_name (type1));
		ret = value1 == value2;
	}

	return ret;
}
Пример #10
0
gboolean
rb_signal_accumulator_value_array (GSignalInvocationHint *hint,
				   GValue *return_accu,
				   const GValue *handler_return,
				   gpointer bleh)
{
	GValueArray *a;
	GValueArray *b;
	int i;

	if (handler_return == NULL)
		return TRUE;

	a = NULL;
	if (G_VALUE_HOLDS_BOXED (return_accu)) {
		a = g_value_get_boxed (return_accu);
		if (a != NULL) {
			a = g_value_array_copy (a);
		}
	}

	if (a == NULL) {
		a = g_value_array_new (1);
	}

	if (G_VALUE_HOLDS_BOXED (handler_return)) {
		b = g_value_get_boxed (handler_return);
		for (i=0; i < b->n_values; i++) {
			GValue *z = g_value_array_get_nth (b, i);
			a = g_value_array_append (a, z);
		}
	}

	g_value_unset (return_accu);
	g_value_init (return_accu, G_TYPE_VALUE_ARRAY);
	g_value_set_boxed (return_accu, a);
	return TRUE;
}
Пример #11
0
static gboolean
draw_arrow_texture (GtkThemingEngine *engine,
                    cairo_t          *cr,
                    gdouble           angle,
                    gdouble           x,
                    gdouble           y,
                    gdouble           size)
{
  GtkStateFlags state;
  GValue value = { 0, };
  cairo_pattern_t *texture = NULL;
  cairo_surface_t *surface = NULL;
  gboolean retval = FALSE;

  state = gtk_theming_engine_get_state (engine);

  gtk_theming_engine_get_property (engine, "-unico-arrow-texture", state, &value);

  if (!G_VALUE_HOLDS_BOXED (&value))
    return FALSE;

  texture = g_value_dup_boxed (&value);
  g_value_unset (&value);

  if (texture != NULL)
    cairo_pattern_get_surface (texture, &surface);

  if (surface != NULL)
    {
      cairo_save (cr);

      cairo_translate (cr, (gint) (x + size / 2), (gint) (y + size / 2));
      cairo_rotate (cr, angle);

      cairo_set_source_surface (cr, surface, - cairo_image_surface_get_width (surface) / 2,
                                             - cairo_image_surface_get_height (surface) / 2);
      cairo_paint (cr);

      cairo_restore (cr);

      retval = TRUE;
    }

  if (texture != NULL)
    cairo_pattern_destroy (texture);

  return retval;
}
Пример #12
0
/**
 * grl_related_keys_get_boxed:
 * @relkeys: set of related keys to inspect
 * @key: key to use
 *
 * Returns the value associated with @key from @relkeys. If @key has no value,
 * the value is not of a boxed type, or @key is not in @relkeys, then %NULL is
 * returned.
 *
 * Returns: (transfer none): the #GBoxed value associated with @key if
 * possible, or %NULL in other case. The caller should not change nor free the
 * value.
 *
 * Since: 0.2.0
 */
gconstpointer
grl_related_keys_get_boxed (GrlRelatedKeys *relkeys,
                            GrlKeyID key)
{
  const GValue *value;

  g_return_val_if_fail (GRL_IS_RELATED_KEYS (relkeys), NULL);

  value = grl_related_keys_get (relkeys, key);

  if (!value || !G_VALUE_HOLDS_BOXED (value)) {
    return NULL;
  } else {
    return g_value_get_boxed (value);
  }
}
// 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);
	}
}
Пример #14
0
/**
 * grl_related_keys_get_binary:
 * @relkeys: set of related keys to inspect
 * @key: (type GrlKeyID): key to use
 * @size: (out): location to store the buffer size
 *
 * Returns the value associated with @key from @relkeys. If @key has no value,
 * or value is not a binary, or @key is not in @relkeys, then 0 is returned.
 *
 * Returns: buffer location associated with @key, or %NULL in other case. If
 * successful @size will be set to the buffer size.
 *
 * Since: 0.1.10
 **/
const guint8 *
grl_related_keys_get_binary (GrlRelatedKeys *relkeys,
                             GrlKeyID key,
                             gsize *size)
{
  const GValue *value;

  g_return_val_if_fail (GRL_IS_RELATED_KEYS (relkeys), NULL);
  g_return_val_if_fail (size, NULL);

  value = grl_related_keys_get (relkeys, key);


  if (!value || !G_VALUE_HOLDS_BOXED (value)) {
    return NULL;
  } else {
    GByteArray * array;

    array = g_value_get_boxed (value);
    *size = array->len;
    return (const guint8 *) array->data;
  }
}
static void
foreach_property_cb (gpointer key, gpointer value, gpointer user_data)
{
	GValue *variant = (GValue *) value;
	NMAccessPoint *ap = (NMAccessPoint *) user_data;

	if (G_VALUE_HOLDS_BOXED (variant)) {
		GArray *array = g_value_get_boxed (variant);

		if (!strcmp (key, "ssid")) {
			guint32 len = MIN (IW_ESSID_MAX_SIZE, array->len);
			GByteArray * ssid;

			/* Stupid ieee80211 layer uses <hidden> */
			if (((len == 8) || (len == 9))
				&& (memcmp (array->data, "<hidden>", 8) == 0))
				return;

			if (nm_utils_is_empty_ssid ((const guint8 *) array->data, len))
				return;

			ssid = g_byte_array_sized_new (len);
			g_byte_array_append (ssid, (const guint8 *) array->data, len);
			nm_ap_set_ssid (ap, ssid);
			g_byte_array_free (ssid, TRUE);
		} else if (!strcmp (key, "bssid")) {
			struct ether_addr addr;

			if (array->len != ETH_ALEN)
				return;
			memset (&addr, 0, sizeof (struct ether_addr));
			memcpy (&addr, array->data, ETH_ALEN);
			nm_ap_set_address (ap, &addr);
		} else if (!strcmp (key, "wpaie")) {
			guint8 * ie = (guint8 *) array->data;
			guint32 flags = nm_ap_get_wpa_flags (ap);

			if (array->len <= 0 || array->len > WPA_MAX_IE_LEN)
				return;
			flags = nm_ap_add_security_from_ie (flags, ie, array->len);
			nm_ap_set_wpa_flags (ap, flags);
		} else if (!strcmp (key, "rsnie")) {
			guint8 * ie = (guint8 *) array->data;
			guint32 flags = nm_ap_get_rsn_flags (ap);

			if (array->len <= 0 || array->len > WPA_MAX_IE_LEN)
				return;
			flags = nm_ap_add_security_from_ie (flags, ie, array->len);
			nm_ap_set_rsn_flags (ap, flags);
		}
	} else if (G_VALUE_HOLDS_INT (variant)) {
		gint32 int_val = g_value_get_int (variant);

		if (!strcmp (key, "frequency")) {
			nm_ap_set_freq (ap, (guint32) int_val);
		} else if (!strcmp (key, "maxrate")) {
			/* Supplicant reports as b/s, we use Kb/s internally */
			nm_ap_set_max_bitrate (ap, int_val / 1000);
		}
	} else if (G_VALUE_HOLDS_UINT (variant)) {
		guint32 val = g_value_get_uint (variant);

		if (!strcmp (key, "capabilities")) {
			if (val & IEEE80211_CAP_ESS) {
				nm_ap_set_mode (ap, NM_802_11_MODE_INFRA);
			} else if (val & IEEE80211_CAP_IBSS) {
				nm_ap_set_mode (ap, NM_802_11_MODE_ADHOC);
			}

			if (val & IEEE80211_CAP_PRIVACY) {
				guint32 flags = nm_ap_get_flags (ap);
				nm_ap_set_flags (ap, flags | NM_802_11_AP_FLAGS_PRIVACY);
			}
		}
	}
}
Пример #16
0
gboolean boxed_in_gvalue(GValue* v) {
    return G_VALUE_HOLDS_BOXED(v);
}
Пример #17
0
static void
modem_properties_changed (DBusGProxy *proxy,
                          const char *interface,
                          GHashTable *props,
                          gpointer user_data)
{
	Modem *modem = user_data;
	GValue *value;
	gboolean old_avail = modem->enabled && modem->loc_enabled && modem->has_location;
	gboolean new_avail;

	if (strcmp (interface, MM_DBUS_MODEM_INTERFACE) == 0) {
		value = g_hash_table_lookup (props, "Enabled");
		if (value && G_VALUE_HOLDS_BOOLEAN (value)) {
			modem->enabled = g_value_get_boolean (value);
			modem->got_enabled = TRUE;
			debugmsg ("%s: (%s) modem %s", __func__, modem->path,
			           modem->enabled ? "enabled" : "disabled");
		}
	} else if (strcmp (interface, MM_DBUS_LOC_INTERFACE) == 0) {
		value = g_hash_table_lookup (props, "Enabled");
		if (value && G_VALUE_HOLDS_BOOLEAN (value)) {
			modem->loc_enabled = g_value_get_boolean (value);
			modem->got_loc_enabled = TRUE;
			debugmsg ("%s: (%s) modem location services %s",
			           __func__, modem->path,
			           modem->loc_enabled ? "enabled" : "disabled");
		}

		value = g_hash_table_lookup (props, "SignalsLocation");
		if (value && G_VALUE_HOLDS_BOOLEAN (value)) {
			modem->signals = g_value_get_boolean (value);
			debugmsg ("%s: (%s) modem %s signal location updates",
			           __func__, modem->path,
			           modem->signals ? "will" : "does not");
		}

		value = g_hash_table_lookup (props, "Capabilities");
		if (value && G_VALUE_HOLDS_UINT (value)) {
			debugmsg ("%s: (%s) modem location capabilities: 0x%X",
			           __func__, modem->path,
			           g_value_get_uint (value));

			if (g_value_get_uint (value) & LOC_CAP_GSM_LACCI)
				modem->has_location = TRUE;
		}

		value = g_hash_table_lookup (props, "Location");
		if (value && G_VALUE_HOLDS_BOXED (value))
			modem_location_update (modem, (GHashTable *) g_value_get_boxed (value));
	}

	new_avail = modem->enabled && modem->loc_enabled && modem->has_location;

	/* If the modem doesn't signal its location, start polling for the
	 * location now.
	 */
	if (new_avail && !modem->signals && !modem->loc_idle) {
		modem->loc_idle = g_timeout_add_seconds (20, modem_loc_poll, modem);
		/* Kick off a quick location request */
		modem_loc_poll (modem);
	}

	/* If the modem is no longer enabled, or it now signals its location
	 * then we no longer need to poll.
	 */
	if ((!new_avail || modem->signals) && modem->loc_idle)
		g_source_remove (modem->loc_idle);

	/* Tell the manager to recheck availability of location info */
	if (old_avail != new_avail)
		recheck_available (modem->owner);

	/* If we've successfully retrieved modem properties and the modem
	 * isn't enabled, do that now.
	 */
	if (modem->got_enabled && !modem->enabled && !modem->enabling) {
		debugmsg ("%s: (%s) enabling...", __func__, modem->path);
		modem->enabling = TRUE;
		dbus_g_proxy_begin_call (modem->modem_proxy, "Enable",
			                 modem_enable_cb, modem, NULL,
			                 G_TYPE_BOOLEAN, TRUE, G_TYPE_INVALID);
	}

	/* If the modem was already enabled but location services weren't,
	 * enable them now.
	 */
	modem_try_loc_enable (modem);

	/* After location is enabled, try to get the location ASAP */
	if (modem->has_location && modem->loc_enabled && !modem->got_initial_loc) {
		modem->got_initial_loc = TRUE;
		modem_loc_poll (modem);
	}
}
gboolean cd_NetworkMonitor_get_active_connection_info (void)
{
	cd_debug ("%s ()", __func__);
	//\_____________ on reset tout.
	myData.bWiredExt = myData.bWirelessExt = FALSE;
	g_free (myData.cDevice);
	myData.cDevice = NULL;
	g_free (myData.cInterface);
	myData.cInterface = NULL;
	g_free (myData.cAccessPoint);
	myData.cAccessPoint = NULL;
	_reset_proxy (myData.dbus_proxy_ActiveConnection);
	_reset_proxy (myData.dbus_proxy_ActiveConnection_prop);
	_reset_proxy (myData.dbus_proxy_Device);
	_reset_proxy (myData.dbus_proxy_Device_prop);
	_reset_proxy (myData.dbus_proxy_ActiveAccessPoint);
	_reset_proxy (myData.dbus_proxy_ActiveAccessPoint_prop);
	_reset_proxy (myData.dbus_proxy_WirelessDevice);
	_reset_proxy (myData.dbus_proxy_WiredDevice);
	
	DBusGProxy *dbus_proxy_ActiveConnection_prop = NULL;
	DBusGProxy *dbus_proxy_Device_prop = NULL;
	
	uint j,k;
	GPtrArray *paActiveConnections = NULL;
	gchar *cActiveConnection, *cDevice, *cAccessPointPath, *cConnection;
	const gchar *cServiceName;
	
	//\_____________ On recupere la liste des connexions actives (ce sont les configs tout-en-un de NM qui sont actuellement utilisees).
	paActiveConnections = (GPtrArray*) cairo_dock_dbus_get_property_as_boxed (myData.dbus_proxy_NM_prop, "org.freedesktop.NetworkManager", "ActiveConnections");
	cd_debug ("%d connections", paActiveConnections->len);
	for (j=0; j < paActiveConnections->len; j++)
	{
		cActiveConnection = (gchar *)g_ptr_array_index(paActiveConnections,j);
		cd_debug ("Network-Monitor : Active Connection path : %s", cActiveConnection);
		
		// on recupere les proprietes de la connexion.
		dbus_proxy_ActiveConnection_prop = cairo_dock_create_new_system_proxy (
			"org.freedesktop.NetworkManager",
			cActiveConnection,
			"org.freedesktop.DBus.Properties");
		GHashTable *props = cairo_dock_dbus_get_all_properties (dbus_proxy_ActiveConnection_prop, "org.freedesktop.NetworkManager.Connection.Active");
		if (props == NULL)
		{
			g_object_unref (dbus_proxy_ActiveConnection_prop);
			continue;
		}
		
		// on regarde si c'est la connexion par defaut.
		GValue *v = g_hash_table_lookup (props, "Default");
		if (!v || !G_VALUE_HOLDS_BOOLEAN (v) || ! g_value_get_boolean (v))
		{
			g_hash_table_unref (props);
			g_object_unref (dbus_proxy_ActiveConnection_prop);
			continue;
		}
		cd_debug (" c'est la connexion par defaut\n");
		myData.cActiveConnection = g_strdup (cActiveConnection);
		
		// on recupere le SpecificObject qui contient le point d'acces courant.
		cAccessPointPath=NULL;
		v = g_hash_table_lookup (props, "SpecificObject");
		if (v && G_VALUE_HOLDS_BOXED (v))
		{
			cAccessPointPath = g_value_get_boxed (v);
			cd_debug (" cAccessPointPath : %s", cAccessPointPath);
		}
		
		// on recupere le nom du service qui fournit cette connexion.
		cServiceName=NULL;
		v = g_hash_table_lookup (props, "ServiceName");
		if (v && G_VALUE_HOLDS_STRING (v))
		{
			cServiceName = g_value_get_string (v);
			cd_debug (" cServiceName : %s", cServiceName);
		}
		
		// on recupere le chemin de la connection.
		cConnection=NULL;
		v = g_hash_table_lookup (props, "Connection");
		if (v && G_VALUE_HOLDS (v, DBUS_TYPE_G_OBJECT_PATH))
		{
			cConnection = g_value_get_boxed (v);
			cd_debug (" cConnectionPath : %s", cConnection);
		}
		
		// on parcourt la liste des devices associes.
		v = g_hash_table_lookup (props, "Devices");
		if (v && G_VALUE_HOLDS_BOXED (v))
		{
			GPtrArray *paDevices = g_value_get_boxed (v);
			cd_debug (" %d devices", paDevices->len);
			for (k=0;  k < paDevices->len; k++)
			{
				// on recupere le device.
				cDevice = (gchar *)g_ptr_array_index(paDevices,k);
				cd_debug (" device path : %s", cDevice);
				dbus_proxy_Device_prop = cairo_dock_create_new_system_proxy (
					"org.freedesktop.NetworkManager",
					cDevice,
					"org.freedesktop.DBus.Properties");
				
				// on regarde son type.
				guint iDeviceType = cairo_dock_dbus_get_property_as_uint (dbus_proxy_Device_prop, "org.freedesktop.NetworkManager.Device", "DeviceType");  // 1 : ethernet, 2 : wifi
				cd_debug (" device type : %d", iDeviceType);
				if (iDeviceType != 1 && iDeviceType != 2)  // ne nous insteresse pas.
				{
					g_object_unref (dbus_proxy_Device_prop);
					continue;
				}
				
				// on recupere son interface.
				gchar *cInterface = cairo_dock_dbus_get_property_as_string (dbus_proxy_Device_prop, "org.freedesktop.NetworkManager.Device", "Interface");
				cd_debug (" interface :%s", cInterface);
				
				// on garde toutes les infos en memoire.
				myData.cInterface = cInterface;
				myData.cDevice = g_strdup(cDevice);
				myData.cServiceName = g_strdup (cServiceName);
				myData.cConnection = g_strdup (cConnection);
				myData.dbus_proxy_ActiveConnection_prop = dbus_proxy_ActiveConnection_prop;
				myData.dbus_proxy_ActiveConnection =  cairo_dock_create_new_system_proxy (
					"org.freedesktop.NetworkManager",
					myData.cActiveConnection,
					"org.freedesktop.NetworkManager.Connection.Active");
				dbus_g_proxy_add_signal(myData.dbus_proxy_ActiveConnection, "PropertiesChanged", CD_DBUS_TYPE_HASH_TABLE, G_TYPE_INVALID);
				dbus_g_proxy_connect_signal(myData.dbus_proxy_ActiveConnection, "PropertiesChanged",
					G_CALLBACK(onChangeActiveConnectionProperties), NULL, NULL);
				
				myData.dbus_proxy_Device_prop = dbus_proxy_Device_prop;
				myData.dbus_proxy_Device = cairo_dock_create_new_system_proxy (
					"org.freedesktop.NetworkManager",
					cDevice,
					"org.freedesktop.NetworkManager.Device");
				
				if (cAccessPointPath && strncmp (cAccessPointPath, "/org/freedesktop/NetworkManager/AccessPoint/", 44) == 0)
				{
					myData.cAccessPoint = g_strdup (cAccessPointPath);
					myData.dbus_proxy_ActiveAccessPoint_prop = cairo_dock_create_new_system_proxy (
						"org.freedesktop.NetworkManager",
						cAccessPointPath,
						"org.freedesktop.DBus.Properties");
					myData.dbus_proxy_ActiveAccessPoint = cairo_dock_create_new_system_proxy (
						"org.freedesktop.NetworkManager",
						cAccessPointPath,
						"org.freedesktop.NetworkManager.AccessPoint");
					dbus_g_proxy_add_signal(myData.dbus_proxy_ActiveAccessPoint, "PropertiesChanged", CD_DBUS_TYPE_HASH_TABLE, G_TYPE_INVALID);
					dbus_g_proxy_connect_signal(myData.dbus_proxy_ActiveAccessPoint, "PropertiesChanged",
						G_CALLBACK(onChangeAccessPointProperties), NULL, NULL);
				}
				
				if (iDeviceType == 1)
				{
					cd_debug (" => Network-Monitor : Connexion filaire\n");
					myData.bWiredExt = TRUE;
					
					// on se connecte au changement de la propriete Carrier.
					myData.dbus_proxy_WiredDevice = cairo_dock_create_new_system_proxy (
						"org.freedesktop.NetworkManager",
						myData.cDevice,
						"org.freedesktop.NetworkManager.Device.Wired");
					dbus_g_proxy_add_signal(myData.dbus_proxy_WiredDevice, "PropertiesChanged", CD_DBUS_TYPE_HASH_TABLE, G_TYPE_INVALID);
					dbus_g_proxy_connect_signal(myData.dbus_proxy_WiredDevice, "PropertiesChanged",
						G_CALLBACK(onChangeWiredDeviceProperties), NULL, NULL);
					
					// on recupere les proprietes de la carte reseau, et de son etat connecte ou non.
					cd_NetworkMonitor_get_wired_connection_infos();
				}
				else
				{
					cd_debug (" => Network-Monitor : Connexion sans fil\n");
					myData.bWirelessExt = TRUE;
					
					// on se connecte au changement de la propriete ActiveAccessPoint.
					myData.dbus_proxy_WirelessDevice = cairo_dock_create_new_system_proxy (
						"org.freedesktop.NetworkManager",
						myData.cDevice,
						"org.freedesktop.NetworkManager.Device.Wireless");
					dbus_g_proxy_add_signal(myData.dbus_proxy_WirelessDevice, "PropertiesChanged", CD_DBUS_TYPE_HASH_TABLE, G_TYPE_INVALID);
					dbus_g_proxy_connect_signal(myData.dbus_proxy_WirelessDevice, "PropertiesChanged",
						G_CALLBACK(onChangeWirelessDeviceProperties), NULL, NULL);
					
					// Recuperation de l'AP active.
					cd_NetworkMonitor_get_wireless_connection_infos();
					
					// Calcul de la qualite du signal
					cd_NetworkMonitor_quality();
				}
				
				cd_NetworkMonitor_draw_icon ();
				
				break ;
			}  // fin de la liste des devices.
		}
		
		g_hash_table_unref (props);
		break;  // on prend la premierr connexion.
	}
	
	g_ptr_array_free(paActiveConnections,TRUE);
	return (myData.bWiredExt || myData.bWirelessExt);
}
Пример #19
0
gint64
gimp_g_value_get_memsize (GValue *value)
{
  gint64 memsize = 0;

  if (! value)
    return 0;

  if (G_VALUE_HOLDS_STRING (value))
    {
      memsize += gimp_string_get_memsize (g_value_get_string (value));
    }
  else if (G_VALUE_HOLDS_BOXED (value))
    {
      if (GIMP_VALUE_HOLDS_RGB (value))
        {
          memsize += sizeof (GimpRGB);
        }
      else if (GIMP_VALUE_HOLDS_MATRIX2 (value))
        {
          memsize += sizeof (GimpMatrix2);
        }
      else if (GIMP_VALUE_HOLDS_PARASITE (value))
        {
          memsize += gimp_parasite_get_memsize (g_value_get_boxed (value),
                                                NULL);
        }
      else if (GIMP_VALUE_HOLDS_ARRAY (value)       ||
               GIMP_VALUE_HOLDS_INT8_ARRAY (value)  ||
               GIMP_VALUE_HOLDS_INT16_ARRAY (value) ||
               GIMP_VALUE_HOLDS_INT32_ARRAY (value) ||
               GIMP_VALUE_HOLDS_FLOAT_ARRAY (value))
        {
          GimpArray *array = g_value_get_boxed (value);

          if (array)
            memsize += (sizeof (GimpArray) +
                        array->static_data ? 0 : array->length);
        }
      else if (GIMP_VALUE_HOLDS_STRING_ARRAY (value))
        {
          GimpArray *array = g_value_get_boxed (value);

          if (array)
            {
              memsize += sizeof (GimpArray);

              if (! array->static_data)
                {
                  gchar **tmp = (gchar **) array->data;
                  gint    i;

                  memsize += array->length * sizeof (gchar *);

                  for (i = 0; i < array->length; i++)
                    memsize += gimp_string_get_memsize (tmp[i]);
                }
            }
        }
      else
        {
          g_printerr ("%s: unhandled boxed value type: %s\n",
                      G_STRFUNC, G_VALUE_TYPE_NAME (value));
        }
    }
  else if (G_VALUE_HOLDS_OBJECT (value))
    {
      g_printerr ("%s: unhandled object value type: %s\n",
                  G_STRFUNC, G_VALUE_TYPE_NAME (value));
    }

  return memsize + sizeof (GValue);
}
Пример #20
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;
}
Пример #21
0
static void
foreach_property_cb (gpointer key, gpointer value, gpointer user_data)
{
	GValue *variant = (GValue *) value;
	NMAccessPoint *ap = (NMAccessPoint *) user_data;

	if (G_VALUE_HOLDS_BOXED (variant)) {
		GArray *array = g_value_get_boxed (variant);

		if (!strcmp (key, "SSID")) {
			guint32 len = MIN (32, array->len);
			GByteArray *ssid;

			/* Stupid ieee80211 layer uses <hidden> */
			if (((len == 8) || (len == 9))
				&& (memcmp (array->data, "<hidden>", 8) == 0))
				return;

			if (nm_utils_is_empty_ssid ((const guint8 *) array->data, len))
				return;

			ssid = g_byte_array_sized_new (len);
			g_byte_array_append (ssid, (const guint8 *) array->data, len);
			nm_ap_set_ssid (ap, ssid);
			g_byte_array_free (ssid, TRUE);
		} else if (!strcmp (key, "BSSID")) {
			struct ether_addr addr;

			if (array->len != ETH_ALEN)
				return;
			memset (&addr, 0, sizeof (struct ether_addr));
			memcpy (&addr, array->data, ETH_ALEN);
			nm_ap_set_address (ap, &addr);
		} else if (!strcmp (key, "Rates")) {
			guint32 maxrate = 0;
			int i;

			/* Find the max AP rate */
			for (i = 0; i < array->len; i++) {
				guint32 r = g_array_index (array, guint32, i);

				if (r > maxrate) {
					maxrate = r;
					nm_ap_set_max_bitrate (ap, r / 1000);
				}
			}
		} else if (!strcmp (key, "WPA")) {
			NM80211ApSecurityFlags flags = nm_ap_get_wpa_flags (ap);

			flags |= security_from_dict (g_value_get_boxed (variant));
			nm_ap_set_wpa_flags (ap, flags);
		} else if (!strcmp (key, "RSN")) {
			NM80211ApSecurityFlags flags = nm_ap_get_rsn_flags (ap);

			flags |= security_from_dict (g_value_get_boxed (variant));
			nm_ap_set_rsn_flags (ap, flags);
		}
	} else if (G_VALUE_HOLDS_UINT (variant)) {
		guint32 val = g_value_get_uint (variant);

		if (!strcmp (key, "Frequency"))
			nm_ap_set_freq (ap, val);
	} else if (G_VALUE_HOLDS_INT (variant)) {
		gint val = g_value_get_int (variant);

		if (!strcmp (key, "Signal"))
			nm_ap_set_strength (ap, nm_ap_utils_level_to_quality (val));
	} else if (G_VALUE_HOLDS_STRING (variant)) {
		const char *val = g_value_get_string (variant);

		if (val && !strcmp (key, "Mode")) {
			if (strcmp (val, "infrastructure") == 0)
				nm_ap_set_mode (ap, NM_802_11_MODE_INFRA);
			else if (strcmp (val, "ad-hoc") == 0)
				nm_ap_set_mode (ap, NM_802_11_MODE_ADHOC);
		}
	} else if (G_VALUE_HOLDS_BOOLEAN (variant)) {
		gboolean val = g_value_get_boolean (variant);

		if (strcmp (key, "Privacy") == 0) {
			if (val) {
				NM80211ApFlags flags = nm_ap_get_flags (ap);
				nm_ap_set_flags (ap, flags | NM_802_11_AP_FLAGS_PRIVACY);
			}
		}
	}
}