]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Merge branch 'sacplot' of git://git.hohndel.org/subsurface
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 19 Nov 2011 21:22:21 +0000 (13:22 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 19 Nov 2011 21:22:21 +0000 (13:22 -0800)
* 'sacplot' of git://git.hohndel.org/subsurface:
  Fix error when gaschange event is one second before next sample

Makefile
display-gtk.h
dive.h
divelist.c
equipment.c
info.c
main.c

index 1b1a31a8c6c4f18dedb59ad0201dcd57c62a1412..edad32ce4259829b8e852672b881a48402095c4a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -133,48 +133,48 @@ install-macosx: $(NAME)
        $(INSTALL) $(MACOSXFILES)/Subsurface.icns $(MACOSXINSTALL)/Contents/Resources/
 
 parse-xml.o: parse-xml.c dive.h
-       $(CC) $(CFLAGS) $(GLIB2CFLAGS) -c $(XML2CFLAGS) $(XSLT) parse-xml.c
+       $(CC) $(CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) $(XSLT) -c parse-xml.c
 
 save-xml.o: save-xml.c dive.h
-       $(CC) $(CFLAGS) $(GLIB2CFLAGS) -c save-xml.c
+       $(CC) $(CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c save-xml.c
 
 dive.o: dive.c dive.h
-       $(CC) $(CFLAGS) $(GLIB2CFLAGS) -c dive.c
+       $(CC) $(CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c dive.c
 
 main.o: main.c dive.h display.h divelist.h
-       $(CC) $(CFLAGS) $(GLIB2CFLAGS) $(GCONF2CFLAGS) -c main.c
+       $(CC) $(CFLAGS) $(GLIB2CFLAGS) $(GCONF2CFLAGS) $(XML2CFLAGS) -c main.c
 
 profile.o: profile.c dive.h display.h divelist.h
-       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) -c profile.c
+       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c profile.c
 
 info.o: info.c dive.h display.h display-gtk.h divelist.h
-       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) -c info.c
+       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c info.c
 
 equipment.o: equipment.c dive.h display.h divelist.h
-       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) -c equipment.c
+       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c equipment.c
 
 statistics.o: statistics.c dive.h display.h divelist.h
-       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) -c statistics.c
+       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c statistics.c
 
 divelist.o: divelist.c dive.h display.h divelist.h
-       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) -c divelist.c
+       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c divelist.c
 
 print.o: print.c dive.h display.h display-gtk.h
-       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) -c print.c
+       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c print.c
 
 libdivecomputer.o: libdivecomputer.c dive.h display.h display-gtk.h libdivecomputer.h
-       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) \
+       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) \
                        $(LIBDIVECOMPUTERCFLAGS) \
                        -c libdivecomputer.c
 
 gtk-gui.o: gtk-gui.c dive.h display.h divelist.h display-gtk.h libdivecomputer.h Makefile
-       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(GCONF2CFLAGS) \
+       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(GCONF2CFLAGS) $(XML2CFLAGS) \
                        $(LIBDIVECOMPUTERCFLAGS) \
                        -DVERSION_STRING='"v$(VERSION)"' \
                        -c gtk-gui.c
 
-uemis.o: uemis.c uemis.h
-       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) -c uemis.c
+uemis.o: uemis.c dive.h uemis.h
+       $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c uemis.c
 
 clean:
        rm -f $(OBJS) *~ $(NAME)
index 3f1ff0dd6cb2626333246f8d34a327234ec02815..56fd5c4d99f515c1597f9cbda16a121840315e98 100644 (file)
@@ -34,6 +34,7 @@ extern GtkWidget *dive_info_frame(void);
 extern GtkWidget *extended_dive_info_widget(void);
 extern GtkWidget *equipment_widget(void);
 extern GtkWidget *stats_widget(void);
+extern GtkWidget *cylinder_list_widget(void);
 
 extern GtkWidget *dive_list_create(void);
 
