RetroShare/retroshare-qml-app/src/qml/Locations.qml
Gioacchino Mazzurco abe84a4f81 Improve Contacts: sorting, searching and unread
ChatHandler::handleUnreadMsgs(...) deprecate 'id' field
  in favour of 'chat_id'
IdentityHandler::handleWildcard(...) reduce sleep time from 500 to 50 ms
IdentityHandler::handleWildcard(...) expose 'is_contact' to JSON API
Split contacts list delegate into GxsIdentityDelegate.qml
Update to QtQuick.Controls 2.0 because 1.4 is not supported anymore and
  2.1 is not available yet in Qt 5.7.1
ChatView.qml mark messages as read
Set refreshTimer.triggeredOnStart=true to improve reponsiveness of views
Contacts.qml use a Popup that is available in Controls 2.0 instead of a
  castrated Dialog to display full fingerprint
TrustedNodesView.qml check if locations[*].is_online is an array before
  attempting calling reduce
main.qml added menuentry to shutdown de core
main.qml added menuantry to search contact
2017-03-24 12:02:13 +01:00

195 lines
4.5 KiB
QML

/*
* 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
import QtQuick.Controls 2.0
import org.retroshare.qml_components.LibresapiLocalClient 1.0
Item
{
id: locationView
state: "selectLocation"
property var qParent
property bool attemptLogin: false
property string password
property string sslid
states:
[
State
{
name: "selectLocation"
PropertyChanges { target: locationsListView; visible: true }
PropertyChanges { target: bottomButton; visible: true }
PropertyChanges { target: loginView; visible: false }
},
State
{
name: "createLocation"
PropertyChanges { target: locationsListView; visible: false }
PropertyChanges { target: bottomButton; visible: false }
PropertyChanges
{
target: loginView
visible: true
buttonText: "Save"
onSubmit:
{
var jsonData = { pgp_name: login, ssl_name: login, pgp_password: password }
rsApi.request("/control/create_location/", JSON.stringify(jsonData))
locationView.state = "selectLocation"
}
}
},
State
{
name: "login"
PropertyChanges { target: locationsListView; visible: false }
PropertyChanges { target: bottomButton; visible: false }
PropertyChanges
{
target: loginView
visible: true
onSubmit:
{
locationView.password = password
console.log("locationView.sslid: ", locationView.sslid)
rsApi.request( "/control/login/",
JSON.stringify({id: locationView.sslid}) )
locationView.attemptLogin = true
busyIndicator.running = true
attemptTimer.start()
}
}
}
]
function requestLocationsList() { rsApi.request("/control/locations/", "") }
onFocusChanged: focus && requestLocationsList()
LibresapiLocalClient
{
id: rsApi
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 }
rsApi.request( "/control/password/",
JSON.stringify(jsonPass) )
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")
}
}
}
}
}
}
BusyIndicator { id: busyIndicator; anchors.centerIn: parent }
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:
{
loginView.login = text
locationView.sslid = model.id
locationView.state = "login"
}
}
visible: false
}
Button
{
id: bottomButton
text: "Create new location"
anchors.bottom: parent.bottom
onClicked: locationView.state = "createLocation"
}
RsLoginPassView
{
id: loginView
visible: false
anchors.fill: parent
}
Timer
{
id: attemptTimer
interval: 500
repeat: true
triggeredOnStart: true
onTriggered:
{
if(locationView.focus)
locationView.requestLocationsList()
if (locationView.attemptLogin)
rsApi.request("/control/password/", "")
}
}
}