diff --git a/libretroshare/src/dbase/fimonitor.cc b/libretroshare/src/dbase/fimonitor.cc index c4f60ee81..765798484 100644 --- a/libretroshare/src/dbase/fimonitor.cc +++ b/libretroshare/src/dbase/fimonitor.cc @@ -431,7 +431,7 @@ int FileIndexMonitor::filterResults(std::list& firesults,std::list& parent_groups) const +bool FileIndexMonitor::findLocalFile(const RsFileHash& hash,FileSearchFlags hint_flags, const RsPeerId& peer_id,std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list& parent_groups) const { std::list results; bool ok = false; @@ -1668,7 +1668,7 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, FileSear return true ; } -void FileIndexMonitor::locked_findShareFlagsAndParentGroups(FileEntry *file,FileStorageFlags& flags,std::list& parent_groups) const +void FileIndexMonitor::locked_findShareFlagsAndParentGroups(FileEntry *file,FileStorageFlags& flags,std::list& parent_groups) const { flags.clear() ; static const FileStorageFlags PERMISSION_MASK = DIR_FLAGS_BROWSABLE_OTHERS | DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | DIR_FLAGS_NETWORK_WIDE_GROUPS ; diff --git a/libretroshare/src/dbase/fimonitor.h b/libretroshare/src/dbase/fimonitor.h index dc616625d..f57ebb5c8 100644 --- a/libretroshare/src/dbase/fimonitor.h +++ b/libretroshare/src/dbase/fimonitor.h @@ -110,7 +110,7 @@ class FileIndexMonitor: public CacheSource, public RsTickingThread virtual ~FileIndexMonitor(); /* external interface for filetransfer */ - bool findLocalFile(const RsFileHash& hash,FileSearchFlags flags,const RsPeerId& peer_id, std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list& parent_groups) const; + bool findLocalFile(const RsFileHash& hash,FileSearchFlags flags,const RsPeerId& peer_id, std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list& parent_groups) const; int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id) ; int SearchBoolExp(Expression *exp, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id) const ; @@ -176,7 +176,7 @@ class FileIndexMonitor: public CacheSource, public RsTickingThread time_t locked_saveFileIndexes(bool update_cache) ; // Finds the share flags associated with this file entry. - void locked_findShareFlagsAndParentGroups(FileEntry *fe,FileStorageFlags& shareflags,std::list& parent_groups) const ; + void locked_findShareFlagsAndParentGroups(FileEntry *fe, FileStorageFlags& shareflags, std::list &parent_groups) const ; std::string locked_findRealRoot(std::string base) const; diff --git a/libretroshare/src/ft/ftdbase.cc b/libretroshare/src/ft/ftdbase.cc index fd0285552..ef68304d8 100644 --- a/libretroshare/src/ft/ftdbase.cc +++ b/libretroshare/src/ft/ftdbase.cc @@ -25,6 +25,7 @@ #include "ft/ftdbase.h" #include "util/rsdir.h" +#include "retroshare/rspeers.h" #include "serialiser/rsconfigitems.h" @@ -237,11 +238,13 @@ bool ftFiMonitor::saveList(bool &cleanup, std::list& sList) for(it = dirList.begin(); it != dirList.end(); ++it) { - RsFileConfigItem *fi = new RsFileConfigItem(); + RsFileConfigItem *fi = new RsFileConfigItem(); fi->file.path = (*it).filename ; fi->file.name = (*it).virtualname ; fi->flags = (*it).shareflags.toUInt32() ; - fi->parent_groups = (*it).parent_groups ; + + for(std::list::const_iterator it2( (*it).parent_groups.begin());it2!=(*it).parent_groups.end();++it2) + fi->parent_groups.ids.insert(*it2) ; sList.push_back(fi); } @@ -332,25 +335,53 @@ bool ftFiMonitor::loadList(std::list& load) continue ; } - RsFileConfigItem *fi = dynamic_cast(*it); - if (!fi) - { - delete (*it); - continue; - } + // 07/05/2016 - This ensures backward compatibility. Can be removed in a few weeks. + RsFileConfigItem_deprecated *fib = dynamic_cast(*it); + if (fib) + { + /* ensure that it exists? */ - /* ensure that it exists? */ + SharedDirInfo info ; + info.filename = RsDirUtil::convertPathToUnix(fib->file.path); + info.virtualname = fib->file.name; + info.shareflags = FileStorageFlags(fib->flags) ; + info.shareflags &= PERMISSION_MASK ; + info.shareflags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // disabling this flag for know, for consistency reasons - SharedDirInfo info ; - info.filename = RsDirUtil::convertPathToUnix(fi->file.path); - info.virtualname = fi->file.name; - info.parent_groups = fi->parent_groups; - info.shareflags = FileStorageFlags(fi->flags) ; - info.shareflags &= PERMISSION_MASK ; - info.shareflags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // disabling this flag for know, for consistency reasons + for(std::list::const_iterator itt(fib->parent_groups.begin());itt!=fib->parent_groups.end();++itt) + { + RsGroupInfo ginfo; + + if(rsPeers->getGroupInfoByName(*itt,ginfo) ) + { + info.parent_groups.push_back(ginfo.id) ; + std::cerr << "(II) converted old group ID \"" << *itt << "\" into corresponding new group id " << ginfo.id << std::endl; + } + else + std::cerr << "(EE) cannot convert old group ID \"" << *itt << "\" into corresponding new group id: no candidate found. " << std::endl; + } + + dirList.push_back(info) ; + } + + RsFileConfigItem *fi = dynamic_cast(*it); + if (fi) + { + /* ensure that it exists? */ + + SharedDirInfo info ; + info.filename = RsDirUtil::convertPathToUnix(fi->file.path); + info.virtualname = fi->file.name; + info.shareflags = FileStorageFlags(fi->flags) ; + info.shareflags &= PERMISSION_MASK ; + info.shareflags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // disabling this flag for know, for consistency reasons + + for(std::set::const_iterator itt(fi->parent_groups.ids.begin());itt!=fi->parent_groups.ids.end();++itt) + info.parent_groups.push_back(*itt) ; + + dirList.push_back(info) ; + } - dirList.push_back(info) ; - delete *it ; } diff --git a/libretroshare/src/ft/ftextralist.cc b/libretroshare/src/ft/ftextralist.cc index d2fb76151..094e07c8d 100644 --- a/libretroshare/src/ft/ftextralist.cc +++ b/libretroshare/src/ft/ftextralist.cc @@ -395,7 +395,7 @@ bool ftExtraList::saveList(bool &cleanup, std::list& sList) std::map::const_iterator it; for(it = mFiles.begin(); it != mFiles.end(); ++it) { - RsFileConfigItem *fi = new RsFileConfigItem(); + RsFileConfigItem_deprecated *fi = new RsFileConfigItem_deprecated(); fi->file.path = (it->second).info.path; fi->file.name = (it->second).info.fname; fi->file.hash = (it->second).info.hash; @@ -428,7 +428,7 @@ bool ftExtraList::loadList(std::list& load) for(it = load.begin(); it != load.end(); ++it) { - RsFileConfigItem *fi = dynamic_cast(*it); + RsFileConfigItem_deprecated *fi = dynamic_cast(*it); if (!fi) { delete (*it); diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index f6271b003..c54019100 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -2575,6 +2575,19 @@ bool p3PeerMgrIMPL::removeGroup(const RsNodeGroupId& groupId) return changed; } +bool p3PeerMgrIMPL::getGroupInfoByName(const std::string& groupName, RsGroupInfo &groupInfo) +{ + RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ + + for(std::map::iterator it = groupList.begin();it!=groupList.end();++it) + if(it->second.name == groupName) + { + groupInfo = it->second ; + return true ; + } + + return false ; +} bool p3PeerMgrIMPL::getGroupInfo(const RsNodeGroupId& groupId, RsGroupInfo &groupInfo) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index e73377677..ee581b275 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -142,6 +142,7 @@ virtual bool addGroup(RsGroupInfo &groupInfo) = 0; virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo) = 0; virtual bool removeGroup(const RsNodeGroupId &groupId) = 0; virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo) = 0; +virtual bool getGroupInfoByName(const std::string& groupName, RsGroupInfo &groupInfo) = 0; virtual bool getGroupInfoList(std::list &groupInfoList) = 0; virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list &peerIds, bool assign) = 0; @@ -256,6 +257,7 @@ public: virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo); virtual bool removeGroup(const RsNodeGroupId &groupId); virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo); + virtual bool getGroupInfoByName(const std::string& groupName, RsGroupInfo &groupInfo) ; virtual bool getGroupInfoList(std::list &groupInfoList); virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list &peerIds, bool assign); diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index c6480b540..e528fa916 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -99,7 +99,7 @@ struct SharedDirInfo std::string filename ; std::string virtualname ; FileStorageFlags shareflags ; // DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | ... - std::list parent_groups ; + std::list parent_groups ; }; class RsFiles diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 6d9246c81..073700b71 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -409,6 +409,7 @@ public: virtual bool editGroup(const RsNodeGroupId& groupId, RsGroupInfo& groupInfo) = 0; virtual bool removeGroup(const RsNodeGroupId& groupId) = 0; virtual bool getGroupInfo(const RsNodeGroupId& groupId, RsGroupInfo& groupInfo) = 0; + virtual bool getGroupInfoByName(const std::string& groupId, RsGroupInfo& groupInfo) = 0; virtual bool getGroupInfoList(std::list& groupInfoList) = 0; // groupId == "" && assign == false -> remove from all groups virtual bool assignPeerToGroup(const RsNodeGroupId& groupId, const RsPgpId& peerId, bool assign) = 0; @@ -427,7 +428,7 @@ public: // virtual FileSearchFlags computePeerPermissionFlags( const RsPeerId& peer_id, FileStorageFlags file_sharing_flags, - const std::list& file_parent_groups) = 0; + const std::list& file_parent_groups) = 0; /* Service permission flags */ diff --git a/libretroshare/src/retroshare/rstypes.h b/libretroshare/src/retroshare/rstypes.h index 37975d605..0ef72e9dc 100644 --- a/libretroshare/src/retroshare/rstypes.h +++ b/libretroshare/src/retroshare/rstypes.h @@ -211,7 +211,7 @@ class FileInfo DwlSpeed priority ; time_t lastTS; - std::list parent_groups ; + std::list parent_groups ; }; std::ostream &operator<<(std::ostream &out, const FileInfo &info); @@ -243,7 +243,7 @@ class DirDetails uint32_t min_age ; // minimum age of files in this subtree std::list children; - std::list parent_groups; // parent groups for the shared directory + std::list parent_groups; // parent groups for the shared directory }; class FileDetail diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index e0dff3dd6..cbe2a2dde 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -1303,6 +1303,14 @@ bool p3Peers::removeGroup(const RsNodeGroupId &groupId) return res ; } +bool p3Peers::getGroupInfoByName(const std::string& groupName, RsGroupInfo &groupInfo) +{ +#ifdef P3PEERS_DEBUG + std::cerr << "p3Peers::getGroupInfo()" << std::endl; +#endif + + return mPeerMgr->getGroupInfoByName(groupName, groupInfo); +} bool p3Peers::getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo) { #ifdef P3PEERS_DEBUG @@ -1343,7 +1351,7 @@ bool p3Peers::assignPeersToGroup(const RsNodeGroupId &groupId, const std::list& directory_parent_groups) + const std::list& directory_parent_groups) { // We should be able to do that in O(1), using groups based on packs of bits. // @@ -1354,7 +1362,7 @@ FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id, bool found = false ; RsPgpId pgp_id = getGPGId(peer_ssl_id) ; - for(std::list::const_iterator it(directory_parent_groups.begin());it!=directory_parent_groups.end() && !found;++it) + for(std::list::const_iterator it(directory_parent_groups.begin());it!=directory_parent_groups.end() && !found;++it) { RsGroupInfo info ; if(!getGroupInfo(*it,info)) diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index 7a67039f0..38fad1c7b 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -127,11 +127,12 @@ public: virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo); virtual bool removeGroup(const RsNodeGroupId &groupId); virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo); - virtual bool getGroupInfoList(std::list &groupInfoList); + virtual bool getGroupInfoByName(const std::string& groupName, RsGroupInfo& groupInfo); + virtual bool getGroupInfoList(std::list &groupInfoList); virtual bool assignPeerToGroup(const RsNodeGroupId &groupId, const RsPgpId &peerId, bool assign); virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list& peerIds, bool assign); - virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id,FileStorageFlags share_flags,const std::list& parent_groups); + virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id, FileStorageFlags share_flags, const std::list &parent_groups); // service permission stuff diff --git a/libretroshare/src/serialiser/rsconfigitems.cc b/libretroshare/src/serialiser/rsconfigitems.cc index 6e040f0dd..db0aa5dcf 100644 --- a/libretroshare/src/serialiser/rsconfigitems.cc +++ b/libretroshare/src/serialiser/rsconfigitems.cc @@ -43,34 +43,34 @@ uint32_t RsFileConfigSerialiser::size(RsItem *i) { RsFileTransfer *rft; - RsFileConfigItem *rfi; + RsFileConfigItem *rfj; if (NULL != (rft = dynamic_cast(i))) { return sizeTransfer(rft); } - if (NULL != (rfi = dynamic_cast(i))) - { - return sizeFileItem(rfi); - } - return 0; + if (NULL != (rfj = dynamic_cast(i))) + { + return sizeFileItem(rfj); + } + return 0; } /* serialise the data to the buffer */ bool RsFileConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) { RsFileTransfer *rft; - RsFileConfigItem *rfi; + RsFileConfigItem *rfj; if (NULL != (rft = dynamic_cast(i))) { return serialiseTransfer(rft, data, pktsize); } - if (NULL != (rfi = dynamic_cast(i))) - { - return serialiseFileItem(rfi, data, pktsize); - } - return false; + if (NULL != (rfj = dynamic_cast(i))) + { + return serialiseFileItem(rfj, data, pktsize); + } + return false; } RsItem *RsFileConfigSerialiser::deserialise(void *data, uint32_t *pktsize) @@ -90,10 +90,13 @@ RsItem *RsFileConfigSerialiser::deserialise(void *data, uint32_t *pktsize) case RS_PKT_SUBTYPE_FILE_TRANSFER: return deserialiseTransfer(data, pktsize); break; - case RS_PKT_SUBTYPE_FILE_ITEM: - return deserialiseFileItem(data, pktsize); + case RS_PKT_SUBTYPE_FILE_ITEM_deprecated: + return deserialiseFileItem_deprecated(data, pktsize); break; - default: + case RS_PKT_SUBTYPE_FILE_ITEM: + return deserialiseFileItem(data, pktsize); + break; + default: return NULL; break; } @@ -158,20 +161,20 @@ std::ostream &RsFileTransfer::print(std::ostream &out, uint16_t indent) /*************************************************************************/ /*************************************************************************/ -RsFileConfigItem::~RsFileConfigItem() +void RsFileConfigItem_deprecated::clear() { - return; -} - -void RsFileConfigItem::clear() -{ - file.TlvClear(); flags = 0; parent_groups.clear() ; } -std::ostream &RsFileConfigItem::print(std::ostream &out, uint16_t indent) +void RsFileConfigItem::clear() +{ + file.TlvClear(); + flags = 0; + parent_groups.TlvClear() ; +} +std::ostream &RsFileConfigItem_deprecated::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsFileConfigItem", indent); uint16_t int_Indent = indent + 2; @@ -188,6 +191,22 @@ std::ostream &RsFileConfigItem::print(std::ostream &out, uint16_t indent) return out; } +std::ostream &RsFileConfigItem::print(std::ostream &out, uint16_t indent) +{ + printRsItemBase(out, "RsFileConfigItem", indent); + uint16_t int_Indent = indent + 2; + file.print(out, int_Indent); + + printIndent(out, int_Indent); out << "flags: " << flags << std::endl; + printIndent(out, int_Indent); out << "groups:" ; + + for(std::set::const_iterator it(parent_groups.ids.begin());it!=parent_groups.ids.end();++it) + out << (*it) << " " ; + out << std::endl; + + printRsItemEnd(out, "RsFileConfigItem", indent); + return out; +} /*************************************************************************/ /*************************************************************************/ @@ -351,8 +370,7 @@ uint32_t RsFileConfigSerialiser::sizeFileItem(RsFileConfigItem *item) s += item->file.TlvSize(); s += 4; // flags - for(std::list::const_iterator it(item->parent_groups.begin());it!=item->parent_groups.end();++it) // parent groups - s += GetTlvStringSize(*it); + s += item->parent_groups.TlvSize() ; return s; } @@ -382,9 +400,7 @@ bool RsFileConfigSerialiser::serialiseFileItem(RsFileConfigItem *item, void /* add mandatory parts first */ ok &= item->file.SetTlv(data, tlvsize, &offset); ok &= setRawUInt32(data, tlvsize, &offset, item->flags); - - for(std::list::const_iterator it(item->parent_groups.begin());ok && it!=item->parent_groups.end();++it) // parent groups - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, *it); + ok &= item->parent_groups.SetTlv(data, tlvsize, &offset); if (offset != tlvsize) { @@ -397,6 +413,66 @@ bool RsFileConfigSerialiser::serialiseFileItem(RsFileConfigItem *item, void return ok; } +RsFileConfigItem_deprecated *RsFileConfigSerialiser::deserialiseFileItem_deprecated(void *data, uint32_t *pktsize) +{ + /* get the type and size */ + uint32_t rstype = getRsItemId(data); + uint32_t rssize = getRsItemSize(data); + + uint32_t offset = 0; + + + if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || + (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || + (RS_PKT_TYPE_FILE_CONFIG != getRsItemType(rstype)) || + (RS_PKT_SUBTYPE_FILE_ITEM_deprecated != getRsItemSubType(rstype))) + { + return NULL; /* wrong type */ + } + + if (*pktsize < rssize) /* check size */ + return NULL; /* not enough data */ + + /* set the packet length */ + *pktsize = rssize; + + bool ok = true; + + /* ready to load */ + RsFileConfigItem_deprecated *item = new RsFileConfigItem_deprecated(); + item->clear(); + + /* skip the header */ + offset += 8; + + /* get mandatory parts first */ + ok &= item->file.GetTlv(data, rssize, &offset); + ok &= getRawUInt32(data, rssize, &offset, &(item->flags)); + + while(offset < rssize) + { + std::string tmp ; + if(GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GROUPID, tmp)) + item->parent_groups.push_back(tmp) ; + else + break ; + } + + if (offset != rssize) + { + /* error */ + delete item; + return NULL; + } + + if (!ok) + { + delete item; + return NULL; + } + + return item; +} RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32_t *pktsize) { /* get the type and size */ @@ -409,7 +485,7 @@ RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32 if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || (RS_PKT_TYPE_FILE_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_FILE_ITEM != getRsItemSubType(rstype))) + (RS_PKT_SUBTYPE_FILE_ITEM_deprecated != getRsItemSubType(rstype))) { return NULL; /* wrong type */ } @@ -423,7 +499,7 @@ RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32 bool ok = true; /* ready to load */ - RsFileConfigItem *item = new RsFileConfigItem(); + RsFileConfigItem *item = new RsFileConfigItem(); item->clear(); /* skip the header */ @@ -432,15 +508,7 @@ RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32 /* get mandatory parts first */ ok &= item->file.GetTlv(data, rssize, &offset); ok &= getRawUInt32(data, rssize, &offset, &(item->flags)); - - while(offset < rssize) - { - std::string tmp ; - if(GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GROUPID, tmp)) - item->parent_groups.push_back(tmp) ; - else - break ; - } + ok &= item->parent_groups.GetTlv(data, rssize, &offset) ; if (offset != rssize) { @@ -1316,6 +1384,15 @@ RsNodeGroupItem::RsNodeGroupItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG { } +RsNodeGroupItem::RsNodeGroupItem(const RsGroupInfo& g) + :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP) +{ + id = g.id ; + name = g.name ; + flag = g.flag ; + pgpList.ids = g.peerIds; +} + void RsNodeGroupItem::clear() { id.clear(); @@ -1348,23 +1425,6 @@ std::ostream &RsNodeGroupItem::print(std::ostream &out, uint16_t indent) return out; } -/* set data from RsGroupInfo to RsPeerGroupItem */ -void RsNodeGroupItem::set(RsGroupInfo &groupInfo) -{ - id = groupInfo.id; - name = groupInfo.name; - flag = groupInfo.flag; - pgpList.ids = groupInfo.peerIds; -} - -/* get data from RsGroupInfo to RsPeerGroupItem */ -void RsNodeGroupItem::get(RsGroupInfo &groupInfo) -{ - groupInfo.id = id; - groupInfo.name = name; - groupInfo.flag = flag; - groupInfo.peerIds = pgpList.ids; -} /*************************************************************************/ /* DEPRECATED CODE. SHOULD BE REMOVED WHEN EVERYONE USES THE NEW CLASS */ /*************************************************************************/ @@ -1409,24 +1469,6 @@ std::ostream &RsPeerGroupItem_deprecated::print(std::ostream &out, uint16_t inde return out; } -/* set data from RsGroupInfo to RsPeerGroupItem */ -void RsPeerGroupItem_deprecated::set(RsGroupInfo &groupInfo) -{ - id = groupInfo.id; - name = groupInfo.name; - flag = groupInfo.flag; - pgpList.ids = groupInfo.peerIds; -} - -/* get data from RsGroupInfo to RsPeerGroupItem */ -void RsPeerGroupItem_deprecated::get(RsGroupInfo &groupInfo) -{ - groupInfo.id = id; - groupInfo.name = name; - groupInfo.flag = flag; - groupInfo.peerIds = pgpList.ids; -} - /*************************************************************************/ uint32_t RsPeerConfigSerialiser::sizeGroup(RsPeerGroupItem_deprecated *i) diff --git a/libretroshare/src/serialiser/rsconfigitems.h b/libretroshare/src/serialiser/rsconfigitems.h index acf33b0e7..33ee08891 100644 --- a/libretroshare/src/serialiser/rsconfigitems.h +++ b/libretroshare/src/serialiser/rsconfigitems.h @@ -58,8 +58,9 @@ const uint8_t RS_PKT_SUBTYPE_PEER_BANDLIMITS = 0x06; const uint8_t RS_PKT_SUBTYPE_NODE_GROUP = 0x07; /* FILE CONFIG SUBTYPES */ -const uint8_t RS_PKT_SUBTYPE_FILE_TRANSFER = 0x01; -const uint8_t RS_PKT_SUBTYPE_FILE_ITEM = 0x02; +const uint8_t RS_PKT_SUBTYPE_FILE_TRANSFER = 0x01; +const uint8_t RS_PKT_SUBTYPE_FILE_ITEM_deprecated = 0x02; +const uint8_t RS_PKT_SUBTYPE_FILE_ITEM = 0x03; /**************************************************************************/ @@ -327,23 +328,39 @@ class RsFileTransfer: public RsItem const uint32_t RS_FILE_CONFIG_CLEANUP_DELETE = 0x0001; /* Used by ft / extralist / configdirs / anyone who wants a basic file */ -class RsFileConfigItem: public RsItem +class RsFileConfigItem_deprecated: public RsItem { - public: - RsFileConfigItem() - :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, - RS_PKT_TYPE_FILE_CONFIG, - RS_PKT_SUBTYPE_FILE_ITEM) - { return; } -virtual ~RsFileConfigItem(); -virtual void clear(); -std::ostream &print(std::ostream &out, uint16_t indent = 0); +public: + RsFileConfigItem_deprecated() + :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, + RS_PKT_TYPE_FILE_CONFIG, + RS_PKT_SUBTYPE_FILE_ITEM_deprecated) + {} + virtual ~RsFileConfigItem_deprecated() {} + virtual void clear(); + std::ostream &print(std::ostream &out, uint16_t indent = 0); - RsTlvFileItem file; - uint32_t flags; - std::list parent_groups ; + RsTlvFileItem file; + uint32_t flags; + std::list parent_groups ; }; +class RsFileConfigItem: public RsItem +{ +public: + RsFileConfigItem() + :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, + RS_PKT_TYPE_FILE_CONFIG, + RS_PKT_SUBTYPE_FILE_ITEM) + {} + virtual ~RsFileConfigItem() {} + virtual void clear(); + std::ostream &print(std::ostream &out, uint16_t indent = 0); + + RsTlvFileItem file; + uint32_t flags; + RsTlvNodeGroupIdSet parent_groups ; +}; /**************************************************************************/ class RsFileConfigSerialiser: public RsSerialType @@ -365,9 +382,11 @@ virtual uint32_t sizeTransfer(RsFileTransfer *); virtual bool serialiseTransfer(RsFileTransfer *item, void *data, uint32_t *size); virtual RsFileTransfer * deserialiseTransfer(void *data, uint32_t *size); +virtual RsFileConfigItem_deprecated * deserialiseFileItem_deprecated(void *data, uint32_t *size); + virtual uint32_t sizeFileItem(RsFileConfigItem *); virtual bool serialiseFileItem(RsFileConfigItem *item, void *data, uint32_t *size); -virtual RsFileConfigItem * deserialiseFileItem(void *data, uint32_t *size); +virtual RsFileConfigItem *deserialiseFileItem(void *data, uint32_t *size); }; diff --git a/libretroshare/src/serialiser/rstlvbase.h b/libretroshare/src/serialiser/rstlvbase.h index 54c6cd5ed..f33a7d8ee 100644 --- a/libretroshare/src/serialiser/rstlvbase.h +++ b/libretroshare/src/serialiser/rstlvbase.h @@ -204,7 +204,7 @@ const uint16_t TLV_TYPE_PGPIDSET = 0x1023; const uint16_t TLV_TYPE_RECOGNSET = 0x1024; const uint16_t TLV_TYPE_GXSIDSET = 0x1025; const uint16_t TLV_TYPE_GXSCIRCLEIDSET= 0x1026; -const uint16_t TLV_TYPE_GXSGROUPIDSET = 0x1027; +const uint16_t TLV_TYPE_NODEGROUPIDSET= 0x1027; const uint16_t TLV_TYPE_SERVICESET = 0x1030; diff --git a/libretroshare/src/serialiser/rstlvidset.h b/libretroshare/src/serialiser/rstlvidset.h index 06d2906af..e70b055cf 100644 --- a/libretroshare/src/serialiser/rstlvidset.h +++ b/libretroshare/src/serialiser/rstlvidset.h @@ -120,7 +120,7 @@ typedef t_RsTlvIdSet RsTlvPgpIdSet ; typedef t_RsTlvIdSet RsTlvHashSet ; typedef t_RsTlvIdSet RsTlvGxsIdSet ; typedef t_RsTlvIdSet RsTlvGxsCircleIdSet ; -typedef t_RsTlvIdSet RsTlvGxsGroupIdSet ; +typedef t_RsTlvIdSet RsTlvNodeGroupIdSet ; class RsTlvServiceIdSet: public RsTlvItem { diff --git a/retroshare-gui/src/gui/MessengerWindow.cpp b/retroshare-gui/src/gui/MessengerWindow.cpp index 542f6f4e8..13ad9d844 100644 --- a/retroshare-gui/src/gui/MessengerWindow.cpp +++ b/retroshare-gui/src/gui/MessengerWindow.cpp @@ -56,8 +56,9 @@ *****/ MessengerWindow* MessengerWindow::_instance = NULL; -static std::set *expandedPeers = NULL; -static std::set *expandedGroups = NULL; + +std::set MessengerWindow::expandedPeers ; +std::set MessengerWindow::expandedGroups ; /*static*/ void MessengerWindow::showYourself () { @@ -79,16 +80,6 @@ void MessengerWindow::releaseInstance() if (_instance) { delete _instance; } - if (expandedPeers) { - /* delete saved expanded peers */ - delete(expandedPeers); - expandedPeers = NULL; - } - if (expandedGroups) { - /* delete saved expanded groups */ - delete(expandedGroups); - expandedGroups = NULL; - } } /** Constructor */ @@ -108,21 +99,15 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WindowFlags flags) connect(NotifyQt::getInstance(), SIGNAL(ownStatusMessageChanged()), this, SLOT(loadmystatusmessage())); connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateOwnStatus(QString,int))); - if (expandedPeers != NULL) { - for (std::set::iterator peerIt = expandedPeers->begin(); peerIt != expandedPeers->end(); ++peerIt) { + for (std::set::iterator peerIt = expandedPeers.begin(); peerIt != expandedPeers.end(); ++peerIt) { ui.friendList->addPeerToExpand(*peerIt); } - delete expandedPeers; - expandedPeers = NULL; - } + expandedPeers.clear(); - if (expandedGroups != NULL) { - for (std::set::iterator groupIt = expandedGroups->begin(); groupIt != expandedGroups->end(); ++groupIt) { + for (std::set::iterator groupIt = expandedGroups.begin(); groupIt != expandedGroups.end(); ++groupIt) { ui.friendList->addGroupToExpand(*groupIt); } - delete expandedGroups; - expandedGroups = NULL; - } + expandedGroups.clear(); ui.messagelineEdit->setMinimumWidth(20); @@ -203,22 +188,12 @@ void MessengerWindow::addFriend() void MessengerWindow::closeEvent (QCloseEvent * /*event*/) { /* save the expanded peers */ - if (expandedPeers == NULL) { - expandedPeers = new std::set; - } else { - expandedPeers->clear(); - } - - ui.friendList->getExpandedPeers(*expandedPeers); + expandedPeers.clear(); + ui.friendList->getExpandedPeers(expandedPeers); /* save the expanded groups */ - if (expandedGroups == NULL) { - expandedGroups = new std::set; - } else { - expandedGroups->clear(); - } - - ui.friendList->getExpandedGroups(*expandedGroups); + expandedGroups.clear(); + ui.friendList->getExpandedGroups(expandedGroups); } /** Shows Share Manager */ diff --git a/retroshare-gui/src/gui/MessengerWindow.h b/retroshare-gui/src/gui/MessengerWindow.h index ff262be11..cd8f23742 100644 --- a/retroshare-gui/src/gui/MessengerWindow.h +++ b/retroshare-gui/src/gui/MessengerWindow.h @@ -66,6 +66,9 @@ private: /** Qt Designer generated object */ Ui::MessengerWindow ui; + + static std::set expandedPeers ; + static std::set expandedGroups ; }; #endif diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index a2220f2ff..d6c95b091 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -212,12 +212,12 @@ QString RetroshareDirModel::getFlagsString(FileStorageFlags flags) return QString(str) ; } -QString RetroshareDirModel::getGroupsString(const std::list& group_ids) +QString RetroshareDirModel::getGroupsString(const std::list& group_ids) { QString groups_str ; RsGroupInfo group_info ; - for(std::list::const_iterator it(group_ids.begin());it!=group_ids.end();) + for(std::list::const_iterator it(group_ids.begin());it!=group_ids.end();) if(rsPeers->getGroupInfo(*it,group_info)) { groups_str += GroupDefs::name(group_info) ; diff --git a/retroshare-gui/src/gui/RemoteDirModel.h b/retroshare-gui/src/gui/RemoteDirModel.h index a16dcfc3f..f308e7c70 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.h +++ b/retroshare-gui/src/gui/RemoteDirModel.h @@ -91,7 +91,7 @@ class RetroshareDirModel : public QAbstractItemModel void treeStyle(); void downloadDirectory(const DirDetails & details, int prefixLen); static QString getFlagsString(FileStorageFlags f) ; - static QString getGroupsString(const std::list&) ; + static QString getGroupsString(const std::list &) ; QString getAgeIndicatorString(const DirDetails &) const; // void getAgeIndicatorRec(const DirDetails &details, QString &ret) const; diff --git a/retroshare-gui/src/gui/ShareManager.cpp b/retroshare-gui/src/gui/ShareManager.cpp index 5b335bbf1..3e9477fdd 100644 --- a/retroshare-gui/src/gui/ShareManager.cpp +++ b/retroshare-gui/src/gui/ShareManager.cpp @@ -249,7 +249,7 @@ void ShareManager::updateGroups() QString group_string; int n = 0; - for (std::list::const_iterator it2((*it).parent_groups.begin());it2!=(*it).parent_groups.end();++it2,++n) + for (std::list::const_iterator it2((*it).parent_groups.begin());it2!=(*it).parent_groups.end();++it2,++n) { if (n>0) group_string += ", " ; diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index d7caa0176..6f0b8d05b 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -116,9 +116,7 @@ FriendList::FriendList(QWidget *parent) : mShowGroups(true), mShowState(false), mHideUnconnected(false), - groupsHasChanged(false), - openGroups(NULL), - openPeers(NULL) + groupsHasChanged(false) { ui->setupUi(this); @@ -219,7 +217,7 @@ void FriendList::processSettings(bool load) int arrayIndex = Settings->beginReadArray("Groups"); for (int index = 0; index < arrayIndex; ++index) { Settings->setArrayIndex(index); - addGroupToExpand(Settings->value("open").toString().toStdString()); + addGroupToExpand(RsNodeGroupId(Settings->value("open").toString().toStdString())); } Settings->endArray(); } else { @@ -236,11 +234,11 @@ void FriendList::processSettings(bool load) // open groups Settings->beginWriteArray("Groups"); int arrayIndex = 0; - std::set expandedPeers; + std::set expandedPeers; getExpandedGroups(expandedPeers); - foreach (std::string groupId, expandedPeers) { + foreach (RsNodeGroupId groupId, expandedPeers) { Settings->setArrayIndex(arrayIndex++); - Settings->setValue("open", QString::fromStdString(groupId)); + Settings->setValue("open", QString::fromStdString(groupId.toStdString())); } Settings->endArray(); } @@ -369,7 +367,7 @@ void FriendList::peerTreeWidgetCustomPopupMenu() addToGroupMenu = new QMenu(tr("Add to group"), &contextMnu); } QAction* addToGroupAction = new QAction(GroupDefs::name(*groupIt), addToGroupMenu); - addToGroupAction->setData(QString::fromStdString(groupIt->id)); + addToGroupAction->setData(QString::fromStdString(groupIt->id.toStdString())); connect(addToGroupAction, SIGNAL(triggered()), this, SLOT(addToGroup())); addToGroupMenu->addAction(addToGroupAction); } @@ -378,7 +376,7 @@ void FriendList::peerTreeWidgetCustomPopupMenu() moveToGroupMenu = new QMenu(tr("Move to group"), &contextMnu); } QAction* moveToGroupAction = new QAction(GroupDefs::name(*groupIt), moveToGroupMenu); - moveToGroupAction->setData(QString::fromStdString(groupIt->id)); + moveToGroupAction->setData(QString::fromStdString(groupIt->id.toStdString())); connect(moveToGroupAction, SIGNAL(triggered()), this, SLOT(moveToGroup())); moveToGroupMenu->addAction(moveToGroupAction); } else { @@ -456,7 +454,7 @@ void FriendList::peerTreeWidgetCustomPopupMenu() void FriendList::createNewGroup() { - CreateGroup createGrpDialog ("", this); + CreateGroup createGrpDialog (RsNodeGroupId(), this); createGrpDialog.exec(); } @@ -596,7 +594,7 @@ void FriendList::insertPeers() if (mShowGroups && groupsHasChanged) { if (parent) { if (parent->type() == TYPE_GROUP) { - std::string groupId = getRsId(parent); + RsNodeGroupId groupId(getRsId(parent)); // the parent is a group, check if the gpg id is assigned to the group for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) { @@ -630,7 +628,7 @@ void FriendList::insertPeers() } } else if (groupsHasChanged) { // remove deleted groups - std::string groupId = getRsId(item); + RsNodeGroupId groupId ( getRsId(item)); for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) { if (groupIt->id == groupId) { break; @@ -671,7 +669,7 @@ void FriendList::insertPeers() int itemCount = peerTreeWidget->topLevelItemCount(); for (int index = 0; index < itemCount; ++index) { QTreeWidgetItem *groupItemLoop = peerTreeWidget->topLevelItem(index); - if (groupItemLoop->type() == TYPE_GROUP && getRsId(groupItemLoop) == groupInfo->id) { + if (groupItemLoop->type() == TYPE_GROUP && RsNodeGroupId(getRsId(groupItemLoop)) == groupInfo->id) { groupItem = groupItemLoop; break; } @@ -690,7 +688,7 @@ void FriendList::insertPeers() groupItem->setForeground(COLUMN_NAME, QBrush(textColorGroup())); /* used to find back the item */ - groupItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(groupInfo->id)); + groupItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(groupInfo->id.toStdString())); groupItem->setData(COLUMN_DATA, ROLE_STANDARD, (groupInfo->flag & RS_GROUP_FLAG_STANDARD) ? true : false); /* Sort data */ @@ -716,7 +714,7 @@ void FriendList::insertPeers() } } - if (openGroups != NULL && openGroups->find(groupInfo->id) != openGroups->end()) { + if (openGroups.find(groupInfo->id) != openGroups.end()) { groupItem->setExpanded(true); } @@ -1182,7 +1180,7 @@ void FriendList::insertPeers() gpgItem->setFont(i, gpgFont); } - if (openPeers != NULL && openPeers->find(gpgId.toStdString()) != openPeers->end()) { + if (openPeers.find(gpgId.toStdString()) != openPeers.end()) { gpgItem->setExpanded(true); } } @@ -1217,14 +1215,6 @@ void FriendList::insertPeers() } groupsHasChanged = false; - if (openGroups != NULL) { - delete(openGroups); - openGroups = NULL; - } - if (openPeers != NULL) { - delete(openPeers); - openPeers = NULL; - } ui->peerTreeWidget->resort(); } @@ -1232,13 +1222,13 @@ void FriendList::insertPeers() /** * Returns a list with all groupIds that are expanded */ -bool FriendList::getExpandedGroups(std::set &groups) const +bool FriendList::getExpandedGroups(std::set &groups) const { int itemCount = ui->peerTreeWidget->topLevelItemCount(); for (int index = 0; index < itemCount; ++index) { QTreeWidgetItem *item = ui->peerTreeWidget->topLevelItem(index); if (item->type() == TYPE_GROUP && item->isExpanded()) { - groups.insert(item->data(COLUMN_DATA, ROLE_ID).toString().toStdString()); + groups.insert(RsNodeGroupId(item->data(COLUMN_DATA, ROLE_ID).toString().toStdString())); } } return true; @@ -1626,7 +1616,7 @@ void FriendList::getSslIdsFromItem(QTreeWidgetItem *item, std::list &s case TYPE_GROUP: { RsGroupInfo groupInfo; - if (rsPeers->getGroupInfo(peerId, groupInfo)) { + if (rsPeers->getGroupInfo(RsNodeGroupId(peerId), groupInfo)) { std::set::iterator gpgIt; for (gpgIt = groupInfo.peerIds.begin(); gpgIt != groupInfo.peerIds.end(); ++gpgIt) { rsPeers->getAssociatedSSLIds(*gpgIt, sslIds); @@ -1649,10 +1639,10 @@ void FriendList::addToGroup() return; } - std::string groupId = qobject_cast(sender())->data().toString().toStdString(); + RsNodeGroupId groupId ( qobject_cast(sender())->data().toString().toStdString()); RsPgpId gpgId ( getRsId(c)); - if (gpgId.isNull() || groupId.empty()) { + if (gpgId.isNull() || groupId.isNull()) { return; } @@ -1675,15 +1665,15 @@ void FriendList::moveToGroup() return; } - std::string groupId = qobject_cast(sender())->data().toString().toStdString(); + RsNodeGroupId groupId ( qobject_cast(sender())->data().toString().toStdString()); RsPgpId gpgId ( getRsId(c)); - if (gpgId.isNull() || groupId.empty()) { + if (gpgId.isNull() || groupId.isNull()) { return; } // remove from all groups - rsPeers->assignPeerToGroup("", gpgId, false); + rsPeers->assignPeerToGroup(RsNodeGroupId(), gpgId, false); // automatically expand the group, the peer is added to addGroupToExpand(groupId); @@ -1704,7 +1694,7 @@ void FriendList::removeFromGroup() return; } - std::string groupId = qobject_cast(sender())->data().toString().toStdString(); + RsNodeGroupId groupId ( qobject_cast(sender())->data().toString().toStdString()); RsPgpId gpgId ( getRsId(c)); if (gpgId.isNull()) { @@ -1727,14 +1717,13 @@ void FriendList::editGroup() return; } - std::string groupId = getRsId(c); + RsNodeGroupId groupId ( getRsId(c)); - if (groupId.empty()) { - return; + if (!groupId.isNull()) + { + CreateGroup editGrpDialog(groupId, this); + editGrpDialog.exec(); } - - CreateGroup editGrpDialog(groupId, this); - editGrpDialog.exec(); } void FriendList::removeGroup() @@ -1749,13 +1738,10 @@ void FriendList::removeGroup() return; } - std::string groupId = getRsId(c); + RsNodeGroupId groupId ( getRsId(c)); - if (groupId.empty()) { - return; - } - - rsPeers->removeGroup(groupId); + if (!groupId.isNull()) + rsPeers->removeGroup(groupId); } void FriendList::exportFriendlistClicked() @@ -2089,7 +2075,7 @@ bool FriendList::importFriendlist(QString &fileName, bool &errorPeers, bool &err // get name and flags and try to get the group ID std::string groupName = group.attribute("name").toStdString(); uint32_t flag = group.attribute("flag").toInt(); - std::string groupId; + RsNodeGroupId groupId; if(getOrCreateGroup(groupName, flag, groupId)) { // group id found! QDomElement pgpID = group.firstChildElement("pgpID"); @@ -2123,7 +2109,7 @@ bool FriendList::importFriendlist(QString &fileName, bool &errorPeers, bool &err * @param id groupd id for the given name * @return success or fail */ -bool FriendList::getGroupIdByName(const std::string &name, std::string &id) +bool FriendList::getGroupIdByName(const std::string &name, RsNodeGroupId &id) { std::list grpList; if(!rsPeers->getGroupInfoList(grpList)) @@ -2146,14 +2132,14 @@ bool FriendList::getGroupIdByName(const std::string &name, std::string &id) * @param id groupd id * @return success or failure */ -bool FriendList::getOrCreateGroup(const std::string &name, const uint &flag, std::string &id) +bool FriendList::getOrCreateGroup(const std::string &name, const uint &flag, RsNodeGroupId &id) { if(getGroupIdByName(name, id)) return true; // -> create one RsGroupInfo grp; - grp.id = "0"; // RS will generate an ID + grp.id.clear(); // RS will generate an ID grp.name = name; grp.flag = flag; @@ -2271,12 +2257,9 @@ void FriendList::filterItems(const QString &text) * Add a groupId to the openGroups list. These groups * will be expanded, when they're added to the QTreeWidget */ -void FriendList::addGroupToExpand(const std::string &groupId) +void FriendList::addGroupToExpand(const RsNodeGroupId &groupId) { - if (openGroups == NULL) { - openGroups = new std::set; - } - openGroups->insert(groupId); + openGroups.insert(groupId); } /** @@ -2285,10 +2268,7 @@ void FriendList::addGroupToExpand(const std::string &groupId) */ void FriendList::addPeerToExpand(const std::string &gpgId) { - if (openPeers == NULL) { - openPeers = new std::set; - } - openPeers->insert(gpgId); + openPeers.insert(gpgId); } void FriendList::createDisplayMenu() diff --git a/retroshare-gui/src/gui/common/FriendList.h b/retroshare-gui/src/gui/common/FriendList.h index cd950a639..6b92530d8 100644 --- a/retroshare-gui/src/gui/common/FriendList.h +++ b/retroshare-gui/src/gui/common/FriendList.h @@ -63,8 +63,8 @@ public: // Add a tool button to the tool area void addToolButton(QToolButton *toolButton); void processSettings(bool load); - void addGroupToExpand(const std::string &groupId); - bool getExpandedGroups(std::set &groups) const; + void addGroupToExpand(const RsNodeGroupId &groupId); + bool getExpandedGroups(std::set &groups) const; void addPeerToExpand(const std::string &gpgId); bool getExpandedPeers(std::set &peers) const; @@ -119,8 +119,9 @@ private: QString mFilterText; bool groupsHasChanged; - std::set *openGroups; - std::set *openPeers; + std::set openGroups; +#warning this would needs an ID, not a std::string. + std::set openPeers; /* Color definitions (for standard see qss.default) */ QColor mTextColorGroup; @@ -129,8 +130,8 @@ private: QTreeWidgetItem *getCurrentPeer() const; void getSslIdsFromItem(QTreeWidgetItem *item, std::list &sslIds); - bool getOrCreateGroup(const std::string &name, const uint &flag, std::string &id); - bool getGroupIdByName(const std::string &name, std::string &id); + bool getOrCreateGroup(const std::string &name, const uint &flag, RsNodeGroupId &id); + bool getGroupIdByName(const std::string &name, RsNodeGroupId &id); bool importExportFriendlistFileDialog(QString &fileName, bool import); bool exportFriendlist(QString &fileName); diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp index f6eb99e13..568fbe79a 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp @@ -271,9 +271,9 @@ void FriendSelectionWidget::secured_fillList() selectedIds(sslIdsSelected,true); } - std::set groupIdsSelected; + std::set groupIdsSelected; if (mShowTypes & SHOW_GROUP) { - selectedIds(groupIdsSelected,true); + selectedIds(groupIdsSelected,true); } std::set gpgIdsSelected; @@ -347,7 +347,7 @@ void FriendSelectionWidget::secured_fillList() groupItem->setTextAlignment(COLUMN_NAME, Qt::AlignLeft | Qt::AlignVCenter); groupItem->setIcon(COLUMN_NAME, QIcon(IMAGE_GROUP16)); - groupItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(groupInfo->id)); + groupItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(groupInfo->id.toStdString())); groupItem->setExpanded(true); @@ -363,7 +363,7 @@ void FriendSelectionWidget::secured_fillList() groupItem->setCheckState(0, Qt::Unchecked); } - emit itemAdded(IDTYPE_GROUP, QString::fromStdString(groupInfo->id), groupItem); + emit itemAdded(IDTYPE_GROUP, QString::fromStdString(groupInfo->id.toStdString()), groupItem); if (std::find(groupIdsSelected.begin(), groupIdsSelected.end(), groupInfo->id) != groupIdsSelected.end()) { setSelected(mListModus, groupItem, true); diff --git a/retroshare-gui/src/gui/common/GroupSelectionBox.cpp b/retroshare-gui/src/gui/common/GroupSelectionBox.cpp index 613459019..2e0cc9c32 100644 --- a/retroshare-gui/src/gui/common/GroupSelectionBox.cpp +++ b/retroshare-gui/src/gui/common/GroupSelectionBox.cpp @@ -20,7 +20,7 @@ GroupSelectionBox::GroupSelectionBox(QWidget *parent) void GroupSelectionBox::fillGroups() { - std::list selectedIds; + std::list selectedIds; selectedGroupIds(selectedIds); clear(); @@ -30,7 +30,7 @@ void GroupSelectionBox::fillGroups() for (std::list::const_iterator it(groupIds.begin()); it != groupIds.end(); ++it) { QListWidgetItem *item = new QListWidgetItem(GroupDefs::name(*it)); - item->setData(ROLE_ID, QString::fromStdString(it->id)); + item->setData(ROLE_ID, QString::fromStdString(it->id.toStdString())); item->setBackgroundColor(QColor(183,236,181)); addItem(item); } @@ -38,27 +38,27 @@ void GroupSelectionBox::fillGroups() setSelectedGroupIds(selectedIds); } -void GroupSelectionBox::selectedGroupIds(std::list &groupIds) const +void GroupSelectionBox::selectedGroupIds(std::list &groupIds) const { int itemCount = count(); for (int i = 0; i < itemCount; ++i) { QListWidgetItem *listItem = item(i); if (listItem->checkState() == Qt::Checked) { - groupIds.push_back(item(i)->data(ROLE_ID).toString().toStdString()); + groupIds.push_back(RsNodeGroupId(item(i)->data(ROLE_ID).toString().toStdString())); std::cerr << "Adding selected item " << groupIds.back() << std::endl; } } } -void GroupSelectionBox::setSelectedGroupIds(const std::list& groupIds) +void GroupSelectionBox::setSelectedGroupIds(const std::list& groupIds) { int itemCount = count(); for (int i = 0; i < itemCount; ++i) { QListWidgetItem *listItem = item(i); - if (std::find(groupIds.begin(), groupIds.end(), listItem->data(ROLE_ID).toString().toStdString()) != groupIds.end()) { + if (std::find(groupIds.begin(), groupIds.end(), RsNodeGroupId(listItem->data(ROLE_ID).toString().toStdString())) != groupIds.end()) { listItem->setCheckState(Qt::Checked); } else { listItem->setCheckState(Qt::Unchecked); diff --git a/retroshare-gui/src/gui/common/GroupSelectionBox.h b/retroshare-gui/src/gui/common/GroupSelectionBox.h index f8e8477fb..4afc9cc94 100644 --- a/retroshare-gui/src/gui/common/GroupSelectionBox.h +++ b/retroshare-gui/src/gui/common/GroupSelectionBox.h @@ -1,4 +1,5 @@ #include +#include class GroupSelectionBox: public QListWidget { @@ -7,10 +8,10 @@ class GroupSelectionBox: public QListWidget public: GroupSelectionBox(QWidget *parent); - void selectedGroupIds(std::list &groupIds) const; + void selectedGroupIds(std::list &groupIds) const; void selectedGroupNames(QList &groupNames) const; - void setSelectedGroupIds(const std::list &groupIds); + void setSelectedGroupIds(const std::list &groupIds); private slots: void fillGroups(); diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index 7990b92c4..afbcb4422 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -297,7 +297,7 @@ static void fillGroups(ConnectFriendWizard *wizard, QComboBox *comboBox, const Q GroupDefs::sortByName(groupInfoList); comboBox->addItem("", ""); // empty value for (std::list::iterator groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) { - comboBox->addItem(GroupDefs::name(*groupIt), QString::fromStdString(groupIt->id)); + comboBox->addItem(GroupDefs::name(*groupIt), QString::fromStdString(groupIt->id.toStdString())); } if (groupId.isEmpty() == false) { @@ -853,7 +853,7 @@ void ConnectFriendWizard::accept() } if (!groupId.isEmpty()) - rsPeers->assignPeerToGroup(groupId.toStdString(), peerDetails.gpg_id, true); + rsPeers->assignPeerToGroup(RsNodeGroupId(groupId.toStdString()), peerDetails.gpg_id, true); } if ((accept_connection) && (!peerDetails.id.isNull())) diff --git a/retroshare-gui/src/gui/groups/CreateGroup.cpp b/retroshare-gui/src/gui/groups/CreateGroup.cpp index 7a919f93a..3fef40542 100644 --- a/retroshare-gui/src/gui/groups/CreateGroup.cpp +++ b/retroshare-gui/src/gui/groups/CreateGroup.cpp @@ -31,7 +31,7 @@ #include /** Default constructor */ -CreateGroup::CreateGroup(const std::string &groupId, QWidget *parent) +CreateGroup::CreateGroup(const RsNodeGroupId &groupId, QWidget *parent) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint) { /* Invoke Qt Designer generated QObject setup routine */ @@ -51,7 +51,7 @@ CreateGroup::CreateGroup(const std::string &groupId, QWidget *parent) ui.friendList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_GPG); ui.friendList->start(); - if (mGroupId.empty() == false) { + if (!mGroupId.isNull()) { /* edit exisiting group */ RsGroupInfo groupInfo; if (rsPeers->getGroupInfo(mGroupId, groupInfo)) { @@ -83,7 +83,7 @@ CreateGroup::CreateGroup(const std::string &groupId, QWidget *parent) std::list::iterator groupIt; for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) { - if (mGroupId.empty() || groupIt->id != mGroupId) { + if (mGroupId.isNull() || groupIt->id != mGroupId) { mUsedGroupNames.append(GroupDefs::name(*groupIt)); } } @@ -114,14 +114,19 @@ void CreateGroup::changeGroup() { RsGroupInfo groupInfo; - if (mGroupId.empty()) { + if (mGroupId.isNull()) + { // add new group groupInfo.name = misc::removeNewLine(ui.groupName->text()).toUtf8().constData(); - if (!rsPeers->addGroup(groupInfo)) { + + if (!rsPeers->addGroup(groupInfo)) return; - } - } else { - if (rsPeers->getGroupInfo(mGroupId, groupInfo) == true) { + + } + else + { + if (rsPeers->getGroupInfo(mGroupId, groupInfo)) + { if (!mIsStandard) { groupInfo.name = misc::removeNewLine(ui.groupName->text()).toUtf8().constData(); if (!rsPeers->editGroup(mGroupId, groupInfo)) { diff --git a/retroshare-gui/src/gui/groups/CreateGroup.h b/retroshare-gui/src/gui/groups/CreateGroup.h index b8177c611..59d75dc42 100644 --- a/retroshare-gui/src/gui/groups/CreateGroup.h +++ b/retroshare-gui/src/gui/groups/CreateGroup.h @@ -30,7 +30,7 @@ class CreateGroup : public QDialog public: /** Default constructor */ - CreateGroup(const std::string &groupId, QWidget *parent = 0); + CreateGroup(const RsNodeGroupId &groupId, QWidget *parent = 0); /** Default destructor */ ~CreateGroup(); @@ -39,7 +39,7 @@ private slots: void groupNameChanged(QString); private: - std::string mGroupId; + RsNodeGroupId mGroupId; QStringList mUsedGroupNames; bool mIsStandard; diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.cpp b/retroshare-gui/src/gui/msgs/MessageComposer.cpp index 0a3bf70af..a190e9c3e 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.cpp +++ b/retroshare-gui/src/gui/msgs/MessageComposer.cpp @@ -887,7 +887,7 @@ void MessageComposer::calculateTitle() setWindowTitle(tr("Compose") + ": " + misc::removeNewLine(ui.titleEdit->text())); } -static void calculateGroupsOfSslIds(const std::list &existingGroupInfos, std::list &checkSslIds, std::list &checkGroupIds) +static void calculateGroupsOfSslIds(const std::list &existingGroupInfos, std::list &checkSslIds, std::list &checkGroupIds) { checkGroupIds.clear(); @@ -1342,7 +1342,7 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox) { case PEER_TYPE_GROUP: { RsGroupInfo groupInfo; - if (rsPeers->getGroupInfo(id, groupInfo) == false) { + if (rsPeers->getGroupInfo(RsNodeGroupId(id), groupInfo) == false) { // group not found continue; } @@ -1587,7 +1587,7 @@ void MessageComposer::setRecipientToRow(int row, enumType type, destinationType icon = QIcon(IMAGE_GROUP16); RsGroupInfo groupInfo; - if (rsPeers->getGroupInfo(id, groupInfo)) { + if (rsPeers->getGroupInfo(RsNodeGroupId(id), groupInfo)) { name = GroupDefs::name(groupInfo); } else { name = tr("Unknown"); @@ -1771,7 +1771,7 @@ void MessageComposer::editingRecipientFinished() QString groupName = GroupDefs::name(*groupIt); if (text.compare(groupName, Qt::CaseSensitive) == 0) { // found it - setRecipientToRow(row, type, PEER_TYPE_GROUP, groupIt->id); + setRecipientToRow(row, type, PEER_TYPE_GROUP, groupIt->id.toStdString()); return; } }