Add Ignore Text list in SearchDialog

Ability to modify the saved list when long click on button "Ignore".
All in tooltip.
This commit is contained in:
Phenom 2022-01-15 15:28:48 +01:00
parent 0c03e93a47
commit 9fb55a555b
3 changed files with 117 additions and 10 deletions

View File

@ -150,6 +150,8 @@ SearchDialog::SearchDialog(QWidget *parent)
connect(ui.filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems()));
connect(ui.filterLineEdit, SIGNAL(filterChanged(int)), this, SLOT(filterItems()));
connect(ui.ignore_PB, SIGNAL(clicked(bool)), this, SLOT(ignore_PB_Clicked(bool)));
compareSummaryRole = new RSTreeWidgetItemCompareRole;
compareSummaryRole->setRole(SS_RESULTS_COL, ROLE_SORT);
@ -215,13 +217,39 @@ SearchDialog::SearchDialog(QWidget *parent)
//ui.filterLineEdit->addFilter(QIcon(), tr("File Size"), SR_SIZE_COL);
ui.filterLineEdit->setCurrentFilter(SR_NAME_COL);
ui.ignore_PB->setAutoRepeat(true);
ui.ignore_PB->setAutoRepeatDelay(1000);
ui.ignore_PB->setAutoRepeatInterval(1000000);
mIgnore_PB_LongPressed = false;
mIgnoreListFrame = new QFrame(this);
mIgnoreListFrame->setObjectName("gradFrame_IgnoreList");
mIgnoreListFrame->setFrameShape(QFrame::StyledPanel);
mIgnoreListTextEdit = new QPlainTextEdit(mIgnoreListFrame);
QVBoxLayout *layout = new QVBoxLayout(mIgnoreListFrame);
layout->setMargin(2);
layout->addWidget(mIgnoreListTextEdit);
QPushButton *valid = new QPushButton(mIgnoreListFrame);
QPushButton *cancel = new QPushButton(mIgnoreListFrame);
valid->setText(tr("Valid"));
cancel->setText(tr("Cancel"));
connect(valid, SIGNAL(clicked()), this, SLOT(ignoreListValided()));
connect(cancel, SIGNAL(clicked()), this, SLOT(ignoreListCanceled()));
QHBoxLayout *buttonLayout = new QHBoxLayout(mIgnoreListFrame);
buttonLayout->addWidget(valid);
buttonLayout->addWidget(cancel);
layout->addLayout(buttonLayout);
mIgnoreListFrame->setLayout(layout);
mIgnoreListFrame->setHidden(true);
// load settings
processSettings(true);
ui._ownFiles_CB->setMinimumWidth(20*f);
ui._friendListsearch_SB->setMinimumWidth(20*f);
ui._ownFiles_CB->setMinimumWidth(20*f);
ui._friendListsearch_SB->setMinimumWidth(20*f);
ui._anonF2Fsearch_CB->setMinimumWidth(20*f);
ui.label->setMinimumWidth(20*f);
ui._max_results_L->setMinimumWidth(20*f);
// workaround for Qt bug, be solved in next Qt release 4.7.0
// https://bugreports.qt-project.org/browse/QTBUG-8270
@ -302,6 +330,9 @@ void SearchDialog::processSettings(bool bLoad)
ui.splitter->restoreState(Settings->value("Splitter").toByteArray());
ui._max_results_SB->setValue(Settings->value("MaxResults").toInt());
mIgnoreList = Settings->value("IgnoreList",QStringList()).toStringList();
updateIgnoreToolTip();
} else {
// save settings
@ -313,12 +344,58 @@ void SearchDialog::processSettings(bool bLoad)
Settings->setValue("Splitter", ui.splitter->saveState());
Settings->setValue("MaxResults", ui._max_results_SB->value());
Settings->setValue("IgnoreList", mIgnoreList);
}
Settings->endGroup();
m_bProcessSettings = false;
}
void SearchDialog::updateIgnoreToolTip()
{
ui.ignore_PB->setToolTip(tr("This allow to ignore results containing one of theses text.") + "\n"
+ QString(mIgnoreList.empty() ? "": (mIgnoreList.join(";") + "\n"))
+ tr("Do a long click to edit it."));
}
void SearchDialog::ignore_PB_Clicked(bool /*checked = true*/)
{
if (ui.ignore_PB->isDown())
{
mIgnore_PB_LongPressed = true;
showIgnoreList();
}
else
{
if (!ui.ignore_PB->isChecked() && !mIgnore_PB_LongPressed)
mIgnoreListFrame->setHidden(true);
mIgnore_PB_LongPressed = false;
}
}
void SearchDialog::showIgnoreList()
{
mIgnoreListTextEdit->setPlainText(mIgnoreList.join("\n"));
mIgnoreListFrame->ensurePolished();
QPoint point = ui.ignore_PB->mapTo(this, QPoint());
mIgnoreListFrame->setGeometry( point.x() , point.y() - mIgnoreListFrame->sizeHint().height()
, mIgnoreListFrame->sizeHint().width(), mIgnoreListFrame->sizeHint().height());
mIgnoreListFrame->setVisible(true);
}
void SearchDialog::ignoreListValided()
{
mIgnoreList = mIgnoreListTextEdit->toPlainText().split("\n");
mIgnoreList.removeAll(QString(""));
mIgnoreListFrame->setHidden(true);
updateIgnoreToolTip();
}
void SearchDialog::ignoreListCanceled()
{
mIgnoreListFrame->setHidden(true);
}
void SearchDialog::checkText(const QString& txt)
{
@ -982,6 +1059,11 @@ void SearchDialog::searchKeywords(const QString& keywords)
void SearchDialog::updateFiles(qulonglong search_id,const FileDetail& file)
{
if (ui.ignore_PB->isChecked())
foreach( auto ignore, mIgnoreList)
if (QString::fromUtf8(file.name.c_str()).contains(ignore, Qt::CaseInsensitive))
return;
searchResultsQueue.push_back(std::pair<qulonglong,FileDetail>(search_id,file)) ;
if(!_queueIsAlreadyTakenCareOf)

View File

@ -21,11 +21,15 @@
#ifndef _SEARCHDIALOG_H
#define _SEARCHDIALOG_H
#include "retroshare/rstypes.h"
#include "retroshare/rsevents.h"
#include "ui_SearchDialog.h"
#include "retroshare-gui/mainpage.h"
#include "retroshare/rsevents.h"
#include "retroshare/rstypes.h"
#include <QPlainTextEdit>
class AdvancedSearchDialog;
class RSTreeWidgetItemCompareRole;
@ -64,7 +68,7 @@ public:
void setTextColorLowSources(QColor color) { mTextColorLowSources = color; }
void setTextColorHighSources(QColor color) { mTextColorHighSources = color; }
void updateFiles(qulonglong request_id, const FileDetail& file) ;
void updateFiles(qulonglong request_id, const FileDetail& file) ;
private slots:
@ -116,6 +120,10 @@ private slots:
void filterItems();
void ignore_PB_Clicked(bool checked = false);
void ignoreListCanceled();
void ignoreListValided();
private:
/** render the results to the tree widget display */
void initSearchResult(const QString& txt,qulonglong searchId, int fileType, bool advanced) ;
@ -151,6 +159,9 @@ private:
bool filterItem(QTreeWidgetItem *item, const QString &text, int filterColumn);
void updateIgnoreToolTip();
void showIgnoreList();
bool m_bProcessSettings;
int nextSearchId;
@ -178,6 +189,10 @@ private:
bool _queueIsAlreadyTakenCareOf ;
std::vector<std::pair<qulonglong,FileDetail> > searchResultsQueue ;
QStringList mIgnoreList;
bool mIgnore_PB_LongPressed;
QFrame *mIgnoreListFrame;
QPlainTextEdit *mIgnoreListTextEdit;
RsEventsHandlerId_t mEventHandlerId ;
};

View File

@ -235,7 +235,7 @@
</column>
</widget>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="searchResult_VL">
<item>
<widget class="SearchTreeWidget" name="searchResultWidget">
<property name="sizePolicy">
@ -292,9 +292,9 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QHBoxLayout" name="SearchResultTool_HL">
<item>
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="filter_L">
<property name="text">
<string>Filter:</string>
</property>
@ -308,7 +308,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<widget class="QLabel" name="_max_results_L">
<property name="text">
<string>Max results:</string>
</property>
@ -333,6 +333,16 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ignore_PB">
<property name="text">
<string>Ignore</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="RSComboBox" name="FileTypeComboBox">
<item>