summaryrefslogtreecommitdiffstats
path: root/info.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-08-31 16:26:04 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-01 21:29:05 -0700
commitc3debc10fdcb0f7e939872ea24d525f41039f5bd (patch)
treeb3f744f54e8ffde489a20930ed0608fddd706dfb /info.c
parenta5f894d1d3b53a3a99580d2da467a46d04c65266 (diff)
downloadsubsurface-c3debc10fdcb0f7e939872ea24d525f41039f5bd.tar.gz
Allow modification and edits of trips
Now that we can load and store trips we needed to add the capability to manipulate those trips as well. This commit allows us remove a dive from a trip via a right click operation on the dive list. The commit also adds code to split a trip into two, to merge two trips and to create a new trip out of a top level dive. To make all that useful this commit changes the right-click on the dive list to identify and act on the record we are actually on (instead of acting on the selection). The right-click menu ("context menu") changes depending which divelist entry the mouse pointer is on - so different operations are offered, depending on where you are. We also add simplistic editing of location and notes for a trip (but the notes are never displayed so far). To make our lives easier this commit adds a link from the dive to the dive trip it is part of. This allowed to hugely simplify the auto trip generation algorithm (among other things). The downside of this change is that there are now three different ways in which we express the relationship of dives and trips: in the dive_trip_list, in the tree_model, and with these pointers. Somehow this screams that I should rethink my data structures... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'info.c')
-rw-r--r--info.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/info.c b/info.c
index d9379ac68..d43d531a0 100644
--- a/info.c
+++ b/info.c
@@ -415,6 +415,24 @@ static void save_dive_info_changes(struct dive *dive, struct dive *master, struc
}
}
+static void dive_trip_widget(GtkWidget *box, struct dive *trip, struct dive_info *info)
+{
+ GtkWidget *hbox, *label;
+ char buffer[80] = "Edit trip summary";
+
+ label = gtk_label_new(buffer);
+ gtk_box_pack_start(GTK_BOX(box), label, FALSE, TRUE, 0);
+
+ info->location = text_entry(box, "Location", location_list, trip->location);
+
+ hbox = gtk_hbox_new(FALSE, 3);
+ gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, TRUE, 0);
+
+ info->notes = text_view(box, "Notes", READ_WRITE);
+ if (trip->notes && *trip->notes)
+ gtk_text_buffer_set_text(gtk_text_view_get_buffer(info->notes), trip->notes, -1);
+}
+
static void dive_info_widget(GtkWidget *box, struct dive *dive, struct dive_info *info, gboolean multi)
{
GtkWidget *hbox, *label, *frame, *equipment;
@@ -489,7 +507,49 @@ void update_equipment_data(struct dive *dive, struct dive *master)
memcpy(dive->weightsystem, master->weightsystem, WS_BYTES);
}
-/* A negative index means "all selected" */
+gboolean edit_trip(struct dive *trip)
+{
+ GtkWidget *dialog, *vbox;
+ int success;
+ gboolean changed = FALSE;
+ char *old_text, *new_text;
+ struct dive_info info;
+
+ memset(&info, 0, sizeof(struct dive_info));
+ dialog = gtk_dialog_new_with_buttons("Edit Trip 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_trip_widget(vbox, trip, &info);
+ gtk_widget_show_all(dialog);
+ success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
+ if (success) {
+ /* we need to store the edited location and notes */
+ new_text = get_combo_box_entry_text(info.location, &trip->location, trip->location);
+ if (new_text) {
+ add_location(new_text);
+ changed = 1;
+ }
+ if (info.notes) {
+ old_text = trip->notes;
+ trip->notes = get_text(info.notes);
+ if (text_changed(old_text, trip->notes))
+ changed = 1;
+ if (old_text)
+ g_free(old_text);
+ }
+ if (changed) {
+ mark_divelist_changed(TRUE);
+ flush_divelist(trip);
+ }
+ }
+ gtk_widget_destroy(dialog);
+ return changed;
+}
+
int edit_multi_dive_info(struct dive *single_dive)
{
int success;