Update RsPhotoItems and switch to GxsGroupDialog.

WIP improvements to PhotoService:
 - Switch from custom image to use RsGxsImage
 - Update classes for new Image class
 - fix serialiser for photos
 - switch group creation to use GxGroupDialog
 - tweak GxsGroupDialog to display extra Widgets
 - add AlbumExtra widget
This commit is contained in:
drbob 2020-02-15 01:01:19 +11:00
parent d88788f411
commit d04518fd55
23 changed files with 704 additions and 473 deletions

View file

@ -3,7 +3,7 @@
* *
* libretroshare: retroshare core library *
* *
* Copyright 2008-2012 by Robert Fernie <retroshare@lunamutt.com> *
* Copyright 2008-2020 by Robert Fernie <retroshare@lunamutt.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -26,6 +26,7 @@
#include <string>
#include <list>
#include "rsgxsservice.h"
#include "rsgxscommon.h"
/* The Main Interface Class - for information about your Peers */
class RsPhoto;
@ -37,21 +38,6 @@ extern RsPhoto *rsPhoto;
#define RSPHOTO_MODE_OWN 2
#define RSPHOTO_MODE_REMOTE 3
class RsPhotoThumbnail
{
public:
RsPhotoThumbnail()
:data(NULL), size(0), type("N/A") { return; }
bool deleteImage();
bool copyFrom(const RsPhotoThumbnail &nail);
// Holds Thumbnail image.
uint8_t *data;
uint32_t size;
std::string type;
};
/* If these flags are no set - the Photo inherits values from the Album
*/
@ -96,7 +82,7 @@ class RsPhotoPhoto
int mOrder;
RsPhotoThumbnail mThumbnail;
RsGxsImage mThumbnail;
int mMode;
@ -137,7 +123,7 @@ class RsPhotoAlbum
std::string mHashTags;
RsPhotoThumbnail mThumbnail;
RsGxsImage mThumbnail;
int mMode;

View file

