2016-09-27 08:05:14 -04:00
|
|
|
/*
|
|
|
|
* RetroShare Android QML App
|
2017-03-17 12:22:58 -04:00
|
|
|
* Copyright (C) 2016-2017 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 2.0
|
2017-03-24 07:02:13 -04:00
|
|
|
import QtQuick.Controls 2.0
|
2017-03-17 12:22:58 -04:00
|
|
|
import QtQuick.Dialogs 1.2
|
2016-10-26 14:37:28 -04:00
|
|
|
import "jsonpath.js" as JSONPath
|
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()
|
|
|
|
onFocusChanged: focus && refreshData()
|
|
|
|
|
|
|
|
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
|
|
|
|
mainWindow.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
|
|
|
}
|
2016-09-27 08:05:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ListView
|
|
|
|
{
|
|
|
|
width: parent.width
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.bottom: bottomButton.top
|
|
|
|
model: jsonModel.model
|
2016-12-22 07:47:44 -05:00
|
|
|
delegate: Item
|
2016-10-26 14:37:28 -04:00
|
|
|
{
|
2017-03-17 12:22:58 -04:00
|
|
|
height: 30
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
Image
|
2016-12-22 07:47:44 -05:00
|
|
|
{
|
2017-03-17 12:22:58 -04:00
|
|
|
id: statusImage
|
|
|
|
source: jsonModel.isOnline(model.pgp_id) ?
|
|
|
|
"icons/state-ok.png" :
|
|
|
|
"icons/state-offline.png"
|
|
|
|
|
|
|
|
height: parent.height - 4
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2017-03-24 07:02:13 -04:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: 3
|
2017-03-17 12:22:58 -04:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
}
|
|
|
|
Text
|
|
|
|
{
|
|
|
|
text: model.name
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.left: statusImage.right
|
|
|
|
anchors.leftMargin: 10
|
|
|
|
}
|
|
|
|
Image
|
|
|
|
{
|
|
|
|
source: "icons/remove-link.png"
|
|
|
|
|
|
|
|
height: parent.height - 6
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2016-12-22 07:47:44 -05:00
|
|
|
|
2017-03-17 12:22:58 -04:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: 2
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
|
|
MouseArea
|
2016-12-22 07:47:44 -05:00
|
|
|
{
|
|
|
|
height: parent.height
|
2017-03-17 12:22:58 -04:00
|
|
|
width: parent.width
|
|
|
|
onClicked:
|
2016-12-22 07:47:44 -05:00
|
|
|
{
|
2017-03-17 12:22:58 -04:00
|
|
|
deleteDialog.nodeName = model.name
|
|
|
|
deleteDialog.nodeId = model.pgp_id
|
|
|
|
deleteDialog.visible = true
|
2016-12-22 07:47:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-27 08:05:14 -04:00
|
|
|
}
|
|
|
|
|
2017-03-17 12:22:58 -04:00
|
|
|
Dialog
|
|
|
|
{
|
|
|
|
id: deleteDialog
|
|
|
|
property string nodeName
|
|
|
|
property string nodeId
|
|
|
|
standardButtons: StandardButton.Yes | StandardButton.No
|
|
|
|
visible: false
|
|
|
|
onYes:
|
|
|
|
{
|
|
|
|
rsApi.request("/peers/"+nodeId+"/delete")
|
|
|
|
trustedNodesView.refreshData()
|
|
|
|
trustedNodesView.forceActiveFocus()
|
|
|
|
}
|
|
|
|
onNo: trustedNodesView.forceActiveFocus()
|
|
|
|
Text
|
|
|
|
{
|
|
|
|
text: "Are you sure to delete " + deleteDialog.nodeName + " ("+
|
|
|
|
deleteDialog.nodeId +") ?"
|
|
|
|
|
|
|
|
width: parent.width - 2
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 08:05:14 -04:00
|
|
|
Button
|
|
|
|
{
|
|
|
|
id: bottomButton
|
|
|
|
text: "Add Trusted Node"
|
|
|
|
anchors.bottom: parent.bottom
|
2017-03-24 07:02:13 -04:00
|
|
|
onClicked: stackView.push("qrc:/qml/AddTrustedNode.qml")
|
2017-03-17 12:22:58 -04:00
|
|
|
width: parent.width
|
|
|
|
}
|
2016-09-27 08:05:14 -04:00
|
|
|
}
|