static gboolean
ip_route_transform_from_metric_string (GBinding     *binding,
                                       const GValue *source_value,
                                       GValue       *target_value,
                                       gpointer      user_data)
{
	NMIPRoute *route;
	const char *text;
	gint64 metric;

	text = g_value_get_string (source_value);
	if (*text)
		metric = strtoul (text, NULL, 10);
	else
		metric = -1;

	/* Fetch the original property value */
	g_object_get (g_binding_get_source (binding),
	              g_binding_get_source_property (binding), &route,
	              NULL);

	nm_ip_route_set_metric (route, metric);

	g_value_take_boxed (target_value, route);
	return TRUE;
}
static gboolean
ip_route_transform_from_dest_string (GBinding     *binding,
                                     const GValue *source_value,
                                     GValue       *target_value,
                                     gpointer      user_data)
{
	int family = GPOINTER_TO_INT (user_data);
	NMIPRoute *route;
	const char *text;
	char *addrstr;
	guint32 prefix;

	text = g_value_get_string (source_value);
	if (!parse_addr_prefix (text, family, &addrstr, &prefix))
		return FALSE;

	/* Fetch the original property value */
	g_object_get (g_binding_get_source (binding),
	              g_binding_get_source_property (binding), &route,
	              NULL);

	nm_ip_route_set_dest (route, addrstr);
	nm_ip_route_set_prefix (route, prefix);
	g_free (addrstr);

	g_value_take_boxed (target_value, route);
	return TRUE;
}
static gboolean
ip_route_transform_from_next_hop_string (GBinding     *binding,
                                         const GValue *source_value,
                                         GValue       *target_value,
                                         gpointer      user_data)
{
	int family = GPOINTER_TO_INT (user_data);
	NMIPRoute *route;
	const char *text;

	text = g_value_get_string (source_value);
	if (*text) {
		if (!nm_utils_ipaddr_valid (family, text))
			return FALSE;
	} else
		text = NULL;

	/* Fetch the original property value */
	g_object_get (g_binding_get_source (binding),
	              g_binding_get_source_property (binding), &route,
	              NULL);

	nm_ip_route_set_next_hop (route, text);

	g_value_take_boxed (target_value, route);
	return TRUE;
}
예제 #4
0
static gboolean
route_list_transform_from_route (GBinding     *binding,
                                 const GValue *source_value,
                                 GValue       *target_value,
                                 gpointer      user_data)
{
	NmtRouteTable *table = NMT_ROUTE_TABLE (g_binding_get_source (binding));
	NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
	int n = GPOINTER_TO_INT (user_data);
	GPtrArray *routes;
	NMIPRoute *route;

	if (n >= priv->routes->len)
		return FALSE;
	route = priv->routes->pdata[n];

	routes = priv->routes;
	priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);

	if (route)
		nm_ip_route_unref (route);
	routes->pdata[n] = g_value_dup_boxed (source_value);

	g_value_take_boxed (target_value, routes);
	return TRUE;
}
예제 #5
0
/**
 * gwy_adjustment_get_object:
 * @adjustment: An adjustment.
 *
 * Gets the object whose property is backing an adjustment.
 *
 * Returns: (allow-none) (transfer none):
 *          The object passed to gwy_adjustment_new_for_property().  Hence,
 *          possibly %NULL.
 **/
