2016-09-15 07:07:13 -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-15 07:07:13 -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/>.
|
|
|
|
*/
|
2016-09-04 09:01:44 -04:00
|
|
|
|
2017-04-16 08:46:43 -04:00
|
|
|
import QtQuick 2.7
|
2017-03-24 07:02:13 -04:00
|
|
|
import QtQuick.Controls 2.0
|
2016-09-15 07:07:13 -04:00
|
|
|
import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
2017-04-13 10:47:27 -04:00
|
|
|
import "URI.js" as UriJs
|
2017-04-11 09:48:16 -04:00
|
|
|
import "." //Needed for TokensManager singleton
|
2016-09-15 07:07:13 -04:00
|
|
|
|
|
|
|
ApplicationWindow
|
|
|
|
{
|
|
|
|
id: mainWindow
|
|
|
|
visible: true
|
2017-03-17 12:22:58 -04:00
|
|
|
title: "RetroShare"
|
2016-10-26 14:37:28 -04:00
|
|
|
width: 400
|
|
|
|
height: 400
|
2016-09-15 07:07:13 -04:00
|
|
|
|
2017-04-07 12:26:08 -04:00
|
|
|
property string pgp_name
|
|
|
|
|
2017-04-13 10:47:27 -04:00
|
|
|
property bool coreReady: stackView.state === "running_ok" ||
|
|
|
|
stackView.state === "running_ok_no_full_control"
|
|
|
|
|
2017-04-14 20:17:27 -04:00
|
|
|
Component.onCompleted:
|
|
|
|
{
|
|
|
|
addUriHandler("/certificate", certificateLinkHandler)
|
|
|
|
|
|
|
|
var argc = mainArgs.length
|
|
|
|
for(var i=0; i<argc; ++i)
|
|
|
|
{
|
|
|
|
var dump = UriJs.URI.parse(mainArgs[i])
|
|
|
|
if(dump.protocol && (dump.query || dump.path))
|
|
|
|
handleIntentUri(mainArgs[i])
|
|
|
|
}
|
|
|
|
}
|
2017-04-13 10:47:27 -04:00
|
|
|
|
|
|
|
property var uriHandlersRegister: ({})
|
2017-04-14 20:17:27 -04:00
|
|
|
property var pendingUriRegister: []
|
2017-04-13 10:47:27 -04:00
|
|
|
function addUriHandler(path, fun) { uriHandlersRegister[path] = fun }
|
|
|
|
function delUriHandler(path, fun) { delete uriHandlersRegister[path] }
|
2017-04-11 07:11:57 -04:00
|
|
|
|
2017-03-24 07:02:13 -04:00
|
|
|
header: ToolBar
|
2016-09-15 07:07:13 -04:00
|
|
|
{
|
2017-03-24 07:02:13 -04:00
|
|
|
id: toolBar
|
|
|
|
|
2017-03-17 12:22:58 -04:00
|
|
|
Image
|
|
|
|
{
|
|
|
|
id: rsIcon
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
height: Math.max(30, parent.height - 4)
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
source: "icons/retroshare06.png"
|
|
|
|
}
|
|
|
|
Label
|
|
|
|
{
|
|
|
|
text: "RetroShare"
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.left: rsIcon.right
|
|
|
|
anchors.leftMargin: 20
|
|
|
|
}
|
2017-03-24 07:02:13 -04:00
|
|
|
MouseArea
|
2016-09-15 07:07:13 -04:00
|
|
|
{
|
2017-03-24 07:02:13 -04:00
|
|
|
height: parent.height
|
|
|
|
width: parent.height
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: 2
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
|
|
onClicked: menu.open()
|
|
|
|
|
|
|
|
Image
|
2016-09-15 07:07:13 -04:00
|
|
|
{
|
2017-04-13 10:47:27 -04:00
|
|
|
source: "qrc:/icons/application-menu.png"
|
2017-03-24 07:02:13 -04:00
|
|
|
height: parent.height - 10
|
|
|
|
width: parent.height - 10
|
|
|
|
anchors.centerIn: parent
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
2017-03-24 07:02:13 -04:00
|
|
|
|
|
|
|
Menu
|
2016-09-15 07:07:13 -04:00
|
|
|
{
|
2017-03-24 07:02:13 -04:00
|
|
|
id: menu
|
|
|
|
y: parent.y + parent.height
|
|
|
|
|
|
|
|
MenuItem
|
|
|
|
{
|
|
|
|
text: qsTr("Trusted Nodes")
|
2017-04-13 10:47:27 -04:00
|
|
|
//iconSource: "qrc:/icons/document-share.png"
|
|
|
|
onTriggered: stackView.push("qrc:/TrustedNodesView.qml")
|
|
|
|
enabled: mainWindow.coreReady
|
2017-03-24 07:02:13 -04:00
|
|
|
}
|
|
|
|
MenuItem
|
|
|
|
{
|
|
|
|
text: qsTr("Search Contacts")
|
|
|
|
onTriggered:
|
2017-04-13 10:47:27 -04:00
|
|
|
stackView.push("qrc:/Contacts.qml",
|
2017-04-03 15:19:14 -04:00
|
|
|
{'searching': true} )
|
2017-04-13 10:47:27 -04:00
|
|
|
enabled: mainWindow.coreReady
|
|
|
|
}
|
|
|
|
MenuItem
|
|
|
|
{
|
|
|
|
text: "Paste Link"
|
|
|
|
onTriggered:
|
|
|
|
{
|
|
|
|
clipboardWrap.selectAll()
|
|
|
|
clipboardWrap.paste()
|
|
|
|
handleIntentUri(clipboardWrap.text)
|
|
|
|
}
|
|
|
|
enabled: mainWindow.coreReady
|
|
|
|
|
|
|
|
TextField { id: clipboardWrap; visible: false }
|
2017-03-24 07:02:13 -04:00
|
|
|
}
|
|
|
|
MenuItem
|
|
|
|
{
|
|
|
|
text: "Terminate Core"
|
|
|
|
onTriggered: rsApi.request("/control/shutdown")
|
2017-04-18 07:30:28 -04:00
|
|
|
visible: !Q_OS_ANDROID
|
2017-03-24 07:02:13 -04:00
|
|
|
}
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
|
|
|
}
|
2017-03-17 12:22:58 -04:00
|
|
|
}
|
2016-09-15 07:07:13 -04:00
|
|
|
|
2017-03-17 12:22:58 -04:00
|
|
|
StackView
|
|
|
|
{
|
|
|
|
id: stackView
|
|
|
|
anchors.fill: parent
|
2017-04-14 20:17:27 -04:00
|
|
|
focus: true
|
|
|
|
onCurrentItemChanged: if (currentItem) currentItem.focus = true
|
2017-03-17 12:22:58 -04:00
|
|
|
Keys.onReleased:
|
|
|
|
if (event.key === Qt.Key_Back && stackView.depth > 1)
|
2016-09-15 07:07:13 -04:00
|
|
|
{
|
2017-03-17 12:22:58 -04:00
|
|
|
stackView.pop();
|
|
|
|
event.accepted = true;
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
|
|
|
|
2017-03-17 12:22:58 -04:00
|
|
|
state: "core_down"
|
2017-04-07 12:26:08 -04:00
|
|
|
initialItem: BusyOverlay { message: qsTr("Connecting to core...") }
|
|
|
|
|
2017-03-17 12:22:58 -04:00
|
|
|
states: [
|
|
|
|
State
|
|
|
|
{
|
|
|
|
name: "core_down"
|
|
|
|
PropertyChanges { target: stackView; enabled: false }
|
|
|
|
},
|
|
|
|
State
|
2016-09-15 07:07:13 -04:00
|
|
|
{
|
2017-03-17 12:22:58 -04:00
|
|
|
name: "waiting_account_select"
|
|
|
|
PropertyChanges { target: stackView; enabled: true }
|
|
|
|
StateChangeScript
|
2016-12-08 09:56:23 -05:00
|
|
|
{
|
2017-03-17 12:22:58 -04:00
|
|
|
script:
|
|
|
|
{
|
|
|
|
console.log("StateChangeScript waiting_account_select")
|
|
|
|
stackView.clear()
|
2017-04-13 10:47:27 -04:00
|
|
|
stackView.push("qrc:/Locations.qml")
|
2017-03-17 12:22:58 -04:00
|
|
|
}
|
2016-12-08 09:56:23 -05:00
|
|
|
}
|
2017-03-17 12:22:58 -04:00
|
|
|
},
|
|
|
|
State
|
2017-04-07 12:26:08 -04:00
|
|
|
{
|
|
|
|
name: "waiting_startup"
|
|
|
|
PropertyChanges { target: stackView; enabled: false }
|
|
|
|
StateChangeScript
|
|
|
|
{
|
|
|
|
script:
|
|
|
|
{
|
|
|
|
console.log("StateChangeScript waiting_startup")
|
|
|
|
stackView.clear()
|
2017-04-13 10:47:27 -04:00
|
|
|
stackView.push("qrc:/BusyOverlay.qml",
|
2017-04-07 12:26:08 -04:00
|
|
|
{ message: "Core initializing..."})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State
|
2017-03-17 12:22:58 -04:00
|
|
|
{
|
|
|
|
name: "running_ok"
|
|
|
|
PropertyChanges { target: stackView; enabled: true }
|
|
|
|
StateChangeScript
|
|
|
|
{
|
|
|
|
script:
|
|
|
|
{
|
2017-04-03 15:19:14 -04:00
|
|
|
console.log("StateChangeScript running_ok")
|
|
|
|
coreStateCheckTimer.stop()
|
2017-03-17 12:22:58 -04:00
|
|
|
stackView.clear()
|
2017-04-13 10:47:27 -04:00
|
|
|
stackView.push("qrc:/Contacts.qml")
|
2017-04-14 20:17:27 -04:00
|
|
|
while(mainWindow.pendingUriRegister.length > 0)
|
|
|
|
mainWindow.handleIntentUri(
|
|
|
|
mainWindow.pendingUriRegister.shift())
|
2017-03-17 12:22:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State
|
|
|
|
{
|
|
|
|
name: "running_ok_no_full_control"
|
|
|
|
PropertyChanges { target: stackView; state: "running_ok" }
|
2016-09-27 08:05:14 -04:00
|
|
|
}
|
2017-03-17 12:22:58 -04:00
|
|
|
]
|
2017-04-03 15:19:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Timer
|
|
|
|
{
|
|
|
|
id: coreStateCheckTimer
|
|
|
|
interval: 1000
|
|
|
|
repeat: true
|
|
|
|
triggeredOnStart: true
|
|
|
|
onTriggered:
|
|
|
|
{
|
|
|
|
var ret = rsApi.request("/control/runstate/", "", runStateCallback)
|
|
|
|
if ( ret < 1 )
|
|
|
|
{
|
|
|
|
console.log("checkCoreStatus() core is down")
|
|
|
|
stackView.state = "core_down"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Component.onCompleted: start()
|
|
|
|
|
|
|
|
function runStateCallback(par)
|
|
|
|
{
|
|
|
|
var jsonReponse = JSON.parse(par.response)
|
|
|
|
var runState = jsonReponse.data.runstate
|
|
|
|
if(typeof(runState) === 'string') stackView.state = runState
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stackView.state = "core_down"
|
|
|
|
console.log("runStateCallback(...) core is down")
|
|
|
|
}
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
|
|
|
}
|
2017-04-13 10:47:27 -04:00
|
|
|
|
|
|
|
function handleIntentUri(uriStr)
|
|
|
|
{
|
|
|
|
console.log("handleIntentUri(uriStr)")
|
|
|
|
|
|
|
|
if(!Array.isArray(uriStr.match(/:\/\/[a-zA-Z.-]*\//g)))
|
|
|
|
{
|
|
|
|
/* RetroShare GUI produces links without hostname and only two
|
|
|
|
* slashes after scheme causing the first piece of the path part
|
|
|
|
* being interpreted as host, this is awckard and should be fixed in
|
|
|
|
* the GUI, in the meantime we add a slash for easier parsing, in
|
|
|
|
* case there is no hostname and just two slashes, we might consider
|
|
|
|
* to use +hostname+ part for some trick in the future, for example
|
|
|
|
* it could help other application to recognize retroshare link by
|
|
|
|
* putting a domain name there that has no meaning for retroshare
|
|
|
|
*/
|
|
|
|
uriStr = uriStr.replace("://", ":///")
|
|
|
|
}
|
|
|
|
|
|
|
|
var uri = new UriJs.URI(uriStr)
|
|
|
|
var hPath = uri.path() // no nesting ATM segmentCoded()
|
|
|
|
console.log(hPath)
|
|
|
|
|
|
|
|
if(typeof uriHandlersRegister[hPath] == "function")
|
|
|
|
{
|
|
|
|
console.log("handleIntentUri(uriStr)", "found handler for path",
|
|
|
|
hPath, uriHandlersRegister[hPath])
|
|
|
|
uriHandlersRegister[hPath](uriStr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function certificateLinkHandler(uriStr)
|
|
|
|
{
|
|
|
|
console.log("certificateLinkHandler(uriStr)", coreReady)
|
|
|
|
|
2017-04-14 20:17:27 -04:00
|
|
|
if(!coreReady)
|
|
|
|
{
|
|
|
|
// Save cert uri for later processing as we need core to examine it
|
|
|
|
pendingUriRegister.push(uriStr)
|
|
|
|
return
|
|
|
|
}
|
2017-04-13 10:47:27 -04:00
|
|
|
|
|
|
|
var uri = new UriJs.URI(uriStr)
|
|
|
|
var uQuery = uri.search(true)
|
|
|
|
if(uQuery.radix)
|
|
|
|
{
|
|
|
|
console.log("/peers/examine_cert/")
|
|
|
|
console.log("uriStr", uriStr)
|
|
|
|
|
|
|
|
var certStr = UriJs.URI.decode(uQuery.radix)
|
|
|
|
|
|
|
|
// Workaround https://github.com/RetroShare/RetroShare/issues/772
|
|
|
|
certStr = certStr.replace(/ /g, "+")
|
|
|
|
|
|
|
|
console.log("certStr", certStr)
|
|
|
|
console.log("JSON.stringify(..)",
|
|
|
|
JSON.stringify({cert_string: certStr}, null, 1))
|
|
|
|
rsApi.request(
|
|
|
|
"/peers/examine_cert/",
|
|
|
|
JSON.stringify({cert_string: certStr}),
|
|
|
|
function(par)
|
|
|
|
{
|
|
|
|
console.log("/peers/examine_cert/ CB", par)
|
|
|
|
var jData = JSON.parse(par.response).data
|
|
|
|
stackView.push(
|
|
|
|
"qrc:/TrustedNodeDetails.qml",
|
|
|
|
{
|
|
|
|
nodeCert: certStr,
|
|
|
|
pgpName: jData.name,
|
|
|
|
pgpId: jData.pgp_id,
|
|
|
|
locations:
|
|
|
|
[{
|
|
|
|
location: jData.location,
|
|
|
|
peer_id: jData.peer_id
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2016-09-04 09:01:44 -04:00
|
|
|
}
|