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
|
|
|
|
import QtQuick.Controls 1.4
|
|
|
|
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
|
|
|
|
2016-12-08 09:56:23 -05:00
|
|
|
function refreshData() { rsApi.request("/identity/*/", "", function(par) { locationsModel.json = par.response; if(contactsView.own_gxs_id == "") refreshOwn() }) }
|
|
|
|
function refreshOwn()
|
2016-09-15 07:07:13 -04:00
|
|
|
{
|
2016-12-08 09:56:23 -05:00
|
|
|
rsApi.request("/identity/own", "", function(par)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
selectedOwnIdentityView.color = "red"
|
|
|
|
selectedOwnIdentityView.text = "You need to create a GXS identity to chat!"
|
|
|
|
}
|
|
|
|
})
|
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
|
|
|
|
{
|
|
|
|
height: 20
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
MouseArea
|
|
|
|
{
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked:
|
|
|
|
{
|
|
|
|
if(model.own) contactsView.own_gxs_id = model.gxs_id
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var jsonData = { "own_gxs_hex": contactsView.own_gxs_id, "remote_gxs_hex": model.gxs_id }
|
|
|
|
rsApi.request("/chat/initiate_distant_chat", JSON.stringify(jsonData), function (par) { mainWindow.activeChatId = JSON.parse(par.response).data.chat_id })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Text
|
|
|
|
{
|
|
|
|
color: model.own ? "blue" : "black"
|
|
|
|
text: model.name + " " + model.gxs_id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
|
|
|
|
2016-12-08 09:56:23 -05:00
|
|
|
Text
|
|
|
|
{
|
|
|
|
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-09-15 07:07:13 -04:00
|
|
|
}
|