turtle search now connected to the gui. Next move: digg turtle tunnels for fast download.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1080 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-03-17 21:01:02 +00:00
parent 7859e40ddd
commit 34e042d02c
3 changed files with 128 additions and 237 deletions

View File

@ -399,14 +399,14 @@ void TurtleSearchDialog::showAdvSearchDialog(bool show)
void TurtleSearchDialog::advancedSearch(Expression* expression)
{
advSearchDialog->hide();
/* call to core */
std::list<FileDetail> results;
rsFiles -> SearchBoolExp(expression, results);
/* abstraction to allow reusee of tree rendering code */
resultsToTree((advSearchDialog->getSearchAsString()).toStdString(), results);
// advSearchDialog->hide();
//
// /* call to core */
// std::list<FileDetail> results;
// rsFiles -> SearchBoolExp(expression, results);
//
// /* abstraction to allow reusee of tree rendering code */
// resultsToTree((advSearchDialog->getSearchAsString()).toStdString(), results);
}
@ -419,110 +419,78 @@ void TurtleSearchDialog::searchKeywords()
TurtleRequestId id = rsTurtle->turtleSearch(txt) ;
}
void TurtleSearchDialog::updateFiles(qulonglong search_id,TurtleFileInfo files)
void TurtleSearchDialog::updateFiles(qulonglong search_id,TurtleFileInfo file)
{
std::cerr << "updating file list for id " << search_id << std::endl ;
#ifdef A_VIRER
QString qTxt = ui.lineEdit->text();
std::string txt = qTxt.toStdString();
std::cerr << "TurtleSearchDialog::searchKeywords() : " << txt << std::endl;
/* extract keywords from lineEdit */
QStringList qWords = qTxt.split(" ", QString::SkipEmptyParts);
std::list<std::string> words;
QStringListIterator qWordsIter(qWords);
while (qWordsIter.hasNext())
{
words.push_back(qWordsIter.next().toStdString());
}
if (words.size() < 1)
{
/* ignore */
return;
}
/* call to core */
std::list<FileDetail> initialResults;
std::list<FileDetail> * finalResults = 0;
rsFiles -> SearchKeywords(words, initialResults,DIR_FLAGS_LOCAL | DIR_FLAGS_REMOTE);
/* which extensions do we use? */
QString qExt, qName;
int extIndex;
bool matched =false;
FileDetail fd;
std::string txt = ui.lineEdit->text().toStdString();
if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_ANY)
insertFile(txt,search_id,file);
else
{
finalResults = &initialResults;
} else {
finalResults = new std::list<FileDetail>;
// amend the text description of the search
txt += " (" + ui.FileTypeComboBox->currentText().toStdString() + ")";
// collect the extensions to use
QString extStr = TurtleSearchDialog::FileTypeExtensionMap->value(ui.FileTypeComboBox->currentIndex());
QStringList extList = extStr.split(" ");
// now iterate through the results ignoring those with wrong extensions
std::list<FileDetail>::iterator resultsIter;
for (resultsIter = initialResults.begin(); resultsIter != initialResults.end(); resultsIter++)
// get this file's extension
QString qName = QString::fromStdString(file.name);
int extIndex = qName.lastIndexOf(".");
if (extIndex >= 0)
{
fd = *resultsIter;
// get this file's extension
qName = QString::fromStdString(fd.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(fd);
matched = true;
}
}
}
}
QString qExt = qName.mid(extIndex+1);
if (qExt != "" )
for (int i = 0; i < extList.size(); ++i)
if (qExt.toUpper() == extList.at(i).toUpper())
insertFile(txt,search_id,file);
}
}
/* abstraction to allow reusee of tree rendering code */
resultsToTree(txt, *finalResults);
#endif
}
void TurtleSearchDialog::resultsToTree(std::string txt, std::list<FileDetail> results)
void TurtleSearchDialog::insertFile(const std::string& txt,qulonglong searchId, const TurtleFileInfo& file)
{
/* translate search results */
int searchId = nextSearchId++;
std::ostringstream out;
out << searchId;
// algo:
//
// 1 - look in result window whether the file already exist.
// 1.1 - If yes, just increment the source number.
// 2.2 - Otherwize, add an entry.
// 2 - look in the summary whether there exist the same request id.
// 1.1 - If yes, just increment the result number.
// 2.2 - Otherwize, add an entry.
//
std::list<FileDetail>::iterator it;
for(it = results.begin(); it != results.end(); it++)
// 1 - look in result window whether the file already exist.
//
int items = ui.searchResultWidget->topLevelItemCount();
bool found = false ;
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).toInt() == searchId)
{
int s = ui.searchResultWidget->topLevelItem(i)->text(SR_ID_COL).toInt() ;
ui.searchResultWidget->topLevelItem(i)->setText(SR_ID_COL,QString::number(s+1));
found = true ;
}
if(!found)
{
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(SR_NAME_COL, QString::fromStdString(it->name));
item->setText(SR_HASH_COL, QString::fromStdString(it->hash));
item->setText(SR_SEARCH_ID_COL, QString::fromStdString(out.str()));
/* translate search results */
QString ext = QFileInfo(QString::fromStdString(it->name)).suffix();
if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif"
|| ext == "bmp" || ext == "ico" || ext == "svg")
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(SR_NAME_COL, QString::fromStdString(file.name));
item->setText(SR_HASH_COL, QString::fromStdString(file.hash));
QString ext = QFileInfo(QString::fromStdString(file.name)).suffix();
if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" || ext == "bmp" || ext == "ico" || ext == "svg")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypePicture.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Picture"));
}
else if (ext == "avi" || ext == "mpg" || ext == "mpeg" || ext == "wmv"
|| ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov"
|| ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp")
else if (ext == "avi" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov" || ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeVideo.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Video"));
@ -532,15 +500,12 @@ void TurtleSearchDialog::resultsToTree(std::string txt, std::list<FileDetail> re
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeAudio.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Audio"));
}
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz"
|| ext == "rar" || ext == "rpm" || ext == "deb")
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "rar" || ext == "rpm" || ext == "deb")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeArchive.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Archive"));
}
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com"
|| ext == "bin" || ext == "exe" || ext == "js" || ext == "pif"
|| ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com" || ext == "bin" || ext == "exe" || ext == "js" || ext == "pif" || ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeProgram.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Program"));
@ -556,7 +521,7 @@ void TurtleSearchDialog::resultsToTree(std::string txt, std::list<FileDetail> re
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
}
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls"
|| ext == "sxc" || ext == "odt" || ext == "ods")
|| ext == "sxc" || ext == "odt" || ext == "ods")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
@ -571,52 +536,45 @@ void TurtleSearchDialog::resultsToTree(std::string txt, std::list<FileDetail> re
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeAny.png"));
}
/*
* to facilitate downlaods we need to save the file size too
*/
//QVariant * variant = new QVariant((qulonglong)it->size);
//item->setText(SR_SIZE_COL, QString(variant->toString()));
item->setText(SR_SIZE_COL, misc::friendlyUnit(it->size));
item->setText(SR_REALSIZE_COL, QString::number(it->size));
item->setText(SR_SIZE_COL, misc::friendlyUnit(file.size));
item->setText(SR_REALSIZE_COL, QString::number(file.size));
item->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
// I kept the color code green=online, grey=offline
// Qt::blue is very dark and hardly compatible with the black text on it.
//
if (it->id == "Local")
{
item->setText(SR_ID_COL, QString::fromStdString(it->id));
item->setText(SR_UID_COL, QString::fromStdString(rsPeers->getOwnId()));
item->setBackground(3, QBrush(Qt::red)); /* colour green? */
}
else
{
item->setText(SR_ID_COL, QString::fromStdString( rsPeers->getPeerName(it->id)));
item->setText(SR_UID_COL, QString::fromStdString( it->id));
if(rsPeers->isOnline(it->id))
item->setBackground(3, QBrush(Qt::green));
else
item->setBackground(3, QBrush(Qt::lightGray));
}
item->setText(SR_ID_COL, QString::number(1));
item->setText(SR_SEARCH_ID_COL, QString::number(searchId));
ui.searchResultWidget->addTopLevelItem(item);
}
/* add to the summary as well */
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(SS_TEXT_COL, QString::fromStdString(txt));
std::ostringstream out2;
out2 << results.size();
int items2 = ui.searchSummaryWidget->topLevelItemCount();
bool found2 = false ;
item->setText(SS_COUNT_COL, QString::fromStdString(out2.str()));
item->setText(SS_SEARCH_ID_COL, QString::fromStdString(out.str()));
for(int i = 0; i < items2; i++)
if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL).toInt() == searchId)
{
if(!found) // only increment result when it's a new item.
{
int s = ui.searchSummaryWidget->topLevelItem(i)->text(SS_COUNT_COL).toInt() ;
ui.searchSummaryWidget->topLevelItem(i)->setText(SS_COUNT_COL,QString::number(s+1));
}
found2 = true ;
}
ui.searchSummaryWidget->addTopLevelItem(item);
ui.searchSummaryWidget->setCurrentItem(item);
if(!found2)
{
QTreeWidgetItem *item2 = new QTreeWidgetItem();
item2->setText(SS_TEXT_COL, QString::fromStdString(txt));
item2->setText(SS_COUNT_COL, QString::number(1));
item2->setText(SS_SEARCH_ID_COL, QString::number(searchId));
ui.searchSummaryWidget->addTopLevelItem(item2);
ui.searchSummaryWidget->setCurrentItem(item2);
}
/* select this search result */
selectSearchResults();

