-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_gen_gui.c
191 lines (150 loc) · 5.78 KB
/
db_gen_gui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* $Id: db_gen_gui.c,v 1.2 2003/02/22 23:17:09 d3august Exp $
*/
/* xtraceroute - graphically show traceroute information.
* Copyright (C) 1996-1998 Björn Augustsson
*
* 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.
*/
/* File created by Edouard Lafargue 07/98
*/
#include "xt.h"
#include <stdlib.h>
#include <string.h>
/* TODO FIXME Allow updating the generic database. */
static gint text_has_changed = FALSE;
static gint guard = FALSE;
static GtkWidget *name_entry;
static GtkWidget *lat_entry;
static GtkWidget *lon_entry;
static GtkWidget *info_entry;
static gint destroy_widget_callback(GtkWidget *wi, gpointer *target)
{
gtk_widget_destroy(GTK_WIDGET(target));
guard = FALSE;
return TRUE;
}
static gint yesbutton_callback(GtkWidget *wi, gpointer *data)
{
dbentry *ent;
if(text_has_changed)
{
text_has_changed = FALSE;
ent = (dbentry *)malloc(sizeof(dbentry));
/* This is a good place to do some sanity/bounds checking! */
ent->lat = atof(gtk_entry_get_text(GTK_ENTRY(lat_entry)));
ent->lon = atof(gtk_entry_get_text(GTK_ENTRY(lon_entry)));
strcpy(ent->name, gtk_entry_get_text(GTK_ENTRY(name_entry)));
strcpy(ent->info, gtk_entry_get_text(GTK_ENTRY(info_entry)));
/* Always add new entries to the private database. */
addToGenDB(local_user_generic, ent);
free(ent);
}
return TRUE;
}
static gint helpbutton_callback(GtkWidget *wi, gpointer *data)
{
tell_user(_("No help yet!"));
return TRUE;
}
static gint text_change_callback(GtkWidget *wi, gpointer *data)
{
text_has_changed = TRUE;
return TRUE;
}
/***
* These two from db_host_gui.c, common to db_*_gui.c
*/
extern void
add_widget_to_table(GtkWidget*, GtkTable*, gint, gint);
extern void
add_string_to_table(const char*, GtkTable*, gint, gint);
void addGen(GtkWidget* wi)
{
GtkWidget *dialog;
GtkWidget *table;
GtkWidget *yesbutton;
GtkWidget *nobutton;
GtkWidget *helpbutton;
GtkWidget *title;
GtkWidget *frame;
char string[100];
if(guard == TRUE)
{
tell_user(_("You can only have one\ndatabase window at at time!"));
return;
}
guard = TRUE;
dialog = gtk_dialog_new();
sprintf(string, _("New generic record"));
title = gtk_label_new(string);
gtk_widget_show(GTK_WIDGET(title));
gtk_window_set_title (GTK_WINDOW(dialog),_("Record info"));
gtk_container_border_width(GTK_CONTAINER(dialog), 10);
table = gtk_table_new(4,2,FALSE);
gtk_container_border_width(GTK_CONTAINER(table), 10);
add_string_to_table(_("Match string:"), GTK_TABLE(table), 0, 0);
add_string_to_table(_("Latitude:"), GTK_TABLE(table), 1, 0);
add_string_to_table(_("Longitude:"), GTK_TABLE(table), 2, 0);
add_string_to_table(_("Info:"), GTK_TABLE(table), 3, 0);
name_entry = gtk_entry_new();
lat_entry = gtk_entry_new();
lon_entry = gtk_entry_new();
info_entry = gtk_entry_new();
gtk_signal_connect(GTK_OBJECT(name_entry), "changed",
GTK_SIGNAL_FUNC(text_change_callback), NULL);
gtk_signal_connect(GTK_OBJECT(lat_entry), "changed",
GTK_SIGNAL_FUNC(text_change_callback), NULL);
gtk_signal_connect(GTK_OBJECT(lon_entry), "changed",
GTK_SIGNAL_FUNC(text_change_callback), NULL);
gtk_signal_connect(GTK_OBJECT(info_entry), "changed",
GTK_SIGNAL_FUNC(text_change_callback), NULL);
add_widget_to_table(GTK_WIDGET(name_entry), GTK_TABLE(table), 0, 1);
add_widget_to_table(GTK_WIDGET(lat_entry), GTK_TABLE(table), 1, 1);
add_widget_to_table(GTK_WIDGET(lon_entry), GTK_TABLE(table), 2, 1);
add_widget_to_table(GTK_WIDGET(info_entry), GTK_TABLE(table), 3, 1);
gtk_widget_show(GTK_WIDGET(table));
/* Pack everything */
frame = gtk_frame_new (_("String matching"));
gtk_container_border_width (GTK_CONTAINER (frame), 10);
gtk_container_add(GTK_CONTAINER(frame), table);
gtk_widget_show(GTK_WIDGET(frame));
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), title, TRUE,
TRUE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, TRUE,
TRUE, 0);
yesbutton = gtk_button_new_with_label(_("OK"));
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), yesbutton,
TRUE, TRUE, 0);
gtk_signal_connect(GTK_OBJECT (yesbutton), "clicked",
GTK_SIGNAL_FUNC (yesbutton_callback), dialog);
gtk_signal_connect(GTK_OBJECT (yesbutton), "clicked",
GTK_SIGNAL_FUNC (destroy_widget_callback), dialog);
GTK_WIDGET_SET_FLAGS(yesbutton, GTK_CAN_DEFAULT);
gtk_widget_grab_default(yesbutton);
gtk_widget_show(yesbutton);
nobutton = gtk_button_new_with_label(_("Cancel"));
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), nobutton,
TRUE, TRUE, 0);
gtk_signal_connect(GTK_OBJECT (nobutton), "clicked",
GTK_SIGNAL_FUNC(destroy_widget_callback), dialog);
gtk_widget_show(nobutton);
helpbutton = gtk_button_new_with_label(_("Help"));
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), helpbutton,
TRUE, TRUE, 0);
gtk_signal_connect(GTK_OBJECT (helpbutton), "clicked",
GTK_SIGNAL_FUNC(helpbutton_callback), dialog);
gtk_widget_show(helpbutton);
gtk_widget_show (dialog);
}