diff --git a/dive.h b/dive.h
index 0116a1cf78a3d07ac4da2ccbe725de15f7e35d9e..ccb007dcbd5be6453fa94b1886d37f03f8d560c5 100644 (file)
--- a/dive.h
+++ b/dive.h
@@ -259,10 +259,8 @@ extern xmlDoc *test_xslt_transforms(xmlDoc *doc);
 #endif
 
 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 show_dive_stats(struct dive *);
 
@@ -304,6 +302,7 @@ extern void add_location(const char *string);
 extern void remember_event(const char *eventname);
 extern void evn_foreach(void (*callback)(const char *, int *, void *), void *data);
 
+extern int edit_dive_info(struct dive *dive);
 extern void dive_list_update_dives(void);
 extern void flush_divelist(struct dive *dive);
 
index 60ad16a7fe541ced018f03010e732957b6974024..48a9ea99a5030fd679dd773190fa3405b388f263 100644 (file)
@@ -506,6 +506,20 @@ static void realize_cb(GtkWidget *tree_view, gpointer userdata)
        gtk_widget_grab_focus(tree_view);
 }
 
+static void row_activated_cb(GtkTreeView *tree_view,
+                       GtkTreePath *path,
+                       GtkTreeViewColumn *column,
+                       GtkTreeModel *model)
+{
+       int index;
+       GtkTreeIter iter;
+
+       if (!gtk_tree_model_get_iter(model, &iter, path))
+               return;
+       gtk_tree_model_get(model, &iter, DIVE_INDEX, &index, -1);
+       edit_dive_info(get_dive(index));
+}
+
 GtkWidget *dive_list_create(void)
 {
        GtkTreeSelection  *selection;
@@ -551,6 +565,7 @@ GtkWidget *dive_list_create(void)
                                          NULL);
 
        g_signal_connect_after(dive_list.tree_view, "realize", G_CALLBACK(realize_cb), NULL);
+       g_signal_connect(dive_list.tree_view, "row-activated", G_CALLBACK(row_activated_cb), dive_list.model);
        g_signal_connect(selection, "changed", G_CALLBACK(selection_cb), dive_list.model);
 
        dive_list.container_widget = gtk_scrolled_window_new(NULL, NULL);
index f86e63b2073f0982902dfb3a55bf1f6e7c9b1f50..2b278934d559cba41c5ccd8eca9293fc18671423 100644 (file)
@@ -3,7 +3,6 @@
  * controlled through the following interfaces:
  *
  * void show_dive_equipment(struct dive *dive)
- * void flush_dive_equipment_changes(struct dive *dive)
  *
  * called from gtk-ui:
  * GtkWidget *equipment_widget(void)
@@ -35,9 +34,7 @@ enum {
 static struct {
        int max_index;
        GtkListStore *model;
-       GtkWidget *tree_view;
        GtkWidget *edit, *add, *del;
-       GtkTreeViewColumn *desc, *size, *workp, *startp, *endp, *o2, *he;
 } cylinder_list;
 
 struct cylinder_widget {
@@ -429,11 +426,6 @@ static void record_cylinder_changes(cylinder_t *cyl, struct cylinder_widget *cyl
        fill_cylinder_info(cylinder, cyl, desc, volume, pressure, start, end, o2);
 }
 
-void flush_dive_equipment_changes(struct dive *dive)
-{
-       /* We do nothing: we require the "Ok" button press */
-}
-
 /*
  * We hardcode the most common standard cylinders,
  * we should pick up any other names from the dive
@@ -667,7 +659,7 @@ static int get_model_index(GtkListStore *model, GtkTreeIter *iter)
        return index;
 }
 
-static void edit_cb(GtkButton *button, gpointer data)
+static void edit_cb(GtkButton *button, GtkTreeView *tree_view)
 {
        int index;
        GtkTreeIter iter;
@@ -675,7 +667,7 @@ static void edit_cb(GtkButton *button, gpointer data)
        GtkTreeSelection *selection;
        cylinder_t cyl;
 
-       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cylinder_list.tree_view));
+       selection = gtk_tree_view_get_selection(tree_view);
 
        /* Nothing selected? This shouldn't happen, since the button should be inactive */
        if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
@@ -689,7 +681,7 @@ static void edit_cb(GtkButton *button, gpointer data)
        repaint_dive();
 }
 
-static void add_cb(GtkButton *button, gpointer data)
+static void add_cb(GtkButton *button, GtkTreeView *tree_view)
 {
        int index = cylinder_list.max_index;
        GtkTreeIter iter;
@@ -703,14 +695,14 @@ static void add_cb(GtkButton *button, gpointer data)
        gtk_list_store_append(model, &iter);
        set_one_cylinder(index, &cyl, model, &iter);
 
-       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cylinder_list.tree_view));
+       selection = gtk_tree_view_get_selection(tree_view);
        gtk_tree_selection_select_iter(selection, &iter);
 
        cylinder_list.max_index++;
        gtk_widget_set_sensitive(cylinder_list.add, cylinder_list.max_index < MAX_CYLINDERS);
 }
 