GObject*
gwy_adjustment_get_object(const GwyAdjustment *adj)
{
    g_return_val_if_fail(GWY_IS_ADJUSTMENT(adj), NULL);
    Adjustment *priv = adj->priv;
    return priv->binding ? g_binding_get_source(priv->binding) : NULL;
}
예제 #6
0
static gboolean
transform_lcp_echo_properties_to_checkbox (GBinding     *binding,
                                           const GValue *from_value,
                                           GValue       *to_value,
                                           gpointer      user_data)
{
	NMSettingPpp *s_ppp = NM_SETTING_PPP (g_binding_get_source (binding));

	if (   nm_setting_ppp_get_lcp_echo_interval (s_ppp) != 0
	    && nm_setting_ppp_get_lcp_echo_failure (s_ppp) != 0)
		g_value_set_boolean (to_value, TRUE);
	else
		g_value_set_boolean (to_value, FALSE);

	return TRUE;
}
static gboolean
sync_recorder_server_enabled_for_daemon (GBinding     *binding,
                                         const GValue *from_value,
                                         GValue       *to_value,
                                         gpointer      user_data)
{
  EmerPermissionsProvider *permissions =
    EMER_PERMISSIONS_PROVIDER (g_binding_get_source (binding));

  gboolean daemon_enabled = g_value_get_boolean (from_value);
  gboolean uploading_enabled =
    emer_permissions_provider_get_uploading_enabled (permissions);

  g_value_set_boolean (to_value, daemon_enabled && uploading_enabled);

  return TRUE;
}
예제 #8
0
static gboolean
route_list_transform_to_route (GBinding     *binding,
                               const GValue *source_value,
                               GValue       *target_value,
                               gpointer      user_data)
{
	NmtRouteTable *table = NMT_ROUTE_TABLE (g_binding_get_source (binding));
	NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
	int n = GPOINTER_TO_INT (user_data);
	NMIPRoute *route;

	if (n >= priv->routes->len)
		return FALSE;

	route = priv->routes->pdata[n];
	g_value_set_boxed (target_value, route);
	return TRUE;
}
static gboolean
ip_addresses_with_prefix_from_strv (GBinding     *binding,
                                    const GValue *source_value,
                                    GValue       *target_value,
                                    gpointer      user_data)
{
	int family = GPOINTER_TO_INT (user_data);
	char **strings;
	GPtrArray *addrs;
	NMIPAddress *addr;
	char *addrstr;
	guint32 prefix;
	int i;

	strings = g_value_get_boxed (source_value);
	/* Fetch the original property value, so as to preserve their extra attributes */
	g_object_get (g_binding_get_source (binding),
	              g_binding_get_source_property (binding), &addrs,
	              NULL);

	for (i = 0; strings[i]; i++) {
		if (i >= addrs->len) {
			if (family == AF_INET)
				addr = nm_ip_address_new (AF_INET, "0.0.0.0", 32, NULL);
			else
				addr = nm_ip_address_new (AF_INET6, "::", 128, NULL);
			g_ptr_array_add (addrs, addr);
		} else
			addr = addrs->pdata[i];

		if (!parse_addr_prefix (strings[i], family, &addrstr, &prefix)) {
			g_ptr_array_unref (addrs);
			return FALSE;
		}

		nm_ip_address_set_address (addr, addrstr);
		nm_ip_address_set_prefix (addr, prefix);
		g_free (addrstr);
	}

	g_ptr_array_set_size (addrs, i);
	g_value_take_boxed (target_value, addrs);
	return TRUE;
}
예제 #10
0
파일: prop-editor.c 프로젝트: 3v1n0/gtk
static void
add_binding_info (GtkInspectorPropEditor *editor)
{
  GObject *object;
  const gchar *name;
  GHashTable *bindings;
  GHashTableIter iter;
  GBinding *binding;
  GtkWidget *row;
  GtkWidget *button;
  gchar *str;
  GObject *other;
  const gchar *property;
  const gchar *direction;
  const gchar *tip;
  GtkWidget *label;

  object = editor->priv->object;
  name = editor->priv->name;

  /* Note: this is accessing private GBinding details, so keep it
   * in sync with the implementation in GObject
   */
  bindings = (GHashTable *)g_object_get_data (G_OBJECT (object), "g-binding");
  if (!bindings)
    return;

  g_hash_table_iter_init (&iter, bindings);
  while (g_hash_table_iter_next (&iter, (gpointer*)&binding, NULL))
    {
      if (g_binding_get_source (binding) == object &&
          g_str_equal (g_binding_get_source_property (binding), name))
        {
          other = g_binding_get_target (binding);
          property = g_binding_get_target_property (binding);
          if (g_binding_get_flags (binding) & G_BINDING_INVERT_BOOLEAN)
            {
              direction = "↛";
              tip = _("inverted");
            }
          else
            {
              direction = "→";
              tip = NULL;
            }
        }
      else if (g_binding_get_target (binding) == object &&
               g_str_equal (g_binding_get_target_property (binding), name))
        {
          other = g_binding_get_source (binding);
          property = g_binding_get_source_property (binding);
          if (g_binding_get_flags (binding) & G_BINDING_INVERT_BOOLEAN)
            {
              direction = "↚";
              tip = _("inverted");
            }
          else
            {
              direction = "←";
              tip = NULL;
            }
        }
      else
        continue;
     
      if (g_binding_get_flags (binding) & G_BINDING_BIDIRECTIONAL)
        {
          if (g_binding_get_flags (binding) & G_BINDING_INVERT_BOOLEAN)
            {
              direction = "↮";
              tip = _("bidirectional, inverted");
            }
          else
            {
              direction = "↔";
              tip = _("bidirectional");
            }
        }

      row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
      gtk_container_add (GTK_CONTAINER (row), gtk_label_new (_("Binding:")));
      label = gtk_label_new (direction);
      if (tip)
        gtk_widget_set_tooltip_text (label, tip);
      gtk_container_add (GTK_CONTAINER (row), label);
      str = g_strdup_printf ("%p :: %s", other, property);
      label = gtk_label_new (str);
      gtk_container_add (GTK_CONTAINER (row), label);
      g_free (str);
      button = gtk_button_new_with_label (_("Properties"));
      g_object_set_data (G_OBJECT (button), "object", other);
      g_signal_connect (button, "clicked",
                        G_CALLBACK (binding_object_properties), editor);
      gtk_container_add (GTK_CONTAINER (row), button);

       gtk_widget_show_all (row);
       gtk_container_add (GTK_CONTAINER (editor), row);
    }
}