This is our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

I am trying to create a new preference under Edit -> Preferences -> User Interface. I can create the text field, but when I fill it with text nothing else happens. When I click apply or ok, and reopen the window, the text is gone. When I grep through the .wireshark/preferences file, I don't see the value I entered.

I have made the following changes to ui/gtk/prefs_gui.c

 #define GUI_MYTEST_DIR_KEY     "path_directory"
...
 GtkWidget *my_test_path_te;
...
    /* Testing my text edit preference */
    my_test_path_te = create_preference_entry(main_grid, pos++,
        "My Test Path:",
        "The Location of something I want.",
        prefs.mypath_dir); //created this variable in prefs.h
    g_object_set_data(G_OBJECT(main_vb), GUI_MYTEST_DIR_KEY, my_test_path_te);
...
    prefs.mypath_dir = g_strdup(gtk_entry_get_text(
          GTK_ENTRY(g_object_get_data(G_OBJECT(w), GUI_MYTEST_DIR_KEY))));

Did I miss something with what I tried? My ultimate goal is to have the new preference pass in a string that will be sent to a few different dissectors.

asked 24 Nov '15, 11:31

0xbismarck's gravatar image

0xbismarck
6225
accept rate: 100%


Had to play with the code a while, but I finally figured it out.

Here is the list of changes I had to make to get it to write to file and show up in the GUI.

epan/prefs.h in e_prefs add:

  gchar       *mypath_dir;

epan/prefs.c

prefs_register_directory_preference(gui_module, "mytest.dir", "New Test",
        "This test better work", (const char **)&prefs.mypath_dir);

ui/gtk/pref_gui.c

static gboolean mytest_changed_cb(GtkWidget *myentry _U_, GdkEvent *event _U_, gpointer parent_w);
...
#define GUI_MYTEST_DIR_KEY      "path_directory"
...

within gui_prefs_show() GtkWidget *my_test_path_te;

...
    my_test_path_te = create_preference_entry(main_grid, pos++,
        "My Test Path:",
        "The Location of something I want.",
        prefs.mypath_dir);
    g_object_set_data(G_OBJECT(main_vb), GUI_MYTEST_DIR_KEY, my_test_path_te);
    g_signal_connect(my_test_path_te, "focus_out_event", G_CALLBACK(mytest_changed_cb), main_vb);
    printf("my new function", prefs.mypath_dir);

within gui_prefs_fetch():

prefs.mypath_dir = g_strdup(gtk_entry_get_text(
              GTK_ENTRY(g_object_get_data(G_OBJECT(w), GUI_MYTEST_DIR_KEY))));

static gboolean
mytest_changed_cb(GtkWidget *recent_files_entry _U_,
          GdkEvent *event _U_, gpointer parent_w)
{
    GtkWidget   *recent_files_count_te;
    gchar * newval;

    recent_files_count_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), GUI_MYTEST_DIR_KEY);

    strlen(gtk_entry_get_text (GTK_ENTRY(recent_files_count_te)));
    newval = gtk_entry_get_text (GTK_ENTRY(recent_files_count_te));

    prefs.mypath_dir = newval;

    return FALSE;
}
permanent link

answered 25 Nov '15, 14:56

0xbismarck's gravatar image

0xbismarck
6225
accept rate: 100%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×158
×39
×25

question asked: 24 Nov '15, 11:31

question was seen: 750 times

last updated: 25 Nov '15, 14:56

p​o​w​e​r​e​d by O​S​Q​A