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_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; }
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; }
/** * gwy_adjustment_get_property_name: * @adjustment: An adjustment. * * Gets the name of property which is backing an adjustment. * * Returns: (allow-none): * The property name of object passed to * gwy_adjustment_new_for_property(). * Hence, possibly %NULL. **/ const gchar* gwy_adjustment_get_property_name(const GwyAdjustment *adj) { g_return_val_if_fail(GWY_IS_ADJUSTMENT(adj), NULL); Adjustment *priv = adj->priv; return priv->binding ? g_binding_get_source_property(priv->binding) : NULL; }
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; }
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); } }