-static void del_cb(GtkButton *button, gpointer data)
+static void del_cb(GtkButton *button, GtkTreeView *tree_view)
 {
        int index, nr;
        GtkTreeIter iter;
@@ -719,7 +711,7 @@ static void del_cb(GtkButton *button, gpointer data)
        struct dive *dive;
        cylinder_t *cyl;
 
-       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cylinder_list.tree_view));
+       selection = gtk_tree_view_get_selection(tree_view);
 
        /* Nothing selected? This shouldn't happen, since the button should be inactive */
        if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
@@ -833,26 +825,18 @@ static void row_activated_cb(GtkTreeView *tree_view,
                        GtkTreeViewColumn *column,
                        GtkTreeModel *model)
 {
-       edit_cb(NULL, NULL);
+       edit_cb(NULL, tree_view);
 }
 
-static GtkWidget *cylinder_list_create(void)
+GtkWidget *cylinder_list_widget(void)
 {
+       GtkListStore *model = cylinder_list.model;
        GtkWidget *tree_view;
        GtkTreeSelection *selection;
-       GtkListStore *model;
 
-       model = gtk_list_store_new(CYL_COLUMNS,
-               G_TYPE_STRING,          /* CYL_DESC: utf8 */
-               G_TYPE_INT,             /* CYL_SIZE: mliter */
-               G_TYPE_INT,             /* CYL_WORKP: mbar */
-               G_TYPE_INT,             /* CYL_STARTP: mbar */
-               G_TYPE_INT,             /* CYL_ENDP: mbar */
-               G_TYPE_INT,             /* CYL_O2: permille */
-               G_TYPE_INT              /* CYL_HE: permille */
-               );
-       cylinder_list.model = model;
        tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
+       gtk_widget_set_can_focus(tree_view, FALSE);
+
        g_signal_connect(tree_view, "row-activated", G_CALLBACK(row_activated_cb), model);
 
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
@@ -863,19 +847,36 @@ static GtkWidget *cylinder_list_create(void)
                                          "enable-grid-lines", GTK_TREE_VIEW_GRID_LINES_BOTH,
                                          NULL);
 
