mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-19 20:04:24 -04:00
Implemented login on Retroshare Android QML App
Login works fine but soon after retroshare-android-service crashes probably when trying to determine local address (getLocalAddresses) Added RsLoginPassView.qml generic login/pass/button view retroshare-android-service can be build as a separate app on non-android systems
This commit is contained in:
parent
8d6d3d1894
commit
c12cfd60b8
9 changed files with 195 additions and 74 deletions
|
@ -8,7 +8,8 @@ QT -= gui
|
||||||
CONFIG += c++11
|
CONFIG += c++11
|
||||||
CONFIG += dll
|
CONFIG += dll
|
||||||
|
|
||||||
TEMPLATE = lib
|
android-g++:TEMPLATE = lib
|
||||||
|
!android-g++:TEMPLATE = app
|
||||||
|
|
||||||
SOURCES += service.cpp
|
SOURCES += service.cpp
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,8 @@ void LibresapiLocalClient::read()
|
||||||
{
|
{
|
||||||
receivedBytes = mLocalSocket.readLine();
|
receivedBytes = mLocalSocket.readLine();
|
||||||
|
|
||||||
|
qDebug() << receivedBytes;
|
||||||
|
|
||||||
if(parseResponse()) // pensar en fer un buffer per parsejar, per evitar errors.
|
if(parseResponse()) // pensar en fer un buffer per parsejar, per evitar errors.
|
||||||
emit goodResponseReceived(QString(receivedBytes));
|
emit goodResponseReceived(QString(receivedBytes));
|
||||||
else
|
else
|
||||||
|
|
|
@ -45,10 +45,6 @@ int main(int argc, char *argv[])
|
||||||
QString sockPath = QString::fromStdString(RsAccounts::ConfigDirectory());
|
QString sockPath = QString::fromStdString(RsAccounts::ConfigDirectory());
|
||||||
sockPath.append("/libresapi.sock");
|
sockPath.append("/libresapi.sock");
|
||||||
|
|
||||||
#ifndef __ANDROID__
|
|
||||||
sockPath = "/home/gio/.retroshare/LOC06_8730499b55bb946424d537b180bee10a/libresapi.sock";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
engine.rootContext()->setContextProperty("apiSocketPath", sockPath);
|
engine.rootContext()->setContextProperty("apiSocketPath", sockPath);
|
||||||
engine.load(QUrl(QLatin1String("qrc:/qml/main.qml")));
|
engine.load(QUrl(QLatin1String("qrc:/qml/main.qml")));
|
||||||
|
|
||||||
|
|
|
@ -20,5 +20,6 @@
|
||||||
<file>qml/JSONListModel.qml</file>
|
<file>qml/JSONListModel.qml</file>
|
||||||
<file>qml/Contacts.qml</file>
|
<file>qml/Contacts.qml</file>
|
||||||
<file>qml/AddTrustedNode.qml</file>
|
<file>qml/AddTrustedNode.qml</file>
|
||||||
|
<file>qml/RsLoginPassView.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -5,16 +5,24 @@ import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
||||||
|
|
||||||
Item
|
Item
|
||||||
{
|
{
|
||||||
|
function refreshData() { rsApi.request("/peers/self/certificate/", "") }
|
||||||
|
|
||||||
Component.onCompleted:
|
Component.onCompleted:
|
||||||
{
|
{
|
||||||
rsApi.openConnection(apiSocketPath)
|
rsApi.openConnection(apiSocketPath)
|
||||||
rsApi.request("/peers/self/certificate/", "")
|
refreshData()
|
||||||
}
|
}
|
||||||
|
onFocusChanged: focus && refreshData()
|
||||||
|
|
||||||
LibresapiLocalClient
|
LibresapiLocalClient
|
||||||
{
|
{
|
||||||
id: rsApi
|
id: rsApi
|
||||||
onGoodResponseReceived: myKeyField.text = JSON.parse(msg).data.cert_string
|
onGoodResponseReceived:
|
||||||
|
{
|
||||||
|
var jsonData = JSON.parse(msg)
|
||||||
|
if(jsonData && jsonData.data && jsonData.data.cert_string)
|
||||||
|
myKeyField.text = jsonData.data.cert_string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout
|
ColumnLayout
|
||||||
|
@ -22,7 +30,7 @@ Item
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.bottom: bottomButton.top
|
anchors.bottom: bottomButton.top
|
||||||
|
|
||||||
TextField { id: myKeyField }
|
Text { id: myKeyField }
|
||||||
TextField { id: otherKeyField }
|
TextField { id: otherKeyField }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ Item
|
||||||
rsApi.request("/identity/*/", "")
|
rsApi.request("/identity/*/", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: refreshData()
|
|
||||||
onFocusChanged: focus && refreshData()
|
onFocusChanged: focus && refreshData()
|
||||||
|
|
||||||
LibresapiLocalClient
|
LibresapiLocalClient
|
||||||
|
|
|
@ -18,13 +18,15 @@
|
||||||
|
|
||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
import QtQuick.Controls 1.4
|
import QtQuick.Controls 1.4
|
||||||
import QtQuick.Layouts 1.3
|
|
||||||
import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
||||||
|
|
||||||
Item
|
Item
|
||||||
{
|
{
|
||||||
id: locationView
|
id: locationView
|
||||||
state: "selectLocation"
|
state: "selectLocation"
|
||||||
|
property var qParent
|
||||||
|
property bool attemptLogin: false
|
||||||
|
property string password
|
||||||
|
|
||||||
states:
|
states:
|
||||||
[
|
[
|
||||||
|
@ -32,77 +34,104 @@ Item
|
||||||
{
|
{
|
||||||
name: "selectLocation"
|
name: "selectLocation"
|
||||||
PropertyChanges { target: locationsListView; visible: true }
|
PropertyChanges { target: locationsListView; visible: true }
|
||||||
PropertyChanges { target: createLocationView; visible: false }
|
PropertyChanges { target: bottomButton; visible: true }
|
||||||
PropertyChanges
|
PropertyChanges { target: loginView; visible: false }
|
||||||
{
|
|
||||||
target: bottomButton
|
|
||||||
text: "Create new location"
|
|
||||||
onClicked: locationView.state = "createLocation"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
State
|
State
|
||||||
{
|
{
|
||||||
name: "createLocation"
|
name: "createLocation"
|
||||||
PropertyChanges { target: locationsListView; visible: false }
|
PropertyChanges { target: locationsListView; visible: false }
|
||||||
PropertyChanges { target: createLocationView; visible: true }
|
PropertyChanges { target: bottomButton; visible: false }
|
||||||
PropertyChanges
|
PropertyChanges
|
||||||
{
|
{
|
||||||
target: bottomButton
|
target: loginView
|
||||||
text: "Save"
|
visible: true
|
||||||
onClicked:
|
buttonText: "Save"
|
||||||
|
onSubmit:
|
||||||
{
|
{
|
||||||
var jsonData = { pgp_name: nameField.text, ssl_name: nameField.text, pgp_password: passwordField.text }
|
var jsonData = { pgp_name: login, ssl_name: login, pgp_password: password }
|
||||||
rsApi.request("/control/create_location/", JSON.stringify(jsonData))
|
rsApi.request("/control/create_location/", JSON.stringify(jsonData))
|
||||||
onClicked: locationView.state = "savingLocation"
|
locationView.state = "selectLocation"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
State
|
State
|
||||||
{
|
{
|
||||||
name: "savingLocation"
|
name: "login"
|
||||||
PropertyChanges { target: locationsListView; visible: false }
|
PropertyChanges { target: locationsListView; visible: false }
|
||||||
PropertyChanges { target: createLocationView; color: "grey" }
|
PropertyChanges { target: bottomButton; visible: false }
|
||||||
PropertyChanges
|
PropertyChanges
|
||||||
{
|
{
|
||||||
target: bottomButton
|
target: loginView
|
||||||
text: "Saving..."
|
visible: true
|
||||||
enabled: false
|
onSubmit:
|
||||||
}
|
|
||||||
},
|
|
||||||
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 }
|
locationView.password = password
|
||||||
rsApi.request("/control/login/", JSON.stringify(jsonData))
|
rsApi.request("/control/login/", JSON.stringify({id: locationsListView.currentItem.sslid}))
|
||||||
jsonData = { password: passwordField.text }
|
locationView.attemptLogin = true
|
||||||
rsApi.request("/control/password/", JSON.stringify(jsonData))
|
busyIndicator.running = true
|
||||||
|
attemptTimer.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
Component.onCompleted:
|
function requestLocationsList() { rsApi.request("/control/locations/", "") }
|
||||||
{
|
|
||||||
rsApi.openConnection(apiSocketPath)
|
onFocusChanged: focus && requestLocationsList()
|
||||||
rsApi.request("/control/locations/", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
LibresapiLocalClient
|
LibresapiLocalClient
|
||||||
{
|
{
|
||||||
id: rsApi
|
id: rsApi
|
||||||
onGoodResponseReceived: locationsModel.json = msg
|
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
|
JSONListModel
|
||||||
{
|
{
|
||||||
id: locationsModel
|
id: locationsModel
|
||||||
|
@ -122,31 +151,40 @@ Item
|
||||||
property string sslid: model.id
|
property string sslid: model.id
|
||||||
onClicked:
|
onClicked:
|
||||||
{
|
{
|
||||||
locationView.state = "loggingIn"
|
loginView.login = text
|
||||||
nameField.text = text
|
locationView.state = "login"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
visible: false
|
visible: false
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout
|
Button
|
||||||
{
|
{
|
||||||
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
|
id: bottomButton
|
||||||
text: "Create new location"
|
text: "Create new location"
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
|
onClicked: locationView.state = "createLocation"
|
||||||
|
}
|
||||||
|
|
||||||
|
RsLoginPassView
|
||||||
|
{
|
||||||
|
id: loginView
|
||||||
|
visible: false
|
||||||
|
anchors.fill: parent
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer
|
||||||
|
{
|
||||||
|
id: attemptTimer
|
||||||
|
interval: 500
|
||||||
|
repeat: true
|
||||||
|
onTriggered:
|
||||||
|
{
|
||||||
|
if(locationView.focus)
|
||||||
|
locationView.requestLocationsList()
|
||||||
|
|
||||||
|
if (locationView.attemptLogin)
|
||||||
|
rsApi.request("/control/password/", "")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
52
retroshare-qml-app/src/qml/RsLoginPassView.qml
Normal file
52
retroshare-qml-app/src/qml/RsLoginPassView.qml
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* 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.Layouts 1.3
|
||||||
|
import QtQuick.Controls 1.4
|
||||||
|
import QtQml 2.2
|
||||||
|
import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
||||||
|
|
||||||
|
Item
|
||||||
|
{
|
||||||
|
id: loginView
|
||||||
|
property string buttonText: "Login"
|
||||||
|
property string login
|
||||||
|
property string password
|
||||||
|
signal submit(string login, string password)
|
||||||
|
|
||||||
|
ColumnLayout
|
||||||
|
{
|
||||||
|
id: inputView
|
||||||
|
width: parent.width
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.bottom: bottomButton.top
|
||||||
|
|
||||||
|
Row { Text {text: "Name:" } TextField { id: nameField; text: loginView.login } }
|
||||||
|
Row { Text {text: "Password:" } TextField { id: passwordField; text: loginView.password } }
|
||||||
|
}
|
||||||
|
|
||||||
|
Button
|
||||||
|
{
|
||||||
|
id: bottomButton
|
||||||
|
text: loginView.buttonText
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.right: parent.right
|
||||||
|
onClicked: loginView.submit(nameField.text, passwordField.text)
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,17 +36,17 @@ ApplicationWindow
|
||||||
State
|
State
|
||||||
{
|
{
|
||||||
name: "waiting_account_select";
|
name: "waiting_account_select";
|
||||||
PropertyChanges { target: swipeView; currentIndex: 1 }
|
PropertyChanges { target: swipeView; currentIndex: locationsView.SwipeView.index }
|
||||||
},
|
},
|
||||||
State
|
State
|
||||||
{
|
{
|
||||||
name: "running_ok"
|
name: "running_ok"
|
||||||
PropertyChanges { target: swipeView; currentIndex: 2 }
|
//PropertyChanges { target: swipeView; currentIndex: contactsView.SwipeView.index }
|
||||||
},
|
},
|
||||||
State
|
State
|
||||||
{
|
{
|
||||||
name: "running_ok_no_full_control"
|
name: "running_ok_no_full_control"
|
||||||
PropertyChanges { target: swipeView; currentIndex: 2 }
|
//PropertyChanges { target: swipeView; currentIndex: contactsView.SwipeView.index }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -69,12 +69,13 @@ ApplicationWindow
|
||||||
id: swipeView
|
id: swipeView
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
visible: true
|
visible: true
|
||||||
currentIndex: 1
|
currentIndex: 0
|
||||||
|
|
||||||
Locations
|
Locations
|
||||||
{
|
{
|
||||||
id: locationsView
|
id: locationsView
|
||||||
visible: true
|
visible: true
|
||||||
|
qParent: swipeView
|
||||||
}
|
}
|
||||||
|
|
||||||
AddTrustedNode
|
AddTrustedNode
|
||||||
|
@ -83,11 +84,34 @@ ApplicationWindow
|
||||||
visible: true
|
visible: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rectangle
|
||||||
|
{
|
||||||
|
color: "red"
|
||||||
|
width: 100
|
||||||
|
height: 100
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle
|
||||||
|
{
|
||||||
|
color: "green"
|
||||||
|
width: 100
|
||||||
|
height: 100
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle
|
||||||
|
{
|
||||||
|
color: "blue"
|
||||||
|
width: 100
|
||||||
|
height: 100
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
Contacts
|
Contacts
|
||||||
{
|
{
|
||||||
id: contactsView
|
id: contactsView
|
||||||
visible: true
|
visible: true
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue