From f194bb1bc2866f0ca4aa1b9618cbbb937522134c Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 28 Sep 2018 23:54:45 +0200 Subject: [PATCH] improve lig view --- libnymea-app-core/models/logsmodel.cpp | 68 +++++- libnymea-app-core/models/logsmodel.h | 3 + .../ui/customviews/GenericTypeLogView.qml | 11 +- nymea-app/ui/devicepages/ButtonDevicePage.qml | 2 +- .../ui/devicepages/InputTriggerDevicePage.qml | 2 +- .../devicepages/NotificationsDevicePage.qml | 2 +- nymea-app/ui/devicepages/StateLogPage.qml | 2 +- nymea-app/ui/images/action-interface.svg | 86 +++---- nymea-app/ui/images/action.svg | 52 +++-- nymea-app/ui/images/event-interface.svg | 39 ++-- nymea-app/ui/images/event.svg | 52 ++--- nymea-app/ui/images/state-interface.svg | 46 ++-- nymea-app/ui/system/LogViewerPage.qml | 212 +++++++++--------- 13 files changed, 322 insertions(+), 255 deletions(-) diff --git a/libnymea-app-core/models/logsmodel.cpp b/libnymea-app-core/models/logsmodel.cpp index a67aa0fe..e70574fb 100644 --- a/libnymea-app-core/models/logsmodel.cpp +++ b/libnymea-app-core/models/logsmodel.cpp @@ -132,6 +132,9 @@ void LogsModel::notificationReceived(const QVariantMap &data) void LogsModel::update() { + if (m_busy) { + return; + } m_busy = true; emit busyChanged(); @@ -157,11 +160,40 @@ void LogsModel::update() Engine::instance()->jsonRpcClient()->sendCommand("Logging.GetLogEntries", params, this, "logsReply"); } +void LogsModel::fetchEarlier(int hours) +{ + if (m_busy) { + return; + } + m_busy = true; + emit busyChanged(); + + QVariantMap params; + if (!m_deviceId.isEmpty()) { + QVariantList deviceIds; + deviceIds.append(m_deviceId); + params.insert("deviceIds", deviceIds); + } + if (!m_typeIds.isEmpty()) { + QVariantList typeIds; + foreach (const QString &typeId, m_typeIds) { + typeIds.append(typeId); + } + params.insert("typeIds", typeIds); + } + QVariantList timeFilters; + QVariantMap timeFilter; + timeFilter.insert("endDate", m_startTime.toSecsSinceEpoch()); + m_startTime = m_startTime.addSecs(-60*60*hours); + timeFilter.insert("startDate", m_startTime.toSecsSinceEpoch()); + timeFilters.append(timeFilter); + params.insert("timeFilters", timeFilters); + Engine::instance()->jsonRpcClient()->sendCommand("Logging.GetLogEntries", params, this, "fetchEarlierReply"); +} + void LogsModel::logsReply(const QVariantMap &data) { qDebug() << "logs reply";// << data; - m_busy = false; - emit busyChanged(); beginResetModel(); qDeleteAll(m_list); m_list.clear(); @@ -183,6 +215,38 @@ void LogsModel::logsReply(const QVariantMap &data) endResetModel(); emit countChanged(); + + m_busy = false; + emit busyChanged(); +} + +void LogsModel::fetchEarlierReply(const QVariantMap &data) +{ + qDebug() << "logs reply";// << data; + + QList logEntries = data.value("params").toMap().value("logEntries").toList(); + QList newEntries; + foreach (const QVariant &logEntryVariant, logEntries) { + QVariantMap entryMap = logEntryVariant.toMap(); + QDateTime timeStamp = QDateTime::fromMSecsSinceEpoch(entryMap.value("timestamp").toLongLong()); + QString deviceId = entryMap.value("deviceId").toString(); + QString typeId = entryMap.value("typeId").toString(); + QMetaEnum sourceEnum = QMetaEnum::fromType(); + LogEntry::LoggingSource loggingSource = (LogEntry::LoggingSource)sourceEnum.keyToValue(entryMap.value("source").toByteArray()); + QMetaEnum loggingEventTypeEnum = QMetaEnum::fromType(); + LogEntry::LoggingEventType loggingEventType = (LogEntry::LoggingEventType)loggingEventTypeEnum.keyToValue(entryMap.value("eventType").toByteArray()); + QVariant value = loggingEventType == LogEntry::LoggingEventTypeActiveChange ? entryMap.value("active").toBool() : entryMap.value("value"); + LogEntry *entry = new LogEntry(timeStamp, value, deviceId, typeId, loggingSource, loggingEventType, this); + newEntries.append(entry); + } + beginInsertRows(QModelIndex(), 0, newEntries.count() - 1); + newEntries.append(m_list); + m_list = newEntries; + endInsertRows(); + emit countChanged(); + + m_busy = false; + emit busyChanged(); } void LogsModel::newLogEntryReceived(const QVariantMap &data) diff --git a/libnymea-app-core/models/logsmodel.h b/libnymea-app-core/models/logsmodel.h index 75691541..4bc211c6 100644 --- a/libnymea-app-core/models/logsmodel.h +++ b/libnymea-app-core/models/logsmodel.h @@ -64,9 +64,12 @@ signals: public slots: virtual void update(); + virtual void fetchEarlier(int hours); +// virtual void fetchLater(int hours); private slots: virtual void logsReply(const QVariantMap &data); + virtual void fetchEarlierReply(const QVariantMap &data); void newLogEntryReceived(const QVariantMap &data); protected: diff --git a/nymea-app/ui/customviews/GenericTypeLogView.qml b/nymea-app/ui/customviews/GenericTypeLogView.qml index 351dc66e..7b126ab8 100644 --- a/nymea-app/ui/customviews/GenericTypeLogView.qml +++ b/nymea-app/ui/customviews/GenericTypeLogView.qml @@ -23,7 +23,7 @@ Item { Layout.fillWidth: true Layout.margins: app.margins wrapMode: Text.WordWrap - text: root.text.arg(logsModel.count) + text: root.text.arg(logsModel.count).arg((logsModel.endTime.getTime() - logsModel.startTime.getTime())/ 1000 / 60 / 60 /24) } ThinDivider {} @@ -40,7 +40,14 @@ Item { Layout.fillHeight: true model: logsModel clip: true - onCountChanged: positionViewAtEnd() +// onCountChanged: positionViewAtEnd() + + onContentYChanged: { + if (!logsModel.busy && contentY - originY < 5 * height) { + logsModel.fetchEarlier(24) + } + } + delegate: SwipeDelegate { id: logEntryDelegate width: parent.width diff --git a/nymea-app/ui/devicepages/ButtonDevicePage.qml b/nymea-app/ui/devicepages/ButtonDevicePage.qml index 43f89875..78f77b4f 100644 --- a/nymea-app/ui/devicepages/ButtonDevicePage.qml +++ b/nymea-app/ui/devicepages/ButtonDevicePage.qml @@ -11,7 +11,7 @@ GenericDevicePage { GenericTypeLogView { anchors.fill: parent - text: qsTr("This button has been pressed %1 times in the last 24 hours.") + text: qsTr("This button has been pressed %1 times in the last %2 days.") logsModel: LogsModel { deviceId: root.device.id diff --git a/nymea-app/ui/devicepages/InputTriggerDevicePage.qml b/nymea-app/ui/devicepages/InputTriggerDevicePage.qml index 2cc98680..2babd6a0 100644 --- a/nymea-app/ui/devicepages/InputTriggerDevicePage.qml +++ b/nymea-app/ui/devicepages/InputTriggerDevicePage.qml @@ -10,7 +10,7 @@ GenericDevicePage { GenericTypeLogView { anchors.fill: parent - text: qsTr("This event has appeared %1 times in the last 24 hours.") + text: qsTr("This event has appeared %1 times in the last %2 days.") logsModel: LogsModel { deviceId: root.device.id diff --git a/nymea-app/ui/devicepages/NotificationsDevicePage.qml b/nymea-app/ui/devicepages/NotificationsDevicePage.qml index 9bc41041..fdbc7384 100644 --- a/nymea-app/ui/devicepages/NotificationsDevicePage.qml +++ b/nymea-app/ui/devicepages/NotificationsDevicePage.qml @@ -74,7 +74,7 @@ DevicePageBase { GenericTypeLogView { Layout.fillHeight: true Layout.fillWidth: true - text: qsTr("%1 notifications sent to this device in the last 24 hours.") + text: qsTr("%1 notifications sent to this device in the last %2 days.") logsModel: LogsModel { deviceId: root.device.id diff --git a/nymea-app/ui/devicepages/StateLogPage.qml b/nymea-app/ui/devicepages/StateLogPage.qml index 08dc3073..52b01bc7 100644 --- a/nymea-app/ui/devicepages/StateLogPage.qml +++ b/nymea-app/ui/devicepages/StateLogPage.qml @@ -72,7 +72,7 @@ Page { id: logView width: swipeView.width height: swipeView.height - text: qsTr("%1, %2 has changed %3 times in the last 24h").arg(device.name).arg(stateType.displayName) + text: qsTr("%1, %2 has changed %3 times in the last %4 days").arg(device.name).arg(stateType.displayName) logsModel: logsModel diff --git a/nymea-app/ui/images/action-interface.svg b/nymea-app/ui/images/action-interface.svg index 80407d8a..51dbfc2c 100644 --- a/nymea-app/ui/images/action-interface.svg +++ b/nymea-app/ui/images/action-interface.svg @@ -25,12 +25,12 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="14.049998" - inkscape:cx="69.993806" - inkscape:cy="44.483695" + inkscape:zoom="4.9674244" + inkscape:cx="-23.781836" + inkscape:cy="-1.5772636" inkscape:document-units="px" inkscape:current-layer="layer1" - showgrid="true" + showgrid="false" showborder="true" fit-margin-top="0" fit-margin-left="0" @@ -151,59 +151,41 @@ width="96" id="rect4782-637" style="color:#000000;display:inline;overflow:visible;visibility:visible;fill:none;stroke:none;stroke-width:3.99999976;marker:none;enable-background:accumulate" /> - + + + + - - - - - - - - - + id="path836" + d="m -45.337483,101.05663 c 10.294337,-10.288755 25.790399,-13.370805 39.240222,-7.802725 13.44979,5.56807 22.23047,18.700765 22.23047,33.251945 0,14.55118 -8.78068,27.68194 -22.23047,33.25002 -13.449823,5.56804 -28.945885,2.48602 -39.240222,-7.80276 l 2.828107,-2.82811 c 9.158173,9.15322 22.916636,11.88745 34.882805,6.93358 11.96618,-4.95383 19.75979,-16.60879 19.75979,-29.55273 0,-12.94393 -7.79361,-24.60083 -19.75979,-29.554705 -11.966169,-4.95382 -25.724632,-2.2196 -34.882805,6.933635 z" + style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:none;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#808080;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3.99999976;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" /> + + diff --git a/nymea-app/ui/images/action.svg b/nymea-app/ui/images/action.svg index 025a1207..032d268a 100644 --- a/nymea-app/ui/images/action.svg +++ b/nymea-app/ui/images/action.svg @@ -15,7 +15,7 @@ version="1.1" inkscape:version="0.92.3 (2405546, 2018-03-11)" viewBox="0 0 96 96.000001" - sodipodi:docname="action.svg"> + sodipodi:docname="event.svg"> image/svg+xml - + @@ -151,22 +151,30 @@ width="96" id="rect4782-637" style="color:#000000;display:inline;overflow:visible;visibility:visible;fill:none;stroke:none;stroke-width:3.99999976;marker:none;enable-background:accumulate" /> - - - + + + + + + + diff --git a/nymea-app/ui/images/event-interface.svg b/nymea-app/ui/images/event-interface.svg index 368b3da5..914503cf 100644 --- a/nymea-app/ui/images/event-interface.svg +++ b/nymea-app/ui/images/event-interface.svg @@ -25,9 +25,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="7.024999" - inkscape:cx="70.049325" - inkscape:cy="25.941564" + inkscape:zoom="2.4837122" + inkscape:cx="99.639249" + inkscape:cy="-59.079403" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -134,7 +134,7 @@ image/svg+xml - + @@ -151,27 +151,32 @@ width="96" id="rect4782-637" style="color:#000000;display:inline;overflow:visible;visibility:visible;fill:none;stroke:none;stroke-width:3.99999976;marker:none;enable-background:accumulate" /> + + id="path5837" + d="m 5.1430854,114.50443 0.0076,24 c 3.6500406,-1.66873 7.3659206,-3.53593 11.1491896,-5.59872 3.747742,-2.06778 7.362822,-4.2005 10.84286,-6.40026 -3.480038,-2.15576 -7.095118,-4.26806 -10.84286,-6.33584 -3.785348,-2.06393 -7.503345,-3.95188 -11.1553126,-5.66518 z" + style="color:#000000;display:inline;overflow:visible;visibility:visible;opacity:1;fill:#808080;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.99940658;marker:none;enable-background:accumulate" /> + id="path830" + d="M 1.6230724,109.05661 C -8.6712646,98.767855 -24.167327,95.685805 -37.61715,101.25388 c -13.44979,5.56808 -22.23047,18.70077 -22.23047,33.25195 0,14.55118 8.78068,27.68194 22.23047,33.25002 13.449823,5.56804 28.9458854,2.48602 39.2402224,-7.80276 l -2.828107,-2.82811 c -9.1581734,9.15322 -22.9166364,11.88745 -34.8828054,6.93358 -11.96618,-4.95383 -19.75979,-16.60879 -19.75979,-29.55273 0,-12.94393 7.79361,-24.60083 19.75979,-29.5547 11.966169,-4.953825 25.724632,-2.2196 34.8828054,6.93363 z" + style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:none;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#808080;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3.99999976;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" /> + inkscape:connector-curvature="0" + id="path832" + d="M 9.6230724,93.05661 C -0.6712646,82.767855 -16.167327,79.685805 -29.61715,85.253885 c -13.44979,5.56807 -22.23047,18.700765 -22.23047,33.251945 0,14.55118 8.78068,27.68194 22.23047,33.25002 13.449823,5.56804 28.9458854,2.48602 39.2402224,-7.80276 l -2.828107,-2.82811 c -9.1581734,9.15322 -22.9166364,11.88745 -34.8828054,6.93358 -11.96618,-4.95383 -19.75979,-16.60879 -19.75979,-29.55273 0,-12.94393 7.79361,-24.60083 19.75979,-29.554705 11.966169,-4.95382 25.724632,-2.2196 34.8828054,6.933635 z" + style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:none;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#808080;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3.99999976;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" /> diff --git a/nymea-app/ui/images/event.svg b/nymea-app/ui/images/event.svg index 032d268a..025a1207 100644 --- a/nymea-app/ui/images/event.svg +++ b/nymea-app/ui/images/event.svg @@ -15,7 +15,7 @@ version="1.1" inkscape:version="0.92.3 (2405546, 2018-03-11)" viewBox="0 0 96 96.000001" - sodipodi:docname="event.svg"> + sodipodi:docname="action.svg"> image/svg+xml - + @@ -151,30 +151,22 @@ width="96" id="rect4782-637" style="color:#000000;display:inline;overflow:visible;visibility:visible;fill:none;stroke:none;stroke-width:3.99999976;marker:none;enable-background:accumulate" /> - - - - - - - + + + diff --git a/nymea-app/ui/images/state-interface.svg b/nymea-app/ui/images/state-interface.svg index 6d046a74..a3346ba4 100644 --- a/nymea-app/ui/images/state-interface.svg +++ b/nymea-app/ui/images/state-interface.svg @@ -17,7 +17,7 @@ sodipodi:docname="state-interface.svg" inkscape:version="0.92.3 (2405546, 2018-03-11)"> + id="defs11" /> + id="grid818" /> @@ -65,27 +65,29 @@ + d="m 29.988,19.999 -0.01134,0.002 c -5.0328,0.0582 -8.7136,-0.12019 -11.725,1.541 -1.5055,0.83062 -2.6968,2.2356 -3.3555,3.9902 -0.65866,1.7546 -0.89647,3.8364 -0.89647,6.4668 v 44.002 c 0,2.6304 0.23773,4.7122 0.89647,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.543 h 0.01134 36.023 0.01134 c 5.0328,-0.0582 8.7136,0.1183 11.725,-1.543 1.5055,-0.83066 2.6968,-2.2356 3.3555,-3.9902 0.65866,-1.7546 0.8965,-3.8364 0.8965,-6.4668 V 31.999 c 0,-2.6304 -0.23773,-4.7122 -0.8965,-6.4668 -0.65866,-1.7547 -1.85,-3.1596 -3.3555,-3.9902 -3.011,-1.6613 -6.6918,-1.4829 -11.725,-1.5411 l -0.01134,-0.002 -8.012,0.002 v 4 l 7.977,-0.002 c 5.0542,0.0586 8.3726,0.23547 9.8398,1.0449 0.73364,0.40479 1.1527,0.85493 1.543,1.8945 0.39024,1.0396 0.64059,2.691 0.64059,5.0606 v 44.002 c 0,2.3695 -0.2502,4.0209 -0.64059,5.0605 -0.39027,1.0396 -0.80935,1.4898 -1.543,1.8945 -1.4645,0.80806 -4.7782,0.98615 -9.8164,1.0449 h -35.977 -0.02268 c -5.0383,-0.059 -8.3519,-0.23697 -9.8164,-1.0449 -0.73364,-0.40475 -1.1508,-0.85489 -1.541,-1.8945 -0.39027,-1.0396 -0.6426,-2.691 -0.6426,-5.0605 v -44.002 c 0,-2.3696 0.25247,-4.0209 0.6426,-5.0606 0.39024,-1.0396 0.80734,-1.4897 1.541,-1.8945 1.4645,-0.80807 4.7782,-0.98616 9.8164,-1.0449 l 8,0.002 v -4 z" + id="path4643-2" + sodipodi:nodetypes="ccccssccccccccsscccccccccsscccccccsscccccc" /> + - - + diff --git a/nymea-app/ui/system/LogViewerPage.qml b/nymea-app/ui/system/LogViewerPage.qml index ca40bb54..1db58277 100644 --- a/nymea-app/ui/system/LogViewerPage.qml +++ b/nymea-app/ui/system/LogViewerPage.qml @@ -14,7 +14,10 @@ Page { HeaderButton { imageSource: "../images/go-down.svg" color: root.autoScroll ? app.accentColor : keyColor - onClicked: root.autoScroll = !root.autoScroll + onClicked: { + listView.positionViewAtEnd(); + root.autoScroll = !root.autoScroll + } } } @@ -24,7 +27,7 @@ Page { id: logsModel startTime: { var date = new Date(); - date.setHours(new Date().getHours() - 1); + date.setHours(new Date().getHours() - 2); return date; } endTime: new Date() @@ -49,117 +52,118 @@ Page { clip: true headerPositioning: ListView.OverlayHeader - property int column0Width: root.width / 10 * 2 - property int column1Width: root.width / 10 * 1 - property int column2Width: root.width / 10 * 3 - property int column3Width: root.width / 10 * 3 - property int column4Width: root.width / 10 * 1 - - header: Rectangle { - width: parent.width - height: app.margins * 3 - color: Material.primary - z: 2 - - Row { - width: parent.width - anchors.verticalCenter: parent.verticalCenter - Label { - width: listView.column0Width - text: qsTr("Time") - } - Label { - text: qsTr("Type") - width: listView.column1Width - } - - Label { - width: listView.column2Width - text: qsTr("Thing") - } - Label { - width: listView.column3Width - text: qsTr("Object") - } - Label { - width: listView.column4Width - text: qsTr("Value") - } - } - ThinDivider { - anchors { left: parent.left; bottom: parent.bottom; right: parent.right } + onDraggingChanged: { + if (dragging) { + root.autoScroll = false; } } - delegate: Row { + ScrollBar.vertical: ScrollBar {} + + onContentYChanged: { + if (!logsModel.busy && contentY - originY < 5 * height) { + logsModel.fetchEarlier(1) + } + } + + delegate: ItemDelegate { id: delegate + width: parent.width property var device: Engine.deviceManager.devices.getDevice(model.deviceId) property var deviceClass: device ? Engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null - Label { - width: listView.column0Width - text: width > 130 ? Qt.formatDateTime(model.timestamp,"dd.MM.yy - hh:mm:ss") : Qt.formatDateTime(model.timestamp,"hh:mm:ss") - elide: Text.ElideRight - } - Label { - width: listView.column1Width - text: { - switch (model.source) { - case LogEntry.LoggingSourceStates: - return "SC"; - case LogEntry.LoggingSourceSystem: - return "SYS"; - case LogEntry.LoggingSourceActions: - return "AE"; - case LogEntry.LoggingSourceEvents: - return "E"; - case LogEntry.LoggingSourceRules: - return "R"; + leftPadding: 0 + rightPadding: 0 + topPadding: 0 + bottomPadding: 0 + contentItem: RowLayout { + id: contentColumn + anchors { left: parent.left; right: parent.right; margins: app.margins / 2 } + ColorIcon { + Layout.preferredWidth: app.iconSize + Layout.preferredHeight: width + Layout.alignment: Qt.AlignVCenter + color: { + switch (model.source) { + case LogEntry.LoggingSourceStates: + case LogEntry.LoggingSourceSystem: + case LogEntry.LoggingSourceActions: + case LogEntry.LoggingSourceEvents: + return app.accentColor + case LogEntry.LoggingSourceRules: + if (model.loggingEventType === LogEntry.LoggingEventTypeActiveChange) { + return model.value === true ? "green" : keyColor + } + return app.accentColor + } } - -// switch (model.loggingEventType) { -// case LogEntry.LoggingEventTypeTrigger: -// return "T"; -// case LogEntry.LoggingEventTypeExitActionsExecuted: -// return "A"; -// case LogEntry.LoggingEventTypeActiveChange: -// return "R"; -// case LogEntry.LoggingEventTypeExitActionsExecuted: -// return "EA"; -// case LogEntry.LoggingEventTypeEnabledChange: -// return "E"; -// } - return "N/A"; - } - } - - Label { - width: listView.column2Width - text: model.source === LogEntry.LoggingSourceSystem ? qsTr("%1 Server").arg(app.systemName) : delegate.device.name - elide: Text.ElideRight - } - Label { - width: listView.column3Width - text : { - switch (model.source) { - case LogEntry.LoggingSourceStates: - return delegate.deviceClass.stateTypes.getStateType(model.typeId).displayName; - case LogEntry.LoggingSourceSystem: - return model.loggingEventType === LogEntry.LoggingEventTypeActiveChange ? qsTr("Active changed") : "FIXME" - case LogEntry.LoggingSourceActions: - return delegate.deviceClass.actionTypes.getActionType(model.typeId).displayName; - case LogEntry.LoggingSourceEvents: - return delegate.deviceClass.eventTypes.getEventType(model.typeId).displayName; - case LogEntry.LoggingSourceRules: - return Engine.ruleManager.rules.getRule(model.typeId).name; + name: { + switch (model.source) { + case LogEntry.LoggingSourceStates: + return "../images/state.svg" + case LogEntry.LoggingSourceSystem: + return "../images/system-shutdown.svg" + case LogEntry.LoggingSourceActions: + return "../images/action.svg" + case LogEntry.LoggingSourceEvents: + return "../images/event.svg" + case LogEntry.LoggingSourceRules: + return "../images/magic.svg" + } + } + } + ColumnLayout { + RowLayout { + Label { + Layout.fillWidth: true + text: model.source === LogEntry.LoggingSourceSystem ? + qsTr("%1 Server").arg(app.systemName) + : model.source === LogEntry.LoggingSourceRules ? + Engine.ruleManager.rules.getRule(model.typeId).name + : delegate.device.name + elide: Text.ElideRight + } + Label { + text: Qt.formatDateTime(model.timestamp,"dd.MM.yy - hh:mm:ss") + elide: Text.ElideRight + font.pixelSize: app.smallFont + } + } + Label { + text : { + switch (model.source) { + case LogEntry.LoggingSourceStates: + return "%1 -> %2".arg(delegate.deviceClass.stateTypes.getStateType(model.typeId).displayName).arg(model.value); + case LogEntry.LoggingSourceSystem: + return model.loggingEventType === LogEntry.LoggingEventTypeActiveChange ? qsTr("System started") : "N/A" + case LogEntry.LoggingSourceActions: + return "%1 (%2)".arg(delegate.deviceClass.actionTypes.getActionType(model.typeId).displayName).arg(model.value); + case LogEntry.LoggingSourceEvents: + return "%1 (%2)".arg(delegate.deviceClass.eventTypes.getEventType(model.typeId).displayName).arg(model.value); + case LogEntry.LoggingSourceRules: + switch (model.loggingEventType) { + case LogEntry.LoggingEventTypeTrigger: + return qsTr("Rule triggered"); + case LogEntry.LoggingEventTypeActionsExecuted: + return qsTr("Actions executed"); + case LogEntry.LoggingEventTypeActiveChange: + return model.value === true ? qsTr("Rule active") : qsTr("Rule inactive") + case LogEntry.LoggingEventTypeExitActionsExecuted: + return qsTr("Exit actions executed"); + case LogEntry.LoggingEventTypeEnabledChange: + return qsTr("Enabled changed"); + default: + print("Unhandled logging event type", model.loggingEventType) + } + return "N/A" + default: + print("unhandled logging source:", model.source) + } + return "N/A"; + } + elide: Text.ElideRight + font.pixelSize: app.smallFont } - return "N/A"; } - elide: Text.ElideRight - } - Label { - width: listView.column4Width - text: model.value - elide: Text.ElideRight } } }