-       cylinder_list.desc = tree_view_column(tree_view, CYL_DESC, "Type", NULL, PANGO_ALIGN_LEFT, TRUE);
-       cylinder_list.size = tree_view_column(tree_view, CYL_SIZE, "Size", size_data_func, PANGO_ALIGN_RIGHT, TRUE);
-       cylinder_list.workp = tree_view_column(tree_view, CYL_WORKP, "MaxPress", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
-       cylinder_list.startp = tree_view_column(tree_view, CYL_STARTP, "Start", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
-       cylinder_list.endp = tree_view_column(tree_view, CYL_ENDP, "End", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
-       cylinder_list.o2 = tree_view_column(tree_view, CYL_O2, "O" UTF8_SUBSCRIPT_2 "%", percentage_data_func, PANGO_ALIGN_RIGHT, TRUE);
-       cylinder_list.he = tree_view_column(tree_view, CYL_HE, "He%", percentage_data_func, PANGO_ALIGN_RIGHT, TRUE);
+       tree_view_column(tree_view, CYL_DESC, "Type", NULL, PANGO_ALIGN_LEFT, TRUE);
+       tree_view_column(tree_view, CYL_SIZE, "Size", size_data_func, PANGO_ALIGN_RIGHT, TRUE);
+       tree_view_column(tree_view, CYL_WORKP, "MaxPress", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
+       tree_view_column(tree_view, CYL_STARTP, "Start", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
+       tree_view_column(tree_view, CYL_ENDP, "End", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
+       tree_view_column(tree_view, CYL_O2, "O" UTF8_SUBSCRIPT_2 "%", percentage_data_func, PANGO_ALIGN_RIGHT, TRUE);
+       tree_view_column(tree_view, CYL_HE, "He%", percentage_data_func, PANGO_ALIGN_RIGHT, TRUE);
        return tree_view;
 }
 
+static GtkWidget *cylinder_list_create(void)
+{
+       GtkListStore *model;
+
+       model = gtk_list_store_new(CYL_COLUMNS,
+               G_TYPE_STRING,          /* CYL_DESC: utf8 */
+               G_TYPE_INT,             /* CYL_SIZE: mliter */
+               G_TYPE_INT,             /* CYL_WORKP: mbar */
+               G_TYPE_INT,             /* CYL_STARTP: mbar */
+               G_TYPE_INT,             /* CYL_ENDP: mbar */
+               G_TYPE_INT,             /* CYL_O2: permille */
+               G_TYPE_INT              /* CYL_HE: permille */
+               );
+       cylinder_list.model = model;
+       return cylinder_list_widget();
+}
+
 GtkWidget *equipment_widget(void)
 {
-       GtkWidget *vbox, *hbox, *frame, *framebox;
+       GtkWidget *vbox, *hbox, *frame, *framebox, *tree_view;
        GtkWidget *add, *del, *edit;
 
        vbox = gtk_vbox_new(FALSE, 3);
@@ -889,7 +890,7 @@ GtkWidget *equipment_widget(void)
         */
        cylinder_model = create_tank_size_model();
 
-       cylinder_list.tree_view = cylinder_list_create();
+       tree_view = cylinder_list_create();
 
        hbox = gtk_hbox_new(FALSE, 3);
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
@@ -903,7 +904,7 @@ GtkWidget *equipment_widget(void)
        hbox = gtk_hbox_new(FALSE, 3);
        gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3);
 
-       gtk_box_pack_start(GTK_BOX(hbox), cylinder_list.tree_view, TRUE, FALSE, 3);
+       gtk_box_pack_start(GTK_BOX(hbox), tree_view, TRUE, FALSE, 3);
 
        hbox = gtk_hbox_new(TRUE, 3);
        gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3);
@@ -919,9 +920,9 @@ GtkWidget *equipment_widget(void)
        cylinder_list.add = add;
        cylinder_list.del = del;
 
-       g_signal_connect(edit, "clicked", G_CALLBACK(edit_cb), NULL);
-       g_signal_connect(add, "clicked", G_CALLBACK(add_cb), NULL);
-       g_signal_connect(del, "clicked", G_CALLBACK(del_cb), NULL);
+       g_signal_connect(edit, "clicked", G_CALLBACK(edit_cb), tree_view);
+       g_signal_connect(add, "clicked", G_CALLBACK(add_cb), tree_view);
+       g_signal_connect(del, "clicked", G_CALLBACK(del_cb), tree_view);
 
        return vbox;
 }
diff --git a/info.c b/info.c
index 11107b1ca91c461eb41245bea72032238305f8fe..7e94a22046b477bbaaf761016703ec205d5e567e 100644 (file)
--- a/info.c
+++ b/info.c
@@ -2,7 +2,6 @@
 /* creates the UI for the info frame - 
  * controlled through the following interfaces:
  * 
- * void flush_dive_info_changes(struct dive *dive)
  * void show_dive_info(struct dive *dive)
  *
  * called from gtk-ui:
 #include "display-gtk.h"
 #include "divelist.h"
 
-static GtkComboBoxEntry *location, *buddy, *divemaster;
-static GtkTextBuffer *notes;
+static GtkEntry *location, *buddy, *divemaster;
+static GtkTextView *notes;
+static GtkListStore *location_list, *people_list;
 
-static char *get_text(GtkTextBuffer *buffer)
+static char *get_text(GtkTextView *view)
 {
+       GtkTextBuffer *buffer;
        GtkTextIter start;
        GtkTextIter end;
 
+       buffer = gtk_text_view_get_buffer(view);
        gtk_text_buffer_get_start_iter(buffer, &start);
        gtk_text_buffer_get_end_iter(buffer, &end);
        return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
@@ -57,89 +59,74 @@ static char *get_combo_box_entry_text(GtkComboBoxEntry *combo_box, char **textp)
        return *textp;
 }
 
+#define SET_TEXT_VALUE(x) \
+       gtk_entry_set_text(x, dive && dive->x ? dive->x : "")
 
-void flush_dive_info_changes(struct dive *dive)
+static int divename(char *buf, size_t size, struct dive *dive)
 {
-       char *old_text, *new_text;
-       int changed = 0;
-
-       if (!dive)
-               return;
-
-       new_text = get_combo_box_entry_text(location, &dive->location);
-       if (new_text) {
-               add_location(new_text);
-               changed = 1;
-       }
-
-       new_text = get_combo_box_entry_text(divemaster, &dive->divemaster);
-       if (new_text) {
-               add_people(new_text);
-               changed = 1;
-       }
-
-       new_text = get_combo_box_entry_text(buddy, &dive->buddy);
-       if (new_text) {
-               add_people(new_text);
-               changed = 1;
-       }
-
-       old_text = dive->notes;
-       dive->notes = get_text(notes);
-       if (text_changed(old_text,dive->notes))
-               changed = 1;
-       if (old_text)
-               g_free(old_text);
-
-       if (changed)
-               mark_divelist_changed(TRUE);
+       struct tm *tm = gmtime(&dive->when);
+       return snprintf(buf, size, "Dive #%d - %s %02d/%02d/%04d at %d:%02d",
+               dive->number,
+               weekday(tm->tm_wday),
+               tm->tm_mon+1, tm->tm_mday,
+               tm->tm_year+1900,
+               tm->tm_hour, tm->tm_min);
 }
 
-static void set_combo_box_entry_text(GtkComboBoxEntry *combo_box, const char *text)
-{
-       GtkEntry *entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
-       gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), -1);
-       if (!*text)
-               gtk_entry_set_text(entry, " ");
-       gtk_entry_set_text(entry, text);
-}
-
-#define SET_TEXT_ENTRY(x) \
-       set_combo_box_entry_text(x, dive && dive->x ? dive->x : "")
-
 void show_dive_info(struct dive *dive)
 {
-       struct tm *tm;
        const char *text;
        char buffer[80];
 
        /* dive number and location (or lacking that, the date) go in the window title */
-       tm = gmtime(&dive->when);
        text = dive->location;
        if (!text)
                text = "";
        if (*text) {
                snprintf(buffer, sizeof(buffer), "Dive #%d - %s", dive->number, text);
        } else {
-               snprintf(buffer, sizeof(buffer), "Dive #%d - %s %02d/%02d/%04d at %d:%02d",
-                       dive->number,
-                       weekday(tm->tm_wday),
-                       tm->tm_mon+1, tm->tm_mday,
-                       tm->tm_year+1900,
-                       tm->tm_hour, tm->tm_min);
+               divename(buffer, sizeof(buffer), dive);
        }
        text = buffer;
        if (!dive->number)
                text += 10;     /* Skip the "Dive #0 - " part */
        gtk_window_set_title(GTK_WINDOW(main_window), text);
 
-       SET_TEXT_ENTRY(divemaster);
-       SET_TEXT_ENTRY(buddy);
-       SET_TEXT_ENTRY(location);
-       gtk_text_buffer_set_text(notes, dive && dive->notes ? dive->notes : "", -1);
+       SET_TEXT_VALUE(divemaster);
+       SET_TEXT_VALUE(buddy);
+       SET_TEXT_VALUE(location);
+       gtk_text_buffer_set_text(gtk_text_view_get_buffer(notes),
+               dive && dive->notes ? dive->notes : "", -1);
+}
+
+static void info_menu_edit_cb(GtkMenuItem *menuitem, gpointer user_data)
+{
+       edit_dive_info(current_dive);
+}
+
+static void populate_popup_cb(GtkTextView *entry, GtkMenu *menu, gpointer user_data)
+{
+       GtkWidget *item = gtk_menu_item_new_with_label("Edit");
+       g_signal_connect(item, "activate", G_CALLBACK(info_menu_edit_cb), NULL);
+       gtk_widget_show(item); /* Yes, really */
+       gtk_menu_prepend(menu, item);
+}
+
+static GtkEntry *text_value(GtkWidget *box, const char *label)
+{
+       GtkWidget *widget;
+       GtkWidget *frame = gtk_frame_new(label);
+
+       gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0);
+       widget = gtk_entry_new();
+       gtk_widget_set_can_focus(widget, FALSE);
+       gtk_editable_set_editable(GTK_EDITABLE(widget), FALSE);
+       gtk_container_add(GTK_CONTAINER(frame), widget);
+       g_signal_connect(widget, "populate-popup", G_CALLBACK(populate_popup_cb), NULL);
+       return GTK_ENTRY(widget);
 }
 
-static GtkComboBoxEntry *text_entry(GtkWidget *box, const char *label, GtkListStore *completions)
+static GtkComboBoxEntry *text_entry(GtkWidget *box, const char *label, GtkListStore *completions, const char *text)
 {
        GtkEntry *entry;
        GtkWidget *combo_box;
@@ -151,7 +138,9 @@ static GtkComboBoxEntry *text_entry(GtkWidget *box, const char *label, GtkListSt
        combo_box = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(completions), 0);
        gtk_container_add(GTK_CONTAINER(frame), combo_box);
 
-       entry = GTK_ENTRY(GTK_BIN(combo_box)->child);
+       entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
+       if (text && *text)
+               gtk_entry_set_text(entry, text);
 
        completion = gtk_entry_completion_new();
        gtk_entry_completion_set_text_column(completion, 0);
@@ -164,10 +153,14 @@ static GtkComboBoxEntry *text_entry(GtkWidget *box, const char *label, GtkListSt
        return GTK_COMBO_BOX_ENTRY(combo_box);
 }
 
-static GtkTextBuffer *text_view(GtkWidget *box, const char *label)
+enum writable {
+       READ_ONLY,
+       READ_WRITE
+};
+
+static GtkTextView *text_view(GtkWidget *box, const char *label, enum writable writable)
 {
        GtkWidget *view, *vbox;
-       GtkTextBuffer *buffer;
        GtkWidget *frame = gtk_frame_new(label);
 
        gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0);
@@ -181,13 +174,16 @@ static GtkTextBuffer *text_view(GtkWidget *box, const char *label)
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN);
 
        view = gtk_text_view_new();
+       if (writable == READ_ONLY) {
+               gtk_widget_set_can_focus(view, FALSE);
+               gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE);
+               gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(view), FALSE);
+               g_signal_connect(view, "populate-popup", G_CALLBACK(populate_popup_cb), NULL);
+       }
        gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
        gtk_container_add(GTK_CONTAINER(scrolled_window), view);
