2016-09-27 08:05:14 -04:00
|
|
|
/*
|
|
|
|
* RetroShare Android QML App
|
2018-02-01 08:22:33 -05:00
|
|
|
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
|
2016-09-27 08:05:14 -04:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-04-13 10:47:27 -04:00
|
|
|
import QtQuick 2.7
|
2017-03-24 07:02:13 -04:00
|
|
|
import QtQuick.Controls 2.0
|
2016-10-26 14:37:28 -04:00
|
|
|
import "jsonpath.js" as JSONPath
|
2017-04-11 09:48:16 -04:00
|
|
|
import "." //Needed for TokensManager singleton
|
2017-07-22 13:11:56 -04:00
|
|
|
import "components/."
|
2016-09-27 08:05:14 -04:00
|
|
|
|
|
|
|
Item
|
|
|
|
{
|
2017-03-17 12:22:58 -04:00
|
|
|
id: trustedNodesView
|
2017-04-03 15:35:42 -04:00
|
|
|
property int token: 0
|
2017-03-17 12:22:58 -04:00
|
|
|
|
2017-04-03 15:35:42 -04:00
|
|
|
Component.onCompleted: refreshData()
|
2018-02-01 08:22:33 -05:00
|
|
|
Component.onDestruction: TokensManager.unRegisterToken(token, refreshData)
|
2017-04-13 10:47:27 -04:00
|
|
|
onVisibleChanged: visible && refreshData()
|
2017-04-03 15:35:42 -04:00
|
|
|
|
|
|
|
function refreshDataCallback(par)
|
2017-03-17 12:22:58 -04:00
|
|
|
{
|
2017-04-03 15:35:42 -04:00
|
|
|
jsonModel.json = par.response
|
|
|
|
token = JSON.parse(par.response).statetoken
|
2017-04-11 09:48:16 -04:00
|
|
|
TokensManager.registerToken(token, refreshData)
|
2017-03-17 12:22:58 -04:00
|
|
|
}
|
2017-04-03 15:35:42 -04:00
|
|
|
function refreshData()
|
|
|
|
{ if(visible) rsApi.request("/peers/*", "", refreshDataCallback) }
|
2016-09-27 08:05:14 -04:00
|
|
|
|
|
|
|
JSONListModel
|
|
|
|
{
|
|
|
|
id: jsonModel
|
|
|
|
query: "$.data[*]"
|
2017-03-17 12:22:58 -04:00
|
|
|
|
|
|
|
function isOnline(pgpId)
|
|
|
|
{
|
|
|
|
var qr = "$.data[?(@.pgp_id=='"+pgpId+"')].locations[*].is_online"
|
2017-03-24 07:02:13 -04:00
|
|
|
var locOn = JSONPath.jsonPath(JSON.parse(jsonModel.json), qr)
|
|
|
|
if (Array.isArray(locOn))
|
|
|
|
return locOn.reduce(function(cur,acc){return cur || acc}, false)
|
|
|
|
return Boolean(locOn)
|
2017-03-17 12:22:58 -04:00
|
|
|
}
|
2017-04-13 10:47:27 -04:00
|
|
|
|
|
|
|
function getLocations(pgpId)
|
|
|
|
{
|
|
|
|
var qr = "$.data[?(@.pgp_id=='"+pgpId+"')].locations"
|
|
|
|
return JSONPath.jsonPath(JSON.parse(jsonModel.json), qr)
|
|
|
|
}
|
2016-09-27 08:05:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ListView
|
|
|
|
{
|
|
|
|
width: parent.width
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.bottom: bottomButton.top
|
|
|
|
model: jsonModel.model
|
2017-07-22 13:51:32 -04:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
spacing: 3
|
2016-12-22 07:47:44 -05:00
|
|
|
delegate: Item
|
2016-10-26 14:37:28 -04:00
|
|
|
{
|
2017-06-23 12:39:18 -04:00
|
|
|
property bool isOnline: jsonModel.isOnline(model.pgp_id)
|
2017-07-09 07:17:19 -04:00
|
|
|
height: 54
|
2017-03-17 12:22:58 -04:00
|
|
|
width: parent.width
|
2017-07-22 13:51:32 -04:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2017-03-17 12:22:58 -04:00
|
|
|
|
2017-07-22 13:51:32 -04:00
|
|
|
ButtonText
|
2017-03-17 12:22:58 -04:00
|
|
|
{
|
2017-07-22 13:51:32 -04:00
|
|
|
id: locationButton
|
|
|
|
// anchors.horizontalCenter: parent.horizontalCenter
|
2017-03-17 12:22:58 -04:00
|
|
|
text: model.name
|
2017-07-22 13:51:32 -04:00
|
|
|
borderRadius:0
|
|
|
|
iconUrl: isOnline?
|
|
|
|
"/icons/state-ok.svg" :
|
|
|
|
"/icons/state-offline.svg"
|
2017-08-03 12:31:05 -04:00
|
|
|
color: "transparent"
|
2017-07-22 13:51:32 -04:00
|
|
|
pressColor: "lightsteelblue"
|
|
|
|
buttonTextPixelSize: 18
|
|
|
|
iconHeight:parent.height - 4
|
|
|
|
|
2017-04-13 10:47:27 -04:00
|
|
|
onClicked:
|
2016-12-22 07:47:44 -05:00
|
|
|
{
|
2017-04-13 10:47:27 -04:00
|
|
|
stackView.push(
|
|
|
|
"qrc:/TrustedNodeDetails.qml",
|
|
|
|
{
|
|
|
|
pgpName: model.name,
|
|
|
|
pgpId: model.pgp_id,
|
2017-06-23 12:39:18 -04:00
|
|
|
isOnline: isOnline,
|
2017-04-13 10:47:27 -04:00
|
|
|
locations: jsonModel.getLocations(
|
|
|
|
model.pgp_id)
|
|
|
|
}
|
|
|
|
)
|
2016-12-22 07:47:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-27 08:05:14 -04:00
|
|
|
}
|
|
|
|
|
2017-07-22 13:11:56 -04:00
|
|
|
ButtonText
|
2016-09-27 08:05:14 -04:00
|
|
|
{
|
|
|
|
id: bottomButton
|
2017-07-24 10:28:04 -04:00
|
|
|
text: qsTr("Add/Share Trusted Node")
|
2016-09-27 08:05:14 -04:00
|
|
|
anchors.bottom: parent.bottom
|
2017-04-13 10:47:27 -04:00
|
|
|
onClicked: stackView.push("qrc:/AddTrustedNode.qml")
|
2017-07-22 13:11:56 -04:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
// width: parent.width
|
|
|
|
|
|
|
|
borderRadius: 0
|
|
|
|
buttonTextPixelSize: 14
|
|
|
|
iconUrl: "/icons/add.svg"
|
2017-03-17 12:22:58 -04:00
|
|
|
}
|
2016-09-27 08:05:14 -04:00
|
|
|
}
|