Merge pull request #890 from G10h4ck/qml_app_identity_avatar

Qml app identity avatar
This commit is contained in:
csoler 2017-06-21 07:42:15 +02:00 committed by GitHub
commit 310c848ca5
4 changed files with 95 additions and 7 deletions

View File

@ -22,6 +22,7 @@
#include <retroshare/rsidentity.h>
#include <retroshare/rspeers.h>
#include <util/radix64.h>
#include <time.h>
#include "Operators.h"
@ -500,6 +501,11 @@ void IdentityHandler::handleGetIdentityDetails(Request& req, Response& resp)
RsIdentityDetails details;
mRsIdentity->getIdDetails(RsGxsId(data.mMeta.mGroupId), details);
std::string base64Avatar;
Radix64::encode(details.mAvatar.mData, details.mAvatar.mSize, base64Avatar);
resp.mDataStream << makeKeyValue("avatar", base64Avatar);
StreamBase& usagesStream = resp.mDataStream.getStreamToMember("usages");
usagesStream.getStreamToMember();

View File

@ -0,0 +1,76 @@
/*
* RetroShare Android QML App
* Copyright (C) 2017 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.7
Item
{
id: compRoot
property string gxs_id
height: 130
width: height
////////////// The following should be considered privates /////////////////////
property bool has_avatar: false
property int avatarAttemptCnt: 0
function getDetails()
{
++compRoot.avatarAttemptCnt
rsApi.request(
"/identity/get_identity_details",
JSON.stringify({ gxs_id: compRoot.gxs_id }),
function(par)
{
var jData = JSON.parse(par.response).data
setDetails(jData)
if(!compRoot.has_avatar &&
compRoot.avatarAttemptCnt < 3) getDetails()
})
}
function setDetails(data)
{
compRoot.has_avatar = data.avatar.length > 0
if(compRoot.has_avatar)
{
contactAvatar.source =
"data:image/png;base64," + data.avatar
}
}
Component.onCompleted: if(visible && !has_avatar) getDetails()
onVisibleChanged: if(visible && !has_avatar) getDetails()
Image
{
id: contactAvatar
anchors.fill: parent
visible: compRoot.has_avatar
}
ColorHash
{
anchors.fill: parent
visible: !compRoot.has_avatar
hash: compRoot.gxs_id
}
}

View File

@ -27,21 +27,20 @@ Item
property var md
property bool is_contact: cntDt.md.is_contact
ColorHash
AvatarOrColorHash
{
id: colorHash
id: topFace
gxs_id: cntDt.md.gxs_id
anchors.top: parent.top
anchors.topMargin: 6
anchors.horizontalCenter: parent.horizontalCenter
height: 150
hash: cntDt.md.gxs_id
}
Column
{
anchors.top: colorHash.bottom
anchors.top: topFace.bottom
anchors.topMargin: 6
anchors.horizontalCenter: parent.horizontalCenter
@ -53,6 +52,13 @@ Item
anchors.horizontalCenter: parent.horizontalCenter
spacing: 6
ColorHash
{
hash: cntDt.md.gxs_id
height: parent.height - 10
anchors.verticalCenter: parent.verticalCenter
}
Text
{
text: cntDt.md.name
@ -61,7 +67,6 @@ Item
Image
{
source: cntDt.is_contact ?
"qrc:/icons/rating.png" :
"qrc:/icons/rating-unrated.png"

View File

@ -29,5 +29,6 @@
<file>icons/rating-unrated.png</file>
<file>icons/rating.png</file>
<file>TimedPopup.qml</file>
<file>AvatarOrColorHash.qml</file>
</qresource>
</RCC>