2016-09-15 07:07:13 -04:00
|
|
|
/*
|
|
|
|
* RetroShare Android QML App
|
|
|
|
* Copyright (C) 2016 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.0
|
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
|
|
|
|
|
|
|
|
Item
|
|
|
|
{
|
|
|
|
id: locationView
|
|
|
|
state: "selectLocation"
|
2016-09-16 06:04:49 -04:00
|
|
|
property var qParent
|
|
|
|
property bool attemptLogin: false
|
|
|
|
property string password
|
2016-10-26 14:37:28 -04:00
|
|
|
property string sslid
|
2016-09-15 07:07:13 -04:00
|
|
|
|
|
|
|
states:
|
|
|
|
[
|
|
|
|
State
|
|
|
|
{
|
|
|
|
name: "selectLocation"
|
|
|
|
PropertyChanges { target: locationsListView; visible: true }
|
2016-10-26 14:37:28 -04:00
|
|
|
PropertyChanges { target: bottomButton; visible: true }
|
2016-09-16 06:04:49 -04:00
|
|
|
PropertyChanges { target: loginView; visible: false }
|
2016-09-15 07:07:13 -04:00
|
|
|
},
|
|
|
|
State
|
|
|
|
{
|
|
|
|
name: "createLocation"
|
|
|
|
PropertyChanges { target: locationsListView; visible: false }
|
2016-09-16 06:04:49 -04:00
|
|
|
PropertyChanges { target: bottomButton; visible: false }
|
2016-09-15 07:07:13 -04:00
|
|
|
PropertyChanges
|
|
|
|
{
|
2016-09-16 06:04:49 -04:00
|
|
|
target: loginView
|
|
|
|
visible: true
|
|
|
|
buttonText: "Save"
|
|
|
|
onSubmit:
|
2016-09-15 07:07:13 -04:00
|
|
|
{
|
2016-09-16 06:04:49 -04:00
|
|
|
var jsonData = { pgp_name: login, ssl_name: login, pgp_password: password }
|
2016-09-15 07:07:13 -04:00
|
|
|
rsApi.request("/control/create_location/", JSON.stringify(jsonData))
|
2016-09-16 06:04:49 -04:00
|
|
|
locationView.state = "selectLocation"
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State
|
|
|
|
{
|
2016-09-16 06:04:49 -04:00
|
|
|
name: "login"
|
2016-09-15 07:07:13 -04:00
|
|
|
PropertyChanges { target: locationsListView; visible: false }
|
2016-09-16 06:04:49 -04:00
|
|
|
PropertyChanges { target: bottomButton; visible: false }
|
2016-09-15 07:07:13 -04:00
|
|
|
PropertyChanges
|
|
|
|
{
|
2016-09-16 06:04:49 -04:00
|
|
|
target: loginView
|
|
|
|
visible: true
|
|
|
|
onSubmit:
|
2016-09-15 07:07:13 -04:00
|
|
|
{
|
2016-09-16 06:04:49 -04:00
|
|
|
locationView.password = password
|
2016-10-26 14:37:28 -04:00
|
|
|
console.log("locationView.sslid: ", locationView.sslid)
|
2017-03-15 18:11:50 -04:00
|
|
|
rsApi.request( "/control/login/",
|
|
|
|
JSON.stringify({id: locationView.sslid}) )
|
2016-09-16 06:04:49 -04:00
|
|
|
locationView.attemptLogin = true
|
|
|
|
busyIndicator.running = true
|
|
|
|
attemptTimer.start()
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2016-09-16 06:04:49 -04:00
|
|
|
function requestLocationsList() { rsApi.request("/control/locations/", "") }
|
|
|
|
|
|
|
|
onFocusChanged: focus && requestLocationsList()
|
2016-09-15 07:07:13 -04:00
|
|
|
|
|
|
|
LibresapiLocalClient
|
|
|
|
{
|
|
|
|
id: rsApi
|
2016-09-16 06:04:49 -04:00
|
|
|
Component.onCompleted:
|
|
|
|
{
|
|
|
|
openConnection(apiSocketPath)
|
|
|
|
locationView.requestLocationsList()
|
|
|
|
}
|
|
|
|
onGoodResponseReceived:
|
|
|
|
{
|
|
|
|
var jsonData = JSON.parse(msg)
|
|
|
|
|
|
|
|
|
|
|
|
if(jsonData)
|
|
|
|
{
|
|
|
|
if(jsonData.data)
|
|
|
|
{
|
|
|
|
if(jsonData.data[0] && jsonData.data[0].pgp_id)
|
|
|
|
{
|
|
|
|
// if location list update
|
|
|
|
locationsModel.json = msg
|
|
|
|
busyIndicator.running = false
|
|
|
|
}
|
|
|
|
if (jsonData.data.key_name)
|
|
|
|
{
|
|
|
|
if(jsonData.data.want_password)
|
|
|
|
{
|
|
|
|
// if Server requested password
|
|
|
|
var jsonPass = { password: locationView.password }
|
2017-03-15 18:11:50 -04:00
|
|
|
rsApi.request( "/control/password/",
|
|
|
|
JSON.stringify(jsonPass) )
|
2016-09-16 06:04:49 -04:00
|
|
|
locationView.attemptLogin = false
|
|
|
|
console.debug("RS core asked for password")
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if Already logged in
|
|
|
|
bottomButton.enabled = false
|
|
|
|
bottomButton.text = "Already logged in"
|
|
|
|
locationView.attemptLogin = false
|
|
|
|
busyIndicator.running = false
|
|
|
|
locationView.state = "selectLocation"
|
|
|
|
locationsListView.enabled = false
|
|
|
|
console.debug("Already logged in")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
|
|
|
|
2016-09-16 06:04:49 -04:00
|
|
|
BusyIndicator { id: busyIndicator; anchors.centerIn: parent }
|
|
|
|
|
2016-09-15 07:07:13 -04:00
|
|
|
JSONListModel
|
|
|
|
{
|
|
|
|
id: locationsModel
|
|
|
|
query: "$.data[*]"
|
|
|
|
}
|
|
|
|
|
|
|
|
ListView
|
|
|
|
{
|
|
|
|
id: locationsListView
|
|
|
|
width: parent.width
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.bottom: bottomButton.top
|
|
|
|
model: locationsModel.model
|
|
|
|
delegate: Button
|
|
|
|
{
|
|
|
|
text: model.name
|
|
|
|
onClicked:
|
|
|
|
{
|
2016-09-16 06:04:49 -04:00
|
|
|
loginView.login = text
|
2016-10-26 14:37:28 -04:00
|
|
|
locationView.sslid = model.id
|
2016-09-16 06:04:49 -04:00
|
|
|
locationView.state = "login"
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
visible: false
|
|
|
|
}
|
|
|
|
|
2016-09-16 06:04:49 -04:00
|
|
|
Button
|
2016-09-15 07:07:13 -04:00
|
|
|
{
|
2016-09-16 06:04:49 -04:00
|
|
|
id: bottomButton
|
|
|
|
text: "Create new location"
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
onClicked: locationView.state = "createLocation"
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
|
|
|
|
2016-09-16 06:04:49 -04:00
|
|
|
RsLoginPassView
|
|
|
|
{
|
|
|
|
id: loginView
|
|
|
|
visible: false
|
|
|
|
anchors.fill: parent
|
|
|
|
}
|
2016-09-15 07:07:13 -04:00
|
|
|
|
2016-09-16 06:04:49 -04:00
|
|
|
Timer
|
2016-09-15 07:07:13 -04:00
|
|
|
{
|
2016-09-16 06:04:49 -04:00
|
|
|
id: attemptTimer
|
|
|
|
interval: 500
|
|
|
|
repeat: true
|
2017-03-24 07:02:13 -04:00
|
|
|
triggeredOnStart: true
|
2016-09-16 06:04:49 -04:00
|
|
|
onTriggered:
|
|
|
|
{
|
|
|
|
if(locationView.focus)
|
|
|
|
locationView.requestLocationsList()
|
|
|
|
|
|
|
|
if (locationView.attemptLogin)
|
|
|
|
rsApi.request("/control/password/", "")
|
|
|
|
}
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
|
|
|
}
|