Fix warnings and add showsolalaweb checkbox

This commit is contained in:
2024-07-12 19:00:53 +02:00
parent 6c235a0fed
commit 94c84af4a1
7 changed files with 106 additions and 42 deletions

View File

@@ -1,2 +1,2 @@
add_subdirectory(qmsgpack) add_subdirectory(qmsgpack SYSTEM)
add_subdirectory(QtZeroConf) add_subdirectory(QtZeroConf SYSTEM)

View File

@@ -68,6 +68,15 @@ NavigationPage {
onAccepted: theSettings.loadSolalawebCert(selectedFile) onAccepted: theSettings.loadSolalawebCert(selectedFile)
} }
} }
CheckDelegate {
Layout.columnSpan: 2
Layout.fillWidth: true
text: qsTr("Show solalaweb:")
checked: theSettings.showSolalaweb
onClicked: theSettings.showSolalaweb = checked
}
} }
} }
} }

View File

@@ -260,29 +260,41 @@ StackView {
Layout.fillWidth: true Layout.fillWidth: true
} }
Button { RowLayout {
enabled: delegate.ip != "" Layout.columnSpan: 2
text: qsTr("Connect local") Button {
onClicked: deviceSelected("ws://" + delegate.ip + "/ws", delegate.password) Layout.fillWidth: true
} enabled: delegate.ip != ""
Button { text: qsTr("Local")
property var cloudUrl: { onClicked: deviceSelected("ws://" + delegate.ip + "/ws", delegate.password)
for (let i = 0; i < cloudUrlsModel.count; ++i) {
const entry = cloudUrlsModel.get(i);
if (delegate.manufacturer === entry.manufacturer &&
delegate.deviceType.includes(entry.deviceType)) {
return entry.url;
}
}
return null;
} }
enabled: cloudUrl !== null Button {
Layout.fillWidth: true
property var cloudUrl: {
for (let i = 0; i < cloudUrlsModel.count; ++i) {
const entry = cloudUrlsModel.get(i);
if (delegate.manufacturer === entry.manufacturer &&
delegate.deviceType.includes(entry.deviceType)) {
return entry.url;
}
}
return null;
}
text: qsTr("Connect cloud") enabled: cloudUrl !== null
onClicked: deviceSelected(cloudUrl + delegate.serial, delegate.password)
text: qsTr("Cloud")
onClicked: deviceSelected(cloudUrl + delegate.serial, delegate.password)
}
Button {
Layout.fillWidth: true
text: qsTr("Solala")
visible: theSettings.showSolalaweb
}
} }
} }
} }

View File

@@ -155,3 +155,20 @@ bool AppSettings::loadSolalawebCert(const QString &url)
return true; return true;
} }
bool AppSettings::showSolalaweb() const
{
if (m_showSolalaweb)
return *m_showSolalaweb;
auto showSolalaweb = value("showSolalaweb").toBool();
m_showSolalaweb = showSolalaweb;
return showSolalaweb;
}
void AppSettings::setShowSolalaweb(bool showSolalaweb)
{
setValue("showSolalaweb", showSolalaweb);
m_showSolalaweb = showSolalaweb;
emit showSolalawebChanged(showSolalaweb);
}

View File

