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