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