static void gog_object_write_property_sax (GogObject const *obj, GParamSpec *pspec, GsfXMLOut *output) { GObject *val_obj; GType prop_type = G_PARAM_SPEC_VALUE_TYPE (pspec); GValue value = { 0 }; g_value_init (&value, prop_type); g_object_get_property (G_OBJECT (obj), pspec->name, &value); /* No need to save default values */ if (((pspec->flags & GOG_PARAM_POSITION) && gog_object_is_default_position_flags (obj, pspec->name)) || (!(pspec->flags & GOG_PARAM_FORCE_SAVE) && !(pspec->flags & GOG_PARAM_POSITION) && g_param_value_defaults (pspec, &value))) { g_value_unset (&value); return; } switch (G_TYPE_FUNDAMENTAL (prop_type)) { case G_TYPE_CHAR: case G_TYPE_UCHAR: case G_TYPE_BOOLEAN: case G_TYPE_INT: case G_TYPE_UINT: case G_TYPE_LONG: case G_TYPE_ULONG: case G_TYPE_ENUM: case G_TYPE_FLAGS: { GValue str = { 0 }; g_value_init (&str, G_TYPE_STRING); g_value_transform (&value, &str); gsf_xml_out_start_element (output, "property"); gsf_xml_out_add_cstr_unchecked (output, "name", pspec->name); gsf_xml_out_add_cstr (output, NULL, g_value_get_string (&str)); gsf_xml_out_end_element (output); /* </property> */ g_value_unset (&str); break; } case G_TYPE_FLOAT: case G_TYPE_DOUBLE: { GValue vd = { 0 }; GString *str = g_string_new (NULL); g_value_init (&vd, G_TYPE_DOUBLE); g_value_transform (&value, &vd); go_dtoa (str, "!g", g_value_get_double (&vd)); g_value_unset (&vd); gsf_xml_out_start_element (output, "property"); gsf_xml_out_add_cstr_unchecked (output, "name", pspec->name); gsf_xml_out_add_cstr (output, NULL, str->str); gsf_xml_out_end_element (output); /* </property> */ g_string_free (str, TRUE); break; } case G_TYPE_STRING: { char const *str = g_value_get_string (&value); if (str != NULL) { gsf_xml_out_start_element (output, "property"); gsf_xml_out_add_cstr_unchecked (output, "name", pspec->name); gsf_xml_out_add_cstr (output, NULL, str); gsf_xml_out_end_element (output); /* </property> */ } break; } case G_TYPE_OBJECT: val_obj = g_value_get_object (&value); if (val_obj != NULL) { if (GO_IS_PERSIST (val_obj)) { gsf_xml_out_start_element (output, "property"); gsf_xml_out_add_cstr_unchecked (output, "name", pspec->name); go_persist_sax_save (GO_PERSIST (val_obj), output); gsf_xml_out_end_element (output); /* </property> */ } else g_warning ("How are we supposed to persist this ??"); } break; default: g_warning ("I could not persist property \"%s\", since type \"%s\" is unhandled.", g_param_spec_get_name (pspec), g_type_name (G_TYPE_FUNDAMENTAL(prop_type))); } g_value_unset (&value); }
static gchar * debug_dump_get_object_params (GObject * object, GstDebugGraphDetails details, const char *const *ignored_propnames) { gchar *param_name = NULL; GParamSpec **properties, *property; GValue value = { 0, }; guint i, number_of_properties; gchar *tmp, *value_str; const gchar *ellipses; /* get paramspecs and show non-default properties */ properties = g_object_class_list_properties (G_OBJECT_GET_CLASS (object), &number_of_properties); if (properties) { for (i = 0; i < number_of_properties; i++) { gint j; gboolean ignore = FALSE; property = properties[i]; /* skip some properties */ if (!(property->flags & G_PARAM_READABLE)) continue; if (!strcmp (property->name, "name")) continue; if (ignored_propnames) for (j = 0; ignored_propnames[j]; j++) if (!g_strcmp0 (ignored_propnames[j], property->name)) ignore = TRUE; if (ignore) continue; g_value_init (&value, property->value_type); g_object_get_property (G_OBJECT (object), property->name, &value); if (!(g_param_value_defaults (property, &value))) { tmp = g_strdup_value_contents (&value); value_str = g_strescape (tmp, NULL); g_free (tmp); /* too long, ellipsize */ if (!(details & GST_DEBUG_GRAPH_SHOW_FULL_PARAMS) && strlen (value_str) > PARAM_MAX_LENGTH) ellipses = "…"; else ellipses = ""; if (param_name) tmp = param_name; else tmp = (char *) ""; if (details & GST_DEBUG_GRAPH_SHOW_FULL_PARAMS) { param_name = g_strdup_printf ("%s\\n%s=%s", tmp, property->name, value_str); } else { param_name = g_strdup_printf ("%s\\n%s=%." G_STRINGIFY (PARAM_MAX_LENGTH) "s%s", tmp, property->name, value_str, ellipses); } if (tmp[0] != '\0') g_free (tmp); g_free (value_str); } g_value_unset (&value); } g_free (properties); } return param_name; }
static void print_element_properties_info (GstElement * element) { GParamSpec **property_specs; guint num_properties, i; gboolean readable; gboolean first_flag; property_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), &num_properties); n_print ("\n"); n_print ("Element Properties:\n"); for (i = 0; i < num_properties; i++) { GValue value = { 0, }; GParamSpec *param = property_specs[i]; readable = FALSE; g_value_init (&value, param->value_type); n_print (" %-20s: %s\n", g_param_spec_get_name (param), g_param_spec_get_blurb (param)); first_flag = TRUE; n_print ("%-23.23s flags: ", ""); if (param->flags & G_PARAM_READABLE) { g_object_get_property (G_OBJECT (element), param->name, &value); readable = TRUE; if (!first_flag) g_print (", "); else first_flag = FALSE; g_print (_("readable")); } if (param->flags & G_PARAM_WRITABLE) { if (!first_flag) g_print (", "); else first_flag = FALSE; g_print (_("writable")); } if (param->flags & GST_PARAM_CONTROLLABLE) { if (!first_flag) g_print (", "); else first_flag = FALSE; g_print (_("controllable")); } n_print ("\n"); switch (G_VALUE_TYPE (&value)) { case G_TYPE_STRING: { GParamSpecString *pstring = G_PARAM_SPEC_STRING (param); n_print ("%-23.23s String. ", ""); if (pstring->default_value == NULL) g_print ("Default: null "); else g_print ("Default: \"%s\" ", pstring->default_value); if (readable) { const char *string_val = g_value_get_string (&value); if (string_val == NULL) g_print ("Current: null"); else g_print ("Current: \"%s\"", string_val); } break; } case G_TYPE_BOOLEAN: { GParamSpecBoolean *pboolean = G_PARAM_SPEC_BOOLEAN (param); n_print ("%-23.23s Boolean. ", ""); g_print ("Default: %s ", (pboolean->default_value ? "true" : "false")); if (readable) g_print ("Current: %s", (g_value_get_boolean (&value) ? "true" : "false")); break; } case G_TYPE_ULONG: { GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param); n_print ("%-23.23s Unsigned Long. ", ""); g_print ("Range: %lu - %lu Default: %lu ", pulong->minimum, pulong->maximum, pulong->default_value); if (readable) g_print ("Current: %lu", g_value_get_ulong (&value)); break; } case G_TYPE_LONG: { GParamSpecLong *plong = G_PARAM_SPEC_LONG (param); n_print ("%-23.23s Long. ", ""); g_print ("Range: %ld - %ld Default: %ld ", plong->minimum, plong->maximum, plong->default_value); if (readable) g_print ("Current: %ld", g_value_get_long (&value)); break; } case G_TYPE_UINT: { GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param); n_print ("%-23.23s Unsigned Integer. ", ""); g_print ("Range: %u - %u Default: %u ", puint->minimum, puint->maximum, puint->default_value); if (readable) g_print ("Current: %u", g_value_get_uint (&value)); break; } case G_TYPE_INT: { GParamSpecInt *pint = G_PARAM_SPEC_INT (param); n_print ("%-23.23s Integer. ", ""); g_print ("Range: %d - %d Default: %d ", pint->minimum, pint->maximum, pint->default_value); if (readable) g_print ("Current: %d", g_value_get_int (&value)); break; } case G_TYPE_UINT64: { GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param); n_print ("%-23.23s Unsigned Integer64. ", ""); g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT " Default: %" G_GUINT64_FORMAT " ", puint64->minimum, puint64->maximum, puint64->default_value); if (readable) g_print ("Current: %" G_GUINT64_FORMAT, g_value_get_uint64 (&value)); break; } case G_TYPE_INT64: { GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param); n_print ("%-23.23s Integer64. ", ""); g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT " Default: %" G_GINT64_FORMAT " ", pint64->minimum, pint64->maximum, pint64->default_value); if (readable) g_print ("Current: %" G_GINT64_FORMAT, g_value_get_int64 (&value)); break; } case G_TYPE_FLOAT: { GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param); n_print ("%-23.23s Float. ", ""); g_print ("Range: %15.7g - %15.7g Default: %15.7g ", pfloat->minimum, pfloat->maximum, pfloat->default_value); if (readable) g_print ("Current: %15.7g", g_value_get_float (&value)); break; } case G_TYPE_DOUBLE: { GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param); n_print ("%-23.23s Double. ", ""); g_print ("Range: %15.7g - %15.7g Default: %15.7g ", pdouble->minimum, pdouble->maximum, pdouble->default_value); if (readable) g_print ("Current: %15.7g", g_value_get_double (&value)); break; } default: if (param->value_type == GST_TYPE_CAPS) { const GstCaps *caps = gst_value_get_caps (&value); if (!caps) n_print ("%-23.23s Caps (NULL)", ""); else { print_caps (caps, " "); } } else if (G_IS_PARAM_SPEC_ENUM (param)) { GParamSpecEnum *penum = G_PARAM_SPEC_ENUM (param); GEnumValue *values; guint j = 0; gint enum_value; const gchar *def_val_nick = "", *cur_val_nick = ""; values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values; enum_value = g_value_get_enum (&value); while (values[j].value_name) { if (values[j].value == enum_value) cur_val_nick = values[j].value_nick; if (values[j].value == penum->default_value) def_val_nick = values[j].value_nick; j++; } n_print ("%-23.23s Enum \"%s\" Default: %d, \"%s\" Current: %d, \"%s\"", "", g_type_name (G_VALUE_TYPE (&value)), penum->default_value, def_val_nick, enum_value, cur_val_nick); j = 0; while (values[j].value_name) { g_print ("\n"); if (_name) g_print (_name); g_print ("%-23.23s (%d): %-16s - %s", "", values[j].value, values[j].value_nick, values[j].value_name); j++; } /* g_type_class_unref (ec); */ } else if (G_IS_PARAM_SPEC_FLAGS (param)) { GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param); GFlagsValue *values; guint j = 0; gint flags_value; GString *cur_flags = NULL, *def_flags = NULL; values = G_FLAGS_CLASS (g_type_class_ref (param->value_type))->values; flags_value = g_value_get_flags (&value); while (values[j].value_name) { if (values[j].value & flags_value) { if (cur_flags) { g_string_append_printf (cur_flags, " | %s", values[j].value_nick); } else { cur_flags = g_string_new (values[j].value_nick); } } if (values[j].value & pflags->default_value) { if (def_flags) { g_string_append_printf (def_flags, " | %s", values[j].value_nick); } else { def_flags = g_string_new (values[j].value_nick); } } j++; } n_print ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\" Current: 0x%08x, \"%s\"", "", g_type_name (G_VALUE_TYPE (&value)), pflags->default_value, (def_flags ? def_flags->str : "(none)"), flags_value, (cur_flags ? cur_flags->str : "(none)")); j = 0; while (values[j].value_name) { g_print ("\n"); if (_name) g_print (_name); g_print ("%-23.23s (0x%08x): %-16s - %s", "", values[j].value, values[j].value_nick, values[j].value_name); j++; } if (cur_flags) g_string_free (cur_flags, TRUE); if (def_flags) g_string_free (def_flags, TRUE); } else if (G_IS_PARAM_SPEC_OBJECT (param)) { n_print ("%-23.23s Object of type \"%s\"", "", g_type_name (param->value_type)); } else if (G_IS_PARAM_SPEC_BOXED (param)) { n_print ("%-23.23s Boxed pointer of type \"%s\"", "", g_type_name (param->value_type)); } else if (G_IS_PARAM_SPEC_POINTER (param)) { if (param->value_type != G_TYPE_POINTER) { n_print ("%-23.23s Pointer of type \"%s\".", "", g_type_name (param->value_type)); } else { n_print ("%-23.23s Pointer.", ""); } } else if (param->value_type == G_TYPE_VALUE_ARRAY) { n_print ("%-23.23s Array of GValues", ""); } else if (GST_IS_PARAM_SPEC_FRACTION (param)) { GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param); n_print ("%-23.23s Fraction. ", ""); g_print ("Range: %d/%d - %d/%d Default: %d/%d ", pfraction->min_num, pfraction->min_den, pfraction->max_num, pfraction->max_den, pfraction->def_num, pfraction->def_den); if (readable) g_print ("Current: %d/%d", gst_value_get_fraction_numerator (&value), gst_value_get_fraction_denominator (&value)); } else { n_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type, g_type_name (param->value_type)); } break; } if (!readable) g_print (" Write only\n"); else g_print ("\n"); g_value_reset (&value); } if (num_properties == 0) n_print (" none\n"); g_free (property_specs); }
static AtkObject* gail_get_accessible_for_widget (GtkWidget *widget, gboolean *transient) { AtkObject *obj = NULL; GType gnome_canvas; gnome_canvas = g_type_from_name ("GnomeCanvas"); *transient = FALSE; if (!widget) return NULL; if (GTK_IS_ENTRY (widget)) { GtkWidget *other_widget = widget->parent; if (GTK_IS_COMBO (other_widget)) { gail_set_focus_widget (other_widget, widget); widget = other_widget; } } else if (GTK_IS_NOTEBOOK (widget)) { GtkNotebook *notebook; gint page_num = -1; notebook = GTK_NOTEBOOK (widget); /* * Report the currently focused tab rather than the currently selected tab */ if (notebook->focus_tab) { page_num = g_list_index (notebook->children, notebook->focus_tab->data); } if (page_num != -1) { obj = gtk_widget_get_accessible (widget); obj = atk_object_ref_accessible_child (obj, page_num); g_object_unref (obj); } } else if (GTK_CHECK_TYPE ((widget), gnome_canvas)) { GObject *focused_item; GValue value = {0, }; g_value_init (&value, G_TYPE_OBJECT); g_object_get_property (G_OBJECT (widget), "focused_item", &value); focused_item = g_value_get_object (&value); if (focused_item) { AtkObject *tmp; obj = atk_gobject_accessible_for_object (G_OBJECT (focused_item)); tmp = g_object_get_qdata (G_OBJECT (obj), quark_focus_object); if (tmp != NULL) obj = tmp; } } else if (GTK_IS_TOGGLE_BUTTON (widget)) { GtkWidget *other_widget = widget->parent; if (GTK_IS_COMBO_BOX (other_widget)) { gail_set_focus_widget (other_widget, widget); widget = other_widget; } } if (obj == NULL) { AtkObject *focus_object; obj = gtk_widget_get_accessible (widget); focus_object = g_object_get_qdata (G_OBJECT (obj), quark_focus_object); /* * We check whether the object for this focus_object has been deleted. * This can happen when navigating to an empty directory in nautilus. * See bug #141907. */ if (ATK_IS_GOBJECT_ACCESSIBLE (focus_object)) { if (!atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (focus_object))) focus_object = NULL; } if (focus_object) obj = focus_object; } return obj; }
/** * gom_command_builder_build_update: * @builder: A #GomCommandBuilder. * @resource: a #GomResource * * Builds a new #GomCommand that will update the contents stored for @resource * in the underlying database. * * Returns: (transfer full): A #GomCommand. */ GomCommand * gom_command_builder_build_update (GomCommandBuilder *builder, GomResource *resource) { GomCommandBuilderPrivate *priv; GomResourceClass *klass; GomCommand *command = NULL; GParamSpec **pspecs = NULL; gboolean did_pspec = FALSE; GString *str = NULL; guint n_pspecs = 0; guint i = 0; guint idx = 0; g_return_val_if_fail(GOM_IS_COMMAND_BUILDER(builder), NULL); priv = builder->priv; klass = g_type_class_ref(priv->resource_type); pspecs = g_object_class_list_properties(G_OBJECT_CLASS(klass), &n_pspecs); str = g_string_new("UPDATE "); g_string_append_printf(str, "%s SET ", klass->table); for (i = 0; i < n_pspecs; i++) { if (do_prop_on_insert(pspecs[i], klass, priv->resource_type)) { if (did_pspec) { g_string_append(str, ", "); } g_string_append_printf(str, "'%s' = ?", pspecs[i]->name); did_pspec = TRUE; } } g_string_append_printf(str, " WHERE '%s'.'%s' = ?;", klass->table, klass->primary_key); command = g_object_new(GOM_TYPE_COMMAND, "adapter", priv->adapter, "sql", str->str, NULL); for (i = 0; i < n_pspecs; i++) { if (do_prop_on_insert(pspecs[i], klass, priv->resource_type)) { GValue value = { 0 }; resource_get_property(G_OBJECT(resource), pspecs[i]->name, &value); gom_command_set_param(command, idx++, &value); g_value_unset(&value); } } { GParamSpec *pspec; GValue value = { 0 }; pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(resource), klass->primary_key); g_assert(pspec); g_value_init(&value, pspec->value_type); g_object_get_property(G_OBJECT(resource), pspec->name, &value); gom_command_set_param(command, idx++, &value); g_value_unset(&value); } g_type_class_unref(klass); if (str) { g_string_free(str, TRUE); } g_free(pspecs); return command; }
static JsonObject * json_gobject_dump (GObject *gobject) { JsonSerializableIface *iface = NULL; JsonSerializable *serializable = NULL; gboolean list_properties = FALSE; gboolean serialize_property = FALSE; gboolean get_property = FALSE; JsonObject *object; GParamSpec **pspecs; guint n_pspecs, i; if (JSON_IS_SERIALIZABLE (gobject)) { serializable = JSON_SERIALIZABLE (gobject); iface = JSON_SERIALIZABLE_GET_IFACE (gobject); list_properties = (iface->list_properties != NULL); serialize_property = (iface->serialize_property != NULL); get_property = (iface->get_property != NULL); } object = json_object_new (); if (list_properties) pspecs = json_serializable_list_properties (serializable, &n_pspecs); else pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (gobject), &n_pspecs); for (i = 0; i < n_pspecs; i++) { GParamSpec *pspec = pspecs[i]; GValue value = { 0, }; JsonNode *node = NULL; /* read only what we can */ if (!(pspec->flags & G_PARAM_READABLE)) continue; g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec)); if (get_property) json_serializable_get_property (serializable, pspec, &value); else g_object_get_property (gobject, pspec->name, &value); /* if there is a serialization vfunc, then it is completely responsible * for serializing the property, possibly by calling the implementation * of the default JsonSerializable interface through chaining up */ if (serialize_property) { node = json_serializable_serialize_property (serializable, pspec->name, &value, pspec); } /* skip if the value is the default for the property */ else if (!g_param_value_defaults (pspec, &value)) node = json_serialize_pspec (&value, pspec); if (node) json_object_set_member (object, pspec->name, node); g_value_unset (&value); } g_free (pspecs); return object; }
/* The public functions */ GtkWidget * gnome_prefs_entry_new (GtkWidget *table, const gchar *label_txt, const gchar *conf_key, const gchar *tooltip, int row, gboolean box) { GnomePrefsWindow *gpw = NULL; GValue value = { 0, {{0}, {0}}}; int cols = 0; GtkWidget *entry = NULL; GtkWidget *label = NULL; GtkWidget *hbox = NULL; gchar *conf_string = NULL; gboolean writable = FALSE; writable = gm_conf_is_key_writable (conf_key); if (box) { hbox = gtk_hbox_new (FALSE, 0); g_value_init (&value, G_TYPE_INT); g_object_get_property (G_OBJECT (table), "n-columns", &value); cols = g_value_get_int (&value); g_value_unset (&value); } label = gtk_label_new_with_mnemonic (label_txt); if (!writable) gtk_widget_set_sensitive (GTK_WIDGET (label), FALSE); if (box) gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 1 * 2); else gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); entry = gtk_entry_new (); gtk_label_set_mnemonic_widget (GTK_LABEL(label), entry); if (!writable) gtk_widget_set_sensitive (GTK_WIDGET (entry), FALSE); if (box) gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 1 * 2); else gtk_table_attach (GTK_TABLE (table), entry, 1, 2, row, row+1, (GtkAttachOptions) (NULL), (GtkAttachOptions) (NULL), 0, 0); conf_string = gm_conf_get_string (conf_key); if (conf_string != NULL) gtk_entry_set_text (GTK_ENTRY (entry), conf_string); g_free (conf_string); g_signal_connect_after (entry, "focus-out-event", G_CALLBACK (entry_focus_changed), (gpointer)conf_key); g_signal_connect_after (entry, "activate", G_CALLBACK (entry_activate_changed), (gpointer)conf_key); gm_conf_notifier_add (conf_key, entry_changed_nt, (gpointer) entry); if (box) gtk_table_attach (GTK_TABLE (table), hbox, 0, cols, row, row+1, (GtkAttachOptions) (NULL), (GtkAttachOptions) (NULL), 0, 0); gpw = (GnomePrefsWindow *) g_object_get_data (G_OBJECT (table), "gpw"); if (gpw && tooltip) gtk_widget_set_tooltip_text (entry, tooltip); gtk_widget_show_all (table); return entry; }
static GtkCellEditable * egg_cell_renderer_keys_start_editing (GtkCellRenderer *cell, GdkEvent *event, GtkWidget *widget, const gchar *path, const GdkRectangle *background_area, const GdkRectangle *cell_area, GtkCellRendererState flags) { GtkCellRendererText *celltext; EggCellRendererKeys *keys; GdkDisplay *display; GdkSeat *seat; GtkWidget *label; GtkWidget *eventbox; GValue celltext_editable = {0}; celltext = GTK_CELL_RENDERER_TEXT (cell); keys = EGG_CELL_RENDERER_KEYS (cell); /* If the cell isn't editable we return NULL. */ g_value_init (&celltext_editable, G_TYPE_BOOLEAN); g_object_get_property (G_OBJECT (celltext), "editable", &celltext_editable); if (g_value_get_boolean (&celltext_editable) == FALSE) return NULL; g_return_val_if_fail (gtk_widget_get_window (widget) != NULL, NULL); display = gtk_widget_get_display (widget); seat = gdk_display_get_default_seat (display); if (gdk_seat_grab (seat, gtk_widget_get_window (widget), GDK_SEAT_CAPABILITY_ALL, FALSE, NULL, event, NULL, NULL) != GDK_GRAB_SUCCESS) return NULL; keys->grab_widget = widget; g_signal_connect (G_OBJECT (widget), "key_press_event", G_CALLBACK (grab_key_callback), keys); eventbox = g_object_new (pointless_eventbox_subclass_get_type (), NULL); keys->edit_widget = eventbox; g_object_add_weak_pointer (G_OBJECT (keys->edit_widget), (void**) &keys->edit_widget); label = gtk_label_new (NULL); gtk_label_set_xalign (GTK_LABEL (label), 0.0); gtk_widget_modify_bg (eventbox, GTK_STATE_NORMAL, >k_widget_get_style (widget)->bg[GTK_STATE_SELECTED]); gtk_widget_modify_fg (label, GTK_STATE_NORMAL, >k_widget_get_style (widget)->fg[GTK_STATE_SELECTED]); gtk_label_set_text (GTK_LABEL (label), TOOLTIP_TEXT); gtk_container_add (GTK_CONTAINER (eventbox), label); g_object_set_data_full (G_OBJECT (keys->edit_widget), EGG_CELL_RENDERER_TEXT_PATH, g_strdup (path), g_free); gtk_widget_show_all (keys->edit_widget); g_signal_connect (G_OBJECT (keys->edit_widget), "unrealize", G_CALLBACK (ungrab_stuff), keys); keys->edit_key = keys->accel_key; return GTK_CELL_EDITABLE (keys->edit_widget); }
TerminalProfile * _terminal_profile_clone (TerminalProfile *base_profile, const char *visible_name) { TerminalApp *app = terminal_app_get (); GObject *base_object = G_OBJECT (base_profile); TerminalProfilePrivate *new_priv; char profile_name[32]; GParameter *params; GParamSpec **pspecs; guint n_pspecs, i, n_params, profile_num; TerminalProfile *new_profile; g_object_ref (base_profile); profile_num = 0; do { g_snprintf (profile_name, sizeof (profile_name), "profile%u", profile_num++); } while (terminal_app_get_profile_by_name (app, profile_name) != NULL); /* Now we have an unused profile name */ pspecs = g_object_class_list_properties (G_OBJECT_CLASS (TERMINAL_PROFILE_GET_CLASS (base_profile)), &n_pspecs); params = g_newa (GParameter, n_pspecs); n_params = 0; for (i = 0; i < n_pspecs; ++i) { GParamSpec *pspec = pspecs[i]; GValue *value; if (pspec->owner_type != TERMINAL_TYPE_PROFILE || (pspec->flags & G_PARAM_WRITABLE) == 0) continue; params[n_params].name = pspec->name; value = ¶ms[n_params].value; G_VALUE_TYPE (value) = 0; g_value_init (value, G_PARAM_SPEC_VALUE_TYPE (pspec)); if (pspec->name == I_(TERMINAL_PROFILE_NAME)) g_value_set_static_string (value, profile_name); else if (pspec->name == I_(TERMINAL_PROFILE_VISIBLE_NAME)) g_value_set_static_string (value, visible_name); else g_object_get_property (base_object, pspec->name, value); ++n_params; } new_profile = g_object_newv (TERMINAL_TYPE_PROFILE, n_params, params); g_object_unref (base_profile); for (i = 0; i < n_params; ++i) g_value_unset (¶ms[i].value); /* Flush the new profile to GSettings */ new_priv = new_profile->priv; g_slist_free (new_priv->dirty_pspecs); new_priv->dirty_pspecs = NULL; if (new_priv->save_idle_id != 0) { g_source_remove (new_priv->save_idle_id); new_priv->save_idle_id = 0; } for (i = 0; i < n_pspecs; ++i) { GParamSpec *pspec = pspecs[i]; if (pspec->owner_type != TERMINAL_TYPE_PROFILE || (pspec->flags & G_PARAM_WRITABLE) == 0) continue; new_priv->dirty_pspecs = g_slist_prepend (new_priv->dirty_pspecs, pspec); } g_free (pspecs); terminal_profile_save (new_profile); return new_profile; }
/* save the preset with the given name */ static gboolean gst_preset_default_save_preset (GstPreset * preset, const gchar * name) { GKeyFile *presets; gchar **props; guint i; GObjectClass *gclass; GST_INFO_OBJECT (preset, "saving new preset: %s", name); /* get the presets from the type */ if (!(presets = preset_get_keyfile (preset))) goto no_presets; /* take copies of current gobject properties from preset */ if (!(props = gst_preset_get_property_names (preset))) goto no_properties; gclass = G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS (preset)); /* loop over the object properties and store the property value in the * keyfile */ for (i = 0; props[i]; i++) { GValue gvalue = { 0, }; gchar *str; GParamSpec *property; /* FIXME, change for childproxy to get the property and element. */ if (!(property = g_object_class_find_property (gclass, props[i]))) { /* the element said it supported the property but then it does not have * that property. This should not happen. */ GST_WARNING_OBJECT (preset, "property '%s' not in object", props[i]); continue; } g_value_init (&gvalue, property->value_type); /* FIXME, change for childproxy */ g_object_get_property (G_OBJECT (preset), props[i], &gvalue); if ((str = gst_value_serialize (&gvalue))) { g_key_file_set_string (presets, name, props[i], (gpointer) str); g_free (str); } else { GST_WARNING_OBJECT (preset, "serialization for property '%s' failed", props[i]); } g_value_unset (&gvalue); } GST_INFO_OBJECT (preset, " saved"); g_strfreev (props); /* save updated version */ return gst_preset_default_save_presets_file (preset); /* ERRORS */ no_presets: { GST_WARNING_OBJECT (preset, "no presets"); return FALSE; } no_properties: { GST_INFO_OBJECT (preset, "no properties"); return FALSE; } }