static gint ambiguous_cmp (const ambiguous_type *a, const ambiguous_type *b, GncXmlImportData *data) { const gchar *string_a = get_decoded_string (a, data->default_encoding); const gchar *string_b = get_decoded_string (b, data->default_encoding); if (string_a) { if (string_b) { /* both look good, usual compare */ return strcmp (string_a, string_b); } else { /* a look good, b not. put b to the top */ return 1; } } else { if (string_b) { /* b looks good, a not. put a to the top */ return -1; } else { /* both look suboptimal, see whether one has a decision attached to it */ conv_type *conv_a = g_hash_table_lookup (data->choices, a->byte_sequence); conv_type *conv_b = g_hash_table_lookup (data->choices, b->byte_sequence); if (conv_a && !conv_b) return 1; if (conv_b && !conv_a) return -1; return strcmp (a->byte_sequence, b->byte_sequence); } } }
void create_image_metadata_stylesheet_file(const std::string& main_filename) { std::string path; std::string::size_type pos = main_filename.find_last_of("/\\"); if (pos != std::string::npos) path = main_filename.substr(0,pos+1); std::ofstream fout((path + "image_metadata_stylesheet.xsl").c_str()); if (!fout) throw dlib::error("ERROR: Unable to open image_metadata_stylesheet.xsl for writing."); fout << get_decoded_string(); if (!fout) throw dlib::error("ERROR: Unable to write to image_metadata_stylesheet.xsl."); }
static void gxi_update_string_box (GncXmlImportData *data) { gchar *string; const gchar *utf8; GtkBox *vbox; GtkComboBox *combo; GtkListStore *store; GList *word_iter, *conv_iter; GtkCellRenderer *renderer; GtkTreeIter iter; GQuark chosen_encoding; GtkTreeIter *chosen_iter, *default_iter; ambiguous_type *amb; conv_type *conv; if (data->string_box) gtk_widget_destroy (data->string_box); data->string_box = gtk_vbox_new (FALSE, 6); vbox = GTK_BOX (data->string_box); data->n_unassigned = 0; /* loop through words */ for (word_iter = data->ambiguous_list; word_iter; word_iter = word_iter->next) { store = gtk_list_store_new (WORD_NUM_COLS, G_TYPE_STRING, G_TYPE_POINTER); combo = GTK_COMBO_BOX (gtk_combo_box_new_with_model ( GTK_TREE_MODEL (store))); g_object_unref (store); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, "text", WORD_COL_STRING, NULL); /* add default string, if possible */ amb = (ambiguous_type*) word_iter->data; utf8 = get_decoded_string (amb, data->default_encoding); default_iter = NULL; if (utf8) { string = g_strdup_printf ("%s (default)", utf8); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, WORD_COL_STRING, string, WORD_COL_ENCODING, GUINT_TO_POINTER (data->default_encoding), -1); g_free (string); default_iter = gtk_tree_iter_copy (&iter); } /* user has selected this previously */ conv = (conv_type*) g_hash_table_lookup (data->choices, amb->byte_sequence); chosen_encoding = (conv) ? conv->encoding : 0; chosen_iter = NULL; /* loop through conversions */ for (conv_iter = amb->conv_list; conv_iter; conv_iter = conv_iter->next) { conv = (conv_type*) conv_iter->data; string = g_strdup_printf ("%s (%s)", conv->utf8_string, g_quark_to_string (conv->encoding)); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, WORD_COL_STRING, string, WORD_COL_ENCODING, GUINT_TO_POINTER (conv->encoding), -1); g_free (string); if (chosen_encoding && conv->encoding == chosen_encoding) { chosen_iter = gtk_tree_iter_copy (&iter); } } /* next conversion */ if (chosen_iter) { /* select previous selection again, are not we cute */ gtk_combo_box_set_active_iter (combo, chosen_iter); gtk_tree_iter_free (chosen_iter); } else { if (default_iter) { /* select default entry */ gtk_combo_box_set_active_iter (combo, default_iter); } else { /* count it */ data->n_unassigned++; } } /* wire up combo */ g_object_set_data (G_OBJECT (combo), "ambiguous", amb); g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (gxi_string_combo_changed_cb), data); gtk_box_pack_start (vbox, GTK_WIDGET (combo), FALSE, FALSE, 0); gtk_widget_show (GTK_WIDGET (combo)); } /* next word */ /* wire up whole string vbox */ gtk_container_add (GTK_CONTAINER (data->string_box_container), GTK_WIDGET (vbox)); gtk_widget_show (GTK_WIDGET (vbox)); /* update label now, n_unassigned is calculated */ if (!data->summary_label) data->summary_label = data->impossible_label; gxi_update_summary_label (data); }