-add support for searching and display directories

-downloading directories from search dialog not implemented yet
-needs more code clean and beautify the directory tree

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1566 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
alexandrut 2009-08-25 20:49:50 +00:00
parent 1292a69ccf
commit 10d44a15b8
13 changed files with 564 additions and 431 deletions

View File

@ -59,7 +59,7 @@ FileIndexMonitor::~FileIndexMonitor()
return;
}
int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags)
int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags)
{
results.clear();
std::list<FileEntry *> firesults;
@ -69,7 +69,7 @@ int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<
return filterResults(firesults,results,flags) ;
}
int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<FileDetail>& results,uint32_t flags) const
int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<DirDetails>& results,uint32_t flags) const
{
results.clear();
std::list<FileEntry *> firesults;
@ -79,29 +79,22 @@ int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<FileDetail>& resu
return filterResults(firesults,results,flags) ;
}
int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<FileDetail>& results,uint32_t flags) const
int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,uint32_t flags) const
{
time_t now = time(NULL) ;
/* translate/filter results */
for(std::list<FileEntry*>::const_iterator rit(firesults.begin()); rit != firesults.end(); ++rit)
{
DirDetails details ;
RequestDirDetails((*rit)->parent,details,0) ;
DirDetails pdetails ;
RequestDirDetails((*rit)->parent,pdetails,0) ;
DirDetails cdetails ;
RequestDirDetails (*rit,cdetails,0);
if(( details.flags & flags & (DIR_FLAGS_BROWSABLE | DIR_FLAGS_NETWORK_WIDE) ) > 0 )
if ( ((cdetails.type == DIR_TYPE_FILE) && (pdetails.flags & flags & (DIR_FLAGS_BROWSABLE | DIR_FLAGS_NETWORK_WIDE)) > 0) ||
((cdetails.type == DIR_TYPE_DIR) && (cdetails.flags & flags & (DIR_FLAGS_BROWSABLE | DIR_FLAGS_NETWORK_WIDE)) > 0) )
{
FileDetail fd;
fd.id = "Local"; //localId;
fd.name = (*rit)->name;
fd.hash = (*rit)->hash;
fd.path = ""; /* TODO */
fd.size = (*rit)->size;
fd.age = now - (*rit)->modtime;
fd.rank = (*rit)->pop;
results.push_back(fd);
cdetails.id = "Local";
results.push_back(cdetails);
}
}
return !results.empty() ;

View File

@ -75,9 +75,9 @@ class FileIndexMonitor: public CacheSource, public RsThread
/* external interface for filetransfer */
bool findLocalFile(std::string hash,uint32_t f, std::string &fullpath, uint64_t &size) const;
int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags) ;
int SearchBoolExp(Expression *exp, std::list<FileDetail> &results,uint32_t flags) const ;
int filterResults(std::list<FileEntry*>& firesults,std::list<FileDetail>& results,uint32_t flags) const ;
int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) ;
int SearchBoolExp(Expression *exp, std::list<DirDetails> &results,uint32_t flags) const ;
int filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,uint32_t flags) const ;
/* external interface for local access to files */

View File

