10 static GtkWidget *divedate, *divetime, *depth, *duration, *temperature, *locationnote;
11 static GtkEntry *location;
12 static GtkTextBuffer *notes;
13 static int location_changed = 1, notes_changed = 1;
15 static const char *weekday(int wday)
17 static const char wday_array[7][4] = {
18 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
20 return wday_array[wday];
23 static char *get_text(GtkTextBuffer *buffer)
28 gtk_text_buffer_get_start_iter(buffer, &start);
29 gtk_text_buffer_get_end_iter(buffer, &end);
30 return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
33 void flush_dive_info_changes(struct dive *dive)
38 if (location_changed) {
39 g_free(dive->location);
40 dive->location = gtk_editable_get_chars(GTK_EDITABLE(location), 0, -1);
45 dive->notes = get_text(notes);
49 void show_dive_info(struct dive *dive)
57 gtk_label_set_text(GTK_LABEL(divedate), "no dive");
58 gtk_label_set_text(GTK_LABEL(divetime), "");
59 gtk_label_set_text(GTK_LABEL(depth), "");
60 gtk_label_set_text(GTK_LABEL(duration), "");
64 tm = gmtime(&dive->when);
65 snprintf(buffer, sizeof(buffer),
68 tm->tm_mon+1, tm->tm_mday, tm->tm_year+1900);
69 gtk_label_set_text(GTK_LABEL(divedate), buffer);
71 snprintf(buffer, sizeof(buffer),
73 tm->tm_hour, tm->tm_min, tm->tm_sec);
74 gtk_label_set_text(GTK_LABEL(divetime), buffer);
76 switch (output_units.length) {
78 snprintf(buffer, sizeof(buffer),
80 dive->maxdepth.mm / 1000.0);
83 snprintf(buffer, sizeof(buffer),
85 to_feet(dive->maxdepth));
88 gtk_label_set_text(GTK_LABEL(depth), buffer);
90 snprintf(buffer, sizeof(buffer),
92 dive->duration.seconds / 60);
93 gtk_label_set_text(GTK_LABEL(duration), buffer);
96 if (dive->watertemp.mkelvin) {
97 switch (output_units.temperature) {
99 snprintf(buffer, sizeof(buffer),
101 to_C(dive->watertemp));
104 snprintf(buffer, sizeof(buffer),
106 to_F(dive->watertemp));
109 snprintf(buffer, sizeof(buffer),
111 to_K(dive->watertemp));
115 gtk_label_set_text(GTK_LABEL(temperature), buffer);
117 text = dive->location ? : "";
118 gtk_entry_set_text(location, text);
122 len = snprintf(buffer, sizeof(buffer), "%d. ", dive->nr);
123 snprintf(buffer+len, sizeof(buffer)-len, "%s", text);
124 gtk_label_set_text(GTK_LABEL(locationnote), buffer);
126 text = dive->notes ? : "";
127 gtk_text_buffer_set_text(notes, text, -1);
130 static GtkWidget *info_label(GtkWidget *box, const char *str, GtkJustification jtype)
132 GtkWidget *label = gtk_label_new(str);
133 gtk_label_set_justify(GTK_LABEL(label), jtype);
134 gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
138 GtkWidget *dive_info_frame(void)
141 GtkWidget *hbox, *hbox2;
144 frame = gtk_frame_new("Dive info");
145 gtk_widget_show(frame);
147 vbox = gtk_vbox_new(TRUE, 6);
148 gtk_container_set_border_width(GTK_CONTAINER(vbox), 3);
149 gtk_container_add(GTK_CONTAINER(frame), vbox);
151 hbox = gtk_hbox_new(TRUE, 6);
152 gtk_container_set_border_width(GTK_CONTAINER(hbox), 3);
153 gtk_container_add(GTK_CONTAINER(vbox), hbox);
155 hbox2 = gtk_hbox_new(FALSE, 6);
156 gtk_container_set_border_width(GTK_CONTAINER(hbox2), 3);
157 gtk_container_add(GTK_CONTAINER(vbox), hbox2);
159 divedate = info_label(hbox, "date", GTK_JUSTIFY_RIGHT);
160 divetime = info_label(hbox, "time", GTK_JUSTIFY_RIGHT);
161 depth = info_label(hbox, "depth", GTK_JUSTIFY_RIGHT);
162 duration = info_label(hbox, "duration", GTK_JUSTIFY_RIGHT);
163 temperature = info_label(hbox, "temperature", GTK_JUSTIFY_RIGHT);
165 locationnote = info_label(hbox2, "location", GTK_JUSTIFY_LEFT);
166 gtk_label_set_width_chars(GTK_LABEL(locationnote), 80);
171 static GtkEntry *text_entry(GtkWidget *box, const char *label)
175 GtkWidget *frame = gtk_frame_new(label);
177 gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0);
179 entry = gtk_entry_new ();
180 gtk_container_add(GTK_CONTAINER(frame), entry);
182 return GTK_ENTRY(entry);
185 static GtkTextBuffer *text_view(GtkWidget *box, const char *label, gboolean expand)
188 GtkTextBuffer *buffer;
190 GtkWidget *frame = gtk_frame_new(label);
192 gtk_box_pack_start(GTK_BOX(box), frame, expand, expand, 0);
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_container_add(GTK_CONTAINER(frame), scrolled_window);
209 GtkWidget *extended_dive_info_widget(void)
213 vbox = gtk_vbox_new(FALSE, 6);
215 location = text_entry(vbox, "Location");
216 gtk_container_set_border_width(GTK_CONTAINER(vbox), 6);
217 notes = text_view(vbox, "Notes", TRUE);
219 /* Add extended info here: name, description, yadda yadda */
220 show_dive_info(current_dive);