From 067506038a5fea72e60680513d768f89722671fd Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 9 Sep 2011 17:10:17 -0700 Subject: [PATCH] Rename 'cylinder.c' as 'equipment.c' Make it about general equipment management, and start hooking up functions to show new equipment information when changing dives (and to flush changes to equipment information for the previously active dive). Nothing is hooked up yet, and it's now showing just one (really big) cylinder choice, so this is all broken. But it should make it possible to at least get somewhere some day. Signed-off-by: Linus Torvalds --- Makefile | 6 +++--- display.h | 4 ++-- dive.h | 7 ++++++- cylinders.c => equipment.c | 21 +++++++++++---------- info.c | 12 +++--------- main.c | 26 +++++++++++++++++++++----- save-xml.c | 2 +- 7 files changed, 47 insertions(+), 31 deletions(-) rename cylinders.c => equipment.c (83%) diff --git a/Makefile b/Makefile index ddd9674..787a74f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC=gcc CFLAGS=-Wall -Wno-pointer-sign -g -OBJS=main.o dive.o profile.o info.o cylinders.o divelist.o parse-xml.o save-xml.o +OBJS=main.o dive.o profile.o info.o equipment.o divelist.o parse-xml.o save-xml.o divelog: $(OBJS) $(CC) $(LDFLAGS) -o divelog $(OBJS) \ @@ -27,8 +27,8 @@ profile.o: profile.c dive.h display.h divelist.h info.o: info.c dive.h display.h divelist.h $(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0 glib-2.0` -c info.c -cylinders.o: cylinders.c dive.h display.h divelist.h - $(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0 glib-2.0` -c cylinders.c +equipment.o: equipment.c dive.h display.h divelist.h + $(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0 glib-2.0` -c equipment.c divelist.o: divelist.c dive.h display.h divelist.h $(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0 glib-2.0` -c divelist.c diff --git a/display.h b/display.h index d499fc7..a9d90ec 100644 --- a/display.h +++ b/display.h @@ -8,8 +8,8 @@ extern GtkWidget *dive_profile_widget(void); extern GtkWidget *dive_info_frame(void); extern GtkWidget *extended_dive_info_widget(void); -extern GtkWidget *cylinder_management_widget(void); -extern void update_dive_info(struct dive *dive); +extern GtkWidget *equipment_widget(void); + extern void repaint_dive(void); #endif diff --git a/dive.h b/dive.h index 15f0821..d9fa35a 100644 --- a/dive.h +++ b/dive.h @@ -175,7 +175,12 @@ static inline struct dive *get_dive(unsigned int nr) extern void parse_xml_init(void); extern void parse_xml_file(const char *filename, GError **error); -extern void flush_dive_info_changes(void); +extern void show_dive_info(struct dive *); +extern void flush_dive_info_changes(struct dive *); + +extern void show_dive_equipment(struct dive *); +extern void flush_dive_equipment_changes(struct dive *); + extern void save_dives(const char *filename); static inline unsigned int dive_size(int samples) diff --git a/cylinders.c b/equipment.c similarity index 83% rename from cylinders.c rename to equipment.c index 5df0702..5b8bf35 100644 --- a/cylinders.c +++ b/equipment.c @@ -8,6 +8,14 @@ #include "display.h" #include "divelist.h" +void show_dive_equipment(struct dive *dive) +{ +} + +void flush_dive_equipment_changes(struct dive *dive) +{ +} + static struct tank_info { const char *name; int size; /* cuft or mliter depending on psi */ @@ -59,7 +67,6 @@ static void fill_tank_list(GtkListStore *store) static void cylinder_widget(GtkWidget *box, int nr, GtkListStore *model) { GtkWidget *frame, *hbox, *size; - GtkCellRenderer *cell; char buffer[80]; snprintf(buffer, sizeof(buffer), "Cylinder %d", nr); @@ -69,11 +76,7 @@ static void cylinder_widget(GtkWidget *box, int nr, GtkListStore *model) hbox = gtk_hbox_new(TRUE, 3); gtk_container_add(GTK_CONTAINER(frame), hbox); - size = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model)); - cell = gtk_cell_renderer_text_new(); - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(size), cell, TRUE); - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(size), cell, "text", 0, NULL ); - + size = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0); gtk_box_pack_start(GTK_BOX(hbox), size, FALSE, FALSE, 0); } @@ -91,17 +94,15 @@ static GtkListStore *create_tank_size_model(void) return model; } -GtkWidget *cylinder_management_widget(void) +GtkWidget *equipment_widget(void) { - int i; GtkWidget *vbox; GtkListStore *model; vbox = gtk_vbox_new(TRUE, 3); model = create_tank_size_model(); - for (i = 0; i < MAX_CYLINDERS; i++) - cylinder_widget(vbox, i, model); + cylinder_widget(vbox, 0, model); return vbox; } diff --git a/info.c b/info.c index b789d9f..9cb048b 100644 --- a/info.c +++ b/info.c @@ -11,7 +11,6 @@ static GtkWidget *divedate, *divetime, *depth, *duration, *temperature, *locatio static GtkEntry *location; static GtkTextBuffer *notes; static int location_changed = 1, notes_changed = 1; -static struct dive *buffered_dive; static const char *weekday(int wday) { @@ -31,10 +30,8 @@ static char *get_text(GtkTextBuffer *buffer) return gtk_text_buffer_get_text(buffer, &start, &end, FALSE); } -void flush_dive_info_changes(void) +void flush_dive_info_changes(struct dive *dive) { - struct dive *dive = buffered_dive; - if (!dive) return; @@ -49,15 +46,12 @@ void flush_dive_info_changes(void) } } -void update_dive_info(struct dive *dive) +void show_dive_info(struct dive *dive) { struct tm *tm; char buffer[80]; char *text; - flush_dive_info_changes(); - buffered_dive = dive; - if (!dive) { gtk_label_set_text(GTK_LABEL(divedate), "no dive"); gtk_label_set_text(GTK_LABEL(divetime), ""); @@ -217,6 +211,6 @@ GtkWidget *extended_dive_info_widget(void) notes = text_view(vbox, "Notes", TRUE); /* Add extended info here: name, description, yadda yadda */ - update_dive_info(current_dive); + show_dive_info(current_dive); return vbox; } diff --git a/main.c b/main.c index dc54538..5367571 100644 --- a/main.c +++ b/main.c @@ -90,9 +90,25 @@ static void on_destroy(GtkWidget* w, gpointer data) static GtkWidget *dive_profile; +void update_dive(struct dive *new_dive) +{ + static struct dive *buffered_dive; + struct dive *old_dive = buffered_dive; + + if (old_dive) { + flush_dive_info_changes(old_dive); + flush_dive_equipment_changes(old_dive); + } + if (new_dive) { + buffered_dive = new_dive; + show_dive_info(new_dive); + show_dive_equipment(new_dive); + } +} + void repaint_dive(void) { - update_dive_info(current_dive); + update_dive(current_dive); gtk_widget_queue_draw(dive_profile); } @@ -356,7 +372,7 @@ int main(int argc, char **argv) GtkWidget *notebook; GtkWidget *frame; GtkWidget *dive_info; - GtkWidget *cylinder_management; + GtkWidget *equipment; GtkWidget *menubar; GtkWidget *vbox; @@ -417,9 +433,9 @@ int main(int argc, char **argv) dive_info = extended_dive_info_widget(); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dive_info, gtk_label_new("Dive Notes")); - /* Frame for extended dive info */ - cylinder_management = cylinder_management_widget(); - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), cylinder_management, gtk_label_new("Cylinders")); + /* Frame for dive equipment */ + equipment = equipment_widget(); + gtk_notebook_append_page(GTK_NOTEBOOK(notebook), equipment, gtk_label_new("Equipment")); gtk_widget_set_app_paintable(win, TRUE); gtk_widget_show_all(win); diff --git a/save-xml.c b/save-xml.c index 07b8b80..c5d4939 100644 --- a/save-xml.c +++ b/save-xml.c @@ -226,7 +226,7 @@ void save_dives(const char *filename) return; /* Flush any edits of current dives back to the dives! */ - flush_dive_info_changes(); + update_dive(NULL); fprintf(f, "\n\n", VERSION); for (i = 0; i < dive_table.nr; i++) -- 2.45.2