mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 19:33:23 +00:00
Track Uemis last dive downloaded on a per data-file basis
Actually, it's even better than that. Thanks to the new divecomputer datastructure we can now simply look up in the dive_table which dives have been downloaded from this specific Uemis SDA. This patch removes the old gconf based code - which leads to one unfortunate problem: the first time a Uemis SDA owner runs this version of Subsurface against their data file ALL dives will be downloaded again (which may not be a bad thing as we have improved a few other details of Uemis support so now they get their deco information, surface pressure and other data that we have started to support since 2.1). Still, this is not ideal. But I didn't want to keep the legacy code around since this new solution is so much cleaner. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
10fac7a6af
commit
a79b74ed36
4 changed files with 19 additions and 96 deletions
|
@ -113,7 +113,7 @@ typedef gint (*sort_func_t)(GtkTreeModel *model,
|
||||||
extern GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title,
|
extern GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title,
|
||||||
data_func_t data_func, unsigned int flags);
|
data_func_t data_func, unsigned int flags);
|
||||||
|
|
||||||
GError *uemis_download(const char *path, char **divenr, char **xml_buffer,
|
GError *uemis_download(const char *path, char **xml_buffer,
|
||||||
progressbar_t *progress, GtkDialog *dialog, gboolean force_download);
|
progressbar_t *progress, GtkDialog *dialog, gboolean force_download);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
19
gtk-gui.c
19
gtk-gui.c
|
@ -42,7 +42,6 @@ partial_pressure_graphs_t partial_pressure_graphs = { FALSE, FALSE, FALSE, 1.6,
|
||||||
static const char *default_dive_computer_vendor;
|
static const char *default_dive_computer_vendor;
|
||||||
static const char *default_dive_computer_product;
|
static const char *default_dive_computer_product;
|
||||||
static const char *default_dive_computer_device;
|
static const char *default_dive_computer_device;
|
||||||
static char *uemis_max_dive_data;
|
|
||||||
static gboolean force_download;
|
static gboolean force_download;
|
||||||
static gboolean prefer_downloaded;
|
static gboolean prefer_downloaded;
|
||||||
|
|
||||||
|
@ -87,12 +86,6 @@ static void set_default_dive_computer_device(const char *name)
|
||||||
subsurface_set_conf("dive_computer_device", PREF_STRING, name);
|
subsurface_set_conf("dive_computer_device", PREF_STRING, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_uemis_last_dive(char *data)
|
|
||||||
{
|
|
||||||
uemis_max_dive_data = data;
|
|
||||||
subsurface_set_conf("uemis_max_dive_data", PREF_STRING, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void repaint_dive(void)
|
void repaint_dive(void)
|
||||||
{
|
{
|
||||||
update_dive(current_dive);
|
update_dive(current_dive);
|
||||||
|
@ -1157,12 +1150,6 @@ void init_ui(int *argcp, char ***argvp)
|
||||||
default_dive_computer_vendor = subsurface_get_conf("dive_computer_vendor", PREF_STRING);
|
default_dive_computer_vendor = subsurface_get_conf("dive_computer_vendor", PREF_STRING);
|
||||||
default_dive_computer_product = subsurface_get_conf("dive_computer_product", PREF_STRING);
|
default_dive_computer_product = subsurface_get_conf("dive_computer_product", PREF_STRING);
|
||||||
default_dive_computer_device = subsurface_get_conf("dive_computer_device", PREF_STRING);
|
default_dive_computer_device = subsurface_get_conf("dive_computer_device", PREF_STRING);
|
||||||
conf_value = subsurface_get_conf("uemis_max_dive_data", PREF_STRING);
|
|
||||||
if (!conf_value)
|
|
||||||
uemis_max_dive_data = strdup("");
|
|
||||||
else
|
|
||||||
uemis_max_dive_data = strdup(conf_value);
|
|
||||||
free((char *)conf_value);
|
|
||||||
error_info_bar = NULL;
|
error_info_bar = NULL;
|
||||||
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
g_set_application_name ("subsurface");
|
g_set_application_name ("subsurface");
|
||||||
|
@ -1662,16 +1649,12 @@ static GError *setup_uemis_import(device_data_t *data)
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
|
|
||||||
error = uemis_download(data->devname, &uemis_max_dive_data, &buf, &data->progress, data->dialog, data->force_download);
|
error = uemis_download(data->devname, &buf, &data->progress, data->dialog, data->force_download);
|
||||||
if (buf && strlen(buf) > 1) {
|
if (buf && strlen(buf) > 1) {
|
||||||
#if UEMIS_DEBUG > 3
|
#if UEMIS_DEBUG > 3
|
||||||
fprintf(debugfile, "xml buffer \"%s\"\n\n", buf);
|
fprintf(debugfile, "xml buffer \"%s\"\n\n", buf);
|
||||||
#endif
|
#endif
|
||||||
parse_xml_buffer("Uemis Download", buf, strlen(buf), TRUE, &error);
|
parse_xml_buffer("Uemis Download", buf, strlen(buf), TRUE, &error);
|
||||||
set_uemis_last_dive(uemis_max_dive_data);
|
|
||||||
#if UEMIS_DEBUG > 2
|
|
||||||
fprintf(debugfile, "uemis_max_dive_data: %s\n", uemis_max_dive_data);
|
|
||||||
#endif
|
|
||||||
mark_divelist_changed(TRUE);
|
mark_divelist_changed(TRUE);
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
|
|
|
@ -44,7 +44,6 @@ static int mbuf_size = 0;
|
||||||
|
|
||||||
struct argument_block {
|
struct argument_block {
|
||||||
const char *mountpath;
|
const char *mountpath;
|
||||||
char **max_dive_data;
|
|
||||||
char **xml_buffer;
|
char **xml_buffer;
|
||||||
progressbar_t *progress;
|
progressbar_t *progress;
|
||||||
gboolean force_download;
|
gboolean force_download;
|
||||||
|
@ -720,78 +719,26 @@ static char *process_raw_buffer(char *inbuf, char **max_divenr)
|
||||||
return strdup(conv_buffer);
|
return strdup(conv_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* to keep track of multiple computers we simply encode the last dive read
|
static char *get_divenr(char *deviceidstr)
|
||||||
in tuples "{deviceid,nr},{deviceid,nr}..." no spaces to make parsing easier */
|
|
||||||
|
|
||||||
static char *find_deviceid(char *max_dive_data, char *deviceid)
|
|
||||||
{
|
{
|
||||||
char *pattern;
|
int deviceid, i, maxdiveid = 0;
|
||||||
char *result;
|
char divenr[10];
|
||||||
if (! deviceid || *deviceid == '\0')
|
|
||||||
return NULL;
|
|
||||||
pattern = malloc(3 + strlen(deviceid));
|
|
||||||
sprintf(pattern, "{%s,", deviceid);
|
|
||||||
result = strstr(max_dive_data, pattern);
|
|
||||||
free(pattern);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *get_divenr(char *max_dive_data, char *deviceid)
|
if (sscanf(deviceidstr, "%d", &deviceid) != 1)
|
||||||
{
|
return "0";
|
||||||
char *q, *p = max_dive_data;
|
for (i = 0; i < dive_table.nr; i++) {
|
||||||
char *result = NULL;
|
struct divecomputer *dc = &dive_table.dives[i]->dc;
|
||||||
|
if (dc->deviceid == deviceid && dc->diveid > maxdiveid)
|
||||||
if (!p || !deviceid)
|
maxdiveid = dc->diveid;
|
||||||
return strdup("0");
|
|
||||||
p = find_deviceid(max_dive_data, deviceid);
|
|
||||||
if (p) {
|
|
||||||
p += strlen(deviceid) + 2;
|
|
||||||
q = strchr(p, '}');
|
|
||||||
if (!q)
|
|
||||||
return result;
|
|
||||||
result = malloc(q - p + 1);
|
|
||||||
strncpy(result, p, q - p);
|
|
||||||
result[q - p] = '\0';
|
|
||||||
}
|
}
|
||||||
if (!result)
|
snprintf(divenr, 10, "%d", maxdiveid);
|
||||||
result = strdup("0");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *update_max_dive_data(char *max_dive_data, char *deviceid, char *newmax)
|
return strdup(divenr);
|
||||||
{
|
|
||||||
char *p;
|
|
||||||
char *result;
|
|
||||||
int len;
|
|
||||||
|
|
||||||
if (! newmax || *newmax == '\0')
|
|
||||||
return max_dive_data;
|
|
||||||
p = find_deviceid(max_dive_data, deviceid);
|
|
||||||
if (p) {
|
|
||||||
/* if there are more entries after this one, copy them,
|
|
||||||
otherwise just remove the existing entry for this device */
|
|
||||||
char *q = strstr(p, "},{");
|
|
||||||
if (q) {
|
|
||||||
memcpy(p + 1, q + 3, strlen(q + 3) + 1);
|
|
||||||
} else {
|
|
||||||
if (p > max_dive_data)
|
|
||||||
*(p-1) = '\0';
|
|
||||||
else
|
|
||||||
*p = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* now add the new one at the end */
|
|
||||||
len = strlen(max_dive_data) + strlen(deviceid) + strlen(newmax) + 4 + (strlen(max_dive_data) ? 1 : 0);
|
|
||||||
result = malloc(len);
|
|
||||||
snprintf(result, len, "%s%s{%s,%s}", max_dive_data, strlen(max_dive_data) ? "," : "", deviceid, newmax);
|
|
||||||
free(max_dive_data);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *do_uemis_download(struct argument_block *args)
|
static char *do_uemis_download(struct argument_block *args)
|
||||||
{
|
{
|
||||||
const char *mountpath = args->mountpath;
|
const char *mountpath = args->mountpath;
|
||||||
char **max_dive_data = args->max_dive_data;
|
|
||||||
char **xml_buffer = args->xml_buffer;
|
char **xml_buffer = args->xml_buffer;
|
||||||
int xml_buffer_size;
|
int xml_buffer_size;
|
||||||
char *newmax = NULL;
|
char *newmax = NULL;
|
||||||
|
@ -827,7 +774,7 @@ static char *do_uemis_download(struct argument_block *args)
|
||||||
* the Uemis; otherwise check which was the last dive
|
* the Uemis; otherwise check which was the last dive
|
||||||
* downloaded */
|
* downloaded */
|
||||||
if (!args->force_download && dive_table.nr > 0)
|
if (!args->force_download && dive_table.nr > 0)
|
||||||
newmax = get_divenr(*max_dive_data, deviceid);
|
newmax = get_divenr(deviceid);
|
||||||
else
|
else
|
||||||
newmax = strdup("0");
|
newmax = strdup("0");
|
||||||
|
|
||||||
|
@ -862,7 +809,6 @@ static char *do_uemis_download(struct argument_block *args)
|
||||||
if (endptr)
|
if (endptr)
|
||||||
*(endptr + 2) = '\0';
|
*(endptr + 2) = '\0';
|
||||||
}
|
}
|
||||||
*args->max_dive_data = update_max_dive_data(*max_dive_data, deviceid, newmax);
|
|
||||||
if (sscanf(newmax, "%d", &end) != 1)
|
if (sscanf(newmax, "%d", &end) != 1)
|
||||||
end = start;
|
end = start;
|
||||||
#if UEMIS_DEBUG > 1
|
#if UEMIS_DEBUG > 1
|
||||||
|
@ -920,12 +866,12 @@ static gboolean timeout_func(gpointer _data)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GError *uemis_download(const char *mountpath, char **max_dive_data, char **xml_buffer, progressbar_t *progress,
|
GError *uemis_download(const char *mountpath, char **xml_buffer, progressbar_t *progress,
|
||||||
GtkDialog *dialog, gboolean force_download)
|
GtkDialog *dialog, gboolean force_download)
|
||||||
{
|
{
|
||||||
pthread_t pthread;
|
pthread_t pthread;
|
||||||
void *retval;
|
void *retval;
|
||||||
struct argument_block args = {mountpath, max_dive_data, xml_buffer, progress, force_download};
|
struct argument_block args = {mountpath, xml_buffer, progress, force_download};
|
||||||
|
|
||||||
/* I'm sure there is some better interface for waiting on a thread in a UI main loop */
|
/* I'm sure there is some better interface for waiting on a thread in a UI main loop */
|
||||||
import_thread_done = 0;
|
import_thread_done = 0;
|
||||||
|
|
12
uemis.c
12
uemis.c
|
@ -199,16 +199,10 @@ void uemis_parse_divelog_binary(char *base64, void *datap) {
|
||||||
else
|
else
|
||||||
dive->salinity = 10000; /* grams per 10l fresh water */
|
dive->salinity = 10000; /* grams per 10l fresh water */
|
||||||
|
|
||||||
|
/* this will allow us to find the last dive read so far from this computer */
|
||||||
dc->model = strdup("Uemis Zurich");
|
dc->model = strdup("Uemis Zurich");
|
||||||
|
dc->deviceid = *(uint32_t *)(data + 9);
|
||||||
/*
|
dc->diveid = *(uint16_t *)(data + 7);
|
||||||
* FIXME:
|
|
||||||
* - make the deive ID the first word of the SHA1 sum of the deviceid string
|
|
||||||
* - do we want to have a dive ID? Without one, we'll just use the dive date,
|
|
||||||
* which is likely fine.
|
|
||||||
*/
|
|
||||||
dc->deviceid = 0;
|
|
||||||
dc->diveid = 0;
|
|
||||||
|
|
||||||
/* dive template in use:
|
/* dive template in use:
|
||||||
0 = air
|
0 = air
|
||||||
|
|
Loading…
Add table
Reference in a new issue