summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dive.h2
-rw-r--r--divelist.c98
-rw-r--r--equipment.c34
-rw-r--r--gtk-gui.c10
-rw-r--r--info.c85
5 files changed, 172 insertions, 57 deletions
diff --git a/dive.h b/dive.h
index 1a61a4a45..4d736b119 100644
--- a/dive.h
+++ b/dive.h
@@ -97,8 +97,6 @@ extern gboolean cylinder_nodata(cylinder_t *cyl);
extern gboolean cylinder_nosamples(cylinder_t *cyl);
extern gboolean cylinder_none(void *_data);
extern gboolean no_cylinders(cylinder_t *cyl);
-extern gboolean cylinders_equal(cylinder_t *cyl1, cylinder_t *cyl2);
-extern void copy_cylinders(cylinder_t *cyl1, cylinder_t *cyl2);
extern gboolean no_weightsystems(weightsystem_t *ws);
extern gboolean weightsystems_equal(weightsystem_t *ws1, weightsystem_t *ws2);
diff --git a/divelist.c b/divelist.c
index 810b5be7c..ce9796d82 100644
--- a/divelist.c
+++ b/divelist.c
@@ -1842,19 +1842,16 @@ void merge_trips_cb(GtkWidget *menuitem, GtkTreePath *trippath)
mark_divelist_changed(TRUE);
}
-/* this gets called with path pointing to a dive, either in the top level
- * or as part of a trip */
-static void delete_dive_cb(GtkWidget *menuitem, GtkTreePath *path)
+/* delete a dive by passing a tree iterator */
+static void delete_single_dive(GtkTreeIter *iter)
{
- GtkTreeIter iter;
- int idx, i;
+ int i, idx;
struct dive *dive, *pdive, *ndive;
- GtkTreeView *tree_view = GTK_TREE_VIEW(dive_list.tree_view);
- GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
+ GtkTreeIter parent;
- gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
- gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1);
+ gtk_tree_model_get(MODEL(dive_list), iter, DIVE_INDEX, &idx, -1);
dive = get_dive(idx);
+
if (dive->divetrip) {
/* we could be displaying the list model, in which case we can't find out
* if this is part of a trip and the only dive in that trip from the model,
@@ -1869,8 +1866,10 @@ static void delete_dive_cb(GtkWidget *menuitem, GtkTreePath *path)
GList *trip = find_matching_trip(dive->when);
delete_trip(trip);
free(dive->divetrip);
+ dive->divetrip = NULL;
}
}
+
/* simply remove the dive and recreate the divelist
* (we can't just manipulate the tree_view as the indices for dives change) */
for (i = idx; i < dive_table.nr - 1; i++)
@@ -1878,7 +1877,69 @@ static void delete_dive_cb(GtkWidget *menuitem, GtkTreePath *path)
dive_table.nr--;
if (dive->selected)
amount_selected--;
+
+ /* once the dive is deleted, update the 'when' flag of the trip it was part of
+ * to the 'when' flag of the earliest dive left in the same trip */
+ if (dive->divetrip) {
+ gtk_tree_model_iter_parent(MODEL(dive_list), &parent, iter);
+ gtk_tree_store_remove(STORE(dive_list), iter);
+ update_trip_timestamp(&parent, dive->divetrip);
+ }
+
free(dive);
+}
+
+/* workaround for not using gtk_tree_selection_get_selected_rows() or modifying the tree
+ * directly from the gtk_tree_selection_selected_foreach() callback function */
+struct tree_selected_st {
+ GtkTreeIter *list;
+ int total;
+};
+
+static void tree_selected_foreach(GtkTreeModel *model, GtkTreePath *path,
+ GtkTreeIter *iter, gpointer userdata)
+{
+ struct tree_selected_st *st = (struct tree_selected_st *)userdata;
+
+ st->total++;
+ st->list = (GtkTreeIter *)realloc(st->list, sizeof(GtkTreeIter) * st->total);
+ memcpy(&st->list[st->total - 1], iter, sizeof(GtkTreeIter));
+}
+
+/* called when multiple dives are selected and one of these is right-clicked for delete */
+static void delete_selected_dives_cb(GtkWidget *menuitem, GtkTreePath *path)
+{
+ int i;
+ GtkTreeView *tree_view = GTK_TREE_VIEW(dive_list.tree_view);
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
+ struct tree_selected_st st = {NULL, 0};
+
+ gtk_tree_selection_selected_foreach(selection, tree_selected_foreach, &st);
+
+ for (i = 0; i < st.total; i++)
+ delete_single_dive(&st.list[i]);
+ free(st.list);
+
+ dive_list_update_dives();
+ mark_divelist_changed(TRUE);
+}
+
+/* this gets called with path pointing to a dive, either in the top level
+ * or as part of a trip */
+static void delete_dive_cb(GtkWidget *menuitem, GtkTreePath *path)
+{
+ GtkTreeIter iter;
+ int i, idx;
+ struct dive *dive;
+ GtkTreeView *tree_view = GTK_TREE_VIEW(dive_list.tree_view);
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
+
+ gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
+ delete_single_dive(&iter);
+
+ gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1);
+ dive = get_dive(idx);
+
/* now make sure the correct dive list is displayed, the same
* dives stay selected and if necessary their trips are
* expanded. If no selected dives are left then fill_dive_list()
@@ -1900,6 +1961,7 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int
{
GtkWidget *menu, *menuitem, *image;
char editlabel[] = "Edit dives";
+ char deletelabel[] = "Delete dives";
GtkTreePath *path, *prevpath, *nextpath;
GtkTreeIter iter, previter, nextiter;
int idx, previdx, nextidx;
@@ -1946,18 +2008,26 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int
g_signal_connect(menuitem, "activate", G_CALLBACK(remove_trip_cb), path);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
} else {
- menuitem = gtk_menu_item_new_with_label("Delete Dive");
- g_signal_connect(menuitem, "activate", G_CALLBACK(delete_dive_cb), path);
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
dive = get_dive(idx);
- /* if we right click on selected dive(s), edit those */
+ /* if we right click on selected dive(s), edit or delete those */
if (dive->selected) {
- if (amount_selected == 1)
+ if (amount_selected == 1) {
+ deletelabel[strlen(deletelabel) - 1] = '\0';
editlabel[strlen(editlabel) - 1] = '\0';
+ }
+ menuitem = gtk_menu_item_new_with_label(deletelabel);
+ g_signal_connect(menuitem, "activate", G_CALLBACK(delete_selected_dives_cb), path);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+
menuitem = gtk_menu_item_new_with_label(editlabel);
g_signal_connect(menuitem, "activate", G_CALLBACK(edit_selected_dives_cb), NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
} else {
+ deletelabel[strlen(deletelabel) - 1] = '\0';
+ menuitem = gtk_menu_item_new_with_label(deletelabel);
+ g_signal_connect(menuitem, "activate", G_CALLBACK(delete_dive_cb), path);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+
editlabel[strlen(editlabel) - 1] = '\0';
menuitem = gtk_menu_item_new_with_label(editlabel);
g_signal_connect(menuitem, "activate", G_CALLBACK(edit_dive_from_path_cb), path);
diff --git a/equipment.c b/equipment.c
index 7c473f6df..ccdee6268 100644
--- a/equipment.c
+++ b/equipment.c
@@ -485,40 +485,6 @@ gboolean description_equal(const char *desc1, const char *desc2)
(desc1 && desc2 && strcmp(desc1, desc2) == 0));
}
-/* when checking for the same cylinder we want the size and description to match
- but don't compare the start and end pressures, nor the Nitrox/He values */
-static gboolean one_cylinder_equal(cylinder_t *cyl1, cylinder_t *cyl2)
-{
- return cyl1->type.size.mliter == cyl2->type.size.mliter &&
- cyl1->type.workingpressure.mbar == cyl2->type.workingpressure.mbar &&
- description_equal(cyl1->type.description, cyl2->type.description);
-}
-
-gboolean cylinders_equal(cylinder_t *cyl1, cylinder_t *cyl2)
-{
- int i;
-
- for (i = 0; i < MAX_CYLINDERS; i++)
- if (!one_cylinder_equal(cyl1 + i, cyl2 + i))
- return FALSE;
- return TRUE;
-}
-
-/* copy size and description of all cylinders from cyl1 to cyl2 */
-void copy_cylinders(cylinder_t *cyl1, cylinder_t *cyl2)
-{
- int i;
-
- for (i = 0; i < MAX_CYLINDERS; i++) {
- cyl2[i].type.size.mliter = cyl1[i].type.size.mliter;
- cyl2[i].type.workingpressure.mbar = cyl1[i].type.workingpressure.mbar;
- if (cyl1[i].type.description)
- cyl2[i].type.description = strdup(cyl1[i].type.description);
- else
- cyl2[i].type.description = NULL;
- }
-}
-
static gboolean weightsystem_none(void *_data)
{
weightsystem_t *ws = _data;
diff --git a/gtk-gui.c b/gtk-gui.c
index 11f9a8013..8704771c7 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -72,7 +72,9 @@ static void set_default_dive_computer_device(const char *name)
return;
if (is_default_dive_computer_device(name))
return;
- default_dive_computer_device = name;
+ if (default_dive_computer_device)
+ free((void *)default_dive_computer_device);
+ default_dive_computer_device = strdup(name);
subsurface_set_conf("dive_computer_device", PREF_STRING, name);
}
@@ -821,14 +823,14 @@ static void about_dialog(GtkWidget *w, gpointer data)
if (need_icon) {
GtkWidget *image = gtk_image_new_from_file(subsurface_icon_name());
- if (image) {
+ if (gtk_image_get_storage_type(GTK_IMAGE(image)) == GTK_IMAGE_PIXBUF) {
logo = gtk_image_get_pixbuf(GTK_IMAGE(image));
logo_property = "logo";
}
}
gtk_show_about_dialog(NULL,
- "program-name", "SubSurface",
+ "program-name", "Subsurface",
"comments", "Multi-platform divelog software in C",
"license", "GPLv2",
"version", VERSION_STRING,
@@ -1118,6 +1120,8 @@ void exit_ui(void)
free((char *)default_filename);
if (existing_filename)
free((void *)existing_filename);
+ if (default_dive_computer_device)
+ free((void *)default_dive_computer_device);
}
typedef struct {
diff --git a/info.c b/info.c
index 96e270459..ce7240c39 100644
--- a/info.c
+++ b/info.c
@@ -519,18 +519,95 @@ static void save_equipment_data(struct dive *dive)
}
}
+/* Empty and NULL compare equal */
+static int same_string(const char *a, const char *b)
+{
+ /* Both NULL or same */
+ if (a == b)
+ return 1;
+ /* Both non-NULL: strcmp */
+ if (a && b)
+ return !strcmp(a, b);
+ /* One non-NULL? Is that one empty? */
+ return !*(a ? a : b);
+}
+
+static int same_type(cylinder_t *dst, cylinder_t *src)
+{
+ return dst->type.size.mliter == src->type.size.mliter &&
+ dst->type.workingpressure.mbar == src->type.workingpressure.mbar &&
+ same_string(dst->type.description, src->type.description);
+}
+
+static void copy_type(cylinder_t *dst, cylinder_t *src)
+{
+ dst->type.size = src->type.size;
+ dst->type.workingpressure = src->type.workingpressure;
+ if (dst->type.description)
+ free((void *)dst->type.description);
+ if (!src->type.description || !*src->type.description)
+ dst->type.description = NULL;
+ else
+ dst->type.description = strdup((char *)src->type.description);
+}
+
+static int same_gasmix(cylinder_t *dst, cylinder_t *src)
+{
+ return !memcmp(&dst->gasmix, &src->gasmix, sizeof(dst->gasmix));
+}
+
+static void copy_gasmix(cylinder_t *dst, cylinder_t *src)
+{
+ memcpy(&dst->gasmix, &src->gasmix, sizeof(dst->gasmix));
+}
+
+static int same_press(cylinder_t *dst, cylinder_t *src)
+{
+ return dst->start.mbar == src->start.mbar &&
+ dst->end.mbar == src->end.mbar;
+}
+
+static void copy_press(cylinder_t *dst, cylinder_t *src)
+{
+ dst->start = src->start;
+ dst->end = src->end;
+}
+
+/*
+ * When we update the cylinder information, we do it individually
+ * by type/gasmix/pressure, so that you can change them separately.
+ *
+ * The rule is: the destination has to be the same as the original
+ * field, and the source has to have changed. If so, we change the
+ * destination field.
+ */
+static void update_cylinder(cylinder_t *dst, cylinder_t *src, cylinder_t *orig)
+{
+ /* Destination type same? Change it */
+ if (same_type(dst, orig) && !same_type(src, orig))
+ copy_type(dst, src);
+
+ /* Destination gasmix same? Change it */
+ if (same_gasmix(dst, orig) && !same_gasmix(src, orig))
+ copy_gasmix(dst, src);
+
+ /* Destination pressures the same? */
+ if (same_press(dst, orig) && !same_press(src, orig))
+ copy_press(dst, src);
+}
+
/* the editing happens on the master dive; we copy the equipment
data if it has changed in the master dive and the other dive
either has no entries for the equipment or the same entries
as the master dive had before it was edited */
void update_equipment_data(struct dive *dive, struct dive *master)
{
+ int i;
+
if (dive == master)
return;
- if ( ! cylinders_equal(remember_cyl, master->cylinder) &&
- (no_cylinders(dive->cylinder) ||
- cylinders_equal(dive->cylinder, remember_cyl)))
- copy_cylinders(master->cylinder, dive->cylinder);
+ for (i = 0; i < MAX_CYLINDERS; i++)
+ update_cylinder(dive->cylinder+i, master->cylinder+i, remember_cyl+i);
if (! weightsystems_equal(remember_ws, master->weightsystem) &&
(no_weightsystems(dive->weightsystem) ||
weightsystems_equal(dive->weightsystem, remember_ws)))