mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Save all dive computer nicknames - whether used or not
We used to save dive computer information only if that dive computer was actually used in any of the dives we saved. But we can simplify the code if we just always save any dive computers we know about. And it does allow for some usage cases where you have nicknames for other peoples computers that you may not actively use, but you want to see if you end up loading multiple XML files in one go. So there's just no compelling reason to not just save all the info we have. And this will make it less painful to remove the "use system config for dive computer nicknames", because you can also use this to continue to gather dive computer info in a separate XML file if you want to. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
9acb52b9ee
commit
52050fdc92
5 changed files with 15 additions and 47 deletions
10
device.c
10
device.c
|
@ -51,16 +51,6 @@ struct device_info *create_device_info(const char *model, uint32_t deviceid)
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_device_saved_status(void)
|
|
||||||
{
|
|
||||||
struct device_info *nn_entry = device_info_list;
|
|
||||||
|
|
||||||
while (nn_entry) {
|
|
||||||
nn_entry->saved = FALSE;
|
|
||||||
nn_entry = nn_entry->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* do we have a DIFFERENT divecomputer of the same model? */
|
/* do we have a DIFFERENT divecomputer of the same model? */
|
||||||
struct device_info *get_different_device_info(const char *model, uint32_t deviceid)
|
struct device_info *get_different_device_info(const char *model, uint32_t deviceid)
|
||||||
{
|
{
|
||||||
|
|
2
device.h
2
device.h
|
@ -9,14 +9,12 @@ struct device_info {
|
||||||
const char *firmware;
|
const char *firmware;
|
||||||
const char *nickname;
|
const char *nickname;
|
||||||
struct device_info *next;
|
struct device_info *next;
|
||||||
gboolean saved;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct device_info *get_device_info(const char *model, uint32_t deviceid);
|
extern struct device_info *get_device_info(const char *model, uint32_t deviceid);
|
||||||
extern struct device_info *get_different_device_info(const char *model, uint32_t deviceid);
|
extern struct device_info *get_different_device_info(const char *model, uint32_t deviceid);
|
||||||
extern struct device_info *create_device_info(const char *model, uint32_t deviceid);
|
extern struct device_info *create_device_info(const char *model, uint32_t deviceid);
|
||||||
extern struct device_info *remove_device_info(const char *model, uint32_t deviceid);
|
extern struct device_info *remove_device_info(const char *model, uint32_t deviceid);
|
||||||
extern void clear_device_saved_status(void);
|
|
||||||
extern struct device_info *head_of_device_info_list(void);
|
extern struct device_info *head_of_device_info_list(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
2
dive.h
2
dive.h
|
@ -538,8 +538,6 @@ extern void flush_divelist(struct dive *dive);
|
||||||
extern void set_dc_nickname(struct dive *dive);
|
extern void set_dc_nickname(struct dive *dive);
|
||||||
extern const char *get_dc_nickname(const char *model, uint32_t deviceid);
|
extern const char *get_dc_nickname(const char *model, uint32_t deviceid);
|
||||||
extern void remember_dc(const char *model, uint32_t deviceid, const char *nickname, gboolean change_conf);
|
extern void remember_dc(const char *model, uint32_t deviceid, const char *nickname, gboolean change_conf);
|
||||||
extern gboolean dc_was_saved(struct divecomputer *dc);
|
|
||||||
extern void mark_dc_saved(struct divecomputer *dc);
|
|
||||||
extern void set_autogroup(gboolean value);
|
extern void set_autogroup(gboolean value);
|
||||||
extern int total_weight(struct dive *);
|
extern int total_weight(struct dive *);
|
||||||
|
|
||||||
|
|
15
gtk-gui.c
15
gtk-gui.c
|
@ -1161,7 +1161,6 @@ static void cell_edited_cb(GtkCellRendererText *cell, gchar *path,
|
||||||
holdnicknames->firmware = NULL;
|
holdnicknames->firmware = NULL;
|
||||||
holdnicknames->nickname = strdup(new_text);
|
holdnicknames->nickname = strdup(new_text);
|
||||||
holdnicknames->next = NULL;
|
holdnicknames->next = NULL;
|
||||||
holdnicknames->saved = FALSE;
|
|
||||||
} else {
|
} else {
|
||||||
struct device_info * top = NULL;
|
struct device_info * top = NULL;
|
||||||
struct device_info * last = holdnicknames;
|
struct device_info * last = holdnicknames;
|
||||||
|
@ -1172,7 +1171,6 @@ static void cell_edited_cb(GtkCellRendererText *cell, gchar *path,
|
||||||
top->firmware = NULL;
|
top->firmware = NULL;
|
||||||
top->nickname = strdup(new_text);
|
top->nickname = strdup(new_text);
|
||||||
top->next = last;
|
top->next = last;
|
||||||
top->saved = FALSE;
|
|
||||||
holdnicknames = top;
|
holdnicknames = top;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1921,19 +1919,6 @@ const char *get_dc_nickname(const char *model, uint32_t deviceid)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean dc_was_saved(struct divecomputer *dc)
|
|
||||||
{
|
|
||||||
struct device_info *nn_entry = get_device_info(dc->model, dc->deviceid);
|
|
||||||
return nn_entry && nn_entry->saved;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mark_dc_saved(struct divecomputer *dc)
|
|
||||||
{
|
|
||||||
struct device_info *nn_entry = get_device_info(dc->model, dc->deviceid);
|
|
||||||
if (nn_entry)
|
|
||||||
nn_entry->saved = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* no curly braces or commas, please */
|
/* no curly braces or commas, please */
|
||||||
static char *cleanedup_nickname(const char *nickname, int len)
|
static char *cleanedup_nickname(const char *nickname, int len)
|
||||||
{
|
{
|
||||||
|
|
33
save-xml.c
33
save-xml.c
|
@ -486,20 +486,14 @@ static void save_trip(FILE *f, dive_trip_t *trip)
|
||||||
fprintf(f, "</trip>\n");
|
fprintf(f, "</trip>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void save_dc_if_needed(FILE *f, struct divecomputer *dc)
|
static void save_one_device(FILE *f, struct device_info *info)
|
||||||
{
|
{
|
||||||
struct device_info *info = get_device_info(dc->model, dc->deviceid);
|
|
||||||
const char *nickname, *serial_nr, *firmware;
|
const char *nickname, *serial_nr, *firmware;
|
||||||
|
|
||||||
/* we have no dc or no model or no deviceid information... nothing to do here */
|
|
||||||
if (!info || info->saved)
|
|
||||||
return;
|
|
||||||
info->saved = 1;
|
|
||||||
|
|
||||||
/* Nicknames that are empty or the same as the device model are not interesting */
|
/* Nicknames that are empty or the same as the device model are not interesting */
|
||||||
nickname = info->nickname;
|
nickname = info->nickname;
|
||||||
if (nickname) {
|
if (nickname) {
|
||||||
if (!*nickname || !strcmp(dc->model, nickname))
|
if (!*nickname || !strcmp(info->model, nickname))
|
||||||
nickname = NULL;
|
nickname = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,7 +511,7 @@ static void save_dc_if_needed(FILE *f, struct divecomputer *dc)
|
||||||
if (!serial_nr && !nickname && !firmware)
|
if (!serial_nr && !nickname && !firmware)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fprintf(f, "<divecomputerid model='%s' deviceid='%08x'", dc->model, dc->deviceid);
|
fprintf(f, "<divecomputerid model='%s' deviceid='%08x'", info->model, info->deviceid);
|
||||||
if (serial_nr)
|
if (serial_nr)
|
||||||
show_utf8(f, serial_nr, " serial='", "'", 1);
|
show_utf8(f, serial_nr, " serial='", "'", 1);
|
||||||
if (firmware)
|
if (firmware)
|
||||||
|
@ -525,7 +519,17 @@ static void save_dc_if_needed(FILE *f, struct divecomputer *dc)
|
||||||
if (nickname)
|
if (nickname)
|
||||||
show_utf8(f, nickname, " nickname='", "'", 1);
|
show_utf8(f, nickname, " nickname='", "'", 1);
|
||||||
fprintf(f, "/>\n");
|
fprintf(f, "/>\n");
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
static void save_device_info(FILE *f)
|
||||||
|
{
|
||||||
|
struct device_info *info;
|
||||||
|
|
||||||
|
info = head_of_device_info_list();
|
||||||
|
while (info) {
|
||||||
|
save_one_device(f, info);
|
||||||
|
info = info->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define VERSION 2
|
#define VERSION 2
|
||||||
|
@ -547,14 +551,7 @@ void save_dives(const char *filename)
|
||||||
fprintf(f, "<divelog program='subsurface' version='%d'>\n<settings>\n", VERSION);
|
fprintf(f, "<divelog program='subsurface' version='%d'>\n<settings>\n", VERSION);
|
||||||
|
|
||||||
/* save the dive computer nicknames, if any */
|
/* save the dive computer nicknames, if any */
|
||||||
clear_device_saved_status();
|
save_device_info(f);
|
||||||
for_each_dive(i, dive) {
|
|
||||||
struct divecomputer *dc = &dive->dc;
|
|
||||||
while (dc) {
|
|
||||||
save_dc_if_needed(f, dc);
|
|
||||||
dc = dc->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (autogroup)
|
if (autogroup)
|
||||||
fprintf(f, "<autogroup state='1' />\n");
|
fprintf(f, "<autogroup state='1' />\n");
|
||||||
fprintf(f, "</settings>\n<dives>\n");
|
fprintf(f, "</settings>\n<dives>\n");
|
||||||
|
|
Loading…
Reference in a new issue