diff options
-rw-r--r-- | dive.h | 2 | ||||
-rw-r--r-- | gtk-gui.c | 18 | ||||
-rw-r--r-- | main.c | 14 | ||||
-rw-r--r-- | parse-xml.c | 2 | ||||
-rw-r--r-- | profile.c | 9 | ||||
-rw-r--r-- | save-xml.c | 2 |
6 files changed, 21 insertions, 26 deletions
@@ -266,7 +266,6 @@ struct event { struct divecomputer { timestamp_t when; const char *model; - const char *nickname; uint32_t deviceid, diveid; int samples, alloc_samples; struct sample *sample; @@ -529,6 +528,7 @@ extern void dive_list_update_dives(void); extern void flush_divelist(struct dive *dive); extern void set_dc_nickname(struct dive *dive); +extern const char *get_dc_nickname(uint32_t deviceid); extern void remember_dc(uint32_t deviceid, const char *nickname, gboolean change_conf); #define DIVE_ERROR_PARSE 1 @@ -2023,7 +2023,7 @@ void set_filename(const char *filename, gboolean force) existing_filename = NULL; } -static const char *get_dc_nickname(uint32_t deviceid) +const char *get_dc_nickname(uint32_t deviceid) { struct dcnicknamelist *known = nicknamelist; while (known) { @@ -2083,15 +2083,15 @@ void remember_dc(uint32_t deviceid, const char *nickname, gboolean change_conf) void set_dc_nickname(struct dive *dive) { GtkWidget *dialog, *vbox, *entry, *frame, *label; - char nickname[160]; - const char *name; + char nickname[160] = ""; + const char *name = nickname; if (!dive) return; - if ((name = get_dc_nickname(dive->dc.deviceid)) != NULL) { - dive->dc.nickname = strdup(name); - } else { + /* we should only do this if we already have a different dive computer + * with the same model -- TBI */ + if (get_dc_nickname(dive->dc.deviceid) == NULL) { dialog = gtk_dialog_new_with_buttons( _("Dive Computer Nickname"), GTK_WINDOW(main_window), @@ -2117,10 +2117,10 @@ void set_dc_nickname(struct dive *dive) gtk_widget_show_all(dialog); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { if (strcmp(dive->dc.model, gtk_entry_get_text(GTK_ENTRY(entry)))) - dive->dc.nickname = cleanedup_nickname(gtk_entry_get_text(GTK_ENTRY(entry)), - sizeof(nickname)); + name = cleanedup_nickname(gtk_entry_get_text(GTK_ENTRY(entry)), + sizeof(nickname)); } gtk_widget_destroy(dialog); - remember_dc(dive->dc.deviceid, dive->dc.nickname, TRUE); + remember_dc(dive->dc.deviceid, name, TRUE); } } @@ -124,15 +124,11 @@ void report_dives(gboolean is_imported, gboolean prefer_imported) int preexisting = dive_table.preexisting; struct dive *last; - /* set the nickname for the divecomputer for newly downloaded dives */ - for (i = dive_table.preexisting; i < dive_table.nr; i++) - if (dive_table.dives[i]->downloaded) { - set_dc_nickname(dive_table.dives[i]); - } else { - struct divecomputer *dc = &dive_table.dives[i]->dc; - if (dc->nickname && *dc->nickname) - remember_dc(dc->deviceid, dc->nickname, TRUE); - } + /* check if we need a nickname for the divecomputer for newly downloaded dives; + * since we know they all came from the same divecomputer we just check for the + * first one */ + if (preexisting < dive_table.nr && dive_table.dives[preexisting]->downloaded) + set_dc_nickname(dive_table.dives[preexisting]); /* This does the right thing for -1: NULL */ last = get_dive(preexisting-1); diff --git a/parse-xml.c b/parse-xml.c index 7d9a4694d..57c4dd1cd 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -625,8 +625,6 @@ static void try_to_fill_dc(struct divecomputer *dc, const char *name, char *buf) return; if (MATCH(".model", utf8_string, &dc->model)) return; - if (MATCH(".nickname", utf8_string, &dc->nickname)) - return; if (MATCH(".deviceid", hex_value, &dc->deviceid)) return; if (MATCH(".diveid", hex_value, &dc->diveid)) @@ -1796,6 +1796,7 @@ void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale) struct plot_info *pi; struct divecomputer *dc = &dive->dc; cairo_rectangle_t *drawing_area = &gc->drawing_area; + const char *nickname; plot_set_scale(scale); @@ -1878,10 +1879,12 @@ void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale) cairo_stroke(gc->cr); /* Put the dive computer name in the lower left corner */ - if (dc->nickname || dc->model) { + nickname = get_dc_nickname(dc->deviceid); + if (!nickname || *nickname == '\0') + nickname = dc->model; + if (nickname) { static const text_render_options_t computer = {10, TIME_TEXT, LEFT, MIDDLE}; - plot_text(gc, &computer, 0, 1, "%s", - dc->nickname && *dc->nickname ? dc->nickname : dc->model); + plot_text(gc, &computer, 0, 1, "%s", nickname); } if (PP_GRAPHS_ENABLED) { diff --git a/save-xml.c b/save-xml.c index 0ec6f27d0..fb9eb413a 100644 --- a/save-xml.c +++ b/save-xml.c @@ -400,8 +400,6 @@ static void save_dc(FILE *f, struct dive *dive, struct divecomputer *dc) fprintf(f, " <divecomputer"); if (dc->model) show_utf8(f, dc->model, " model='", "'", 1); - if (dc->nickname && *dc->nickname) - show_utf8(f, dc->nickname, " nickname='", "'", 1); if (dc->deviceid) fprintf(f, " deviceid='%08x'", dc->deviceid); if (dc->diveid) |