2007-01-29 10:25:54 +00:00
|
|
|
/*
|
|
|
|
* uat_gui.c
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* User Accessible Tables GUI
|
|
|
|
* Mantain an array of user accessible data strucures
|
|
|
|
*
|
|
|
|
* (c) 2007, Luis E. Garcia Ontanon <luis.ontanon@gmail.com>
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 2001 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2007-02-07 03:39:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TO DO:
|
|
|
|
* + improvements
|
|
|
|
* - field value check (red/green editbox)
|
|
|
|
* - tooltips (add field descriptions)
|
|
|
|
*/
|
|
|
|
|
2007-01-29 10:25:54 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <epan/dfilter/dfilter-macro.h>
|
2007-01-29 14:14:01 +00:00
|
|
|
#include <epan/emem.h>
|
|
|
|
#include <epan/report_err.h>
|
2007-02-05 04:22:06 +00:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
#include "gtkglobals.h"
|
2007-01-29 10:25:54 +00:00
|
|
|
#include "gui_utils.h"
|
2007-02-05 04:22:06 +00:00
|
|
|
#include "dlg_utils.h"
|
2007-02-05 05:06:21 +00:00
|
|
|
#include "help_dlg.h"
|
2007-02-09 03:11:14 +00:00
|
|
|
#include "menu.h"
|
2007-01-29 10:25:54 +00:00
|
|
|
#include "compat_macros.h"
|
2007-02-09 03:11:14 +00:00
|
|
|
#include <epan/proto.h>
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include "../stat_menu.h"
|
|
|
|
#include "gui_stat_menu.h"
|
2007-02-11 16:09:21 +00:00
|
|
|
#include "main.h"
|
2007-01-29 10:25:54 +00:00
|
|
|
|
|
|
|
#include <epan/uat-int.h>
|
2007-02-07 03:39:40 +00:00
|
|
|
#include <epan/value_string.h>
|
2007-01-29 10:25:54 +00:00
|
|
|
#include "uat_gui.h"
|
|
|
|
|
|
|
|
#if GTK_MAJOR_VERSION >= 2
|
|
|
|
# undef GTK_MAJOR_VERSION
|
|
|
|
# define GTK_MAJOR_VERSION 1
|
|
|
|
# define BUTTON_SIZE_X -1
|
|
|
|
# define BUTTON_SIZE_Y -1
|
|
|
|
#else
|
|
|
|
# define BUTTON_SIZE_X 50
|
|
|
|
# define BUTTON_SIZE_Y 20
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct _uat_rep_t {
|
|
|
|
GtkWidget* window;
|
|
|
|
GtkWidget* vbox;
|
2008-01-19 07:46:52 +00:00
|
|
|
GtkWidget* scrolledwindow;
|
|
|
|
GtkWidget* clist;
|
2007-01-29 10:25:54 +00:00
|
|
|
GtkWidget* bbox;
|
|
|
|
GtkWidget* bt_new;
|
|
|
|
GtkWidget* bt_edit;
|
|
|
|
GtkWidget* bt_delete;
|
2007-02-04 05:19:02 +00:00
|
|
|
GtkWidget* bt_up;
|
|
|
|
GtkWidget* bt_down;
|
2007-02-11 16:09:21 +00:00
|
|
|
GtkWidget* bt_apply;
|
|
|
|
GtkWidget* bt_cancel;
|
|
|
|
GtkWidget* bt_ok;
|
2007-02-05 04:22:06 +00:00
|
|
|
GtkWidget* unsaved_window;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 10:25:54 +00:00
|
|
|
gint selected;
|
2007-02-05 04:22:06 +00:00
|
|
|
gboolean dont_save;
|
2007-01-29 10:25:54 +00:00
|
|
|
#if GTK_MAJOR_VERSION >= 2
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-01-29 14:14:01 +00:00
|
|
|
struct _str_pair {
|
|
|
|
const char* ptr;
|
|
|
|
unsigned len;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _uat_dlg_data {
|
2008-01-19 07:46:52 +00:00
|
|
|
GtkWidget* win;
|
|
|
|
GPtrArray* entries;
|
2007-01-29 14:14:01 +00:00
|
|
|
uat_t* uat;
|
|
|
|
void* rec;
|
|
|
|
gboolean is_new;
|
|
|
|
gint row;
|
2007-02-07 03:39:40 +00:00
|
|
|
GPtrArray* tobe_freed;
|
2007-01-29 14:14:01 +00:00
|
|
|
};
|
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
|
|
|
|
static gboolean unsaved_dialog(GtkWindow *w, GdkEvent* e, gpointer u);
|
|
|
|
static gboolean uat_window_delete_event_cb(GtkWindow *w, GdkEvent* e, gpointer u);
|
|
|
|
|
|
|
|
static void set_buttons(uat_t* uat, gint row) {
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-03-04 02:27:11 +00:00
|
|
|
if (!uat->rep) return;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
if (row > 0) {
|
|
|
|
gtk_widget_set_sensitive (uat->rep->bt_up, TRUE);
|
|
|
|
} else {
|
|
|
|
gtk_widget_set_sensitive (uat->rep->bt_up, FALSE);
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
if (row < (gint)(*uat->nrows_p - 1) && row >= 0) {
|
|
|
|
gtk_widget_set_sensitive (uat->rep->bt_down, TRUE);
|
|
|
|
} else {
|
|
|
|
gtk_widget_set_sensitive (uat->rep->bt_down, FALSE);
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
if (uat->changed) {
|
|
|
|
SIGNAL_DISCONNECT_BY_FUNC(uat->rep->window, uat_window_delete_event_cb, uat);
|
|
|
|
SIGNAL_CONNECT(uat->rep->window, "delete_event", unsaved_dialog, uat);
|
|
|
|
SIGNAL_CONNECT(uat->rep->window, "destroy", unsaved_dialog, uat);
|
|
|
|
} else {
|
|
|
|
SIGNAL_DISCONNECT_BY_FUNC(uat->rep->window, unsaved_dialog, uat);
|
|
|
|
SIGNAL_CONNECT(GTK_WINDOW(uat->rep->window), "delete_event", uat_window_delete_event_cb, uat);
|
|
|
|
SIGNAL_CONNECT(GTK_WINDOW(uat->rep->window), "destroy", uat_window_delete_event_cb, uat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
static char* fld_tostr(void* rec, uat_field_t* f) {
|
|
|
|
guint len;
|
2007-04-23 10:59:26 +00:00
|
|
|
const char* ptr;
|
2007-02-07 03:39:40 +00:00
|
|
|
char* out;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
f->cb.tostr(rec,&ptr,&len,f->cbdata.tostr,f->fld_data);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
switch(f->mode) {
|
|
|
|
case PT_TXTMOD_STRING:
|
|
|
|
case PT_TXTMOD_ENUM:
|
|
|
|
out = ep_strndup(ptr,len);
|
|
|
|
break;
|
|
|
|
case PT_TXTMOD_HEXBYTES: {
|
|
|
|
GString* s = g_string_sized_new( len*2 + 1 );
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i=0; i<len;i++) g_string_sprintfa(s,"%.2X",((guint8*)ptr)[i]);
|
|
|
|
|
|
|
|
out = ep_strdup_printf(s->str);
|
|
|
|
|
|
|
|
g_string_free(s,TRUE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2007-02-19 01:21:10 +00:00
|
|
|
out = NULL;
|
2007-02-07 03:39:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-01-29 14:14:01 +00:00
|
|
|
static void append_row(uat_t* uat, guint idx) {
|
|
|
|
GPtrArray* a = g_ptr_array_new();
|
|
|
|
void* rec = UAT_INDEX_PTR(uat,idx);
|
2007-02-03 14:25:02 +00:00
|
|
|
uat_field_t* f = uat->fields;
|
2007-01-29 14:14:01 +00:00
|
|
|
guint rownum;
|
2007-02-03 14:25:02 +00:00
|
|
|
guint colnum;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-03-04 02:27:11 +00:00
|
|
|
if (! uat->rep) return;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 14:14:01 +00:00
|
|
|
gtk_clist_freeze(GTK_CLIST(uat->rep->clist));
|
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
for ( colnum = 0; colnum < uat->ncols; colnum++ )
|
|
|
|
g_ptr_array_add(a,fld_tostr(rec,&(f[colnum])));
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 14:14:01 +00:00
|
|
|
rownum = gtk_clist_append(GTK_CLIST(uat->rep->clist), (gchar**)a->pdata);
|
|
|
|
gtk_clist_set_row_data(GTK_CLIST(uat->rep->clist), rownum, rec);
|
|
|
|
|
|
|
|
gtk_clist_thaw(GTK_CLIST(uat->rep->clist));
|
|
|
|
|
|
|
|
g_ptr_array_free(a,TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reset_row(uat_t* uat, guint idx) {
|
|
|
|
void* rec = UAT_INDEX_PTR(uat,idx);
|
2007-02-03 14:25:02 +00:00
|
|
|
uat_field_t* f = uat->fields;
|
|
|
|
guint colnum;
|
2007-03-04 02:27:11 +00:00
|
|
|
|
|
|
|
if (! uat->rep) return;
|
|
|
|
|
2007-01-29 14:14:01 +00:00
|
|
|
gtk_clist_freeze(GTK_CLIST(uat->rep->clist));
|
2007-02-03 14:25:02 +00:00
|
|
|
|
|
|
|
for ( colnum = 0; colnum < uat->ncols; colnum++ ) {
|
2007-02-07 03:39:40 +00:00
|
|
|
gtk_clist_set_text(GTK_CLIST(uat->rep->clist), idx, colnum, fld_tostr(rec,&(f[colnum])));
|
2007-01-29 14:14:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_clist_thaw(GTK_CLIST(uat->rep->clist));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-04-23 10:59:26 +00:00
|
|
|
static guint8* unhexbytes(const char* si, guint len, guint* len_p, const char** err) {
|
2007-02-07 03:39:40 +00:00
|
|
|
guint8* buf;
|
|
|
|
guint8* p;
|
|
|
|
const guint8* s = (void*)si;
|
|
|
|
unsigned i;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
if (len % 2) {
|
|
|
|
*err = "Uneven number of chars hex string";
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
buf = ep_alloc(len/2+1);
|
|
|
|
p = buf;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
for (i = 0; i<len ; i += 2) {
|
|
|
|
guint8 lo = s[i+1];
|
|
|
|
guint8 hi = s[i];
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
if (hi >= '0' && hi <= '9') {
|
|
|
|
hi -= '0';
|
|
|
|
} else if (hi >= 'a' && hi <= 'f') {
|
|
|
|
hi -= 'a';
|
|
|
|
hi += 0xa;
|
|
|
|
} else if (hi >= 'A' && hi <= 'F') {
|
|
|
|
hi -= 'A';
|
|
|
|
hi += 0xa;
|
|
|
|
} else {
|
|
|
|
goto on_error;
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
if (lo >= '0' && lo <= '9') {
|
|
|
|
lo -= '0';
|
|
|
|
} else if (lo >= 'a' && lo <= 'f') {
|
|
|
|
lo -= 'a';
|
|
|
|
lo += 0xa;
|
|
|
|
} else if (lo >= 'A' && lo <= 'F') {
|
|
|
|
lo -= 'A';
|
|
|
|
lo += 0xa;
|
|
|
|
} else {
|
|
|
|
goto on_error;
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
*(p++) = (hi*0x10) + lo;
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
len /= 2;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
if (len_p) *len_p = len;
|
|
|
|
|
|
|
|
buf[len] = '\0';
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
*err = NULL;
|
|
|
|
return buf;
|
|
|
|
|
|
|
|
on_error:
|
|
|
|
*err = "Error parsing hex string";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-01-29 14:14:01 +00:00
|
|
|
|
|
|
|
static gboolean uat_dlg_cb(GtkWidget *win _U_, gpointer user_data) {
|
|
|
|
struct _uat_dlg_data* dd = user_data;
|
2007-02-03 14:25:02 +00:00
|
|
|
guint ncols = dd->uat->ncols;
|
|
|
|
uat_field_t* f = dd->uat->fields;
|
2007-04-23 10:59:26 +00:00
|
|
|
const char* err = NULL;
|
2007-02-03 14:25:02 +00:00
|
|
|
guint colnum;
|
|
|
|
|
|
|
|
for ( colnum = 0; colnum < ncols; colnum++ ) {
|
2007-02-07 03:39:40 +00:00
|
|
|
void* e = g_ptr_array_index(dd->entries,colnum);
|
|
|
|
const char* text;
|
|
|
|
unsigned len = 0;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
switch(f[colnum].mode) {
|
|
|
|
case PT_TXTMOD_STRING:
|
|
|
|
text = gtk_entry_get_text(GTK_ENTRY(e));
|
|
|
|
len = strlen(text);
|
|
|
|
break;
|
|
|
|
case PT_TXTMOD_HEXBYTES: {
|
|
|
|
text = gtk_entry_get_text(GTK_ENTRY(e));
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
text = (void*) unhexbytes(text, strlen(text), &len, &err);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
if (err) {
|
|
|
|
err = ep_strdup_printf("error in field '%s': %s",f[colnum].name,err);
|
|
|
|
goto on_failure;
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
break;
|
2008-01-19 07:46:52 +00:00
|
|
|
}
|
2007-02-07 03:39:40 +00:00
|
|
|
case PT_TXTMOD_ENUM: {
|
|
|
|
text = *(char**)e;
|
|
|
|
text = text ? text : "";
|
|
|
|
len = strlen(text);
|
|
|
|
break;
|
2008-01-19 07:46:52 +00:00
|
|
|
}
|
2007-02-07 03:39:40 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
if (f[colnum].cb.chk) {
|
2007-02-07 03:39:40 +00:00
|
|
|
if (! f[colnum].cb.chk(dd->rec, text, len, f[colnum].cbdata.chk, f[colnum].fld_data, &err)) {
|
2007-02-03 14:25:02 +00:00
|
|
|
err = ep_strdup_printf("error in field '%s': %s",f[colnum].name,err);
|
2007-01-29 14:14:01 +00:00
|
|
|
goto on_failure;
|
|
|
|
}
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
f[colnum].cb.set(dd->rec,text,len, f[colnum].cbdata.set, f[colnum].fld_data);
|
2007-01-29 14:14:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dd->uat->update_cb) {
|
|
|
|
dd->uat->update_cb(dd->rec,&err);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 14:14:01 +00:00
|
|
|
if (err) {
|
|
|
|
err = ep_strdup_printf("error updating record: %s",err);
|
|
|
|
goto on_failure;
|
|
|
|
}
|
2007-02-03 14:25:02 +00:00
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
if (dd->is_new) {
|
|
|
|
void* rec_tmp = dd->rec;
|
|
|
|
dd->rec = uat_add_record(dd->uat, dd->rec);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
if (dd->uat->free_cb) {
|
|
|
|
dd->uat->free_cb(rec_tmp);
|
2007-01-29 14:14:01 +00:00
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
g_free(rec_tmp);
|
2007-01-29 14:14:01 +00:00
|
|
|
}
|
2007-02-03 14:25:02 +00:00
|
|
|
|
2007-02-04 05:19:02 +00:00
|
|
|
dd->uat->changed = TRUE;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
set_buttons(dd->uat,-1);
|
|
|
|
|
2007-01-29 14:14:01 +00:00
|
|
|
if (dd->is_new) {
|
|
|
|
append_row(dd->uat, (*dd->uat->nrows_p) - 1 );
|
|
|
|
} else {
|
|
|
|
reset_row(dd->uat,dd->row);
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
|
|
|
g_ptr_array_free(dd->entries,TRUE);
|
|
|
|
window_destroy(GTK_WIDGET(dd->win));
|
|
|
|
|
2007-03-04 02:27:11 +00:00
|
|
|
if (dd->uat->rep)
|
|
|
|
window_present(GTK_WIDGET(dd->uat->rep->window));
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2008-01-21 07:35:16 +00:00
|
|
|
while (dd->tobe_freed->len) g_free( g_ptr_array_remove_index_fast(dd->tobe_freed, dd->tobe_freed->len - 1 ) );
|
|
|
|
|
|
|
|
g_free(dd);
|
|
|
|
|
2008-01-19 07:46:52 +00:00
|
|
|
return TRUE;
|
2007-01-29 14:14:01 +00:00
|
|
|
on_failure:
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 14:14:01 +00:00
|
|
|
report_failure("%s",err);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean uat_cancel_dlg_cb(GtkWidget *win _U_, gpointer user_data) {
|
|
|
|
struct _uat_dlg_data* dd = user_data;
|
|
|
|
|
2007-03-04 02:27:11 +00:00
|
|
|
if (dd->uat->rep)
|
|
|
|
window_present(GTK_WIDGET(dd->uat->rep->window));
|
2007-01-29 14:14:01 +00:00
|
|
|
|
|
|
|
if (dd->is_new) g_free(dd->rec);
|
2008-01-19 07:46:52 +00:00
|
|
|
g_ptr_array_free(dd->entries,TRUE);
|
|
|
|
window_destroy(GTK_WIDGET(dd->win));
|
2007-01-29 14:14:01 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
while (dd->tobe_freed->len) g_free( g_ptr_array_remove_index_fast(dd->tobe_freed, dd->tobe_freed->len - 1 ) );
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-14 19:21:37 +00:00
|
|
|
g_free(dd);
|
|
|
|
|
2008-01-19 07:46:52 +00:00
|
|
|
return TRUE;
|
2007-01-29 14:14:01 +00:00
|
|
|
}
|
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
struct _fld_menu_item_data_t {
|
|
|
|
const char* text;
|
|
|
|
char const** valptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void fld_menu_item_cb(GtkMenuItem *menuitem _U_, gpointer user_data) {
|
|
|
|
struct _fld_menu_item_data_t* md = user_data;
|
|
|
|
|
|
|
|
*(md->valptr) = md->text;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fld_menu_item_destroy_cb(GtkMenuItem *menuitem _U_, gpointer user_data) {
|
|
|
|
g_free(user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uat_edit_dialog(uat_t* uat, gint row) {
|
2008-01-19 07:46:52 +00:00
|
|
|
GtkWidget *win, *main_tb, *main_vb, *bbox, *bt_cancel, *bt_ok;
|
|
|
|
struct _uat_dlg_data* dd = g_malloc(sizeof(struct _uat_dlg_data));
|
2007-02-03 14:25:02 +00:00
|
|
|
uat_field_t* f = uat->fields;
|
|
|
|
guint colnum;
|
2007-02-12 19:57:41 +00:00
|
|
|
GtkTooltips *tooltips;
|
|
|
|
|
|
|
|
tooltips = gtk_tooltips_new();
|
2007-01-29 14:14:01 +00:00
|
|
|
|
2008-01-19 07:46:52 +00:00
|
|
|
dd->entries = g_ptr_array_new();
|
|
|
|
dd->win = dlg_window_new(ep_strdup_printf("%s: %s", uat->name, (row == -1 ? "New" : "Edit")));
|
|
|
|
dd->uat = uat;
|
2007-01-29 14:14:01 +00:00
|
|
|
dd->rec = row < 0 ? g_malloc0(uat->record_size) : UAT_INDEX_PTR(uat,row);
|
|
|
|
dd->is_new = row < 0 ? TRUE : FALSE;
|
|
|
|
dd->row = row;
|
2008-01-19 07:46:52 +00:00
|
|
|
dd->tobe_freed = g_ptr_array_new();
|
|
|
|
|
|
|
|
win = dd->win;
|
|
|
|
|
2007-01-29 14:14:01 +00:00
|
|
|
#if GTK_MAJOR_VERSION >= 2
|
2007-02-07 13:55:34 +00:00
|
|
|
gtk_window_set_resizable(GTK_WINDOW(win),FALSE);
|
2008-01-19 07:46:52 +00:00
|
|
|
gtk_window_resize(GTK_WINDOW(win),400, 30*(uat->ncols+2));
|
2007-01-29 14:14:01 +00:00
|
|
|
#else
|
2008-01-19 07:46:52 +00:00
|
|
|
gtk_window_set_policy(GTK_WINDOW(win), FALSE, FALSE, TRUE);
|
2007-02-07 13:55:34 +00:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(win), 400, 30*(uat->ncols+2));
|
2008-01-19 07:46:52 +00:00
|
|
|
gtk_widget_set_usize(win, 400, 30*(uat->ncols+2));
|
2007-01-29 14:14:01 +00:00
|
|
|
#endif
|
2008-01-19 07:46:52 +00:00
|
|
|
|
|
|
|
main_vb = gtk_vbox_new(FALSE,5);
|
|
|
|
gtk_container_add(GTK_CONTAINER(win), main_vb);
|
2007-01-29 14:14:01 +00:00
|
|
|
gtk_container_border_width(GTK_CONTAINER(main_vb), 6);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
|
|
|
main_tb = gtk_table_new(uat->ncols+1, 2, FALSE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
|
|
|
|
gtk_table_set_row_spacings(GTK_TABLE(main_tb), 5);
|
|
|
|
gtk_table_set_col_spacings(GTK_TABLE(main_tb), 10);
|
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
for ( colnum = 0; colnum < uat->ncols; colnum++ ) {
|
2008-01-19 07:46:52 +00:00
|
|
|
GtkWidget *entry, *label, *event_box;
|
|
|
|
char* text = fld_tostr(dd->rec,&(f[colnum]));
|
2007-02-12 19:57:41 +00:00
|
|
|
|
|
|
|
event_box = gtk_event_box_new();
|
|
|
|
|
2008-01-19 07:46:52 +00:00
|
|
|
label = gtk_label_new(f[colnum].name);
|
2007-02-12 19:57:41 +00:00
|
|
|
if (f[colnum].desc != NULL)
|
|
|
|
gtk_tooltips_set_tip(tooltips, event_box, f[colnum].desc, NULL);
|
|
|
|
|
2008-01-19 07:46:52 +00:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), event_box, 0, 1, colnum+1, colnum + 2);
|
2007-02-12 19:57:41 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(event_box), label);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
switch(f[colnum].mode) {
|
|
|
|
case PT_TXTMOD_STRING:
|
|
|
|
case PT_TXTMOD_HEXBYTES: {
|
|
|
|
entry = gtk_entry_new();
|
|
|
|
g_ptr_array_add(dd->entries,entry);
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), entry, 1, 2, colnum+1, colnum + 2);
|
|
|
|
if (! dd->is_new) {
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry),text);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PT_TXTMOD_ENUM: {
|
|
|
|
GtkWidget *menu, *option_menu;
|
|
|
|
int menu_index, index;
|
|
|
|
const value_string* enum_vals = f[colnum].fld_data;
|
|
|
|
void* valptr = g_malloc0(sizeof(void*));
|
|
|
|
|
|
|
|
menu = gtk_menu_new();
|
|
|
|
menu_index = -1;
|
|
|
|
for (index = 0; enum_vals[index].strptr != NULL; index++) {
|
2008-01-19 07:46:52 +00:00
|
|
|
struct _fld_menu_item_data_t* md = g_malloc(sizeof(struct _fld_menu_item_data_t));
|
2007-02-07 03:39:40 +00:00
|
|
|
const char* str = enum_vals[index].strptr;
|
|
|
|
GtkWidget* menu_item = gtk_menu_item_new_with_label(str);
|
|
|
|
|
|
|
|
md->text = str;
|
|
|
|
md->valptr = valptr;
|
|
|
|
|
|
|
|
gtk_menu_append(GTK_MENU(menu), menu_item);
|
|
|
|
|
|
|
|
if ( g_str_equal(str, text) ) {
|
|
|
|
menu_index = index;
|
|
|
|
*((char const**)valptr) = str;
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
SIGNAL_CONNECT(menu_item, "activate", fld_menu_item_cb, md);
|
|
|
|
SIGNAL_CONNECT(menu_item, "destroy", fld_menu_item_destroy_cb, md);
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
g_ptr_array_add(dd->entries,valptr);
|
|
|
|
g_ptr_array_add(dd->tobe_freed,valptr);
|
|
|
|
|
|
|
|
/* Create the option menu from the menu */
|
|
|
|
option_menu = gtk_option_menu_new();
|
|
|
|
gtk_option_menu_set_menu(GTK_OPTION_MENU(option_menu), menu);
|
|
|
|
|
|
|
|
/* Set its current value to the variable's current value */
|
|
|
|
if (menu_index != -1)
|
|
|
|
gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), menu_index);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), option_menu, 1, 2, colnum+1, colnum + 2);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
return;
|
2007-01-29 14:14:01 +00:00
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
}
|
2007-01-29 14:14:01 +00:00
|
|
|
|
2008-01-19 07:46:52 +00:00
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_CANCEL,GTK_STOCK_OK, NULL);
|
2007-02-07 03:39:40 +00:00
|
|
|
gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
|
|
|
bt_ok = OBJECT_GET_DATA(bbox, GTK_STOCK_OK);
|
|
|
|
SIGNAL_CONNECT(bt_ok, "clicked", uat_dlg_cb, dd);
|
|
|
|
|
|
|
|
bt_cancel = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
|
|
|
|
SIGNAL_CONNECT(bt_cancel, "clicked", uat_cancel_dlg_cb, dd);
|
|
|
|
window_set_cancel_button(win, bt_cancel, NULL);
|
|
|
|
|
|
|
|
gtk_widget_show_all(win);
|
2007-01-29 14:14:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct _uat_del {
|
|
|
|
GtkWidget *win;
|
|
|
|
uat_t* uat;
|
|
|
|
gint idx;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void uat_del_cb(GtkButton *button _U_, gpointer u) {
|
|
|
|
struct _uat_del* ud = u;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 14:14:01 +00:00
|
|
|
uat_remove_record_idx(ud->uat, ud->idx);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-03-04 02:27:11 +00:00
|
|
|
if (ud->uat->rep)
|
|
|
|
gtk_clist_remove(GTK_CLIST(ud->uat->rep->clist),ud->idx);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-04 05:19:02 +00:00
|
|
|
ud->uat->changed = TRUE;
|
2007-02-05 04:22:06 +00:00
|
|
|
set_buttons(ud->uat,-1);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
|
|
|
window_destroy(GTK_WIDGET(ud->win));
|
|
|
|
|
2007-03-04 02:27:11 +00:00
|
|
|
if (ud->uat->rep)
|
|
|
|
window_present(GTK_WIDGET(ud->uat->rep->window));
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 14:14:01 +00:00
|
|
|
g_free(ud);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uat_cancel_del_cb(GtkButton *button _U_, gpointer u) {
|
|
|
|
struct _uat_del* ud = u;
|
2008-01-19 07:46:52 +00:00
|
|
|
window_destroy(GTK_WIDGET(ud->win));
|
2007-03-04 02:27:11 +00:00
|
|
|
|
|
|
|
if (ud->uat->rep)
|
|
|
|
window_present(GTK_WIDGET(ud->uat->rep->window));
|
2007-01-29 14:14:01 +00:00
|
|
|
g_free(ud);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uat_del_dlg(uat_t* uat, int idx) {
|
2008-01-19 07:46:52 +00:00
|
|
|
GtkWidget *win, *main_tb, *main_vb, *bbox, *bt_cancel, *bt_ok;
|
2007-02-03 14:25:02 +00:00
|
|
|
uat_field_t* f = uat->fields;
|
|
|
|
guint colnum;
|
2007-01-29 14:14:01 +00:00
|
|
|
void* rec = UAT_INDEX_PTR(uat,idx);
|
|
|
|
struct _uat_del* ud = g_malloc(sizeof(struct _uat_del));
|
|
|
|
|
|
|
|
ud->uat = uat;
|
|
|
|
ud->idx = idx;
|
2008-01-19 07:46:52 +00:00
|
|
|
ud->win = win = dlg_window_new(ep_strdup_printf("%s: Confirm Delete", uat->name));
|
2007-02-07 13:55:34 +00:00
|
|
|
|
2007-01-29 14:14:01 +00:00
|
|
|
#if GTK_MAJOR_VERSION >= 2
|
2007-02-07 13:55:34 +00:00
|
|
|
gtk_window_set_resizable(GTK_WINDOW(win),FALSE);
|
2008-01-19 07:46:52 +00:00
|
|
|
gtk_window_resize(GTK_WINDOW(win),400,25*(uat->ncols+2));
|
2007-01-29 14:14:01 +00:00
|
|
|
#else
|
2007-02-07 13:55:34 +00:00
|
|
|
gtk_window_set_policy(GTK_WINDOW(win), FALSE, FALSE, TRUE);
|
|
|
|
gtk_window_set_default_size(GTK_WINDOW(win), 400, 25*(uat->ncols+2));
|
2008-01-19 07:46:52 +00:00
|
|
|
gtk_widget_set_usize(win, 400, 25*(uat->ncols+2));
|
2007-01-29 14:14:01 +00:00
|
|
|
#endif
|
2008-01-19 07:46:52 +00:00
|
|
|
|
|
|
|
main_vb = gtk_vbox_new(FALSE,5);
|
|
|
|
gtk_container_add(GTK_CONTAINER(win), main_vb);
|
2007-01-29 14:14:01 +00:00
|
|
|
gtk_container_border_width(GTK_CONTAINER(main_vb), 6);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
|
|
|
main_tb = gtk_table_new(uat->ncols+1, 2, FALSE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
|
|
|
|
gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
|
|
|
|
gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
|
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
for ( colnum = 0; colnum < uat->ncols; colnum++ ) {
|
2008-01-19 07:46:52 +00:00
|
|
|
GtkWidget *label;
|
|
|
|
char* text = fld_tostr(rec,&(f[colnum]));
|
|
|
|
|
|
|
|
label = gtk_label_new(f[colnum].name);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1, colnum+1, colnum + 2);
|
2007-01-29 14:14:01 +00:00
|
|
|
|
2008-01-19 07:46:52 +00:00
|
|
|
label = gtk_label_new(text);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 1, 2, colnum+1, colnum + 2);
|
2007-02-03 14:25:02 +00:00
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_CANCEL,GTK_STOCK_DELETE, NULL);
|
2007-01-29 14:14:01 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
|
|
|
bt_ok = OBJECT_GET_DATA(bbox,GTK_STOCK_DELETE);
|
|
|
|
SIGNAL_CONNECT(bt_ok, "clicked", uat_del_cb, ud);
|
|
|
|
|
|
|
|
bt_cancel = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
|
|
|
|
SIGNAL_CONNECT(bt_cancel, "clicked", uat_cancel_del_cb, ud);
|
|
|
|
window_set_cancel_button( win, bt_cancel, NULL);
|
|
|
|
|
|
|
|
gtk_widget_show_all(win);
|
2007-01-29 14:14:01 +00:00
|
|
|
}
|
2007-01-29 10:25:54 +00:00
|
|
|
|
|
|
|
static void uat_new_cb(GtkButton *button _U_, gpointer u) {
|
|
|
|
uat_t* uat = u;
|
2007-03-04 02:27:11 +00:00
|
|
|
|
|
|
|
if (! uat->rep) return;
|
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
uat_edit_dialog(uat, -1);
|
2007-01-29 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uat_edit_cb(GtkButton *button _U_, gpointer u) {
|
|
|
|
uat_t* uat = u;
|
2007-03-04 02:27:11 +00:00
|
|
|
|
|
|
|
if (! uat->rep) return;
|
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
uat_edit_dialog(uat, uat->rep->selected);
|
2007-01-29 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uat_delete_cb(GtkButton *button _U_, gpointer u) {
|
|
|
|
uat_t* uat = u;
|
2007-03-04 02:27:11 +00:00
|
|
|
|
|
|
|
if (! uat->rep) return;
|
|
|
|
|
2007-01-29 14:14:01 +00:00
|
|
|
uat_del_dlg(uat,uat->rep->selected);
|
2007-01-29 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
static gboolean uat_window_delete_event_cb(GtkWindow *w _U_, GdkEvent* e _U_, gpointer u) {
|
|
|
|
uat_t* uat = u;
|
2007-02-04 05:19:02 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
if (uat->rep) {
|
|
|
|
void* rep = uat->rep;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
SIGNAL_DISCONNECT_BY_FUNC(uat->rep->window, uat_window_delete_event_cb, uat);
|
|
|
|
SIGNAL_DISCONNECT_BY_FUNC(uat->rep->window, unsaved_dialog, uat);
|
2007-02-05 04:22:06 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
gtk_widget_destroy(uat->rep->window);
|
2007-02-05 04:22:06 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
uat->rep = NULL;
|
|
|
|
if (rep) g_free(rep);
|
|
|
|
}
|
2007-02-05 04:22:06 +00:00
|
|
|
return TRUE;
|
2007-02-04 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uat_up_cb(GtkButton *button _U_, gpointer u) {
|
|
|
|
uat_t* uat = u;
|
|
|
|
guint row = uat->rep->selected;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-04 05:19:02 +00:00
|
|
|
g_assert(row > 0);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-04 05:19:02 +00:00
|
|
|
uat_swap(uat,row,row-1);
|
|
|
|
gtk_clist_swap_rows(GTK_CLIST(uat->rep->clist),row,row-1);
|
|
|
|
|
|
|
|
uat->changed = TRUE;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-04 05:19:02 +00:00
|
|
|
row -= 1;
|
|
|
|
uat->rep->selected = row;
|
|
|
|
set_buttons(uat,row);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uat_down_cb(GtkButton *button _U_, gpointer u) {
|
|
|
|
uat_t* uat = u;
|
|
|
|
guint row = uat->rep->selected;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-04 05:19:02 +00:00
|
|
|
g_assert(row < *uat->nrows_p - 1);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-04 05:19:02 +00:00
|
|
|
uat_swap(uat,row,row+1);
|
|
|
|
gtk_clist_swap_rows(GTK_CLIST(uat->rep->clist),row,row+1);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-04 05:19:02 +00:00
|
|
|
uat->changed = TRUE;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-04 05:19:02 +00:00
|
|
|
row += 1;
|
|
|
|
uat->rep->selected = row;
|
|
|
|
set_buttons(uat,row);
|
|
|
|
}
|
|
|
|
|
2007-08-31 23:22:45 +00:00
|
|
|
static void uat_cancel_cb(GtkWidget *button _U_, gpointer u) {
|
2007-02-04 05:19:02 +00:00
|
|
|
uat_t* uat = u;
|
|
|
|
gchar* err = NULL;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
if (uat->changed) {
|
|
|
|
uat_clear(uat);
|
|
|
|
uat_load(uat,&err);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
if (err) {
|
|
|
|
report_failure("Error while loading %s: %s",uat->name,err);
|
|
|
|
}
|
2007-02-04 05:19:02 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
if (cfile.state == FILE_READ_DONE) cf_reload(&cfile);
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
SIGNAL_DISCONNECT_BY_FUNC(uat->rep->window, uat_window_delete_event_cb, uat);
|
|
|
|
SIGNAL_DISCONNECT_BY_FUNC(uat->rep->window, unsaved_dialog, uat);
|
|
|
|
gtk_widget_destroy(uat->rep->window);
|
|
|
|
g_free(uat->rep);
|
|
|
|
uat->rep = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uat_apply_cb(GtkButton *button _U_, gpointer u) {
|
|
|
|
uat_t* uat = u;
|
|
|
|
|
2007-11-26 18:00:21 +00:00
|
|
|
uat_window_delete_event_cb(NULL,NULL,uat);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
if (uat->changed && cfile.state == FILE_READ_DONE)
|
|
|
|
cf_reload(&cfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uat_ok_cb(GtkButton *button _U_, gpointer u) {
|
|
|
|
uat_t* uat = u;
|
|
|
|
gchar* err = NULL;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
if (uat->changed) {
|
|
|
|
uat_save(uat,&err);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
if (err) {
|
|
|
|
report_failure("Error while saving %s: %s",uat->name,err);
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
if (cfile.state == FILE_READ_DONE) cf_reload(&cfile);
|
2007-02-04 05:19:02 +00:00
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
SIGNAL_DISCONNECT_BY_FUNC(uat->rep->window, uat_window_delete_event_cb, uat);
|
|
|
|
SIGNAL_DISCONNECT_BY_FUNC(uat->rep->window, unsaved_dialog, uat);
|
|
|
|
gtk_widget_destroy(uat->rep->window);
|
|
|
|
g_free(uat->rep);
|
|
|
|
uat->rep = NULL;
|
2007-02-04 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
|
|
|
|
|
2007-01-29 10:25:54 +00:00
|
|
|
static void remember_selected_row(GtkCList *clist _U_, gint row, gint column _U_, GdkEvent *event _U_, gpointer u) {
|
2008-01-19 07:46:52 +00:00
|
|
|
uat_t* uat = u;
|
|
|
|
|
|
|
|
uat->rep->selected = row;
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (uat->rep->bt_edit, TRUE);
|
|
|
|
gtk_widget_set_sensitive(uat->rep->bt_delete, TRUE);
|
|
|
|
|
2007-02-04 05:19:02 +00:00
|
|
|
set_buttons(uat,row);
|
2007-01-29 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
2008-01-19 07:46:52 +00:00
|
|
|
static void unremember_selected_row(GtkCList *clist _U_, gint row _U_, gint column _U_, GdkEvent *event _U_, gpointer u) {
|
|
|
|
uat_t* uat = u;
|
2007-01-29 10:25:54 +00:00
|
|
|
|
|
|
|
uat->rep->selected = -1;
|
|
|
|
gtk_widget_set_sensitive (uat->rep->bt_edit, FALSE);
|
|
|
|
gtk_widget_set_sensitive(uat->rep->bt_delete, FALSE);
|
2007-02-04 05:19:02 +00:00
|
|
|
gtk_widget_set_sensitive (uat->rep->bt_down, FALSE);
|
|
|
|
gtk_widget_set_sensitive (uat->rep->bt_up, FALSE);
|
2007-01-29 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
static void uat_yessave_cb(GtkWindow *w _U_, void* u) {
|
2007-02-05 04:22:06 +00:00
|
|
|
uat_t* uat = u;
|
2007-02-11 16:09:21 +00:00
|
|
|
gchar* err = NULL;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
window_delete_event_cb(uat->rep->unsaved_window,NULL,NULL);
|
2007-02-11 16:09:21 +00:00
|
|
|
|
|
|
|
uat_save(uat,&err);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
if (err) {
|
|
|
|
report_failure("Error while saving %s: %s",uat->name,err);
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
SIGNAL_DISCONNECT_BY_FUNC(uat->rep->window, uat_window_delete_event_cb, uat);
|
|
|
|
SIGNAL_DISCONNECT_BY_FUNC(uat->rep->window, unsaved_dialog, uat);
|
|
|
|
window_destroy(uat->rep->window);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
g_free(uat->rep);
|
2007-01-29 10:25:54 +00:00
|
|
|
uat->rep = NULL;
|
2007-02-05 04:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
static void uat_nosave_cb(GtkWindow *w _U_, void* u) {
|
|
|
|
uat_t* uat = u;
|
|
|
|
window_delete_event_cb(uat->rep->unsaved_window,NULL,NULL);
|
|
|
|
SIGNAL_DISCONNECT_BY_FUNC(uat->rep->window, uat_window_delete_event_cb, uat);
|
|
|
|
SIGNAL_DISCONNECT_BY_FUNC(uat->rep->window, unsaved_dialog, uat);
|
|
|
|
window_destroy(uat->rep->window);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
g_free(uat->rep);
|
|
|
|
uat->rep = NULL;
|
2007-02-05 04:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean unsaved_dialog(GtkWindow *w _U_, GdkEvent* e _U_, gpointer u) {
|
|
|
|
GtkWidget *win, *vbox, *label, *bbox;
|
2007-02-11 16:09:21 +00:00
|
|
|
GtkWidget *yes_bt, *no_bt;
|
2007-02-05 04:22:06 +00:00
|
|
|
gchar* message;
|
|
|
|
uat_t* uat = u;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
if (uat->rep->unsaved_window) {
|
|
|
|
window_present(uat->rep->unsaved_window);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
uat->rep->unsaved_window = win = window_new(GTK_WINDOW_TOPLEVEL, "Discard Changes?");
|
|
|
|
gtk_window_set_default_size(GTK_WINDOW(win), 360, 140);
|
|
|
|
|
|
|
|
#if GTK_MAJOR_VERSION >= 2
|
|
|
|
gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER_ON_PARENT);
|
|
|
|
#else
|
|
|
|
gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER);
|
|
|
|
#endif
|
|
|
|
vbox = gtk_vbox_new(FALSE, 12);
|
|
|
|
gtk_container_border_width(GTK_CONTAINER(vbox), 6);
|
|
|
|
gtk_container_add(GTK_CONTAINER(win), vbox);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
message = ep_strdup_printf("Changes to '%s' are not being saved!\n"
|
2008-01-19 07:46:52 +00:00
|
|
|
"Do you want to save '%s'?", uat->name, uat->name);
|
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
label = gtk_label_new(message);
|
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_YES,GTK_STOCK_NO, NULL);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
yes_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_YES);
|
|
|
|
no_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_NO);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
SIGNAL_CONNECT(no_bt, "clicked", uat_nosave_cb, uat);
|
|
|
|
SIGNAL_CONNECT(yes_bt, "clicked", uat_yessave_cb, uat);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
gtk_widget_show_all(win);
|
|
|
|
window_present(win);
|
|
|
|
|
|
|
|
return TRUE;
|
2007-01-29 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
2007-02-05 05:06:21 +00:00
|
|
|
#if (GLIB_MAJOR_VERSION >= 2)
|
|
|
|
static void uat_help_cb(GtkWidget* w _U_, gpointer u) {
|
|
|
|
help_topic_html(ep_strdup_printf("%s.html",((uat_t*)u)->help));
|
|
|
|
}
|
|
|
|
#endif
|
2007-01-29 10:25:54 +00:00
|
|
|
|
2007-02-09 03:11:14 +00:00
|
|
|
static GtkWidget* uat_window(void* u) {
|
2007-02-03 14:25:02 +00:00
|
|
|
uat_t* uat = u;
|
|
|
|
uat_field_t* f = uat->fields;
|
2007-01-29 10:25:54 +00:00
|
|
|
uat_rep_t* rep;
|
|
|
|
guint i;
|
2007-02-03 14:25:02 +00:00
|
|
|
guint colnum;
|
2007-02-11 16:09:21 +00:00
|
|
|
GtkWidget *hbox, *vbox, *move_hbox, *edit_hbox;
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 10:25:54 +00:00
|
|
|
if (uat->rep) {
|
|
|
|
window_present(uat->rep->window);
|
|
|
|
return uat->rep->window;
|
|
|
|
} else {
|
|
|
|
uat->rep = rep = g_malloc0(sizeof(uat_rep_t));
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
rep->window = window_new(GTK_WINDOW_TOPLEVEL, uat->name);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
#if GTK_MAJOR_VERSION >= 2
|
|
|
|
gtk_window_set_resizable(GTK_WINDOW(rep->window),FALSE);
|
2008-01-19 07:46:52 +00:00
|
|
|
gtk_window_resize(GTK_WINDOW(rep->window), 720, 512);
|
2007-02-11 16:09:21 +00:00
|
|
|
#else
|
|
|
|
gtk_window_set_policy(GTK_WINDOW(rep->window), FALSE, FALSE, TRUE);
|
|
|
|
gtk_window_set_default_size(GTK_WINDOW(rep->window), 720, 512);
|
2008-01-19 07:46:52 +00:00
|
|
|
gtk_widget_set_usize(rep->window, 720, 512);
|
2007-02-11 16:09:21 +00:00
|
|
|
#endif
|
|
|
|
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 10:25:54 +00:00
|
|
|
#if GTK_MAJOR_VERSION >= 2
|
|
|
|
gtk_window_set_position(GTK_WINDOW(rep->window), GTK_WIN_POS_CENTER_ON_PARENT);
|
|
|
|
#else
|
|
|
|
gtk_window_set_position(GTK_WINDOW(rep->window), GTK_WIN_POS_CENTER);
|
|
|
|
#endif
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 10:25:54 +00:00
|
|
|
gtk_container_border_width(GTK_CONTAINER(rep->window), 6);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 10:25:54 +00:00
|
|
|
rep->vbox = gtk_vbox_new(FALSE, 12);
|
|
|
|
gtk_container_border_width(GTK_CONTAINER(rep->vbox), 6);
|
|
|
|
gtk_container_add(GTK_CONTAINER(rep->window), rep->vbox);
|
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
hbox = gtk_hbox_new(FALSE,12);
|
|
|
|
gtk_container_border_width(GTK_CONTAINER(hbox), 6);
|
|
|
|
gtk_container_add(GTK_CONTAINER(rep->vbox), hbox);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
vbox = gtk_vbox_new(FALSE, 12);
|
|
|
|
gtk_container_border_width(GTK_CONTAINER(vbox), 6);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 10:25:54 +00:00
|
|
|
rep->scrolledwindow = scrolled_window_new(NULL, NULL);
|
|
|
|
|
|
|
|
#if GTK_MAJOR_VERSION >= 2
|
2008-01-19 07:46:52 +00:00
|
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(rep->scrolledwindow), GTK_SHADOW_IN);
|
2007-01-29 10:25:54 +00:00
|
|
|
#endif
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 10:25:54 +00:00
|
|
|
rep->clist = gtk_clist_new(uat->ncols);
|
2007-05-25 16:47:22 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(rep->scrolledwindow), rep->clist);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), rep->scrolledwindow, TRUE, TRUE, 0);
|
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
for ( colnum = 0; colnum < uat->ncols; colnum++ ) {
|
|
|
|
gtk_clist_set_column_title(GTK_CLIST(rep->clist), colnum, f[colnum].name);
|
|
|
|
gtk_clist_set_column_auto_resize(GTK_CLIST(rep->clist), colnum, TRUE);
|
2007-01-29 10:25:54 +00:00
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 10:25:54 +00:00
|
|
|
gtk_clist_column_titles_show(GTK_CLIST(rep->clist));
|
|
|
|
gtk_clist_freeze(GTK_CLIST(rep->clist));
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 10:25:54 +00:00
|
|
|
for ( i = 0 ; i < *(uat->nrows_p); i++ ) {
|
|
|
|
append_row(uat, i);
|
|
|
|
}
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 10:25:54 +00:00
|
|
|
gtk_clist_thaw(GTK_CLIST(rep->clist));
|
|
|
|
|
|
|
|
#if GTK_MAJOR_VERSION < 2
|
|
|
|
gtk_clist_set_selection_mode(GTK_CLIST(rep->clist),GTK_SELECTION_SINGLE);
|
|
|
|
#else
|
|
|
|
rep->selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(rep->clist));
|
|
|
|
gtk_tree_selection_set_mode(rep->selection, GTK_SELECTION_SINGLE);
|
|
|
|
#endif
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
#if (GLIB_MAJOR_VERSION >= 2)
|
|
|
|
if(uat->help) {
|
|
|
|
GtkWidget* help_btn;
|
|
|
|
rep->bbox = dlg_button_row_new(GTK_STOCK_HELP, GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_CANCEL, NULL);
|
|
|
|
help_btn = OBJECT_GET_DATA(rep->bbox,GTK_STOCK_HELP);
|
|
|
|
SIGNAL_CONNECT(help_btn, "clicked", uat_help_cb, uat);
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
rep->bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_CANCEL, NULL);
|
|
|
|
#if (GLIB_MAJOR_VERSION >= 2)
|
|
|
|
}
|
|
|
|
#endif
|
2008-01-19 07:46:52 +00:00
|
|
|
|
|
|
|
move_hbox = gtk_vbutton_box_new();
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), move_hbox, TRUE, FALSE, 0);
|
2007-02-04 05:19:02 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
edit_hbox = gtk_vbutton_box_new();
|
2008-01-19 07:46:52 +00:00
|
|
|
gtk_box_pack_end(GTK_BOX(vbox), edit_hbox, TRUE, FALSE, 0);
|
|
|
|
|
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
rep->bt_down = BUTTON_NEW_FROM_STOCK(GTK_STOCK_GO_DOWN);
|
|
|
|
rep->bt_up = BUTTON_NEW_FROM_STOCK(GTK_STOCK_GO_UP);
|
2007-08-31 23:22:45 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(move_hbox), rep->bt_up, TRUE, FALSE, 5);
|
|
|
|
gtk_box_pack_start(GTK_BOX(move_hbox), rep->bt_down, TRUE, FALSE, 5);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-08-31 23:22:45 +00:00
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
rep->bt_new = BUTTON_NEW_FROM_STOCK(GTK_STOCK_NEW);
|
|
|
|
rep->bt_edit = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_EDIT);
|
2007-01-29 10:25:54 +00:00
|
|
|
rep->bt_delete = BUTTON_NEW_FROM_STOCK(GTK_STOCK_DELETE);
|
2007-02-05 04:22:06 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
gtk_box_pack_end(GTK_BOX(edit_hbox), rep->bt_new, TRUE, FALSE, 5);
|
|
|
|
gtk_box_pack_end(GTK_BOX(edit_hbox), rep->bt_edit, TRUE, FALSE, 5);
|
|
|
|
gtk_box_pack_end(GTK_BOX(edit_hbox), rep->bt_delete, TRUE, FALSE, 5);
|
2007-02-05 05:06:21 +00:00
|
|
|
|
2007-08-31 23:22:45 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
rep->bt_apply = OBJECT_GET_DATA(rep->bbox,GTK_STOCK_APPLY);
|
|
|
|
rep->bt_cancel = OBJECT_GET_DATA(rep->bbox,GTK_STOCK_CANCEL);
|
|
|
|
rep->bt_ok = OBJECT_GET_DATA(rep->bbox,GTK_STOCK_OK);
|
2007-02-05 04:22:06 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
gtk_box_pack_end(GTK_BOX(rep->vbox), rep->bbox, FALSE, FALSE, 0);
|
2007-02-05 04:22:06 +00:00
|
|
|
|
|
|
|
gtk_widget_set_sensitive (rep->bt_up, FALSE);
|
|
|
|
gtk_widget_set_sensitive (rep->bt_down, FALSE);
|
|
|
|
gtk_widget_set_sensitive (rep->bt_edit, FALSE);
|
|
|
|
gtk_widget_set_sensitive (rep->bt_delete, FALSE);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-04 05:19:02 +00:00
|
|
|
|
2007-01-29 10:25:54 +00:00
|
|
|
#if GTK_MAJOR_VERSION < 2
|
|
|
|
SIGNAL_CONNECT(rep->clist, "select_row", remember_selected_row, uat);
|
|
|
|
SIGNAL_CONNECT(rep->clist, "unselect_row", unremember_selected_row, uat);
|
|
|
|
#else
|
|
|
|
SIGNAL_CONNECT(selection, "changed", remember_selected_row, uat);
|
|
|
|
#endif
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-01-29 10:25:54 +00:00
|
|
|
SIGNAL_CONNECT(rep->bt_new, "clicked", uat_new_cb, uat);
|
|
|
|
SIGNAL_CONNECT(rep->bt_edit, "clicked", uat_edit_cb, uat);
|
|
|
|
SIGNAL_CONNECT(rep->bt_delete, "clicked", uat_delete_cb, uat);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-04 05:19:02 +00:00
|
|
|
SIGNAL_CONNECT(rep->bt_up, "clicked", uat_up_cb, uat);
|
|
|
|
SIGNAL_CONNECT(rep->bt_down, "clicked", uat_down_cb, uat);
|
2008-01-19 07:46:52 +00:00
|
|
|
|
2007-02-11 16:09:21 +00:00
|
|
|
SIGNAL_CONNECT(rep->bt_apply, "clicked", uat_apply_cb, uat);
|
|
|
|
SIGNAL_CONNECT(rep->bt_cancel, "clicked", uat_cancel_cb, uat);
|
|
|
|
SIGNAL_CONNECT(rep->bt_ok, "clicked", uat_ok_cb, uat);
|
2007-02-05 04:22:06 +00:00
|
|
|
|
2008-01-19 07:46:52 +00:00
|
|
|
window_set_cancel_button(rep->window, rep->bt_cancel, NULL); /* set esc to activate cancel button */
|
2007-08-31 23:22:45 +00:00
|
|
|
|
2007-02-05 04:22:06 +00:00
|
|
|
if (uat->changed) {
|
|
|
|
SIGNAL_CONNECT(GTK_WINDOW(rep->window), "delete_event", unsaved_dialog, uat);
|
2008-01-19 07:46:52 +00:00
|
|
|
SIGNAL_CONNECT(GTK_WINDOW(rep->window), "destroy", unsaved_dialog, uat);
|
2007-02-05 04:22:06 +00:00
|
|
|
} else {
|
|
|
|
SIGNAL_CONNECT(GTK_WINDOW(rep->window), "delete_event", uat_window_delete_event_cb, uat);
|
2008-01-19 07:46:52 +00:00
|
|
|
SIGNAL_CONNECT(GTK_WINDOW(rep->window), "destroy", uat_window_delete_event_cb, uat);
|
2007-02-05 04:22:06 +00:00
|
|
|
}
|
2007-01-29 10:25:54 +00:00
|
|
|
|
|
|
|
gtk_widget_grab_focus(rep->clist);
|
|
|
|
|
|
|
|
gtk_widget_show_all(rep->window);
|
|
|
|
window_present(rep->window);
|
|
|
|
|
|
|
|
return rep->window;
|
|
|
|
}
|
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
void uat_window_cb(GtkWidget* u _U_, void* uat) {
|
|
|
|
uat_window(uat);
|
|
|
|
}
|
2007-02-09 03:11:14 +00:00
|
|
|
|