@@ -21,6 +21,7 @@ class AppSettings : public QSettings
Q_PROPERTY(int numberOfAppInstances READ numberOfAppInstances WRITE setNumberOfAppInstances NOTIFY numberOfAppInstancesChanged FINAL) Q_PROPERTY(int numberOfAppInstances READ numberOfAppInstances WRITE setNumberOfAppInstances NOTIFY numberOfAppInstancesChanged FINAL)
Q_PROPERTY(QString solalawebKey READ solalawebKey WRITE setSolalawebKey NOTIFY solalawebKeyChanged FINAL) Q_PROPERTY(QString solalawebKey READ solalawebKey WRITE setSolalawebKey NOTIFY solalawebKeyChanged FINAL)
Q_PROPERTY(QString solalawebCert READ solalawebCert WRITE setSolalawebCert NOTIFY solalawebCertChanged FINAL) Q_PROPERTY(QString solalawebCert READ solalawebCert WRITE setSolalawebCert NOTIFY solalawebCertChanged FINAL)
Q_PROPERTY(bool showSolalaweb READ showSolalaweb WRITE setShowSolalaweb NOTIFY showSolalawebChanged FINAL)
public: public:
std::vector<SavedDevice> getSavedDevices(); std::vector<SavedDevice> getSavedDevices();
@@ -39,13 +40,18 @@ public:
void setSolalawebCert(const QString &solalawebCert); void setSolalawebCert(const QString &solalawebCert);
Q_INVOKABLE bool loadSolalawebCert(const QString &url); Q_INVOKABLE bool loadSolalawebCert(const QString &url);
bool showSolalaweb() const;
void setShowSolalaweb(bool showSolalaweb);
signals: signals:
void numberOfAppInstancesChanged(int numberOfAppInstances); void numberOfAppInstancesChanged(int numberOfAppInstances);
void solalawebKeyChanged(const QString &solalawebKey); void solalawebKeyChanged(const QString &solalawebKey);
void solalawebCertChanged(const QString &solalawebCert); void solalawebCertChanged(const QString &solalawebCert);
void showSolalawebChanged(bool showSolalaweb);
private: private:
mutable std::optional<int> m_numberOfAppInstances; mutable std::optional<int> m_numberOfAppInstances;
mutable std::optional<QString> m_solalawebKey; mutable std::optional<QString> m_solalawebKey;
mutable std::optional<QString> m_solalawebCert; mutable std::optional<QString> m_solalawebCert;
mutable std::optional<bool> m_showSolalaweb;
}; };

View File

