]> git.tdb.fi Git - ext/subsurface.git/blob - info.c
e9a08ca2a5c2f240d564dc9310e73e33126c684e
[ext/subsurface.git] / info.c
1 /* info.c */
2 /* creates the UI for the info frame - 
3  * controlled through the following interfaces:
4  * 
5  * void show_dive_info(struct dive *dive)
6  *
7  * called from gtk-ui:
8  * GtkWidget *extended_dive_info_widget(void)
9  */
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <time.h>
14 #include <ctype.h>
15 #include <sys/time.h>
16
17 #include "dive.h"
18 #include "display.h"
19 #include "display-gtk.h"
20 #include "divelist.h"
21
22 static GtkEntry *location, *buddy, *divemaster, *rating, *suit;
23 static GtkTextView *notes;
24 static GtkListStore *location_list, *people_list, *star_list, *suit_list;
25
26 static char *get_text(GtkTextView *view)
27 {
28         GtkTextBuffer *buffer;
29         GtkTextIter start;
30         GtkTextIter end;
31
32         buffer = gtk_text_view_get_buffer(view);
33         gtk_text_buffer_get_start_iter(buffer, &start);
34         gtk_text_buffer_get_end_iter(buffer, &end);
35         return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
36 }
37
38 /* old is NULL or a valid string, new is a valid string
39  * NOTW: NULL and "" need to be treated as "unchanged" */
40 static int text_changed(const char *old, const char *new)
41 {
42         return (old && strcmp(old,new)) ||
43                 (!old && strcmp("",new));
44 }
45
46 static char *get_combo_box_entry_text(GtkComboBoxEntry *combo_box, char **textp)
47 {
48         char *old = *textp;
49         const gchar *new;
50         GtkEntry *entry;
51
52         entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
53         new = gtk_entry_get_text(entry);
54         while (isspace(*new))
55                 new++;
56         if (!text_changed(old,new))
57                 return NULL;
58         free(old);
59         *textp = strdup(new);
60         return *textp;
61 }
62
63 #define SET_TEXT_VALUE(x) \
64         gtk_entry_set_text(x, dive && dive->x ? dive->x : "")
65
66 static int divename(char *buf, size_t size, struct dive *dive)
67 {
68         struct tm *tm = gmtime(&dive->when);
69         return snprintf(buf, size, "Dive #%d - %s %02d/%02d/%04d at %d:%02d",
70                 dive->number,
71                 weekday(tm->tm_wday),
72                 tm->tm_mon+1, tm->tm_mday,
73                 tm->tm_year+1900,
74                 tm->tm_hour, tm->tm_min);
75 }
76
77 void show_dive_info(struct dive *dive)
78 {
79         const char *text;
80         char buffer[80];
81
82         /* dive number and location (or lacking that, the date) go in the window title */
83         text = dive->location;
84         if (!text)
85                 text = "";
86         if (*text) {
87                 snprintf(buffer, sizeof(buffer), "Dive #%d - %s", dive->number, text);
88         } else {
89                 divename(buffer, sizeof(buffer), dive);
90         }
91         text = buffer;
92         if (!dive->number)
93                 text += 10;     /* Skip the "Dive #0 - " part */
94         gtk_window_set_title(GTK_WINDOW(main_window), text);
95
96         SET_TEXT_VALUE(divemaster);
97         SET_TEXT_VALUE(buddy);
98         SET_TEXT_VALUE(location);
99         SET_TEXT_VALUE(suit);
100         gtk_entry_set_text(rating, star_strings[dive->rating]);
101         gtk_text_buffer_set_text(gtk_text_view_get_buffer(notes),
102                 dive && dive->notes ? dive->notes : "", -1);
103 }
104
105 static int delete_dive_info(struct dive *dive)
106 {
107         int success;
108         GtkWidget *dialog;
109
110         if (!dive)
111                 return 0;
112
113         dialog = gtk_dialog_new_with_buttons("Delete Dive",
114                 GTK_WINDOW(main_window),
115                 GTK_DIALOG_DESTROY_WITH_PARENT,
116                 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
117                 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
118                 NULL);
119
120         gtk_widget_show_all(dialog);
121         success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
122         if (success) {
123                 delete_dive(dive);
124                 mark_divelist_changed(TRUE);
125                 dive_list_update_dives();
126         }
127
128         gtk_widget_destroy(dialog);
129
130         return success;
131 }
132
133 static void info_menu_edit_cb(GtkMenuItem *menuitem, gpointer user_data)
134 {
135         edit_multi_dive_info(amount_selected, selectiontracker);
136 }
137
138 static void info_menu_delete_cb(GtkMenuItem *menuitem, gpointer user_data)
139 {
140         /* this needs to delete all the selected dives as well, I guess? */
141         delete_dive_info(current_dive);
142 }
143
144 static void add_menu_item(GtkMenu *menu, const char *label, void (*cb)(GtkMenuItem *, gpointer))
145 {
146         GtkWidget *item = gtk_menu_item_new_with_label(label);
147         g_signal_connect(item, "activate", G_CALLBACK(cb), NULL);
148         gtk_widget_show(item); /* Yes, really */
149         gtk_menu_prepend(menu, item);
150 }
151
152 static void populate_popup_cb(GtkTextView *entry, GtkMenu *menu, gpointer user_data)
153 {
154         add_menu_item(menu, "Delete", info_menu_delete_cb);
155         add_menu_item(menu, "Edit", info_menu_edit_cb);
156 }
157
158 static GtkEntry *text_value(GtkWidget *box, const char *label)
159 {
160         GtkWidget *widget;
161         GtkWidget *frame = gtk_frame_new(label);
162
163         gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0);
164         widget = gtk_entry_new();
165         gtk_widget_set_can_focus(widget, FALSE);
166         gtk_editable_set_editable(GTK_EDITABLE(widget), FALSE);
167         gtk_container_add(GTK_CONTAINER(frame), widget);
168         g_signal_connect(widget, "populate-popup", G_CALLBACK(populate_popup_cb), NULL);
169         return GTK_ENTRY(widget);
170 }
171
172 static GtkComboBoxEntry *text_entry(GtkWidget *box, const char *label, GtkListStore *completions, const char *text)
173 {
174         GtkEntry *entry;
175         GtkWidget *combo_box;
176         GtkWidget *frame = gtk_frame_new(label);
177         GtkEntryCompletion *completion;
178
179         gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0);
180
181         combo_box = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(completions), 0);
182         gtk_container_add(GTK_CONTAINER(frame), combo_box);
183
184         entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
185         if (text && *text)
186                 gtk_entry_set_text(entry, text);
187
188         completion = gtk_entry_completion_new();
189         gtk_entry_completion_set_text_column(completion, 0);
190         gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(completions));
191         gtk_entry_completion_set_inline_completion(completion, TRUE);
192         gtk_entry_completion_set_inline_selection(completion, TRUE);
193         gtk_entry_completion_set_popup_single_match(completion, FALSE);
194         gtk_entry_set_completion(entry, completion);
195
196         return GTK_COMBO_BOX_ENTRY(combo_box);
197 }
198
199 enum writable {
200         READ_ONLY,
201         READ_WRITE
202 };
203
204 static GtkTextView *text_view(GtkWidget *box, const char *label, enum writable writable)
205 {
206         GtkWidget *view, *vbox;
207         GtkWidget *frame = gtk_frame_new(label);
208
209         gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0);
210         box = gtk_hbox_new(FALSE, 3);
211         gtk_container_add(GTK_CONTAINER(frame), box);
212         vbox = gtk_vbox_new(FALSE, 3);
213         gtk_container_add(GTK_CONTAINER(box), vbox);
214
215         GtkWidget* scrolled_window = gtk_scrolled_window_new(0, 0);
216         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
217         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN);
218
219         view = gtk_text_view_new();
220         if (writable == READ_ONLY) {
221                 gtk_widget_set_can_focus(view, FALSE);
222                 gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE);
223                 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(view), FALSE);
224                 g_signal_connect(view, "populate-popup", G_CALLBACK(populate_popup_cb), NULL);
225         }
226         gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
227         gtk_container_add(GTK_CONTAINER(scrolled_window), view);
228         gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
229         return GTK_TEXT_VIEW(view);
230 }
231
232 static enum {
233         MATCH_EXACT,
234         MATCH_PREPEND,
235         MATCH_AFTER
236 } found_string_entry;
237 static GtkTreeIter string_entry_location;
238
239 static gboolean match_string_entry(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
240 {
241         const char *string = data;
242         char *entry;
243         int cmp;
244
245         gtk_tree_model_get(model, iter, 0, &entry, -1);
246         cmp = strcmp(entry, string);
247         if (entry)
248                 free(entry);
249
250         /* Stop. The entry is bigger than the new one */
251         if (cmp > 0)
252                 return TRUE;
253
254         /* Exact match */
255         if (!cmp) {
256                 found_string_entry = MATCH_EXACT;
257                 return TRUE;
258         }
259
260         string_entry_location = *iter;
261         found_string_entry = MATCH_AFTER;
262         return FALSE;
263 }
264
265 static int match_list(GtkListStore *list, const char *string)
266 {
267         found_string_entry = MATCH_PREPEND;
268         gtk_tree_model_foreach(GTK_TREE_MODEL(list), match_string_entry, (void *)string);
269         return found_string_entry;
270 }
271
272 static void add_string_list_entry(const char *string, GtkListStore *list)
273 {
274         GtkTreeIter *iter, loc;
275
276         if (!string || !*string)
277                 return;
278
279         switch (match_list(list, string)) {
280         case MATCH_EXACT:
281                 return;
282         case MATCH_PREPEND:
283                 iter = NULL;
284                 break;
285         case MATCH_AFTER:
286                 iter = &string_entry_location;
287                 break;
288         }
289         gtk_list_store_insert_after(list, &loc, iter);
290         gtk_list_store_set(list, &loc, 0, string, -1);
291 }
292
293 void add_people(const char *string)
294 {
295         add_string_list_entry(string, people_list);
296 }
297
298 void add_location(const char *string)
299 {
300         add_string_list_entry(string, location_list);
301 }
302
303 void add_suit(const char *string)
304 {
305         add_string_list_entry(string, suit_list);
306 }
307
308 static int get_rating(const char *string)
309 {
310         int rating_val = 0;
311         int i;
312
313         for (i = 0; i <= 5; i++)
314                 if (!strcmp(star_strings[i],string))
315                         rating_val = i;
316         return rating_val;
317 }
318
319 struct dive_info {
320         GtkComboBoxEntry *location, *divemaster, *buddy, *rating, *suit;
321         GtkTextView *notes;
322 };
323
324 static void save_dive_info_changes(struct dive *dive, struct dive_info *info)
325 {
326         char *old_text, *new_text;
327         char *rating_string;
328         int changed = 0;
329
330         new_text = get_combo_box_entry_text(info->location, &dive->location);
331         if (new_text) {
332                 add_location(new_text);
333                 changed = 1;
334         }
335
336         new_text = get_combo_box_entry_text(info->divemaster, &dive->divemaster);
337         if (new_text) {
338                 add_people(new_text);
339                 changed = 1;
340         }
341
342         new_text = get_combo_box_entry_text(info->buddy, &dive->buddy);
343         if (new_text) {
344                 add_people(new_text);
345                 changed = 1;
346         }
347
348         new_text = get_combo_box_entry_text(info->suit, &dive->suit);
349         if (new_text) {
350                 add_suit(new_text);
351                 changed = 1;
352         }
353
354         rating_string = strdup(star_strings[dive->rating]);
355         new_text = get_combo_box_entry_text(info->rating, &rating_string);
356         if (new_text) {
357                 dive->rating = get_rating(rating_string);
358                 free(rating_string);
359                 changed =1;
360         }
361
362         if (info->notes) {
363                 old_text = dive->notes;
364                 dive->notes = get_text(info->notes);
365                 if (text_changed(old_text,dive->notes))
366                         changed = 1;
367                 if (old_text)
368                         g_free(old_text);
369         }
370         if (changed) {
371                 mark_divelist_changed(TRUE);
372                 update_dive(dive);
373         }
374 }
375
376 static void dive_info_widget(GtkWidget *box, struct dive *dive, struct dive_info *info, gboolean multi)
377 {
378         GtkWidget *hbox, *label, *frame, *equipment;
379         char buffer[80] = "Edit multiple dives";
380
381         if (!multi)
382                 divename(buffer, sizeof(buffer), dive);
383         label = gtk_label_new(buffer);
384         gtk_box_pack_start(GTK_BOX(box), label, FALSE, TRUE, 0);
385
386         info->location = text_entry(box, "Location", location_list, dive->location);
387
388         hbox = gtk_hbox_new(FALSE, 3);
389         gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, TRUE, 0);
390
391         info->divemaster = text_entry(hbox, "Dive master", people_list, dive->divemaster);
392         info->buddy = text_entry(hbox, "Buddy", people_list, dive->buddy);
393
394         hbox = gtk_hbox_new(FALSE, 3);
395         gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, TRUE, 0);
396
397         info->rating = text_entry(hbox, "Rating", star_list, star_strings[dive->rating]);
398         info->suit = text_entry(hbox, "Suit", suit_list, dive->suit);
399
400         /* only show notes if editing a single dive */
401         if (multi) {
402                 info->notes = NULL;
403         } else {
404                 info->notes = text_view(box, "Notes", READ_WRITE);
405                 if (dive->notes && *dive->notes)
406                         gtk_text_buffer_set_text(gtk_text_view_get_buffer(info->notes), dive->notes, -1);
407         }
408         hbox = gtk_hbox_new(FALSE, 3);
409         gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, TRUE, 0);
410
411         /* create a secondary Equipment widget */
412         frame = gtk_frame_new("Equipment");
413         equipment = equipment_widget(W_IDX_SECONDARY);
414         gtk_container_add(GTK_CONTAINER(frame), equipment);
415         gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 0);
416 }
417
418 /* we use these to find out if we edited the cylinder or weightsystem entries */
419 static cylinder_t remember_cyl[MAX_CYLINDERS];
420 static weightsystem_t remember_ws[MAX_WEIGHTSYSTEMS];
421
422 void save_equipment_data(struct dive *dive)
423 {
424         if (dive) {
425                 memcpy(remember_cyl, dive->cylinder, sizeof(cylinder_t) * MAX_CYLINDERS);
426                 memcpy(remember_ws, dive->weightsystem, sizeof(weightsystem_t) * MAX_WEIGHTSYSTEMS);
427         }
428 }
429
430 void update_equipment_data(struct dive *dive, struct dive *master)
431 {
432         if (dive == master)
433                 return;
434         if (memcmp(remember_cyl, master->cylinder, sizeof(cylinder_t) * MAX_CYLINDERS)) {
435                 memcpy(dive->cylinder, master->cylinder, sizeof(cylinder_t) * MAX_CYLINDERS);
436         }
437         if (memcmp(remember_ws, master->weightsystem, sizeof(weightsystem_t) * MAX_WEIGHTSYSTEMS)) {
438                 memcpy(dive->weightsystem, master->weightsystem, sizeof(weightsystem_t) * MAX_WEIGHTSYSTEMS);
439         }
440 }
441
442 int edit_multi_dive_info(int nr, int *indices)
443 {
444         int success, i;
445         GtkWidget *dialog, *vbox;
446         struct dive_info info;
447         struct dive *dive;
448
449         if (!nr)
450                 return 0;
451         dialog = gtk_dialog_new_with_buttons("Dive Info",
452                 GTK_WINDOW(main_window),
453                 GTK_DIALOG_DESTROY_WITH_PARENT,
454                 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
455                 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
456                 NULL);
457
458         vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
459         /* SCARY STUFF - IS THIS THE BEST WAY TO DO THIS???
460          *
461          * current_dive is one of our selected dives - and that is
462          * the one that is used to pre-fill the edit widget. Its
463          * data is used as the starting point for all selected dives
464          * I think it would be better to somehow collect and combine
465          * info from all the selected dives */
466         dive = current_dive;
467         dive_info_widget(vbox, dive, &info, (nr > 1));
468         show_dive_equipment(dive, W_IDX_SECONDARY);
469         save_equipment_data(dive);
470         gtk_widget_show_all(dialog);
471         success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
472         if (success)
473                 for (i = 0; i < nr; i++) {
474                         int idx = indices[i];
475                         struct dive *n = get_dive(idx);
476
477                         if (!n)
478                                 continue;
479                         /* copy all "info" fields */
480                         save_dive_info_changes(n, &info);
481                         /* copy the cylinders / weightsystems */
482                         update_equipment_data(n, dive);
483                         /* this is extremely inefficient... it loops through all
484                            dives to find the right one - but we KNOW the index already */
485                         flush_divelist(n);
486                 }
487         gtk_widget_destroy(dialog);
488
489         return success;
490 }
491
492 int edit_dive_info(struct dive *dive)
493 {
494         int idx;
495
496         if (!dive)
497                 return 0;
498         idx = dive->number;
499         return edit_multi_dive_info(1, &idx);
500 }
501
502 static GtkWidget *frame_box(GtkWidget *vbox, const char *fmt, ...)
503 {
504         va_list ap;
505         char buffer[64];
506         GtkWidget *frame, *hbox;
507
508         va_start(ap, fmt);
509         vsnprintf(buffer, sizeof(buffer), fmt, ap);
510         va_end(ap);
511
512         frame = gtk_frame_new(buffer);
513         gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, TRUE, 0);
514         hbox = gtk_hbox_new(0, 3);
515         gtk_container_add(GTK_CONTAINER(frame), hbox);
516         return hbox;
517 }
518
519 /* Fixme - should do at least depths too - a dive without a depth is kind of pointless */
520 static time_t dive_time_widget(struct dive *dive)
521 {
522         GtkWidget *dialog;
523         GtkWidget *cal, *hbox, *vbox, *box;
524         GtkWidget *h, *m;
525         GtkWidget *duration, *depth;
526         GtkWidget *label;
527         guint yval, mval, dval;
528         struct tm tm, *tmp;
529         struct timeval tv;
530         time_t time;
531         int success;
532         double depthinterval, val;
533
534         dialog = gtk_dialog_new_with_buttons("Date and Time",
535                 GTK_WINDOW(main_window),
536                 GTK_DIALOG_DESTROY_WITH_PARENT,
537                 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
538                 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
539                 NULL);
540
541         vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
542
543         /* Calendar hbox */
544         hbox = frame_box(vbox, "Date:");
545         cal = gtk_calendar_new();
546         gtk_box_pack_start(GTK_BOX(hbox), cal, FALSE, TRUE, 0);
547
548         /* Time hbox */
549         hbox = frame_box(vbox, "Time");
550
551         h = gtk_spin_button_new_with_range (0.0, 23.0, 1.0);
552         m = gtk_spin_button_new_with_range (0.0, 59.0, 1.0);
553
554         gettimeofday(&tv, NULL);
555         time = tv.tv_sec;
556         tmp = localtime(&time);
557         gtk_spin_button_set_value(GTK_SPIN_BUTTON(h), tmp->tm_hour);
558         gtk_spin_button_set_value(GTK_SPIN_BUTTON(m), (tmp->tm_min / 5)*5);
559
560         gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(h), TRUE);
561         gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(m), TRUE);
562
563         gtk_box_pack_end(GTK_BOX(hbox), m, FALSE, FALSE, 0);
564         label = gtk_label_new(":");
565         gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
566         gtk_box_pack_end(GTK_BOX(hbox), h, FALSE, FALSE, 0);
567
568         hbox = gtk_hbox_new(TRUE, 3);
569         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
570
571         /* Duration hbox */
572         box = frame_box(hbox, "Duration (min)");
573         duration = gtk_spin_button_new_with_range (0.0, 1000.0, 1.0);
574         gtk_box_pack_end(GTK_BOX(box), duration, FALSE, FALSE, 0);
575
576         /* Depth box */
577         box = frame_box(hbox, "Depth (%s):", output_units.length == FEET ? "ft" : "m");
578         if (output_units.length == FEET) {
579                 depthinterval = 1.0;
580         } else {
581                 depthinterval = 0.1;
582         }
583         depth = gtk_spin_button_new_with_range (0.0, 1000.0, depthinterval);
584         gtk_box_pack_end(GTK_BOX(box), depth, FALSE, FALSE, 0);
585
586         /* All done, show it and wait for editing */
587         gtk_widget_show_all(dialog);
588         success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
589         if (!success) {
590                 gtk_widget_destroy(dialog);
591                 return 0;
592         }
593
594         memset(&tm, 0, sizeof(tm));
595         gtk_calendar_get_date(GTK_CALENDAR(cal), &yval, &mval, &dval);
596         tm.tm_year = yval;
597         tm.tm_mon = mval;
598         tm.tm_mday = dval;
599
600         tm.tm_hour = gtk_spin_button_get_value(GTK_SPIN_BUTTON(h));
601         tm.tm_min = gtk_spin_button_get_value(GTK_SPIN_BUTTON(m));
602
603         val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(depth));
604         if (output_units.length == FEET) {
605                 dive->maxdepth.mm = feet_to_mm(val);
606         } else {
607                 dive->maxdepth.mm = val * 1000 + 0.5;
608         }
609
610         dive->duration.seconds = gtk_spin_button_get_value(GTK_SPIN_BUTTON(duration))*60;
611
612         gtk_widget_destroy(dialog);
613         dive->when = utc_mktime(&tm);
614
615         return 1;
616 }
617
618 int add_new_dive(struct dive *dive)
619 {
620         if (!dive)
621                 return 0;
622
623         if (!dive_time_widget(dive))
624                 return 0;
625
626         return edit_dive_info(dive);
627 }
628
629 GtkWidget *extended_dive_info_widget(void)
630 {
631         GtkWidget *vbox, *hbox;
632         vbox = gtk_vbox_new(FALSE, 6);
633
634         people_list = gtk_list_store_new(1, G_TYPE_STRING);
635         location_list = gtk_list_store_new(1, G_TYPE_STRING);
636         star_list = gtk_list_store_new(1, G_TYPE_STRING);
637         add_string_list_entry(ZERO_STARS, star_list);
638         add_string_list_entry(ONE_STARS, star_list);
639         add_string_list_entry(TWO_STARS, star_list);
640         add_string_list_entry(THREE_STARS, star_list);
641         add_string_list_entry(FOUR_STARS, star_list);
642         add_string_list_entry(FIVE_STARS, star_list);
643         suit_list = gtk_list_store_new(1, G_TYPE_STRING);
644
645         gtk_container_set_border_width(GTK_CONTAINER(vbox), 6);
646         location = text_value(vbox, "Location");
647
648         hbox = gtk_hbox_new(FALSE, 3);
649         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
650
651         divemaster = text_value(hbox, "Divemaster");
652         buddy = text_value(hbox, "Buddy");
653
654         hbox = gtk_hbox_new(FALSE, 3);
655         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
656
657         rating = text_value(hbox, "Rating");
658         suit = text_value(hbox, "Suit");
659
660         notes = text_view(vbox, "Notes", READ_ONLY);
661         return vbox;
662 }