]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Rename 'cylinder.c' as 'equipment.c'
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 10 Sep 2011 00:10:17 +0000 (17:10 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 10 Sep 2011 00:10:17 +0000 (17:10 -0700)
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 <torvalds@linux-foundation.org>
Makefile
cylinders.c [deleted file]
display.h
dive.h
equipment.c [new file with mode: 0644]
info.c
main.c
save-xml.c

index ddd96745884561cd9351a88c57bdfc6d1d3e7883..787a74feefa7d59799be666b3314f0d3c566abe2 100644 (file)
--- 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 (file)
index 5df0702..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <time.h>
-
-#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;
-}
index d499fc7fc571b706bf251fdfe0d01e10dce2ab23..a9d90ece2295a15db1c71bea54699ed5b8bbb5ba 100644 (file)
--- 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 15f082104b5c36219e5b1750343cfbf85286135c..d9fa35abf88997f76143ff8b0130cb7ca3acc17f 100644 (file)
--- 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 (file)
index 0000000..5b8bf35
--- /dev/null
@@ -0,0 +1,108 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <time.h>
+
+#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 b789d9fd8a6916923e29ccfa7069e69df46e9a7a..9cb048b808fbba20b8ed5b1daa0bfc4a700abaa8 100644 (file)
--- 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 dc5453892c2585a6de6d22ab0a16f8a418c963fe..5367571ad6e6520c5b2fc6db21ee2c3907916f90 100644 (file)
--- 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);
index 07b8b80969d25f28616499083b8aab452127fd22..c5d49391b194c71f59d16756ab087a6605dbdac7 100644 (file)
@@ -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, "<dives>\n<program name='diveclog' version='%d'></program>\n", VERSION);
        for (i = 0; i < dive_table.nr; i++)