@ -37,8 +37,8 @@ RsItem *RsGxsPhotoSerialiser::create_item(uint16_t service, uint8_t item_sub_id)
switch(item_sub_id)
{
case RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM: return new RsGxsPhotoCommentItem() ;
case RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM: return new RsGxsPhotoAlbumItem() ;
case RS_PKT_SUBTYPE_PHOTO_ITEM: return new RsGxsPhotoPhotoItem() ;
case RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM: return new RsGxsPhotoPhotoItem() ;
case RS_PKT_SUBTYPE_PHOTO_ITEM: return new RsGxsPhotoAlbumItem() ;
default:
return NULL ;
}
@ -55,25 +55,23 @@ void RsGxsPhotoAlbumItem::serial_process(RsGenericSerializer::SerializeJob j,RsG
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME, album.mPhotographer, "mPhotographer");
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DATE, album.mWhen, "mWhen");
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_LOCATION, album.mWhere, "mWhere");
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PIC_TYPE, album.mThumbnail.type,"mThumbnail.type");
RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO, album.mThumbnail.data, album.mThumbnail.size);
RsTypeSerializer::serial_process<RsTlvItem>(j, ctx, b, "thumbnail binary data") ;
RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO, album.mThumbnail.mData, album.mThumbnail.mSize);
RsTypeSerializer::serial_process<RsTlvItem>(j, ctx, b, "mThumbnail") ;
}
void RsGxsPhotoPhotoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_CAPTION, photo.mCaption, "mCaption");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_CATEGORY, photo.mCategory, "mCategory");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_DESCR, photo.mDescription, "mDescription");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_HASH_TAG, photo.mHashTags, "mHashTags");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_MSG, photo.mOther, "mOther");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_PIC_AUTH, photo.mPhotographer, "mPhotographer");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_DATE, photo.mWhen, "mWhen");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_LOCATION, photo.mWhere, "mWhere");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_PIC_TYPE, photo.mThumbnail.type, "mThumbnail.type");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_CAPTION, photo.mCaption, "mCaption");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_CATEGORY, photo.mCategory, "mCategory");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_DESCR, photo.mDescription, "mDescription");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_HASH_TAG, photo.mHashTags, "mHashTags");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_MSG, photo.mOther, "mOther");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_PIC_AUTH, photo.mPhotographer, "mPhotographer");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_DATE, photo.mWhen, "mWhen");
RsTypeSerializer::serial_process(j, ctx, TLV_TYPE_STR_LOCATION, photo.mWhere, "mWhere");
RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO, photo.mThumbnail.data, photo.mThumbnail.size);
RsTypeSerializer::serial_process<RsTlvItem>(j, ctx, b, "mThumbnail") ;
RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO, photo.mThumbnail.mData, photo.mThumbnail.mSize);
RsTypeSerializer::serial_process<RsTlvItem>(j, ctx, b, "mThumbnail") ;
}
void RsGxsPhotoCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
@ -83,16 +81,16 @@ void RsGxsPhotoCommentItem::serial_process(RsGenericSerializer::SerializeJob j,R
void RsGxsPhotoAlbumItem::clear()
{
album.mCaption.clear();
album.mCategory.clear();
album.mDescription.clear();
album.mHashTags.clear();
album.mOther.clear();
album.mPhotoPath.clear();
album.mPhotographer.clear();
album.mWhen.clear();
album.mWhere.clear();
album.mThumbnail.deleteImage();
album.mCaption.clear();
album.mCategory.clear();
album.mDescription.clear();
album.mHashTags.clear();
album.mOther.clear();
album.mPhotoPath.clear();
album.mPhotographer.clear();
album.mWhen.clear();
album.mWhere.clear();
album.mThumbnail.clear();
}
void RsGxsPhotoCommentItem::clear()
@ -103,13 +101,13 @@ void RsGxsPhotoCommentItem::clear()
void RsGxsPhotoPhotoItem::clear()
{
photo.mCaption.clear();
photo.mCategory.clear();
photo.mDescription.clear();
photo.mHashTags.clear();
photo.mOther.clear();
photo.mPhotographer.clear();
photo.mWhen.clear();
photo.mWhere.clear();
photo.mThumbnail.deleteImage();
photo.mCaption.clear();
photo.mCategory.clear();
photo.mDescription.clear();
photo.mHashTags.clear();
photo.mOther.clear();
photo.mPhotographer.clear();
photo.mWhen.clear();
photo.mWhere.clear();
photo.mThumbnail.clear();
}

View file

@ -30,56 +30,16 @@ const uint32_t RsPhoto::FLAG_MSG_TYPE_MASK = 0x000f;
const uint32_t RsPhoto::FLAG_MSG_TYPE_PHOTO_POST = 0x0001;
const uint32_t RsPhoto::FLAG_MSG_TYPE_PHOTO_COMMENT = 0x0002;
bool RsPhotoThumbnail::copyFrom(const RsPhotoThumbnail &nail)
{
if (data)
{
deleteImage();
}
if ((!nail.data) || (nail.size == 0))
{
return false;
}
size = nail.size;
type = nail.type;
data = (uint8_t *) rs_malloc(size);
if(data == NULL)
return false ;
memcpy(data, nail.data, size);
return true;
}
bool RsPhotoThumbnail::deleteImage()
{
if (data)
{
free(data);
data = NULL;
size = 0;
type.clear();
}
return true;
}
RsPhotoPhoto::RsPhotoPhoto()
:mSetFlags(0), mOrder(0), mMode(0), mModFlags(0)
:mSetFlags(0), mOrder(0), mMode(0), mModFlags(0)
{
return;
return;
}
RsPhotoAlbum::RsPhotoAlbum()
:mMode(0), mSetFlags(0), mModFlags(0)
:mMode(0), mSetFlags(0), mModFlags(0)
{
return;
return;
}
RsPhotoComment::RsPhotoComment()
@ -96,19 +56,19 @@ RsPhotoComment::RsPhotoComment(const RsGxsPhotoCommentItem &comment)
}
std::ostream &operator<<(std::ostream &out, const RsPhotoPhoto &photo)
{
out << "RsPhotoPhoto [ ";
out << "Title: " << photo.mMeta.mMsgName;
out << "]";
return out;
out << "RsPhotoPhoto [ ";
out << "Title: " << photo.mMeta.mMsgName;
out << "]";
return out;
}
std::ostream &operator<<(std::ostream &out, const RsPhotoAlbum &album)
{
out << "RsPhotoAlbum [ ";
out << "Title: " << album.mMeta.mGroupName;
out << "]";
return out;
out << "RsPhotoAlbum [ ";
out << "Title: " << album.mMeta.mGroupName;
out << "]";
return out;
}
p3PhotoService::p3PhotoService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs)
@ -125,7 +85,7 @@ const uint16_t GXS_PHOTO_MIN_MINOR_VERSION = 0;
RsServiceInfo p3PhotoService::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_GXS_TYPE_PHOTO,
return RsServiceInfo(RS_SERVICE_GXS_TYPE_PHOTO,
GXS_PHOTO_APP_NAME,
GXS_PHOTO_APP_MAJOR_VERSION,
GXS_PHOTO_APP_MINOR_VERSION,
@ -137,20 +97,20 @@ RsServiceInfo p3PhotoService::getServiceInfo()
uint32_t p3PhotoService::photoAuthenPolicy()
{
uint32_t policy = 0;
uint8_t flag = 0;
uint32_t policy = 0;
uint8_t flag = 0;
flag = GXS_SERV::MSG_AUTHEN_ROOT_PUBLISH_SIGN | GXS_SERV::MSG_AUTHEN_CHILD_AUTHOR_SIGN;
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::PUBLIC_GRP_BITS);
flag = GXS_SERV::MSG_AUTHEN_ROOT_PUBLISH_SIGN | GXS_SERV::MSG_AUTHEN_CHILD_AUTHOR_SIGN;
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::PUBLIC_GRP_BITS);
flag |= GXS_SERV::MSG_AUTHEN_CHILD_PUBLISH_SIGN;
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::RESTRICTED_GRP_BITS);
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::PRIVATE_GRP_BITS);
flag |= GXS_SERV::MSG_AUTHEN_CHILD_PUBLISH_SIGN;
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::RESTRICTED_GRP_BITS);
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::PRIVATE_GRP_BITS);
flag = GXS_SERV::GRP_OPTION_AUTHEN_AUTHOR_SIGN;
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::GRP_OPTION_BITS);
flag = GXS_SERV::GRP_OPTION_AUTHEN_AUTHOR_SIGN;
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::GRP_OPTION_BITS);
return policy;
return policy;
}
bool p3PhotoService::updated()
@ -175,14 +135,15 @@ void p3PhotoService::groupsChanged(std::list<RsGxsGroupId>& grpIds)
while(!mGroupChange.empty())
{
RsGxsGroupChange* gc = mGroupChange.back();
std::list<RsGxsGroupId>& gList = gc->mGrpIdList;
std::list<RsGxsGroupId>::iterator lit = gList.begin();
for(; lit != gList.end(); ++lit)
grpIds.push_back(*lit);
RsGxsGroupChange* gc = mGroupChange.back();
std::list<RsGxsGroupId>& gList = gc->mGrpIdList;
std::list<RsGxsGroupId>::iterator lit = gList.begin();
for(; lit != gList.end(); ++lit) {
grpIds.push_back(*lit);
}
mGroupChange.pop_back();
delete gc;
mGroupChange.pop_back();
delete gc;
}
}
@ -203,105 +164,107 @@ void p3PhotoService::msgsChanged(GxsMsgIdResult& msgs)
RsTokenService* p3PhotoService::getTokenService() {
return RsGenExchange::getTokenService();
return RsGenExchange::getTokenService();
}
bool p3PhotoService::getGroupList(const uint32_t& token,
std::list<RsGxsGroupId>& groupIds)
std::list<RsGxsGroupId>& groupIds)
{
return RsGenExchange::getGroupList(token, groupIds);
bool okay = RsGenExchange::getGroupList(token, groupIds);
return okay;
}
bool p3PhotoService::getMsgList(const uint32_t& token,
GxsMsgIdResult& msgIds)
GxsMsgIdResult& msgIds)
{
return RsGenExchange::getMsgList(token, msgIds);
return RsGenExchange::getMsgList(token, msgIds);
}
bool p3PhotoService::getGroupSummary(const uint32_t& token,
std::list<RsGroupMetaData>& groupInfo)
std::list<RsGroupMetaData>& groupInfo)
{
return RsGenExchange::getGroupMeta(token, groupInfo);
bool okay = RsGenExchange::getGroupMeta(token, groupInfo);
return okay;
}
bool p3PhotoService::getMsgSummary(const uint32_t& token,
MsgMetaResult& msgInfo)
MsgMetaResult& msgInfo)
{
return RsGenExchange::getMsgMeta(token, msgInfo);
return RsGenExchange::getMsgMeta(token, msgInfo);
}
bool p3PhotoService::getAlbum(const uint32_t& token, std::vector<RsPhotoAlbum>& albums)
{
std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData);
std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData);
if(ok)
{
std::vector<RsGxsGrpItem*>::iterator vit = grpData.begin();
if(ok)
{
std::vector<RsGxsGrpItem*>::iterator vit = grpData.begin();
for(; vit != grpData.end(); ++vit)
{
RsGxsPhotoAlbumItem* item = dynamic_cast<RsGxsPhotoAlbumItem*>(*vit);
if (item)
{
RsPhotoAlbum album = item->album;
item->album.mMeta = item->meta;
album.mMeta = item->album.mMeta;
delete item;
albums.push_back(album);
}
else
{
std::cerr << "Not a RsGxsPhotoAlbumItem, deleting!" << std::endl;
delete *vit;
}
}
}
for(; vit != grpData.end(); ++vit)
{
RsGxsPhotoAlbumItem* item = dynamic_cast<RsGxsPhotoAlbumItem*>(*vit);
if (item)
{
RsPhotoAlbum album = item->album;
item->album.mMeta = item->meta;
album.mMeta = item->album.mMeta;
delete item;
albums.push_back(album);
}
else
{
std::cerr << "Not a RsGxsPhotoAlbumItem, deleting!" << std::endl;
delete *vit;
}
}
}
return ok;
return ok;
}
bool p3PhotoService::getPhoto(const uint32_t& token, PhotoResult& photos)
{
GxsMsgDataMap msgData;
bool ok = RsGenExchange::getMsgData(token, msgData);
GxsMsgDataMap msgData;
bool ok = RsGenExchange::getMsgData(token, msgData);
if(ok)
{
GxsMsgDataMap::iterator mit = msgData.begin();
if(ok)
{
GxsMsgDataMap::iterator mit = msgData.begin();
for(; mit != msgData.end(); ++mit)
{
RsGxsGroupId grpId = mit->first;
std::vector<RsGxsMsgItem*>& msgItems = mit->second;
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
for(; mit != msgData.end(); ++mit)
{
RsGxsGroupId grpId = mit->first;
std::vector<RsGxsMsgItem*>& msgItems = mit->second;
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
for(; vit != msgItems.end(); ++vit)
{
RsGxsPhotoPhotoItem* item = dynamic_cast<RsGxsPhotoPhotoItem*>(*vit);
for(; vit != msgItems.end(); ++vit)
{
RsGxsPhotoPhotoItem* item = dynamic_cast<RsGxsPhotoPhotoItem*>(*vit);
if(item)
{
RsPhotoPhoto photo = item->photo;
photo.mMeta = item->meta;
photos[grpId].push_back(photo);
delete item;
}else
{
std::cerr << "Not a photo Item, deleting!" << std::endl;
delete *vit;
}
}
}
}
if(item)
{
RsPhotoPhoto photo = item->photo;
photo.mMeta = item->meta;
photos[grpId].push_back(photo);
delete item;
}else
{
std::cerr << "Not a photo Item, deleting!" << std::endl;
delete *vit;
}
}
}
}
return ok;
return ok;
}
bool p3PhotoService::getPhotoComment(const uint32_t &token, PhotoCommentResult &comments)
@ -349,9 +312,7 @@ RsPhotoComment& RsPhotoComment::operator=(const RsGxsPhotoCommentItem& comment)
bool p3PhotoService::getPhotoRelatedComment(const uint32_t &token, PhotoRelatedCommentResult &comments)
{
return RsGenExchange::getMsgRelatedDataT<RsGxsPhotoCommentItem, RsPhotoComment>(token, comments);
}
bool p3PhotoService::submitAlbumDetails(uint32_t& token, RsPhotoAlbum& album)
@ -379,28 +340,27 @@ void p3PhotoService::notifyChanges(std::vector<RsGxsNotify*>& changes)
RsGxsMsgChange* mc;
if((mc = dynamic_cast<RsGxsMsgChange*>(n)) != NULL)
{
mMsgChange.push_back(mc);
mMsgChange.push_back(mc);
}
else if((gc = dynamic_cast<RsGxsGroupChange*>(n)) != NULL)
{
mGroupChange.push_back(gc);
mGroupChange.push_back(gc);
}
else
{
delete n;
delete n;
}
}
}
bool p3PhotoService::submitPhoto(uint32_t& token, RsPhotoPhoto& photo)
{
RsGxsPhotoPhotoItem* photoItem = new RsGxsPhotoPhotoItem();
photoItem->photo = photo;
photoItem->meta = photo.mMeta;
photoItem->meta.mMsgFlags = FLAG_MSG_TYPE_PHOTO_POST;
RsGxsPhotoPhotoItem* photoItem = new RsGxsPhotoPhotoItem();
photoItem->photo = photo;
photoItem->meta = photo.mMeta;
RsGenExchange::publishMsg(token, photoItem);
return true;
RsGenExchange::publishMsg(token, photoItem);
return true;
}
bool p3PhotoService::submitComment(uint32_t &token, RsPhotoComment &comment)
@ -415,16 +375,16 @@ bool p3PhotoService::submitComment(uint32_t &token, RsPhotoComment &comment)
}
bool p3PhotoService::acknowledgeMsg(const uint32_t& token,
std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
{
return RsGenExchange::acknowledgeTokenMsg(token, msgId);
return RsGenExchange::acknowledgeTokenMsg(token, msgId);
}
bool p3PhotoService::acknowledgeGrp(const uint32_t& token,
RsGxsGroupId& grpId)
RsGxsGroupId& grpId)
{
return RsGenExchange::acknowledgeTokenGrp(token, grpId);
return RsGenExchange::acknowledgeTokenGrp(token, grpId);
}
bool p3PhotoService::subscribeToAlbum(uint32_t &token, const RsGxsGroupId &grpId, bool subscribe)