@ -1079,6 +1079,28 @@ int FileIndex::searchTerms(std::list<std::string> terms, std::list<FileEntry *>
dirlist.push_back(it->second);
}
for (iter = terms.begin(); iter != terms.end(); iter ++) {
std::string::const_iterator it2;
const std::string &str1 = ndir->name;
const std::string &str2 = *iter;
it2 = std::search(str1.begin(), str1.end(), str2.begin(), str2.end(), CompareCharIC());
if (it2 != str1.end()) {
/* first search to see if its parent is in the results list */
bool addDir = true;
for (std::list<FileEntry *>::iterator rit(results.begin()); rit != results.end() && addDir; rit ++) {
DirEntry *de = dynamic_cast<DirEntry *>(*rit);
if (de && (de == root))
continue;
if (de && (de == ndir->parent))
addDir = false;
}
if (addDir) {
results.push_back((FileEntry *) ndir);
break;
}
}
}
for(fit = ndir->files.begin(); fit != ndir->files.end(); fit++)
{
/* cycle through terms */

View File

@ -411,7 +411,7 @@ int FileIndexStore::SearchHash(std::string hash, std::list<FileDetail> &results)
}
int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags) const
int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) const
{
lockData();
std::map<RsPeerId, FileIndex *>::const_iterator pit;
@ -432,18 +432,10 @@ int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<Fi
/* translate results */
for(rit = firesults.begin(); rit != firesults.end(); rit++)
{
FileDetail fd;
fd.id = pit->first;
fd.name = (*rit)->name;
fd.hash = (*rit)->hash;
fd.path = ""; /* TODO */
fd.size = (*rit)->size;
fd.age = now - (*rit)->modtime;
fd.rank = (*rit)->pop;
results.push_back(fd);
DirDetails dd;
(pit->second)->RequestDirDetails(*rit, dd, 0);
results.push_back(dd);
}
}
if(flags & DIR_FLAGS_LOCAL)
@ -455,16 +447,10 @@ int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<Fi
/* translate results */
for(rit = firesults.begin(); rit != firesults.end(); rit++)
{
FileDetail fd;
fd.id = "Local"; //localId;
fd.name = (*rit)->name;
fd.hash = (*rit)->hash;
fd.path = ""; /* TODO */
fd.size = (*rit)->size;
fd.age = now - (*rit)->modtime;
fd.rank = (*rit)->pop;
results.push_back(fd);
DirDetails dd;
(pit->second)->RequestDirDetails(*rit, dd, 0);
dd.id = "Local";
results.push_back(dd);
}
}
@ -474,7 +460,7 @@ int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<Fi
}
int FileIndexStore::searchBoolExp(Expression * exp, std::list<FileDetail> &results) const
int FileIndexStore::searchBoolExp(Expression * exp, std::list<DirDetails> &results) const
{
lockData();
std::map<RsPeerId, FileIndex *>::const_iterator pit;
@ -495,16 +481,9 @@ int FileIndexStore::searchBoolExp(Expression * exp, std::list<FileDetail> &resul
/* translate results */
for(rit = firesults.begin(); rit != firesults.end(); rit++)
{
FileDetail fd;
fd.id = pit->first;
fd.name = (*rit)->name;
fd.hash = (*rit)->hash;
fd.path = ""; /* TODO */
fd.size = (*rit)->size;
fd.age = now - (*rit)->modtime;
fd.rank = (*rit)->pop;
results.push_back(fd);
DirDetails dd;
(pit->second)->RequestDirDetails(*rit, dd, 0);
results.push_back(dd);
}
}
@ -519,16 +498,10 @@ int FileIndexStore::searchBoolExp(Expression * exp, std::list<FileDetail> &resul
/* translate results */
for(rit = firesults.begin(); rit != firesults.end(); rit++)
{
FileDetail fd;
fd.id = "Local"; //localId;
fd.name = (*rit)->name;
fd.hash = (*rit)->hash;
fd.path = ""; /* TODO */
fd.size = (*rit)->size;
fd.age = now - (*rit)->modtime;
fd.rank = (*rit)->pop;
results.push_back(fd);
DirDetails dd;
(pit->second)->RequestDirDetails(*rit, dd, 0);
dd.id = "Local";
results.push_back(dd);
}
}

View File

@ -74,10 +74,10 @@ virtual int loadCache(const CacheData &data); /* actual load, once data availa
int SearchHash(std::string hash, std::list<FileDetail> &results) const;
/* Search Interface - For Search Interface */
int SearchKeywords(std::list<std::string> terms, std::list<FileDetail> &results,uint32_t flags) const;
int SearchKeywords(std::list<std::string> terms, std::list<DirDetails> &results,uint32_t flags) const;
/* Search Interface - for Adv Search Interface */
int searchBoolExp(Expression * exp, std::list<FileDetail> &results) const;
int searchBoolExp(Expression * exp, std::list<DirDetails> &results) const;
/* Search Interface - For Directory Access */

View File

@ -438,7 +438,7 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
/***************************************************************/
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags)
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::SearchKeywords()";
@ -457,7 +457,7 @@ int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<FileDeta
return mFiStore->SearchKeywords(keywords, results,flags);
}
int ftServer::SearchBoolExp(Expression * exp, std::list<FileDetail> &results,uint32_t flags)
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags)
{
if(flags & DIR_FLAGS_LOCAL)
return mFiMon->SearchBoolExp(exp,results,flags) ;

View File

@ -157,8 +157,8 @@ virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details);
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags);
virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results,uint32_t flags);
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags);
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags);
/***
* Utility Functions

View File

@ -149,8 +149,8 @@ virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details) = 0;
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) = 0;
virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags) = 0;
virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results,uint32_t flags) = 0;
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) = 0;
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags) = 0;
/***
* Utility Functions.

View File

@ -1302,7 +1302,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
void RsTurtleStringSearchRequestItem::performLocalSearch(std::list<TurtleFileInfo>& result) const
{
/* call to core */
std::list<FileDetail> initialResults;
std::list<DirDetails> initialResults;
std::list<std::string> words ;
// to do: split search string into words.
@ -1313,11 +1313,14 @@ void RsTurtleStringSearchRequestItem::performLocalSearch(std::list<TurtleFileInf
result.clear() ;
for(std::list<FileDetail>::const_iterator it(initialResults.begin());it!=initialResults.end();++it)
for(std::list<DirDetails>::const_iterator it(initialResults.begin());it!=initialResults.end();++it)
{
// retain only file type
if (it->type == DIR_TYPE_DIR) continue;
TurtleFileInfo i ;
i.hash = it->hash ;
i.size = it->size ;
i.size = it->count ;
i.name = it->name ;
result.push_back(i) ;
@ -1326,7 +1329,7 @@ void RsTurtleStringSearchRequestItem::performLocalSearch(std::list<TurtleFileInf
void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::list<TurtleFileInfo>& result) const
{
/* call to core */
std::list<FileDetail> initialResults;
std::list<DirDetails> initialResults;
// to do: split search string into words.
Expression *exp = LinearizedExpression::toExpr(expr) ;
@ -1336,11 +1339,11 @@ void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::list<TurtleFileInf
result.clear() ;
for(std::list<FileDetail>::const_iterator it(initialResults.begin());it!=initialResults.end();++it)
for(std::list<DirDetails>::const_iterator it(initialResults.begin());it!=initialResults.end();++it)
{
TurtleFileInfo i ;
i.hash = it->hash ;
i.size = it->size ;
i.size = it->count ;
i.name = it->name ;
result.push_back(i) ;

View File

@ -44,6 +44,7 @@
#define IMAGE_START ":/images/download.png"
#define IMAGE_REMOVE ":/images/delete.png"
#define IMAGE_REMOVEALL ":/images/deleteall.png"
#define IMAGE_DIRECTORY ":/images/folder_green16.png"
/* Key for UI Preferences */
#define UI_PREF_ADVANCED_SEARCH "UIOptions/AdvancedSearch"
@ -76,6 +77,7 @@ const int SearchDialog::FILETYPE_IDX_DOCUMENT = 4;
const int SearchDialog::FILETYPE_IDX_PICTURE = 5;
const int SearchDialog::FILETYPE_IDX_PROGRAM = 6;
const int SearchDialog::FILETYPE_IDX_VIDEO = 7;
const int SearchDialog::FILETYPE_IDX_DIRECTORY = 8;
QMap<int, QString> * SearchDialog::FileTypeExtensionMap = new QMap<int, QString>();
bool SearchDialog::initialised = false;
@ -411,7 +413,7 @@ void SearchDialog::advancedSearch(Expression* expression)
advSearchDialog->hide();
/* call to core */
std::list<FileDetail> results;
std::list<DirDetails> results;
// send a turtle search request
LinearizedExpression e ;
@ -458,8 +460,8 @@ void SearchDialog::searchKeywords()
}
/* call to core */
std::list<FileDetail> initialResults;
std::list<FileDetail> * finalResults = 0;
std::list<DirDetails> initialResults;
std::list<DirDetails> * finalResults = 0;
//rsFiles -> SearchKeywords(words, initialResults,DIR_FLAGS_LOCAL | DIR_FLAGS_REMOTE | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE);
rsFiles -> SearchKeywords(words, initialResults,DIR_FLAGS_REMOTE | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE);
@ -467,15 +469,34 @@ void SearchDialog::searchKeywords()
QString qExt, qName;
int extIndex;
bool matched =false;
FileDetail fd;
DirDetails dd;
if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_ANY)
{
finalResults = &initialResults;
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<FileDetail>;
finalResults = new std::list<DirDetails>;
// amend the text description of the search
txt += " (" + ui.FileTypeComboBox->currentText().toStdString() + ")";
// collect the extensions to use
@ -483,12 +504,13 @@ void SearchDialog::searchKeywords()
QStringList extList = extStr.split(" ");
// now iterate through the results ignoring those with wrong extensions
std::list<FileDetail>::iterator resultsIter;
std::list<DirDetails>::iterator resultsIter;
for (resultsIter = initialResults.begin(); resultsIter != initialResults.end(); resultsIter++)
{
fd = *resultsIter;
dd = *resultsIter;
if (dd.type == DIR_TYPE_DIR) continue;
// get this file's extension
qName = QString::fromStdString(fd.name);
qName = QString::fromStdString(dd.name);
extIndex = qName.lastIndexOf(".");
if (extIndex >= 0) {
qExt = qName.mid(extIndex+1);
@ -501,7 +523,7 @@ void SearchDialog::searchKeywords()
{
if (qExt.toUpper() == extList.at(i).toUpper())
{
finalResults->push_back(fd);
finalResults->push_back(dd);
matched = true;
}
}
@ -546,6 +568,94 @@ void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)
}
}
void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir, QTreeWidgetItem *item)
{
if (dir.type == DIR_TYPE_FILE) {
QTreeWidgetItem *child;
if (item == NULL) {
child = new QTreeWidgetItem(ui.searchResultWidget);
} else {
child = new QTreeWidgetItem(item);
}
/* translate search result for a file */
child->setText(SR_NAME_COL, QString::fromStdString(dir.name));
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
QString ext = QFileInfo(QString::fromStdString(dir.name)).suffix();
child->setText(SR_SIZE_COL, misc::friendlyUnit(dir.count));
child->setText(SR_REALSIZE_COL, QString::number(dir.count));
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
child->setText(SR_ID_COL, QString::number(1));
child->setText(SR_SEARCH_ID_COL, QString::number(searchId,16));
setIconAndType(child, ext);
if (item == NULL) {
ui.searchResultWidget->addTopLevelItem(child);
} else {
item->addChild(child);
}
} else { /* it is a directory */
QTreeWidgetItem *child;
if (item == NULL) {
child = new QTreeWidgetItem(ui.searchResultWidget);
} else {
child = new QTreeWidgetItem(item);
}
child->setIcon(SR_ICON_COL, QIcon(IMAGE_DIRECTORY));
child->setText(SR_NAME_COL, QString::fromStdString(dir.name));
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
child->setText(SR_SIZE_COL, misc::friendlyUnit(dir.count));
child->setText(SR_REALSIZE_COL, QString::number(dir.count));
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
child->setText(SR_ID_COL, QString::number(1));
child->setText(SR_SEARCH_ID_COL, QString::number(searchId,16));
if (item == NULL) {
ui.searchResultWidget->addTopLevelItem(child);
/* add to the summary as well */
int items = ui.searchSummaryWidget->topLevelItemCount();
bool found = false ;
for(int i = 0; i < items; i++)
{
if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL).toInt(NULL,16) == searchId)
{
// increment result since every item is new
int s = ui.searchSummaryWidget->topLevelItem(i)->text(SS_COUNT_COL).toInt() ;
ui.searchSummaryWidget->topLevelItem(i)->setText(SS_COUNT_COL,QString::number(s+1));
found = true ;
}
}
if(!found)
{
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,16));
ui.searchSummaryWidget->addTopLevelItem(item2);
ui.searchSummaryWidget->setCurrentItem(item2);
}
/* select this search result */
selectSearchResults();
} else {
item->addChild(child);
}
/* go through all children directories/files for a recursive call */
for (std::list<DirStub>::const_iterator it(dir.children.begin()); it != dir.children.end(); it ++) {
DirDetails details;
rsFiles->RequestDirDetails(it->ref, details, 0);
insertDirectory(txt, searchId, details, child);
}
}
}
void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const FileDetail& file)
{
// algo:
@ -581,56 +691,7 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
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")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeVideo.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Video"));
}
else if (ext == "ogg" || ext == "mp3" || ext == "wav" || ext == "wma")
{
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")
{
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")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeProgram.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Program"));
}
else if (ext == "iso" || ext == "nrg" || ext == "mdf" )
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeCDImage.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("CD-Image"));
}
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
}
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls"
|| ext == "sxc" || ext == "odt" || ext == "ods")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
}
else if (ext == "html" || ext == "htm" || ext == "php")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
}
else
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeAny.png"));
}
setIconAndType(item, ext);
/*
* to facilitate downlaods we need to save the file size too
@ -676,15 +737,32 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
selectSearchResults();
}
void SearchDialog::resultsToTree(std::string txt,qulonglong searchId, const std::list<FileDetail>& results)
void SearchDialog::resultsToTree(std::string txt,qulonglong searchId, const std::list<DirDetails>& results)
{
ui.searchResultWidget->setSortingEnabled(false);
/* translate search results */
std::ostringstream out;
out << searchId;
std::list<FileDetail>::const_iterator it;
std::list<DirDetails>::const_iterator it;
for(it = results.begin(); it != results.end(); it++)
insertFile(txt,searchId,*it) ;
if (it->type == DIR_TYPE_FILE) {
FileDetail fd;
fd.id = it->id;
fd.name = it->name;
fd.hash = it->hash;
fd.path = it->path;
fd.size = it->count;
fd.age = it->age;
fd.rank = 0;
insertFile(txt,searchId,fd);
} else if (it->type == DIR_TYPE_DIR) {
insertDirectory(txt, searchId, *it, NULL);
}
ui.searchResultWidget->setSortingEnabled(true);
}
@ -722,4 +800,56 @@ void SearchDialog::selectSearchResults()
ui.searchResultWidget->update();
}
void SearchDialog::setIconAndType(QTreeWidgetItem *item, QString &ext)
{
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")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeVideo.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Video"));
}
else if (ext == "ogg" || ext == "mp3" || ext == "wav" || ext == "wma")
{
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")
{
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")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeProgram.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Program"));
}
else if (ext == "iso" || ext == "nrg" || ext == "mdf" )
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeCDImage.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("CD-Image"));
}
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
}
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls"
|| ext == "sxc" || ext == "odt" || ext == "ods")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
}
else if (ext == "html" || ext == "htm" || ext == "php")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
}
else
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeAny.png"));
}
}

