From: Linus Torvalds Date: Sat, 10 Sep 2011 00:10:17 +0000 (-0700) Subject: Rename 'cylinder.c' as 'equipment.c' X-Git-Url: http://git.tdb.fi/?p=ext%2Fsubsurface.git;a=commitdiff_plain;h=067506038a5fea72e60680513d768f89722671fd 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 --- 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/cylinders.c b/cylinders.c deleted file mode 100644 index 5df0702..0000000 --- a/cylinders.c +++ /dev/null @@ -1,107 +0,0 @@ -#include -#include -#include -#include -#include - -#include "dive.h" -#include "display.h" -#include "divelist.h" - -static struct tank_info { - const char *name; - int size; /* cuft or mliter depending on psi */ - int psi; /* If zero, size is in mliter */ -} tank_info[] = { - { "None", }, - { "10.0 l", 10000 }, - { "11.1 l", 11100 }, - { "AL72", 72, 3000 }, - { "AL80", 80, 3000 }, - { "LP85", 85, 2640 }, - { "LP95", 95, 2640 }, - { "HP100", 100, 3442 }, - { "HP119", 119, 3442 }, - { NULL, } -}; - -static void fill_tank_list(GtkListStore *store) -{ - GtkTreeIter iter; - - struct tank_info *info = tank_info; - - while (info->name) { - int size = info->size; - int psi = info->psi; - int mbar = 0, ml = size; - - /* Is it in cuft and psi? */ - if (psi) { - double bar = 0.0689475729 * psi; - double airvolume = 28316.8466 * size; - double atm = bar / 1.01325; - - ml = airvolume / atm + 0.5; - mbar = bar*1000 + 0.5; - } - - gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, - 0, info->name, - 1, ml, - 2, mbar, - -1); - info++; - } -} - -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); - frame = gtk_frame_new(buffer); - gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0); - - 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 ); - - gtk_box_pack_start(GTK_BOX(hbox), size, FALSE, FALSE, 0); -} - -static GtkListStore *create_tank_size_model(void) -{ - GtkListStore *model; - - model = gtk_list_store_new(3, - G_TYPE_STRING, /* Tank name */ - G_TYPE_INT, /* Tank size in mliter */ - G_TYPE_INT, /* Tank working pressure in mbar */ - -1); - - fill_tank_list(model); - return model; -} - -GtkWidget *cylinder_management_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); - - return vbox; -} 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/equipment.c b/equipment.c new file mode 100644 index 0000000..5b8bf35 --- /dev/null +++ b/equipment.c @@ -0,0 +1,108 @@ +#include +#include +#include +#include +#include + +#include "dive.h" +#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 */ + int psi; /* If zero, size is in mliter */ +} tank_info[] = { + { "None", }, + { "10.0 l", 10000 }, + { "11.1 l", 11100 }, + { "AL72", 72, 3000 }, + { "AL80", 80, 3000 }, + { "LP85", 85, 2640 }, + { "LP95", 95, 2640 }, + { "HP100", 100, 3442 }, + { "HP119", 119, 3442 }, + { NULL, } +}; + +static void fill_tank_list(GtkListStore *store) +{ + GtkTreeIter iter; + + struct tank_info *info = tank_info; + + while (info->name) { + int size = info->size; + int psi = info->psi; + int mbar = 0, ml = size; + + /* Is it in cuft and psi? */ + if (psi) { + double bar = 0.0689475729 * psi; + double airvolume = 28316.8466 * size; + double atm = bar / 1.01325; + + ml = airvolume / atm + 0.5; + mbar = bar*1000 + 0.5; + } + + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, + 0, info->name, + 1, ml, + 2, mbar, + -1); + info++; + } +} + +static void cylinder_widget(GtkWidget *box, int nr, GtkListStore *model) +{ + GtkWidget *frame, *hbox, *size; + char buffer[80]; + + snprintf(buffer, sizeof(buffer), "Cylinder %d", nr); + frame = gtk_frame_new(buffer); + gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0); + + hbox = gtk_hbox_new(TRUE, 3); + gtk_container_add(GTK_CONTAINER(frame), hbox); + + size = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0); + gtk_box_pack_start(GTK_BOX(hbox), size, FALSE, FALSE, 0); +} + +static GtkListStore *create_tank_size_model(void) +{ + GtkListStore *model; + + model = gtk_list_store_new(3, + G_TYPE_STRING, /* Tank name */ + G_TYPE_INT, /* Tank size in mliter */ + G_TYPE_INT, /* Tank working pressure in mbar */ + -1); + + fill_tank_list(model); + return model; +} + +GtkWidget *equipment_widget(void) +{ + GtkWidget *vbox; + GtkListStore *model; + + vbox = gtk_vbox_new(TRUE, 3); + + model = create_tank_size_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++)