mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-05 12:51:08 -05:00
improved the search dialog behaviour
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1680 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
c4e7f02f79
commit
cef9385f5b
@ -404,6 +404,21 @@ void SearchDialog::showAdvSearchDialog(bool show)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Creates a new entry in the search summary, not to leave it blank whatever happens.
|
||||||
|
//
|
||||||
|
void SearchDialog::initSearchResult(const std::string& txt,qulonglong searchId)
|
||||||
|
{
|
||||||
|
QString sid_hexa = QString::number(searchId,16) ;
|
||||||
|
|
||||||
|
QTreeWidgetItem *item2 = new QTreeWidgetItem();
|
||||||
|
item2->setText(SS_TEXT_COL, QString::fromStdString(txt));
|
||||||
|
item2->setText(SS_COUNT_COL, QString::number(0));
|
||||||
|
item2->setText(SS_SEARCH_ID_COL, sid_hexa);
|
||||||
|
|
||||||
|
ui.searchSummaryWidget->addTopLevelItem(item2);
|
||||||
|
ui.searchSummaryWidget->setCurrentItem(item2);
|
||||||
|
}
|
||||||
|
|
||||||
void SearchDialog::advancedSearch(Expression* expression)
|
void SearchDialog::advancedSearch(Expression* expression)
|
||||||
{
|
{
|
||||||
advSearchDialog->hide();
|
advSearchDialog->hide();
|
||||||
@ -417,6 +432,10 @@ void SearchDialog::advancedSearch(Expression* expression)
|
|||||||
|
|
||||||
TurtleRequestId req_id = rsTurtle->turtleSearch(e) ;
|
TurtleRequestId req_id = rsTurtle->turtleSearch(e) ;
|
||||||
|
|
||||||
|
// This will act before turtle results come to the interface, thanks to the signals scheduling policy.
|
||||||
|
// The text "bool exp" should be replaced by an appropriate text describing the actual search.
|
||||||
|
initSearchResult(std::string("bool exp"),req_id) ;
|
||||||
|
|
||||||
rsFiles -> SearchBoolExp(expression, results, DIR_FLAGS_REMOTE | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE);
|
rsFiles -> SearchBoolExp(expression, results, DIR_FLAGS_REMOTE | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE);
|
||||||
|
|
||||||
/* abstraction to allow reusee of tree rendering code */
|
/* abstraction to allow reusee of tree rendering code */
|
||||||
@ -440,6 +459,8 @@ void SearchDialog::searchKeywords()
|
|||||||
|
|
||||||
TurtleRequestId req_id = rsTurtle->turtleSearch(txt) ;
|
TurtleRequestId req_id = rsTurtle->turtleSearch(txt) ;
|
||||||
|
|
||||||
|
initSearchResult(txt,req_id) ; // this will act before turtle results come to the interface, thanks to the signals scheduling policy.
|
||||||
|
|
||||||
/* 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;
|
||||||
@ -530,7 +551,7 @@ void SearchDialog::searchKeywords()
|
|||||||
|
|
||||||
/* 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)
|
||||||
@ -538,6 +559,11 @@ void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)
|
|||||||
/* which extensions do we use? */
|
/* which extensions do we use? */
|
||||||
std::string txt = ui.lineEdit->text().toStdString();
|
std::string txt = ui.lineEdit->text().toStdString();
|
||||||
|
|
||||||
|
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 ;
|
||||||
|
|
||||||
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
|
||||||
@ -549,7 +575,7 @@ void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)
|
|||||||
QStringList extList = extStr.split(" ");
|
QStringList extList = extStr.split(" ");
|
||||||
|
|
||||||
// get this file's extension
|
// get this file's extension
|
||||||
QString qName = QString::fromStdString(file.name);
|
QString qName = QString::fromUtf8(file.name.c_str());
|
||||||
int extIndex = qName.lastIndexOf(".");
|
int extIndex = qName.lastIndexOf(".");
|
||||||
|
|
||||||
if (extIndex >= 0)
|
if (extIndex >= 0)
|
||||||
@ -566,7 +592,10 @@ void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)
|
|||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
if (dir.type == DIR_TYPE_FILE) {
|
QString sid_hexa = QString::number(searchId,16) ;
|
||||||
|
|
||||||
|
if (dir.type == DIR_TYPE_FILE)
|
||||||
|
{
|
||||||
QTreeWidgetItem *child;
|
QTreeWidgetItem *child;
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
child = new QTreeWidgetItem(ui.searchResultWidget);
|
child = new QTreeWidgetItem(ui.searchResultWidget);
|
||||||
@ -576,14 +605,14 @@ void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId,
|
|||||||
|
|
||||||
/* translate search result for a file */
|
/* translate search result for a file */
|
||||||
|
|
||||||
child->setText(SR_NAME_COL, QString::fromStdString(dir.name));
|
child->setText(SR_NAME_COL, QString::fromUtf8(dir.name.c_str()));
|
||||||
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
|
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
|
||||||
QString ext = QFileInfo(QString::fromStdString(dir.name)).suffix();
|
QString ext = QFileInfo(QString::fromStdString(dir.name)).suffix();
|
||||||
child->setText(SR_SIZE_COL, misc::friendlyUnit(dir.count));
|
child->setText(SR_SIZE_COL, misc::friendlyUnit(dir.count));
|
||||||
child->setText(SR_REALSIZE_COL, QString::number(dir.count));
|
child->setText(SR_REALSIZE_COL, QString::number(dir.count));
|
||||||
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
||||||
child->setText(SR_ID_COL, QString::number(1));
|
child->setText(SR_ID_COL, QString::number(1));
|
||||||
child->setText(SR_SEARCH_ID_COL, QString::number(searchId,16));
|
child->setText(SR_SEARCH_ID_COL, sid_hexa);
|
||||||
setIconAndType(child, ext);
|
setIconAndType(child, ext);
|
||||||
|
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
@ -591,7 +620,9 @@ void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId,
|
|||||||
} else {
|
} else {
|
||||||
item->addChild(child);
|
item->addChild(child);
|
||||||
}
|
}
|
||||||
} else { /* it is a directory */
|
}
|
||||||
|
else
|
||||||
|
{ /* it is a directory */
|
||||||
QTreeWidgetItem *child;
|
QTreeWidgetItem *child;
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
child = new QTreeWidgetItem(ui.searchResultWidget);
|
child = new QTreeWidgetItem(ui.searchResultWidget);
|
||||||
@ -600,13 +631,13 @@ void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId,
|
|||||||
}
|
}
|
||||||
|
|
||||||
child->setIcon(SR_ICON_COL, QIcon(IMAGE_DIRECTORY));
|
child->setIcon(SR_ICON_COL, QIcon(IMAGE_DIRECTORY));
|
||||||
child->setText(SR_NAME_COL, QString::fromStdString(dir.name));
|
child->setText(SR_NAME_COL, QString::fromUtf8(dir.name.c_str()));
|
||||||
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
|
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
|
||||||
child->setText(SR_SIZE_COL, misc::friendlyUnit(dir.count));
|
child->setText(SR_SIZE_COL, misc::friendlyUnit(dir.count));
|
||||||
child->setText(SR_REALSIZE_COL, QString::number(dir.count));
|
child->setText(SR_REALSIZE_COL, QString::number(dir.count));
|
||||||
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
||||||
child->setText(SR_ID_COL, QString::number(1));
|
child->setText(SR_ID_COL, QString::number(1));
|
||||||
child->setText(SR_SEARCH_ID_COL, QString::number(searchId,16));
|
child->setText(SR_SEARCH_ID_COL, sid_hexa);
|
||||||
|
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
ui.searchResultWidget->addTopLevelItem(child);
|
ui.searchResultWidget->addTopLevelItem(child);
|
||||||
@ -618,7 +649,7 @@ void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId,
|
|||||||
|
|
||||||
for(int i = 0; i < items; i++)
|
for(int i = 0; i < items; i++)
|
||||||
{
|
{
|
||||||
if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL).toInt(NULL,16) == searchId)
|
if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL) == sid_hexa)
|
||||||
{
|
{
|
||||||
// increment result since every item is new
|
// increment result since every item is new
|
||||||
int s = ui.searchSummaryWidget->topLevelItem(i)->text(SS_COUNT_COL).toInt() ;
|
int s = ui.searchSummaryWidget->topLevelItem(i)->text(SS_COUNT_COL).toInt() ;
|
||||||
@ -631,7 +662,7 @@ void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId,
|
|||||||
QTreeWidgetItem *item2 = new QTreeWidgetItem();
|
QTreeWidgetItem *item2 = new QTreeWidgetItem();
|
||||||
item2->setText(SS_TEXT_COL, QString::fromStdString(txt));
|
item2->setText(SS_TEXT_COL, QString::fromStdString(txt));
|
||||||
item2->setText(SS_COUNT_COL, QString::number(1));
|
item2->setText(SS_COUNT_COL, QString::number(1));
|
||||||
item2->setText(SS_SEARCH_ID_COL, QString::number(searchId,16));
|
item2->setText(SS_SEARCH_ID_COL, sid_hexa);
|
||||||
|
|
||||||
ui.searchSummaryWidget->addTopLevelItem(item2);
|
ui.searchSummaryWidget->addTopLevelItem(item2);
|
||||||
ui.searchSummaryWidget->setCurrentItem(item2);
|
ui.searchSummaryWidget->setCurrentItem(item2);
|
||||||
@ -669,13 +700,16 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
|
|||||||
int items = ui.searchResultWidget->topLevelItemCount();
|
int items = ui.searchResultWidget->topLevelItemCount();
|
||||||
bool found = false ;
|
bool found = false ;
|
||||||
|
|
||||||
|
QString sid_hexa = QString::number(searchId,16) ;
|
||||||
|
|
||||||
for(int i = 0; i < items; i++)
|
for(int i = 0; i < items; i++)
|
||||||
if(ui.searchResultWidget->topLevelItem(i)->text(SR_HASH_COL) == QString::fromStdString(file.hash)
|
if(ui.searchResultWidget->topLevelItem(i)->text(SR_HASH_COL) == QString::fromStdString(file.hash)
|
||||||
&& ui.searchResultWidget->topLevelItem(i)->text(SR_SEARCH_ID_COL).toInt(NULL,16) == searchId)
|
&& ui.searchResultWidget->topLevelItem(i)->text(SR_SEARCH_ID_COL) == sid_hexa)
|
||||||
{
|
{
|
||||||
int s = ui.searchResultWidget->topLevelItem(i)->text(SR_ID_COL).toInt() ;
|
int s = ui.searchResultWidget->topLevelItem(i)->text(SR_ID_COL).toInt() ;
|
||||||
ui.searchResultWidget->topLevelItem(i)->setText(SR_ID_COL,QString::number(s+1));
|
ui.searchResultWidget->topLevelItem(i)->setText(SR_ID_COL,QString::number(s+1));
|
||||||
found = true ;
|
found = true ;
|
||||||
|
break ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!found)
|
if(!found)
|
||||||
@ -683,7 +717,7 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
|
|||||||
/* translate search results */
|
/* translate search results */
|
||||||
|
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||||
item->setText(SR_NAME_COL, QString::fromStdString(file.name));
|
item->setText(SR_NAME_COL, QString::fromUtf8(file.name.c_str()));
|
||||||
item->setText(SR_HASH_COL, QString::fromStdString(file.hash));
|
item->setText(SR_HASH_COL, QString::fromStdString(file.hash));
|
||||||
|
|
||||||
QString ext = QFileInfo(QString::fromStdString(file.name)).suffix();
|
QString ext = QFileInfo(QString::fromStdString(file.name)).suffix();
|
||||||
@ -697,7 +731,7 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
|
|||||||
item->setText(SR_REALSIZE_COL, QString::number(file.size));
|
item->setText(SR_REALSIZE_COL, QString::number(file.size));
|
||||||
item->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
item->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
||||||
item->setText(SR_ID_COL, QString::number(1));
|
item->setText(SR_ID_COL, QString::number(1));
|
||||||
item->setText(SR_SEARCH_ID_COL, QString::number(searchId,16));
|
item->setText(SR_SEARCH_ID_COL, sid_hexa);
|
||||||
|
|
||||||
ui.searchResultWidget->addTopLevelItem(item);
|
ui.searchResultWidget->addTopLevelItem(item);
|
||||||
}
|
}
|
||||||
@ -708,7 +742,7 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
|
|||||||
bool found2 = false ;
|
bool found2 = false ;
|
||||||
|
|
||||||
for(int i = 0; i < items2; i++)
|
for(int i = 0; i < items2; i++)
|
||||||
if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL).toInt(NULL,16) == searchId)
|
if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL) == sid_hexa)
|
||||||
{
|
{
|
||||||
if(!found) // only increment result when it's a new item.
|
if(!found) // only increment result when it's a new item.
|
||||||
{
|
{
|
||||||
@ -716,6 +750,7 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
|
|||||||
ui.searchSummaryWidget->topLevelItem(i)->setText(SS_COUNT_COL,QString::number(s+1));
|
ui.searchSummaryWidget->topLevelItem(i)->setText(SS_COUNT_COL,QString::number(s+1));
|
||||||
}
|
}
|
||||||
found2 = true ;
|
found2 = true ;
|
||||||
|
break ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!found2)
|
if(!found2)
|
||||||
@ -723,7 +758,7 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
|
|||||||
QTreeWidgetItem *item2 = new QTreeWidgetItem();
|
QTreeWidgetItem *item2 = new QTreeWidgetItem();
|
||||||
item2->setText(SS_TEXT_COL, QString::fromStdString(txt));
|
item2->setText(SS_TEXT_COL, QString::fromStdString(txt));
|
||||||
item2->setText(SS_COUNT_COL, QString::number(1));
|
item2->setText(SS_COUNT_COL, QString::number(1));
|
||||||
item2->setText(SS_SEARCH_ID_COL, QString::number(searchId,16));
|
item2->setText(SS_SEARCH_ID_COL, sid_hexa);
|
||||||
|
|
||||||
ui.searchSummaryWidget->addTopLevelItem(item2);
|
ui.searchSummaryWidget->addTopLevelItem(item2);
|
||||||
ui.searchSummaryWidget->setCurrentItem(item2);
|
ui.searchSummaryWidget->setCurrentItem(item2);
|
||||||
|
@ -86,6 +86,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/** render the results to the tree widget display */
|
/** render the results to the tree widget display */
|
||||||
|
void initSearchResult(const std::string& txt,qulonglong searchId) ;
|
||||||
void resultsToTree(std::string,qulonglong searchId, const std::list<DirDetails>&);
|
void resultsToTree(std::string,qulonglong searchId, const std::list<DirDetails>&);
|
||||||
void insertFile(const std::string& txt,qulonglong searchId, const FileDetail& file) ;
|
void insertFile(const std::string& txt,qulonglong searchId, const FileDetail& file) ;
|
||||||
void insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir, QTreeWidgetItem *item);
|
void insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir, QTreeWidgetItem *item);
|
||||||
|
Loading…
Reference in New Issue
Block a user