diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp index 94e4229cc..2ecf442e4 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp @@ -37,6 +37,7 @@ #include "gui/advsearch/advancedsearchdialog.h" #include "gui/common/RSTreeWidgetItem.h" #include "util/QtVersion.h" +#include "util/qtthreadsutils.h" #include #include @@ -217,6 +218,15 @@ SearchDialog::SearchDialog(QWidget *parent) checkText(ui.lineEdit->text()); + // add an event handler to get search results (previously available through notifyQt) + + mEventHandlerId = 0; + + rsEvents->registerEventsHandler( [this](std::shared_ptr event) + { + RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this ); + }, mEventHandlerId, RsEventType::FILE_TRANSFER ); + } SearchDialog::~SearchDialog() @@ -235,6 +245,29 @@ SearchDialog::~SearchDialog() ui.searchResultWidget->setItemDelegateForColumn(SR_SIZE_COL, nullptr); ui.searchResultWidget->setItemDelegateForColumn(SR_AGE_COL, nullptr); + + rsEvents->unregisterEventsHandler(mEventHandlerId); +} + +void SearchDialog::handleEvent_main_thread(std::shared_ptr event) +{ + if(event->mType != RsEventType::FILE_TRANSFER) + return; + + auto fe = dynamic_cast(event.get()); + + if(!fe || fe->mFileTransferEventCode!=RsFileTransferEventCode::NEW_DISTANT_SEARCH_RESULTS) + return; + + for(uint32_t i=0;imResults.size();++i) + { + FileDetail f; + f.hash = fe->mResults[i].fHash; + f.name = fe->mResults[i].fName; + f.size = fe->mResults[i].fSize; + + updateFiles(fe->mRequestId,f); + } } void SearchDialog::processSettings(bool bLoad) @@ -961,7 +994,7 @@ void SearchDialog::processResultQueue() while(!searchResultsQueue.empty() && nb_treated_elements++ < 250) { qulonglong search_id = searchResultsQueue.back().first ; - FileDetail& file = searchResultsQueue.back().second ; + const FileDetail& file = searchResultsQueue.back().second ; #ifdef DEBUG std::cout << "Updating file detail:" << std::endl ; diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.h b/retroshare-gui/src/gui/FileTransfer/SearchDialog.h index 25925c36d..5661f6246 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.h @@ -22,6 +22,7 @@ #define _SEARCHDIALOG_H #include "retroshare/rstypes.h" +#include "retroshare/rsevents.h" #include "ui_SearchDialog.h" #include "retroshare-gui/mainpage.h" @@ -125,6 +126,7 @@ private: void setIconAndType(QTreeWidgetItem *item, const QString& filename); void downloadDirectory(const QTreeWidgetItem *item, const QString &base); void getSourceFriendsForHash(const RsFileHash &hash,std::list &srcIds); + void handleEvent_main_thread(std::shared_ptr event); /** the advanced search dialog instance */ AdvancedSearchDialog * advSearchDialog; @@ -176,6 +178,8 @@ private: bool _queueIsAlreadyTakenCareOf ; std::vector > searchResultsQueue ; + + RsEventsHandlerId_t mEventHandlerId ; }; #endif diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index 9012e77bd..d2dee5ac4 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -482,6 +482,8 @@ void NotifyQt::notifyTurtleSearchResult(uint32_t /*search_id*/,const std::list& files) { { @@ -507,6 +509,7 @@ void NotifyQt::notifyTurtleSearchResult(const RsPeerId& pid,uint32_t search_id,c emit gotTurtleSearchResult(search_id,det) ; } } +#endif void NotifyQt::notifyHistoryChanged(uint32_t msgId, int type) { diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index d2b15fa09..0f9ae11e2 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -67,7 +67,9 @@ class NotifyQt: public QObject, public NotifyClient virtual void notifyChatStatus(const ChatId &chat_id,const std::string& status_string); virtual void notifyChatCleared(const ChatId &chat_id); virtual void notifyCustomState(const std::string& peer_id, const std::string& status_string); +#ifdef TO_REMOVE virtual void notifyTurtleSearchResult(const RsPeerId &pid, uint32_t search_id, const std::list& found_files); +#endif virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list& found_groups); virtual void notifyPeerHasNewAvatar(std::string peer_id) ; virtual void notifyOwnAvatarChanged() ; diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index 2d3fabf89..3361597c8 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -540,7 +540,7 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO); qRegisterMetaType("RsPeerId") ; std::cerr << "connecting signals and slots" << std::endl ; - QObject::connect(notify,SIGNAL(gotTurtleSearchResult(qulonglong,FileDetail)),w->transfersDialog->searchDialog ,SLOT(updateFiles(qulonglong,FileDetail))) ; +// QObject::connect(notify,SIGNAL(gotTurtleSearchResult(qulonglong,FileDetail)),w->transfersDialog->searchDialog ,SLOT(updateFiles(qulonglong,FileDetail))) ; QObject::connect(notify,SIGNAL(deferredSignatureHandlingRequested()),notify,SLOT(handleSignatureEvent()),Qt::QueuedConnection) ; QObject::connect(notify,SIGNAL(chatLobbyTimeShift(int)),notify,SLOT(handleChatLobbyTimeShift(int)),Qt::QueuedConnection) ; QObject::connect(notify,SIGNAL(diskFull(int,int)) ,w ,SLOT(displayDiskSpaceWarning(int,int))) ;