aboutsummaryrefslogtreecommitdiffstats
path: root/core/downloadfromdcthread.h
blob: 685c6e5e8e92db8b13a4486abfbf81e0704b4389 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef DOWNLOADFROMDCTHREAD_H
#define DOWNLOADFROMDCTHREAD_H

#include <QThread>
#include <QMap>
#include <QHash>
#include <QLoggingCategory>

#include "libdivecomputer.h"
#include "connectionlistmodel.h"
#if BT_SUPPORT
#include "core/btdiscovery.h"
#endif
/* Helper object for access of Device Data in QML */
class DCDeviceData : public QObject {
	Q_OBJECT
#ifdef SUBSURFACE_MOBILE
	Q_PROPERTY(QString vendor READ vendor WRITE setVendor)
	Q_PROPERTY(QString product READ product WRITE setProduct)
	Q_PROPERTY(bool bluetoothMode READ bluetoothMode WRITE setBluetoothMode)
	Q_PROPERTY(QString devName READ devName WRITE setDevName)
	Q_PROPERTY(QString devBluetoothName READ devBluetoothName WRITE setDevBluetoothName)
	Q_PROPERTY(QString descriptor READ descriptor)
	Q_PROPERTY(bool forceDownload READ forceDownload WRITE setForceDownload)
	Q_PROPERTY(bool createNewTrip READ createNewTrip WRITE setCreateNewTrip)
	Q_PROPERTY(int deviceId READ deviceId WRITE setDeviceId)
	Q_PROPERTY(int diveId READ diveId WRITE setDiveId)
	Q_PROPERTY(bool saveDump READ saveDump WRITE setSaveDump)
	Q_PROPERTY(bool saveLog READ saveLog WRITE setSaveLog)
#endif // SUBSURFACE_MOBILE

public:
	DCDeviceData(QObject *parent = nullptr);
	static DCDeviceData *instance();

	QString vendor() const;
	QString product() const;
	QString devName() const;
	bool bluetoothMode() const;
	bool saveDump() const;
	QString devBluetoothName() const;
#ifdef SUBSURFACE_MOBILE
	QString descriptor() const;
	bool forceDownload() const;
	bool createNewTrip() const;
	bool saveLog() const;
	int deviceId() const;
	int diveId() const;
#endif // SUBSURFACE_MOBILE

	/* this needs to be a pointer to make the C-API happy */
	device_data_t* internalData();

#ifdef SUBSURFACE_MOBILE
	Q_INVOKABLE QStringList getProductListFromVendor(const QString& vendor);
	Q_INVOKABLE int getMatchingAddress(const QString &vendor, const QString &product);

	Q_INVOKABLE int getDetectedVendorIndex();
	Q_INVOKABLE int getDetectedProductIndex(const QString &currentVendorText);
#else
	QStringList getProductListFromVendor(const QString& vendor);
	int getMatchingAddress(const QString &vendor, const QString &product);

	int getDetectedVendorIndex();
	int getDetectedProductIndex(const QString &currentVendorText);
#endif // SUBSURFACE_MOBILE

#ifdef SUBSURFACE_MOBILE
public slots:
	void setDeviceId(int deviceId);
	void setDiveId(int diveId);
#else
public:
#endif // SUBSURFACE_MOBILE
	void setVendor(const QString& vendor);
	void setProduct(const QString& product);
	void setDevName(const QString& devName);
	void setDevBluetoothName(const QString& devBluetoothName);
	void setBluetoothMode(bool mode);
	void setForceDownload(bool force);
	void setCreateNewTrip(bool create);
	void setSaveDump(bool dumpMode);
	void setSaveLog(bool saveLog);
private:
	static DCDeviceData *m_instance;
	device_data_t data;

	// Bluetooth name is managed outside of libdivecomputer
	QString m_devBluetoothName;
};

class DownloadThread : public QThread {
	Q_OBJECT
#ifdef SUBSURFACE_MOBILE
	Q_PROPERTY(DCDeviceData* deviceData MEMBER m_data)
#endif // SUBSURFACE_MOBILE

public:
	DownloadThread();
	void run() override;

#ifdef SUBSURFACE_MOBILE
	Q_INVOKABLE DCDeviceData *data();
#else
	DCDeviceData *data();
#endif // SUBSURFACE_MOBILE
	QString error;

private:
	DCDeviceData *m_data;
};

//TODO: C++ify descriptor?
struct mydescriptor {
	const char *vendor;
	const char *product;
	dc_family_t type;
	unsigned int model;
};

/* This fills the vendor list QStringList and related members.
* this code needs to be reworked to be less ugly, but it will
* stay like this for now.
*/
void fill_computer_list();
void show_computer_list();
extern QStringList vendorList;
extern QHash<QString, QStringList> productList;
extern QMap<QString, dc_descriptor_t *> descriptorLookup;
extern ConnectionListModel connectionListModel;
#endif