some cleanups

This commit is contained in:
Michael Zanetti 2018-04-20 18:03:52 +02:00
parent 88d730ddb5
commit 370df7d047
12 changed files with 122 additions and 78 deletions

View File

@ -38,6 +38,11 @@ QHash<int, QByteArray> DeviceDiscovery::roleNames() const
void DeviceDiscovery::discoverDevices(const QUuid &deviceClassId, const QVariantList &discoveryParams) void DeviceDiscovery::discoverDevices(const QUuid &deviceClassId, const QVariantList &discoveryParams)
{ {
beginResetModel();
m_foundDevices.clear();
endResetModel();
emit countChanged();
QVariantMap params; QVariantMap params;
params.insert("deviceClassId", deviceClassId.toString()); params.insert("deviceClassId", deviceClassId.toString());
if (!discoveryParams.isEmpty()) { if (!discoveryParams.isEmpty()) {
@ -46,7 +51,6 @@ void DeviceDiscovery::discoverDevices(const QUuid &deviceClassId, const QVariant
Engine::instance()->jsonRpcClient()->sendCommand("Devices.GetDiscoveredDevices", params, this, "discoverDevicesResponse"); Engine::instance()->jsonRpcClient()->sendCommand("Devices.GetDiscoveredDevices", params, this, "discoverDevicesResponse");
m_busy = true; m_busy = true;
emit busyChanged(); emit busyChanged();
emit countChanged();
} }
bool DeviceDiscovery::busy() const bool DeviceDiscovery::busy() const

View File

@ -129,7 +129,6 @@ QHash<int, QByteArray> Devices::roleNames() const
roles[RoleId] = "id"; roles[RoleId] = "id";
roles[RoleDeviceClass] = "deviceClassId"; roles[RoleDeviceClass] = "deviceClassId";
roles[RoleSetupComplete] = "setupComplete"; roles[RoleSetupComplete] = "setupComplete";
roles[RoleBasicTag] = "basicTag";
roles[RoleInterfaces] = "interfaces"; roles[RoleInterfaces] = "interfaces";
return roles; return roles;
} }

View File

@ -38,7 +38,6 @@ public:
RoleId, RoleId,
RoleDeviceClass, RoleDeviceClass,
RoleSetupComplete, RoleSetupComplete,
RoleBasicTag,
RoleInterfaces RoleInterfaces
}; };
Q_ENUM(Roles) Q_ENUM(Roles)

View File

