]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Add a notebook for cylinder information
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 9 Sep 2011 15:38:48 +0000 (08:38 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 9 Sep 2011 17:31:51 +0000 (10:31 -0700)
Ok, so it's not connected to anything yet, and the tank choices (that
don't do anything) are some random hardcoded collection, but maybe it
will do something some day.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Makefile
cylinders.c [new file with mode: 0644]
display.h
main.c

index a2062e6fcfe55f527b59ab54e910e10c694d89fd..ddd96745884561cd9351a88c57bdfc6d1d3e7883 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 divelist.o parse-xml.o save-xml.o
+OBJS=main.o dive.o profile.o info.o cylinders.o divelist.o parse-xml.o save-xml.o
 
 divelog: $(OBJS)
        $(CC) $(LDFLAGS) -o divelog $(OBJS) \
@@ -27,5 +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
+
 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
new file mode 100644 (file)
index 0000000..5df0702
--- /dev/null
@@ -0,0 +1,107 @@
+#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 e2e217ff067c8f40ff2047ffcc40d7d8df873c3e..d499fc7fc571b706bf251fdfe0d01e10dce2ab23 100644 (file)
--- a/display.h
+++ b/display.h
@@ -8,6 +8,7 @@
 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 void repaint_dive(void);
 
diff --git a/main.c b/main.c
index 7088a6dfacac37a824c62886ff039cba02756153..dc5453892c2585a6de6d22ab0a16f8a418c963fe 100644 (file)
--- a/main.c
+++ b/main.c
@@ -215,11 +215,9 @@ static void create_radio(GtkWidget *dialog, const char *name, ...)
 
        box = gtk_hbox_new(TRUE, 10);
        gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), box);
-       gtk_widget_show(box);
 
        label = gtk_label_new(name);
        gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
-       gtk_widget_show(label);
 
        va_start(args, name);
        for (;;) {
@@ -239,7 +237,6 @@ static void create_radio(GtkWidget *dialog, const char *name, ...)
                gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), enabled);
                g_signal_connect(button, "toggled", G_CALLBACK(callback_fn), NULL);
-               gtk_widget_show(button);
        }
        va_end(args);
 }
@@ -296,7 +293,7 @@ static void unit_dialog(GtkWidget *w, gpointer data)
                "Fahrenheit",  set_fahrenheit, (output_units.temperature == FAHRENHEIT),
                NULL);
 
-       gtk_widget_show(dialog);
+       gtk_widget_show_all(dialog);
        result = gtk_dialog_run(GTK_DIALOG(dialog));
        if (result == GTK_RESPONSE_ACCEPT) {
                output_units = menu_units;
@@ -359,6 +356,7 @@ int main(int argc, char **argv)
        GtkWidget *notebook;
        GtkWidget *frame;
        GtkWidget *dive_info;
+       GtkWidget *cylinder_management;
        GtkWidget *menubar;
        GtkWidget *vbox;
 
@@ -417,7 +415,11 @@ int main(int argc, char **argv)
 
        /* Frame for extended dive info */
        dive_info = extended_dive_info_widget();
-       gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dive_info, gtk_label_new("Extended Dive Info"));
+       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"));
 
        gtk_widget_set_app_paintable(win, TRUE);
        gtk_widget_show_all(win);