10 static GtkWidget *info_frame;
11 static GtkWidget *depth, *duration, *temperature, *airconsumption;
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)
68 gtk_label_set_text(GTK_LABEL(depth), "");
69 gtk_label_set_text(GTK_LABEL(duration), "");
70 gtk_label_set_text(GTK_LABEL(airconsumption), "");
73 /* dive number and location (or lacking that, the date) go in the window title */
74 tm = gmtime(&dive->when);
75 text = dive->location;
79 snprintf(buffer, sizeof(buffer), "Dive #%d - %s", dive->number, text);
81 snprintf(buffer, sizeof(buffer), "Dive #%d - %s %02d/%02d/%04d at %d:%02d",
84 tm->tm_mon+1, tm->tm_mday,
86 tm->tm_hour, tm->tm_min);
90 text += 10; /* Skip the "Dive #0 - " part */
91 gtk_window_set_title(GTK_WINDOW(main_window), text);
93 /* the date goes in the frame label */
94 snprintf(buffer, sizeof(buffer), "%s %02d/%02d/%04d at %d:%02d",
96 tm->tm_mon+1, tm->tm_mday,
98 tm->tm_hour, tm->tm_min);
99 gtk_frame_set_label(GTK_FRAME(info_frame), buffer);
102 switch (output_units.length) {
104 snprintf(buffer, sizeof(buffer),
106 dive->maxdepth.mm / 1000.0);
109 snprintf(buffer, sizeof(buffer),
111 to_feet(dive->maxdepth));
114 gtk_label_set_text(GTK_LABEL(depth), buffer);
116 snprintf(buffer, sizeof(buffer),
118 dive->duration.seconds / 60);
119 gtk_label_set_text(GTK_LABEL(duration), buffer);
122 if (dive->watertemp.mkelvin) {
123 switch (output_units.temperature) {
125 snprintf(buffer, sizeof(buffer),
127 to_C(dive->watertemp));
130 snprintf(buffer, sizeof(buffer),
132 to_F(dive->watertemp));
135 snprintf(buffer, sizeof(buffer),
137 to_K(dive->watertemp));
141 gtk_label_set_text(GTK_LABEL(temperature), buffer);
143 text = dive->location ? : "";
144 gtk_entry_set_text(location, text);
146 text = dive->divemaster ? : "";
147 gtk_entry_set_text(divemaster, text);
149 text = dive->buddy ? : "";
150 gtk_entry_set_text(buddy, text);
152 text = dive->notes ? : "";
153 gtk_text_buffer_set_text(notes, text, -1);
156 static GtkWidget *info_label(GtkWidget *box, const char *str, GtkJustification jtype)
158 GtkWidget *label = gtk_label_new(str);
159 gtk_label_set_justify(GTK_LABEL(label), jtype);
160 gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
164 GtkWidget *dive_info_frame(void)
170 frame = gtk_frame_new("Dive info");
172 gtk_widget_show(frame);
174 vbox = gtk_vbox_new(FALSE, 6);
175 gtk_container_set_border_width(GTK_CONTAINER(vbox), 3);
176 gtk_container_add(GTK_CONTAINER(frame), vbox);
178 hbox = gtk_hbox_new(FALSE, 16);
179 gtk_container_set_border_width(GTK_CONTAINER(hbox), 3);
180 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
182 depth = info_label(hbox, "depth", GTK_JUSTIFY_RIGHT);
183 duration = info_label(hbox, "duration", GTK_JUSTIFY_RIGHT);
184 temperature = info_label(hbox, "temperature", GTK_JUSTIFY_RIGHT);
185 airconsumption = info_label(hbox, "air", GTK_JUSTIFY_RIGHT);
190 void update_air_info(char *buffer)
194 snprintf(markup, sizeof(markup), "<span font=\"8\">%s</span>",buffer);
195 gtk_label_set_markup(GTK_LABEL(airconsumption), markup);
198 static GtkEntry *text_entry(GtkWidget *box, const char *label)
201 GtkWidget *frame = gtk_frame_new(label);
203 gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0);
205 entry = gtk_entry_new();
206 gtk_container_add(GTK_CONTAINER(frame), entry);
208 return GTK_ENTRY(entry);
211 static GtkTextBuffer *text_view(GtkWidget *box, const char *label)
213 GtkWidget *view, *vbox;
214 GtkTextBuffer *buffer;
215 GtkWidget *frame = gtk_frame_new(label);
217 gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0);
218 box = gtk_hbox_new(FALSE, 3);
219 gtk_container_add(GTK_CONTAINER(frame), box);
220 vbox = gtk_vbox_new(FALSE, 3);
221 gtk_container_add(GTK_CONTAINER(box), vbox);
223 GtkWidget* scrolled_window = gtk_scrolled_window_new(0, 0);
224 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
225 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN);
226 gtk_widget_show(scrolled_window);
228 view = gtk_text_view_new();
229 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
230 gtk_container_add(GTK_CONTAINER(scrolled_window), view);
232 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
234 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
238 GtkWidget *extended_dive_info_widget(void)
240 GtkWidget *vbox, *hbox;
241 vbox = gtk_vbox_new(FALSE, 6);
243 gtk_container_set_border_width(GTK_CONTAINER(vbox), 6);
244 location = text_entry(vbox, "Location");
246 hbox = gtk_hbox_new(FALSE, 3);
247 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
249 divemaster = text_entry(hbox, "Divemaster");
250 buddy = text_entry(hbox, "Buddy");
252 notes = text_view(vbox, "Notes");
254 /* Add extended info here: name, description, yadda yadda */
255 show_dive_info(current_dive);