Warning, /pim/kube/views/log/qml/View.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * Copyright (C) 2017 Michael Bohlender, <michael.bohlender@kdemail.net>
0003 * Copyright (C) 2017 Christian Mollekopf, <mollekopf@kolabsys.com>
0004 *
0005 * This program is free software; you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation; either version 2 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License along
0016 * with this program; if not, write to the Free Software Foundation, Inc.,
0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018 */
0019
0020 import QtQuick 2.4
0021 import QtQuick.Layouts 1.1
0022 import QtQuick.Controls 1.3 as Controls1
0023 import QtQuick.Controls 2
0024 import org.kube.framework 1.0 as Kube
0025
0026 Controls1.SplitView {
0027 id: root
0028
0029 property bool pendingError: false;
0030 property bool pendingNotification: false;
0031 onPendingErrorChanged: {
0032 Kube.Fabric.postMessage(Kube.Messages.errorPending, {errorPending: pendingError})
0033 }
0034 onPendingNotificationChanged: {
0035 Kube.Fabric.postMessage(Kube.Messages.notificationPending, {notificationPending: pendingNotification})
0036 }
0037
0038 StackView.onActivated: {
0039 root.pendingError = false;
0040 root.pendingNotification = false;
0041 //Always select the latest notification
0042 listView.currentIndex = 0
0043 }
0044
0045 Item {
0046 id: accountList
0047 width: parent.width/3
0048 Layout.fillHeight: true
0049
0050 Kube.Listener {
0051 filter: Kube.Messages.notification
0052 onMessageReceived: {
0053 //Ignore noise that we can't usefully render anyways
0054 if (!message.message) {
0055 return
0056 }
0057 //Avoid highlighting the iconbutton again if we're already looking at this view.
0058 if (root.StackView.status != StackView.Active) {
0059 if (message.type == Kube.Notifications.error) {
0060 root.pendingError = true
0061 }
0062 root.pendingNotification = true
0063 }
0064 logModel.insert(message)
0065 }
0066 }
0067
0068 Kube.Label {
0069 anchors.centerIn: parent
0070 visible: listView.count == 0
0071 text: qsTr("Nothing here...")
0072 }
0073
0074 Kube.ListView {
0075 id: listView
0076 anchors {
0077 fill: parent
0078 }
0079
0080 clip: true
0081
0082 model: Kube.LogModel {
0083 id: logModel
0084 objectName: "logModel"
0085 onEntryAdded: {
0086 Kube.Fabric.postMessage(Kube.Messages.displayNotification, message)
0087 }
0088 }
0089
0090 onCurrentItemChanged: {
0091 if (!!currentItem.currentData.resource) {
0092 details.resourceId = currentItem.currentData.resource
0093 }
0094 details.message = currentItem.currentData.message + "\n" + currentItem.currentData.details
0095 details.timestamp = currentItem.currentData.timestamp
0096 details.entities = currentItem.currentData.entities
0097 if (!!currentItem.currentData.subtype) {
0098 details.subtype = currentItem.currentData.subtype
0099 } else {
0100 details.subtype = ""
0101 }
0102 }
0103
0104 delegate: Kube.ListDelegate {
0105 id: delegateRoot
0106 border.color: Kube.Colors.buttonColor
0107 border.width: 1
0108 Kube.Label {
0109 id: description
0110 anchors {
0111 top: parent.top
0112 topMargin: Kube.Units.smallSpacing
0113 left: parent.left
0114 leftMargin: Kube.Units.largeSpacing
0115 }
0116 height: Kube.Units.gridUnit
0117 width: parent.width - Kube.Units.largeSpacing * 2
0118 text: model.type == Kube.Notifications.error ? qsTr("Error") : qsTr("Info")
0119 }
0120
0121 Kube.Label {
0122 id: message
0123 anchors {
0124 topMargin: Kube.Units.smallSpacing
0125 top: description.bottom
0126 left: parent.left
0127 leftMargin: Kube.Units.largeSpacing
0128 }
0129 height: Kube.Units.gridUnit
0130 width: parent.width - Kube.Units.largeSpacing * 2
0131 maximumLineCount: 1
0132 elide: Text.ElideRight
0133 color: delegateRoot.disabledTextColor
0134 text: model.message
0135 }
0136
0137 Kube.Label {
0138 id: date
0139
0140 anchors {
0141 right: parent.right
0142 bottom: parent.bottom
0143 rightMargin: Kube.Units.smallSpacing
0144 }
0145 text: Qt.formatDateTime(model.timestamp, " hh:mm:ss dd MMM yyyy")
0146 font.italic: true
0147 color: delegateRoot.disabledTextColor
0148 font.pointSize: Kube.Units.smallFontSize
0149 }
0150 }
0151 }
0152 }
0153 Item {
0154 id: details
0155 property string subtype: ""
0156 property date timestamp
0157 property string message: ""
0158 property string resourceId: ""
0159 property var entities: []
0160
0161 Kube.ModelIndexRetriever {
0162 id: retriever
0163 model: Kube.AccountsModel {
0164 resourceId: details.resourceId
0165 }
0166 }
0167
0168 Loader {
0169 id: detailsLoader
0170 visible: message != ""
0171 clip: true
0172 anchors {
0173 fill: parent
0174 margins: Kube.Units.largeSpacing
0175 }
0176 property date timestamp: details.timestamp
0177 property string message: details.message
0178 property string resourceId: details.resourceId
0179 property string accountId: retriever.currentData ? retriever.currentData.accountId : ""
0180 property string accountName: retriever.currentData ? retriever.currentData.name : ""
0181 property string entityId: (details.entities && details.entities.length != 0) ? details.entities[0] : ""
0182
0183 function getComponent(subtype) {
0184 if (subtype == Kube.Notifications.loginError) {
0185 return loginErrorComponent
0186 }
0187 if (subtype == Kube.Notifications.hostNotFoundError) {
0188 return hostNotFoundErrorComponent
0189 }
0190 if (subtype == Kube.Notifications.connectionError) {
0191 return hostNotFoundErrorComponent
0192 }
0193 if (subtype == Kube.Notifications.transmissionError) {
0194 return transmissionErrorComponent
0195 }
0196 if (subtype == Kube.Notifications.messageSent) {
0197 return transmissionSuccessComponent
0198 }
0199 return detailsComponent
0200 }
0201
0202 sourceComponent: getComponent(details.subtype)
0203 }
0204 }
0205
0206 Component {
0207 id: detailsComponent
0208 Rectangle {
0209 color: Kube.Colors.viewBackgroundColor
0210 GridLayout {
0211 id: gridLayout
0212 Layout.minimumWidth: 0
0213 anchors {
0214 top: parent.top
0215 left: parent.left
0216 right: parent.right
0217 }
0218 columns: 2
0219 Kube.Label {
0220 text: qsTr("Account:")
0221 visible: accountName
0222 }
0223 Kube.Label {
0224 Layout.fillWidth: true
0225 text: accountName
0226 visible: accountName
0227 elide: Text.ElideRight
0228 }
0229 Kube.Label {
0230 text: qsTr("Account Id:")
0231 visible: accountId
0232 }
0233 Kube.Label {
0234 text: accountId
0235 visible: accountId
0236 Layout.fillWidth: true
0237 elide: Text.ElideRight
0238 }
0239 Kube.Label {
0240 text: qsTr("Resource Id:")
0241 visible: resourceId
0242 }
0243 Kube.Label {
0244 text: resourceId
0245 visible: resourceId
0246 Layout.fillWidth: true
0247 elide: Text.ElideRight
0248 }
0249 Kube.Label {
0250 text: qsTr("Timestamp:")
0251 }
0252 Kube.Label {
0253 text: Qt.formatDateTime(timestamp, " hh:mm:ss dd MMM yyyy")
0254 Layout.fillWidth: true
0255 elide: Text.ElideRight
0256 }
0257 Kube.Label {
0258 text: qsTr("Message:")
0259 Layout.alignment: Qt.AlignTop
0260 }
0261 Kube.Label {
0262 text: message
0263 Layout.fillWidth: true
0264 wrapMode: Text.Wrap
0265 }
0266 Item {
0267 Layout.columnSpan: 2
0268 Layout.fillHeight: true
0269 Layout.fillWidth: true
0270 }
0271 }
0272
0273 Kube.SelectableItem {
0274 layout: gridLayout
0275 }
0276 }
0277 }
0278
0279 Component {
0280 id: loginErrorComponent
0281 Item {
0282 Column {
0283 anchors {
0284 top: parent.top
0285 left: parent.left
0286 right: parent.right
0287 }
0288 spacing: Kube.Units.largeSpacing
0289 Column {
0290 Kube.Heading {
0291 id: heading
0292 text: qsTr("Failed to login")
0293 color: Kube.Colors.warningColor
0294 }
0295
0296 Kube.Label {
0297 id: subHeadline
0298 text: qsTr("%1: please check your credentials.").arg(accountName)
0299 color: Kube.Colors.disabledTextColor
0300 wrapMode: Text.Wrap
0301 }
0302 }
0303 Kube.Button {
0304 text: qsTr("Change Password")
0305 onClicked: {
0306 Kube.Fabric.postMessage(Kube.Messages.componentDone, {})
0307 Kube.Fabric.postMessage(Kube.Messages.requestLogin, {accountId: accountId})
0308 }
0309 }
0310 }
0311 }
0312 }
0313
0314 Component {
0315 id: hostNotFoundErrorComponent
0316 Item {
0317 Column {
0318 anchors {
0319 top: parent.top
0320 left: parent.left
0321 right: parent.right
0322 }
0323 spacing: Kube.Units.largeSpacing
0324 Column {
0325 Kube.Heading {
0326 id: heading
0327 text: qsTr("Host not found")
0328 color: Kube.Colors.warningColor
0329 }
0330
0331 Kube.Label {
0332 id: subHeadline
0333 text: qsTr("%1: please check your network connection and settings.").arg(accountName)
0334 color: Kube.Colors.disabledTextColor
0335 wrapMode: Text.Wrap
0336 }
0337 }
0338 Kube.Button {
0339 text: qsTr("Account Settings")
0340 onClicked: {
0341 Kube.Fabric.postMessage(Kube.Messages.componentDone, {})
0342 Kube.Fabric.postMessage(Kube.Messages.requestAccountsConfiguration, {})
0343 }
0344 }
0345 }
0346 }
0347 }
0348
0349 Component {
0350 id: transmissionErrorComponent
0351 Item {
0352 id: componentRoot
0353 Column {
0354 anchors {
0355 top: parent.top
0356 left: parent.left
0357 right: parent.right
0358 }
0359 spacing: Kube.Units.largeSpacing
0360
0361 Kube.Heading {
0362 id: heading
0363 text: qsTr("Failed to send the message.")
0364 color: Kube.Colors.warningColor
0365 }
0366
0367 Column {
0368 spacing: Kube.Units.largeSpacing
0369
0370 Repeater {
0371 model: Kube.MailListModel {
0372 filter: {
0373 "entityId": componentRoot.parent ? componentRoot.parent.entityId : null,
0374 "headersOnly": true,
0375 "fetchMails": true
0376 }
0377 }
0378 delegate: Column {
0379 id: subHeadline
0380
0381 Kube.Label {
0382 text: qsTr("Account: %1").arg(accountName)
0383 color: Kube.Colors.disabledTextColor
0384 wrapMode: Text.Wrap
0385 }
0386 Kube.Label {
0387 text: qsTr("Subject: %1").arg(model.subject)
0388 color: Kube.Colors.disabledTextColor
0389 wrapMode: Text.Wrap
0390 }
0391 Kube.Label {
0392 text: qsTr("To: %1").arg(model.to)
0393 color: Kube.Colors.disabledTextColor
0394 wrapMode: Text.Wrap
0395 }
0396 Kube.Label {
0397 visible: !!model.cc
0398 text: qsTr("Cc: %1").arg(model.cc)
0399 color: Kube.Colors.disabledTextColor
0400 wrapMode: Text.Wrap
0401 }
0402
0403 }
0404 }
0405 }
0406
0407 Kube.Button {
0408 text: qsTr("Try Again")
0409 onClicked: {
0410 Kube.Fabric.postMessage(Kube.Messages.sendOutbox, {})
0411 }
0412 }
0413 }
0414 }
0415 }
0416
0417 Component {
0418 id: transmissionSuccessComponent
0419 Item {
0420 id: componentRoot
0421 Column {
0422 anchors {
0423 top: parent.top
0424 left: parent.left
0425 right: parent.right
0426 }
0427 spacing: Kube.Units.largeSpacing
0428
0429 Kube.Heading {
0430 id: heading
0431 text: qsTr("Succeeded to send the message.")
0432 }
0433
0434 Column {
0435 spacing: Kube.Units.largeSpacing
0436
0437 Repeater {
0438 model: Kube.MailListModel {
0439 filter: {
0440 "entityId": componentRoot.parent ? componentRoot.parent.entityId : null,
0441 "headersOnly": true,
0442 "fetchMails": true
0443 }
0444 }
0445 delegate: Column {
0446 id: subHeadline
0447
0448 Kube.Label {
0449 text: qsTr("Account: %1").arg(accountName)
0450 color: Kube.Colors.disabledTextColor
0451 wrapMode: Text.Wrap
0452 }
0453 Kube.Label {
0454 text: qsTr("Subject: %1").arg(model.subject)
0455 color: Kube.Colors.disabledTextColor
0456 wrapMode: Text.Wrap
0457 }
0458 Kube.Label {
0459 text: qsTr("To: %1").arg(model.to)
0460 color: Kube.Colors.disabledTextColor
0461 wrapMode: Text.Wrap
0462 }
0463 Kube.Label {
0464 visible: !!model.cc
0465 text: qsTr("Cc: %1").arg(model.cc)
0466 color: Kube.Colors.disabledTextColor
0467 wrapMode: Text.Wrap
0468 }
0469 }
0470 }
0471 }
0472 }
0473 }
0474 }
0475
0476 }