mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -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
@ -8,7 +8,8 @@ QT -= gui
|
||||
CONFIG += c++11
|
||||
CONFIG += dll
|
||||
|
||||
TEMPLATE = lib
|
||||
android-g++:TEMPLATE = lib
|
||||
!android-g++:TEMPLATE = app
|
||||
|
||||
SOURCES += service.cpp
|
||||
|
||||
|
@ -51,6 +51,8 @@ void LibresapiLocalClient::read()
|
||||
{
|
||||
receivedBytes = mLocalSocket.readLine();
|
||||
|
||||
qDebug() << receivedBytes;
|
||||
|
||||
if(parseResponse()) // pensar en fer un buffer per parsejar, per evitar errors.
|
||||
emit goodResponseReceived(QString(receivedBytes));
|
||||
else
|
||||
|
@ -45,10 +45,6 @@ int main(int argc, char *argv[])
|
||||
QString sockPath = QString::fromStdString(RsAccounts::ConfigDirectory());
|
||||
sockPath.append("/libresapi.sock");
|
||||
|
||||
#ifndef __ANDROID__
|
||||
sockPath = "/home/gio/.retroshare/LOC06_8730499b55bb946424d537b180bee10a/libresapi.sock";
|
||||
#endif
|
||||
|
||||
engine.rootContext()->setContextProperty("apiSocketPath", sockPath);
|
||||
engine.load(QUrl(QLatin1String("qrc:/qml/main.qml")));
|
||||
|
||||
|
@ -20,5 +20,6 @@
|
||||
<file>qml/JSONListModel.qml</file>
|
||||
<file>qml/Contacts.qml</file>
|
||||
<file>qml/AddTrustedNode.qml</file>
|
||||
<file>qml/RsLoginPassView.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -5,16 +5,24 @@ import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
||||
|
||||
Item
|
||||
{
|
||||
function refreshData() { rsApi.request("/peers/self/certificate/", "") }
|
||||
|
||||
Component.onCompleted:
|
||||
{
|
||||
rsApi.openConnection(apiSocketPath)
|
||||
rsApi.request("/peers/self/certificate/", "")
|
||||
refreshData()
|
||||
}
|
||||
onFocusChanged: focus && refreshData()
|
||||
|
||||
LibresapiLocalClient
|
||||
{
|
||||
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
|
||||
@ -22,7 +30,7 @@ Item
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: bottomButton.top
|
||||
|
||||
TextField { id: myKeyField }
|
||||
Text { id: myKeyField }
|
||||
TextField { id: otherKeyField }
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,6 @@ Item
|
||||
rsApi.request("/identity/*/", "")
|
||||
}
|
||||
|
||||
Component.onCompleted: refreshData()
|
||||
onFocusChanged: focus && refreshData()
|
||||
|
||||
LibresapiLocalClient
|
||||
|
@ -18,13 +18,15 @@
|
||||
|
||||
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"
|
||||
property var qParent
|
||||
property bool attemptLogin: false
|
||||
property string password
|
||||
|
||||
states:
|
||||
[
|
||||
@ -32,76 +34,103 @@ Item
|
||||
{
|
||||
name: "selectLocation"
|
||||
PropertyChanges { target: locationsListView; visible: true }
|
||||
PropertyChanges { target: createLocationView; visible: false }
|
||||
PropertyChanges
|
||||
{
|
||||
target: bottomButton
|
||||
text: "Create new location"
|
||||
onClicked: locationView.state = "createLocation"
|
||||
}
|
||||
PropertyChanges { target: bottomButton; visible: true }
|
||||
PropertyChanges { target: loginView; visible: false }
|
||||
},
|
||||
State
|
||||
{
|
||||
name: "createLocation"
|
||||
PropertyChanges { target: locationsListView; visible: false }
|
||||
PropertyChanges { target: createLocationView; visible: true }
|
||||
PropertyChanges { target: bottomButton; visible: false }
|
||||
PropertyChanges
|
||||
{
|
||||
target: bottomButton
|
||||
text: "Save"
|
||||
onClicked:
|
||||
target: loginView
|
||||
visible: true
|
||||
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))
|
||||
onClicked: locationView.state = "savingLocation"
|
||||
locationView.state = "selectLocation"
|
||||
}
|
||||
}
|
||||
},
|
||||
State
|
||||
{
|
||||
name: "savingLocation"
|
||||
name: "login"
|
||||
PropertyChanges { target: locationsListView; visible: false }
|
||||
PropertyChanges { target: createLocationView; color: "grey" }
|
||||
PropertyChanges { target: bottomButton; visible: false }
|
||||
PropertyChanges
|
||||
{
|
||||
target: bottomButton
|
||||
text: "Saving..."
|
||||
enabled: false
|
||||
}
|
||||
},
|
||||
State
|
||||
target: loginView
|
||||
visible: true
|
||||
onSubmit:
|
||||
{
|
||||
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))
|
||||
locationView.password = password
|
||||
rsApi.request("/control/login/", JSON.stringify({id: locationsListView.currentItem.sslid}))
|
||||
locationView.attemptLogin = true
|
||||
busyIndicator.running = true
|
||||
attemptTimer.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
Component.onCompleted:
|
||||
{
|
||||
rsApi.openConnection(apiSocketPath)
|
||||
rsApi.request("/control/locations/", "")
|
||||
}
|
||||
function requestLocationsList() { rsApi.request("/control/locations/", "") }
|
||||
|
||||
onFocusChanged: focus && requestLocationsList()
|
||||
|
||||
LibresapiLocalClient
|
||||
{
|
||||
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
|
||||
{
|
||||
@ -122,31 +151,40 @@ Item
|
||||
property string sslid: model.id
|
||||
onClicked:
|
||||
{
|
||||
locationView.state = "loggingIn"
|
||||
nameField.text = text
|
||||
loginView.login = text
|
||||
locationView.state = "login"
|
||||
}
|
||||
}
|
||||
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
|
||||
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
|
||||
{
|
||||
name: "waiting_account_select";
|
||||
PropertyChanges { target: swipeView; currentIndex: 1 }
|
||||
PropertyChanges { target: swipeView; currentIndex: locationsView.SwipeView.index }
|
||||
},
|
||||
State
|
||||
{
|
||||
name: "running_ok"
|
||||
PropertyChanges { target: swipeView; currentIndex: 2 }
|
||||
//PropertyChanges { target: swipeView; currentIndex: contactsView.SwipeView.index }
|
||||
},
|
||||
State
|
||||
{
|
||||
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
|
||||
anchors.fill: parent
|
||||
visible: true
|
||||
currentIndex: 1
|
||||
currentIndex: 0
|
||||
|
||||
Locations
|
||||
{
|
||||
id: locationsView
|
||||
visible: true
|
||||
qParent: swipeView
|
||||
}
|
||||
|
||||
AddTrustedNode
|
||||
@ -83,11 +84,34 @@ ApplicationWindow
|
||||
visible: true
|
||||
}
|
||||
|
||||
Rectangle
|
||||
{
|
||||
color: "red"
|
||||
width: 100
|
||||
height: 100
|
||||
}
|
||||
|
||||
Rectangle
|
||||
{
|
||||
color: "green"
|
||||
width: 100
|
||||
height: 100
|
||||
}
|
||||
|
||||
Rectangle
|
||||
{
|
||||
color: "blue"
|
||||
width: 100
|
||||
height: 100
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Contacts
|
||||
{
|
||||
id: contactsView
|
||||
visible: true
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user