GtkWidget *tree_view;
GtkWidget *container_widget;
GtkListStore *model;
- GtkTreeViewColumn *nr, *date, *depth, *duration, *location;
+ GtkTreeViewColumn *nr, *date, *stars, *depth, *duration, *location;
GtkTreeViewColumn *temperature, *cylinder, *nitrox, *sac, *otu;
int changed;
};
DIVE_INDEX = 0,
DIVE_NR, /* int: dive->nr */
DIVE_DATE, /* time_t: dive->when */
+ DIVE_RATING, /* int: 0-5 stars */
DIVE_DEPTH, /* int: dive->maxdepth in mm */
DIVE_DURATION, /* int: in seconds */
DIVE_TEMPERATURE, /* int: in mkelvin */
}
}
+const char *star_strings[] = {
+ ZERO_STARS,
+ ONE_STARS,
+ TWO_STARS,
+ THREE_STARS,
+ FOUR_STARS,
+ FIVE_STARS
+};
+
+static void star_data_func(GtkTreeViewColumn *col,
+ GtkCellRenderer *renderer,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ int nr_stars;
+ char buffer[40];
+
+ gtk_tree_model_get(model, iter, DIVE_RATING, &nr_stars, -1);
+ if (nr_stars < 0 || nr_stars > 5)
+ nr_stars = 0;
+ snprintf(buffer, sizeof(buffer), "%s", star_strings[nr_stars]);
+ g_object_set(renderer, "text", buffer, NULL);
+}
+
static void date_data_func(GtkTreeViewColumn *col,
GtkCellRenderer *renderer,
GtkTreeModel *model,
static int calculate_sac(struct dive *dive)
{
double airuse, pressure, sac;
+ int duration, i;
airuse = calculate_airuse(dive);
if (!airuse)
if (!dive->duration.seconds)
return 0;
+ /* find and eliminate long surface intervals */
+ duration = dive->duration.seconds;
+ for (i = 0; i < dive->samples; i++) {
+ if (dive->sample[i].depth.mm < 100) { /* less than 10cm */
+ int end = i + 1;
+ while (end < dive->samples && dive->sample[end].depth.mm < 100)
+ end++;
+ /* we only want the actual surface time during a dive */
+ if (end < dive->samples) {
+ end--;
+ duration -= dive->sample[end].time.seconds -
+ dive->sample[i].time.seconds;
+ i = end + 1;
+ }
+ }
+ }
/* Mean pressure in atm: 1 atm per 10m */
pressure = 1 + (dive->meandepth.mm / 10000.0);
- sac = airuse / pressure * 60 / dive->duration.seconds;
+ sac = airuse / pressure * 60 / duration;
/* milliliters per minute.. */
return sac * 1000;
DIVE_NR, dive->number,
DIVE_LOCATION, location,
DIVE_CYLINDER, cylinder,
+ DIVE_RATING, dive->rating,
DIVE_SAC, dive->sac,
DIVE_OTU, dive->otu,
-1);
G_TYPE_INT, /* index */
G_TYPE_INT, /* nr */
G_TYPE_INT, /* Date */
+ G_TYPE_INT, /* Star rating */
G_TYPE_INT, /* Depth */
G_TYPE_INT, /* Duration */
G_TYPE_INT, /* Temperature */
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.stars = divelist_column(&dive_list, DIVE_RATING, "Rating", star_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, visible_cols.temperature);