mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-13 08:29:32 -05:00
added a fair limit to search in FL in order to avoid crazy costs
This commit is contained in:
parent
d93e259702
commit
f139685438
@ -31,6 +31,7 @@
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
#include "rshare.h"
|
||||
#include "SharedFilesDialog.h"
|
||||
#include "gui/notifyqt.h"
|
||||
#include "gui/MainWindow.h"
|
||||
@ -49,6 +50,7 @@
|
||||
|
||||
#include <retroshare/rspeers.h>
|
||||
#include <retroshare/rsfiles.h>
|
||||
#include <retroshare/rsexpr.h>
|
||||
|
||||
|
||||
/* Images for context menu icons */
|
||||
@ -85,6 +87,8 @@
|
||||
#define VIEW_TYPE_TREE 0
|
||||
#define VIEW_TYPE_FLAT 1
|
||||
|
||||
#define MAX_SEARCH_RESULTS 3000
|
||||
|
||||
// Define to avoid using the search in treeview, because it is really slow for now.
|
||||
//
|
||||
//#define DONT_USE_SEARCH_IN_TREE_VIEW 1
|
||||
@ -1226,6 +1230,63 @@ void SharedFilesDialog::filterRegExpChanged()
|
||||
} else {
|
||||
ui.filterStartButton->show();
|
||||
}
|
||||
|
||||
bool valid = false ;
|
||||
QColor color ;
|
||||
|
||||
if(text.length() > 0 && text.length() < 3)
|
||||
{
|
||||
std::cout << "setting palette 1" << std::endl ;
|
||||
valid = false;
|
||||
//color = QApplication::palette().color(QPalette::Disabled, QPalette::Base);
|
||||
|
||||
ui.filterStartButton->setEnabled(false) ;
|
||||
ui.filterPatternFrame->setToolTip(tr("Search string should be at least 3 characters long.")) ;
|
||||
return ;
|
||||
}
|
||||
|
||||
if(text.length() > 0 && proxyModel == tree_proxyModel)
|
||||
{
|
||||
std::list<DirDetails> result_list ;
|
||||
std::list<std::string> keywords;
|
||||
|
||||
QStringList lst = text.split(" ",QString::SkipEmptyParts) ;
|
||||
|
||||
for(auto it(lst.begin());it!=lst.end();++it)
|
||||
keywords.push_back((*it).toStdString());
|
||||
|
||||
FileSearchFlags flags = isRemote()?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL;
|
||||
|
||||
if(keywords.size() > 1)
|
||||
{
|
||||
RsRegularExpression::NameExpression exp(RsRegularExpression::ContainsAllStrings,keywords,true);
|
||||
rsFiles->SearchBoolExp(&exp,result_list, flags) ;
|
||||
}
|
||||
else
|
||||
rsFiles->SearchKeywords(keywords,result_list, flags) ;
|
||||
|
||||
uint32_t nb_results = result_list.size();
|
||||
|
||||
if(nb_results > MAX_SEARCH_RESULTS)
|
||||
{
|
||||
ui.filterStartButton->setEnabled(false) ;
|
||||
ui.filterPatternFrame->setToolTip(tr("More than 3000 results. Add more/longer search words to select less.")) ;
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
ui.filterStartButton->setEnabled(true) ;
|
||||
ui.filterPatternFrame->setToolTip(QString());
|
||||
|
||||
/* unpolish widget to clear the stylesheet's palette cache */
|
||||
// ui.filterPatternFrame->style()->unpolish(ui.filterPatternFrame);
|
||||
|
||||
// QPalette palette = ui.filterPatternLineEdit->palette();
|
||||
// palette.setColor(ui.filterPatternLineEdit->backgroundRole(), color);
|
||||
// ui.filterPatternLineEdit->setPalette(palette);
|
||||
|
||||
// //ui.searchLineFrame->setProperty("valid", valid);
|
||||
// Rshare::refreshStyleSheet(ui.filterPatternFrame, false);
|
||||
}
|
||||
|
||||
/* clear Filter */
|
||||
@ -1342,11 +1403,28 @@ void SharedFilesDialog::FilterItems()
|
||||
setCursor(Qt::ArrowCursor);
|
||||
return ;
|
||||
}
|
||||
keywords.push_back(text.toStdString());
|
||||
|
||||
if(text.length() < 3)
|
||||
return ;
|
||||
|
||||
FileSearchFlags flags = isRemote()?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL;
|
||||
QStringList lst = text.split(" ",QString::SkipEmptyParts) ;
|
||||
|
||||
rsFiles->SearchKeywords(keywords,result_list, flags) ;
|
||||
for(auto it(lst.begin());it!=lst.end();++it)
|
||||
keywords.push_back((*it).toStdString());
|
||||
|
||||
if(keywords.size() > 1)
|
||||
{
|
||||
RsRegularExpression::NameExpression exp(RsRegularExpression::ContainsAllStrings,keywords,true);
|
||||
rsFiles->SearchBoolExp(&exp,result_list, flags) ;
|
||||
}
|
||||
else
|
||||
rsFiles->SearchKeywords(keywords,result_list, flags) ;
|
||||
|
||||
std::cerr << "Found " << result_list.size() << " results" << std::endl;
|
||||
|
||||
if(result_list.size() > MAX_SEARCH_RESULTS)
|
||||
return ;
|
||||
#ifdef DEBUG_SHARED_FILES_DIALOG
|
||||
std::cerr << "Found this result: " << std::endl;
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1156</width>
|
||||
<width>1407</width>
|
||||
<height>402</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -53,7 +53,7 @@
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="icons.qrc">:/icons/svg/folders.svg</pixmap>
|
||||
<pixmap resource="../icons.qrc">:/icons/svg/folders.svg</pixmap>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
@ -89,7 +89,7 @@
|
||||
<string>Configure shared directories</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/add-share24.png</normaloff>:/images/add-share24.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@ -105,15 +105,41 @@
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="images.qrc">:/images/find-16.png</pixmap>
|
||||
<pixmap resource="../images.qrc">:/images/find-16.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="filterPatternLineEdit">
|
||||
<property name="toolTip">
|
||||
<string>Search files</string>
|
||||
<widget class="QFrame" name="filterPatternFrame">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>50</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="filterPatternLineEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -140,7 +166,7 @@
|
||||
<string>Start Search</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/start.png</normaloff>:/images/start.png</iconset>
|
||||
</property>
|
||||
<property name="flat">
|
||||
@ -214,7 +240,7 @@ border-image: url(:/images/closepressed.png)
|
||||
<string>All</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/view_calendar_list.png</normaloff>:/images/view_calendar_list.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@ -223,7 +249,7 @@ border-image: url(:/images/closepressed.png)
|
||||
<string>One day old</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/view_calendar_day.png</normaloff>:/images/view_calendar_day.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@ -232,7 +258,7 @@ border-image: url(:/images/closepressed.png)
|
||||
<string>One Week old</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/view_calendar_week.png</normaloff>:/images/view_calendar_week.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@ -241,7 +267,7 @@ border-image: url(:/images/closepressed.png)
|
||||
<string>One month old</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/view_calendar_month.png</normaloff>:/images/view_calendar_month.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@ -282,7 +308,7 @@ border-image: url(:/images/closepressed.png)
|
||||
<string>Download</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/download16.png</normaloff>:/images/download16.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@ -363,8 +389,8 @@ border-image: url(:/images/closepressed.png)
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="images.qrc"/>
|
||||
<include location="icons.qrc"/>
|
||||
<include location="../icons.qrc"/>
|
||||
<include location="../images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
Loading…
Reference in New Issue
Block a user