]> git.tdb.fi Git - ext/subsurface.git/blob - info.c
Add some more dive info - and actually update it
[ext/subsurface.git] / info.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <time.h>
4
5 #include "dive.h"
6 #include "display.h"
7
8 static GtkWidget *datetime, *depth, *duration;
9
10 void update_dive_info(struct dive *dive)
11 {
12         struct tm *tm;
13         char buffer[80];
14
15         tm = gmtime(&dive->when);
16         snprintf(buffer, sizeof(buffer),
17                 "%04d-%02d-%02d "
18                 "%02d:%02d:%02d",
19                 tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
20                 tm->tm_hour, tm->tm_min, tm->tm_sec);
21         gtk_entry_set_text(GTK_ENTRY(datetime), buffer);
22
23         snprintf(buffer, sizeof(buffer),
24                 "%d ft",
25                 to_feet(dive->maxdepth));
26         gtk_entry_set_text(GTK_ENTRY(depth), buffer);
27
28         snprintf(buffer, sizeof(buffer),
29                 "%d min",
30                 dive->duration.seconds / 60);
31         gtk_entry_set_text(GTK_ENTRY(duration), buffer);
32 }
33
34 GtkWidget *dive_info_frame(void)
35 {
36         GtkWidget *frame;
37         GtkWidget *hbox;
38
39         frame = gtk_frame_new("Dive info");
40         gtk_widget_show(frame);
41
42         hbox = gtk_hbox_new(FALSE, 5);
43         gtk_container_add(GTK_CONTAINER(frame), hbox);
44
45         datetime = gtk_entry_new();
46         gtk_editable_set_editable(GTK_EDITABLE(datetime), FALSE);
47
48         gtk_box_pack_start(GTK_BOX(hbox), datetime, FALSE, FALSE, 0);
49
50         depth = gtk_entry_new();
51         gtk_editable_set_editable(GTK_EDITABLE(depth), FALSE);
52
53         gtk_box_pack_start(GTK_BOX(hbox), depth, FALSE, FALSE, 0);
54
55         duration = gtk_entry_new();
56         gtk_editable_set_editable(GTK_EDITABLE(duration), FALSE);
57
58         gtk_box_pack_start(GTK_BOX(hbox), duration, FALSE, FALSE, 0);
59
60         update_dive_info(current_dive);
61         return frame;
62 }