]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Merge branch 'ui' of git://github.com/dirkhh/subsurface
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 24 Oct 2011 05:03:22 +0000 (07:03 +0200)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 24 Oct 2011 05:03:22 +0000 (07:03 +0200)
* 'ui' of git://github.com/dirkhh/subsurface:
  Disable sorting by dive number
  Fix oversight in preference implementation
  Make columns for temperature, cylinder, and nitrox optional
  Show dive number in dive list
  Improve time marker handling and add printing of some time labels

display-gtk.h
divelist.c
gtk-gui.c
main.c
profile.c

index fe373a14fc3ab9eb1349ee14080fdd36a4d79eec..fb2b9af5b40c0450677eba2b246ed8950f669f25 100644 (file)
@@ -12,6 +12,9 @@ typedef struct {
 } progressbar_t;
 
 typedef struct {
+       gboolean cylinder;
+       gboolean temperature;
+       gboolean nitrox;
        gboolean sac;
        gboolean otu;
 } visible_cols_t;
index 5f2063e9f8192fa6f10fb4a744f046dd5b448904..3ddfb6582dea8aedb2a44ef6e257f7452e42f0e7 100644 (file)
@@ -25,7 +25,7 @@ struct DiveList {
        GtkWidget    *tree_view;
        GtkWidget    *container_widget;
        GtkListStore *model;
-       GtkTreeViewColumn *date, *depth, *duration, *location;
+       GtkTreeViewColumn *nr, *date, *depth, *duration, *location;
        GtkTreeViewColumn *temperature, *cylinder, *nitrox, *sac, *otu;
        int changed;
 };
