Merge pull request #1207 from PhenomRetroShare/Add_TimerFilterInSharedFilesDialog

Add a timer in SharedFilesDialog filter to not so often triggs search in
This commit is contained in:
csoler 2018-04-15 22:26:35 +02:00 committed by GitHub
commit d5d445a7b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 21 deletions

View File

@ -81,6 +81,8 @@
#define MAX_SEARCH_RESULTS 3000
#define DISABLE_SEARCH_WHILE_TYPING 1
// Define to avoid using the search in treeview, because it is really slow for now.
//
//#define DONT_USE_SEARCH_IN_TREE_VIEW 1
@ -186,7 +188,14 @@ SharedFilesDialog::SharedFilesDialog(RetroshareDirModel *_tree_model,RetroshareD
connect(ui.filterClearButton, SIGNAL(clicked()), this, SLOT(clearFilter()));
connect(ui.filterStartButton, SIGNAL(clicked()), this, SLOT(startFilter()));
connect(ui.filterPatternLineEdit, SIGNAL(returnPressed()), this, SLOT(startFilter()));
connect(ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged()));
connect(ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(onFilterTextEdited()));
//Hidden by default, shown on onFilterTextEdited
ui.filterClearButton->hide();
ui.filterStartButton->hide();
mFilterTimer = new RsProtectedTimer( this );
mFilterTimer->setSingleShot( true ); // Ensure the timer will fire only once after it was started
connect(mFilterTimer, SIGNAL(timeout()), this, SLOT(filterRegExpChanged()));
/* Set header resize modes and initial section sizes */
QHeaderView * header = ui.dirTreeView->header () ;
@ -1246,7 +1255,7 @@ void SharedFilesDialog::indicatorChanged(int index)
updateDisplay() ;
}
void SharedFilesDialog::filterRegExpChanged()
void SharedFilesDialog::onFilterTextEdited()
{
QString text = ui.filterPatternLineEdit->text();
@ -1262,18 +1271,26 @@ void SharedFilesDialog::filterRegExpChanged()
ui.filterStartButton->show();
}
//bool valid = false ;
//QColor color ;
if(text.length() > 0 && text.length() < 3)
{
//valid = false;
ui.filterStartButton->setEnabled(false) ;
ui.filterPatternFrame->setToolTip(tr("Search string should be at least 3 characters long.")) ;
return ;
}
ui.filterStartButton->setEnabled(true) ;
ui.filterPatternFrame->setToolTip(QString());
#ifndef DISABLE_SEARCH_WHILE_TYPING
mFilterTimer->start( 500 ); // This will fire filterRegExpChanged after 500 ms.
// If the user types something before it fires, the timer restarts counting
#endif
}
void SharedFilesDialog::filterRegExpChanged()
{
QString text = ui.filterPatternLineEdit->text();
if(text.length() > 0 && proxyModel == tree_proxyModel)
{
std::list<DirDetails> result_list ;
@ -1497,8 +1514,19 @@ void SharedFilesDialog::FilterItems()
std::cerr << "Found " << result_list.size() << " results" << std::endl;
#endif
if(result_list.size() > MAX_SEARCH_RESULTS)
size_t resSize = result_list.size();
if(resSize == 0)
{
ui.filterPatternFrame->setToolTip(tr("No result.")) ;
return ;
}
if(resSize > MAX_SEARCH_RESULTS)
{
ui.filterPatternFrame->setToolTip(tr("More than %1 results. Add more/longer search words to select less.").arg(MAX_SEARCH_RESULTS)) ;
return ;
}
ui.filterPatternFrame->setToolTip(tr("Found %1 results.").arg(resSize)) ;
#ifdef DEBUG_SHARED_FILES_DIALOG
std::cerr << "Found this result: " << std::endl;
#endif

View File

@ -22,10 +22,13 @@
#ifndef _SHAREDFILESDIALOG_H
#define _SHAREDFILESDIALOG_H
#include <set>
#include "ui_SharedFilesDialog.h"
#include "RsAutoUpdatePage.h"
#include "gui/RetroShareLink.h"
#include "ui_SharedFilesDialog.h"
#include "util/RsProtectedTimer.h"
#include <set>
class RetroshareDirModel;
class QSortFilterProxyModel;
@ -73,6 +76,7 @@ private slots:
void indicatorChanged(int index);
void onFilterTextEdited();
void filterRegExpChanged();
void clearFilter();
void startFilter();
@ -137,6 +141,7 @@ protected:
QString lastFilterString;
QString mLastFilterText ;
RsProtectedTimer* mFilterTimer;
QList<QModelIndex> mHiddenIndexes;
};