X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=divelist.c;h=36c40b8b249342e2288d25dd69950b95bb084386;hb=f9bb3f79106baba7cda330e0c04f54a01745581f;hp=a8afd3ac2e5aac5540bd0faef71d3863c33d8c4c;hpb=cb2114f263d7b23b8b2471cdf2037a0877eec50d;p=ext%2Fsubsurface.git diff --git a/divelist.c b/divelist.c index a8afd3a..36c40b8 100644 --- a/divelist.c +++ b/divelist.c @@ -25,7 +25,7 @@ struct DiveList { 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; }; @@ -40,6 +40,7 @@ enum { 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 */ @@ -89,6 +90,31 @@ static void selection_cb(GtkTreeSelection *selection, GtkTreeModel *model) } } +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, @@ -134,8 +160,9 @@ static void depth_data_func(GtkTreeViewColumn *col, frac = depth % 10; if (integer < 20) break; + if (frac >= 5) + integer++; frac = -1; - /* Rounding? */ break; case FEET: integer = mm_to_feet(depth) + 0.5; @@ -403,6 +430,7 @@ static void fill_one_dive(struct dive *dive, DIVE_NR, dive->number, DIVE_LOCATION, location, DIVE_CYLINDER, cylinder, + DIVE_RATING, dive->rating, DIVE_SAC, dive->sac, DIVE_OTU, dive->otu, -1); @@ -509,9 +537,11 @@ void dive_list_update_dives(void) } static GtkTreeViewColumn *divelist_column(struct DiveList *dl, int index, const char *title, - data_func_t data_func, PangoAlignment align, gboolean visible) + data_func_t data_func, unsigned int flags, int visible) { - return tree_view_column(dl->tree_view, index, title, data_func, align, visible); + if (!visible) + flags |= INVISIBLE; + return tree_view_column(dl->tree_view, index, title, data_func, flags); } /* @@ -545,6 +575,7 @@ GtkWidget *dive_list_create(void) 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 */ @@ -562,17 +593,17 @@ 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, 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); + dive_list.nr = divelist_column(&dive_list, DIVE_NR, "#", NULL, ALIGN_RIGHT | UNSORTABLE, TRUE); + dive_list.date = divelist_column(&dive_list, DIVE_DATE, "Date", date_data_func, ALIGN_LEFT, TRUE); + dive_list.stars = divelist_column(&dive_list, DIVE_RATING, UTF8_BLACKSTAR, star_data_func, ALIGN_LEFT, TRUE); + dive_list.depth = divelist_column(&dive_list, DIVE_DEPTH, "ft", depth_data_func, ALIGN_RIGHT, TRUE); + dive_list.duration = divelist_column(&dive_list, DIVE_DURATION, "min", duration_data_func, ALIGN_RIGHT, TRUE); + dive_list.temperature = divelist_column(&dive_list, DIVE_TEMPERATURE, UTF8_DEGREE "F", temperature_data_func, ALIGN_RIGHT, visible_cols.temperature); + dive_list.cylinder = divelist_column(&dive_list, DIVE_CYLINDER, "Cyl", NULL, 0, visible_cols.cylinder); + dive_list.nitrox = divelist_column(&dive_list, DIVE_NITROX, "O" UTF8_SUBSCRIPT_2 "%", nitrox_data_func, 0, visible_cols.nitrox); + dive_list.sac = divelist_column(&dive_list, DIVE_SAC, "SAC", sac_data_func, 0, visible_cols.sac); + dive_list.otu = divelist_column(&dive_list, DIVE_OTU, "OTU", otu_data_func, 0, visible_cols.otu); + dive_list.location = divelist_column(&dive_list, DIVE_LOCATION, "Location", NULL, ALIGN_LEFT, TRUE); fill_dive_list();