summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--divelist.c60
-rw-r--r--gtk-gui.c33
-rw-r--r--print.c54
3 files changed, 80 insertions, 67 deletions
diff --git a/divelist.c b/divelist.c
index 32f5f44a3..f2e678181 100644
--- a/divelist.c
+++ b/divelist.c
@@ -2740,7 +2740,7 @@ static GtkTreeIter *get_iter_from_idx(int idx)
void select_next_dive(void)
{
- GtkTreeIter *nextiter;
+ GtkTreeIter *nextiter, *parent;
GtkTreeIter *iter = get_iter_from_idx(selected_dive);
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
GtkTreePath *treepath;
@@ -2750,31 +2750,33 @@ void select_next_dive(void)
return;
nextiter = gtk_tree_iter_copy(iter);
if (!gtk_tree_model_iter_next(MODEL(dive_list), nextiter)) {
- if (!gtk_tree_model_iter_parent(MODEL(dive_list), nextiter, iter))
+ if (!gtk_tree_model_iter_parent(MODEL(dive_list), nextiter, iter)) {
/* we're at the last top level node */
return;
- if (!gtk_tree_model_iter_next(MODEL(dive_list), nextiter))
+ }
+ if (!gtk_tree_model_iter_next(MODEL(dive_list), nextiter)) {
/* last trip */
return;
- gtk_tree_model_get(MODEL(dive_list), nextiter, DIVE_INDEX, &idx, -1);
- if (idx < 0) {
- /* need the first child */
- GtkTreeIter *parent = gtk_tree_iter_copy(nextiter);
- if (! gtk_tree_model_iter_children(MODEL(dive_list), nextiter, parent))
- return;
}
}
+ gtk_tree_model_get(MODEL(dive_list), nextiter, DIVE_INDEX, &idx, -1);
+ if (idx < 0) {
+ /* need the first child */
+ parent = gtk_tree_iter_copy(nextiter);
+ if (! gtk_tree_model_iter_children(MODEL(dive_list), nextiter, parent))
+ return;
+ }
treepath = gtk_tree_model_get_path(MODEL(dive_list), nextiter);
gtk_tree_view_expand_to_path(GTK_TREE_VIEW(dive_list.tree_view), treepath);
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(dive_list.tree_view), treepath, NULL, FALSE, 0, 0);
+ gtk_tree_selection_unselect_all(selection);
gtk_tree_selection_select_iter(selection, nextiter);
- gtk_tree_selection_unselect_iter(selection, iter);
gtk_tree_path_free(treepath);
}
void select_prev_dive(void)
{
- GtkTreeIter previter;
+ GtkTreeIter previter, *parent;
GtkTreeIter *iter = get_iter_from_idx(selected_dive);
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
GtkTreePath *treepath;
@@ -2786,29 +2788,31 @@ void select_prev_dive(void)
if (!gtk_tree_path_prev(treepath)) {
if (!gtk_tree_model_iter_parent(MODEL(dive_list), &previter, iter))
/* we're at the last top level node */
- return;
+ goto free_path;
+ gtk_tree_path_free(treepath);
treepath = gtk_tree_model_get_path(MODEL(dive_list), &previter);
if (!gtk_tree_path_prev(treepath))
/* first trip */
- return;
- if (!gtk_tree_model_get_iter(MODEL(dive_list), &previter, treepath))
- return;
- gtk_tree_model_get(MODEL(dive_list), &previter, DIVE_INDEX, &idx, -1);
- if (idx < 0) {
- /* need the last child */
- GtkTreeIter *parent = gtk_tree_iter_copy(&previter);
- if (! gtk_tree_model_iter_nth_child(MODEL(dive_list), &previter, parent,
- gtk_tree_model_iter_n_children(MODEL(dive_list), parent) - 1))
- return;
- }
- treepath = gtk_tree_model_get_path(MODEL(dive_list), &previter);
- } else {
+ goto free_path;
if (!gtk_tree_model_get_iter(MODEL(dive_list), &previter, treepath))
- return;
+ goto free_path;
}
+ if (!gtk_tree_model_get_iter(MODEL(dive_list), &previter, treepath))
+ goto free_path;
+ gtk_tree_model_get(MODEL(dive_list), &previter, DIVE_INDEX, &idx, -1);
+ if (idx < 0) {
+ /* need the last child */
+ parent = gtk_tree_iter_copy(&previter);
+ if (! gtk_tree_model_iter_nth_child(MODEL(dive_list), &previter, parent,
+ gtk_tree_model_iter_n_children(MODEL(dive_list), parent) - 1))
+ goto free_path;
+ }
+ gtk_tree_path_free(treepath);
+ treepath = gtk_tree_model_get_path(MODEL(dive_list), &previter);
gtk_tree_view_expand_to_path(GTK_TREE_VIEW(dive_list.tree_view), treepath);
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(dive_list.tree_view), treepath, NULL, FALSE, 0, 0);
+ gtk_tree_selection_unselect_all(selection);
gtk_tree_selection_select_iter(selection, &previter);
- gtk_tree_selection_unselect_iter(selection, iter);
- gtk_tree_path_free(treepath);
+ free_path:
+ gtk_tree_path_free(treepath);
}
diff --git a/gtk-gui.c b/gtk-gui.c
index 1b1113cad..0540de266 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -1210,7 +1210,7 @@ static void switch_page(GtkNotebook *notebook, gint arg1, gpointer user_data)
static gboolean on_key_press(GtkWidget *w, GdkEventKey *event, GtkWidget *divelist)
{
- if (event->type != GDK_KEY_PRESS)
+ if (event->type != GDK_KEY_PRESS || event->state != 0)
return FALSE;
switch (event->keyval) {
case GDK_Up:
@@ -2267,40 +2267,29 @@ static char *cleanedup_nickname(const char *nickname, int len)
void replace_nickname_nicknamestring(const char *model, int deviceid, const char *nickname)
{
- char buf[11];
- char *entry, *comma1, *comma2, *brace, *new_nn;
+ char pattern[160];
+ char *entry, *brace, *new_nn;
int len;
if (!nickname)
nickname = "";
- snprintf(buf, sizeof(buf), "{%08x,", deviceid);
- entry = strstr(nicknamestring, buf);
+ snprintf(pattern, sizeof(pattern), "{%08x,%s", deviceid, model);
+ entry = strstr(nicknamestring, pattern);
if (!entry)
/* this cannot happen as we know we have an entry for this deviceid */
goto bail;
+
len = strlen(entry);
- comma1 = g_utf8_strchr(entry, len, ',');
- if (!comma1)
- goto bail;
- len = strlen(comma1);
- comma2 = g_utf8_strchr(comma1, len, ',');
- brace = g_utf8_strchr(comma1, len, '}');
+ brace = g_utf8_strchr(entry, len, '}');
if (!brace)
goto bail;
- if (!comma2 || brace < comma2) {
- /* didn't have a nickname, so add one */
- len = strlen(nicknamestring) + strlen(nickname) + 2;
- *brace = '\0';
- } else {
- /* replace the nickname */
- len = strlen(nicknamestring) + strlen(nickname) - (brace - comma2) + 1;
- *comma2 = '\0';
- }
+ *entry = *brace = '\0';
+ len = strlen(nicknamestring) + strlen(brace + 1) + strlen(pattern) + strlen(nickname) + 3;
new_nn = malloc(len);
if (strlen(nickname))
- snprintf(new_nn, len, "%s,%s}%s", nicknamestring, nickname, brace + 1);
+ snprintf(new_nn, len, "%s%s,%s}%s", nicknamestring, pattern, nickname, brace + 1);
else
- snprintf(new_nn, len, "%s}%s", nicknamestring, brace + 1);
+ snprintf(new_nn, len, "%s%s}%s", nicknamestring, pattern, brace + 1);
free(nicknamestring);
nicknamestring = new_nn;
return;
diff --git a/print.c b/print.c
index be9a0502b..3d1894d0d 100644
--- a/print.c
+++ b/print.c
@@ -187,13 +187,21 @@ static void print_ean_trimix (cairo_t *cr, PangoLayout *layout, int O2, int He){
pango_cairo_show_layout(cr, layout);
}
+static unsigned start_pressure(cylinder_t *cyl)
+{
+ return cyl->start.mbar ? : cyl->sample_start.mbar;
+}
+
+static unsigned end_pressure(cylinder_t *cyl)
+{
+ return cyl->end.mbar ? : cyl->sample_end.mbar;
+}
+
/* Print the tank data */
static void print_tanks (struct dive *dive, cairo_t *cr, int maxwidth, int maxheight,
int height, int tank_count, int first_tank, PangoFontDescription *font)
{
- int curwidth, decimals, n, i, counter, cyl_press, cyl_end;
- double cyl_cap, cyl_cons_gas;
- const char *unit_vol, *unit_press;
+ int curwidth, n, i, counter;
char buffer[80], dataheader1[3][80]= { N_("Cylinder"), N_("Gasmix"), N_("Gas Used")};
PangoLayout *layout;
@@ -219,35 +227,47 @@ static void print_tanks (struct dive *dive, cairo_t *cr, int maxwidth, int maxhe
/* Then the cylinder stuff */
n = first_tank;
counter = 0;
- while ( n < tank_count && n < first_tank + 4){
+ while ( n < tank_count && n < first_tank + 4) {
+ int decimals;
+ const char *unit, *desc;
+ double gas_usage;
+ cylinder_t *cyl = dive->cylinder + n;
+
cairo_translate (cr, 0, height / (double) PANGO_SCALE);
cairo_move_to(cr, 0, 0);
- cyl_cap = get_volume_units(dive->cylinder[n].type.size.mliter, &decimals, &unit_vol);
- cyl_press= get_pressure_units(dive->cylinder[n].start.mbar, &unit_press);
- cyl_end= get_pressure_units(dive->cylinder[n].end.mbar, &unit_press);
- cyl_cons_gas = (cyl_press - cyl_end) * cyl_cap;
+
+ /* Get the cylinder gas use in mbar */
+ gas_usage = start_pressure(cyl) - end_pressure(cyl);
+
+ /* Can we turn it into a volume? */
+ if (cyl->type.size.mliter) {
+ gas_usage = bar_to_atm(gas_usage / 1000);
+ gas_usage *= cyl->type.size.mliter;
+ gas_usage = get_volume_units(gas_usage, &decimals, &unit);
+ } else {
+ gas_usage = get_pressure_units(gas_usage, &unit);
+ decimals = 0;
+ }
curwidth = 0;
cairo_move_to (cr, curwidth / (double) PANGO_SCALE, 0);
- snprintf(buffer, sizeof(buffer), "%s", dive->cylinder[n].type.description);
+ desc = cyl->type.description ? : "";
+ snprintf(buffer, sizeof(buffer), "%s", desc);
pango_layout_set_text(layout, buffer, -1);
pango_cairo_show_layout(cr, layout);
curwidth += (maxwidth/ 3);
cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);
print_ean_trimix (cr, layout,
- dive->cylinder[n].gasmix.o2.permille/10,
- dive->cylinder[n].gasmix.he.permille/10);
+ cyl->gasmix.o2.permille/10,
+ cyl->gasmix.he.permille/10);
curwidth += (maxwidth/ 3);
cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);
- if (prefs.output_units.pressure == PSI) {
- cyl_cons_gas = (psi_to_bar(cyl_press) - psi_to_bar(cyl_end)) * cyl_cap;
- }
snprintf(buffer, sizeof(buffer), _("%.*f %s\n"),
decimals,
- cyl_cons_gas,
- unit_vol);
+ gas_usage,
+ unit);
pango_layout_set_text(layout, buffer, -1);
pango_cairo_show_layout(cr, layout);
curwidth += (maxwidth/ 3);
@@ -383,7 +403,7 @@ static void show_dive_tanks(struct dive *dive, cairo_t *cr, double w,
/* We need to know how many cylinders we used*/
for ( tank_count = 0; tank_count < MAX_CYLINDERS; tank_count++ ){
- if (dive->cylinder[tank_count].start.mbar == 0) {
+ if (cylinder_nodata(dive->cylinder+tank_count)) {
break;
}
}