mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-01 06:30:26 +00:00
Merge branch 'macBLE' of github.com:Subsurface-divelog/subsurface
This commit is contained in:
commit
ae209a3d9f
9 changed files with 112 additions and 23 deletions
|
@ -220,9 +220,8 @@ if (BTSUPPORT AND "${Qt5Core_VERSION}" VERSION_LESS 5.4.0)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Windows Qt doesn't support BLE at all
|
# Windows Qt doesn't support BLE at all
|
||||||
# Mac hasn't been tested, yet - so far it's disabled
|
|
||||||
# the rest of them need at least 5.6 to be reasonable but really, you want 5.9.1
|
# the rest of them need at least 5.6 to be reasonable but really, you want 5.9.1
|
||||||
if (BTSUPPORT AND (ANDROID OR CMAKE_SYSTEM_NAME STREQUAL "Linux"))
|
if (BTSUPPORT AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||||
if ("${Qt5Core_VERSION}" VERSION_LESS 5.6.0)
|
if ("${Qt5Core_VERSION}" VERSION_LESS 5.6.0)
|
||||||
message(STATUS "Turning off BLE support as Qt version ${Qt5Core_VERSION} is insufficient for that")
|
message(STATUS "Turning off BLE support as Qt version ${Qt5Core_VERSION} is insufficient for that")
|
||||||
else()
|
else()
|
||||||
|
|
|
@ -174,11 +174,10 @@ QString markBLEAddress(const QBluetoothDeviceInfo *device)
|
||||||
flags = device->coreConfigurations();
|
flags = device->coreConfigurations();
|
||||||
if (flags == QBluetoothDeviceInfo::LowEnergyCoreConfiguration)
|
if (flags == QBluetoothDeviceInfo::LowEnergyCoreConfiguration)
|
||||||
prefix = "LE:";
|
prefix = "LE:";
|
||||||
#if defined(Q_OS_IOS)
|
if (device->address().isNull())
|
||||||
return prefix + device->deviceUuid().toString();
|
return prefix + device->deviceUuid().toString();
|
||||||
#else
|
else
|
||||||
return prefix + device->address().toString();
|
return prefix + device->address().toString();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device)
|
void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device)
|
||||||
|
@ -308,4 +307,18 @@ bool BTDiscovery::checkException(const char* method, const QAndroidJniObject *ob
|
||||||
}
|
}
|
||||||
#endif // Q_OS_ANDROID
|
#endif // Q_OS_ANDROID
|
||||||
|
|
||||||
|
QHash<QString, QBluetoothDeviceInfo> btDeviceInfo;
|
||||||
|
|
||||||
|
void saveBtDeviceInfo(const char* devaddr, QBluetoothDeviceInfo deviceInfo)
|
||||||
|
{
|
||||||
|
btDeviceInfo[devaddr] = deviceInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
QBluetoothDeviceInfo getBtDeviceInfo(const char* devaddr)
|
||||||
|
{
|
||||||
|
if (btDeviceInfo.contains(devaddr))
|
||||||
|
return btDeviceInfo[devaddr];
|
||||||
|
qDebug() << "need to scan for" << devaddr;
|
||||||
|
return QBluetoothDeviceInfo();
|
||||||
|
}
|
||||||
#endif // BT_SUPPORT
|
#endif // BT_SUPPORT
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
#include <QAndroidJniEnvironment>
|
#include <QAndroidJniEnvironment>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void saveBtDeviceInfo(const char* devaddr, QBluetoothDeviceInfo deviceInfo);
|
||||||
|
QBluetoothDeviceInfo getBtDeviceInfo(const char* devaddr);
|
||||||
|
|
||||||
class ConnectionListModel : public QAbstractListModel {
|
class ConnectionListModel : public QAbstractListModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -1121,6 +1121,7 @@ const char *do_libdivecomputer_import(device_data_t *data)
|
||||||
/* TODO: Show the logfile to the user on error. */
|
/* TODO: Show the logfile to the user on error. */
|
||||||
dc_device_close(data->device);
|
dc_device_close(data->device);
|
||||||
data->device = NULL;
|
data->device = NULL;
|
||||||
|
dev_info(data, translate("gettextFromC", "No new dives downloaded from dive computer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_context_free(data->context);
|
dc_context_free(data->context);
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include "libdivecomputer.h"
|
#include "libdivecomputer.h"
|
||||||
#include "core/qt-ble.h"
|
#include "core/qt-ble.h"
|
||||||
|
#include "core/btdiscovery.h"
|
||||||
|
|
||||||
#if defined(SSRF_CUSTOM_IO)
|
#if defined(SSRF_CUSTOM_IO)
|
||||||
|
|
||||||
|
@ -287,12 +288,11 @@ dc_status_t qt_ble_open(dc_custom_io_t *io, dc_context_t *context, const char *d
|
||||||
if (!strncmp(devaddr, "LE:", 3))
|
if (!strncmp(devaddr, "LE:", 3))
|
||||||
devaddr += 3;
|
devaddr += 3;
|
||||||
|
|
||||||
QBluetoothAddress remoteDeviceAddress(devaddr);
|
|
||||||
|
|
||||||
// HACK ALERT! Qt 5.9 needs this for proper Bluez operation
|
// HACK ALERT! Qt 5.9 needs this for proper Bluez operation
|
||||||
qputenv("QT_DEFAULT_CENTRAL_SERVICES", "1");
|
qputenv("QT_DEFAULT_CENTRAL_SERVICES", "1");
|
||||||
|
|
||||||
QLowEnergyController *controller = new QLowEnergyController(remoteDeviceAddress);
|
QBluetoothDeviceInfo remoteDevice = getBtDeviceInfo(devaddr);
|
||||||
|
QLowEnergyController *controller = QLowEnergyController::createCentral(remoteDevice);
|
||||||
|
|
||||||
qDebug() << "qt_ble_open(" << devaddr << ")";
|
qDebug() << "qt_ble_open(" << devaddr << ")";
|
||||||
|
|
||||||
|
@ -382,8 +382,19 @@ dc_status_t qt_ble_open(dc_custom_io_t *io, dc_context_t *context, const char *d
|
||||||
qDebug() << "Descriptor:" << d.name() << "uuid:" << d.uuid().toString();
|
qDebug() << "Descriptor:" << d.name() << "uuid:" << d.uuid().toString();
|
||||||
|
|
||||||
if (!l.isEmpty()) {
|
if (!l.isEmpty()) {
|
||||||
|
bool foundCCC = false;
|
||||||
|
foreach (d, l) {
|
||||||
|
if (d.type() == QBluetoothUuid::ClientCharacteristicConfiguration) {
|
||||||
|
// pick the correct characteristic
|
||||||
|
foundCCC = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!foundCCC)
|
||||||
|
// if we didn't find a ClientCharacteristicConfiguration, try the first one
|
||||||
d = l.first();
|
d = l.first();
|
||||||
qDebug() << "now writing \"0x0100\" to the first descriptor";
|
|
||||||
|
qDebug() << "now writing \"0x0100\" to the descriptor" << d.uuid().toString();
|
||||||
|
|
||||||
ble->preferredService()->writeDescriptor(d, QByteArray::fromHex("0100"));
|
ble->preferredService()->writeDescriptor(d, QByteArray::fromHex("0100"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include "core/btdiscovery.h"
|
||||||
|
|
||||||
|
#include <QBluetoothUuid>
|
||||||
|
|
||||||
#include "ui_btdeviceselectiondialog.h"
|
#include "ui_btdeviceselectiondialog.h"
|
||||||
#include "btdeviceselectiondialog.h"
|
#include "btdeviceselectiondialog.h"
|
||||||
|
@ -149,7 +152,9 @@ void BtDeviceSelectionDialog::on_save_clicked()
|
||||||
|
|
||||||
// Save the selected device
|
// Save the selected device
|
||||||
selectedRemoteDeviceInfo = QSharedPointer<QBluetoothDeviceInfo>(new QBluetoothDeviceInfo(remoteDeviceInfo));
|
selectedRemoteDeviceInfo = QSharedPointer<QBluetoothDeviceInfo>(new QBluetoothDeviceInfo(remoteDeviceInfo));
|
||||||
|
QString address = remoteDeviceInfo.address().isNull() ? remoteDeviceInfo.deviceUuid().toString() :
|
||||||
|
remoteDeviceInfo.address().toString();
|
||||||
|
saveBtDeviceInfo(address.toUtf8().constData(), remoteDeviceInfo);
|
||||||
if (remoteDeviceDiscoveryAgent->isActive()) {
|
if (remoteDeviceDiscoveryAgent->isActive()) {
|
||||||
// Stop the SDP agent if the clear button is pressed and enable the Scan button
|
// Stop the SDP agent if the clear button is pressed and enable the Scan button
|
||||||
remoteDeviceDiscoveryAgent->stop();
|
remoteDeviceDiscoveryAgent->stop();
|
||||||
|
@ -236,8 +241,16 @@ void BtDeviceSelectionDialog::addRemoteDevice(const QBluetoothDeviceInfo &remote
|
||||||
if (remoteDeviceInfo.address().isNull())
|
if (remoteDeviceInfo.address().isNull())
|
||||||
pairingColor = QColor(Qt::gray);
|
pairingColor = QColor(Qt::gray);
|
||||||
|
|
||||||
|
QString deviceLabel;
|
||||||
|
|
||||||
QString deviceLabel = tr("%1 (%2) [State: %3]").arg(remoteDeviceInfo.name(),
|
#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
|
||||||
|
if (!remoteDeviceInfo.deviceUuid().isNull()) {
|
||||||
|
// we have only a Uuid, no address, so show that and reset the pairing color
|
||||||
|
deviceLabel = QString("%1 (%2)").arg(remoteDeviceInfo.name(),remoteDeviceInfo.deviceUuid().toString());
|
||||||
|
pairingColor = QColor(Qt::white);
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
deviceLabel = tr("%1 (%2) [State: %3]").arg(remoteDeviceInfo.name(),
|
||||||
remoteDeviceInfo.address().toString(),
|
remoteDeviceInfo.address().toString(),
|
||||||
pairingStatusLabel);
|
pairingStatusLabel);
|
||||||
#endif
|
#endif
|
||||||
|
@ -255,11 +268,15 @@ void BtDeviceSelectionDialog::itemClicked(QListWidgetItem *item)
|
||||||
// By default we assume that the devices are paired
|
// By default we assume that the devices are paired
|
||||||
QBluetoothDeviceInfo remoteDeviceInfo = item->data(Qt::UserRole).value<QBluetoothDeviceInfo>();
|
QBluetoothDeviceInfo remoteDeviceInfo = item->data(Qt::UserRole).value<QBluetoothDeviceInfo>();
|
||||||
QString statusMessage = tr("The device %1 can be used for connection. You can press the Save button.")
|
QString statusMessage = tr("The device %1 can be used for connection. You can press the Save button.")
|
||||||
.arg(remoteDeviceInfo.address().toString());
|
.arg(remoteDeviceInfo.address().isNull() ?
|
||||||
|
remoteDeviceInfo.deviceUuid().toString() :
|
||||||
|
remoteDeviceInfo.address().toString());
|
||||||
bool enableSaveButton = true;
|
bool enableSaveButton = true;
|
||||||
|
|
||||||
#if !defined(Q_OS_WIN)
|
#if !defined(Q_OS_WIN)
|
||||||
// On other platforms than Windows we can obtain the pairing status so if the devices are not paired we disable the button
|
// On other platforms than Windows we can obtain the pairing status so if the devices are not paired we disable the button
|
||||||
|
// except on MacOS for those devices that only give us a Uuid and not and address (as we have no pairing status for those, either)
|
||||||
|
if (!remoteDeviceInfo.address().isNull()) {
|
||||||
QBluetoothLocalDevice::Pairing pairingStatus = localDevice->pairingStatus(remoteDeviceInfo.address());
|
QBluetoothLocalDevice::Pairing pairingStatus = localDevice->pairingStatus(remoteDeviceInfo.address());
|
||||||
|
|
||||||
if (pairingStatus == QBluetoothLocalDevice::Unpaired) {
|
if (pairingStatus == QBluetoothLocalDevice::Unpaired) {
|
||||||
|
@ -267,7 +284,8 @@ void BtDeviceSelectionDialog::itemClicked(QListWidgetItem *item)
|
||||||
.arg(remoteDeviceInfo.address().toString());
|
.arg(remoteDeviceInfo.address().toString());
|
||||||
enableSaveButton = false;
|
enableSaveButton = false;
|
||||||
}
|
}
|
||||||
if (remoteDeviceInfo.address().isNull()) {
|
}
|
||||||
|
if (remoteDeviceInfo.address().isNull() && remoteDeviceInfo.deviceUuid().isNull()) {
|
||||||
statusMessage = tr("A device needs a non-zero address for a connection.");
|
statusMessage = tr("A device needs a non-zero address for a connection.");
|
||||||
enableSaveButton = false;
|
enableSaveButton = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,8 +112,24 @@ void DownloadFromDCWidget::updateProgressBar()
|
||||||
}
|
}
|
||||||
if (!same_string(progress_bar_text , "")) {
|
if (!same_string(progress_bar_text , "")) {
|
||||||
ui.progressBar->setFormat(progress_bar_text);
|
ui.progressBar->setFormat(progress_bar_text);
|
||||||
|
#if defined(Q_OS_MAC)
|
||||||
|
// on mac the progress bar doesn't show its text
|
||||||
|
ui.progressText->setText(progress_bar_text);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
if (IS_FP_SAME(progress_bar_fraction, 0.0)) {
|
||||||
|
ui.progressBar->setFormat(tr("Connecting to dive computer"));
|
||||||
|
#if defined(Q_OS_MAC)
|
||||||
|
// on mac the progress bar doesn't show its text
|
||||||
|
ui.progressText->setText(tr("Connecting to dive computer"));
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
ui.progressBar->setFormat("%p%");
|
ui.progressBar->setFormat("%p%");
|
||||||
|
#if defined(Q_OS_MAC)
|
||||||
|
// on mac the progress bar doesn't show its text
|
||||||
|
ui.progressText->setText(QString("%1%").arg(lrint(progress_bar_fraction * 100)));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ui.progressBar->setValue(lrint(progress_bar_fraction * 100));
|
ui.progressBar->setValue(lrint(progress_bar_fraction * 100));
|
||||||
free(last_text);
|
free(last_text);
|
||||||
|
@ -131,6 +147,10 @@ void DownloadFromDCWidget::updateState(states state)
|
||||||
markChildrenAsEnabled();
|
markChildrenAsEnabled();
|
||||||
timer->stop();
|
timer->stop();
|
||||||
progress_bar_text = "";
|
progress_bar_text = "";
|
||||||
|
#if defined(Q_OS_MAC)
|
||||||
|
// on mac we show the text in a label
|
||||||
|
ui.progressText->setText(progress_bar_text);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// tries to cancel an on going download
|
// tries to cancel an on going download
|
||||||
|
@ -153,6 +173,10 @@ void DownloadFromDCWidget::updateState(states state)
|
||||||
ui.progressBar->hide();
|
ui.progressBar->hide();
|
||||||
markChildrenAsEnabled();
|
markChildrenAsEnabled();
|
||||||
progress_bar_text = "";
|
progress_bar_text = "";
|
||||||
|
#if defined(Q_OS_MAC)
|
||||||
|
// on mac we show the text in a label
|
||||||
|
ui.progressText->setText(progress_bar_text);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// DOWNLOAD is finally done, but we don't know if there was an error as libdivecomputer doesn't pass
|
// DOWNLOAD is finally done, but we don't know if there was an error as libdivecomputer doesn't pass
|
||||||
|
@ -165,10 +189,15 @@ void DownloadFromDCWidget::updateState(states state)
|
||||||
markChildrenAsEnabled();
|
markChildrenAsEnabled();
|
||||||
progress_bar_text = "";
|
progress_bar_text = "";
|
||||||
} else {
|
} else {
|
||||||
|
if (downloadTable.nr != 0)
|
||||||
progress_bar_text = "";
|
progress_bar_text = "";
|
||||||
ui.progressBar->setValue(100);
|
ui.progressBar->setValue(100);
|
||||||
markChildrenAsEnabled();
|
markChildrenAsEnabled();
|
||||||
}
|
}
|
||||||
|
#if defined(Q_OS_MAC)
|
||||||
|
// on mac we show the text in a label
|
||||||
|
ui.progressText->setText(progress_bar_text);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// DOWNLOAD is started.
|
// DOWNLOAD is started.
|
||||||
|
@ -188,6 +217,10 @@ void DownloadFromDCWidget::updateState(states state)
|
||||||
markChildrenAsEnabled();
|
markChildrenAsEnabled();
|
||||||
progress_bar_text = "";
|
progress_bar_text = "";
|
||||||
ui.progressBar->hide();
|
ui.progressBar->hide();
|
||||||
|
#if defined(Q_OS_MAC)
|
||||||
|
// on mac we show the text in a label
|
||||||
|
ui.progressText->setText(progress_bar_text);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// properly updating the widget state
|
// properly updating the widget state
|
||||||
|
|
|
@ -189,6 +189,13 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="progressText">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="aboveOKCancelSpacer">
|
<spacer name="aboveOKCancelSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|
|
@ -71,6 +71,10 @@ pushd Subsurface.app/Contents/PlugIns/grantlee
|
||||||
ln -s . 5.0
|
ln -s . 5.0
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
if [ "$1" = "-nodmg" ] ; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
# copy things into staging so we can create a nice DMG
|
# copy things into staging so we can create a nice DMG
|
||||||
rm -rf ./staging
|
rm -rf ./staging
|
||||||
mkdir ./staging
|
mkdir ./staging
|
||||||
|
|
Loading…
Reference in a new issue