10 static GtkWidget *info_frame;
11 static GtkWidget *divedate, *divetime, *depth, *duration, *temperature;
12 static GtkEntry *location, *buddy, *divemaster;
13 static GtkTextBuffer *notes;
14 static int location_changed = 1, notes_changed = 1;
15 static int divemaster_changed = 1, buddy_changed = 1;
17 static const char *weekday(int wday)
19 static const char wday_array[7][4] = {
20 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
22 return wday_array[wday];
25 static char *get_text(GtkTextBuffer *buffer)
30 gtk_text_buffer_get_start_iter(buffer, &start);
31 gtk_text_buffer_get_end_iter(buffer, &end);
32 return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
35 void flush_dive_info_changes(struct dive *dive)
40 if (location_changed) {
41 g_free(dive->location);
42 dive->location = gtk_editable_get_chars(GTK_EDITABLE(location), 0, -1);
45 if (divemaster_changed) {
46 g_free(dive->divemaster);
47 dive->divemaster = gtk_editable_get_chars(GTK_EDITABLE(divemaster), 0, -1);
52 dive->buddy = gtk_editable_get_chars(GTK_EDITABLE(buddy), 0, -1);
57 dive->notes = get_text(notes);
61 void show_dive_info(struct dive *dive)
69 gtk_label_set_text(GTK_LABEL(divedate), "no dive");
70 gtk_label_set_text(GTK_LABEL(divetime), "");
71 gtk_label_set_text(GTK_LABEL(depth), "");
72 gtk_label_set_text(GTK_LABEL(duration), "");
76 tm = gmtime(&dive->when);
77 snprintf(buffer, sizeof(buffer),
80 tm->tm_mon+1, tm->tm_mday, tm->tm_year+1900);
81 gtk_label_set_text(GTK_LABEL(divedate), buffer);
83 snprintf(buffer, sizeof(buffer),
85 tm->tm_hour, tm->tm_min, tm->tm_sec);
86 gtk_label_set_text(GTK_LABEL(divetime), buffer);
88 switch (output_units.length) {
90 snprintf(buffer, sizeof(buffer),
92 dive->maxdepth.mm / 1000.0);
95 snprintf(buffer, sizeof(buffer),
97 to_feet(dive->maxdepth));
100 gtk_label_set_text(GTK_LABEL(depth), buffer);
102 snprintf(buffer, sizeof(buffer),
104 dive->duration.seconds / 60);
105 gtk_label_set_text(GTK_LABEL(duration), buffer);
108 if (dive->watertemp.mkelvin) {
109 switch (output_units.temperature) {
111 snprintf(buffer, sizeof(buffer),
113 to_C(dive->watertemp));
116 snprintf(buffer, sizeof(buffer),
118 to_F(dive->watertemp));
121 snprintf(buffer, sizeof(buffer),
123 to_K(dive->watertemp));
127 gtk_label_set_text(GTK_LABEL(temperature), buffer);
129 text = dive->location ? : "";
130 gtk_entry_set_text(location, text);
132 text = dive->divemaster ? : "";
133 gtk_entry_set_text(divemaster, text);
135 text = dive->buddy ? : "";
136 gtk_entry_set_text(buddy, text);
139 if (dive->location && *dive->location)
140 text = dive->location;
143 len = snprintf(buffer, sizeof(buffer), "%d. ", dive->number);
144 snprintf(buffer+len, sizeof(buffer)-len, "%s", text);
145 gtk_frame_set_label(GTK_FRAME(info_frame), buffer);
147 text = dive->notes ? : "";
148 gtk_text_buffer_set_text(notes, text, -1);
151 static GtkWidget *info_label(GtkWidget *box, const char *str, GtkJustification jtype)
153 GtkWidget *label = gtk_label_new(str);
154 gtk_label_set_justify(GTK_LABEL(label), jtype);
155 gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
159 GtkWidget *dive_info_frame(void)
165 frame = gtk_frame_new("Dive info");
167 gtk_widget_show(frame);
169 vbox = gtk_vbox_new(FALSE, 6);
170 gtk_container_set_border_width(GTK_CONTAINER(vbox), 3);
171 gtk_container_add(GTK_CONTAINER(frame), vbox);
173 hbox = gtk_hbox_new(FALSE, 16);
174 gtk_container_set_border_width(GTK_CONTAINER(hbox), 3);
175 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
177 divedate = info_label(hbox, "date", GTK_JUSTIFY_RIGHT);
178 divetime = info_label(hbox, "time", GTK_JUSTIFY_RIGHT);
179 depth = info_label(hbox, "depth", GTK_JUSTIFY_RIGHT);
180 duration = info_label(hbox, "duration", GTK_JUSTIFY_RIGHT);
181 temperature = info_label(hbox, "temperature", GTK_JUSTIFY_RIGHT);
186 static GtkEntry *text_entry(GtkWidget *box, const char *label)
189 GtkWidget *frame = gtk_frame_new(label);
191 gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0);
193 entry = gtk_entry_new();
194 gtk_container_add(GTK_CONTAINER(frame), entry);
196 return GTK_ENTRY(entry);
199 static GtkTextBuffer *text_view(GtkWidget *box, const char *label)
201 GtkWidget *view, *vbox;
202 GtkTextBuffer *buffer;
203 GtkWidget *frame = gtk_frame_new(label);
205 gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0);
206 box = gtk_hbox_new(FALSE, 3);
207 gtk_container_add(GTK_CONTAINER(frame), box);
208 vbox = gtk_vbox_new(FALSE, 3);
209 gtk_container_add(GTK_CONTAINER(box), vbox);
211 GtkWidget* scrolled_window = gtk_scrolled_window_new(0, 0);
212 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
213 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN);
214 gtk_widget_show(scrolled_window);
216 view = gtk_text_view_new();
217 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
218 gtk_container_add(GTK_CONTAINER(scrolled_window), view);
220 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
222 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
226 GtkWidget *extended_dive_info_widget(void)
228 GtkWidget *vbox, *hbox;
229 vbox = gtk_vbox_new(FALSE, 6);
231 gtk_container_set_border_width(GTK_CONTAINER(vbox), 6);
232 location = text_entry(vbox, "Location");
234 hbox = gtk_hbox_new(FALSE, 3);
235 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
237 divemaster = text_entry(hbox, "Divemaster");
238 buddy = text_entry(hbox, "Buddy");
240 notes = text_view(vbox, "Notes");
242 /* Add extended info here: name, description, yadda yadda */
243 show_dive_info(current_dive);