mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
cb410fe1ba
commit
a38ea971a0
18 changed files with 130 additions and 1 deletions
|
|
@ -227,6 +227,7 @@ DCDeviceData::DCDeviceData()
|
|||
#if defined(Q_OS_ANDROID)
|
||||
data.androidUsbDeviceDescriptor = nullptr;
|
||||
#endif
|
||||
data.sync_time = false;
|
||||
}
|
||||
|
||||
DCDeviceData *DCDeviceData::instance()
|
||||
|
|
@ -291,6 +292,11 @@ int DCDeviceData::diveId() const
|
|||
return data.diveid;
|
||||
}
|
||||
|
||||
bool DCDeviceData::syncTime() const
|
||||
{
|
||||
return data.sync_time;
|
||||
}
|
||||
|
||||
void DCDeviceData::setVendor(const QString &vendor)
|
||||
{
|
||||
data.vendor = copy_qstring(vendor);
|
||||
|
|
@ -350,6 +356,11 @@ void DCDeviceData::setDiveId(int diveId)
|
|||
data.diveid = diveId;
|
||||
}
|
||||
|
||||
void DCDeviceData::setSyncTime(bool syncTime)
|
||||
{
|
||||
data.sync_time = syncTime;
|
||||
}
|
||||
|
||||
void DCDeviceData::setSaveDump(bool save)
|
||||
{
|
||||
data.libdc_dump = save;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public:
|
|||
bool forceDownload() const;
|
||||
bool saveLog() const;
|
||||
int diveId() const;
|
||||
bool syncTime() const;
|
||||
|
||||
/* this needs to be a pointer to make the C-API happy */
|
||||
device_data_t *internalData();
|
||||
|
|
@ -54,6 +55,7 @@ public:
|
|||
#if defined(Q_OS_ANDROID)
|
||||
void setUsbDevice(const android_usb_serial_device_descriptor &usbDescriptor);
|
||||
#endif
|
||||
void setSyncTime(bool syncTime);
|
||||
private:
|
||||
#if defined(Q_OS_ANDROID)
|
||||
struct android_usb_serial_device_descriptor androidUsbDescriptor;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ typedef struct {
|
|||
bool libdc_log;
|
||||
bool libdc_dump;
|
||||
bool bluetooth_mode;
|
||||
bool sync_time;
|
||||
FILE *libdc_logfile;
|
||||
struct divelog *log;
|
||||
void *androidUsbDeviceDescriptor;
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ struct preferences default_prefs = {
|
|||
.extract_video_thumbnails = true,
|
||||
.extract_video_thumbnails_position = 20, // The first fifth seems like a reasonable place
|
||||
.three_m_based_grid = false,
|
||||
.sync_dc_time = false,
|
||||
};
|
||||
|
||||
/* copy a preferences block, including making copies of all included strings */
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ struct preferences {
|
|||
dive_computer_prefs_t dive_computer2;
|
||||
dive_computer_prefs_t dive_computer3;
|
||||
dive_computer_prefs_t dive_computer4;
|
||||
bool sync_dc_time;
|
||||
|
||||
// ********** Display *************
|
||||
bool display_invalid_dives;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ void qPrefDiveComputer::loadSync(bool doSync)
|
|||
DISK_DC(2)
|
||||
DISK_DC(3)
|
||||
DISK_DC(4)
|
||||
|
||||
disk_sync_dc_time(doSync);
|
||||
}
|
||||
|
||||
// these are the 'active' settings
|
||||
|
|
@ -54,3 +56,5 @@ HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_vendor1", vendor, div
|
|||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_vendor2", vendor, dive_computer, 2)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_vendor3", vendor, dive_computer, 3)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_vendor4", vendor, dive_computer, 4)
|
||||
|
||||
HANDLE_PREFERENCE_BOOL(DiveComputer, "sync_dive_computer_time", sync_dc_time);
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ class qPrefDiveComputer : public QObject {
|
|||
Q_PROPERTY(QString vendor3 READ vendor3 WRITE set_vendor3 NOTIFY vendor3Changed)
|
||||
Q_PROPERTY(QString vendor4 READ vendor4 WRITE set_vendor4 NOTIFY vendor4Changed)
|
||||
|
||||
Q_PROPERTY(bool sync_dc_time READ sync_dc_time WRITE set_sync_dc_time NOTIFY sync_dc_timeChanged)
|
||||
|
||||
public:
|
||||
static qPrefDiveComputer *instance();
|
||||
|
||||
|
|
@ -49,6 +51,8 @@ public:
|
|||
IMPLEMENT5GETTERS(product)
|
||||
IMPLEMENT5GETTERS(vendor)
|
||||
|
||||
static bool sync_dc_time() { return prefs.sync_dc_time; }
|
||||
|
||||
public slots:
|
||||
static void set_device(const QString &device);
|
||||
static void set_device1(const QString &device);
|
||||
|
|
@ -74,6 +78,8 @@ public slots:
|
|||
static void set_vendor3(const QString &vendor);
|
||||
static void set_vendor4(const QString &vendor);
|
||||
|
||||
static void set_sync_dc_time(bool value);
|
||||
|
||||
signals:
|
||||
void deviceChanged(const QString &device);
|
||||
void device1Changed(const QString &device);
|
||||
|
|
@ -99,6 +105,8 @@ signals:
|
|||
void vendor3Changed(const QString &vendor);
|
||||
void vendor4Changed(const QString &vendor);
|
||||
|
||||
void sync_dc_timeChanged(bool value);
|
||||
|
||||
private:
|
||||
qPrefDiveComputer() {}
|
||||
|
||||
|
|
@ -127,6 +135,8 @@ private:
|
|||
static void disk_vendor2(bool doSync);
|
||||
static void disk_vendor3(bool doSync);
|
||||
static void disk_vendor4(bool doSync);
|
||||
|
||||
static void disk_sync_dc_time(bool doSync);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1518,6 +1518,9 @@ const char *do_uemis_import(device_data_t *data)
|
|||
if (uemis_mem_status != UEMIS_MEM_OK)
|
||||
result = translate("gettextFromC", ERR_FS_ALMOST_FULL);
|
||||
|
||||
if (data->sync_time)
|
||||
uemis_info(translate("gettextFromC", "Time sync not supported by dive computer"));
|
||||
|
||||
bail:
|
||||
(void)uemis_get_answer(mountpath, "terminateSync", 0, 3, &result);
|
||||
if (!strcmp(param_buff[0], "error")) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue