8 static GtkWidget *divedate, *divetime, *depth, *duration;
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);
88 text = dive->location ? : "";
89 gtk_text_buffer_set_text(location, text, -1);
90 text = dive->notes ? : "";
91 gtk_text_buffer_set_text(notes, text, -1);
94 static GtkWidget *info_label(GtkWidget *box, const char *str)
96 GtkWidget *label = gtk_label_new(str);
97 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT);
98 gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
102 GtkWidget *dive_info_frame(void)
107 frame = gtk_frame_new("Dive info");
108 gtk_widget_show(frame);
110 hbox = gtk_hbox_new(TRUE, 5);
111 gtk_container_set_border_width(GTK_CONTAINER(hbox), 3);
112 gtk_container_add(GTK_CONTAINER(frame), hbox);
114 divedate = info_label(hbox, "date");
115 divetime = info_label(hbox, "time");
116 depth = info_label(hbox, "depth");
117 duration = info_label(hbox, "duration");
122 static GtkTextBuffer *text_entry(GtkWidget *box, const char *label, gboolean expand)
125 GtkTextBuffer *buffer;
127 GtkWidget *frame = gtk_frame_new(label);
129 gtk_box_pack_start(GTK_BOX(box), frame, expand, expand, 0);
131 view = gtk_text_view_new ();
132 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
134 gtk_container_add(GTK_CONTAINER(frame), view);
138 GtkWidget *extended_dive_info_frame(void)
143 frame = gtk_frame_new("Extended dive info");
144 gtk_widget_show(frame);
146 vbox = gtk_vbox_new(FALSE, 5);
147 gtk_container_add(GTK_CONTAINER(frame), vbox);
149 location = text_entry(vbox, "Location", FALSE);
150 notes = text_entry(vbox, "Notes", TRUE);
152 /* Add extended info here: name, description, yadda yadda */
153 update_dive_info(current_dive);