From Dirk via bug 6361:
authorstig <stig@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 20 Sep 2011 10:14:58 +0000 (10:14 +0000)
committerstig <stig@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 20 Sep 2011 10:14:58 +0000 (10:14 +0000)
Add a File/Directory Dialog as a field type for UAT preferences.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@39058 f5534014-38df-0310-8fa8-9805f1628bb7

epan/uat.c
epan/uat.h
gtk/uat_gui.c

index 97066e732a3ee0a0a1409fc477a92255cac2d49b..8283ea38f036ce80faeba654e57cdeeccf0e125d 100644 (file)
@@ -208,8 +208,10 @@ static void putfld(FILE* fp, void* rec, uat_field_t* f) {
        f->cb.tostr(rec,&fld_ptr,&fld_len,f->cbdata.tostr,f->fld_data);
 
        switch(f->mode){
-               case  PT_TXTMOD_ENUM:
-               case  PT_TXTMOD_STRING: {
+               case PT_TXTMOD_ENUM:
+               case PT_TXTMOD_FILENAME:
+               case PT_TXTMOD_DIRECTORYNAME:
+               case PT_TXTMOD_STRING: {
                        guint i;
 
                        putc('"',fp);
index 9f19ecbc60ffcf032d09e46871e85da95ab4bd6b..7c4424f361e493005512ca7c3816e147cf9be748 100644 (file)
@@ -182,7 +182,12 @@ typedef enum _uat_text_mode_t {
                 "invalid" as NULL,3
                 "a1b" as NULL, 1
         */
-       PT_TXTMOD_ENUM
+       PT_TXTMOD_ENUM,
+
+       PT_TXTMOD_FILENAME,
+       /* processed like a PT_TXTMOD_STRING, but shows a filename dialog */
+       PT_TXTMOD_DIRECTORYNAME,
+       /* processed like a PT_TXTMOD_STRING, but shows a directory dialog */
 } uat_text_mode_t;
 
 /*
@@ -364,15 +369,24 @@ static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out
        {#field_name, title, PT_TXTMOD_STRING,{ chk ,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
 
 /*
- * PATHNAME - for now, just a CSTRING, but we might want to have a
- * way to pop up a dialog to let you browse for a file name.
+ * FILENAME and DIRECTORYNAME,
+ *    a simple c-string contained in (((rec_t*)rec)->(field_name))
  */
-#define UAT_FLD_PATHNAME(basename,field_name,title,desc) \
-       {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_str,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
+#define UAT_FILENAME_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
+
+#define UAT_FLD_FILENAME(basename,field_name,title,desc) \
+       {#field_name, title, PT_TXTMOD_FILENAME,{uat_fld_chk_str,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
+
+#define UAT_FLD_FILENAME_OTHER(basename,field_name,title,chk,desc) \
+       {#field_name, title, PT_TXTMOD_FILENAME,{chk,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
+
+#define UAT_DIRECTORYNAME_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
+
+#define UAT_FLD_DIRECTORYNAME(basename,field_name,title,desc) \
+       {#field_name, title, PT_TXTMOD_DIRECTORYNAME,{uat_fld_chk_str,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
 
 /*
  * OID - just a CSTRING with a specific check routine 
- *
  */
 #define UAT_FLD_OID(basename,field_name,title,desc) \
        {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_oid,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
index dc6ee7b53e96192b46f8eaefad2d7c4eb753d51a..f315ddad366a662b00f9f214415e3a7b08995478 100644 (file)
@@ -158,6 +158,8 @@ static char* fld_tostr(void* rec, uat_field_t* f) {
        switch(f->mode) {
                case PT_TXTMOD_STRING:
                case PT_TXTMOD_ENUM:
+               case PT_TXTMOD_FILENAME:
+               case PT_TXTMOD_DIRECTORYNAME:
                        out = ep_strndup(ptr,len);
                        break;
                case PT_TXTMOD_HEXBYTES: {
@@ -302,10 +304,22 @@ static gboolean uat_dlg_cb(GtkWidget *win _U_, gpointer user_data) {
 
        for ( colnum = 0; colnum < ncols; colnum++ ) {
                void* e = g_ptr_array_index(dd->entries,colnum);
-               const char* text;
+               const char *text = NULL;
+               char *text_free = NULL;
                unsigned len = 0;
 
                switch(f[colnum].mode) {
+                       case PT_TXTMOD_FILENAME:
+                       case PT_TXTMOD_DIRECTORYNAME:
+                               text = text_free = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(e));
+                               if (text) {
+                                       len = (unsigned) strlen(text);
+                               } else {
+                                       text = "";
+                                       len = 0;
+                               }
+                               break;
+
                        case PT_TXTMOD_STRING:
                                text = gtk_entry_get_text(GTK_ENTRY(e));
                                len = (unsigned) strlen(text);
@@ -333,7 +347,6 @@ static gboolean uat_dlg_cb(GtkWidget *win _U_, gpointer user_data) {
                                return FALSE;
                }
 
-
                if (f[colnum].cb.chk) {
                        if (! f[colnum].cb.chk(dd->rec, text, len, f[colnum].cbdata.chk, f[colnum].fld_data, &err)) {
                                err = ep_strdup_printf("error in column '%s': %s",f[colnum].title,err);
@@ -342,6 +355,8 @@ static gboolean uat_dlg_cb(GtkWidget *win _U_, gpointer user_data) {
                }
 
                f[colnum].cb.set(dd->rec,text,len, f[colnum].cbdata.set, f[colnum].fld_data);
+
+               g_free(text_free);
        }
 
        if (dd->uat->update_cb) {
@@ -477,17 +492,28 @@ static void uat_edit_dialog(uat_t* uat, gint row, gboolean copy) {
                gtk_container_add(GTK_CONTAINER(event_box), label);
 
                switch(f[colnum].mode) {
-                       case PT_TXTMOD_STRING:
-                       case PT_TXTMOD_HEXBYTES: {
-                               entry = gtk_entry_new();
+                       case PT_TXTMOD_FILENAME:
+                       case PT_TXTMOD_DIRECTORYNAME:
+                               entry = gtk_file_chooser_button_new(f[colnum].desc,
+                                                                   (f[colnum].mode == PT_TXTMOD_FILENAME) ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+                               if (! dd->is_new || copy) {
+                                       gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(entry), text);
+                               }
                                g_ptr_array_add(dd->entries,entry);
                                gtk_table_attach_defaults(GTK_TABLE(main_tb), entry, 1, 2, colnum+1, colnum + 2);
+                               break;
+
+                       case PT_TXTMOD_STRING:
+                       case PT_TXTMOD_HEXBYTES:
+                               entry = gtk_entry_new();
                                if (! dd->is_new || copy) {
                                        gtk_entry_set_text(GTK_ENTRY(entry),text);
                                }
+                               g_ptr_array_add(dd->entries,entry);
+                               gtk_table_attach_defaults(GTK_TABLE(main_tb), entry, 1, 2, colnum+1, colnum + 2);
                                dlg_set_activate(entry, bt_ok);
                                break;
-                       }
+
                        case PT_TXTMOD_ENUM: {
                                GtkWidget *combo_box;
                                int idx;