-
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
        gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
-       return buffer;
+       return GTK_TEXT_VIEW(view);
 }
 
 static enum {
@@ -228,8 +224,6 @@ static int match_list(GtkListStore *list, const char *string)
        return found_string_entry;
 }
 
-static GtkListStore *location_list, *people_list;
-
 static void add_string_list_entry(const char *string, GtkListStore *list)
 {
        GtkTreeIter *iter, loc;
@@ -261,6 +255,103 @@ void add_location(const char *string)
        add_string_list_entry(string, location_list);
 }
 
+struct dive_info {
+       GtkComboBoxEntry *location, *divemaster, *buddy;
+       GtkTextView *notes;
+};
+
+static void save_dive_info_changes(struct dive *dive, struct dive_info *info)
+{
+       char *old_text, *new_text;
+       int changed = 0;
+
+       new_text = get_combo_box_entry_text(info->location, &dive->location);
+       if (new_text) {
+               add_location(new_text);
+               changed = 1;
+       }
+
+       new_text = get_combo_box_entry_text(info->divemaster, &dive->divemaster);
+       if (new_text) {
+               add_people(new_text);
+               changed = 1;
+       }
+
+       new_text = get_combo_box_entry_text(info->buddy, &dive->buddy);
+       if (new_text) {
+               add_people(new_text);
+               changed = 1;
+       }
+
+       old_text = dive->notes;
+       dive->notes = get_text(info->notes);
+       if (text_changed(old_text,dive->notes))
+               changed = 1;
+       if (old_text)
+               g_free(old_text);
+
+       if (changed) {
+               mark_divelist_changed(TRUE);
+               flush_divelist(dive);
+       }
+}
+
+static void dive_info_widget(GtkWidget *box, struct dive *dive, struct dive_info *info)
+{
+       GtkWidget *hbox, *label, *cylinder, *frame;
+       char buffer[80];
+
+       divename(buffer, sizeof(buffer), dive);
+       label = gtk_label_new(buffer);
+       gtk_box_pack_start(GTK_BOX(box), label, FALSE, TRUE, 0);
+
+       info->location = text_entry(box, "Location", location_list, dive->location);
+
+       hbox = gtk_hbox_new(FALSE, 3);
+       gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, TRUE, 0);
+
+       info->divemaster = text_entry(hbox, "Dive master", people_list, dive->divemaster);
+       info->buddy = text_entry(hbox, "Buddy", people_list, dive->buddy);
+
+       info->notes = text_view(box, "Notes", READ_WRITE);
+       if (dive->notes && *dive->notes)
+               gtk_text_buffer_set_text(gtk_text_view_get_buffer(info->notes), dive->notes, -1);
+
+       frame = gtk_frame_new("Cylinder");
+       cylinder = cylinder_list_widget();
+       gtk_container_add(GTK_CONTAINER(frame), cylinder);
+       gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0);
+}
+
+int edit_dive_info(struct dive *dive)
+{
+       int success;
+       GtkWidget *dialog, *vbox;
+       struct dive_info info;
+
+       if (!dive)
+               return 0;
+
+       dialog = gtk_dialog_new_with_buttons("Dive Info",
+               GTK_WINDOW(main_window),
+               GTK_DIALOG_DESTROY_WITH_PARENT,
+               GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+               GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+               NULL);
+
+       vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+       dive_info_widget(vbox, dive, &info);
+
+       gtk_widget_show_all(dialog);
+       success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
+       if (success)
+               save_dive_info_changes(dive, &info);
+
+       gtk_widget_destroy(dialog);
+
+       return success;
+}
+
 GtkWidget *extended_dive_info_widget(void)
 {
        GtkWidget *vbox, *hbox;
@@ -270,14 +361,14 @@ GtkWidget *extended_dive_info_widget(void)
        location_list = gtk_list_store_new(1, G_TYPE_STRING);
 
        gtk_container_set_border_width(GTK_CONTAINER(vbox), 6);
-       location = text_entry(vbox, "Location", location_list);
+       location = text_value(vbox, "Location");
 
        hbox = gtk_hbox_new(FALSE, 3);
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
 
-       divemaster = text_entry(hbox, "Divemaster", people_list);
-       buddy = text_entry(hbox, "Buddy", people_list);
+       divemaster = text_value(hbox, "Divemaster");
+       buddy = text_value(hbox, "Buddy");
 
-       notes = text_view(vbox, "Notes");
+       notes = text_view(vbox, "Notes", READ_ONLY);
        return vbox;
 }
diff --git a/main.c b/main.c
index 9aaa5d1f42ca61b384fb37740a7ebbbefe9472dc..d77fcd2d97adbf4c6eac1410bddc4424635f01d9 100644 (file)
--- a/main.c
+++ b/main.c
@@ -186,8 +186,6 @@ void update_dive(struct dive *new_dive)
        struct dive *old_dive = buffered_dive;
 
        if (old_dive) {
-               flush_dive_info_changes(old_dive);
-               flush_dive_equipment_changes(old_dive);
                flush_divelist(old_dive);
        }
        if (new_dive) {