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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 2.0
|
|
|
|
import QtQuick.Controls 1.4
|
2016-12-08 15:57:26 -05:00
|
|
|
import QtQuick.Dialogs 1.2
|
2016-09-15 07:07:13 -04:00
|
|
|
import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
|
|
|
|
|
|
|
Item
|
|
|
|
{
|
2016-12-08 09:56:23 -05:00
|
|
|
id: contactsView
|
|
|
|
property string own_gxs_id: ""
|
|
|
|
property string own_nick: ""
|
2016-09-15 07:07:13 -04:00
|
|
|
|
2016-12-08 09:56:23 -05:00
|
|
|
Component.onCompleted: refreshOwn()
|
2016-09-15 07:07:13 -04:00
|
|
|
|
2017-03-17 12:22:58 -04:00
|
|
|
function refreshData()
|
|
|
|
{
|
|
|
|
function refreshCallback(par)
|
|
|
|
{
|
|
|
|
locationsModel.json = par.response
|
|
|
|
if(contactsView.own_gxs_id == "") refreshOwn()
|
|
|
|
}
|
|
|
|
rsApi.request("/identity/*/", "", refreshCallback)
|
|
|
|
}
|
2016-12-08 09:56:23 -05:00
|
|
|
function refreshOwn()
|
2016-09-15 07:07:13 -04:00
|
|
|
{
|
2016-12-08 09:56:23 -05:00
|
|
|
rsApi.request("/identity/own", "", function(par)
|
2016-12-10 14:23:30 -05:00
|
|
|
{
|
|
|
|
var json = JSON.parse(par.response)
|
|
|
|
if(json.data.length > 0)
|
|
|
|
{
|
|
|
|
contactsView.own_gxs_id = json.data[0].gxs_id
|
|
|
|
contactsView.own_nick = json.data[0].name
|
|
|
|
}
|
|
|
|
else createIdentityDialog.visible = true
|
|
|
|
})
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
2017-03-17 12:22:58 -04:00
|
|
|
function startChatCallback(par)
|
|
|
|
{
|
|
|
|
var chId = JSON.parse(par.response).data.chat_id
|
|
|
|
stackView.push({
|
|
|
|
item:"qrc:/qml/ChatView.qml",
|
|
|
|
properties: {chatId: chId}
|
|
|
|
})
|
|
|
|
}
|
2016-09-15 07:07:13 -04:00
|
|
|
|
2016-12-08 09:56:23 -05:00
|
|
|
onFocusChanged: focus && refreshData()
|
|
|
|
|
2016-09-15 07:07:13 -04:00
|
|
|
JSONListModel
|
|
|
|
{
|
|
|
|
id: locationsModel
|
|
|
|
query: "$.data[*]"
|
|
|
|
}
|
|
|
|
|
|
|
|
ListView
|
|
|
|
{
|
|
|
|
id: locationsListView
|
|
|
|
width: parent.width
|
|
|
|
height: 300
|
|
|
|
model: locationsModel.model
|
2016-12-08 09:56:23 -05:00
|
|
|
delegate: Item
|
|
|
|
{
|
2017-03-21 09:47:34 -04:00
|
|
|
height: 40
|
2016-12-08 09:56:23 -05:00
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
MouseArea
|
|
|
|
{
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked:
|
|
|
|
{
|
2017-03-17 12:22:58 -04:00
|
|
|
console.log("Contacts view onclicked:", model.name,
|
|
|
|
model.gxs_id)
|
2016-12-08 09:56:23 -05:00
|
|
|
if(model.own) contactsView.own_gxs_id = model.gxs_id
|
|
|
|
else
|
|
|
|
{
|
2017-03-17 12:22:58 -04:00
|
|
|
var jsonData = { "own_gxs_hex": contactsView.own_gxs_id,
|
|
|
|
"remote_gxs_hex": model.gxs_id }
|
|
|
|
rsApi.request("/chat/initiate_distant_chat",
|
|
|
|
JSON.stringify(jsonData),
|
|
|
|
contactsView.startChatCallback)
|
2016-12-08 09:56:23 -05:00
|
|
|
}
|
|
|
|
}
|
2017-03-21 09:47:34 -04:00
|
|
|
Rectangle
|
|
|
|
{
|
|
|
|
id: colorHash
|
|
|
|
height: parent.height - 4
|
|
|
|
width: height
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: 2
|
|
|
|
color: "white"
|
|
|
|
property int childHeight : height/2
|
|
|
|
|
|
|
|
Rectangle
|
|
|
|
{
|
|
|
|
color: '#' + model.gxs_id.substring(1, 9)
|
|
|
|
height: parent.childHeight
|
|
|
|
width: height
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: parent.left
|
|
|
|
}
|
|
|
|
Rectangle
|
|
|
|
{
|
|
|
|
color: '#' + model.gxs_id.substring(9, 17)
|
|
|
|
height: parent.childHeight
|
|
|
|
width: height
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.right: parent.right
|
|
|
|
}
|
|
|
|
Rectangle
|
|
|
|
{
|
|
|
|
color: '#' + model.gxs_id.substring(17, 25)
|
|
|
|
height: parent.childHeight
|
|
|
|
width: height
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
}
|
|
|
|
Rectangle
|
|
|
|
{
|
|
|
|
color: '#' + model.gxs_id.slice(-8)
|
|
|
|
height: parent.childHeight
|
|
|
|
width: height
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.right: parent.right
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea
|
|
|
|
{
|
|
|
|
anchors.fill: parent
|
|
|
|
onPressAndHold:
|
|
|
|
{
|
|
|
|
fingerPrintDialog.nick = model.name
|
|
|
|
fingerPrintDialog.gxs_id = model.gxs_id
|
|
|
|
fingerPrintDialog.visible = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-08 09:56:23 -05:00
|
|
|
Text
|
|
|
|
{
|
2017-03-21 09:47:34 -04:00
|
|
|
id: nickText
|
2016-12-08 09:56:23 -05:00
|
|
|
color: model.own ? "blue" : "black"
|
2017-03-21 09:47:34 -04:00
|
|
|
text: model.name
|
|
|
|
anchors.left: colorHash.right
|
|
|
|
anchors.leftMargin: 5
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2016-12-08 09:56:23 -05:00
|
|
|
}
|
|
|
|
}
|
2017-03-21 09:47:34 -04:00
|
|
|
}
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
|
|
|
|
2017-03-21 09:47:34 -04:00
|
|
|
Text
|
|
|
|
{
|
2016-12-08 09:56:23 -05:00
|
|
|
id: selectedOwnIdentityView
|
|
|
|
color: "green"
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
width: parent.width
|
|
|
|
text: "Open Chat as: " + contactsView.own_nick + " " + contactsView.own_gxs_id
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer
|
|
|
|
{
|
|
|
|
id: refreshTimer
|
|
|
|
interval: 5000
|
|
|
|
repeat: true
|
|
|
|
onTriggered: if(contactsView.visible) contactsView.refreshData()
|
|
|
|
Component.onCompleted: start()
|
|
|
|
}
|
2016-12-08 15:57:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
Dialog
|
|
|
|
{
|
|
|
|
id: createIdentityDialog
|
|
|
|
visible: false
|
|
|
|
title: "You need to create a GXS identity to chat!"
|
|
|
|
standardButtons: StandardButton.Save
|
|
|
|
|
|
|
|
onAccepted: rsApi.request("/identity/create_identity", JSON.stringify({"name":identityNameTE.text, "pgp_linked": !psdnmCheckBox.checked }))
|
|
|
|
|
|
|
|
TextField
|
|
|
|
{
|
|
|
|
id: identityNameTE
|
|
|
|
width: 300
|
|
|
|
}
|
|
|
|
|
|
|
|
Row
|
|
|
|
{
|
|
|
|
anchors.top: identityNameTE.bottom
|
|
|
|
Text { text: "Pseudonymous: " }
|
|
|
|
CheckBox { id: psdnmCheckBox; checked: true; enabled: false }
|
|
|
|
}
|
|
|
|
}
|
2017-03-21 09:47:34 -04:00
|
|
|
|
|
|
|
Dialog
|
|
|
|
{
|
|
|
|
id: fingerPrintDialog
|
|
|
|
visible: false
|
|
|
|
property string nick
|
|
|
|
property string gxs_id
|
|
|
|
title: nick + " fingerprint:"
|
|
|
|
standardButtons: StandardButton.NoButton
|
|
|
|
Text
|
|
|
|
{
|
|
|
|
id: fingerPrintText
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text: "<pre>" +
|
|
|
|
fingerPrintDialog.gxs_id.substring(1, 9) + "<br/>" +
|
|
|
|
fingerPrintDialog.gxs_id.substring(9, 17) + "<br/>" +
|
|
|
|
fingerPrintDialog.gxs_id.substring(17, 25) + "<br/>" +
|
|
|
|
fingerPrintDialog.gxs_id.slice(-8) + "<br/>" +
|
|
|
|
"</pre>"
|
|
|
|
}
|
|
|
|
}
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|