mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Add typical 0 to 5 star rating for dives
This works ok-ish, but doesn't allow us to click on the stars and edit them in the divelist, which a user might expect to be able to do - in most "star rating UIs" you simply click on the n-th star to set that rating. Here you need to edit the dive and pick the rating from a drop down menu. Minor oddity: you can actually (if you force it) write anything you want into the star rating. But anything that isn't one of the predefined strings simply results in a zero star rating. Overall the UI feels a bit... forced. But I think this is quite useful anyway. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
ce6c3ee56d
commit
af290d5eb2
6 changed files with 77 additions and 5 deletions
1
dive.c
1
dive.c
|
@ -559,6 +559,7 @@ struct dive *try_to_merge(struct dive *a, struct dive *b)
|
||||||
MERGE_TXT(res, a, b, notes);
|
MERGE_TXT(res, a, b, notes);
|
||||||
MERGE_TXT(res, a, b, buddy);
|
MERGE_TXT(res, a, b, buddy);
|
||||||
MERGE_TXT(res, a, b, divemaster);
|
MERGE_TXT(res, a, b, divemaster);
|
||||||
|
MERGE_MAX(res, a, b, rating);
|
||||||
MERGE_MAX(res, a, b, number);
|
MERGE_MAX(res, a, b, number);
|
||||||
MERGE_MAX(res, a, b, maxdepth.mm);
|
MERGE_MAX(res, a, b, maxdepth.mm);
|
||||||
res->meandepth.mm = 0;
|
res->meandepth.mm = 0;
|
||||||
|
|
10
dive.h
10
dive.h
|
@ -199,6 +199,7 @@ struct dive {
|
||||||
char *location;
|
char *location;
|
||||||
char *notes;
|
char *notes;
|
||||||
char *divemaster, *buddy;
|
char *divemaster, *buddy;
|
||||||
|
int rating;
|
||||||
double latitude, longitude;
|
double latitude, longitude;
|
||||||
depth_t maxdepth, meandepth;
|
depth_t maxdepth, meandepth;
|
||||||
duration_t duration, surfacetime;
|
duration_t duration, surfacetime;
|
||||||
|
@ -313,5 +314,14 @@ const char *monthname(int mon);
|
||||||
|
|
||||||
#define UTF8_DEGREE "\xc2\xb0"
|
#define UTF8_DEGREE "\xc2\xb0"
|
||||||
#define UTF8_SUBSCRIPT_2 "\xe2\x82\x82"
|
#define UTF8_SUBSCRIPT_2 "\xe2\x82\x82"
|
||||||
|
#define UTF8_WHITESTAR "\xe2\x98\x86"
|
||||||
|
#define UTF8_BLACKSTAR "\xe2\x98\x85"
|
||||||
|
#define ZERO_STARS UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
|
||||||
|
#define ONE_STARS UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
|
||||||
|
#define TWO_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
|
||||||
|
#define THREE_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR
|
||||||
|
#define FOUR_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR
|
||||||
|
#define FIVE_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR
|
||||||
|
extern const char *star_strings[];
|
||||||
|
|
||||||
#endif /* DIVE_H */
|
#endif /* DIVE_H */
|
||||||
|
|
31
divelist.c
31
divelist.c
|
@ -25,7 +25,7 @@ struct DiveList {
|
||||||
GtkWidget *tree_view;
|
GtkWidget *tree_view;
|
||||||
GtkWidget *container_widget;
|
GtkWidget *container_widget;
|
||||||
GtkListStore *model;
|
GtkListStore *model;
|
||||||
GtkTreeViewColumn *nr, *date, *depth, *duration, *location;
|
GtkTreeViewColumn *nr, *date, *stars, *depth, *duration, *location;
|
||||||
GtkTreeViewColumn *temperature, *cylinder, *nitrox, *sac, *otu;
|
GtkTreeViewColumn *temperature, *cylinder, *nitrox, *sac, *otu;
|
||||||
int changed;
|
int changed;
|
||||||
};
|
};
|
||||||
|
@ -40,6 +40,7 @@ enum {
|
||||||
DIVE_INDEX = 0,
|
DIVE_INDEX = 0,
|
||||||
DIVE_NR, /* int: dive->nr */
|
DIVE_NR, /* int: dive->nr */
|
||||||
DIVE_DATE, /* time_t: dive->when */
|
DIVE_DATE, /* time_t: dive->when */
|
||||||
|
DIVE_RATING, /* int: 0-5 stars */
|
||||||
DIVE_DEPTH, /* int: dive->maxdepth in mm */
|
DIVE_DEPTH, /* int: dive->maxdepth in mm */
|
||||||
DIVE_DURATION, /* int: in seconds */
|
DIVE_DURATION, /* int: in seconds */
|
||||||
DIVE_TEMPERATURE, /* int: in mkelvin */
|
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,
|
static void date_data_func(GtkTreeViewColumn *col,
|
||||||
GtkCellRenderer *renderer,
|
GtkCellRenderer *renderer,
|
||||||
GtkTreeModel *model,
|
GtkTreeModel *model,
|
||||||
|
@ -403,6 +429,7 @@ static void fill_one_dive(struct dive *dive,
|
||||||
DIVE_NR, dive->number,
|
DIVE_NR, dive->number,
|
||||||
DIVE_LOCATION, location,
|
DIVE_LOCATION, location,
|
||||||
DIVE_CYLINDER, cylinder,
|
DIVE_CYLINDER, cylinder,
|
||||||
|
DIVE_RATING, dive->rating,
|
||||||
DIVE_SAC, dive->sac,
|
DIVE_SAC, dive->sac,
|
||||||
DIVE_OTU, dive->otu,
|
DIVE_OTU, dive->otu,
|
||||||
-1);
|
-1);
|
||||||
|
@ -545,6 +572,7 @@ GtkWidget *dive_list_create(void)
|
||||||
G_TYPE_INT, /* index */
|
G_TYPE_INT, /* index */
|
||||||
G_TYPE_INT, /* nr */
|
G_TYPE_INT, /* nr */
|
||||||
G_TYPE_INT, /* Date */
|
G_TYPE_INT, /* Date */
|
||||||
|
G_TYPE_INT, /* Star rating */
|
||||||
G_TYPE_INT, /* Depth */
|
G_TYPE_INT, /* Depth */
|
||||||
G_TYPE_INT, /* Duration */
|
G_TYPE_INT, /* Duration */
|
||||||
G_TYPE_INT, /* Temperature */
|
G_TYPE_INT, /* Temperature */
|
||||||
|
@ -565,6 +593,7 @@ GtkWidget *dive_list_create(void)
|
||||||
dive_list.nr = divelist_column(&dive_list, DIVE_NR, "#", NULL, PANGO_ALIGN_RIGHT, TRUE);
|
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);
|
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.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.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.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.temperature = divelist_column(&dive_list, DIVE_TEMPERATURE, UTF8_DEGREE "F", temperature_data_func, PANGO_ALIGN_RIGHT, visible_cols.temperature);
|
||||||
|
|
36
info.c
36
info.c
|
@ -18,9 +18,9 @@
|
||||||
#include "display-gtk.h"
|
#include "display-gtk.h"
|
||||||
#include "divelist.h"
|
#include "divelist.h"
|
||||||
|
|
||||||
static GtkEntry *location, *buddy, *divemaster;
|
static GtkEntry *location, *buddy, *divemaster, *rating;
|
||||||
static GtkTextView *notes;
|
static GtkTextView *notes;
|
||||||
static GtkListStore *location_list, *people_list;
|
static GtkListStore *location_list, *people_list, *star_list;
|
||||||
|
|
||||||
static char *get_text(GtkTextView *view)
|
static char *get_text(GtkTextView *view)
|
||||||
{
|
{
|
||||||
|
@ -95,6 +95,7 @@ void show_dive_info(struct dive *dive)
|
||||||
SET_TEXT_VALUE(divemaster);
|
SET_TEXT_VALUE(divemaster);
|
||||||
SET_TEXT_VALUE(buddy);
|
SET_TEXT_VALUE(buddy);
|
||||||
SET_TEXT_VALUE(location);
|
SET_TEXT_VALUE(location);
|
||||||
|
gtk_entry_set_text(rating, star_strings[dive->rating]);
|
||||||
gtk_text_buffer_set_text(gtk_text_view_get_buffer(notes),
|
gtk_text_buffer_set_text(gtk_text_view_get_buffer(notes),
|
||||||
dive && dive->notes ? dive->notes : "", -1);
|
dive && dive->notes ? dive->notes : "", -1);
|
||||||
}
|
}
|
||||||
|
@ -255,14 +256,26 @@ void add_location(const char *string)
|
||||||
add_string_list_entry(string, location_list);
|
add_string_list_entry(string, location_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int get_rating(const char *string)
|
||||||
|
{
|
||||||
|
int rating = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i <= 5; i++)
|
||||||
|
if (!strcmp(star_strings[i],string))
|
||||||
|
rating = i;
|
||||||
|
return rating;
|
||||||
|
}
|
||||||
|
|
||||||
struct dive_info {
|
struct dive_info {
|
||||||
GtkComboBoxEntry *location, *divemaster, *buddy;
|
GtkComboBoxEntry *location, *divemaster, *buddy, *rating;
|
||||||
GtkTextView *notes;
|
GtkTextView *notes;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void save_dive_info_changes(struct dive *dive, struct dive_info *info)
|
static void save_dive_info_changes(struct dive *dive, struct dive_info *info)
|
||||||
{
|
{
|
||||||
char *old_text, *new_text;
|
char *old_text, *new_text;
|
||||||
|
char *rating_string;
|
||||||
int changed = 0;
|
int changed = 0;
|
||||||
|
|
||||||
new_text = get_combo_box_entry_text(info->location, &dive->location);
|
new_text = get_combo_box_entry_text(info->location, &dive->location);
|
||||||
|
@ -283,6 +296,14 @@ static void save_dive_info_changes(struct dive *dive, struct dive_info *info)
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rating_string = strdup(star_strings[dive->rating]);
|
||||||
|
new_text = get_combo_box_entry_text(info->rating, &rating_string);
|
||||||
|
if (new_text) {
|
||||||
|
dive->rating = get_rating(rating_string);
|
||||||
|
free(rating_string);
|
||||||
|
changed =1;
|
||||||
|
}
|
||||||
|
|
||||||
old_text = dive->notes;
|
old_text = dive->notes;
|
||||||
dive->notes = get_text(info->notes);
|
dive->notes = get_text(info->notes);
|
||||||
if (text_changed(old_text,dive->notes))
|
if (text_changed(old_text,dive->notes))
|
||||||
|
@ -312,6 +333,7 @@ static void dive_info_widget(GtkWidget *box, struct dive *dive, struct dive_info
|
||||||
|
|
||||||
info->divemaster = text_entry(hbox, "Dive master", people_list, dive->divemaster);
|
info->divemaster = text_entry(hbox, "Dive master", people_list, dive->divemaster);
|
||||||
info->buddy = text_entry(hbox, "Buddy", people_list, dive->buddy);
|
info->buddy = text_entry(hbox, "Buddy", people_list, dive->buddy);
|
||||||
|
info->rating = text_entry(hbox, "Rating", star_list, star_strings[dive->rating]);
|
||||||
|
|
||||||
info->notes = text_view(box, "Notes", READ_WRITE);
|
info->notes = text_view(box, "Notes", READ_WRITE);
|
||||||
if (dive->notes && *dive->notes)
|
if (dive->notes && *dive->notes)
|
||||||
|
@ -359,6 +381,13 @@ GtkWidget *extended_dive_info_widget(void)
|
||||||
|
|
||||||
people_list = gtk_list_store_new(1, G_TYPE_STRING);
|
people_list = gtk_list_store_new(1, G_TYPE_STRING);
|
||||||
location_list = gtk_list_store_new(1, G_TYPE_STRING);
|
location_list = gtk_list_store_new(1, G_TYPE_STRING);
|
||||||
|
star_list = gtk_list_store_new(1, G_TYPE_STRING);
|
||||||
|
add_string_list_entry(ZERO_STARS, star_list);
|
||||||
|
add_string_list_entry(ONE_STARS, star_list);
|
||||||
|
add_string_list_entry(TWO_STARS, star_list);
|
||||||
|
add_string_list_entry(THREE_STARS, star_list);
|
||||||
|
add_string_list_entry(FOUR_STARS, star_list);
|
||||||
|
add_string_list_entry(FIVE_STARS, star_list);
|
||||||
|
|
||||||
gtk_container_set_border_width(GTK_CONTAINER(vbox), 6);
|
gtk_container_set_border_width(GTK_CONTAINER(vbox), 6);
|
||||||
location = text_value(vbox, "Location");
|
location = text_value(vbox, "Location");
|
||||||
|
@ -368,6 +397,7 @@ GtkWidget *extended_dive_info_widget(void)
|
||||||
|
|
||||||
divemaster = text_value(hbox, "Divemaster");
|
divemaster = text_value(hbox, "Divemaster");
|
||||||
buddy = text_value(hbox, "Buddy");
|
buddy = text_value(hbox, "Buddy");
|
||||||
|
rating = text_value(hbox, "Rating");
|
||||||
|
|
||||||
notes = text_view(vbox, "Notes", READ_ONLY);
|
notes = text_view(vbox, "Notes", READ_ONLY);
|
||||||
return vbox;
|
return vbox;
|
||||||
|
|
|
@ -1024,7 +1024,8 @@ static void try_to_fill_dive(struct dive **divep, const char *name, char *buf)
|
||||||
return;
|
return;
|
||||||
if (MATCH(".buddy", utf8_string, &dive->buddy))
|
if (MATCH(".buddy", utf8_string, &dive->buddy))
|
||||||
return;
|
return;
|
||||||
|
if (MATCH(".rating", get_index, &dive->rating))
|
||||||
|
return;
|
||||||
if (MATCH(".cylinder.size", cylindersize, &dive->cylinder[cylinder_index].type.size))
|
if (MATCH(".cylinder.size", cylindersize, &dive->cylinder[cylinder_index].type.size))
|
||||||
return;
|
return;
|
||||||
if (MATCH(".cylinder.workpressure", pressure, &dive->cylinder[cylinder_index].type.workingpressure))
|
if (MATCH(".cylinder.workpressure", pressure, &dive->cylinder[cylinder_index].type.workingpressure))
|
||||||
|
|
|
@ -182,6 +182,7 @@ static void save_overview(FILE *f, struct dive *dive)
|
||||||
show_location(f, dive);
|
show_location(f, dive);
|
||||||
show_utf8(f, dive->divemaster, " <divemaster>","</divemaster>\n");
|
show_utf8(f, dive->divemaster, " <divemaster>","</divemaster>\n");
|
||||||
show_utf8(f, dive->buddy, " <buddy>","</buddy>\n");
|
show_utf8(f, dive->buddy, " <buddy>","</buddy>\n");
|
||||||
|
fprintf(f, " <rating>%d</rating>\n", dive->rating);
|
||||||
show_utf8(f, dive->notes, " <notes>","</notes>\n");
|
show_utf8(f, dive->notes, " <notes>","</notes>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue