mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 18:33:23 +00:00
Different is different from the same (fix silly bug in nickname handling)
Trying to simplify the API for nickname handling I went a bit too far. We indeed need to different API calls, one that returns an entry in the nicknamelist for the deviceid that we have. And one that looks if there is an entry for a different deviceid but the same model that we have. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
06cd494a2f
commit
1bd6f72d31
1 changed files with 15 additions and 3 deletions
18
gtk-gui.c
18
gtk-gui.c
|
@ -2063,7 +2063,7 @@ const char *get_dc_nickname(uint32_t deviceid)
|
|||
}
|
||||
|
||||
/* do we have a DIFFERENT divecomputer of the same model? */
|
||||
static struct dcnicknamelist *get_dc_nicknameentry(const char *model, int deviceid)
|
||||
static struct dcnicknamelist *get_different_dc_nicknameentry(const char *model, int deviceid)
|
||||
{
|
||||
struct dcnicknamelist *known = nicknamelist;
|
||||
while (known) {
|
||||
|
@ -2075,6 +2075,18 @@ static struct dcnicknamelist *get_dc_nicknameentry(const char *model, int device
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* just fine the entry for this divecomputer */
|
||||
static struct dcnicknamelist *get_dc_nicknameentry(int deviceid)
|
||||
{
|
||||
struct dcnicknamelist *known = nicknamelist;
|
||||
while (known) {
|
||||
if (known->deviceid == deviceid)
|
||||
return known;
|
||||
known = known->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* no curly braces or commas, please */
|
||||
static char *cleanedup_nickname(const char *nickname, int len)
|
||||
{
|
||||
|
@ -2168,7 +2180,7 @@ void remember_dc(uint32_t deviceid, const char *model, const char *nickname, gbo
|
|||
subsurface_set_conf("dc_nicknames", PREF_STRING, nicknamestring);
|
||||
} else {
|
||||
/* modify existing entry */
|
||||
struct dcnicknamelist *nn_entry = get_dc_nicknameentry(model, deviceid);
|
||||
struct dcnicknamelist *nn_entry = get_dc_nicknameentry(deviceid);
|
||||
if (!nn_entry->model || !*nn_entry->model)
|
||||
nn_entry->model = model;
|
||||
nn_entry->nickname = nickname;
|
||||
|
@ -2201,7 +2213,7 @@ void set_dc_nickname(struct dive *dive)
|
|||
fprintf(debugfile, "set_dc_nickname for model %s deviceid %8x\n", dc->model ? : "", dc->deviceid);
|
||||
#endif
|
||||
if (get_dc_nickname(dc->deviceid) == NULL) {
|
||||
struct dcnicknamelist *nn_entry = get_dc_nicknameentry(dc->model, dc->deviceid);
|
||||
struct dcnicknamelist *nn_entry = get_different_dc_nicknameentry(dc->model, dc->deviceid);
|
||||
if (!nn_entry) {
|
||||
/* just remember the dive computer without setting a nickname */
|
||||
if (dc->model)
|
||||
|
|
Loading…
Add table
Reference in a new issue