Qml app improved trusted nodes exchange

AddTrustedNode.qml support for plain certificate and node link import/export
Move clipboard wrapper to it's own singleton ClipboardWrapper.qml with
  improved clipboard API
This commit is contained in:
Gioacchino Mazzurco 2017-04-20 21:39:59 +02:00
parent 5c1ad36d2b
commit 7b070e482d
9 changed files with 141 additions and 62 deletions

View file

@ -1,43 +1,83 @@
/*
* RetroShare Android QML App
* Copyright (C) 2016-2017 Gioacchino Mazzurco <gio@eigenlab.org>
*
* 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.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import org.retroshare.qml_components.LibresapiLocalClient 1.0
import "." //Needed for ClipboardWrapper singleton
import "URI.js" as UriJs
Item
{
function refreshData() { rsApi.request("/peers/self/certificate/", "") }
property ApplicationWindow mW
Component.onCompleted:
{
rsApi.openConnection(apiSocketPath)
refreshData()
}
onFocusChanged: focus && refreshData()
LibresapiLocalClient
{
id: rsApi
onGoodResponseReceived:
{
var jsonData = JSON.parse(msg)
if(jsonData && jsonData.data && jsonData.data.cert_string)
myKeyField.text = jsonData.data.cert_string
}
}
ColumnLayout
Column
{
anchors.fill: parent
Text
{
text: qsTr("Import/export node from/to clipboard")
font.bold: true
wrapMode: Text.Wrap
}
Button
{
id: bottomButton
text: "Add trusted node"
text: qsTr("Export own certificate link")
onClicked:
{
console.log("onClicked", text)
rsApi.request(
"/peers/self/certificate/", "",
function(par)
{
var radix = JSON.parse(par.response).data.cert_string
var name = mainWindow.user_name
var encodedName = UriJs.URI.encode(name)
ClipboardWrapper.postToClipBoard(
"retroshare://certificate?" +
"name=" + encodedName +
"&radix=" + UriJs.URI.encode(radix) +
"&location=" + encodedName
)
linkCopiedPopup.itemName = name
linkCopiedPopup.open()
})
}
}
Button
{
text: qsTr("Import trusted node")
onClicked:
{
var cptext = ClipboardWrapper.getFromClipBoard()
console.log("typeof(cptext)", typeof(cptext))
if(cptext.search("://") > 0)
mainWindow.handleIntentUri(cptext)
else
rsApi.request(
"/peers/examine_cert/",
JSON.stringify({cert_string: otherKeyField.text}),
JSON.stringify({cert_string: cptext}),
function(par)
{
console.log("/peers/examine_cert/ CB", par)
@ -59,25 +99,19 @@ Item
Button
{
text: "Copy"
text: qsTr("Export own plain certificate")
onClicked:
{
myKeyField.selectAll()
myKeyField.copy()
rsApi.request(
"/peers/self/certificate/", "",
function(par)
{
var jD = JSON.parse(par.response).data
ClipboardWrapper.postToClipBoard(jD.cert_string)
mainWindow.linkCopiedPopup.itemName=mainWindow.user_name
mainWindow.linkCopiedPopup.open()
})
}
}
Button
{
text: "Paste"
onClicked:
{
otherKeyField.selectAll()
otherKeyField.paste()
}
}
TextField { id: myKeyField }
TextField { id: otherKeyField }
}
}