mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-14 09:05:48 -04:00
Retroshare QML App: Implemesh some basic stuff
Implement location creation, selection and login Implement people listing Implement firends adding (not working yet) Depend on androidextra qt module only if compiling for android LibresapiLocalClient parse one line at time to avoid error if two requests are sent rapidly one after another LibresapiLocalClient socket path now is a parameter of openConnection() to use it as qml type constructor without parameter must be useful Added JSONListModel for JASON based MVC pattern
This commit is contained in:
parent
ad21d7202a
commit
8d6d3d1894
15 changed files with 565 additions and 99 deletions
39
retroshare-qml-app/src/qml/AddTrustedNode.qml
Normal file
39
retroshare-qml-app/src/qml/AddTrustedNode.qml
Normal file
|
@ -0,0 +1,39 @@
|
|||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.4
|
||||
import QtQuick.Layouts 1.3
|
||||
import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
||||
|
||||
Item
|
||||
{
|
||||
Component.onCompleted:
|
||||
{
|
||||
rsApi.openConnection(apiSocketPath)
|
||||
rsApi.request("/peers/self/certificate/", "")
|
||||
}
|
||||
|
||||
LibresapiLocalClient
|
||||
{
|
||||
id: rsApi
|
||||
onGoodResponseReceived: myKeyField.text = JSON.parse(msg).data.cert_string
|
||||
}
|
||||
|
||||
ColumnLayout
|
||||
{
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: bottomButton.top
|
||||
|
||||
TextField { id: myKeyField }
|
||||
TextField { id: otherKeyField }
|
||||
}
|
||||
|
||||
Button
|
||||
{
|
||||
id: bottomButton
|
||||
text: "Add trusted node"
|
||||
anchors.bottom: parent.bottom
|
||||
onClicked:
|
||||
{
|
||||
rsApi.request("/peers/examine_cert/", JSON.stringify({ cert_string: otherKeyField.text }))
|
||||
}
|
||||
}
|
||||
}
|
56
retroshare-qml-app/src/qml/Contacts.qml
Normal file
56
retroshare-qml-app/src/qml/Contacts.qml
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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
|
||||
{
|
||||
function refreshData()
|
||||
{
|
||||
rsApi.openConnection(apiSocketPath)
|
||||
rsApi.request("/identity/*/", "")
|
||||
}
|
||||
|
||||
Component.onCompleted: refreshData()
|
||||
onFocusChanged: focus && refreshData()
|
||||
|
||||
LibresapiLocalClient
|
||||
{
|
||||
id: rsApi
|
||||
onGoodResponseReceived: locationsModel.json = msg
|
||||
}
|
||||
|
||||
JSONListModel
|
||||
{
|
||||
id: locationsModel
|
||||
query: "$.data[*]"
|
||||
}
|
||||
|
||||
ListView
|
||||
{
|
||||
id: locationsListView
|
||||
width: parent.width
|
||||
height: 300
|
||||
model: locationsModel.model
|
||||
delegate: Text { text: model.name }
|
||||
}
|
||||
|
||||
Text { text: "Contacts View"; anchors.bottom: parent.bottom }
|
||||
}
|
51
retroshare-qml-app/src/qml/JSONListModel.qml
Normal file
51
retroshare-qml-app/src/qml/JSONListModel.qml
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* JSONListModel - a QML ListModel with JSON and JSONPath support
|
||||
*
|
||||
* Copyright (c) 2012 Romain Pokrzywka (KDAB) (romain@kdab.com)
|
||||
* Licensed under the MIT licence (http://opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "jsonpath.js" as JSONPath
|
||||
|
||||
Item {
|
||||
property string source: ""
|
||||
property string json: ""
|
||||
property string query: ""
|
||||
|
||||
property ListModel model : ListModel { id: jsonModel }
|
||||
property alias count: jsonModel.count
|
||||
|
||||
onSourceChanged: {
|
||||
var xhr = new XMLHttpRequest;
|
||||
xhr.open("GET", source);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == XMLHttpRequest.DONE)
|
||||
json = xhr.responseText;
|
||||
}
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
onJsonChanged: updateJSONModel()
|
||||
onQueryChanged: updateJSONModel()
|
||||
|
||||
function updateJSONModel() {
|
||||
jsonModel.clear();
|
||||
|
||||
if ( json === "" )
|
||||
return;
|
||||
|
||||
var objectArray = parseJSONString(json, query);
|
||||
for ( var key in objectArray ) {
|
||||
var jo = objectArray[key];
|
||||
jsonModel.append( jo );
|
||||
}
|
||||
}
|
||||
|
||||
function parseJSONString(jsonString, jsonPathQuery) {
|
||||
var objectArray = JSON.parse(jsonString);
|
||||
if ( jsonPathQuery !== "" )
|
||||
objectArray = JSONPath.jsonPath(objectArray, jsonPathQuery);
|
||||
|
||||
return objectArray;
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
import LibresapiLocalClientQml 1.0
|
||||
|
||||
LibresapiLocalClientComm {
|
||||
id: llc
|
||||
}
|
152
retroshare-qml-app/src/qml/Locations.qml
Normal file
152
retroshare-qml-app/src/qml/Locations.qml
Normal file
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* 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 QtQuick.Layouts 1.3
|
||||
import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
||||
|
||||
Item
|
||||
{
|
||||
id: locationView
|
||||
state: "selectLocation"
|
||||
|
||||
states:
|
||||
[
|
||||
State
|
||||
{
|
||||
name: "selectLocation"
|
||||
PropertyChanges { target: locationsListView; visible: true }
|
||||
PropertyChanges { target: createLocationView; visible: false }
|
||||
PropertyChanges
|
||||
{
|
||||
target: bottomButton
|
||||
text: "Create new location"
|
||||
onClicked: locationView.state = "createLocation"
|
||||
}
|
||||
},
|
||||
State
|
||||
{
|
||||
name: "createLocation"
|
||||
PropertyChanges { target: locationsListView; visible: false }
|
||||
PropertyChanges { target: createLocationView; visible: true }
|
||||
PropertyChanges
|
||||
{
|
||||
target: bottomButton
|
||||
text: "Save"
|
||||
onClicked:
|
||||
{
|
||||
var jsonData = { pgp_name: nameField.text, ssl_name: nameField.text, pgp_password: passwordField.text }
|
||||
rsApi.request("/control/create_location/", JSON.stringify(jsonData))
|
||||
onClicked: locationView.state = "savingLocation"
|
||||
}
|
||||
}
|
||||
},
|
||||
State
|
||||
{
|
||||
name: "savingLocation"
|
||||
PropertyChanges { target: locationsListView; visible: false }
|
||||
PropertyChanges { target: createLocationView; color: "grey" }
|
||||
PropertyChanges
|
||||
{
|
||||
target: bottomButton
|
||||
text: "Saving..."
|
||||
enabled: false
|
||||
}
|
||||
},
|
||||
State
|
||||
{
|
||||
name: "loggingIn"
|
||||
PropertyChanges { target: locationsListView; visible: false }
|
||||
PropertyChanges { target: createLocationView; visible: true }
|
||||
PropertyChanges { target: nameField; enabled: false}
|
||||
PropertyChanges
|
||||
{
|
||||
target: bottomButton
|
||||
text: "Login"
|
||||
enabled: true
|
||||
onClicked:
|
||||
{
|
||||
var jsonData = { id: nameField.sslid, autologin: false }
|
||||
rsApi.request("/control/login/", JSON.stringify(jsonData))
|
||||
jsonData = { password: passwordField.text }
|
||||
rsApi.request("/control/password/", JSON.stringify(jsonData))
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
Component.onCompleted:
|
||||
{
|
||||
rsApi.openConnection(apiSocketPath)
|
||||
rsApi.request("/control/locations/", "")
|
||||
}
|
||||
|
||||
LibresapiLocalClient
|
||||
{
|
||||
id: rsApi
|
||||
onGoodResponseReceived: locationsModel.json = msg
|
||||
}
|
||||
|
||||
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
|
||||
property string sslid: model.id
|
||||
onClicked:
|
||||
{
|
||||
locationView.state = "loggingIn"
|
||||
nameField.text = text
|
||||
}
|
||||
}
|
||||
visible: false
|
||||
}
|
||||
|
||||
ColumnLayout
|
||||
{
|
||||
id: createLocationView
|
||||
width: parent.width
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: bottomButton.top
|
||||
visible: false
|
||||
|
||||
Row { Text {text: "Name:" } TextField { id: nameField; property string sslid } }
|
||||
Row { Text {text: "Password:" } TextField { id: passwordField; echoMode: PasswordEchoOnEdit } }
|
||||
}
|
||||
|
||||
Text { text: "Locations View"; anchors.bottom: bottomButton.top }
|
||||
|
||||
Button
|
||||
{
|
||||
id: bottomButton
|
||||
text: "Create new location"
|
||||
anchors.bottom: parent.bottom
|
||||
}
|
||||
}
|
88
retroshare-qml-app/src/qml/jsonpath.js
Normal file
88
retroshare-qml-app/src/qml/jsonpath.js
Normal file
|
@ -0,0 +1,88 @@
|
|||
/* JSONPath 0.8.5 - XPath for JSON
|
||||
*
|
||||
* Copyright (c) 2007 Stefan Goessner (goessner.net)
|
||||
* Licensed under the MIT (MIT-LICENSE.txt) licence.
|
||||
*
|
||||
*/
|
||||
function jsonPath(obj, expr, arg) {
|
||||
var P = {
|
||||
resultType: arg && arg.resultType || "VALUE",
|
||||
result: [],
|
||||
normalize: function(expr) {
|
||||
var subx = [];
|
||||
return expr.replace(/[\['](\??\(.*?\))[\]']|\['(.*?)'\]/g, function($0,$1,$2){return "[#"+(subx.push($1||$2)-1)+"]";}) /* http://code.google.com/p/jsonpath/issues/detail?id=4 */
|
||||
.replace(/'?\.'?|\['?/g, ";")
|
||||
.replace(/;;;|;;/g, ";..;")
|
||||
.replace(/;$|'?\]|'$/g, "")
|
||||
.replace(/#([0-9]+)/g, function($0,$1){return subx[$1];});
|
||||
},
|
||||
asPath: function(path) {
|
||||
var x = path.split(";"), p = "$";
|
||||
for (var i=1,n=x.length; i<n; i++)
|
||||
p += /^[0-9*]+$/.test(x[i]) ? ("["+x[i]+"]") : ("['"+x[i]+"']");
|
||||
return p;
|
||||
},
|
||||
store: function(p, v) {
|
||||
if (p) P.result[P.result.length] = P.resultType == "PATH" ? P.asPath(p) : v;
|
||||
return !!p;
|
||||
},
|
||||
trace: function(expr, val, path) {
|
||||
if (expr !== "") {
|
||||
var x = expr.split(";"), loc = x.shift();
|
||||
x = x.join(";");
|
||||
if (val && val.hasOwnProperty(loc))
|
||||
P.trace(x, val[loc], path + ";" + loc);
|
||||
else if (loc === "*")
|
||||
P.walk(loc, x, val, path, function(m,l,x,v,p) { P.trace(m+";"+x,v,p); });
|
||||
else if (loc === "..") {
|
||||
P.trace(x, val, path);
|
||||
P.walk(loc, x, val, path, function(m,l,x,v,p) { typeof v[m] === "object" && P.trace("..;"+x,v[m],p+";"+m); });
|
||||
}
|
||||
else if (/^\(.*?\)$/.test(loc)) // [(expr)]
|
||||
P.trace(P.eval(loc, val, path.substr(path.lastIndexOf(";")+1))+";"+x, val, path);
|
||||
else if (/^\?\(.*?\)$/.test(loc)) // [?(expr)]
|
||||
P.walk(loc, x, val, path, function(m,l,x,v,p) { if (P.eval(l.replace(/^\?\((.*?)\)$/,"$1"), v instanceof Array ? v[m] : v, m)) P.trace(m+";"+x,v,p); }); // issue 5 resolved
|
||||
else if (/^(-?[0-9]*):(-?[0-9]*):?([0-9]*)$/.test(loc)) // [start:end:step] phyton slice syntax
|
||||
P.slice(loc, x, val, path);
|
||||
else if (/,/.test(loc)) { // [name1,name2,...]
|
||||
for (var s=loc.split(/'?,'?/),i=0,n=s.length; i<n; i++)
|
||||
P.trace(s[i]+";"+x, val, path);
|
||||
}
|
||||
}
|
||||
else
|
||||
P.store(path, val);
|
||||
},
|
||||
walk: function(loc, expr, val, path, f) {
|
||||
if (val instanceof Array) {
|
||||
for (var i=0,n=val.length; i<n; i++)
|
||||
if (i in val)
|
||||
f(i,loc,expr,val,path);
|
||||
}
|
||||
else if (typeof val === "object") {
|
||||
for (var m in val)
|
||||
if (val.hasOwnProperty(m))
|
||||
f(m,loc,expr,val,path);
|
||||
}
|
||||
},
|
||||
slice: function(loc, expr, val, path) {
|
||||
if (val instanceof Array) {
|
||||
var len=val.length, start=0, end=len, step=1;
|
||||
loc.replace(/^(-?[0-9]*):(-?[0-9]*):?(-?[0-9]*)$/g, function($0,$1,$2,$3){start=parseInt($1||start);end=parseInt($2||end);step=parseInt($3||step);});
|
||||
start = (start < 0) ? Math.max(0,start+len) : Math.min(len,start);
|
||||
end = (end < 0) ? Math.max(0,end+len) : Math.min(len,end);
|
||||
for (var i=start; i<end; i+=step)
|
||||
P.trace(i+";"+expr, val, path);
|
||||
}
|
||||
},
|
||||
eval: function(x, _v, _vname) {
|
||||
try { return $ && _v && eval(x.replace(/(^|[^\\])@/g, "$1_v").replace(/\\@/g, "@")); } // issue 7 : resolved ..
|
||||
catch(e) { throw new SyntaxError("jsonPath: " + e.message + ": " + x.replace(/(^|[^\\])@/g, "$1_v").replace(/\\@/g, "@")); } // issue 7 : resolved ..
|
||||
}
|
||||
};
|
||||
|
||||
var $ = obj;
|
||||
if (expr && obj && (P.resultType == "VALUE" || P.resultType == "PATH")) {
|
||||
P.trace(P.normalize(expr).replace(/^\$;?/,""), obj, "$"); // issue 6 resolved
|
||||
return P.result.length ? P.result : false;
|
||||
}
|
||||
}
|
|
@ -1,27 +1,98 @@
|
|||
//import QtQuick 2.7 //2.2
|
||||
//import QtQuick.Layouts 1.0 //1.1
|
||||
//import QtQuick.Controls 2.0 //1.1
|
||||
import "."
|
||||
/*
|
||||
* 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.2
|
||||
import QtQuick.Layouts 1.1
|
||||
import QtQuick.Controls 1.1 // millor fer servir 2.0 o més
|
||||
import LibresapiLocalClientQml 1.0
|
||||
import QtQuick.Controls 2.0
|
||||
import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
||||
|
||||
ApplicationWindow {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("RSChat")
|
||||
ApplicationWindow
|
||||
{
|
||||
id: mainWindow
|
||||
visible: true
|
||||
title: qsTr("RSChat")
|
||||
|
||||
Rectangle
|
||||
{
|
||||
id: mainView
|
||||
anchors.fill: parent;
|
||||
|
||||
states:
|
||||
[
|
||||
State
|
||||
{
|
||||
name: "waiting_account_select";
|
||||
PropertyChanges { target: swipeView; currentIndex: 1 }
|
||||
},
|
||||
State
|
||||
{
|
||||
name: "running_ok"
|
||||
PropertyChanges { target: swipeView; currentIndex: 2 }
|
||||
},
|
||||
State
|
||||
{
|
||||
name: "running_ok_no_full_control"
|
||||
PropertyChanges { target: swipeView; currentIndex: 2 }
|
||||
}
|
||||
]
|
||||
|
||||
LibresapiLocalClient
|
||||
{
|
||||
onGoodResponseReceived:
|
||||
{
|
||||
var jsonReponse = JSON.parse(msg)
|
||||
mainView.state = jsonReponse.data.runstate
|
||||
}
|
||||
Component.onCompleted:
|
||||
{
|
||||
openConnection(apiSocketPath)
|
||||
request("/control/runstate/", "")
|
||||
}
|
||||
}
|
||||
|
||||
SwipeView
|
||||
{
|
||||
id: swipeView
|
||||
anchors.fill: parent
|
||||
visible: true
|
||||
currentIndex: 1
|
||||
|
||||
Locations
|
||||
{
|
||||
id: locationsView
|
||||
visible: true
|
||||
}
|
||||
|
||||
AddTrustedNode
|
||||
{
|
||||
id: addTrustedNodeView
|
||||
visible: true
|
||||
}
|
||||
|
||||
Contacts
|
||||
{
|
||||
id: contactsView
|
||||
visible: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
LibresapiLocalClientComm{
|
||||
id: llc
|
||||
onGoodResponseReceived: gxss.title = msg
|
||||
|
||||
}*/
|
||||
onSceneGraphInitialized: llc.openConnection()
|
||||
onSceneGraphInitialized: llc.openConnection()
|
||||
|
||||
Rectangle {
|
||||
id: page
|
||||
|
@ -154,7 +225,5 @@ ApplicationWindow {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue