GtkBuilder* create_builder_or_die(const gchar * name) { guint res = 0; GValue *gval; GError *error = NULL; const gchar *ghb_ui; const gchar *markup = N_("<b><big>Unable to create %s.</big></b>\n" "\n" "Internal error. Could not parse UI description.\n" "%s"); g_debug("create_builder_or_die ()\n"); GtkBuilder *xml = gtk_builder_new(); gval = ghb_resource_get("ghb-ui"); ghb_ui = g_value_get_string(gval); if (xml != NULL) res = gtk_builder_add_from_string(xml, ghb_ui, -1, &error); if (!xml || !res) { GtkWidget *dialog = gtk_message_dialog_new_with_markup(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _(markup), name, error->message); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); exit(EXIT_FAILURE); } return xml; }
void ghb_load_icons() { GHashTableIter iter; gchar *key; GValue *gval; GValue *icons = ghb_resource_get("icons"); ghb_dict_iter_init(&iter, icons); // middle (void*) cast prevents gcc warning "defreferencing type-punned // pointer will break strict-aliasing rules" while (g_hash_table_iter_next( &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval)) { ghb_rawdata_t *rd; gint size; GdkPixbuf *pb; gboolean svg; char *name = g_strdup(key); char *pos; pos = g_strstr_len(name, -1, "."); if (pos != NULL) *pos = '\0'; GInputStream *gis; svg = ghb_value_boolean(ghb_dict_lookup(gval, "svg")); rd = g_value_get_boxed(ghb_dict_lookup(gval, "data")); if (svg) { int ii; int sizes[] = {16, 22, 24, 32, 48, 64, 128, 256, 0}; for (ii = 0; sizes[ii]; ii++) { gis = g_memory_input_stream_new_from_data(rd->data, rd->size, NULL); pb = gdk_pixbuf_new_from_stream_at_scale(gis, sizes[ii], sizes[ii], TRUE, NULL, NULL); g_input_stream_close(gis, NULL, NULL); size = gdk_pixbuf_get_height(pb); gtk_icon_theme_add_builtin_icon(name, size, pb); g_object_unref(pb); } } else { gis = g_memory_input_stream_new_from_data(rd->data, rd->size, NULL); pb = gdk_pixbuf_new_from_stream(gis, NULL, NULL); g_input_stream_close(gis, NULL, NULL); size = gdk_pixbuf_get_height(pb); gtk_icon_theme_add_builtin_icon(name, size, pb); g_object_unref(pb); } g_free(name); } }
void ghb_load_icons() { GHashTableIter iter; gchar *key; GValue *gval; GValue *icons = ghb_resource_get("icons"); ghb_dict_iter_init(&iter, icons); // middle (void*) cast prevents gcc warning "defreferencing type-punned // pointer will break strict-aliasing rules" while (g_hash_table_iter_next( &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval)) { gint colorspace, bps, width, height, rowstride; gboolean alpha; ghb_rawdata_t *rd; gint size; GdkPixbuf *pb; char *name = g_strdup(key); char *pos; pos = g_strstr_len(name, -1, "."); if (pos != NULL) *pos = '\0'; colorspace = ghb_value_int(ghb_dict_lookup(gval, "colorspace")); alpha = ghb_value_boolean(ghb_dict_lookup(gval, "alpha")); bps = ghb_value_int(ghb_dict_lookup(gval, "bps")); width = ghb_value_int(ghb_dict_lookup(gval, "width")); height = ghb_value_int(ghb_dict_lookup(gval, "height")); rowstride = ghb_value_int(ghb_dict_lookup(gval, "rowstride")); rd = g_value_get_boxed(ghb_dict_lookup(gval, "data")); pb = gdk_pixbuf_new_from_data( rd->data, colorspace, alpha, bps, width, height, rowstride, NULL, NULL); size = gdk_pixbuf_get_height(pb); gtk_icon_theme_add_builtin_icon(name, size, pb); g_object_unref(pb); g_free(name); } }