@@ -38,6 +38,7 @@ static struct DiveList dive_list;
  */
 enum {
        DIVE_INDEX = 0,
+       DIVE_NR,                /* int: dive->nr */
        DIVE_DATE,              /* time_t: dive->when */
        DIVE_DEPTH,             /* int: dive->maxdepth in mm */
        DIVE_DURATION,          /* int: in seconds */
@@ -375,6 +376,7 @@ static void fill_one_dive(struct dive *dive,
         * The core data itself is unaffected by units
         */
        gtk_list_store_set(GTK_LIST_STORE(model), iter,
+               DIVE_NR, dive->number,
                DIVE_LOCATION, location,
                DIVE_CYLINDER, cylinder,
                DIVE_SAC, sac,
@@ -449,6 +451,9 @@ void update_dive_list_units(void)
 
 void update_dive_list_col_visibility(void)
 {
+       gtk_tree_view_column_set_visible(dive_list.cylinder, visible_cols.cylinder);
+       gtk_tree_view_column_set_visible(dive_list.temperature, visible_cols.temperature);
+       gtk_tree_view_column_set_visible(dive_list.nitrox, visible_cols.nitrox);
        gtk_tree_view_column_set_visible(dive_list.sac, visible_cols.sac);
        gtk_tree_view_column_set_visible(dive_list.otu, visible_cols.otu);
        return;
@@ -469,6 +474,7 @@ static void fill_dive_list(void)
                gtk_list_store_append(store, &iter);
                gtk_list_store_set(store, &iter,
                        DIVE_INDEX, i,
+                       DIVE_NR, dive->number,
                        DIVE_DATE, dive->when,
                        DIVE_DEPTH, dive->maxdepth,
                        DIVE_DURATION, dive->duration.seconds,
@@ -515,6 +521,7 @@ GtkWidget *dive_list_create(void)
 
        dive_list.model = gtk_list_store_new(DIVELIST_COLUMNS,
                                G_TYPE_INT,                     /* index */
+                               G_TYPE_INT,                     /* nr */
                                G_TYPE_INT,                     /* Date */
                                G_TYPE_INT,                     /* Depth */
                                G_TYPE_INT,                     /* Duration */
@@ -533,12 +540,14 @@ GtkWidget *dive_list_create(void)
        gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE);
        gtk_widget_set_size_request(dive_list.tree_view, 200, 200);
 
+       dive_list.nr = divelist_column(&dive_list, DIVE_NR, "#", NULL, PANGO_ALIGN_RIGHT, TRUE);
+       gtk_tree_view_column_set_sort_column_id(dive_list.nr, -1);
        dive_list.date = divelist_column(&dive_list, DIVE_DATE, "Date", date_data_func, PANGO_ALIGN_LEFT, TRUE);
        dive_list.depth = divelist_column(&dive_list, DIVE_DEPTH, "ft", depth_data_func, PANGO_ALIGN_RIGHT, TRUE);
        dive_list.duration = divelist_column(&dive_list, DIVE_DURATION, "min", duration_data_func, PANGO_ALIGN_RIGHT, TRUE);
-       dive_list.temperature = divelist_column(&dive_list, DIVE_TEMPERATURE, UTF8_DEGREE "F", temperature_data_func, PANGO_ALIGN_RIGHT, TRUE);
-       dive_list.cylinder = divelist_column(&dive_list, DIVE_CYLINDER, "Cyl", NULL, PANGO_ALIGN_CENTER, TRUE);
-       dive_list.nitrox = divelist_column(&dive_list, DIVE_NITROX, "O" UTF8_SUBSCRIPT_2 "%", nitrox_data_func, PANGO_ALIGN_CENTER, TRUE);
+       dive_list.temperature = divelist_column(&dive_list, DIVE_TEMPERATURE, UTF8_DEGREE "F", temperature_data_func, PANGO_ALIGN_RIGHT, visible_cols.temperature);
+       dive_list.cylinder = divelist_column(&dive_list, DIVE_CYLINDER, "Cyl", NULL, PANGO_ALIGN_CENTER, visible_cols.cylinder);
+       dive_list.nitrox = divelist_column(&dive_list, DIVE_NITROX, "O" UTF8_SUBSCRIPT_2 "%", nitrox_data_func, PANGO_ALIGN_CENTER, visible_cols.nitrox);
        dive_list.sac = divelist_column(&dive_list, DIVE_SAC, "SAC", sac_data_func, PANGO_ALIGN_CENTER, visible_cols.sac);
        dive_list.otu = divelist_column(&dive_list, DIVE_OTU, "OTU", otu_data_func, PANGO_ALIGN_CENTER, visible_cols.otu);
        dive_list.location = divelist_column(&dive_list, DIVE_LOCATION, "Location", NULL, PANGO_ALIGN_LEFT, TRUE);
index 39703ff60eaad94102aad648fe41b2da687ac92c..47cab62fabc46f0d060d17e821434ce41d4bc211 100644 (file)
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -301,6 +301,9 @@ static void name(GtkWidget *w, gpointer data) \
 
 OPTIONCALLBACK(otu_toggle, visible_cols.otu)
 OPTIONCALLBACK(sac_toggle, visible_cols.sac)
+OPTIONCALLBACK(nitrox_toggle, visible_cols.nitrox)
+OPTIONCALLBACK(temperature_toggle, visible_cols.temperature)
+OPTIONCALLBACK(cylinder_toggle, visible_cols.cylinder)
 
 static void preferences_dialog(GtkWidget *w, gpointer data)
 {
@@ -349,6 +352,21 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
        box = gtk_hbox_new(FALSE, 6);
        gtk_container_add(GTK_CONTAINER(frame), box);
 
+       button = gtk_check_button_new_with_label("Show Temp");
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.temperature);
+       gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
+       g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(temperature_toggle), NULL);
+
+       button = gtk_check_button_new_with_label("Show Cyl");
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.cylinder);
+       gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
+       g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(cylinder_toggle), NULL);
+
+       button = gtk_check_button_new_with_label("Show O" UTF8_SUBSCRIPT_2 "%");
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.nitrox);
+       gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
+       g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(nitrox_toggle), NULL);
+
        button = gtk_check_button_new_with_label("Show SAC");
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.sac);
        gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
@@ -379,7 +397,10 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
                gconf_client_set_bool(gconf, GCONF_NAME(psi), output_units.pressure == PSI, NULL);
                gconf_client_set_bool(gconf, GCONF_NAME(cuft), output_units.volume == CUFT, NULL);
                gconf_client_set_bool(gconf, GCONF_NAME(fahrenheit), output_units.temperature == FAHRENHEIT, NULL);
