Re: How to keep UTF-8 characters, but escape non-UTF-8 byte sequence to hex codes in ASCII



On Mon, 2006-12-04 at 18:22 -0800, Daniel Yek wrote:

At 07:29 AM 12/1/2006, Peter Lund wrote:
On Thu, 2006-11-30 at 15:46 -0800, Daniel Yek wrote:

Well, with g_utf8_validate(), it is trivial to implement a function that
escape non-UTF-8 bytes to Hex. However, I then found out that TreeView, or
more likely Pango, would unescape the %xx sequence (undo my attempt to 
help
it) and choke!??!

What if you double the percent signs?

Was it supposed to work? I tried, it didn't work.


I just made a test (a simple modification of a program I'm hacking on).

Inserting strings like "abcÃÃ%F3ÃÃ" into a GtkTreeStore works fine.
GtkTreeView displays them precisely as expected.

(In other words, "escaping" the %-sign with another %-sign is completely
unnecessary.)

I think something is going wrong at your end, unfortunately :(

Here's how I create the view:

I read the GtkTreeView from a Glade XML file

        tree = GTK_TREE_VIEW(glade_xml_get_widget(ui, "signals"));
        gtk_tree_view_set_rules_hint(tree, TRUE);


The first column contains a toggle field, which I currently don't need


        /* stupid silly toggle field */
        renderer = gtk_cell_renderer_toggle_new();
        g_signal_connect(renderer, "toggled",
                         G_CALLBACK(on_selected_field_toggled),
                         tree);
        col = gtk_tree_view_column_new_with_attributes("Sel?", renderer,
                                "active", SELECTED_FIELD,
                                NULL);
        gtk_tree_view_append_column(tree, col);

This is the column with the string that I'm going to use for my test

        /* name */
        col = gtk_tree_view_column_new();
        gtk_tree_view_column_set_title(col, "Name");

        renderer = gtk_cell_renderer_text_new();
        g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_START, NULL);
        gtk_tree_view_column_pack_start(col, renderer, TRUE);
        gtk_tree_view_column_set_attributes(col, renderer,
                                "text", NAME_FIELD, NULL);

        gtk_tree_view_column_set_expand(col, TRUE);
        gtk_tree_view_column_set_resizable(col, TRUE);
        gtk_tree_view_append_column(tree, col);

Make the string field searchable

        gtk_tree_view_set_enable_search(tree, TRUE);
        gtk_tree_view_set_search_column(tree, NAME_FIELD);
        gtk_tree_view_set_search_equal_func(tree, tree_search_equal_func, NULL, NULL);
        g_signal_connect(tree, "key-press-event", G_CALLBACK(signals_key_press), NULL);



Here's how I create the store:


        store = gtk_tree_store_new(N_FIELDS,
                                   G_TYPE_INT,          /* NO       */
                                   G_TYPE_STRING,       /* SIGNAME  */
                                   G_TYPE_BOOLEAN);     /* SELECTED */

        gtk_tree_view_set_model(tree, GTK_TREE_MODEL(store));
        /* set the search column again - it gets reset to 0 every time we set
         * a new store.
         */
        gtk_tree_view_set_search_column(tree, NAME_FIELD);




Here's how I put stuff into the store:


        gtk_tree_store_clear(store);

        for (i=0; i < 10; i++) {
                GtkTreeIter              iter;

                gtk_tree_store_append(store, &iter, NULL);
                gtk_tree_store_set(store, &iter,
                          NO_FIELD      , i,
                          NAME_FIELD    , "abcÃÃ%F3def",
                          SELECTED_FIELD, FALSE,
                          -1);
        }



-Peter



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]