diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index fcd2ac751..dbf025cd3 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -35,7 +35,7 @@ #include #include -#define DEBUG_RSLINK 1 +//#define DEBUG_RSLINK 1 #define HOST_FILE "file" #define HOST_PERSON "person" @@ -344,7 +344,9 @@ bool RetroShareLink::process(int flag) case TYPE_FILE: { +#ifdef DEBUG_RSLINK std::cerr << " RetroShareLink::process FileRequest : fileName : " << name().toUtf8().constData() << ". fileHash : " << hash().toStdString() << ". fileSize : " << size() << std::endl; +#endif // Get a list of available direct sources, in case the file is browsable only. std::list srcIds; @@ -353,7 +355,9 @@ bool RetroShareLink::process(int flag) for(std::list::const_iterator it(finfo.peers.begin());it!=finfo.peers.end();++it) { +#ifdef DEBUG_RSLINK std::cerr << " adding peerid " << (*it).peerId << std::endl ; +#endif srcIds.push_back((*it).peerId) ; } @@ -376,7 +380,9 @@ bool RetroShareLink::process(int flag) case TYPE_PERSON: { +#ifdef DEBUG_RSLINK std::cerr << " RetroShareLink::process FriendRequest : name : " << name().toStdString() << ". id : " << hash().toStdString() << std::endl; +#endif RsPeerDetails detail; if (rsPeers->getPeerDetails(hash().toStdString(), detail)) { @@ -477,11 +483,15 @@ void RSLinkClipboard::parseClipboard(std::vector &links) if(!already) { links.push_back(link) ; +#ifdef DEBUG_RSLINK std::cerr << "captured link: " << link.toString().toStdString() << std::endl ; +#endif } } +#ifdef DEBUG_RSLINK else std::cerr << "invalid link" << std::endl ; +#endif pos += rx.matchedLength(); } diff --git a/retroshare-gui/src/gui/SearchDialog.cpp b/retroshare-gui/src/gui/SearchDialog.cpp index e0ffe6d8b..245f9a0a6 100644 --- a/retroshare-gui/src/gui/SearchDialog.cpp +++ b/retroshare-gui/src/gui/SearchDialog.cpp @@ -21,6 +21,7 @@ #include #include +#include #include "SearchDialog.h" #include "RetroShareLink.h" @@ -82,6 +83,7 @@ SearchDialog::SearchDialog(QWidget *parent) /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); + _queueIsAlreadyTakenCareOf = false ; ui.lineEdit->setFocus(); ui.lineEdit->setToolTip(tr("Enter a keyword here (at least 3 char long)")); @@ -599,39 +601,64 @@ void SearchDialog::searchKeywords() void SearchDialog::updateFiles(qulonglong search_id,FileDetail file) { - /* which extensions do we use? */ - std::string txt = ui.lineEdit->text().toStdString(); + searchResultsQueue.push_back(std::pair(search_id,file)) ; + + if(!_queueIsAlreadyTakenCareOf) + { + QTimer::singleShot(100,this,SLOT(processResultQueue())) ; + _queueIsAlreadyTakenCareOf = true ; + } +} + +void SearchDialog::processResultQueue() +{ + int nb_treated_elements = 0 ; + + while(!searchResultsQueue.empty() && nb_treated_elements++ < 500) + { + qulonglong search_id = searchResultsQueue.back().first ; + FileDetail file = searchResultsQueue.back().second ; + + searchResultsQueue.pop_back() ; + + /* which extensions do we use? */ + std::string txt = ui.lineEdit->text().toStdString(); #ifdef DEBUG - std::cout << "Updating file detail:" << std::endl ; - std::cout << " size = " << file.size << std::endl ; - std::cout << " name = " << file.name << std::endl ; - std::cout << " s_id = " << search_id << std::endl ; + std::cout << "Updating file detail:" << std::endl ; + std::cout << " size = " << file.size << std::endl ; + std::cout << " name = " << file.name << std::endl ; + std::cout << " s_id = " << search_id << std::endl ; #endif - if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_ANY) - insertFile(txt,search_id,file); - else - { - // amend the text description of the search - txt += " (" + ui.FileTypeComboBox->currentText().toStdString() + ")"; - // collect the extensions to use - QString extStr = SearchDialog::FileTypeExtensionMap->value(ui.FileTypeComboBox->currentIndex()); - QStringList extList = extStr.split(" "); - - // get this file's extension - QString qName = QString::fromUtf8(file.name.c_str()); - int extIndex = qName.lastIndexOf("."); - - if (extIndex >= 0) + if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_ANY) + insertFile(txt,search_id,file); + else { - QString qExt = qName.mid(extIndex+1).toUpper(); + // amend the text description of the search + txt += " (" + ui.FileTypeComboBox->currentText().toStdString() + ")"; + // collect the extensions to use + QString extStr = SearchDialog::FileTypeExtensionMap->value(ui.FileTypeComboBox->currentIndex()); + QStringList extList = extStr.split(" "); - if (qExt != "" ) - for (int i = 0; i < extList.size(); ++i) - if (qExt == extList.at(i).toUpper()) - insertFile(txt,search_id,file); + // get this file's extension + QString qName = QString::fromUtf8(file.name.c_str()); + int extIndex = qName.lastIndexOf("."); + + if (extIndex >= 0) + { + QString qExt = qName.mid(extIndex+1).toUpper(); + + if (qExt != "" ) + for (int i = 0; i < extList.size(); ++i) + if (qExt == extList.at(i).toUpper()) + insertFile(txt,search_id,file); + } } } + if(!searchResultsQueue.empty()) + QTimer::singleShot(1000,this,SLOT(processResultQueue())) ; + else + _queueIsAlreadyTakenCareOf = false ; } void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir, QTreeWidgetItem *item) @@ -815,11 +842,12 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const QString sid_hexa = QString::number(searchId,16) ; - for(int i = 0; i < items; i++) - if(ui.searchResultWidget->topLevelItem(i)->text(SR_HASH_COL) == QString::fromStdString(file.hash) - && ui.searchResultWidget->topLevelItem(i)->text(SR_SEARCH_ID_COL) == sid_hexa) + QList itms = ui.searchResultWidget->findItems(QString::fromStdString(file.hash),Qt::MatchExactly,SR_HASH_COL) ; + + for(QList::const_iterator it(itms.begin());it!=itms.end();++it) + if((*it)->text(SR_SEARCH_ID_COL) == sid_hexa) { - QString resultCount = ui.searchResultWidget->topLevelItem(i)->text(SR_ID_COL); + QString resultCount = (*it)->text(SR_ID_COL); QStringList modifiedResultCount = resultCount.split("/", QString::SkipEmptyParts); if(searchType == FRIEND_SEARCH) { @@ -833,8 +861,8 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const } anonymousSource = anonymousSource + friendSource; modifiedResult = QString::number(friendSource) + "/" + QString::number(anonymousSource); - ui.searchResultWidget->topLevelItem(i)->setText(SR_ID_COL,modifiedResult); - QTreeWidgetItem *item = ui.searchResultWidget->topLevelItem(i); + (*it)->setText(SR_ID_COL,modifiedResult); + QTreeWidgetItem *item = (*it); found = true ; int sources = friendSource + anonymousSource ; if ( sources < 1) diff --git a/retroshare-gui/src/gui/SearchDialog.h b/retroshare-gui/src/gui/SearchDialog.h index de3c0efdc..fc274b27b 100644 --- a/retroshare-gui/src/gui/SearchDialog.h +++ b/retroshare-gui/src/gui/SearchDialog.h @@ -49,6 +49,7 @@ private slots: /** Create the context popup menu and it's submenus */ void searchtableWidgetCostumPopupMenu( QPoint point ); + void processResultQueue(); void searchtableWidget2CostumPopupMenu( QPoint point ); void download(); @@ -130,6 +131,9 @@ QTreeWidget *searchtablewidget2; /** Qt Designer generated object */ Ui::SearchDialog ui; + + bool _queueIsAlreadyTakenCareOf ; + std::vector > searchResultsQueue ; }; #endif