From 9206daca370570afead22b584840bda0e1608b86 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 18 Oct 2017 23:20:19 +0200 Subject: [PATCH] fixed up collection link display --- libretroshare/src/file_sharing/file_tree.cc | 6 +++++- libretroshare/src/file_sharing/file_tree.h | 6 +++++- .../gui/FileTransfer/SharedFilesDialog.cpp | 2 +- retroshare-gui/src/gui/RetroShareLink.cpp | 20 +++++++++++++------ retroshare-gui/src/gui/RetroShareLink.h | 3 ++- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/libretroshare/src/file_sharing/file_tree.cc b/libretroshare/src/file_sharing/file_tree.cc index 75736ddc8..65eacbcef 100644 --- a/libretroshare/src/file_sharing/file_tree.cc +++ b/libretroshare/src/file_sharing/file_tree.cc @@ -55,6 +55,9 @@ void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const Di ft.mDirs[index].subfiles.push_back(ft.mFiles.size()) ; ft.mFiles.push_back(f) ; + + ft.mTotalFiles++ ; + ft.mTotalSize += f.size ; } else if(dd.children[i].type == DIR_TYPE_DIR) { @@ -264,7 +267,8 @@ bool FileTreeImpl::serialise(unsigned char *& buffer,uint32_t& buffer_size) cons void FileTreeImpl::print() const { - recurs_print(0,"") ; + std::cerr << "File hierarchy: name=" << mDirs[0].name << " size=" << mTotalSize << std::endl; + recurs_print(0," ") ; } void FileTreeImpl::recurs_print(uint32_t index,const std::string& indent) const diff --git a/libretroshare/src/file_sharing/file_tree.h b/libretroshare/src/file_sharing/file_tree.h index f4f951361..942414e67 100644 --- a/libretroshare/src/file_sharing/file_tree.h +++ b/libretroshare/src/file_sharing/file_tree.h @@ -3,7 +3,11 @@ class FileTreeImpl: public FileTree { public: - FileTreeImpl() {} + FileTreeImpl() + { + mTotalFiles = 0 ; + mTotalSize = 0 ; + } virtual std::string toRadix64() const ; virtual bool getDirectoryContent(uint32_t index,std::vector& subdirs,std::vector& subfiles) const ; diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index a43e3cc5f..3a437c9cf 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -578,7 +578,7 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote) std::cerr << "Created collection file tree:" << std::endl; ft->print(); - RetroShareLink link = RetroShareLink::createCollection(QString::fromUtf8(details.name.c_str()), details.count,QString::fromStdString(ft->toRadix64())) ; + RetroShareLink link = RetroShareLink::createCollection(QString::fromUtf8(details.name.c_str()),ft->mTotalSize,ft->mTotalFiles,QString::fromStdString(ft->toRadix64())) ; if(link.valid()) urls.push_back(link) ; diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index 27ec2c1a9..d141422f1 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -69,7 +69,7 @@ #define HOST_CERTIFICATE "certificate" #define HOST_PUBLIC_MSG "public_msg" #define HOST_IDENTITY "identity" -#define HOST_REGEXP "file|extra|person|forum|channel|posted|search|message|certificate|private_chat|public_msg|identity" +#define HOST_REGEXP "file|collection|extra|person|forum|channel|posted|search|message|certificate|private_chat|public_msg|identity" #define FILE_NAME "name" #define FILE_SIZE "size" @@ -79,6 +79,7 @@ #define COLLECTION_NAME "name" #define COLLECTION_SIZE "size" #define COLLECTION_DATA "radix" +#define COLLECTION_COUNT "files" #define PERSON_NAME "name" #define PERSON_HASH "hash" @@ -337,8 +338,9 @@ void RetroShareLink::fromUrl(const QUrl& url) bool ok; _type = TYPE_COLLECTION; _radix = decodedQueryItemValue(urlQuery, COLLECTION_DATA); + _name = decodedQueryItemValue(urlQuery, COLLECTION_NAME); _size = urlQuery.queryItemValue(COLLECTION_SIZE).toULongLong(&ok); - _name = urlQuery.queryItemValue(COLLECTION_NAME).toULongLong(&ok); + _count = urlQuery.queryItemValue(COLLECTION_COUNT).toULongLong(&ok); #ifdef DEBUG_RSLINK std::cerr << "Got a certificate link!!" << std::endl; @@ -418,12 +420,13 @@ RetroShareLink RetroShareLink::createFile(const QString& name, uint64_t size, co return link; } -RetroShareLink RetroShareLink::createCollection(const QString& name, const uint64_t size,const QString& radix_data) +RetroShareLink RetroShareLink::createCollection(const QString& name, uint64_t size, uint32_t count, const QString& radix_data) { RetroShareLink link; link.clear(); link._name = name; + link._count = count; link._size = size; link._radix = radix_data ; link._type = TYPE_COLLECTION; @@ -899,8 +902,10 @@ QString RetroShareLink::toString() const case TYPE_COLLECTION: url.setScheme(RSLINK_SCHEME); url.setHost(HOST_COLLECTION) ; - urlQuery.addQueryItem(CERTIFICATE_RADIX, encodeItem(_radix)); - urlQuery.addQueryItem(CERTIFICATE_NAME, encodeItem(_name)); + urlQuery.addQueryItem(COLLECTION_NAME, encodeItem(_name)); + urlQuery.addQueryItem(COLLECTION_SIZE, QString::number(_size)); + urlQuery.addQueryItem(COLLECTION_DATA, encodeItem(_radix)); + urlQuery.addQueryItem(COLLECTION_COUNT, QString::number(_count)); break; case TYPE_CERTIFICATE: @@ -925,11 +930,14 @@ QString RetroShareLink::niceName() const if (type() == TYPE_PERSON) return PeerDefs::rsid(name().toUtf8().constData(), RsPgpId(hash().toStdString())); + if(type() == TYPE_COLLECTION) + return QObject::tr("%1 (%2 files, %3)").arg(_name).arg(_count).arg(misc::friendlyUnit(_size)); + if(type() == TYPE_IDENTITY) return QObject::tr("Identity link (name=%1, ID=%2)").arg(_name).arg(_hash) ; if(type() == TYPE_COLLECTION) - return QObject::tr("Click to browse/download this file collection"); + return QObject::tr("File directory (Total %s) Click to browse/download this file collection").arg(misc::friendlyUnit(_size)); if(type() == TYPE_PUBLIC_MSG) { RsPeerDetails detail; diff --git a/retroshare-gui/src/gui/RetroShareLink.h b/retroshare-gui/src/gui/RetroShareLink.h index a2e54798d..2576b880c 100644 --- a/retroshare-gui/src/gui/RetroShareLink.h +++ b/retroshare-gui/src/gui/RetroShareLink.h @@ -81,7 +81,7 @@ class RetroShareLink static RetroShareLink createIdentity(const RsGxsId& gxs_id,const QString& name,const QString& radix_data) ; static RetroShareLink createExtraFile(const QString& name, uint64_t size, const QString& hash, const QString& ssl_id); static RetroShareLink createFile(const QString& name, uint64_t size, const QString& hash); - static RetroShareLink createCollection(const QString& name, const uint64_t size,const QString& radix_data); + static RetroShareLink createCollection(const QString& name, uint64_t size,uint32_t count,const QString& radix_data); static RetroShareLink createPublicMsgInvite(time_t time_stamp,const QString& pgp_id,const QString& hash) ; static RetroShareLink createPerson(const RsPgpId &id); static RetroShareLink createCertificate(const RsPeerId &ssl_id) ; @@ -169,6 +169,7 @@ class RetroShareLink QString _encrypted_chat_info ; // encrypted data string for the recipient of a chat invite time_t _time_stamp ; // time stamp at which the link will expire. QString _radix_group_data; + uint32_t _count ; unsigned int _subType; // for general use as sub type for _type (RSLINK_SUBTYPE_...) };