Import: Add option to sync time on dive computer download

Add an option for users to sync the dive computer time with the PC time
every time dives are downloaded.
Obviously this will only work on dive computers that have time
synchronisation support in libdivecomputer, for other computers a notice
is logged.
The selection for this option is persisted as a preference.

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2023-04-02 18:28:33 +12:00 committed by Dirk Hohndel
parent cb410fe1ba
commit a38ea971a0
18 changed files with 130 additions and 1 deletions

View file

@ -1413,6 +1413,14 @@ dc_status_t divecomputer_device_open(device_data_t *data)
return DC_STATUS_UNSUPPORTED;
}
static dc_status_t sync_divecomputer_time(dc_device_t *device)
{
dc_datetime_t now;
dc_datetime_localtime(&now, dc_datetime_now());
return dc_device_timesync(device, &now);
}
const char *do_libdivecomputer_import(device_data_t *data)
{
dc_status_t rc;
@ -1463,6 +1471,28 @@ const char *do_libdivecomputer_import(device_data_t *data)
dev_info(data, "Starting import ...");
err = do_device_import(data);
/* TODO: Show the logfile to the user on error. */
dev_info(data, "Import complete");
if (!err && data->sync_time) {
dev_info(data, "Syncing dive computer time ...");
rc = sync_divecomputer_time(data->device);
switch (rc) {
case DC_STATUS_SUCCESS:
dev_info(data, "Time sync complete");
break;
case DC_STATUS_UNSUPPORTED:
dev_info(data, "Time sync not supported by dive computer");
break;
default:
dev_info(data, "Time sync failed");
break;
}
}
dc_device_close(data->device);
data->device = NULL;
if (!data->log->dives->nr)