some more work on rules and the main view
This commit is contained in:
parent
143900a19a
commit
bfd197a016
@ -40,7 +40,7 @@ void BasicConfiguration::init()
|
||||
|
||||
void BasicConfiguration::getConfigurationsResponse(const QVariantMap ¶ms)
|
||||
{
|
||||
qDebug() << "have config reply" << params;
|
||||
// qDebug() << "have config reply" << params;
|
||||
QVariantMap basicConfig = params.value("params").toMap().value("basicConfiguration").toMap();
|
||||
m_debugServerEnabled = basicConfig.value("debugServerEnabled").toBool();
|
||||
m_serverName = basicConfig.value("serverName").toString();
|
||||
|
||||
@ -34,7 +34,7 @@ void ZeroconfDiscovery::serviceEntryAdded(const AvahiServiceEntry &entry)
|
||||
if (!entry.name().startsWith("nymea") || entry.serviceType() != "_jsonrpc._tcp") {
|
||||
return;
|
||||
}
|
||||
qDebug() << "avahi service entry added" << entry.name() << entry.hostAddress() << entry.port() << entry.txt() << entry.serviceType();
|
||||
// qDebug() << "avahi service entry added" << entry.name() << entry.hostAddress() << entry.port() << entry.txt() << entry.serviceType();
|
||||
|
||||
QString uuid;
|
||||
bool sslEnabled = false;
|
||||
|
||||
@ -83,23 +83,26 @@ void InterfacesModel::syncInterfaces()
|
||||
}
|
||||
}
|
||||
QStringList interfacesToAdd = interfacesInSource;
|
||||
QStringList interfacesToRemove;
|
||||
|
||||
for (QStringList::iterator i = m_interfaces.begin(); i != m_interfaces.end();) {
|
||||
if (!interfacesInSource.contains(*i)) {
|
||||
int idx = m_interfaces.indexOf(*i);
|
||||
beginRemoveRows(QModelIndex(), idx, idx);
|
||||
m_interfaces.takeAt(idx);
|
||||
endRemoveRows();
|
||||
continue;
|
||||
foreach (const QString &interface, m_interfaces) {
|
||||
if (!interfacesInSource.contains(interface)) {
|
||||
interfacesToRemove.append(interface);
|
||||
}
|
||||
interfacesToAdd.removeAll(*i);
|
||||
++i;
|
||||
interfacesToAdd.removeAll(interface);
|
||||
}
|
||||
foreach (const QString &interface, interfacesToRemove) {
|
||||
int idx = m_interfaces.indexOf(interface);
|
||||
beginRemoveRows(QModelIndex(), idx, idx);
|
||||
m_interfaces.takeAt(idx);
|
||||
endRemoveRows();
|
||||
}
|
||||
if (!interfacesToAdd.isEmpty()) {
|
||||
beginInsertRows(QModelIndex(), m_interfaces.count(), m_interfaces.count() + interfacesToAdd.count() - 1);
|
||||
m_interfaces.append(interfacesToAdd);
|
||||
endInsertRows();
|
||||
}
|
||||
emit countChanged();
|
||||
}
|
||||
|
||||
void InterfacesModel::rowsChanged(const QModelIndex &index, int first, int last)
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
class InterfacesModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||
Q_PROPERTY(Devices* devices READ devices WRITE setDevices NOTIFY devicesChanged)
|
||||
Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged)
|
||||
|
||||
@ -31,6 +32,7 @@ public:
|
||||
void setShownInterfaces(const QStringList &shownInterfaces);
|
||||
|
||||
signals:
|
||||
void countChanged();
|
||||
void devicesChanged();
|
||||
void shownInterfacesChanged();
|
||||
|
||||
|
||||
@ -158,7 +158,7 @@ void JsonRpcClient::sendRequest(const QVariantMap &request)
|
||||
{
|
||||
QVariantMap newRequest = request;
|
||||
newRequest.insert("token", m_token);
|
||||
qDebug() << "Sending request" << qUtf8Printable(QJsonDocument::fromVariant(newRequest).toJson());
|
||||
// qDebug() << "Sending request" << qUtf8Printable(QJsonDocument::fromVariant(newRequest).toJson());
|
||||
m_connection->sendData(QJsonDocument::fromVariant(newRequest).toJson());
|
||||
}
|
||||
|
||||
|
||||
@ -140,5 +140,6 @@
|
||||
<file>ui/magic/SimpleStateEvaluatorDelegate.qml</file>
|
||||
<file>ui/magic/SelectStateDescriptorParamsPage.qml</file>
|
||||
<file>ui/magic/SelectStateDescriptorPage.qml</file>
|
||||
<file>ui/images/select-none.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@ -112,7 +112,7 @@ void RuleManager::getRulesReply(const QVariantMap ¶ms)
|
||||
qWarning() << "Error getting rules:" << params.value("error").toString();
|
||||
return;
|
||||
}
|
||||
qDebug() << "Get Rules reply" << params;
|
||||
// qDebug() << "Get Rules reply" << params;
|
||||
foreach (const QVariant &ruleDescriptionVariant, params.value("params").toMap().value("ruleDescriptions").toList()) {
|
||||
QUuid ruleId = ruleDescriptionVariant.toMap().value("id").toUuid();
|
||||
QString name = ruleDescriptionVariant.toMap().value("name").toString();
|
||||
@ -139,7 +139,7 @@ void RuleManager::getRuleDetailsReply(const QVariantMap ¶ms)
|
||||
qDebug() << "Got rule details for a rule we don't know";
|
||||
return;
|
||||
}
|
||||
qDebug() << "got rule details for rule" << ruleMap;
|
||||
// qDebug() << "got rule details for rule" << ruleMap;
|
||||
parseEventDescriptors(ruleMap.value("eventDescriptors").toList(), rule);
|
||||
parseRuleActions(ruleMap.value("actions").toList(), rule);
|
||||
parseRuleExitActions(ruleMap.value("exitActions").toList(), rule);
|
||||
|
||||
@ -8,13 +8,12 @@ GridView {
|
||||
id: interfacesGridView
|
||||
|
||||
property alias shownInterfaces: interfacesModel.shownInterfaces
|
||||
property int tilesPerRow: Math.ceil(Math.sqrt(interfacesGridView.count))
|
||||
|
||||
model: InterfacesModel {
|
||||
id: interfacesModel
|
||||
devices: Engine.deviceManager.devices
|
||||
}
|
||||
|
||||
property int tilesPerRow: Math.ceil(Math.sqrt(interfacesGridView.count))
|
||||
cellWidth: width / tilesPerRow
|
||||
cellHeight: height / tilesPerRow
|
||||
delegate: Item {
|
||||
|
||||
@ -21,7 +21,7 @@ Page {
|
||||
ColorIcon {
|
||||
height: app.iconSize
|
||||
width: height
|
||||
name: app.interfaceToIcon(model.interfaces[0])
|
||||
name: app.interfacesToIcon(model.interfaces)
|
||||
color: app.guhAccent
|
||||
}
|
||||
|
||||
|
||||
@ -48,6 +48,107 @@ Page {
|
||||
}
|
||||
}
|
||||
|
||||
InterfacesModel {
|
||||
id: page1Model
|
||||
devices: Engine.deviceManager.devices
|
||||
shownInterfaces: ["light", "weather", "sensor", "media", "garagegate"]
|
||||
property var view: null
|
||||
onCountChanged: buildView()
|
||||
}
|
||||
InterfacesModel {
|
||||
id: page2Model
|
||||
devices: Engine.deviceManager.devices
|
||||
shownInterfaces: ["gateway", "button", "notifications"]
|
||||
property var view: null
|
||||
onCountChanged: buildView()
|
||||
}
|
||||
|
||||
Component {
|
||||
id: devicePageComponent
|
||||
DevicesPage {
|
||||
width: swipeView.width
|
||||
height: swipeView.height
|
||||
visible: count > 0
|
||||
shownInterfaces: ["light", "weather", "sensor", "media", "garagegate"]
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: allDevicesComponent
|
||||
ListView {
|
||||
width: swipeView.width
|
||||
height: swipeView.height
|
||||
model: Engine.deviceManager.devices
|
||||
delegate: ItemDelegate {
|
||||
width: parent.width
|
||||
contentItem: RowLayout {
|
||||
spacing: app.margins
|
||||
ColorIcon {
|
||||
height: app.iconSize
|
||||
width: height
|
||||
name: app.interfacesToIcon(model.interfaces)
|
||||
color: app.guhAccent
|
||||
}
|
||||
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: model.name
|
||||
}
|
||||
}
|
||||
onClicked: {
|
||||
pageStack.push(Qt.resolvedUrl("devicepages/GenericDevicePage.qml"), {device: Engine.deviceManager.devices.get(index)})
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
anchors { left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter; margins: app.margins }
|
||||
spacing: app.margins
|
||||
visible: Engine.deviceManager.devices.count === 0
|
||||
Label {
|
||||
text: "Welcome to nymea!"
|
||||
font.pixelSize: app.largeFont
|
||||
Layout.fillWidth: true
|
||||
wrapMode: Text.WordWrap
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
color: app.guhAccent
|
||||
}
|
||||
Label {
|
||||
text: "There are no things set up yet. You can start with adding your things by using the menu on the upper left and selecting \"Add a new thing\"."
|
||||
Layout.fillWidth: true
|
||||
wrapMode: Text.WordWrap
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function buildView() {
|
||||
var shownViews = []
|
||||
if (page1Model.count > 0) {
|
||||
shownViews.push(0)
|
||||
}
|
||||
if (page2Model.count > 0) {
|
||||
shownViews.push(1)
|
||||
}
|
||||
shownViews.push(2)
|
||||
|
||||
if (swipeView.count === shownViews.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (swipeView.count > 0) {
|
||||
swipeView.removeItem(0)
|
||||
}
|
||||
if (shownViews.indexOf(0) >= 0) {
|
||||
swipeView.addItem(devicePageComponent.createObject(swipeView, {model: page1Model}))
|
||||
}
|
||||
if (shownViews.indexOf(1) >= 0) {
|
||||
swipeView.addItem(devicePageComponent.createObject(swipeView, {model: page2Model}))
|
||||
}
|
||||
swipeView.addItem(allDevicesComponent.createObject(swipeView))
|
||||
}
|
||||
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
|
||||
@ -57,44 +158,6 @@ Page {
|
||||
Layout.fillHeight: true
|
||||
currentIndex: pageIndicator.currentIndex
|
||||
clip: true
|
||||
|
||||
DevicesPage {
|
||||
width: parent.view.width
|
||||
height: parent.view.height
|
||||
shownInterfaces: ["light", "weather", "sensor", "media", "garagegate"]
|
||||
}
|
||||
|
||||
DevicesPage {
|
||||
width: parent.view.width
|
||||
height: parent.view.height
|
||||
shownInterfaces: ["gateway", "button", "notifications"]
|
||||
}
|
||||
|
||||
ListView {
|
||||
width: parent.view.width
|
||||
height: parent.view.height
|
||||
model: Engine.deviceManager.devices
|
||||
delegate: ItemDelegate {
|
||||
width: parent.width
|
||||
contentItem: RowLayout {
|
||||
spacing: app.margins
|
||||
ColorIcon {
|
||||
height: app.iconSize
|
||||
width: height
|
||||
name: app.interfaceToIcon(model.interfaces[0])
|
||||
color: app.guhAccent
|
||||
}
|
||||
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: model.name
|
||||
}
|
||||
}
|
||||
onClicked: {
|
||||
pageStack.push(Qt.resolvedUrl("devicepages/GenericDevicePage.qml"), {device: Engine.deviceManager.devices.get(index)})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PageIndicator {
|
||||
|
||||
@ -3,7 +3,7 @@ import QtQuick.Layouts 1.1
|
||||
import QtQuick.Controls 2.1
|
||||
import Mea 1.0
|
||||
import "components"
|
||||
import "paramdelegates"
|
||||
import "paramdelegates-ng"
|
||||
|
||||
Page {
|
||||
id: root
|
||||
@ -334,6 +334,7 @@ Page {
|
||||
var param = {}
|
||||
param.paramTypeId = paramRepeater.itemAt(i).paramType.id
|
||||
param.value = paramRepeater.itemAt(i).value
|
||||
print("adding param", param.paramTypeId, param.value)
|
||||
params.push(param)
|
||||
}
|
||||
|
||||
|
||||
17
mea/ui/images/select-none.svg
Normal file
17
mea/ui/images/select-none.svg
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg id="svg4874" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="96" viewBox="0 0 96 96.000001" width="96" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<metadata id="metadata4879">
|
||||
<rdf:RDF>
|
||||
<cc:Work rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
|
||||
<dc:title/>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g id="layer1" transform="translate(67.857 -78.505)">
|
||||
<rect id="rect4782" style="color:#000000;fill:none" transform="rotate(90)" height="96" width="96" y="-28.143" x="78.505"/>
|
||||
<path id="path4643" style="color-rendering:auto;text-decoration-color:#000000;color:#000000;font-variant-numeric:normal;shape-rendering:auto;solid-color:#000000;text-decoration-line:none;fill:#808080;font-variant-position:normal;mix-blend-mode:normal;block-progression:tb;font-feature-settings:normal;shape-padding:0;font-variant-alternates:normal;text-indent:0;font-variant-caps:normal;image-rendering:auto;white-space:normal;text-decoration-style:solid;font-variant-ligatures:none;isolation:auto;text-transform:none" d="m-43.869 86.504-0.01172 0.002c-5.0328 0.05818-8.7136-0.12027-11.725 1.541-1.5055 0.83064-2.6968 2.2356-3.3555 3.9902-0.65866 1.7547-0.89648 3.8364-0.89648 6.4668v56.002c0 2.6304 0.23782 4.7121 0.89648 6.4668 0.65866 1.7546 1.85 3.1596 3.3555 3.9902 3.011 1.6613 6.6918 1.4848 11.725 1.543h0.01172 48.023 0.011719c5.0328-0.0582 8.7136 0.11832 11.725-1.543 1.5055-0.83064 2.6968-2.2356 3.3555-3.9902 0.65866-1.7547 0.89648-3.8364 0.89648-6.4668v-56.002c0-2.6304-0.23782-4.7121-0.89648-6.4668-0.66-1.759-1.851-3.163-3.356-3.994-3.011-1.661-6.6922-1.483-11.725-1.541l-0.011719-0.002h-48.023zm0.01172 4h48c5.0383 0.05877 8.3519 0.23688 9.8164 1.0449 0.73364 0.40478 1.1527 0.85491 1.543 1.8945 0.39025 1.0396 0.64062 2.691 0.64062 5.0605v56.002c0 2.3696-0.25037 4.0209-0.64062 5.0606-0.39025 1.0396-0.80933 1.4898-1.543 1.8945-1.4645 0.80804-4.7782 0.98616-9.8164 1.0449h-47.977-0.02344c-5.0383-0.0588-8.3519-0.23688-9.8164-1.0449-0.73364-0.40478-1.1508-0.85491-1.541-1.8945-0.39025-1.0396-0.64258-2.691-0.64258-5.0606v-56.002c0-2.3696 0.25232-4.0209 0.64258-5.0605 0.39025-1.0396 0.80738-1.4898 1.541-1.8945 1.4645-0.80804 4.7782-0.98616 9.8164-1.0449z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.4 KiB |
@ -129,6 +129,16 @@ ApplicationWindow {
|
||||
}
|
||||
}
|
||||
|
||||
function interfacesToIcon(interfaces) {
|
||||
for (var i = 0; i < interfaces.length; i++) {
|
||||
var icon = interfaceToIcon(interfaces[i]);
|
||||
if (icon !== "") {
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
return Qt.resolvedUrl("images/select-none.svg")
|
||||
}
|
||||
|
||||
function interfaceToIcon(name) {
|
||||
switch (name) {
|
||||
case "light":
|
||||
@ -136,6 +146,8 @@ ApplicationWindow {
|
||||
case "dimmablelight":
|
||||
return Qt.resolvedUrl("images/torch-on.svg")
|
||||
case "sensor":
|
||||
case "temperaturesensor":
|
||||
case "humiditysensor":
|
||||
return Qt.resolvedUrl("images/sensors.svg")
|
||||
case "media":
|
||||
case "mediacontroller":
|
||||
@ -155,7 +167,10 @@ ApplicationWindow {
|
||||
return Qt.resolvedUrl("images/network-wired-symbolic.svg")
|
||||
case "notifications":
|
||||
return Qt.resolvedUrl("images/notification.svg")
|
||||
case "connectable":
|
||||
return Qt.resolvedUrl("images/stock_link.svg")
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function interfaceToColor(name) {
|
||||
|
||||
@ -36,7 +36,10 @@ ItemDelegate {
|
||||
case "bool":
|
||||
return boolComponent;
|
||||
case "int":
|
||||
return stringComponent;
|
||||
if (root.paramType.minimumValue !== undefined && root.paramType.maximumValue !== undefined) {
|
||||
return sliderComponent;
|
||||
}
|
||||
return textFieldComponent;
|
||||
case "string":
|
||||
case "qstring":
|
||||
if (root.paramType.allowedValues.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user