mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 18:23:23 +00:00
Remove nickname from divecomputer data structure
Having it there with the model information seemed to make sense but on second thought it's the wrong spot to keep that information, especially since we were storing it in the XML file in every single dive. This change removes the nickname member from the divecomputer and makes the rest of the code reasonably self consistent. It does not add much of the new code for the new design to handle nicknames. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
eb3e879030
commit
8d2abc05f6
6 changed files with 21 additions and 26 deletions
2
dive.h
2
dive.h
|
@ -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
|
||||
|
|
18
gtk-gui.c
18
gtk-gui.c
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
14
main.c
14
main.c
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue