aboutsummaryrefslogtreecommitdiffstats
path: root/cli-downloader.cpp
blob: 3eef0b2d5385b26759d1ed95883d92064b505228 (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
// SPDX-License-Identifier: GPL-2.0
#include "qt-models/diveimportedmodel.h"

void cliDownloader(const char *vendor, const char *product, const char *device)
{
	DiveImportedModel diveImportedModel;
	DiveImportedModel::connect(&diveImportedModel, &DiveImportedModel::downloadFinished, [] {
		// do something useful at the end of the download
		printf("Finished\n");
	});

	auto data = diveImportedModel.thread.data();
	data->setVendor(vendor);
	data->setProduct(product);
	data->setBluetoothMode(false);
	if (data->vendor() == "Uemis") {
		QString devname(device);
		int colon = devname.indexOf(QStringLiteral(":\\ (UEMISSDA)"));
		if (colon >= 0) {
			devname.truncate(colon + 2);
			fprintf(stderr, "shortened devname to \"%s\"", qPrintable(devname));
		}
		data->setDevName(devname);
	} else {
		data->setDevName(device);
	}

	// some assumptions - should all be configurable
	data->setForceDownload(false);
	data->setSaveLog(true);
	data->setSaveDump(false);

	diveImportedModel.startDownload();
	diveImportedModel.waitForDownload();
	diveImportedModel.recordDives();
}