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:
Gio 2016-09-15 13:07:13 +02:00
parent ad21d7202a
commit 8d6d3d1894
15 changed files with 565 additions and 99 deletions

View file

@ -1,35 +1,39 @@
/*
* RetroShare Android QML App
* Copyright (C) 2016 Gioacchino Mazzurco <gio@eigenlab.org>
* Copyright (C) 2016 Manu Pineda <manu@cooperativa.cat>
*
* 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/>.
*/
#include "libresapilocalclient.h"
#include "debugutils.h"
#include <QChar>
/* Constructor de còpia per proves, no s'ha d'usar.
LibresapiLocalClient::LibresapiLocalClient(const LibresapiLocalClient & l)
{
//mLocalSocket = l.mLocalSocket;
receivedBytes = l.receivedBytes;
json = l.json;
}*/
LibresapiLocalClient::LibresapiLocalClient(const QString & socketPath) :
mLocalSocket(this)
void LibresapiLocalClient::openConnection(QString socketPath)
{
myDebug(this);
mSocketPath = socketPath;
connect(& mLocalSocket, SIGNAL(error(QLocalSocket::LocalSocketError)),
this, SLOT(socketError(QLocalSocket::LocalSocketError)));
connect(& mLocalSocket, SIGNAL(readyRead()),
this, SLOT(read()));
//openConnection();
}
void LibresapiLocalClient::openConnection()
{
mLocalSocket.connectToServer(mSocketPath);
connect(& mLocalSocket, SIGNAL(error(QLocalSocket::LocalSocketError)),
this, SLOT(socketError(QLocalSocket::LocalSocketError)));
connect(& mLocalSocket, SIGNAL(readyRead()),
this, SLOT(read()));
mLocalSocket.connectToServer(socketPath);
}
int LibresapiLocalClient::request(const QString & path, const QString & jsonData)
{
qDebug() << "LibresapiLocalClient::request()" << path << jsonData;
QByteArray data;
data.append(path); data.append('\n');
data.append(jsonData); data.append('\n');
@ -38,25 +42,24 @@ int LibresapiLocalClient::request(const QString & path, const QString & jsonData
return 1;
}
void LibresapiLocalClient::socketError(QLocalSocket::LocalSocketError error)
void LibresapiLocalClient::socketError(QLocalSocket::LocalSocketError)
{
myDebug("error!!!!\n" + mLocalSocket.errorString());//error.errorString());
myDebug("error!!!!\n" + mLocalSocket.errorString());
}
void LibresapiLocalClient::read()
{
receivedBytes = mLocalSocket.readAll();
if(parseResponse()){ // pensar en fer un buffer per parsejar, per evitar errors.
emit goodResponseReceived(QString(receivedBytes));
return;
}
QString errMess = "The message was not understood!\n"
"It should be a JSON formatted text file\n"
"Its contents were:\n" + receivedBytes;
myDebug(errMess.replace(QChar('\n'), QChar::LineSeparator));
receivedBytes = mLocalSocket.readLine();
if(parseResponse()) // pensar en fer un buffer per parsejar, per evitar errors.
emit goodResponseReceived(QString(receivedBytes));
else
{
QString errMess = "The message was not understood!\n"
"It should be a JSON formatted text file\n"
"Its contents were:\n" + receivedBytes;
myDebug(errMess.replace(QChar('\n'), QChar::LineSeparator));
}
}
bool LibresapiLocalClient::parseResponse()