View File

@ -86,8 +86,10 @@ private slots:
private:
/** render the results to the tree widget display */
void resultsToTree(std::string,qulonglong searchId, const std::list<FileDetail>&);
void resultsToTree(std::string,qulonglong searchId, const std::list<DirDetails>&);
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 setIconAndType(QTreeWidgetItem *item, QString &ext);
/** the advanced search dialog instance */
@ -115,6 +117,7 @@ private:
static const int FILETYPE_IDX_PICTURE;
static const int FILETYPE_IDX_PROGRAM;
static const int FILETYPE_IDX_VIDEO;
static const int FILETYPE_IDX_DIRECTORY;
static QMap<int, QString> * FileTypeExtensionMap;

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>627</width>
<width>645</width>
<height>341</height>
</rect>
</property>
@ -576,6 +576,15 @@
<normaloff>:/images/FileTypeVideo.png</normaloff>:/images/FileTypeVideo.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Directory</string>
</property>
<property name="icon">
<iconset resource="images.qrc">
<normaloff>:/images/folder_green16.png</normaloff>:/images/folder_green16.png</iconset>
</property>
</item>
</widget>
</item>
<item row="0" column="1">

View File

@ -149,8 +149,8 @@ virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details) = 0;
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) = 0;
virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags) = 0;
virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results,uint32_t flags) = 0;
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) = 0;
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags) = 0;
/***
* Utility Functions.