Skip to content

Commit

Permalink
macOS fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
emericg committed Sep 28, 2023
1 parent 3de44cb commit a99e44a
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 41 deletions.
1 change: 1 addition & 0 deletions qml/PanelDeviceInfos.qml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ Flickable {
Layout.minimumHeight: 32

text: (selectedDevice && selectedDevice.deviceAddress)
font.pixelSize: Theme.fontSizeComponentSmall
wrapMode: Text.WrapAnywhere
}
}
Expand Down
9 changes: 0 additions & 9 deletions qml/components_themed/SpinBoxThemed_desktop.qml
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,6 @@ T.SpinBox {
inputMethodHints: Qt.ImhDigitsOnly

onEditingFinished: {
var v = parseInt(text)
if (text.length <= 0) v = control.from
if (isNaN(v)) v = control.from
if (v < control.from) v = control.from
if (v > control.to) v = control.to

control.value = v
control.valueModified()

control.focus = false
focus = false
}
Expand Down
8 changes: 4 additions & 4 deletions src/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,10 +840,10 @@ void DeviceManager::addBleDevice(const QBluetoothDeviceInfo &info)
DeviceToolBLEx *d = new DeviceToolBLEx(info, this);
if (d)
{
if (info.name().isEmpty()) d->setBeacon(true);
if (info.name().replace('-', ':') == info.address().toString()) d->setBeacon(true);
if (info.isCached() || info.rssi() == 0) d->setCached(true);
if (m_devices_blacklist.contains(info.address().toString())) d->setBlacklisted(true);
if (info.name().isEmpty()) d->setBeacon(true);
if (info.name().replace('-', ':') == d->getAddress()) d->setBeacon(true);
if (m_devices_blacklist.contains(d->getAddress())) d->setBlacklisted(true);

// Get a random color
d->setDeviceColor(getAvailableColor());
Expand All @@ -856,7 +856,7 @@ void DeviceManager::addBleDevice(const QBluetoothDeviceInfo &info)
SettingsManager *sm = SettingsManager::getInstance();
if (sm->getScanCacheAuto() && !d->isBeacon())
{
cacheDevice(info.address().toString());
cacheDevice(d->getAddress());
}

//qDebug() << "Device added (from BLE discovery): " << d->getName() << "/" << d->getAddress();
Expand Down
4 changes: 3 additions & 1 deletion src/SettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ bool SettingsManager::readSettings()
if (m_appVisibility < 1 || m_appVisibility > 5) m_appVisibility = 1;
#endif

////

if (settings.contains("settings/appTheme"))
m_appTheme = settings.value("settings/appTheme").toString();

Expand All @@ -100,7 +102,7 @@ bool SettingsManager::readSettings()
if (settings.contains("settings/appUnits"))
m_appUnits = settings.value("settings/appUnits").toInt();

//
////

if (settings.contains("settings/scanAuto"))
m_scanAuto = settings.value("settings/scanAuto").toBool();
Expand Down
1 change: 0 additions & 1 deletion src/SettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ class SettingsManager: public QObject

////

// Utils
Q_INVOKABLE void reloadSettings();
Q_INVOKABLE void resetSettings();
};
Expand Down
72 changes: 51 additions & 21 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Device::Device(const QString &deviceAddr, const QString &deviceName, QObject *pa
// Check address validity
if (m_bleDevice.isValid() == false)
{
qWarning() << "Device() '" << m_deviceAddress << "' is an invalid QBluetoothDeviceInfo...";
qWarning() << "Device() '" << getAddress() << "' is an invalid QBluetoothDeviceInfo...";
}

// Database
Expand Down Expand Up @@ -111,7 +111,7 @@ Device::Device(const QBluetoothDeviceInfo &d, QObject *parent) : QObject(parent)
// Check address validity
if (m_bleDevice.isValid() == false)
{
qWarning() << "Device() '" << m_deviceAddress << "' is an invalid QBluetoothDeviceInfo...";
qWarning() << "Device() '" << getAddress() << "' is an invalid QBluetoothDeviceInfo...";
}

// Database
Expand Down Expand Up @@ -358,7 +358,7 @@ void Device::setTimeoutTimer(int)

bool Device::getSqlDeviceInfos()
{
//qDebug() << "Device::getSqlDeviceInfos(" << m_deviceAddress << ")";
//qDebug() << "Device::getSqlDeviceInfos(" << getAddress() << ")";
return false;
}

Expand Down Expand Up @@ -394,30 +394,60 @@ bool Device::isUpdating() const

bool Device::hasAddressMAC() const
{
#if !defined(Q_OS_MACOS) && !defined(Q_OS_IOS)
return true;
#endif
if (m_deviceAddressMAC.size() == 17) return true;
if (m_deviceAddress.size() == 17) return true;

return !m_deviceAddressMAC.isEmpty();
return false;
}

QString Device::getAddressMAC() const
{
#if !defined(Q_OS_MACOS) && !defined(Q_OS_IOS)
return m_deviceAddress;
#endif
if (m_deviceAddressMAC.size() == 17) return m_deviceAddressMAC;
if (m_deviceAddress.size() == 17) return m_deviceAddress;

return m_deviceAddressMAC;
return QString();
}

void Device::setAddressMAC(const QString &mac)
{
//qDebug() << "setAddressMAC(" << mac << ")";

if (m_deviceAddressMAC != mac)
if (mac.size() == 17)
{
m_deviceAddressMAC = mac;
Q_EMIT settingsUpdated();
if (m_deviceAddressMAC != mac)
{
m_deviceAddressMAC = mac;
Q_EMIT sensorUpdated();
}
}
}

bool Device::hasAddressUUID() const
{
return (m_deviceAddress.size() == 38);
}

QString Device::getAddressUUID() const
{
if (m_deviceAddress.size() == 38) return m_deviceAddress;

return QString();
}

void Device::setAddressUUID(const QString &uuid)
{
//qDebug() << "setAddressUUID(" << uuid << ")";

if (uuid.size() == 38)
{
if (m_deviceAddress.isEmpty() || m_deviceAddress.size() == 38)
{
if (m_deviceAddress != uuid)
{
m_deviceAddress = uuid;
Q_EMIT sensorUpdated();
}
}
}
}

Expand Down Expand Up @@ -576,7 +606,7 @@ void Device::setCoreConfiguration(const int bleconf)

void Device::setDeviceClass(const int major, const int minor, const int service)
{
//qDebug() << "Device::setDeviceClass() " << info.name() << info.address() << info.minorDeviceClass() << info.majorDeviceClass() << info.serviceClasses();
//qDebug() << "Device::setDeviceClass() " << getName() << getAddress() << major << minor << service;

if (m_major != major || m_minor != minor || m_service != service)
{
Expand Down Expand Up @@ -620,7 +650,7 @@ void Device::cleanRssi()

void Device::deviceConnected()
{
//qDebug() << "Device::deviceConnected(" << m_deviceAddress << ")";
//qDebug() << "Device::deviceConnected(" << getAddress() << ")";

m_ble_status = DeviceUtils::DEVICE_CONNECTED;

Expand Down Expand Up @@ -679,7 +709,7 @@ void Device::deviceConnected()

void Device::deviceDisconnected()
{
//qDebug() << "Device::deviceDisconnected(" << m_deviceAddress << ")";
//qDebug() << "Device::deviceDisconnected(" << getAddress() << ")";

Q_EMIT disconnected();

Expand All @@ -690,7 +720,7 @@ void Device::deviceDisconnected()
void Device::deviceErrored(QLowEnergyController::Error error)
{
if (error <= QLowEnergyController::NoError) return;
qWarning() << "Device::deviceErrored(" << m_deviceAddress << ") error:" << error;
qWarning() << "Device::deviceErrored(" << getAddress() << ") error:" << error;
/*
QLowEnergyController::NoError 0 No error has occurred.
QLowEnergyController::UnknownError 1 An unknown error has occurred.
Expand All @@ -714,7 +744,7 @@ void Device::deviceErrored(QLowEnergyController::Error error)

void Device::deviceStateChanged(QLowEnergyController::ControllerState)
{
//qDebug() << "Device::deviceStateChanged(" << m_deviceAddress << ") state:" << state;
//qDebug() << "Device::deviceStateChanged(" << getAddress() << ") state:" << state;
}

/* ************************************************************************** */
Expand All @@ -726,12 +756,12 @@ void Device::addLowEnergyService(const QBluetoothUuid &)

void Device::serviceDetailsDiscovered(QLowEnergyService::ServiceState)
{
//qDebug() << "Device::serviceDetailsDiscovered(" << m_deviceAddress << ")";
//qDebug() << "Device::serviceDetailsDiscovered(" << getAddress() << ")";
}

void Device::serviceScanDone()
{
//qDebug() << "Device::serviceScanDone(" << m_deviceAddress << ")";
//qDebug() << "Device::serviceScanDone(" << getAddress() << ")";
}

/* ************************************************************************** */
Expand Down
10 changes: 7 additions & 3 deletions src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ class Device: public QObject
QString getFirmware() const { return m_deviceFirmware; }
int getBatteryLevel() const { return m_deviceBattery; }

bool hasAddressMAC() const;
QString getAddressMAC() const;
void setAddressMAC(const QString &mac);
bool hasAddressUUID() const;
QString getAddressUUID() const;
void setAddressUUID(const QString &uuid);

// Device type, capabilities and sensors
int getDeviceType() const { return m_deviceType; }
int getDeviceCapabilities() const { return m_deviceCapabilities; }
Expand Down Expand Up @@ -248,9 +255,6 @@ class Device: public QObject
bool isErrored() const; //!< Has emitted a BLE error

// Device associated data
bool hasAddressMAC() const;
QString getAddressMAC() const;
void setAddressMAC(const QString &mac);
bool isEnabled() const { return m_isEnabled; }
// Device additional settings
Q_INVOKABLE bool hasSetting(const QString &key) const;
Expand Down
12 changes: 10 additions & 2 deletions src/device_toolblex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,9 +1086,17 @@ bool DeviceToolBLEx::exportDeviceInfo(const QString &exportPath,
QString str;
QString endl = QChar('\n');

// Name and address
str += "Device Name: " + m_deviceName + endl;
if (hasAddressMAC()) str += "Device MAC: " + m_deviceAddress + endl;
if (m_deviceManufacturer.length() > 0) str += "Device MAC manufacturer: " + m_deviceManufacturer + endl;
if (hasAddressMAC())
{
str += "Device MAC: " + getAddressMAC() + endl;
if (m_deviceManufacturer.length() > 0) str += "Device MAC manufacturer: " + m_deviceManufacturer + endl;
}
else if (hasAddressUUID())
{
str += "Device MAC: " + getAddressUUID() + endl;
}
str += endl;

// Generic info
Expand Down

0 comments on commit a99e44a

Please sign in to comment.