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) \
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
+++ /dev/null
-#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;
-}
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
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)
--- /dev/null
+#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;
+}
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)
{
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;
}
}
-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), "");
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;
}
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);
}
GtkWidget *notebook;
GtkWidget *frame;
GtkWidget *dive_info;
- GtkWidget *cylinder_management;
+ GtkWidget *equipment;
GtkWidget *menubar;
GtkWidget *vbox;
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);
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++)