mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Move gas string computation into core logic code
This is now a helper called from the Gtk UI code (and will soon be used by the Qt UI code). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
e6ec626c97
commit
63c5080561
3 changed files with 37 additions and 24 deletions
|
@ -431,40 +431,24 @@ static gint nitrox_sort_func(GtkTreeModel *model,
|
|||
return a_he - b_he;
|
||||
}
|
||||
|
||||
#define UTF8_ELLIPSIS "\xE2\x80\xA6"
|
||||
|
||||
static void nitrox_data_func(GtkTreeViewColumn *col,
|
||||
GtkCellRenderer *renderer,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
int idx, o2, he, o2low;
|
||||
char buffer[80];
|
||||
int idx;
|
||||
char *buffer;
|
||||
struct dive *dive;
|
||||
|
||||
gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, -1);
|
||||
if (idx < 0) {
|
||||
*buffer = '\0';
|
||||
goto exit;
|
||||
if (idx >= 0 && (dive = get_dive(idx))) {
|
||||
buffer = get_nitrox_string(dive);
|
||||
g_object_set(renderer, "text", buffer, NULL);
|
||||
free(buffer);
|
||||
} else {
|
||||
g_object_set(renderer, "text", "", NULL);
|
||||
}
|
||||
dive = get_dive(idx);
|
||||
get_dive_gas(dive, &o2, &he, &o2low);
|
||||
o2 = (o2 + 5) / 10;
|
||||
he = (he + 5) / 10;
|
||||
o2low = (o2low + 5) / 10;
|
||||
|
||||
if (he)
|
||||
snprintf(buffer, sizeof(buffer), "%d/%d", o2, he);
|
||||
else if (o2)
|
||||
if (o2 == o2low)
|
||||
snprintf(buffer, sizeof(buffer), "%d", o2);
|
||||
else
|
||||
snprintf(buffer, sizeof(buffer), "%d" UTF8_ELLIPSIS "%d", o2low, o2);
|
||||
else
|
||||
strcpy(buffer, _("air"));
|
||||
exit:
|
||||
g_object_set(renderer, "text", buffer, NULL);
|
||||
}
|
||||
|
||||
/* Render the SAC data (integer value of "ml / min") */
|
||||
|
|
28
divelist.c
28
divelist.c
|
@ -595,6 +595,34 @@ char *get_trip_date_string(timestamp_t when, int nr) {
|
|||
return buffer;
|
||||
}
|
||||
|
||||
#define MAX_NITROX_STRING 80
|
||||
#define UTF8_ELLIPSIS "\xE2\x80\xA6"
|
||||
|
||||
/* callers needs to free the string */
|
||||
char *get_nitrox_string(struct dive *dive)
|
||||
{
|
||||
int o2, he, o2low;
|
||||
char *buffer = malloc(MAX_NITROX_STRING);
|
||||
|
||||
if (buffer) {
|
||||
get_dive_gas(dive, &o2, &he, &o2low);
|
||||
o2 = (o2 + 5) / 10;
|
||||
he = (he + 5) / 10;
|
||||
o2low = (o2low + 5) / 10;
|
||||
|
||||
if (he)
|
||||
snprintf(buffer, sizeof(buffer), "%d/%d", o2, he);
|
||||
else if (o2)
|
||||
if (o2 == o2low)
|
||||
snprintf(buffer, sizeof(buffer), "%d", o2);
|
||||
else
|
||||
snprintf(buffer, sizeof(buffer), "%d" UTF8_ELLIPSIS "%d", o2low, o2);
|
||||
else
|
||||
strcpy(buffer, _("air"));
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/*
|
||||
* helper functions for dive_trip handling
|
||||
*/
|
||||
|
|
|
@ -32,6 +32,7 @@ extern void export_all_dives_uddf_cb();
|
|||
extern void process_dives(bool imported, bool prefer_imported);
|
||||
extern char *get_dive_date_string(timestamp_t when);
|
||||
extern char *get_trip_date_string(timestamp_t when, int nr);
|
||||
extern char *get_nitrox_string(struct dive *dive);
|
||||
extern void clear_trip_indexes(void);
|
||||
extern dive_trip_t *find_trip_by_idx(int idx);
|
||||
extern int dive_nr_sort(int idx_a, int idx_b, timestamp_t when_a, timestamp_t when_b);
|
||||
|
|
Loading…
Reference in a new issue