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;
14 static struct dive *buffered_dive;
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(void)
36 struct dive *dive = buffered_dive;
41 if (location_changed) {
42 g_free(dive->location);
43 dive->location = gtk_editable_get_chars(GTK_EDITABLE(location), 0, -1);
48 dive->notes = get_text(notes);
52 void update_dive_info(struct dive *dive)
58 flush_dive_info_changes();
62 gtk_label_set_text(GTK_LABEL(divedate), "no dive");
63 gtk_label_set_text(GTK_LABEL(divetime), "");
64 gtk_label_set_text(GTK_LABEL(depth), "");
65 gtk_label_set_text(GTK_LABEL(duration), "");
69 tm = gmtime(&dive->when);
70 snprintf(buffer, sizeof(buffer),
73 tm->tm_mon+1, tm->tm_mday, tm->tm_year+1900);
74 gtk_label_set_text(GTK_LABEL(divedate), buffer);
76 snprintf(buffer, sizeof(buffer),
78 tm->tm_hour, tm->tm_min, tm->tm_sec);
79 gtk_label_set_text(GTK_LABEL(divetime), buffer);
81 snprintf(buffer, sizeof(buffer),
83 to_feet(dive->maxdepth));
84 gtk_label_set_text(GTK_LABEL(depth), buffer);
86 snprintf(buffer, sizeof(buffer),
88 dive->duration.seconds / 60);
89 gtk_label_set_text(GTK_LABEL(duration), buffer);
92 if (dive->watertemp.mkelvin)
93 snprintf(buffer, sizeof(buffer),
95 to_C(dive->watertemp));
96 gtk_label_set_text(GTK_LABEL(temperature), buffer);
98 text = dive->location ? : "";
99 gtk_entry_set_text(location, text);
100 gtk_label_set_text(GTK_LABEL(locationnote), text);
102 text = dive->notes ? : "";
103 gtk_text_buffer_set_text(notes, text, -1);
106 static GtkWidget *info_label(GtkWidget *box, const char *str, GtkJustification jtype)
108 GtkWidget *label = gtk_label_new(str);
109 gtk_label_set_justify(GTK_LABEL(label), jtype);
110 gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
114 GtkWidget *dive_info_frame(void)
117 GtkWidget *hbox, *hbox2;
120 frame = gtk_frame_new("Dive info");
121 gtk_widget_show(frame);
123 vbox = gtk_vbox_new(TRUE, 6);
124 gtk_container_set_border_width(GTK_CONTAINER(vbox), 3);
125 gtk_container_add(GTK_CONTAINER(frame), vbox);
127 hbox = gtk_hbox_new(TRUE, 6);
128 gtk_container_set_border_width(GTK_CONTAINER(hbox), 3);
129 gtk_container_add(GTK_CONTAINER(vbox), hbox);
131 hbox2 = gtk_hbox_new(FALSE, 6);
132 gtk_container_set_border_width(GTK_CONTAINER(hbox2), 3);
133 gtk_container_add(GTK_CONTAINER(vbox), hbox2);
135 divedate = info_label(hbox, "date", GTK_JUSTIFY_RIGHT);
136 divetime = info_label(hbox, "time", GTK_JUSTIFY_RIGHT);
137 depth = info_label(hbox, "depth", GTK_JUSTIFY_RIGHT);
138 duration = info_label(hbox, "duration", GTK_JUSTIFY_RIGHT);
139 temperature = info_label(hbox, "temperature", GTK_JUSTIFY_RIGHT);
141 locationnote = info_label(hbox2, "location", GTK_JUSTIFY_LEFT);
142 gtk_label_set_width_chars(GTK_LABEL(locationnote), 80);
147 static GtkEntry *text_entry(GtkWidget *box, const char *label)
151 GtkWidget *frame = gtk_frame_new(label);
153 gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0);
155 entry = gtk_entry_new ();
156 gtk_container_add(GTK_CONTAINER(frame), entry);
158 return GTK_ENTRY(entry);
161 static GtkTextBuffer *text_view(GtkWidget *box, const char *label, gboolean expand)
164 GtkTextBuffer *buffer;
166 GtkWidget *frame = gtk_frame_new(label);
168 gtk_box_pack_start(GTK_BOX(box), frame, expand, expand, 0);
170 GtkWidget* scrolled_window = gtk_scrolled_window_new (0, 0);
171 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
172 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN);
173 gtk_widget_show(scrolled_window);
175 view = gtk_text_view_new ();
176 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
177 gtk_container_add(GTK_CONTAINER(scrolled_window), view);
179 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
181 gtk_container_add(GTK_CONTAINER(frame), scrolled_window);
185 GtkWidget *extended_dive_info_widget(void)
189 vbox = gtk_vbox_new(FALSE, 6);
191 location = text_entry(vbox, "Location");
192 gtk_container_set_border_width(GTK_CONTAINER(vbox), 6);
193 notes = text_view(vbox, "Notes", TRUE);
195 /* Add extended info here: name, description, yadda yadda */
196 update_dive_info(current_dive);