View File

@ -85,7 +85,7 @@ class TurtleSearchDialog : public MainPage
private:
/** render the results to the tree widget display */
void resultsToTree(std::string, std::list<FileDetail>);
void insertFile(const std::string& txt,qulonglong search_id, const TurtleFileInfo& file);
/** the advanced search dialog instance */
AdvancedSearchDialog * advSearchDialog;

View File

@ -522,16 +522,7 @@
<property name="spacing" >
<number>0</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>0</number>
</property>
<item>
@ -539,16 +530,7 @@
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>0</number>
</property>
<item>
@ -556,20 +538,14 @@
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>5</number>
</property>
<property name="topMargin" >
<number>5</number>
</property>
<property name="rightMargin" >
<number>5</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>5</number>
</property>
<item>
<widget class="QPushButton" name="toggleAdvancedSearchBtn" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<horstretch>0</horstretch>
@ -595,7 +571,8 @@
<string/>
</property>
<property name="icon" >
<iconset resource="images.qrc" >:/images/advsearch_24x24.png</iconset>
<iconset resource="images.qrc" >
<normaloff>:/images/advsearch_24x24.png</normaloff>:/images/advsearch_24x24.png</iconset>
</property>
<property name="iconSize" >
<size>
@ -613,7 +590,7 @@
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>0</height>
@ -647,16 +624,7 @@
<property name="spacing" >
<number>0</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>0</number>
</property>
<item>
@ -677,16 +645,7 @@
<property name="spacing" >
<number>0</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>0</number>
</property>
<item>
@ -694,16 +653,7 @@
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>0</number>
</property>
<item>
@ -724,7 +674,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>10</width>
<height>20</height>
@ -769,7 +719,7 @@
<property name="sizeType" >
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>16</width>
<height>32</height>
@ -794,7 +744,8 @@ p, li { white-space: pre-wrap; }
<string>Any</string>
</property>
<property name="icon" >
<iconset resource="images.qrc" >:/images/FileTypeAny.png</iconset>
<iconset resource="images.qrc" >
<normaloff>:/images/FileTypeAny.png</normaloff>:/images/FileTypeAny.png</iconset>
</property>
</item>
<item>
@ -802,7 +753,8 @@ p, li { white-space: pre-wrap; }
<string>Archive</string>
</property>
<property name="icon" >
<iconset resource="images.qrc" >:/images/FileTypeArchive.png</iconset>
<iconset resource="images.qrc" >
<normaloff>:/images/FileTypeArchive.png</normaloff>:/images/FileTypeArchive.png</iconset>
</property>
</item>
<item>
@ -810,7 +762,8 @@ p, li { white-space: pre-wrap; }
<string>Audio</string>
</property>
<property name="icon" >
<iconset resource="images.qrc" >:/images/FileTypeAudio.png</iconset>
<iconset resource="images.qrc" >
<normaloff>:/images/FileTypeAudio.png</normaloff>:/images/FileTypeAudio.png</iconset>
</property>
</item>
<item>
@ -818,7 +771,8 @@ p, li { white-space: pre-wrap; }
<string>CD-Image</string>
</property>
<property name="icon" >
<iconset resource="images.qrc" >:/images/FileTypeCDImage.png</iconset>
<iconset resource="images.qrc" >
<normaloff>:/images/FileTypeCDImage.png</normaloff>:/images/FileTypeCDImage.png</iconset>
</property>
</item>
<item>
@ -826,7 +780,8 @@ p, li { white-space: pre-wrap; }
<string>Document</string>
</property>
<property name="icon" >
<iconset resource="images.qrc" >:/images/FileTypeDocument.png</iconset>
<iconset resource="images.qrc" >
<normaloff>:/images/FileTypeDocument.png</normaloff>:/images/FileTypeDocument.png</iconset>
</property>
</item>
<item>
@ -834,7 +789,8 @@ p, li { white-space: pre-wrap; }
<string>Picture</string>
</property>
<property name="icon" >
<iconset resource="images.qrc" >:/images/FileTypePicture.png</iconset>
<iconset resource="images.qrc" >
<normaloff>:/images/FileTypePicture.png</normaloff>:/images/FileTypePicture.png</iconset>
</property>
</item>
<item>
@ -842,7 +798,8 @@ p, li { white-space: pre-wrap; }
<string>Program</string>
</property>
<property name="icon" >
<iconset resource="images.qrc" >:/images/FileTypeProgram.png</iconset>
<iconset resource="images.qrc" >
<normaloff>:/images/FileTypeProgram.png</normaloff>:/images/FileTypeProgram.png</iconset>
</property>
</item>
<item>
@ -850,7 +807,8 @@ p, li { white-space: pre-wrap; }
<string>Video</string>
</property>
<property name="icon" >
<iconset resource="images.qrc" >:/images/FileTypeVideo.png</iconset>
<iconset resource="images.qrc" >
<normaloff>:/images/FileTypeVideo.png</normaloff>:/images/FileTypeVideo.png</iconset>
</property>
</item>
</widget>
@ -860,7 +818,7 @@ p, li { white-space: pre-wrap; }
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>16</width>
<height>20</height>
@ -889,7 +847,8 @@ p, li { white-space: pre-wrap; }
<string/>
</property>
<property name="icon" >
<iconset resource="images.qrc" >:/images/find.png</iconset>
<iconset resource="images.qrc" >
<normaloff>:/images/find.png</normaloff>:/images/find.png</iconset>
</property>
<property name="iconSize" >
<size>
@ -925,16 +884,7 @@ p, li { white-space: pre-wrap; }
<property name="spacing" >
<number>0</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>0</number>
</property>
<item>
@ -942,16 +892,7 @@ p, li { white-space: pre-wrap; }
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>0</number>
</property>
<item>
@ -969,7 +910,7 @@ p, li { white-space: pre-wrap; }
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>50</width>
<height>20</height>
@ -1006,16 +947,7 @@ p, li { white-space: pre-wrap; }
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>5</number>
</property>
<property name="topMargin" >
<number>5</number>
</property>
<property name="rightMargin" >
<number>5</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>5</number>
</property>
<item>
@ -1045,7 +977,8 @@ p, li { white-space: pre-wrap; }
<string/>
</property>
<property name="icon" >
<iconset resource="images.qrc" >:/images/down_24x24.png</iconset>
<iconset resource="images.qrc" >
<normaloff>:/images/down_24x24.png</normaloff>:/images/down_24x24.png</iconset>
</property>
<property name="iconSize" >
<size>
@ -1060,7 +993,7 @@ p, li { white-space: pre-wrap; }
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>0</height>