mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-19 03:49:29 -04:00
improved cost of search usign temporization. Removed some debugging outputs from RetroShareLink
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4027 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
081cfee461
commit
62c7f815fc
3 changed files with 75 additions and 33 deletions
|
@ -35,7 +35,7 @@
|
||||||
#include <retroshare/rsfiles.h>
|
#include <retroshare/rsfiles.h>
|
||||||
#include <retroshare/rspeers.h>
|
#include <retroshare/rspeers.h>
|
||||||
|
|
||||||
#define DEBUG_RSLINK 1
|
//#define DEBUG_RSLINK 1
|
||||||
|
|
||||||
#define HOST_FILE "file"
|
#define HOST_FILE "file"
|
||||||
#define HOST_PERSON "person"
|
#define HOST_PERSON "person"
|
||||||
|
@ -344,7 +344,9 @@ bool RetroShareLink::process(int flag)
|
||||||
|
|
||||||
case TYPE_FILE:
|
case TYPE_FILE:
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_RSLINK
|
||||||
std::cerr << " RetroShareLink::process FileRequest : fileName : " << name().toUtf8().constData() << ". fileHash : " << hash().toStdString() << ". fileSize : " << size() << std::endl;
|
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.
|
// Get a list of available direct sources, in case the file is browsable only.
|
||||||
std::list<std::string> srcIds;
|
std::list<std::string> srcIds;
|
||||||
|
@ -353,7 +355,9 @@ bool RetroShareLink::process(int flag)
|
||||||
|
|
||||||
for(std::list<TransferInfo>::const_iterator it(finfo.peers.begin());it!=finfo.peers.end();++it)
|
for(std::list<TransferInfo>::const_iterator it(finfo.peers.begin());it!=finfo.peers.end();++it)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_RSLINK
|
||||||
std::cerr << " adding peerid " << (*it).peerId << std::endl ;
|
std::cerr << " adding peerid " << (*it).peerId << std::endl ;
|
||||||
|
#endif
|
||||||
srcIds.push_back((*it).peerId) ;
|
srcIds.push_back((*it).peerId) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,7 +380,9 @@ bool RetroShareLink::process(int flag)
|
||||||
|
|
||||||
case TYPE_PERSON:
|
case TYPE_PERSON:
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_RSLINK
|
||||||
std::cerr << " RetroShareLink::process FriendRequest : name : " << name().toStdString() << ". id : " << hash().toStdString() << std::endl;
|
std::cerr << " RetroShareLink::process FriendRequest : name : " << name().toStdString() << ". id : " << hash().toStdString() << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
RsPeerDetails detail;
|
RsPeerDetails detail;
|
||||||
if (rsPeers->getPeerDetails(hash().toStdString(), detail)) {
|
if (rsPeers->getPeerDetails(hash().toStdString(), detail)) {
|
||||||
|
@ -477,11 +483,15 @@ void RSLinkClipboard::parseClipboard(std::vector<RetroShareLink> &links)
|
||||||
if(!already)
|
if(!already)
|
||||||
{
|
{
|
||||||
links.push_back(link) ;
|
links.push_back(link) ;
|
||||||
|
#ifdef DEBUG_RSLINK
|
||||||
std::cerr << "captured link: " << link.toString().toStdString() << std::endl ;
|
std::cerr << "captured link: " << link.toString().toStdString() << std::endl ;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef DEBUG_RSLINK
|
||||||
else
|
else
|
||||||
std::cerr << "invalid link" << std::endl ;
|
std::cerr << "invalid link" << std::endl ;
|
||||||
|
#endif
|
||||||
|
|
||||||
pos += rx.matchedLength();
|
pos += rx.matchedLength();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "SearchDialog.h"
|
#include "SearchDialog.h"
|
||||||
#include "RetroShareLink.h"
|
#include "RetroShareLink.h"
|
||||||
|
@ -82,6 +83,7 @@ SearchDialog::SearchDialog(QWidget *parent)
|
||||||
/* Invoke the Qt Designer generated object setup routine */
|
/* Invoke the Qt Designer generated object setup routine */
|
||||||
ui.setupUi(this);
|
ui.setupUi(this);
|
||||||
|
|
||||||
|
_queueIsAlreadyTakenCareOf = false ;
|
||||||
ui.lineEdit->setFocus();
|
ui.lineEdit->setFocus();
|
||||||
ui.lineEdit->setToolTip(tr("Enter a keyword here (at least 3 char long)"));
|
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)
|
void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)
|
||||||
{
|
{
|
||||||
/* which extensions do we use? */
|
searchResultsQueue.push_back(std::pair<qulonglong,FileDetail>(search_id,file)) ;
|
||||||
std::string txt = ui.lineEdit->text().toStdString();
|
|
||||||
|
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
|
#ifdef DEBUG
|
||||||
std::cout << "Updating file detail:" << std::endl ;
|
std::cout << "Updating file detail:" << std::endl ;
|
||||||
std::cout << " size = " << file.size << std::endl ;
|
std::cout << " size = " << file.size << std::endl ;
|
||||||
std::cout << " name = " << file.name << std::endl ;
|
std::cout << " name = " << file.name << std::endl ;
|
||||||
std::cout << " s_id = " << search_id << std::endl ;
|
std::cout << " s_id = " << search_id << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_ANY)
|
if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_ANY)
|
||||||
insertFile(txt,search_id,file);
|
insertFile(txt,search_id,file);
|
||||||
else
|
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)
|
|
||||||
{
|
{
|
||||||
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 != "" )
|
// get this file's extension
|
||||||
for (int i = 0; i < extList.size(); ++i)
|
QString qName = QString::fromUtf8(file.name.c_str());
|
||||||
if (qExt == extList.at(i).toUpper())
|
int extIndex = qName.lastIndexOf(".");
|
||||||
insertFile(txt,search_id,file);
|
|
||||||
|
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)
|
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) ;
|
QString sid_hexa = QString::number(searchId,16) ;
|
||||||
|
|
||||||
for(int i = 0; i < items; i++)
|
QList<QTreeWidgetItem*> itms = ui.searchResultWidget->findItems(QString::fromStdString(file.hash),Qt::MatchExactly,SR_HASH_COL) ;
|
||||||
if(ui.searchResultWidget->topLevelItem(i)->text(SR_HASH_COL) == QString::fromStdString(file.hash)
|
|
||||||
&& ui.searchResultWidget->topLevelItem(i)->text(SR_SEARCH_ID_COL) == sid_hexa)
|
for(QList<QTreeWidgetItem*>::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);
|
QStringList modifiedResultCount = resultCount.split("/", QString::SkipEmptyParts);
|
||||||
if(searchType == FRIEND_SEARCH)
|
if(searchType == FRIEND_SEARCH)
|
||||||
{
|
{
|
||||||
|
@ -833,8 +861,8 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
|
||||||
}
|
}
|
||||||
anonymousSource = anonymousSource + friendSource;
|
anonymousSource = anonymousSource + friendSource;
|
||||||
modifiedResult = QString::number(friendSource) + "/" + QString::number(anonymousSource);
|
modifiedResult = QString::number(friendSource) + "/" + QString::number(anonymousSource);
|
||||||
ui.searchResultWidget->topLevelItem(i)->setText(SR_ID_COL,modifiedResult);
|
(*it)->setText(SR_ID_COL,modifiedResult);
|
||||||
QTreeWidgetItem *item = ui.searchResultWidget->topLevelItem(i);
|
QTreeWidgetItem *item = (*it);
|
||||||
found = true ;
|
found = true ;
|
||||||
int sources = friendSource + anonymousSource ;
|
int sources = friendSource + anonymousSource ;
|
||||||
if ( sources < 1)
|
if ( sources < 1)
|
||||||
|
|
|
@ -49,6 +49,7 @@ private slots:
|
||||||
/** Create the context popup menu and it's submenus */
|
/** Create the context popup menu and it's submenus */
|
||||||
void searchtableWidgetCostumPopupMenu( QPoint point );
|
void searchtableWidgetCostumPopupMenu( QPoint point );
|
||||||
|
|
||||||
|
void processResultQueue();
|
||||||
void searchtableWidget2CostumPopupMenu( QPoint point );
|
void searchtableWidget2CostumPopupMenu( QPoint point );
|
||||||
|
|
||||||
void download();
|
void download();
|
||||||
|
@ -130,6 +131,9 @@ QTreeWidget *searchtablewidget2;
|
||||||
|
|
||||||
/** Qt Designer generated object */
|
/** Qt Designer generated object */
|
||||||
Ui::SearchDialog ui;
|
Ui::SearchDialog ui;
|
||||||
|
|
||||||
|
bool _queueIsAlreadyTakenCareOf ;
|
||||||
|
std::vector<std::pair<qulonglong,FileDetail> > searchResultsQueue ;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue