From 1383846364412e6ef2951156281c8ff5d16136b1 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Sep 2018 13:42:49 +0200 Subject: [PATCH 1/8] added extra list view in own files. --- .../src/file_sharing/dir_hierarchy.cc | 7 +- .../src/file_sharing/file_sharing_defaults.h | 1 + libretroshare/src/file_sharing/p3filelists.cc | 112 ++++++++++++++++-- libretroshare/src/file_sharing/p3filelists.h | 9 +- libretroshare/src/ft/ftextralist.cc | 29 +++-- libretroshare/src/ft/ftextralist.h | 7 ++ libretroshare/src/ft/ftserver.cc | 3 + libretroshare/src/retroshare/rstypes.h | 1 + retroshare-gui/src/gui/RemoteDirModel.cpp | 4 +- 9 files changed, 149 insertions(+), 24 deletions(-) diff --git a/libretroshare/src/file_sharing/dir_hierarchy.cc b/libretroshare/src/file_sharing/dir_hierarchy.cc index 743176e38..b6208eb57 100644 --- a/libretroshare/src/file_sharing/dir_hierarchy.cc +++ b/libretroshare/src/file_sharing/dir_hierarchy.cc @@ -865,7 +865,7 @@ void InternalFileHierarchyStorage::print() const for(uint32_t i=0;itype() == FileStorageNode::TYPE_DIR) @@ -1183,6 +1183,11 @@ bool InternalFileHierarchyStorage::load(const std::string& fname) } free(buffer) ; + std::string err_str ; + + if(!check(err_str)) + std::cerr << "(EE) Error while loading file hierarchy " << fname << std::endl; + return true ; } catch(read_error& e) diff --git a/libretroshare/src/file_sharing/file_sharing_defaults.h b/libretroshare/src/file_sharing/file_sharing_defaults.h index 6633e348f..75f19075a 100644 --- a/libretroshare/src/file_sharing/file_sharing_defaults.h +++ b/libretroshare/src/file_sharing/file_sharing_defaults.h @@ -25,6 +25,7 @@ static const uint32_t DELAY_BETWEEN_DIRECTORY_UPDATES = 600 ; // 10 m static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORY_SYNC_REQ = 120 ; // 2 minutes static const uint32_t DELAY_BETWEEN_LOCAL_DIRECTORIES_TS_UPDATE = 20 ; // 20 sec. But we only update for real if something has changed. static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP = 60 ; // 60 sec. +static const uint32_t DELAY_BETWEEN_EXTRA_FILES_CACHE_UPDATES = 2 ; // 2 sec. static const uint32_t DELAY_BEFORE_DELETE_NON_EMPTY_REMOTE_DIR = 60*24*86400 ; // delete non empty remoe directories after 60 days of inactivity static const uint32_t DELAY_BEFORE_DELETE_EMPTY_REMOTE_DIR = 5*24*86400 ; // delete empty remote directories after 5 days of inactivity diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 156490e18..c6ee048be 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -38,6 +38,7 @@ //#define DEBUG_P3FILELISTS 1 #define DEBUG_CONTENT_FILTERING 1 +#define DEBUG_FILE_HIERARCHY 1 static const uint32_t P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED = 0x0000 ; static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED = 0x0001 ; @@ -71,6 +72,7 @@ p3FileDatabase::p3FileDatabase(p3ServiceControl *mpeers) mUpdateFlags = P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED ; mLastRemoteDirSweepTS = 0 ; + mLastExtraFilesCacheUpdate = 0; mLastCleanupTime = 0 ; mLastDataRecvTS = 0 ; mTrustFriendNodesForBannedFiles = TRUST_FRIEND_NODES_FOR_BANNED_FILES_DEFAULT; @@ -884,6 +886,8 @@ void p3FileDatabase::requestDirUpdate(void *ref) } } +// Finds the pointer to the sub-element #row under element ref. + bool p3FileDatabase::findChildPointer( void *ref, int row, void *& result, FileSearchFlags flags ) const { @@ -891,10 +895,10 @@ bool p3FileDatabase::findChildPointer( void *ref, int row, void *& result, { if(flags & RS_FILE_HINTS_LOCAL) { - if(row != 0) + if(row != 0 && row != 1) return false ; - convertEntryIndexToPointer(0,0,result); + convertEntryIndexToPointer(0,row,result); return true ; } @@ -913,12 +917,18 @@ bool p3FileDatabase::findChildPointer( void *ref, int row, void *& result, convertPointerToEntryIndex(ref,e,fi); // check consistency - if( (fi == 0 && !(flags & RS_FILE_HINTS_LOCAL)) || (fi > 0 && (flags & RS_FILE_HINTS_LOCAL))) + if( (fi == 0 && !(flags & RS_FILE_HINTS_LOCAL)) || (fi > 1 && (flags & RS_FILE_HINTS_LOCAL))) { P3FILELISTS_ERROR() << "(EE) remote request on local index or local request on remote index. This should not happen." << std::endl; return false ; } - DirectoryStorage *storage = (fi==0)? ((DirectoryStorage*)mLocalSharedDirs) : ((DirectoryStorage*)mRemoteDirectories[fi-1]); + + if(fi==1 && (flags & RS_FILE_HINTS_LOCAL)) // extra list + { + convertEntryIndexToPointer(row+1,1,result); + return true; + } + DirectoryStorage *storage = (flags & RS_FILE_HINTS_LOCAL)? ((DirectoryStorage*)mLocalSharedDirs) : ((DirectoryStorage*)mRemoteDirectories[fi-1]); // Case where the index is the top of a single person. Can be us, or a friend. @@ -950,6 +960,65 @@ int p3FileDatabase::getSharedDirStatistics(const RsPeerId& pid,SharedDirStats& s } } +void p3FileDatabase::getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIndex e,DirDetails& d) const +{ + // update the cache of extra files if last requested too long ago + + time_t now = time(NULL); + + if(mLastExtraFilesCacheUpdate + DELAY_BETWEEN_EXTRA_FILES_CACHE_UPDATES <= now) + { + mExtraFiles->getExtraFileList(mExtraFilesCache); + mLastExtraFilesCacheUpdate = now; + } + + // + + if(e == 0) // "virtual extra files directory" => create a dir with as many child as they are extra files + { + d.parent = NULL ; + + d.prow = 0;//fi-1 ; + d.type = DIR_TYPE_DIR; + d.hash.clear() ; + d.count = mExtraFilesCache.size(); + d.max_mtime = time(NULL); + d.mtime = time(NULL); + d.name = "Temporary shared files"; + d.path = "/"; + d.ref = ref ; + + for(uint32_t i=0;i(i,1,stub.ref); // local shared files from extra list + + d.children.push_back(stub); + } + } + else // extra file. Just query the corresponding data from ftExtra + { + d.prow = 1;//fi-1 ; + d.type = DIR_TYPE_FILE; + + FileInfo& f(mExtraFilesCache[(int)e-1]) ; + + d.hash = f.hash; + d.count = 0; + d.max_mtime = time(NULL); + d.mtime = time(NULL); + d.name = f.fname; + d.path = "/"; + d.ref = ref ; + + convertEntryIndexToPointer(0,1,d.parent) ; + } + + d.id = RsPeerId(); +} + // This function converts a pointer into directory details, to be used by the AbstractItemModel for browsing the files. int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags flags) const { @@ -975,10 +1044,8 @@ int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags { d.ref = NULL ; d.type = DIR_TYPE_ROOT; - d.count = 1; d.parent = NULL; d.prow = -1; - d.ref = NULL; d.name = "root"; d.hash.clear() ; d.path = ""; @@ -989,13 +1056,26 @@ int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags if(flags & RS_FILE_HINTS_LOCAL) { void *p; - convertEntryIndexToPointer(0,0,p); + { + convertEntryIndexToPointer(0,0,p); // root of own directories DirStub stub; stub.type = DIR_TYPE_PERSON; stub.name = mServCtrl->getOwnId().toStdString(); stub.ref = p; d.children.push_back(stub); + } + { + convertEntryIndexToPointer(0,1,p); // local shared files from extra list + DirStub stub; + stub.type = DIR_TYPE_PERSON; + stub.name = "Temporary shared files"; + stub.ref = p; + + d.children.push_back(stub); + } + + } else for(uint32_t i=0;i(ref,e,fi); // check consistency - if( (fi == 0 && !(flags & RS_FILE_HINTS_LOCAL)) || (fi > 0 && (flags & RS_FILE_HINTS_LOCAL))) + if( (fi == 0 && !(flags & RS_FILE_HINTS_LOCAL)) || (fi > 1 && (flags & RS_FILE_HINTS_LOCAL))) { P3FILELISTS_ERROR() << "(EE) remote request on local index or local request on remote index. This should not happen." << std::endl; return false ; } - DirectoryStorage *storage = (fi==0)? ((DirectoryStorage*)mLocalSharedDirs) : ((DirectoryStorage*)mRemoteDirectories[fi-1]); + + if((flags & RS_FILE_HINTS_LOCAL) && fi == 1) // extra list + { + getExtraFilesDirDetails(ref,e,d); + +#ifdef DEBUG_FILE_HIERARCHY + P3FILELISTS_DEBUG() << "ExtractData: ref=" << ref << ", flags=" << flags << " : returning this: " << std::endl; + P3FILELISTS_DEBUG() << d << std::endl; +#endif + return true; + } + + + DirectoryStorage *storage = (flags & RS_FILE_HINTS_LOCAL)? ((DirectoryStorage*)mLocalSharedDirs) : ((DirectoryStorage*)mRemoteDirectories[fi-1]); // Case where the index is the top of a single person. Can be us, or a friend. diff --git a/libretroshare/src/file_sharing/p3filelists.h b/libretroshare/src/file_sharing/p3filelists.h index a8ac377ea..8e35c0bf2 100644 --- a/libretroshare/src/file_sharing/p3filelists.h +++ b/libretroshare/src/file_sharing/p3filelists.h @@ -45,6 +45,7 @@ #pragma once #include "ft/ftsearch.h" +#include "ft/ftextralist.h" #include "retroshare/rsfiles.h" #include "services/p3service.h" @@ -87,9 +88,10 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub // [...] more to add here }; - explicit p3FileDatabase(p3ServiceControl *mpeers) ; + explicit p3FileDatabase(p3ServiceControl *mpeers); ~p3FileDatabase(); + void setExtraList(ftExtraList *f) { mExtraFiles = f ; } /*! * \brief forceSyncWithPeers * @@ -169,6 +171,7 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub bool hashingProcessPaused(); protected: + void getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIndex e,DirDetails& d) const; int filterResults(const std::list& firesults,std::list& results,FileSearchFlags flags,const RsPeerId& peer_id) const; std::string makeRemoteFileName(const RsPeerId& pid) const; @@ -219,8 +222,8 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub std::vector mRemoteDirectories ; LocalDirectoryStorage *mLocalSharedDirs ; - LocalDirectoryUpdater *mLocalDirWatcher ; + ftExtraList *mExtraFiles; // utility functions to make/get a pointer out of an (EntryIndex,PeerId) pair. This is further documented in the .cc @@ -268,6 +271,8 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub std::map mPrimaryBanList ; // primary list (user controlled) of files banned from FT search and forwarding. map std::map mPeerBannedFiles ; // records of which files other peers ban, stored as H(H(f)) std::set mBannedFileList ; // list of banned hashes. This include original hashs and H(H(f)) when coming from friends. + mutable std::vector mExtraFilesCache; // cache for extra files, to avoid requesting them too often. + mutable time_t mLastExtraFilesCacheUpdate ; bool mTrustFriendNodesForBannedFiles ; bool mBannedFileListNeedsUpdate; time_t mLastPrimaryBanListChangeTimeStamp; diff --git a/libretroshare/src/ft/ftextralist.cc b/libretroshare/src/ft/ftextralist.cc index cf5a4f603..a8ad41b23 100644 --- a/libretroshare/src/ft/ftextralist.cc +++ b/libretroshare/src/ft/ftextralist.cc @@ -96,7 +96,7 @@ void ftExtraList::hashAFile() FileDetails details; { - RsStackMutex stack(extMutex); + RS_STACK_MUTEX(extMutex); if (mToHash.empty()) return; @@ -116,7 +116,7 @@ void ftExtraList::hashAFile() if (RsDirUtil::hashFile(details.info.path, details.info.fname, details.info.hash, details.info.size)) { - RsStackMutex stack(extMutex); + RS_STACK_MUTEX(extMutex); /* stick it in the available queue */ mFiles[details.info.hash] = details; @@ -146,7 +146,7 @@ bool ftExtraList::addExtraFile(std::string path, const RsFileHash& hash, std::cerr << std::endl; #endif - RsStackMutex stack(extMutex); + RS_STACK_MUTEX(extMutex); FileDetails details; @@ -179,7 +179,7 @@ bool ftExtraList::removeExtraFile(const RsFileHash& hash, TransferRequestFlags f std::cerr << std::endl; #endif - RsStackMutex stack(extMutex); + RS_STACK_MUTEX(extMutex); mHashOfHash.erase(makeEncryptedHash(hash)) ; @@ -230,7 +230,7 @@ bool ftExtraList::cleanupOldFiles() std::cerr << std::endl; #endif - RsStackMutex stack(extMutex); + RS_STACK_MUTEX(extMutex); time_t now = time(NULL); @@ -286,7 +286,7 @@ bool ftExtraList::hashExtraFile(std::string path, uint32_t period, TransferRequ #endif /* add into queue */ - RsStackMutex stack(extMutex); + RS_STACK_MUTEX(extMutex); FileDetails details(path, period, flags); details.info.age = time(NULL) + period; @@ -305,7 +305,7 @@ bool ftExtraList::hashExtraFileDone(std::string path, FileInfo &info) RsFileHash hash; { /* Find in the path->hash map */ - RsStackMutex stack(extMutex); + RS_STACK_MUTEX(extMutex); std::map::iterator it; if (mHashedList.end() == (it = mHashedList.find(path))) @@ -420,7 +420,7 @@ bool ftExtraList::saveList(bool &cleanup, std::list& sList) std::cerr << std::endl; #endif - RsStackMutex stack(extMutex); + RS_STACK_MUTEX(extMutex); std::map::const_iterator it; @@ -489,8 +489,8 @@ bool ftExtraList::loadList(std::list& load) /* add into system */ FileDetails file; - RsStackMutex stack(extMutex); - + RS_STACK_MUTEX(extMutex); + FileDetails details; details.info.path = fi->file.path; @@ -513,3 +513,12 @@ bool ftExtraList::loadList(std::list& load) return true; } +void ftExtraList::getExtraFileList(std::vector& files) const +{ + RS_STACK_MUTEX(extMutex); + + files.clear(); + + for(auto it(mFiles.begin());it!=mFiles.end();++it) + files.push_back(it->second.info); +} diff --git a/libretroshare/src/ft/ftextralist.h b/libretroshare/src/ft/ftextralist.h index 5832b33fd..8f6b3cbd2 100644 --- a/libretroshare/src/ft/ftextralist.h +++ b/libretroshare/src/ft/ftextralist.h @@ -137,6 +137,12 @@ public: **/ virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const; + /*! + * \brief getExtraFileList + * Retrieves the list for display purposes + */ + void getExtraFileList(std::vector& files) const ; + /*** * Thread Main Loop **/ @@ -146,6 +152,7 @@ public: * Configuration - store extra files. * **/ + protected: virtual RsSerialiser *setupSerialiser(); virtual bool saveList(bool &cleanup, std::list&); diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 182964446..cf81cbcc8 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -174,8 +174,11 @@ void ftServer::SetupFtServer() void ftServer::connectToFileDatabase(p3FileDatabase *fdb) { mFileDatabase = fdb ; + mFtSearch->addSearchMode(fdb, RS_FILE_HINTS_LOCAL); // due to a bug in addSearchModule, modules can only be added one by one. Using | between flags wont work. mFtSearch->addSearchMode(fdb, RS_FILE_HINTS_REMOTE); + + mFileDatabase->setExtraList(mFtExtra); } void ftServer::connectToTurtleRouter(p3turtle *fts) { diff --git a/libretroshare/src/retroshare/rstypes.h b/libretroshare/src/retroshare/rstypes.h index b1b35748c..9b480f6f8 100644 --- a/libretroshare/src/retroshare/rstypes.h +++ b/libretroshare/src/retroshare/rstypes.h @@ -160,6 +160,7 @@ struct PeerBandwidthLimits : RsSerializable #define DIR_TYPE_PERSON 0x02 #define DIR_TYPE_DIR 0x04 #define DIR_TYPE_FILE 0x08 +#define DIR_TYPE_EXTRA 0x10 /* flags for Directry request - * two types; diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 22fb0af5b..8eee722c7 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -1158,9 +1158,9 @@ void FlatStyle_RDM::postMods() bool RetroshareDirModel::requestDirDetails(void *ref, bool remote,DirDetails& d) const { -#ifdef RDM_DEBUG +//#ifdef RDM_DEBUG std::cerr << "RequestDirDetails:: ref = " << ref << ", remote=" << remote << std::endl; -#endif +//#endif // We look in cache and re-use the last result if the reference and remote are the same. From 7ab7c7db93a4287d801a8c52ba590b84f23b5f57 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Sep 2018 16:53:08 +0200 Subject: [PATCH 2/8] added possibility to remove extra shared file --- libretroshare/src/file_sharing/p3filelists.cc | 41 +++++++-- libretroshare/src/file_sharing/p3filelists.h | 5 +- libretroshare/src/ft/ftextralist.cc | 4 +- libretroshare/src/ft/ftextralist.h | 2 +- libretroshare/src/ft/ftserver.cc | 9 +- libretroshare/src/ft/ftserver.h | 2 +- libretroshare/src/retroshare/rsfiles.h | 2 +- libretroshare/src/retroshare/rstypes.h | 2 +- libretroshare/src/services/p3gxschannels.cc | 4 +- .../gui/FileTransfer/SharedFilesDialog.cpp | 92 ++++++++++++------- .../src/gui/FileTransfer/SharedFilesDialog.h | 2 + retroshare-gui/src/gui/RemoteDirModel.cpp | 27 +++--- retroshare-gui/src/gui/feeds/SubFileItem.cpp | 2 +- 13 files changed, 125 insertions(+), 69 deletions(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index c6ee048be..4a0b92d4f 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -37,8 +37,8 @@ #define P3FILELISTS_ERROR() std::cerr << "***ERROR***" << " : FILE_LISTS : " << __FUNCTION__ << " : " //#define DEBUG_P3FILELISTS 1 -#define DEBUG_CONTENT_FILTERING 1 -#define DEBUG_FILE_HIERARCHY 1 +//#define DEBUG_CONTENT_FILTERING 1 +//#define DEBUG_FILE_HIERARCHY 1 static const uint32_t P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED = 0x0000 ; static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED = 0x0001 ; @@ -960,6 +960,14 @@ int p3FileDatabase::getSharedDirStatistics(const RsPeerId& pid,SharedDirStats& s } } +void p3FileDatabase::removeExtraFile(const RsFileHash& hash) +{ + RS_STACK_MUTEX(mFLSMtx) ; + + mExtraFiles->removeExtraFile(hash); + mLastExtraFilesCacheUpdate = 0 ; // forced cache reload +} + void p3FileDatabase::getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIndex e,DirDetails& d) const { // update the cache of extra files if last requested too long ago @@ -1001,7 +1009,7 @@ void p3FileDatabase::getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIn else // extra file. Just query the corresponding data from ftExtra { d.prow = 1;//fi-1 ; - d.type = DIR_TYPE_FILE; + d.type = DIR_TYPE_EXTRA_FILE; FileInfo& f(mExtraFilesCache[(int)e-1]) ; @@ -1068,7 +1076,7 @@ int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags { convertEntryIndexToPointer(0,1,p); // local shared files from extra list DirStub stub; - stub.type = DIR_TYPE_PERSON; + stub.type = DIR_TYPE_PERSON; // not totally exact, but used as a trick. stub.name = "Temporary shared files"; stub.ref = p; @@ -1179,7 +1187,7 @@ int p3FileDatabase::RequestDirDetails(const RsPeerId &/*uid*/, const std::string // NOT_IMPLEMENTED(); // return 0; //} -uint32_t p3FileDatabase::getType(void *ref) const +uint32_t p3FileDatabase::getType(void *ref,FileSearchFlags flags) const { RS_STACK_MUTEX(mFLSMtx) ; @@ -1194,12 +1202,25 @@ uint32_t p3FileDatabase::getType(void *ref) const if(e == 0) return DIR_TYPE_PERSON ; - if(fi == 0 && mLocalSharedDirs != NULL) - return mLocalSharedDirs->getEntryType(e) ; - else if(fi-1 < mRemoteDirectories.size() && mRemoteDirectories[fi-1]!=NULL) - return mRemoteDirectories[fi-1]->getEntryType(e) ; - else + if(flags & RS_FILE_HINTS_LOCAL) + { + if(fi == 0 && mLocalSharedDirs != NULL) + return mLocalSharedDirs->getEntryType(e) ; + + if(fi == 1) + return DIR_TYPE_EXTRA_FILE; + + P3FILELISTS_ERROR() << " Cannot determine type of entry " << ref << std::endl; return DIR_TYPE_ROOT ;// some failure case. Should not happen + } + else + { + if(fi-1 < mRemoteDirectories.size() && mRemoteDirectories[fi-1]!=NULL) + return mRemoteDirectories[fi-1]->getEntryType(e) ; + + P3FILELISTS_ERROR() << " Cannot determine type of entry " << ref << std::endl; + return DIR_TYPE_ROOT ;// some failure case. Should not happen + } } void p3FileDatabase::forceDirectoryCheck() // Force re-sweep the directories and see what's changed diff --git a/libretroshare/src/file_sharing/p3filelists.h b/libretroshare/src/file_sharing/p3filelists.h index 8e35c0bf2..b6d88328a 100644 --- a/libretroshare/src/file_sharing/p3filelists.h +++ b/libretroshare/src/file_sharing/p3filelists.h @@ -109,6 +109,9 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub virtual int SearchKeywords(const std::list& keywords, std::list& results,FileSearchFlags flags,const RsPeerId& peer_id) ; virtual int SearchBoolExp(RsRegularExpression::Expression *exp, std::list& results,FileSearchFlags flags,const RsPeerId& peer_id) const ; + // Extra file list + virtual void removeExtraFile(const RsFileHash& hash); + // Interface for browsing dir hierarchy // @@ -121,7 +124,7 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub void requestDirUpdate(void *ref) ; // triggers an update. Used when browsing. int RequestDirDetails(void *, DirDetails&, FileSearchFlags) const ; - uint32_t getType(void *) const ; + uint32_t getType(void *, FileSearchFlags flags) const ; // proxy method used by the web UI. Dont't delete! int RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details)const; diff --git a/libretroshare/src/ft/ftextralist.cc b/libretroshare/src/ft/ftextralist.cc index a8ad41b23..d15a848bb 100644 --- a/libretroshare/src/ft/ftextralist.cc +++ b/libretroshare/src/ft/ftextralist.cc @@ -166,11 +166,9 @@ bool ftExtraList::addExtraFile(std::string path, const RsFileHash& hash, return true; } -bool ftExtraList::removeExtraFile(const RsFileHash& hash, TransferRequestFlags flags) +bool ftExtraList::removeExtraFile(const RsFileHash& hash) { /* remove unused parameter warnings */ - (void) flags; - #ifdef DEBUG_ELIST std::cerr << "ftExtraList::removeExtraFile()"; std::cerr << " hash: " << hash; diff --git a/libretroshare/src/ft/ftextralist.h b/libretroshare/src/ft/ftextralist.h index 8f6b3cbd2..bc470e677 100644 --- a/libretroshare/src/ft/ftextralist.h +++ b/libretroshare/src/ft/ftextralist.h @@ -117,7 +117,7 @@ public: bool addExtraFile(std::string path, const RsFileHash &hash, uint64_t size, uint32_t period, TransferRequestFlags flags); - bool removeExtraFile(const RsFileHash& hash, TransferRequestFlags flags); + bool removeExtraFile(const RsFileHash& hash); bool moveExtraFile(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath); diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index cf81cbcc8..227f84d23 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -677,9 +677,10 @@ bool ftServer::ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t return mFtExtra->addExtraFile(fname, hash, size, period, flags); } -bool ftServer::ExtraFileRemove(const RsFileHash& hash, TransferRequestFlags flags) +bool ftServer::ExtraFileRemove(const RsFileHash& hash) { - return mFtExtra->removeExtraFile(hash, flags); + mFileDatabase->removeExtraFile(hash); + return true; } bool ftServer::ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags) @@ -714,9 +715,9 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags { return mFileDatabase->RequestDirDetails(ref,details,flags) ; } -uint32_t ftServer::getType(void *ref, FileSearchFlags /* flags */) +uint32_t ftServer::getType(void *ref, FileSearchFlags flags) { - return mFileDatabase->getType(ref) ; + return mFileDatabase->getType(ref,flags) ; } /***************************************************************/ /******************** Search Interface *************************/ diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index c15c991fc..167ac72dd 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -180,7 +180,7 @@ public: * Extra List Access ***/ virtual bool ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t size, uint32_t period, TransferRequestFlags flags); - virtual bool ExtraFileRemove(const RsFileHash& hash, TransferRequestFlags flags); + virtual bool ExtraFileRemove(const RsFileHash& hash); virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags); virtual bool ExtraFileStatus(std::string localpath, FileInfo &info); virtual bool ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath); diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 1a77cb829..9d5231042 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -409,7 +409,7 @@ public: * Extra List Access ***/ //virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, TransferRequestFlags flags) = 0; - virtual bool ExtraFileRemove(const RsFileHash& hash, TransferRequestFlags flags) = 0; + virtual bool ExtraFileRemove(const RsFileHash& hash) = 0; virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags) = 0; virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0; virtual bool ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath) = 0; diff --git a/libretroshare/src/retroshare/rstypes.h b/libretroshare/src/retroshare/rstypes.h index 9b480f6f8..71a994cc1 100644 --- a/libretroshare/src/retroshare/rstypes.h +++ b/libretroshare/src/retroshare/rstypes.h @@ -160,7 +160,7 @@ struct PeerBandwidthLimits : RsSerializable #define DIR_TYPE_PERSON 0x02 #define DIR_TYPE_DIR 0x04 #define DIR_TYPE_FILE 0x08 -#define DIR_TYPE_EXTRA 0x10 +#define DIR_TYPE_EXTRA_FILE 0x10 /* flags for Directry request - * two types; diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index 386fe4ee0..534fcfaba 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -1291,9 +1291,9 @@ bool p3GxsChannels::ExtraFileHash(const std::string& path) bool p3GxsChannels::ExtraFileRemove(const RsFileHash &hash) { - TransferRequestFlags tflags = RS_FILE_REQ_ANONYMOUS_ROUTING | RS_FILE_REQ_EXTRA; + //TransferRequestFlags tflags = RS_FILE_REQ_ANONYMOUS_ROUTING | RS_FILE_REQ_EXTRA; RsFileHash fh = RsFileHash(hash); - return rsFiles->ExtraFileRemove(fh, tflags); + return rsFiles->ExtraFileRemove(fh); } diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index cbb420eba..c1ba31b50 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -76,6 +76,7 @@ #define IMAGE_COLLOPEN ":/images/library.png" #define IMAGE_EDITSHARE ":/images/edit_16.png" #define IMAGE_MYFILES ":/icons/svg/folders1.svg" +#define IMAGE_REMOVE ":/images/deletemail24.png" /*define viewType_CB value */ #define VIEW_TYPE_TREE 0 @@ -229,6 +230,9 @@ SharedFilesDialog::SharedFilesDialog(RetroshareDirModel *_tree_model,RetroshareD sendlinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Links" ), this ); connect( sendlinkAct , SIGNAL( triggered() ), this, SLOT( sendLinkTo( ) ) ); + removeExtraFileAct = new QAction(QIcon(IMAGE_REMOVE), tr( "Stop sharing this file" ), this ); + connect( removeExtraFileAct , SIGNAL( triggered() ), this, SLOT( removeExtraFile() ) ); + collCreateAct= new QAction(QIcon(IMAGE_COLLCREATE), tr("Create Collection..."), this) ; connect(collCreateAct,SIGNAL(triggered()),this,SLOT(collCreate())) ; collModifAct= new QAction(QIcon(IMAGE_COLLMODIF), tr("Modify Collection..."), this) ; @@ -1093,7 +1097,7 @@ void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) currentFile = model->data(midx, RetroshareDirModel::FileNameRole).toString() ; int type = model->getType(midx) ; - if (type != DIR_TYPE_DIR && type != DIR_TYPE_FILE) return; + if (type != DIR_TYPE_DIR && type != DIR_TYPE_FILE && type != DIR_TYPE_EXTRA_FILE) return; QMenu contextMnu(this) ; @@ -1127,58 +1131,70 @@ void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) contextMnu.addMenu(&collectionMenu) ; contextMnu.addSeparator() ;//------------------------------------ contextMnu.addAction(QIcon(IMAGE_MSG), tr("Recommend in a message to..."), this, SLOT(recommendFilesToMsg())) ; + break; + + case DIR_TYPE_EXTRA_FILE: + contextMnu.addAction(openfileAct) ; + contextMnu.addSeparator() ;//------------------------------------ + contextMnu.addAction(copylinkAct) ; + contextMnu.addAction(sendlinkAct) ; + contextMnu.addAction(removeExtraFileAct) ; + break ; default : return ; } - GxsChannelDialog *channelDialog = dynamic_cast(MainWindow::getPage(MainWindow::Channels)); - QMenu shareChannelMenu(tr("Share on channel...")) ; // added here because the shareChannelMenu QMenu object is deleted afterwards - - if(channelDialog != NULL) + if(type != DIR_TYPE_EXTRA_FILE) { - shareChannelMenu.setIcon(QIcon(IMAGE_CHANNEL)); + GxsChannelDialog *channelDialog = dynamic_cast(MainWindow::getPage(MainWindow::Channels)); + QMenu shareChannelMenu(tr("Share on channel...")) ; // added here because the shareChannelMenu QMenu object is deleted afterwards - std::map grp_metas ; - channelDialog->getGroupList(grp_metas) ; + if(channelDialog != NULL) + { + shareChannelMenu.setIcon(QIcon(IMAGE_CHANNEL)); - std::vector > grplist ; // I dont use a std::map because two or more channels may have the same name. + std::map grp_metas ; + channelDialog->getGroupList(grp_metas) ; - for(auto it(grp_metas.begin());it!=grp_metas.end();++it) - if(IS_GROUP_PUBLISHER((*it).second.mSubscribeFlags) && IS_GROUP_SUBSCRIBED((*it).second.mSubscribeFlags)) - grplist.push_back(std::make_pair((*it).second.mGroupName, (*it).second.mGroupId)); + std::vector > grplist ; // I dont use a std::map because two or more channels may have the same name. - std::sort(grplist.begin(),grplist.end(),ChannelCompare()) ; + for(auto it(grp_metas.begin());it!=grp_metas.end();++it) + if(IS_GROUP_PUBLISHER((*it).second.mSubscribeFlags) && IS_GROUP_SUBSCRIBED((*it).second.mSubscribeFlags)) + grplist.push_back(std::make_pair((*it).second.mGroupName, (*it).second.mGroupId)); - for(auto it(grplist.begin());it!=grplist.end();++it) + std::sort(grplist.begin(),grplist.end(),ChannelCompare()) ; + + for(auto it(grplist.begin());it!=grplist.end();++it) shareChannelMenu.addAction(QString::fromUtf8((*it).first.c_str()), this, SLOT(shareOnChannel()))->setData(QString::fromStdString((*it).second.toStdString())) ; - contextMnu.addMenu(&shareChannelMenu) ; - } + contextMnu.addMenu(&shareChannelMenu) ; + } - GxsForumsDialog *forumsDialog = dynamic_cast(MainWindow::getPage(MainWindow::Forums)); - QMenu shareForumMenu(tr("Share on forum...")) ; // added here because the shareChannelMenu QMenu object is deleted afterwards + GxsForumsDialog *forumsDialog = dynamic_cast(MainWindow::getPage(MainWindow::Forums)); + QMenu shareForumMenu(tr("Share on forum...")) ; // added here because the shareChannelMenu QMenu object is deleted afterwards - if(forumsDialog != NULL) - { - shareForumMenu.setIcon(QIcon(IMAGE_FORUMS)); + if(forumsDialog != NULL) + { + shareForumMenu.setIcon(QIcon(IMAGE_FORUMS)); - std::map grp_metas ; - forumsDialog->getGroupList(grp_metas) ; + std::map grp_metas ; + forumsDialog->getGroupList(grp_metas) ; - std::vector > grplist ; // I dont use a std::map because two or more channels may have the same name. + std::vector > grplist ; // I dont use a std::map because two or more channels may have the same name. - for(auto it(grp_metas.begin());it!=grp_metas.end();++it) - if(IS_GROUP_SUBSCRIBED((*it).second.mSubscribeFlags)) - grplist.push_back(std::make_pair((*it).second.mGroupName, (*it).second.mGroupId)); + for(auto it(grp_metas.begin());it!=grp_metas.end();++it) + if(IS_GROUP_SUBSCRIBED((*it).second.mSubscribeFlags)) + grplist.push_back(std::make_pair((*it).second.mGroupName, (*it).second.mGroupId)); - std::sort(grplist.begin(),grplist.end(),ChannelCompare()) ; + std::sort(grplist.begin(),grplist.end(),ChannelCompare()) ; - for(auto it(grplist.begin());it!=grplist.end();++it) - shareForumMenu.addAction(QString::fromUtf8((*it).first.c_str()), this, SLOT(shareInForum()))->setData(QString::fromStdString((*it).second.toStdString())) ; + for(auto it(grplist.begin());it!=grplist.end();++it) + shareForumMenu.addAction(QString::fromUtf8((*it).first.c_str()), this, SLOT(shareInForum()))->setData(QString::fromStdString((*it).second.toStdString())) ; - contextMnu.addMenu(&shareForumMenu) ; + contextMnu.addMenu(&shareForumMenu) ; + } } contextMnu.exec(QCursor::pos()) ; @@ -1564,6 +1580,20 @@ void SharedFilesDialog::FilterItems() #endif } +void SharedFilesDialog::removeExtraFile() +{ + std::list files_info ; + + model->getFileInfoFromIndexList(getSelected(),files_info); + + for(auto it(files_info.begin());it!=files_info.end();++it) + { + std::cerr << "removing file " << (*it).name << ", hash = " << (*it).hash << std::endl; + + rsFiles->ExtraFileRemove((*it).hash); + } +} + #ifdef DEPRECATED_CODE bool SharedFilesDialog::flat_FilterItem(const QModelIndex &index, const QString &text, int /*level*/) { diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h index 0d35260ee..ae231ee93 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h @@ -66,6 +66,7 @@ private slots: void copyLink(); void copyLinkhtml(); void sendLinkTo(); + void removeExtraFile(); void collCreate(); void collModif(); @@ -122,6 +123,7 @@ protected: QAction* sendlinkAct; QAction* sendchatlinkAct; QAction* copylinkhtmlAct; + QAction* removeExtraFileAct; QAction *collCreateAct; QAction *collModifAct; diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 8eee722c7..a754cf328 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -162,7 +162,7 @@ bool TreeStyle_RDM::hasChildren(const QModelIndex &parent) const return false; } - if (details.type == DIR_TYPE_FILE) + if (details.type == DIR_TYPE_FILE || details.type == DIR_TYPE_EXTRA_FILE) { #ifdef RDM_DEBUG std::cerr << "lookup FILE -> false"; @@ -220,7 +220,7 @@ int TreeStyle_RDM::rowCount(const QModelIndex &parent) const #endif return 0; } - if (details.type == DIR_TYPE_FILE) + if (details.type == DIR_TYPE_FILE || details.type == DIR_TYPE_EXTRA_FILE) { #ifdef RDM_DEBUG std::cerr << "lookup FILE: 0"; @@ -425,7 +425,7 @@ QVariant RetroshareDirModel::decorationRole(const DirDetails& details,int coln) else return QIcon(categoryIcon); } - else if (details.type == DIR_TYPE_FILE) /* File */ + else if (details.type == DIR_TYPE_FILE || details.type == DIR_TYPE_EXTRA_FILE) /* File */ { // extensions predefined if(details.hash.isNull()) @@ -506,7 +506,7 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const return QString() ; } } - else if (details.type == DIR_TYPE_FILE) /* File */ + else if (details.type == DIR_TYPE_FILE || details.type == DIR_TYPE_EXTRA_FILE) /* File */ { switch(coln) { @@ -598,7 +598,7 @@ QString FlatStyle_RDM::computeDirectoryPath(const DirDetails& details) const QVariant FlatStyle_RDM::displayRole(const DirDetails& details,int coln) const { - if (details.type == DIR_TYPE_FILE) /* File */ + if (details.type == DIR_TYPE_FILE || details.type == DIR_TYPE_EXTRA_FILE) /* File */ switch(coln) { case COLUMN_NAME: return QString::fromUtf8(details.name.c_str()); @@ -654,7 +654,7 @@ QVariant TreeStyle_RDM::sortRole(const QModelIndex& /*index*/,const DirDetails& return QString(); } } - else if (details.type == DIR_TYPE_FILE) /* File */ + else if (details.type == DIR_TYPE_FILE || details.type == DIR_TYPE_EXTRA_FILE) /* File */ { switch(coln) { @@ -707,7 +707,7 @@ QVariant FlatStyle_RDM::sortRole(const QModelIndex& /*index*/,const DirDetails& * Dir : name, (0) count, (0) path, (0) ts */ - if (details.type == DIR_TYPE_FILE) /* File */ + if (details.type == DIR_TYPE_FILE || details.type == DIR_TYPE_EXTRA_FILE) /* File */ { switch(coln) { @@ -769,7 +769,7 @@ QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const if (role == Qt::TextColorRole) { - if(details.type == DIR_TYPE_FILE && details.hash.isNull()) + if((details.type == DIR_TYPE_FILE || details.type == DIR_TYPE_EXTRA_FILE) && details.hash.isNull()) return QVariant(QColor(Qt::green)) ; else if(ageIndicator != IND_ALWAYS && details.max_mtime + ageIndicator < time(NULL)) return QVariant(QColor(Qt::gray)) ; @@ -1083,6 +1083,7 @@ Qt::ItemFlags RetroshareDirModel::flags( const QModelIndex & index ) const case DIR_TYPE_PERSON: return isNewerThanEpoque(details.max_mtime)? (Qt::ItemIsEnabled):(Qt::NoItemFlags) ; case DIR_TYPE_DIR: return Qt::ItemIsSelectable | Qt::ItemIsEnabled; case DIR_TYPE_FILE: return Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled; + case DIR_TYPE_EXTRA_FILE: return Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled; } return Qt::ItemIsSelectable; @@ -1158,9 +1159,9 @@ void FlatStyle_RDM::postMods() bool RetroshareDirModel::requestDirDetails(void *ref, bool remote,DirDetails& d) const { -//#ifdef RDM_DEBUG +#ifdef RDM_DEBUG std::cerr << "RequestDirDetails:: ref = " << ref << ", remote=" << remote << std::endl; -//#endif +#endif // We look in cache and re-use the last result if the reference and remote are the same. @@ -1400,7 +1401,7 @@ void RetroshareDirModel::openSelected(const QModelIndexList &qmil) QDir dir(QString::fromUtf8((*it).path.c_str())); QString dest; - if ((*it).type & DIR_TYPE_FILE) { + if ((*it).type & DIR_TYPE_FILE || (*it).type & DIR_TYPE_EXTRA_FILE) { dest = dir.absoluteFilePath(QString::fromUtf8(it->name.c_str())); } else if ((*it).type & DIR_TYPE_DIR) { dest = dir.absolutePath(); @@ -1509,7 +1510,7 @@ void RetroshareDirModel::filterItems(const std::list& keywords,uint mFilteredPointers.insert(p) ; ++found ; - while(det.type == DIR_TYPE_FILE || det.type == DIR_TYPE_DIR) + while(det.type == DIR_TYPE_FILE || det.type == DIR_TYPE_EXTRA_FILE || det.type == DIR_TYPE_DIR) { p = det.parent ; rsFiles->RequestDirDetails( p, det, flags); @@ -1555,7 +1556,7 @@ QMimeData * RetroshareDirModel::mimeData ( const QModelIndexList & indexes ) con std::cerr << "Path: " << details.path << std::endl; #endif - if (details.type != DIR_TYPE_FILE) + if (details.type != DIR_TYPE_FILE && details.type != DIR_TYPE_EXTRA_FILE) { #ifdef RDM_DEBUG std::cerr << "RetroshareDirModel::mimeData() Not File" << std::endl; diff --git a/retroshare-gui/src/gui/feeds/SubFileItem.cpp b/retroshare-gui/src/gui/feeds/SubFileItem.cpp index 0e3350127..3b6ec3896 100644 --- a/retroshare-gui/src/gui/feeds/SubFileItem.cpp +++ b/retroshare-gui/src/gui/feeds/SubFileItem.cpp @@ -561,7 +561,7 @@ void SubFileItem::cancel() if (((mType == SFI_TYPE_ATTACH) || (mType == SFI_TYPE_CHANNEL)) && (mFlag & SFI_FLAG_CREATE)) { hide(); - rsFiles->ExtraFileRemove(FileHash(), RS_FILE_REQ_ANONYMOUS_ROUTING | RS_FILE_REQ_EXTRA); + rsFiles->ExtraFileRemove(FileHash());//, RS_FILE_REQ_ANONYMOUS_ROUTING | RS_FILE_REQ_EXTRA); mPath = ""; } else From c77a28c17af73896bb1d9732fb9eeab4ac943fe6 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Sep 2018 21:20:06 +0200 Subject: [PATCH 3/8] added proper notification when removing an extra file --- libretroshare/src/file_sharing/p3filelists.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 4a0b92d4f..6331c6c03 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -962,10 +962,14 @@ int p3FileDatabase::getSharedDirStatistics(const RsPeerId& pid,SharedDirStats& s void p3FileDatabase::removeExtraFile(const RsFileHash& hash) { + { RS_STACK_MUTEX(mFLSMtx) ; mExtraFiles->removeExtraFile(hash); mLastExtraFilesCacheUpdate = 0 ; // forced cache reload + } + + RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); } void p3FileDatabase::getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIndex e,DirDetails& d) const From 2610f62e419f8a347af37fc71982c9008c3a67e8 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Sep 2018 21:42:21 +0200 Subject: [PATCH 4/8] fixed display of temporary shared file text --- libretroshare/src/file_sharing/p3filelists.cc | 11 ++++++----- retroshare-gui/src/gui/RemoteDirModel.cpp | 11 +++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 6331c6c03..c64b89069 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -991,12 +991,12 @@ void p3FileDatabase::getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIn d.parent = NULL ; d.prow = 0;//fi-1 ; - d.type = DIR_TYPE_DIR; + d.type = DIR_TYPE_PERSON; d.hash.clear() ; d.count = mExtraFilesCache.size(); d.max_mtime = time(NULL); d.mtime = time(NULL); - d.name = "Temporary shared files"; + d.name = "Extra List"; d.path = "/"; d.ref = ref ; @@ -1021,13 +1021,14 @@ void p3FileDatabase::getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIn d.count = 0; d.max_mtime = time(NULL); d.mtime = time(NULL); - d.name = f.fname; - d.path = "/"; + d.name = f.path; // so that the UI shows the complete path, since the parent directory is not really a directory. + d.path = f.path; d.ref = ref ; convertEntryIndexToPointer(0,1,d.parent) ; } + d.flags = DIR_FLAGS_ANONYMOUS_DOWNLOAD ; d.id = RsPeerId(); } @@ -1081,7 +1082,7 @@ int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags convertEntryIndexToPointer(0,1,p); // local shared files from extra list DirStub stub; stub.type = DIR_TYPE_PERSON; // not totally exact, but used as a trick. - stub.name = "Temporary shared files"; + stub.name = "Extra List"; stub.ref = p; d.children.push_back(stub); diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index a754cf328..2d9820690 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -457,13 +457,12 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const QString res ; if(RemoteMode) - { res = QString::fromUtf8(rsPeers->getPeerName(details.id).c_str()); - } - else - { - res = tr("My files"); - } + else if(details.id == rsPeers->getOwnId()) + res = tr("My files"); + else + res = tr("Temporary shared files"); + return res ; } case COLUMN_FILENB: { From e1698429de4e997003104146fdb774137a2a319e Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Sep 2018 21:46:00 +0200 Subject: [PATCH 5/8] fixed display of size --- libretroshare/src/file_sharing/p3filelists.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index c64b89069..ab76bec52 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -1018,7 +1018,7 @@ void p3FileDatabase::getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIn FileInfo& f(mExtraFilesCache[(int)e-1]) ; d.hash = f.hash; - d.count = 0; + d.count = f.size; d.max_mtime = time(NULL); d.mtime = time(NULL); d.name = f.path; // so that the UI shows the complete path, since the parent directory is not really a directory. From 54ec49dc032d057ffd8de702d2a0fb0b7d131aec Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Sep 2018 21:56:41 +0200 Subject: [PATCH 6/8] make extra shared file list appear only when non empty --- libretroshare/src/file_sharing/p3filelists.cc | 2 ++ libretroshare/src/ft/ftextralist.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index ab76bec52..c8b5749d9 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -1078,6 +1078,8 @@ int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags stub.ref = p; d.children.push_back(stub); } + + if(mExtraFiles->size() > 0) { convertEntryIndexToPointer(0,1,p); // local shared files from extra list DirStub stub; diff --git a/libretroshare/src/ft/ftextralist.h b/libretroshare/src/ft/ftextralist.h index bc470e677..6d89cfe7b 100644 --- a/libretroshare/src/ft/ftextralist.h +++ b/libretroshare/src/ft/ftextralist.h @@ -122,6 +122,8 @@ public: std::string destpath); + uint32_t size() const { return mFiles.size() ; } + /*** * Hash file, and add to the files, * file is removed after period. From 752275f813c866ab72cefd706d72539027b5608a Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Sep 2018 22:14:00 +0200 Subject: [PATCH 7/8] fixed various display bugs in extra file list --- libretroshare/src/file_sharing/p3filelists.cc | 4 ++-- libretroshare/src/ft/ftextralist.cc | 3 +-- retroshare-gui/src/gui/RemoteDirModel.cpp | 14 ++++++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index c8b5749d9..8da837bc6 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -1019,8 +1019,8 @@ void p3FileDatabase::getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIn d.hash = f.hash; d.count = f.size; - d.max_mtime = time(NULL); - d.mtime = time(NULL); + d.max_mtime = 0; // this is irrelevant + d.mtime = 0; // this is irrelevant d.name = f.path; // so that the UI shows the complete path, since the parent directory is not really a directory. d.path = f.path; d.ref = ref ; diff --git a/libretroshare/src/ft/ftextralist.cc b/libretroshare/src/ft/ftextralist.cc index d15a848bb..2c8152d3e 100644 --- a/libretroshare/src/ft/ftextralist.cc +++ b/libretroshare/src/ft/ftextralist.cc @@ -113,8 +113,7 @@ void ftExtraList::hashAFile() /* hash it! */ std::string name, hash; //uint64_t size; - if (RsDirUtil::hashFile(details.info.path, details.info.fname, - details.info.hash, details.info.size)) + if (RsDirUtil::hashFile(details.info.path, details.info.fname, details.info.hash, details.info.size)) { RS_STACK_MUTEX(extMutex); diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 2d9820690..e0da77b2e 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -470,8 +470,10 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const if(RemoteMode) rsFiles->getSharedDirStatistics(details.id,stats) ; - else + else if(details.id == rsPeers->getOwnId()) rsFiles->getSharedDirStatistics(rsPeers->getOwnId(),stats) ; + else + stats.total_number_of_files = details.count; if(stats.total_number_of_files > 0) { @@ -487,8 +489,10 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const if(RemoteMode) rsFiles->getSharedDirStatistics(details.id,stats) ; - else + else if(details.id == rsPeers->getOwnId()) rsFiles->getSharedDirStatistics(rsPeers->getOwnId(),stats) ; + else + return QString(); if(stats.total_shared_size > 0) return misc::friendlyUnit(stats.total_shared_size) ; @@ -498,6 +502,8 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const case COLUMN_AGE: if(!isNewerThanEpoque(details.max_mtime)) return QString(); + else if(details.id != rsPeers->getOwnId()) + return QString(); else return misc::timeRelativeToNow(details.max_mtime); @@ -516,7 +522,7 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const case COLUMN_SIZE: return misc::friendlyUnit(details.count); case COLUMN_AGE: - return misc::timeRelativeToNow(details.max_mtime); + return (details.type == DIR_TYPE_FILE)?(misc::timeRelativeToNow(details.max_mtime)):QString(); case COLUMN_FRIEND_ACCESS: return QVariant(); case COLUMN_WN_VISU_DIR: @@ -795,7 +801,7 @@ QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const return decorationRole(details,coln) ; if(role == Qt::ToolTipRole) - if(!isNewerThanEpoque(details.max_mtime)) + if(!isNewerThanEpoque(details.max_mtime) && details.type == DIR_TYPE_PERSON) return tr("This node hasn't sent any directory information yet.") ; /***************** From 443dbdfbef03e3b7ee728bba3819152607c0c7ee Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 29 Sep 2018 19:04:23 +0200 Subject: [PATCH 8/8] fixed small bug breaking display of flat mode in files --- libretroshare/src/file_sharing/p3filelists.cc | 6 +++--- retroshare-gui/src/gui/RemoteDirModel.cpp | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 8da837bc6..32482106f 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -996,7 +996,7 @@ void p3FileDatabase::getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIn d.count = mExtraFilesCache.size(); d.max_mtime = time(NULL); d.mtime = time(NULL); - d.name = "Extra List"; + d.name = "[Extra List]"; d.path = "/"; d.ref = ref ; @@ -1005,7 +1005,7 @@ void p3FileDatabase::getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIn DirStub stub; stub.type = DIR_TYPE_FILE; stub.name = mExtraFilesCache[i].fname; - convertEntryIndexToPointer(i,1,stub.ref); // local shared files from extra list + convertEntryIndexToPointer(i+1,1,stub.ref); // local shared files from extra list d.children.push_back(stub); } @@ -1084,7 +1084,7 @@ int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags convertEntryIndexToPointer(0,1,p); // local shared files from extra list DirStub stub; stub.type = DIR_TYPE_PERSON; // not totally exact, but used as a trick. - stub.name = "Extra List"; + stub.name = "[Extra List]"; stub.ref = p; d.children.push_back(stub); diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index e0da77b2e..658b944fb 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -1663,7 +1663,7 @@ void FlatStyle_RDM::updateRefs() if (requestDirDetails(ref, RemoteMode,details)) { - if(details.type == DIR_TYPE_FILE) // only push files, not directories nor persons. + if(details.type == DIR_TYPE_FILE || details.type == DIR_TYPE_EXTRA_FILE) // only push files, not directories nor persons. _ref_entries.push_back(ref) ; #ifdef RDM_DEBUG std::cerr << "FlatStyle_RDM::postMods(): adding ref " << ref << std::endl; @@ -1689,6 +1689,9 @@ void FlatStyle_RDM::updateRefs() std::cerr << "reference tab contains " << std::dec << _ref_entries.size() << " files" << std::endl; } + if(_ref_stack.empty()) + _needs_update = false ; + RetroshareDirModel::postMods() ; }