9 static GtkWidget *divedate, *divetime, *depth, *duration, *temperature, *locationnote;
10 static GtkTextBuffer *location, *notes;
11 static int location_changed = 1, notes_changed = 1;
12 static struct dive *buffered_dive;
14 static const char *weekday(int wday)
16 static const char wday_array[7][4] = {
17 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
19 return wday_array[wday];
22 static char *get_text(GtkTextBuffer *buffer)
27 gtk_text_buffer_get_start_iter(buffer, &start);
28 gtk_text_buffer_get_end_iter(buffer, &end);
29 return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
32 void flush_dive_info_changes(void)
34 struct dive *dive = buffered_dive;
39 if (location_changed) {
40 g_free(dive->location);
41 dive->location = get_text(location);
46 dive->notes = get_text(notes);
50 void update_dive_info(struct dive *dive)
56 flush_dive_info_changes();
60 gtk_label_set_text(GTK_LABEL(divedate), "no dive");
61 gtk_label_set_text(GTK_LABEL(divetime), "");
62 gtk_label_set_text(GTK_LABEL(depth), "");
63 gtk_label_set_text(GTK_LABEL(duration), "");
67 tm = gmtime(&dive->when);
68 snprintf(buffer, sizeof(buffer),
71 tm->tm_mon+1, tm->tm_mday, tm->tm_year+1900);
72 gtk_label_set_text(GTK_LABEL(divedate), buffer);
74 snprintf(buffer, sizeof(buffer),
76 tm->tm_hour, tm->tm_min, tm->tm_sec);
77 gtk_label_set_text(GTK_LABEL(divetime), buffer);
79 snprintf(buffer, sizeof(buffer),
81 to_feet(dive->maxdepth));
82 gtk_label_set_text(GTK_LABEL(depth), buffer);
84 snprintf(buffer, sizeof(buffer),
86 dive->duration.seconds / 60);
87 gtk_label_set_text(GTK_LABEL(duration), buffer);
90 if (dive->watertemp.mkelvin)
91 snprintf(buffer, sizeof(buffer),
93 to_C(dive->watertemp));
94 gtk_label_set_text(GTK_LABEL(temperature), buffer);
96 text = dive->location ? : "";
97 gtk_text_buffer_set_text(location, text, -1);
98 gtk_label_set_text(GTK_LABEL(locationnote), text);
100 text = dive->notes ? : "";
101 gtk_text_buffer_set_text(notes, text, -1);
104 static GtkWidget *info_label(GtkWidget *box, const char *str, GtkJustification jtype)
106 GtkWidget *label = gtk_label_new(str);
107 gtk_label_set_justify(GTK_LABEL(label), jtype);
108 gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
112 GtkWidget *dive_info_frame(void)
115 GtkWidget *hbox, *hbox2;
118 frame = gtk_frame_new("Dive info");
119 gtk_widget_show(frame);
121 vbox = gtk_vbox_new(TRUE, 5);
122 gtk_container_set_border_width(GTK_CONTAINER(vbox), 3);
123 gtk_container_add(GTK_CONTAINER(frame), vbox);
125 hbox = gtk_hbox_new(TRUE, 5);
126 gtk_container_set_border_width(GTK_CONTAINER(hbox), 3);
127 gtk_container_add(GTK_CONTAINER(vbox), hbox);
129 hbox2 = gtk_hbox_new(FALSE, 0);
130 gtk_container_set_border_width(GTK_CONTAINER(hbox2), 3);
131 gtk_container_add(GTK_CONTAINER(vbox), hbox2);
133 divedate = info_label(hbox, "date", GTK_JUSTIFY_RIGHT);
134 divetime = info_label(hbox, "time", GTK_JUSTIFY_RIGHT);
135 depth = info_label(hbox, "depth", GTK_JUSTIFY_RIGHT);
136 duration = info_label(hbox, "duration", GTK_JUSTIFY_RIGHT);
137 temperature = info_label(hbox, "temperature", GTK_JUSTIFY_RIGHT);
139 locationnote = info_label(hbox2, "location", GTK_JUSTIFY_LEFT);
140 gtk_label_set_width_chars(GTK_LABEL(locationnote), 80);
145 static GtkTextBuffer *text_entry(GtkWidget *box, const char *label, gboolean expand)
148 GtkTextBuffer *buffer;
150 GtkWidget *frame = gtk_frame_new(label);
152 gtk_box_pack_start(GTK_BOX(box), frame, expand, expand, 0);
154 view = gtk_text_view_new ();
155 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
157 gtk_container_add(GTK_CONTAINER(frame), view);
161 GtkWidget *extended_dive_info_frame(void)
166 frame = gtk_frame_new("Extended dive info");
167 gtk_widget_show(frame);
169 vbox = gtk_vbox_new(FALSE, 5);
170 gtk_container_add(GTK_CONTAINER(frame), vbox);
172 location = text_entry(vbox, "Location", FALSE);
173 notes = text_entry(vbox, "Notes", TRUE);
175 /* Add extended info here: name, description, yadda yadda */
176 update_dive_info(current_dive);