void ghb_dict_set_int(GhbValue *dict, const gchar *key, gint64 ival) { GhbValue *value; value = ghb_int_value_new(ival); ghb_dict_set(dict, key, value); }
static void x264_update_int_setting(signal_user_data_t *ud, const gchar *name, const gchar *val) { gint ival; if (val == NULL) return; ival = g_strtod (val, NULL); ghb_dict_set(ud->x264_priv, name, ghb_int_value_new(ival)); ghb_check_dependency(ud, NULL, name); }
static void start_element( GMarkupParseContext *ctx, const gchar *tag, const gchar **attr_names, const gchar **attr_values, gpointer ud, GError **error) { parse_data_t *pd = (parse_data_t*)ud; union { gint id; gpointer pid; } id; gint ii; // Check to see if the first element found has been closed // If so, ignore any junk following it. if (pd->closed_top) return; for (ii = 0; ii < TAG_MAP_SZ; ii++) { if (strcmp(tag, tag_map[ii].tag) == 0) { id.id = tag_map[ii].id; break; } } if (ii == TAG_MAP_SZ) { g_warning("Unrecognized start tag (%s)", tag); return; } g_queue_push_head(pd->tag_stack, id.pid); GType gtype = 0; GValue *gval = NULL; GValue *current = g_queue_peek_head(pd->stack); switch (id.id) { case R_SECTION: { const gchar *name; name = lookup_attr_value("name", attr_names, attr_values); if (name && strcmp(name, "icons") == 0) { gval = ghb_dict_value_new(); if (pd->key) g_free(pd->key); pd->key = g_strdup(name); g_queue_push_head(pd->stack, gval); } } break; case R_ICON: { gchar *filename; const gchar *name; name = lookup_attr_value("file", attr_names, attr_values); filename = find_file(inc_list, name); name = lookup_attr_value("name", attr_names, attr_values); if (filename && name) { ghb_rawdata_t *rd; GdkPixbuf *pb; GError *err = NULL; pb = gdk_pixbuf_new_from_file(filename, &err); if (pb == NULL) { g_warning("Failed to open icon file %s: %s", filename, err->message); break; } gval = ghb_dict_value_new(); int colorspace = gdk_pixbuf_get_colorspace(pb); gboolean alpha = gdk_pixbuf_get_has_alpha(pb); int width = gdk_pixbuf_get_width(pb); int height = gdk_pixbuf_get_height(pb); int bps = gdk_pixbuf_get_bits_per_sample(pb); int rowstride = gdk_pixbuf_get_rowstride(pb); ghb_dict_insert(gval, g_strdup("colorspace"), ghb_int_value_new(colorspace)); ghb_dict_insert(gval, g_strdup("alpha"), ghb_boolean_value_new(alpha)); ghb_dict_insert(gval, g_strdup("width"), ghb_int_value_new(width)); ghb_dict_insert(gval, g_strdup("height"), ghb_int_value_new(height)); ghb_dict_insert(gval, g_strdup("bps"), ghb_int_value_new(bps)); ghb_dict_insert(gval, g_strdup("rowstride"), ghb_int_value_new(rowstride)); rd = g_malloc(sizeof(ghb_rawdata_t)); rd->data = gdk_pixbuf_get_pixels(pb); rd->size = height * rowstride * bps / 8; GValue *data = ghb_rawdata_value_new(rd); ghb_dict_insert(gval, g_strdup("data"), data); if (pd->key) g_free(pd->key); pd->key = g_strdup(name); g_free(filename); } else { g_warning("%s:missing a requried attribute", name); exit(EXIT_FAILURE); } } break; case R_PLIST: { gchar *filename; const gchar *name; name = lookup_attr_value("file", attr_names, attr_values); filename = find_file(inc_list, name); name = lookup_attr_value("name", attr_names, attr_values); if (filename && name) { gval = ghb_plist_parse_file(filename); if (pd->key) g_free(pd->key); pd->key = g_strdup(name); g_free(filename); } else { g_warning("%s:missing a requried attribute", name); exit(EXIT_FAILURE); } } break; case R_STRING: { gchar *filename; const gchar *name; name = lookup_attr_value("file", attr_names, attr_values); filename = find_file(inc_list, name); name = lookup_attr_value("name", attr_names, attr_values); if (filename && name) { gval = read_string_from_file(filename); if (pd->key) g_free(pd->key); pd->key = g_strdup(name); g_free(filename); } else { g_warning("%s:missing a requried attribute", name); exit(EXIT_FAILURE); } } break; } // Add the element to the current container if (gval) { // There's an element to add if (current == NULL) { pd->plist = gval; return; } gtype = G_VALUE_TYPE(current); if (gtype == ghb_array_get_type()) { ghb_array_append(current, gval); } else if (gtype == ghb_dict_get_type()) { if (pd->key == NULL) { g_warning("No key for dictionary item"); ghb_value_free(gval); } else { ghb_dict_insert(current, g_strdup(pd->key), gval); } } else { g_error("Invalid container type. This shouldn't happen"); } } }
static void end_element( GMarkupParseContext *ctx, const gchar *name, gpointer ud, GError **error) { parse_data_t *pd = (parse_data_t*)ud; gint id; union { gint id; gpointer pid; } start_id; gint ii; // Check to see if the first element found has been closed // If so, ignore any junk following it. if (pd->closed_top) return; for (ii = 0; ii < TAG_MAP_SZ; ii++) { if (strcmp(name, tag_map[ii].tag) == 0) { id = tag_map[ii].id; break; } } if (ii == TAG_MAP_SZ) { g_warning("Unrecognized start tag (%s)", name); return; } start_id.pid = g_queue_pop_head(pd->tag_stack); if (start_id.id != id) g_warning("start tag != end tag: (%s %d) %d", name, id, id); GhbValue *gval = NULL; GhbValue *current = g_queue_peek_head(pd->stack); GhbType gtype = 0; switch (id) { case P_PLIST: { // Ignore } break; case P_KEY: { if (pd->key) g_free(pd->key); pd->key = g_strdup(pd->value); return; } break; case P_DICT: { g_queue_pop_head(pd->stack); } break; case P_ARRAY: { g_queue_pop_head(pd->stack); } break; case P_INTEGER: { gint64 val = g_strtod(pd->value, NULL); gval = ghb_int_value_new(val); } break; case P_REAL: { gdouble val = g_strtod(pd->value, NULL); gval = ghb_double_value_new(val); } break; case P_STRING: { gval = ghb_string_value_new(pd->value); } break; case P_TRUE: { gval = ghb_bool_value_new(TRUE); } break; case P_FALSE: { gval = ghb_bool_value_new(FALSE); } break; default: { g_message("Unhandled plist type %d", id); } break; } if (gval) { // Get the top of the data structure stack and if it's an array // or dict, add the current element if (current == NULL) { pd->plist = gval; pd->closed_top = TRUE; return; } gtype = ghb_value_type(current); if (gtype == GHB_ARRAY) { ghb_array_append(current, gval); } else if (gtype == GHB_DICT) { if (pd->key == NULL) { g_warning("No key for dictionary item"); ghb_value_free(&gval); } else { ghb_dict_set(current, pd->key, gval); } } else { g_error("Invalid container type. This shouldn't happen"); } } if (g_queue_is_empty(pd->stack)) pd->closed_top = TRUE; }
GValue* ghb_widget_value(GtkWidget *widget) { GValue *value = NULL; const gchar *name; GType type; if (widget == NULL) { g_debug("NULL widget\n"); return NULL; } type = G_OBJECT_TYPE(widget); name = ghb_get_setting_key(widget); g_debug("ghb_widget_value widget (%s)\n", name); if (type == GTK_TYPE_ENTRY) { const gchar *str = gtk_entry_get_text(GTK_ENTRY(widget)); value = ghb_string_value_new(str); } else if (type == GTK_TYPE_RADIO_BUTTON) { g_debug("\tradio_button"); gboolean bval; bval = gtk_toggle_button_get_inconsistent(GTK_TOGGLE_BUTTON(widget)); if (bval) { value = ghb_boolean_value_new(FALSE); } else { bval = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); value = ghb_boolean_value_new(bval); } } else if (type == GTK_TYPE_CHECK_BUTTON) { g_debug("\tcheck_button"); gboolean bval; bval = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); value = ghb_boolean_value_new(bval); } else if (type == GTK_TYPE_TOGGLE_TOOL_BUTTON) { g_debug("\ttoggle_tool_button"); gboolean bval; bval = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget)); value = ghb_boolean_value_new(bval); } else if (type == GTK_TYPE_TOGGLE_BUTTON) { g_debug("\ttoggle_button"); gboolean bval; bval = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); value = ghb_boolean_value_new(bval); } else if (type == GTK_TYPE_CHECK_MENU_ITEM) { g_debug("\tcheck_menu_item"); gboolean bval; bval = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); value = ghb_boolean_value_new(bval); } else if (type == GTK_TYPE_COMBO_BOX) { g_debug("\tcombo_box"); GtkTreeModel *store; GtkTreeIter iter; gchar *shortOpt; store = gtk_combo_box_get_model(GTK_COMBO_BOX(widget)); if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter)) { gtk_tree_model_get(store, &iter, 2, &shortOpt, -1); value = ghb_string_value_new(shortOpt); g_free(shortOpt); } else if (gtk_combo_box_get_has_entry(GTK_COMBO_BOX(widget))) { const gchar *str; str = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(widget)))); if (str == NULL) str = ""; value = ghb_string_value_new(str); } else { value = ghb_string_value_new(""); } } else if (type == GTK_TYPE_SPIN_BUTTON) { gint ival; ival = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); value = ghb_int64_value_new(ival); } else if (type == GTK_TYPE_SCALE) { gdouble dval; gint digits; digits = gtk_scale_get_digits(GTK_SCALE(widget)); dval = gtk_range_get_value(GTK_RANGE(widget)); if (digits) { value = ghb_double_value_new(dval); } else { value = ghb_int_value_new(dval); } } else if (type == GTK_TYPE_SCALE_BUTTON) { gdouble dval; dval = gtk_scale_button_get_value(GTK_SCALE_BUTTON(widget)); value = ghb_double_value_new(dval); } else if (type == GTK_TYPE_TEXT_VIEW) { GtkTextBuffer *buffer; GtkTextIter start, end; gchar *str; buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget)); gtk_text_buffer_get_bounds(buffer, &start, &end); str = gtk_text_buffer_get_text(buffer, &start, &end, FALSE); value = ghb_string_value_new(str); g_free(str); } else if (type == GTK_TYPE_LABEL) { const gchar *str; str = gtk_label_get_text (GTK_LABEL(widget)); value = ghb_string_value_new(str); } else if (type == GTK_TYPE_FILE_CHOOSER_BUTTON) { gchar *str = NULL; str = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(widget)); if (str == NULL) { str = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(widget)); } value = ghb_string_value_new(str); if (str != NULL) g_free(str); } else { g_debug("Attempt to set unknown widget type: %s\n", name); g_free(value); value = NULL; } return value; }