cleaned some memory leak in search, added 2 checkboxes for F2F and friend lists, made the "include own files" work properly

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2455 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-02-27 21:10:54 +00:00
parent 9d6173a1ee
commit 84cad6a7b0
2 changed files with 93 additions and 104 deletions

View File

@ -544,10 +544,17 @@ void SearchDialog::searchKeywords()
std::cerr << "SearchDialog::searchKeywords() : " << txt << std::endl; std::cerr << "SearchDialog::searchKeywords() : " << txt << std::endl;
TurtleRequestId req_id = rsTurtle->turtleSearch(txt) ; TurtleRequestId req_id ;
if(ui._anonF2Fsearch_CB->isChecked())
req_id = rsTurtle->turtleSearch(txt) ;
else
req_id = (((uint32_t)rand()) << 16)^0x1e2fd5e4 + ((uint32_t)rand())^0x1b19acfe ; // generate a random 32 bits request id
initSearchResult(txt,req_id) ; // this will act before turtle results come to the interface, thanks to the signals scheduling policy. initSearchResult(txt,req_id) ; // this will act before turtle results come to the interface, thanks to the signals scheduling policy.
if(ui._friendListsearch_SB->isChecked() || ui._ownFiles_CB->isChecked())
{
/* extract keywords from lineEdit */ /* extract keywords from lineEdit */
QStringList qWords = qTxt.split(" ", QString::SkipEmptyParts); QStringList qWords = qTxt.split(" ", QString::SkipEmptyParts);
std::list<std::string> words; std::list<std::string> words;
@ -563,92 +570,44 @@ void SearchDialog::searchKeywords()
return; return;
} }
/* call to core */ std::list<DirDetails> finalResults ;
std::list<DirDetails> initialResults;
std::list<DirDetails> * finalResults = 0; if(ui._friendListsearch_SB->isChecked())
{
std::list<DirDetails> initialResults;
rsFiles -> SearchKeywords(words, initialResults, DIR_FLAGS_REMOTE) ;
uint32_t flags = DIR_FLAGS_REMOTE | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE;
if (ui.checkBox->isChecked())
flags |= DIR_FLAGS_LOCAL;
rsFiles -> SearchKeywords(words, initialResults,flags);
/* which extensions do we use? */ /* which extensions do we use? */
QString qExt, qName;
int extIndex;
bool matched =false;
DirDetails dd; DirDetails dd;
// if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_ANY) for(std::list<DirDetails>::iterator resultsIter = initialResults.begin(); resultsIter != initialResults.end(); resultsIter ++)
// {
// finalResults = new std::list<DirDetails>;
// std::list<DirDetails>::iterator resultsIter;
// for (resultsIter = initialResults.begin(); resultsIter != initialResults.end(); resultsIter ++)
// {
// dd = *resultsIter;
// if (dd.type == DIR_TYPE_DIR) continue;
// finalResults->push_back(dd);
// }
// }
// else if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_DIRECTORY)
// {
// finalResults = new std::list<DirDetails>;
// txt += " (" + ui.FileTypeComboBox->currentText().toStdString() + ")";
// std::list<DirDetails>::iterator resultsIter;
// for (resultsIter = initialResults.begin(); resultsIter != initialResults.end(); resultsIter ++)
// {
// dd = *resultsIter;
// if (dd.type != DIR_TYPE_DIR) continue;
// finalResults->push_back(dd);
// }
// }
// else
// {
// finalResults = new std::list<DirDetails>;
// // 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(" ");
//
// // now iterate through the results ignoring those with wrong extensions
// std::list<DirDetails>::iterator resultsIter;
// for (resultsIter = initialResults.begin(); resultsIter != initialResults.end(); resultsIter++)
// {
// dd = *resultsIter;
// if (dd.type == DIR_TYPE_DIR) continue;
// // get this file's extension
// qName = QString::fromStdString(dd.name);
// extIndex = qName.lastIndexOf(".");
// if (extIndex >= 0) {
// qExt = qName.mid(extIndex+1);
// if (qExt != "" )
// {
// // does it match?
// matched = false;
// /* iterate through the requested extensions */
// for (int i = 0; i < extList.size(); ++i)
// {
// if (qExt.toUpper() == extList.at(i).toUpper())
// {
// finalResults->push_back(dd);
// matched = true;
// }
// }
// }
// }
// }
// }
finalResults = new std::list<DirDetails>;
std::list<DirDetails>::iterator resultsIter;
for (resultsIter = initialResults.begin(); resultsIter != initialResults.end(); resultsIter ++)
{ {
dd = *resultsIter; dd = *resultsIter;
finalResults->push_back(dd); finalResults.push_back(dd);
}
}
if(ui._ownFiles_CB->isChecked())
{
std::list<DirDetails> initialResults;
rsFiles -> SearchKeywords(words, initialResults, DIR_FLAGS_LOCAL | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE) ;
/* which extensions do we use? */
DirDetails dd;
for(std::list<DirDetails>::iterator resultsIter = initialResults.begin(); resultsIter != initialResults.end(); resultsIter ++)
{
dd = *resultsIter;
finalResults.push_back(dd);
}
} }
/* abstraction to allow reusee of tree rendering code */ /* abstraction to allow reusee of tree rendering code */
resultsToTree(txt,req_id, *finalResults); resultsToTree(txt,req_id, finalResults);
ui.lineEdit->clear() ; ui.lineEdit->clear() ;
}
} }
void SearchDialog::updateFiles(qulonglong search_id,FileDetail file) void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>651</width> <width>1064</width>
<height>340</height> <height>340</height>
</rect> </rect>
</property> </property>
@ -979,7 +979,7 @@ border-image: url(:/images/btn_26_pressed.png) 4;
</widget> </widget>
<widget class="SearchTreeWidget" name="searchResultWidget"> <widget class="SearchTreeWidget" name="searchResultWidget">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>1</horstretch> <horstretch>1</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -1088,17 +1088,47 @@ border-image: url(:/images/btn_26_pressed.png) 4;
</string> </string>
</property> </property>
<property name="text"> <property name="text">
<string>Close All Search Results</string> <string>Clear All Search Results</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="checkBox"> <widget class="QCheckBox" name="_ownFiles_CB">
<property name="toolTip">
<string>Include files from your own file list in the search result</string>
</property>
<property name="text"> <property name="text">
<string>Include own files</string> <string>Include own files</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="_friendListsearch_SB">
<property name="toolTip">
<string>Search inside &quot;browsable&quot; files of your friends</string>
</property>
<property name="text">
<string>Search in friends lists</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="_anonF2Fsearch_CB">
<property name="toolTip">
<string>Multi-hop search at distance 6 in the network
(always reports available files)</string>
</property>
<property name="text">
<string>F2F search</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">