8 static GtkWidget *divedate, *divetime, *depth, *duration, *temperature;
9 static GtkTextBuffer *location, *notes;
10 static int location_changed = 1, notes_changed = 1;
11 static struct dive *buffered_dive;
13 static const char *weekday(int wday)
15 static const char wday_array[7][4] = {
16 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
18 return wday_array[wday];
21 static char *get_text(GtkTextBuffer *buffer)
26 gtk_text_buffer_get_start_iter(buffer, &start);
27 gtk_text_buffer_get_end_iter(buffer, &end);
28 return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
31 void flush_dive_info_changes(void)
33 struct dive *dive = buffered_dive;
38 if (location_changed) {
39 g_free(dive->location);
40 dive->location = get_text(location);
45 dive->notes = get_text(notes);
49 void update_dive_info(struct dive *dive)
55 flush_dive_info_changes();
59 gtk_label_set_text(GTK_LABEL(divedate), "no dive");
60 gtk_label_set_text(GTK_LABEL(divetime), "");
61 gtk_label_set_text(GTK_LABEL(depth), "");
62 gtk_label_set_text(GTK_LABEL(duration), "");
66 tm = gmtime(&dive->when);
67 snprintf(buffer, sizeof(buffer),
70 tm->tm_mon+1, tm->tm_mday, tm->tm_year+1900);
71 gtk_label_set_text(GTK_LABEL(divedate), buffer);
73 snprintf(buffer, sizeof(buffer),
75 tm->tm_hour, tm->tm_min, tm->tm_sec);
76 gtk_label_set_text(GTK_LABEL(divetime), buffer);
78 snprintf(buffer, sizeof(buffer),
80 to_feet(dive->maxdepth));
81 gtk_label_set_text(GTK_LABEL(depth), buffer);
83 snprintf(buffer, sizeof(buffer),
85 dive->duration.seconds / 60);
86 gtk_label_set_text(GTK_LABEL(duration), buffer);
89 if (dive->watertemp.mkelvin)
90 snprintf(buffer, sizeof(buffer),
92 to_C(dive->watertemp));
93 gtk_label_set_text(GTK_LABEL(temperature), buffer);
95 text = dive->location ? : "";
96 gtk_text_buffer_set_text(location, text, -1);
97 text = dive->notes ? : "";
98 gtk_text_buffer_set_text(notes, text, -1);
101 static GtkWidget *info_label(GtkWidget *box, const char *str)
103 GtkWidget *label = gtk_label_new(str);
104 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT);
105 gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
109 GtkWidget *dive_info_frame(void)
114 frame = gtk_frame_new("Dive info");
115 gtk_widget_show(frame);
117 hbox = gtk_hbox_new(TRUE, 5);
118 gtk_container_set_border_width(GTK_CONTAINER(hbox), 3);
119 gtk_container_add(GTK_CONTAINER(frame), hbox);
121 divedate = info_label(hbox, "date");
122 divetime = info_label(hbox, "time");
123 depth = info_label(hbox, "depth");
124 duration = info_label(hbox, "duration");
125 temperature = info_label(hbox, "temperature");
130 static GtkTextBuffer *text_entry(GtkWidget *box, const char *label, gboolean expand)
133 GtkTextBuffer *buffer;
135 GtkWidget *frame = gtk_frame_new(label);
137 gtk_box_pack_start(GTK_BOX(box), frame, expand, expand, 0);
139 view = gtk_text_view_new ();
140 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
142 gtk_container_add(GTK_CONTAINER(frame), view);
146 GtkWidget *extended_dive_info_frame(void)
151 frame = gtk_frame_new("Extended dive info");
152 gtk_widget_show(frame);
154 vbox = gtk_vbox_new(FALSE, 5);
155 gtk_container_add(GTK_CONTAINER(frame), vbox);
157 location = text_entry(vbox, "Location", FALSE);
158 notes = text_entry(vbox, "Notes", TRUE);
160 /* Add extended info here: name, description, yadda yadda */
161 update_dive_info(current_dive);