@ -39,6 +39,7 @@ void DevicesProxy::setDevices(Devices *devices)
if (m_devices != devices) { if (m_devices != devices) {
m_devices = devices; m_devices = devices;
setSourceModel(devices); setSourceModel(devices);
setSortRole(Devices::RoleName);
sort(0); sort(0);
connect(devices, &Devices::countChanged, this, &DevicesProxy::countChanged); connect(devices, &Devices::countChanged, this, &DevicesProxy::countChanged);
emit devicesChanged(); emit devicesChanged();
@ -83,8 +84,8 @@ Device *DevicesProxy::get(int index) const
bool DevicesProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const bool DevicesProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
{ {
QVariant leftName = sourceModel()->data(left); QVariant leftName = sourceModel()->data(left, Devices::RoleName);
QVariant rightName = sourceModel()->data(right); QVariant rightName = sourceModel()->data(right, Devices::RoleName);
return QString::localeAwareCompare(leftName.toString(), rightName.toString()) < 0; return QString::localeAwareCompare(leftName.toString(), rightName.toString()) < 0;
} }

View File

@ -134,8 +134,10 @@ void UpnpDiscovery::readData()
data.resize(pendingDatagramSize()); data.resize(pendingDatagramSize());
readDatagram(data.data(), data.size(), &hostAddress, &port); readDatagram(data.data(), data.size(), &hostAddress, &port);
} }
if (data.contains("10.10.10.128"))
qDebug() << "Data received" << data; if (!discovering()) {
return;
}
// if the data contains the HTTP OK header... // if the data contains the HTTP OK header...
if (data.contains("HTTP/1.1 200 OK") || data.contains("NOTIFY * HTTP/1.1")) { if (data.contains("HTTP/1.1 200 OK") || data.contains("NOTIFY * HTTP/1.1")) {

View File

@ -150,5 +150,6 @@
<file>ui/images/clock-app-symbolic.svg</file> <file>ui/images/clock-app-symbolic.svg</file>
<file>ui/devicepages/StateLogPage.qml</file> <file>ui/devicepages/StateLogPage.qml</file>
<file>ui/customviews/GenericTypeLogView.qml</file> <file>ui/customviews/GenericTypeLogView.qml</file>
<file>guh-logo.svg</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -157,7 +157,6 @@ Page {
Dialog { Dialog {
id: certDialog id: certDialog
width: Math.min(parent.width * .9, 400) width: Math.min(parent.width * .9, 400)
height: content.height
x: (parent.width - width) / 2 x: (parent.width - width) / 2
y: (parent.height - height) / 2 y: (parent.height - height) / 2
standardButtons: Dialog.Yes | Dialog.No standardButtons: Dialog.Yes | Dialog.No
@ -167,7 +166,6 @@ Page {
ColumnLayout { ColumnLayout {
anchors { left: parent.left; right: parent.right; top: parent.top } anchors { left: parent.left; right: parent.right; top: parent.top }
height: childrenRect.height
spacing: app.margins spacing: app.margins
RowLayout { RowLayout {

View File

@ -15,6 +15,14 @@ Page {
onMenuPressed: mainMenu.open() onMenuPressed: mainMenu.open()
} }
Image {
id: bg
source: "../guh-logo.svg"
anchors.fill: parent
fillMode: Image.PreserveAspectFit
opacity: .2
}
Menu { Menu {
id: mainMenu id: mainMenu
width: implicitWidth + app.margins width: implicitWidth + app.margins
@ -77,9 +85,13 @@ Page {
ListView { ListView {
width: swipeView.width width: swipeView.width
height: swipeView.height height: swipeView.height
model: Engine.deviceManager.devices model: DevicesProxy {
id: devicesProxy
devices: Engine.deviceManager.devices
}
delegate: ItemDelegate { delegate: ItemDelegate {
width: parent.width width: parent.width
property string mainInterface: app.interfacesToIcon(model.interfaces)
contentItem: RowLayout { contentItem: RowLayout {
spacing: app.margins spacing: app.margins
ColorIcon { ColorIcon {
@ -93,9 +105,14 @@ Page {
Layout.fillWidth: true Layout.fillWidth: true
text: model.name text: model.name
} }
Image {
source: "images/next.svg"
Layout.preferredHeight: parent.height
Layout.preferredWidth: height
}
} }
onClicked: { onClicked: {
pageStack.push(Qt.resolvedUrl("devicepages/GenericDevicePage.qml"), {device: Engine.deviceManager.devices.get(index)}) pageStack.push(Qt.resolvedUrl("devicepages/GenericDevicePage.qml"), {device: devicesProxy.get(index)})
} }
} }
@ -117,7 +134,7 @@ Page {
} }
ColumnLayout { ColumnLayout {
anchors { left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter; margins: app.margins } anchors { left: parent.left; right: parent.right; top: parent.top; margins: app.margins }
spacing: app.margins spacing: app.margins
visible: Engine.deviceManager.devices.count === 0 && !Engine.deviceManager.fetchingData visible: Engine.deviceManager.devices.count === 0 && !Engine.deviceManager.fetchingData
Label { Label {

View File

@ -34,10 +34,6 @@ Page {
property bool addResult: false property bool addResult: false
} }
DeviceDiscovery {
id: discovery
}
Connections { Connections {
target: Engine.deviceManager target: Engine.deviceManager
onPairDeviceReply: { onPairDeviceReply: {
@ -63,6 +59,10 @@ Page {
} }
} }
DeviceDiscovery {
id: discovery
}
StackView { StackView {
id: internalPageStack id: internalPageStack
anchors.fill: parent anchors.fill: parent
@ -75,14 +75,15 @@ Page {
delegate: ItemDelegate { delegate: ItemDelegate {
width: parent.width width: parent.width
height: app.delegateHeight height: app.delegateHeight
ColumnLayout { contentItem: RowLayout {
anchors.fill: parent
anchors.margins: app.margins
Label { Label {
text: model.displayName
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true text: model.displayName
verticalAlignment: Text.AlignVCenter }
Image {
source: "images/next.svg"
Layout.preferredHeight: parent.height
Layout.preferredWidth: height
} }
} }
@ -109,14 +110,15 @@ Page {
delegate: ItemDelegate { delegate: ItemDelegate {
width: parent.width width: parent.width
height: app.delegateHeight height: app.delegateHeight
ColumnLayout { contentItem: RowLayout {
anchors.fill: parent
anchors.margins: app.margins
Label { Label {
text: model.displayName
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true text: model.displayName
verticalAlignment: Text.AlignVCenter }
Image {
source: "images/next.svg"
Layout.preferredHeight: parent.height
Layout.preferredWidth: height
} }
} }
@ -145,26 +147,52 @@ Page {
Page { Page {
id: discoveryParamsView id: discoveryParamsView
ColumnLayout { ColumnLayout {
anchors.fill: parent anchors.fill: parent
anchors.margins: 10 anchors.margins: 10
Repeater { Flickable {
id: paramRepeater Layout.fillHeight: true
model: d.deviceClass ? d.deviceClass["discoveryParamTypes"] : null Layout.fillWidth: true
Loader { ColumnLayout {
Layout.fillWidth: true width: parent.width
sourceComponent: searchStringEntryComponent
property var discoveryParams: model Repeater {
property var value: item ? item.value : null id: paramRepeater
model: d.deviceClass ? d.deviceClass["discoveryParamTypes"] : null
Loader {
Layout.fillWidth: true
sourceComponent: searchStringEntryComponent
property var discoveryParams: model
property var value: item ? item.value : null
}
}
Button {
Layout.fillWidth: true
text: "Next"
onClicked: {
var paramTypes = d.deviceClass["discoveryParamTypes"];
d.discoveryParams = [];
for (var i = 0; i < paramTypes.count; i++) {
var param = {};
param["paramTypeId"] = paramTypes.get(i).id;
param["value"] = paramRepeater.itemAt(i).value
d.discoveryParams.push(param);
}
discovery.discoverDevices(d.deviceClass.id, d.discoveryParams)
internalPageStack.push(discoveryPage)
}
}
} }
} }
Component { Component {
id: searchStringEntryComponent id: searchStringEntryComponent
ColumnLayout { ColumnLayout {
property alias value: searchTextField.text property alias value: searchTextField.text
Label { Label {
text: discoveryParams.name text: discoveryParams.displayName
Layout.fillWidth: true Layout.fillWidth: true
} }
TextField { TextField {
@ -173,23 +201,6 @@ Page {
} }
} }
} }
Button {
Layout.fillWidth: true
text: "Next"
onClicked: {
var paramTypes = d.deviceClass["discoveryParamTypes"];
d.discoveryParams = [];
for (var i = 0; i < paramTypes.count; i++) {
var param = {};
param["paramTypeId"] = paramTypes.get(i).id;
param["value"] = paramRepeater.itemAt(i).value
d.discoveryParams.push(param);
}
discovery.discoverDevices(d.deviceClass.id, d.discoveryParams)
internalPageStack.push(discoveryPage)
}
}
} }
} }
} }
@ -200,6 +211,7 @@ Page {
Page { Page {
id: discoveryView id: discoveryView
ListView { ListView {
anchors.fill: parent anchors.fill: parent
model: discovery model: discovery
@ -286,6 +298,7 @@ Page {
ColumnLayout { ColumnLayout {
anchors.fill: parent anchors.fill: parent
spacing: app.margins spacing: app.margins
ColumnLayout { ColumnLayout {
Layout.margins: app.margins Layout.margins: app.margins
Layout.fillWidth: true Layout.fillWidth: true
@ -301,15 +314,19 @@ Page {
} }
ThinDivider {} ThinDivider {}
Flickable { Flickable {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
contentHeight: paramsColumn.implicitHeight
clip: true
Column { Column {
id: paramsColumn
width: parent.width width: parent.width
Repeater { Repeater {
id: paramRepeater id: paramRepeater
model: d.deviceClass.paramTypes model: d.deviceDescriptorId == null ? d.deviceClass.paramTypes : null
delegate: ParamDelegate { delegate: ParamDelegate {
width: parent.width width: parent.width
paramType: d.deviceClass.paramTypes.get(index) paramType: d.deviceClass.paramTypes.get(index)
@ -321,6 +338,8 @@ Page {
Button { Button {
Layout.fillWidth: true Layout.fillWidth: true
Layout.margins: app.margins
text: "OK" text: "OK"
onClicked: { onClicked: {
print("setupMethod", d.deviceClass.setupMethod) print("setupMethod", d.deviceClass.setupMethod)

View File

@ -103,20 +103,6 @@ Page {
color: app.guhAccent color: app.guhAccent
} }
RowLayout {
Layout.fillWidth: true
Layout.leftMargin: app.margins
Layout.rightMargin: app.margins
spacing: app.margins
Label {
text: qsTr("Debug server enabled")
Layout.fillWidth: true
}
Switch {
checked: Engine.basicConfiguration.debugServerEnabled
onClicked: Engine.basicConfiguration.debugServerEnabled = checked
}
}
RowLayout { RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
@ -133,6 +119,25 @@ Page {
} }
} }
ColumnLayout {
Layout.fillWidth: true
RowLayout {
Layout.fillWidth: true
Layout.leftMargin: app.margins
Layout.rightMargin: app.margins
spacing: app.margins
Label {
text: qsTr("Debug server enabled")
Layout.fillWidth: true
}
Switch {
checked: Engine.basicConfiguration.debugServerEnabled
onClicked: Engine.basicConfiguration.debugServerEnabled = checked
}
}
}
ItemDelegate { ItemDelegate {
Layout.fillWidth: true Layout.fillWidth: true
contentItem: RowLayout { contentItem: RowLayout {
@ -150,6 +155,5 @@ Page {
pageStack.push(Qt.resolvedUrl("system/PluginsPage.qml")) pageStack.push(Qt.resolvedUrl("system/PluginsPage.qml"))
} }
} }
} }
} }

View File

@ -32,7 +32,11 @@ ItemDelegate {
switch (paramType.type.toLowerCase()) { switch (paramType.type.toLowerCase()) {
case "bool": case "bool":
return boolComponent; return boolComponent;
case "double":
case "int": case "int":
if (paramType.minValue === undefined || paramType.maxValue === undefined) {
return textFieldComponent
}
return stringComponent; return stringComponent;
case "string": case "string":
case "qstring": case "qstring":
@ -72,7 +76,7 @@ ItemDelegate {
switch (paramType.type.toLowerCase()) { switch (paramType.type.toLowerCase()) {
case "int": case "int":
case "double": case "double":
if (paramType.minValue != undefined && paramType.maxValue != undefined) { if (paramType.minValue !== undefined && paramType.maxValue !== undefined) {
return sliderComponent return sliderComponent
} }
break; break;

View File

@ -78,21 +78,17 @@ DevicePageBase {
} }
ColorPickerCt { ColorPickerCt {
id: pickerCt id: pickerCt
Layout.fillWidth: true Layout.fillWidth: true
Layout.margins: app.margins Layout.margins: app.margins
property var actionType: root.deviceClass.actionTypes.findByName("colorTemperature") property var actionType: root.deviceClass.actionTypes.findByName("colorTemperature")
property var stateType: root.deviceClass.stateTypes.findByName("colorTemperature")
property var ctState: actionType ? root.device.states.getState(actionType.id) : null property var ctState: actionType ? root.device.states.getState(actionType.id) : null
ct: ctState ? ctState.value : 0 ct: ctState ? ctState.value : 0
visible: root.deviceClass.interfaces.indexOf("colorlight") >= 0 visible: root.deviceClass.interfaces.indexOf("colorlight") >= 0
minCt: actionType.paramTypes.findByName("colorTemperature").minValue
maxCt: actionType.paramTypes.findByName("colorTemperature").maxValue
height: 80 height: 80