[PATCH] Add a "View next dive computer" menu item

Linus Torvalds torvalds at linux-foundation.org
Mon Dec 17 09:50:04 PST 2012


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Mon, 17 Dec 2012 09:37:07 -0800
Subject: [PATCH] Add a "View next dive computer" menu item

This adds the capability to actually view all your dive computers, by
adding a menu item under "Log"->"View"->"Next DC" to show the next dive
computer.

Realistically, if you actually commonly use this, you'd use the
accelerator shortcut.  Which right now is Ctrl-C ("C for Computer"),
which is probably a horrible choice.

I really would want to have nice "next/prev dive" accelerators too,
because the cursor keys don't work very well with the gtk focus issues.
Being able to switch between dives would also make the "just the dive
profile, maam" view (ctrl-2) much more useful.

The prev/next dive in the profile view should probably be done with a
keyboard action callback, which also avoids some of the limitations of
accelerators (ie you can make any key do the action).  Some gtk person,
please?

Anyway, this commit only does the dive computer choice thing, and only
using the accelerators.

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

Ok, ^C is probably a horrible choice, but we can paint that shed later. 
This finally actually exposes the fact that we keep track of multiple dive 
computers, and that I already wrote all the infrastructure to show them 
individually.

There's no "previous dive computer", because I don't expect people to have 
*so* many computers that you can't be bothered to just go through them in 
a forward direction. Doing ^C past the last dive computer will just start 
at the beginning again.

 display.h |  2 +-
 gtk-gui.c |  9 +++++++++
 profile.c | 18 ++++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/display.h b/display.h
index fbffc8f9545e..b337c4caab05 100644
--- a/display.h
+++ b/display.h
@@ -55,6 +55,6 @@ struct options {
 	int print_selected;
 };
 
-extern char zoomed_plot;
+extern char zoomed_plot, dc_number;
 
 #endif
diff --git a/gtk-gui.c b/gtk-gui.c
index 4d795be1d8c5..c22d2b573133 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -1014,6 +1014,13 @@ static void toggle_zoom(GtkWidget *w, gpointer data)
 	repaint_dive();
 }
 
+static void next_dc(GtkWidget *w, gpointer data)
+{
+	dc_number++;
+	/* If the dc number overflows, we'll "wrap around" and zero it */
+	repaint_dive();
+}
+
 static GtkActionEntry menu_items[] = {
 	{ "FileMenuAction", NULL, N_("File"), NULL, NULL, NULL},
 	{ "LogMenuAction",  NULL, N_("Log"), NULL, NULL, NULL},
@@ -1039,6 +1046,7 @@ static GtkActionEntry menu_items[] = {
 	{ "ViewProfile",    NULL, N_("Profile"), CTRLCHAR "2", NULL, G_CALLBACK(view_profile) },
 	{ "ViewInfo",       NULL, N_("Info"), CTRLCHAR "3", NULL, G_CALLBACK(view_info) },
 	{ "ViewThree",      NULL, N_("Three"), CTRLCHAR "4", NULL, G_CALLBACK(view_three) },
+	{ "NextDC",         NULL, N_("Next DC"), CTRLCHAR "C", NULL, G_CALLBACK(next_dc) },
 };
 static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
 
@@ -1080,6 +1088,7 @@ static const gchar* ui_string = " \
 					<menuitem name=\"Profile\" action=\"ViewProfile\" /> \
 					<menuitem name=\"Info\" action=\"ViewInfo\" /> \
 					<menuitem name=\"Paned\" action=\"ViewThree\" /> \
+					<menuitem name=\"NextDC\" action=\"NextDC\" /> \
 				</menu> \
 			</menu> \
 			<menu name=\"FilterMenu\" action=\"FilterMenuAction\"> \
diff --git a/profile.c b/profile.c
index 3bc5e8ed14b0..4244b47c7f55 100644
--- a/profile.c
+++ b/profile.c
@@ -20,6 +20,7 @@
 
 int selected_dive = 0;
 char zoomed_plot = 0;
+char dc_number = 0;
 
 static double plot_scale = SCALE_SCREEN;
 static struct plot_data *last_pi_entry = NULL;
@@ -1775,6 +1776,21 @@ static void plot_set_scale(scale_mode_t scale)
 	}
 }
 
+static struct divecomputer *select_dc(struct divecomputer *main)
+{
+	int i = dc_number;
+	struct divecomputer *dc = main;
+
+	do {
+		if (--i < 0)
+			return dc;
+	} while ((dc = dc->next) != NULL);
+
+	/* If we switched dives to one with fewer DC's, reset the dive computer counter */
+	dc_number = 0;
+	return main;
+}
+
 void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale)
 {
 	struct plot_info *pi;
@@ -1828,6 +1844,8 @@ void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale)
 	gc->maxx = (drawing_area->width - 2*drawing_area->x);
 	gc->maxy = (drawing_area->height - 2*drawing_area->y);
 
+	dc = select_dc(dc);
+
 	/* This is per-dive-computer. Right now we just do the first one */
 	pi = create_plot_info(dive, dc, gc);
 
-- 
1.8.0.dirty



More information about the subsurface mailing list