@@ -105,7 +105,7 @@ void DeviceConnection::setPassword(const QString &password)
void DeviceConnection::messageReceived(const QVariant &variant) void DeviceConnection::messageReceived(const QVariant &variant)
{ {
if (variant.type() != QMetaType::QVariantMap) if (variant.typeId() != QMetaType::QVariantMap)
{ {
emit logMessage(tr("Received something that is not a json object!")); emit logMessage(tr("Received something that is not a json object!"));
return; return;
@@ -120,7 +120,7 @@ void DeviceConnection::messageReceived(const QVariant &variant)
} }
const auto &typeVariant = *typeIter; const auto &typeVariant = *typeIter;
if (typeVariant.type() != QMetaType::QString) if (typeVariant.typeId() != QMetaType::QString)
{ {
emit logMessage(tr("Received something with a non-string type!")); emit logMessage(tr("Received something with a non-string type!"));
return; return;
@@ -140,7 +140,7 @@ void DeviceConnection::messageReceived(const QVariant &variant)
} }
const auto &serialVariant = *iter; const auto &serialVariant = *iter;
if (serialVariant.type() != QMetaType::QString) if (serialVariant.typeId() != QMetaType::QString)
{ {
emit logMessage(tr("Received hello with a non-string serial!")); emit logMessage(tr("Received hello with a non-string serial!"));
return; return;
@@ -152,7 +152,7 @@ void DeviceConnection::messageReceived(const QVariant &variant)
if (auto iter = map.find("secured"); iter != std::cend(map)) if (auto iter = map.find("secured"); iter != std::cend(map))
{ {
const auto &securedVariant = *iter; const auto &securedVariant = *iter;
if (securedVariant.type() != QMetaType::Bool) if (securedVariant.typeId() != QMetaType::Bool)
{ {
emit logMessage(tr("Received hello with a non-bool secured!")); emit logMessage(tr("Received hello with a non-bool secured!"));
return; return;
@@ -172,7 +172,7 @@ void DeviceConnection::messageReceived(const QVariant &variant)
} }
const auto &manufacturerVariant = *manufacturerIter; const auto &manufacturerVariant = *manufacturerIter;
if (manufacturerVariant.type() != QMetaType::QString) if (manufacturerVariant.typeId() != QMetaType::QString)
{ {
emit logMessage(tr("Received hello with a non-string manufacturer!")); emit logMessage(tr("Received hello with a non-string manufacturer!"));
return; return;
@@ -190,7 +190,7 @@ void DeviceConnection::messageReceived(const QVariant &variant)
} }
const auto &deviceTypeVariant = *devicetypeIter; const auto &deviceTypeVariant = *devicetypeIter;
if (deviceTypeVariant.type() != QMetaType::QString) if (deviceTypeVariant.typeId() != QMetaType::QString)
{ {
emit logMessage(tr("Received hello with a non-string devicetype!")); emit logMessage(tr("Received hello with a non-string devicetype!"));
return; return;
@@ -208,7 +208,7 @@ void DeviceConnection::messageReceived(const QVariant &variant)
} }
const auto &friendlyNameVariant = *friendlyNameIter; const auto &friendlyNameVariant = *friendlyNameIter;
if (friendlyNameVariant.type() != QMetaType::QString) if (friendlyNameVariant.typeId() != QMetaType::QString)
{ {
emit logMessage(tr("Received hello with a non-string friendly_name!")); emit logMessage(tr("Received hello with a non-string friendly_name!"));
return; return;
@@ -236,7 +236,7 @@ void DeviceConnection::messageReceived(const QVariant &variant)
} }
const auto &token1Variant = *iter; const auto &token1Variant = *iter;
if (token1Variant.type() != QMetaType::QString) if (token1Variant.typeId() != QMetaType::QString)
{ {
emit logMessage(tr("Received authRequired with a non-string token1!")); emit logMessage(tr("Received authRequired with a non-string token1!"));
return; return;
@@ -254,7 +254,7 @@ void DeviceConnection::messageReceived(const QVariant &variant)
} }
const auto &token2Variant = *iter; const auto &token2Variant = *iter;
if (token2Variant.type() != QMetaType::QString) if (token2Variant.typeId() != QMetaType::QString)
{ {
emit logMessage(tr("Received authRequired with a non-string token2!")); emit logMessage(tr("Received authRequired with a non-string token2!"));
return; return;
@@ -277,7 +277,7 @@ void DeviceConnection::messageReceived(const QVariant &variant)
if (auto iter = map.find("partial"); iter != std::cend(map)) if (auto iter = map.find("partial"); iter != std::cend(map))
{ {
const auto &partialVariant = *iter; const auto &partialVariant = *iter;
if (partialVariant.type() != QMetaType::Bool) if (partialVariant.typeId() != QMetaType::Bool)
{ {
emit logMessage(tr("Received fullStatus with a non-bool partial!")); emit logMessage(tr("Received fullStatus with a non-bool partial!"));
return; return;
@@ -294,7 +294,7 @@ void DeviceConnection::messageReceived(const QVariant &variant)
} }
const auto &statusVariant = *iter; const auto &statusVariant = *iter;
if (statusVariant.type() != QMetaType::QVariantMap) if (statusVariant.typeId() != QMetaType::QVariantMap)
{ {
emit logMessage(tr("Received fullStatus with a non-object status!")); emit logMessage(tr("Received fullStatus with a non-object status!"));
return; return;
@@ -321,7 +321,7 @@ void DeviceConnection::messageReceived(const QVariant &variant)
} }
const auto &statusVariant = *iter; const auto &statusVariant = *iter;
if (statusVariant.type() != QMetaType::QVariantMap) if (statusVariant.typeId() != QMetaType::QVariantMap)
{ {
emit logMessage(tr("Received deltaStatus with a non-object status!")); emit logMessage(tr("Received deltaStatus with a non-object status!"));
return; return;
@@ -335,7 +335,7 @@ void DeviceConnection::messageReceived(const QVariant &variant)
if (iter.key() == "fna") if (iter.key() == "fna")
{ {
const auto &friendlyNameVariant = iter.value(); const auto &friendlyNameVariant = iter.value();
if (friendlyNameVariant.type() == QMetaType::QString) if (friendlyNameVariant.typeId() == QMetaType::QString)
{ {
const auto &friendlyName = friendlyNameVariant.toString(); const auto &friendlyName = friendlyNameVariant.toString();
if (m_friendlyName != friendlyName) if (m_friendlyName != friendlyName)
@@ -363,7 +363,7 @@ void DeviceConnection::messageReceived(const QVariant &variant)
if (auto iter = map.find("requestId"); iter != std::cend(map)) if (auto iter = map.find("requestId"); iter != std::cend(map))
{ {
const auto &requestIdVariant = *iter; const auto &requestIdVariant = *iter;
if (requestIdVariant.type() != QMetaType::QString) if (requestIdVariant.typeId() != QMetaType::QString)
{ {
emit logMessage(tr("Received message with a non-string requestId!")); emit logMessage(tr("Received message with a non-string requestId!"));
return; return;

View File

@@ -203,6 +203,12 @@
<source>solalaweb cert:</source> <source>solalaweb cert:</source>
<translation>solalaweb cert:</translation> <translation>solalaweb cert:</translation>
</message> </message>
<message>
<location filename="../AppSettingsPage.qml" line="74"/>
<location filename="../build/Desktop-Debug/EVChargerApp/AppSettingsPage.qml" line="74"/>
<source>Show solalaweb:</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>BaseNavigationPage</name> <name>BaseNavigationPage</name>
@@ -887,8 +893,26 @@
<translation>Seriennummer %0</translation> <translation>Seriennummer %0</translation>
</message> </message>
<message> <message>
<location filename="../DeviceListScreen.qml" line="316"/> <location filename="../DeviceListScreen.qml" line="266"/>
<location filename="../build/Desktop-Debug/EVChargerApp/DeviceListScreen.qml" line="316"/> <location filename="../build/Desktop-Debug/EVChargerApp/DeviceListScreen.qml" line="266"/>
<source>🛜</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../DeviceListScreen.qml" line="284"/>
<location filename="../build/Desktop-Debug/EVChargerApp/DeviceListScreen.qml" line="284"/>
<source></source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../DeviceListScreen.qml" line="289"/>
<location filename="../build/Desktop-Debug/EVChargerApp/DeviceListScreen.qml" line="289"/>
<source>Solala</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../DeviceListScreen.qml" line="320"/>
<location filename="../build/Desktop-Debug/EVChargerApp/DeviceListScreen.qml" line="320"/>
<source>Add or setup device</source> <source>Add or setup device</source>
<translation>Gerät hinzufügen oder einrichten</translation> <translation>Gerät hinzufügen oder einrichten</translation>
</message> </message>
@@ -937,16 +961,12 @@
<translation>Ip:</translation> <translation>Ip:</translation>
</message> </message>
<message> <message>
<location filename="../DeviceListScreen.qml" line="266"/>
<location filename="../build/Desktop-Debug/EVChargerApp/DeviceListScreen.qml" line="266"/>
<source>Connect local</source> <source>Connect local</source>
<translation>Lokal verbinden</translation> <translation type="vanished">Lokal verbinden</translation>
</message> </message>
<message> <message>
<location filename="../DeviceListScreen.qml" line="284"/>
<location filename="../build/Desktop-Debug/EVChargerApp/DeviceListScreen.qml" line="284"/>
<source>Connect cloud</source> <source>Connect cloud</source>
<translation>Über cloud verbinden</translation> <translation type="vanished">Über cloud verbinden</translation>
</message> </message>
<message> <message>
<source>Settings</source> <source>Settings</source>