diff --git a/libretroshare/src/ft/ftextralist.cc b/libretroshare/src/ft/ftextralist.cc index a4a1245e0..3912cc1b3 100644 --- a/libretroshare/src/ft/ftextralist.cc +++ b/libretroshare/src/ft/ftextralist.cc @@ -129,6 +129,11 @@ void ftExtraList::hashAFile() mHashedList[details.info.path] = details.info.hash; IndicateConfigChanged(); + + auto ev = std::make_shared(); + ev->mEventCode = RsSharedDirectoriesEventCode::EXTRA_LIST_FILE_ADDED; + if(rsEvents) + rsEvents->postEvent(ev); } } @@ -195,6 +200,12 @@ bool ftExtraList::removeExtraFile(const RsFileHash& hash) IndicateConfigChanged(); + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mEventCode = RsSharedDirectoriesEventCode::EXTRA_LIST_FILE_REMOVED; + rsEvents->postEvent(ev); + } return true; } diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index fa6b37e29..f25d90957 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -184,6 +184,8 @@ enum class RsSharedDirectoriesEventCode: uint8_t { HASHING_FILE = 0x02, // mMessage: full path and hashing speed of the file being hashed DIRECTORY_SWEEP_ENDED = 0x03, // (void) SAVING_FILE_INDEX = 0x04, // (void) + EXTRA_LIST_FILE_ADDED = 0x05, // (void) + EXTRA_LIST_FILE_REMOVED = 0x06, // (void) }; enum class RsFileTransferEventCode: uint8_t { diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 49d9b2d6e..f989a2ec5 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -30,6 +30,7 @@ #include "retroshare/rsfiles.h" #include "retroshare/rspeers.h" #include "util/misc.h" +#include "util/qtthreadsutils.h" #include "retroshare/rsexpr.h" #include @@ -63,6 +64,37 @@ RetroshareDirModel::RetroshareDirModel(bool mode, QObject *parent) treeStyle(); mDirDetails.ref = (void*)intptr_t(0xffffffff) ; + + rsEvents->registerEventsHandler( + [this](std::shared_ptr event) + { + RsQThreadUtils::postToObject( [this,event]() { handleEvent_main_thread(event); }); + }, + mEventHandlerId, + RsEventType::SHARED_DIRECTORIES ); +} + +RetroshareDirModel::~RetroshareDirModel() +{ + rsEvents->unregisterEventsHandler(mEventHandlerId); +} +void RetroshareDirModel::handleEvent_main_thread(std::shared_ptr event) +{ + if(event->mType != RsEventType::SHARED_DIRECTORIES) return; + + const RsSharedDirectoriesEvent *fe = dynamic_cast(event.get()); + if(!fe) + return; + + switch (fe->mEventCode) + { + case RsSharedDirectoriesEventCode::EXTRA_LIST_FILE_ADDED: + case RsSharedDirectoriesEventCode::EXTRA_LIST_FILE_REMOVED: + update(); + break; + default: + break; + } } TreeStyle_RDM::TreeStyle_RDM(bool mode) diff --git a/retroshare-gui/src/gui/RemoteDirModel.h b/retroshare-gui/src/gui/RemoteDirModel.h index 115ba5b20..9d94abf32 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.h +++ b/retroshare-gui/src/gui/RemoteDirModel.h @@ -22,6 +22,7 @@ #define REMOTE_DIR_MODEL #include +#include #include #include @@ -63,9 +64,9 @@ class RetroshareDirModel : public QAbstractItemModel enum Roles{ FileNameRole = Qt::UserRole+1, SortRole = Qt::UserRole+2, FilterRole = Qt::UserRole+3 }; RetroshareDirModel(bool mode, QObject *parent = 0); - virtual ~RetroshareDirModel() {} + virtual ~RetroshareDirModel() ; - virtual Qt::ItemFlags flags ( const QModelIndex & index ) const; + virtual Qt::ItemFlags flags ( const QModelIndex & index ) const; /* Callback from Core */ virtual void preMods(); @@ -107,7 +108,9 @@ class RetroshareDirModel : public QAbstractItemModel protected: bool _visible ; - void treeStyle(); + void handleEvent_main_thread(std::shared_ptr event); + + void treeStyle(); void downloadDirectory(const DirDetails & details, int prefixLen); static QString getFlagsString(FileStorageFlags f) ; static QString getGroupsString(FileStorageFlags flags, const std::list &) ; @@ -176,6 +179,8 @@ class RetroshareDirModel : public QAbstractItemModel bool mUpdating ; std::set mFilteredPointers ; + + RsEventsHandlerId_t mEventHandlerId; }; // This class shows the classical hierarchical directory view of shared files