-               gconf_client_set_bool(gconf, GCONF_NAME(SAC), ! visible_cols.sac, NULL); /* inverted to get the correct default */
+               gconf_client_set_bool(gconf, GCONF_NAME(TEMPERATURE), visible_cols.temperature, NULL);
+               gconf_client_set_bool(gconf, GCONF_NAME(CYLINDER), visible_cols.cylinder, NULL);
+               gconf_client_set_bool(gconf, GCONF_NAME(NITROX), visible_cols.nitrox, NULL);
+               gconf_client_set_bool(gconf, GCONF_NAME(SAC), visible_cols.sac, NULL);
                gconf_client_set_bool(gconf, GCONF_NAME(OTU), visible_cols.otu, NULL);
                gconf_client_set_string(gconf, GCONF_NAME(divelist_font), divelist_font, NULL);
        }
@@ -625,10 +646,12 @@ void init_ui(int argc, char **argv)
                output_units.volume = CUFT;
        if (gconf_client_get_bool(gconf, GCONF_NAME(fahrenheit), NULL))
                output_units.temperature = FAHRENHEIT;
-       /* an unset key is FALSE - so in order to get the default behavior right we 
-          invert the meaning of the SAC key */
+       /* an unset key is FALSE - all these are hidden by default */
+       visible_cols.cylinder = gconf_client_get_bool(gconf, GCONF_NAME(CYLINDER), NULL);
+       visible_cols.temperature = gconf_client_get_bool(gconf, GCONF_NAME(TEMPERATURE), NULL);
+       visible_cols.nitrox = gconf_client_get_bool(gconf, GCONF_NAME(NITROX), NULL);
        visible_cols.otu = gconf_client_get_bool(gconf, GCONF_NAME(OTU), NULL);
-       visible_cols.sac = gconf_client_get_bool(gconf, GCONF_NAME(SAC), NULL);
+       visible_cols.sac = gconf_client_get_bool(gconf, GCONF_NAME(SAC), NULL);
                
        divelist_font = gconf_client_get_string(gconf, GCONF_NAME(divelist_font), NULL);
        if (!divelist_font)
diff --git a/main.c b/main.c
index ee09b9a82e50b4ee0bceda0ef9eebdd7cadaae64..a82cffc2bc8c9de71fe7a38a5c08c27df94d911e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -203,6 +203,7 @@ void renumber_dives(int nr)
        for (i = 0; i < dive_table.nr; i++) {
                struct dive *dive = dive_table.dives[i];
                dive->number = nr + i;
+               flush_divelist(dive);
        }
        mark_divelist_changed(TRUE);
 }
index 78643cd753d1c393760c593e6d7957377ddbabbf..5dad475bcbc850de7464064afd3acc50e0e38efa 100644 (file)
--- a/profile.c
+++ b/profile.c
@@ -299,23 +299,43 @@ static void plot_minmax_profile(struct graphics_context *gc, struct plot_info *p
 
 static void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi)
 {
-       int i;
+       int i, incr;
        cairo_t *cr = gc->cr;
        int sec, depth;
        struct plot_data *entry;
        int maxtime, maxdepth, marker;
+       int increments[4] = { 5*60, 10*60, 15*60, 30*60 };
 
        /* Get plot scaling limits */
        maxtime = get_maxtime(pi);
        maxdepth = get_maxdepth(pi);
 
-       /* Time markers: every 5 min */
+       /* Time markers: at most every 5 min, but no more than 12 markers
+        * and for convenience we do 5, 10, 15 or 30 min intervals.
+        * This allows for 6h dives - enough (I hope) for even the craziest
+        * divers - but just in case, for those 8h depth-record-breaking dives,
+        * we double the interval if this still doesn't get us to 12 or fewer
+        * time markers */
+       i = 0;
+       while (maxtime / increments[i] > 12 && i < 4)
+               i++;
+       incr = increments[i];
+       while (maxtime / incr > 12)
+               incr *= 2;
+
        gc->leftx = 0; gc->rightx = maxtime;
        gc->topy = 0; gc->bottomy = 1.0;
-       for (i = 5*60; i < maxtime; i += 5*60) {
+       set_source_rgba(gc, 1, 1, 1, 0.5);
+       for (i = incr; i < maxtime; i += incr) {
                move_to(gc, i, 0);
                line_to(gc, i, 1);
        }
+       cairo_stroke(cr);
+
+       /* now the text on every second time marker */
+       text_render_options_t tro = {10, 0.2, 1.0, 0.2, CENTER, TOP};
+       for (i = incr; i < maxtime; i += 2 * incr)
+               plot_text(gc, &tro, i, 1, "%d", i/60);
 
        /* Depth markers: every 30 ft or 10 m*/
        gc->leftx = 0; gc->rightx = 1.0;