10 static GtkWidget *info_frame;
11 static GtkWidget *divedate, *divetime, *depth, *duration, *temperature;
12 static GtkEntry *location;
13 static GtkTextBuffer *notes;
14 static int location_changed = 1, notes_changed = 1;
16 static const char *weekday(int wday)
18 static const char wday_array[7][4] = {
19 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
21 return wday_array[wday];
24 static char *get_text(GtkTextBuffer *buffer)
29 gtk_text_buffer_get_start_iter(buffer, &start);
30 gtk_text_buffer_get_end_iter(buffer, &end);
31 return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
34 void flush_dive_info_changes(struct dive *dive)
39 if (location_changed) {
40 g_free(dive->location);
41 dive->location = gtk_editable_get_chars(GTK_EDITABLE(location), 0, -1);
46 dive->notes = get_text(notes);
50 void show_dive_info(struct dive *dive)
58 gtk_label_set_text(GTK_LABEL(divedate), "no dive");
59 gtk_label_set_text(GTK_LABEL(divetime), "");
60 gtk_label_set_text(GTK_LABEL(depth), "");
61 gtk_label_set_text(GTK_LABEL(duration), "");
65 tm = gmtime(&dive->when);
66 snprintf(buffer, sizeof(buffer),
69 tm->tm_mon+1, tm->tm_mday, tm->tm_year+1900);
70 gtk_label_set_text(GTK_LABEL(divedate), buffer);
72 snprintf(buffer, sizeof(buffer),
74 tm->tm_hour, tm->tm_min, tm->tm_sec);
75 gtk_label_set_text(GTK_LABEL(divetime), buffer);
77 switch (output_units.length) {
79 snprintf(buffer, sizeof(buffer),
81 dive->maxdepth.mm / 1000.0);
84 snprintf(buffer, sizeof(buffer),
86 to_feet(dive->maxdepth));
89 gtk_label_set_text(GTK_LABEL(depth), buffer);
91 snprintf(buffer, sizeof(buffer),
93 dive->duration.seconds / 60);
94 gtk_label_set_text(GTK_LABEL(duration), buffer);
97 if (dive->watertemp.mkelvin) {
98 switch (output_units.temperature) {
100 snprintf(buffer, sizeof(buffer),
102 to_C(dive->watertemp));
105 snprintf(buffer, sizeof(buffer),
107 to_F(dive->watertemp));
110 snprintf(buffer, sizeof(buffer),
112 to_K(dive->watertemp));
116 gtk_label_set_text(GTK_LABEL(temperature), buffer);
118 text = dive->location ? : "";
119 gtk_entry_set_text(location, text);
122 if (dive->location && *dive->location)
123 text = dive->location;
126 len = snprintf(buffer, sizeof(buffer), "%d. ", dive->number);
127 snprintf(buffer+len, sizeof(buffer)-len, "%s", text);
128 gtk_frame_set_label(GTK_FRAME(info_frame), buffer);
130 text = dive->notes ? : "";
131 gtk_text_buffer_set_text(notes, text, -1);
134 static GtkWidget *info_label(GtkWidget *box, const char *str, GtkJustification jtype)
136 GtkWidget *label = gtk_label_new(str);
137 gtk_label_set_justify(GTK_LABEL(label), jtype);
138 gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
142 GtkWidget *dive_info_frame(void)
148 frame = gtk_frame_new("Dive info");
150 gtk_widget_show(frame);
152 vbox = gtk_vbox_new(FALSE, 6);
153 gtk_container_set_border_width(GTK_CONTAINER(vbox), 3);
154 gtk_container_add(GTK_CONTAINER(frame), vbox);
156 hbox = gtk_hbox_new(FALSE, 16);
157 gtk_container_set_border_width(GTK_CONTAINER(hbox), 3);
158 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
160 divedate = info_label(hbox, "date", GTK_JUSTIFY_RIGHT);
161 divetime = info_label(hbox, "time", GTK_JUSTIFY_RIGHT);
162 depth = info_label(hbox, "depth", GTK_JUSTIFY_RIGHT);
163 duration = info_label(hbox, "duration", GTK_JUSTIFY_RIGHT);
164 temperature = info_label(hbox, "temperature", GTK_JUSTIFY_RIGHT);
169 static GtkEntry *text_entry(GtkWidget *box, const char *label)
172 GtkWidget *frame = gtk_frame_new(label);
174 gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0);
176 entry = gtk_entry_new();
177 gtk_container_add(GTK_CONTAINER(frame), entry);
179 return GTK_ENTRY(entry);
182 static GtkTextBuffer *text_view(GtkWidget *box, const char *label)
184 GtkWidget *view, *vbox;
185 GtkTextBuffer *buffer;
186 GtkWidget *frame = gtk_frame_new(label);
188 gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0);
189 box = gtk_hbox_new(FALSE, 3);
190 gtk_container_add(GTK_CONTAINER(frame), box);
191 vbox = gtk_vbox_new(FALSE, 3);
192 gtk_container_add(GTK_CONTAINER(box), vbox);
194 GtkWidget* scrolled_window = gtk_scrolled_window_new(0, 0);
195 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
196 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN);
197 gtk_widget_show(scrolled_window);
199 view = gtk_text_view_new();
200 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
201 gtk_container_add(GTK_CONTAINER(scrolled_window), view);
203 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
205 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
209 GtkWidget *extended_dive_info_widget(void)
212 vbox = gtk_vbox_new(FALSE, 6);
214 location = text_entry(vbox, "Location");
215 gtk_container_set_border_width(GTK_CONTAINER(vbox), 6);
216 notes = text_view(vbox, "Notes");
218 /* Add extended info here: name, description, yadda yadda */
219 show_dive_info(current_dive);