void ghb_settings_set_int(GValue *settings, const gchar *key, gint ival) { GValue *value; value = ghb_int64_value_new((gint64)ival); ghb_dict_insert(settings, g_strdup(key), value); }
void ghb_settings_set_boolean(GValue *settings, const gchar *key, gboolean bval) { GValue *value; value = ghb_boolean_value_new(bval); ghb_dict_insert(settings, g_strdup(key), value); }
void ghb_settings_set_double(GValue *settings, const gchar *key, gdouble dval) { GValue *value; value = ghb_double_value_new(dval); ghb_dict_insert(settings, g_strdup(key), value); }
void ghb_settings_set_string( GValue *settings, const gchar *key, const gchar *sval) { GValue *value; value = ghb_string_value_new(sval); ghb_dict_insert(settings, g_strdup(key), value); }
void ghb_settings_set_value( GValue *settings, const gchar *key, const GValue *value) { if (key == NULL || value == NULL) return; ghb_dict_insert(settings, g_strdup(key), ghb_value_dup(value)); }
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); GValue *gval = NULL; GValue *current = g_queue_peek_head(pd->stack); GType gtype = 0; switch (id) { case R_SECTION: { g_queue_pop_head(pd->stack); } 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 = 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"); } } if (g_queue_is_empty(pd->tag_stack)) pd->closed_top = TRUE; }
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 start_element( GMarkupParseContext *ctx, const gchar *name, 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(name, tag_map[ii].tag) == 0) { id.id = tag_map[ii].id; break; } } if (ii == TAG_MAP_SZ) { g_warning("Unrecognized start tag (%s)", name); 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 P_PLIST: { // Ignore } break; case P_KEY: { if (pd->key) g_free(pd->key); pd->key = NULL; } break; case P_DICT: { gval = ghb_dict_value_new(); g_queue_push_head(pd->stack, gval); } break; case P_ARRAY: { gval = ghb_array_value_new(128); g_queue_push_head(pd->stack, gval); } break; case P_INTEGER: { } break; case P_REAL: { } break; case P_STRING: { } break; case P_DATE: { } break; case P_TRUE: { } break; case P_FALSE: { } break; case P_DATA: { } 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); GValue *gval = NULL; GValue *current = g_queue_peek_head(pd->stack); GType 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_int64_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_DATE: { GDate date; GTimeVal time; g_time_val_from_iso8601(pd->value, &time); g_date_set_time_val(&date, &time); gval = ghb_date_value_new(&date); } break; case P_TRUE: { gval = ghb_boolean_value_new(TRUE); } break; case P_FALSE: { gval = ghb_boolean_value_new(FALSE); } break; case P_DATA: { ghb_rawdata_t *data; data = g_malloc(sizeof(ghb_rawdata_t)); data->data = g_base64_decode(pd->value, &(data->size)); gval = ghb_rawdata_value_new(data); } 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 = 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"); } } if (g_queue_is_empty(pd->stack)) pd->closed_top = TRUE; }
void ghb_settings_take_value(GValue *settings, const gchar *key, GValue *value) { ghb_dict_insert(settings, g_strdup(key), value); }
int main(gint argc, gchar *argv[]) { gint ii, jj; GValue *top; gint count = sizeof(dep_map) / sizeof(dependency_t); g_type_init(); top = ghb_dict_value_new(); for (ii = 0; ii < count; ii++) { const gchar *name; GValue *array; name = dep_map[ii].widget_name; if (ghb_dict_lookup(top, name)) continue; array = ghb_array_value_new(8); for (jj = 0; jj < count; jj++) { if (strcmp(name, dep_map[jj].widget_name) == 0) { ghb_array_append(array, ghb_value_dup(ghb_string_value(dep_map[jj].dep_name))); } } ghb_dict_insert(top, g_strdup(name), array); } ghb_plist_write_file("widget.deps", top); // reverse map top = ghb_dict_value_new(); for (ii = 0; ii < count; ii++) { const gchar *name; GValue *array; name = dep_map[ii].dep_name; if (ghb_dict_lookup(top, name)) continue; array = ghb_array_value_new(8); for (jj = 0; jj < count; jj++) { if (strcmp(name, dep_map[jj].dep_name) == 0) { GValue *data; data = ghb_array_value_new(3); ghb_array_append(data, ghb_value_dup( ghb_string_value(dep_map[jj].widget_name))); ghb_array_append(data, ghb_value_dup( ghb_string_value(dep_map[jj].enable_value))); ghb_array_append(data, ghb_value_dup( ghb_boolean_value(dep_map[jj].disable_if_equal))); ghb_array_append(data, ghb_value_dup( ghb_boolean_value(dep_map[jj].hide))); ghb_array_append(array, data); } } ghb_dict_insert(top, g_strdup(name), array); } ghb_plist_write_file("widget_reverse.deps", top); return 0; }