Index config GUI: fix bug where the +- forms of skippedNames and noContentSuffixes were not taken into account
This commit is contained in:
parent
e59b356bad
commit
572eb5b57d
@ -65,27 +65,34 @@ bool o_uptodate_test_use_mtime = false;
|
||||
string RclConfig::o_localecharset;
|
||||
string RclConfig::o_origcwd;
|
||||
|
||||
// Compute the difference of 1st to 2nd set<string> and return as
|
||||
// plus/minus strings
|
||||
static void setPlusMinus(const set<string>& base, const set<string>& upd,
|
||||
string& plus, string& minus)
|
||||
// Compute the difference of 1st to 2nd sets and return as plus/minus
|
||||
// sets. Some args are std::set and some others stringToString()
|
||||
// strings for convenience
|
||||
void RclConfig::setPlusMinus(const string& sbase, const set<string>& upd,
|
||||
string& splus, string& sminus)
|
||||
{
|
||||
set<string> base;
|
||||
stringToStrings(sbase, base);
|
||||
|
||||
vector<string> diff;
|
||||
auto it =
|
||||
set_difference(base.begin(), base.end(), upd.begin(), upd.end(),
|
||||
std::inserter(diff, diff.begin()));
|
||||
minus = stringsToString(diff);
|
||||
sminus = stringsToString(diff);
|
||||
|
||||
diff.clear();
|
||||
it = set_difference(upd.begin(), upd.end(), base.begin(), base.end(),
|
||||
std::inserter(diff, diff.begin()));
|
||||
plus = stringsToString(diff);
|
||||
splus = stringsToString(diff);
|
||||
}
|
||||
|
||||
/* Compute result of substracting strminus and adding strplus to base string.
|
||||
All string represent sets of values to be computed with stringToStrings() */
|
||||
static void computeBasePlusMinus(set<string>& res, const string& strbase,
|
||||
const string& strplus, const string& strminus)
|
||||
{
|
||||
set<string> plus, minus;
|
||||
res.clear();
|
||||
stringToStrings(strbase, res);
|
||||
stringToStrings(strplus, plus);
|
||||
stringToStrings(strminus, minus);
|
||||
@ -660,41 +667,54 @@ public:
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
typedef multiset<SfString, SuffCmp> SuffixStore;
|
||||
|
||||
typedef multiset<SfString, SuffCmp> SuffixStore;
|
||||
#define STOPSUFFIXES ((SuffixStore *)m_stopsuffixes)
|
||||
|
||||
vector<string>& RclConfig::getStopSuffixes()
|
||||
{
|
||||
bool needrecompute = m_stpsuffstate.needrecompute();
|
||||
needrecompute = m_oldstpsuffstate.needrecompute() || needrecompute;
|
||||
if (needrecompute || m_stopsuffixes == 0) {
|
||||
// Need to initialize the suffixes
|
||||
|
||||
// Let the old customisation have priority: if recoll_noindex from
|
||||
// mimemap is set, it the user's (the default value is gone). Else
|
||||
// use the new variable
|
||||
if (!m_oldstpsuffstate.getvalue(0).empty()) {
|
||||
stringToStrings(m_oldstpsuffstate.getvalue(0), m_stopsuffvec);
|
||||
} else {
|
||||
std::set<string> ss;
|
||||
computeBasePlusMinus(ss, m_stpsuffstate.getvalue(0),
|
||||
m_stpsuffstate.getvalue(1),
|
||||
m_stpsuffstate.getvalue(2));
|
||||
m_stopsuffvec = vector<string>(ss.begin(), ss.end());
|
||||
}
|
||||
|
||||
// Compute the special suffixes store
|
||||
delete STOPSUFFIXES;
|
||||
if ((m_stopsuffixes = new SuffixStore) == 0) {
|
||||
LOGERR("RclConfig::inStopSuffixes: out of memory\n");
|
||||
return m_stopsuffvec;
|
||||
}
|
||||
m_maxsufflen = 0;
|
||||
for (const auto& entry : m_stopsuffvec) {
|
||||
STOPSUFFIXES->insert(SfString(stringtolower(entry)));
|
||||
if (m_maxsufflen < entry.length())
|
||||
m_maxsufflen = int(entry.length());
|
||||
}
|
||||
}
|
||||
LOGDEB1("RclConfig::getStopSuffixes: ->" <<
|
||||
stringsToString(m_stopsuffvec) << endl);
|
||||
return m_stopsuffvec;
|
||||
}
|
||||
|
||||
bool RclConfig::inStopSuffixes(const string& fni)
|
||||
{
|
||||
LOGDEB2("RclConfig::inStopSuffixes(" << fni << ")\n");
|
||||
// Beware: both needrecompute() need to be called always hence the
|
||||
// bizarre way we do things
|
||||
bool needrecompute = m_stpsuffstate.needrecompute();
|
||||
needrecompute = m_oldstpsuffstate.needrecompute() || needrecompute;
|
||||
if (needrecompute || m_stopsuffixes == 0) {
|
||||
// Need to initialize the suffixes
|
||||
delete STOPSUFFIXES;
|
||||
if ((m_stopsuffixes = new SuffixStore) == 0) {
|
||||
LOGERR("RclConfig::inStopSuffixes: out of memory\n");
|
||||
return false;
|
||||
}
|
||||
// Let the old customisation have priority: if recoll_noindex
|
||||
// from mimemap is set, it the user's (the default value is
|
||||
// gone). Else use the new variable
|
||||
set<string> stoplist;
|
||||
if (!m_oldstpsuffstate.getvalue(0).empty()) {
|
||||
stringToStrings(m_oldstpsuffstate.getvalue(0), stoplist);
|
||||
} else {
|
||||
computeBasePlusMinus(stoplist, m_stpsuffstate.getvalue(0),
|
||||
m_stpsuffstate.getvalue(1),
|
||||
m_stpsuffstate.getvalue(2));
|
||||
}
|
||||
for (auto& it : stoplist) {
|
||||
STOPSUFFIXES->insert(SfString(stringtolower(it)));
|
||||
if (m_maxsufflen < it.length())
|
||||
m_maxsufflen = int(it.length());
|
||||
}
|
||||
}
|
||||
|
||||
// Call getStopSuffixes() to possibly update state, ignore result
|
||||
getStopSuffixes();
|
||||
|
||||
// Only need a tail as long as the longest suffix.
|
||||
int pos = MAX(0, int(fni.length() - m_maxsufflen));
|
||||
@ -1097,13 +1117,11 @@ bool RclConfig::setMimeViewerAllEx(const set<string>& allex)
|
||||
if (mimeview == 0)
|
||||
return false;
|
||||
|
||||
string s;
|
||||
mimeview->get("xallexcepts", s, "");
|
||||
set<string> base;
|
||||
stringToStrings(s, base);
|
||||
string sbase;
|
||||
mimeview->get("xallexcepts", sbase, "");
|
||||
|
||||
string splus, sminus;
|
||||
setPlusMinus(base, allex, splus, sminus);
|
||||
setPlusMinus(sbase, allex, splus, sminus);
|
||||
|
||||
if (!mimeview->set("xallexcepts-", sminus, "")) {
|
||||
m_reason = string("RclConfig:: cant set value. Readonly?");
|
||||
@ -1619,6 +1637,7 @@ void RclConfig::initFrom(const RclConfig& r)
|
||||
m_xattrtofld = r.m_xattrtofld;
|
||||
m_maxsufflen = r.m_maxsufflen;
|
||||
m_skpnlist = r.m_skpnlist;
|
||||
m_stopsuffixes = r.m_stopsuffixes;
|
||||
m_defcharset = r.m_defcharset;
|
||||
m_restrictMTypes = r.m_restrictMTypes;
|
||||
m_excludeMTypes = r.m_excludeMTypes;
|
||||
|
||||
@ -213,6 +213,10 @@ class RclConfig {
|
||||
Doesn't depend on the keydir */
|
||||
vector<string> getDaemSkippedPaths() const;
|
||||
|
||||
/** Return list of no content suffixes. Used by confgui, indexing uses
|
||||
inStopSuffixes() for testing suffixes */
|
||||
std::vector<std::string>& getStopSuffixes();
|
||||
|
||||
/**
|
||||
* mimemap: Check if file name should be ignored because of suffix
|
||||
*
|
||||
@ -247,6 +251,13 @@ class RclConfig {
|
||||
static bool valueSplitAttributes(const string& whole, string& value,
|
||||
ConfSimple& attrs) ;
|
||||
|
||||
/** Compute difference between 'base' and 'changed', as elements to be
|
||||
* added and substracted from base. Input and output strings are in
|
||||
* stringToStrings() format. */
|
||||
static void setPlusMinus(
|
||||
const std::string& base, const std::set<std::string>& changed,
|
||||
std::string& plus, std::string& minus);
|
||||
|
||||
/** Return the locale's character set */
|
||||
static const std::string& getLocaleCharset();
|
||||
|
||||
@ -369,6 +380,7 @@ class RclConfig {
|
||||
unsigned int m_maxsufflen;
|
||||
ParamStale m_oldstpsuffstate; // Values from user mimemap, now obsolete
|
||||
ParamStale m_stpsuffstate;
|
||||
vector<string> m_stopsuffvec;
|
||||
|
||||
ParamStale m_skpnstate;
|
||||
vector<string> m_skpnlist;
|
||||
|
||||
@ -29,7 +29,11 @@
|
||||
#include <QListWidget>
|
||||
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <string>
|
||||
using std::list;
|
||||
using std::set;
|
||||
using std::string;
|
||||
|
||||
#include "confgui.h"
|
||||
#include "recoll.h"
|
||||
@ -37,7 +41,6 @@ using std::list;
|
||||
#include "smallut.h"
|
||||
#include "log.h"
|
||||
#include "rcldb.h"
|
||||
#include "conflinkrcl.h"
|
||||
#include "execmd.h"
|
||||
#include "rclconfig.h"
|
||||
|
||||
@ -45,6 +48,110 @@ namespace confgui {
|
||||
static const int spacing = 3;
|
||||
static const int margin = 3;
|
||||
|
||||
/**
|
||||
* A Gui-to-Data link class for ConfTree
|
||||
* Has a subkey pointer member which makes it easy to change the
|
||||
* current subkey for a number at a time.
|
||||
*/
|
||||
class ConfLinkRclRep : public ConfLinkRep {
|
||||
public:
|
||||
ConfLinkRclRep(ConfNull *conf, const string& nm,
|
||||
string *sk = 0)
|
||||
: m_conf(conf), m_nm(nm), m_sk(sk) /* KEEP THE POINTER, shared data */
|
||||
{
|
||||
}
|
||||
virtual ~ConfLinkRclRep() {}
|
||||
|
||||
virtual bool set(const string& val)
|
||||
{
|
||||
if (!m_conf)
|
||||
return false;
|
||||
LOGDEB1("Setting [" << m_nm << "] value to [" << val << "]\n");
|
||||
bool ret = m_conf->set(m_nm, val, getSk());
|
||||
if (!ret)
|
||||
LOGERR("Value set failed\n" );
|
||||
return ret;
|
||||
}
|
||||
virtual bool get(string& val)
|
||||
{
|
||||
if (!m_conf)
|
||||
return false;
|
||||
bool ret = m_conf->get(m_nm, val, getSk());
|
||||
LOGDEB1("ConfLinkRcl::get: [" << m_nm << "] sk [" <<
|
||||
getSk() << "] -> [" << (ret ? val : "no value") << "]\n" );
|
||||
return ret;
|
||||
}
|
||||
private:
|
||||
string getSk() {
|
||||
return m_sk ? *m_sk : string();
|
||||
}
|
||||
ConfNull *m_conf;
|
||||
const string m_nm;
|
||||
const string *m_sk;
|
||||
};
|
||||
|
||||
|
||||
typedef std::function<vector<string>()> RclConfVecValueGetter;
|
||||
|
||||
/* Special link for skippedNames and noContentSuffixes which are
|
||||
computed as set differences */
|
||||
class ConfLinkPlusMinus : public ConfLinkRep {
|
||||
public:
|
||||
ConfLinkPlusMinus(RclConfig *rclconf, ConfNull *conf,
|
||||
const string& basename, RclConfVecValueGetter getter,
|
||||
string *sk = 0)
|
||||
: m_rclconf(rclconf), m_conf(conf),
|
||||
m_basename(basename), m_getter(getter),
|
||||
m_sk(sk) /* KEEP THE POINTER, shared data */
|
||||
{
|
||||
}
|
||||
virtual ~ConfLinkPlusMinus() {}
|
||||
|
||||
virtual bool set(const string& snval) {
|
||||
if (!m_conf || !m_rclconf)
|
||||
return false;
|
||||
|
||||
string sbase;
|
||||
m_conf->get(m_basename, sbase, getSk());
|
||||
std::set<string> nval;
|
||||
stringToStrings(snval, nval);
|
||||
string splus, sminus;
|
||||
RclConfig::setPlusMinus(sbase, nval, splus, sminus);
|
||||
LOGDEB1("ConfLinkPlusMinus: base [" << sbase << "] nvalue [" << snval <<
|
||||
"] splus [" << splus << "] sminus [" << sminus << "]\n");
|
||||
if (!m_conf->set(m_basename + "-", sminus, getSk())) {
|
||||
return false;
|
||||
}
|
||||
if (!m_conf->set(m_basename + "+", splus, getSk())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool get(string& val) {
|
||||
if (!m_conf || !m_rclconf)
|
||||
return false;
|
||||
|
||||
m_rclconf->setKeyDir(getSk());
|
||||
vector<string> vval = m_getter();
|
||||
val = stringsToString(vval);
|
||||
LOGDEB1("ConfLinkPlusMinus: "<<m_basename<<" -> " << val <<std::endl);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
string getSk() {
|
||||
return m_sk ? *m_sk : string();
|
||||
}
|
||||
|
||||
RclConfig *m_rclconf;
|
||||
ConfNull *m_conf;
|
||||
string m_basename;
|
||||
RclConfVecValueGetter m_getter;
|
||||
const string *m_sk;
|
||||
};
|
||||
|
||||
|
||||
ConfIndexW::ConfIndexW(QWidget *parent, RclConfig *config)
|
||||
: QDialog(parent), m_rclconf(config)
|
||||
{
|
||||
@ -429,7 +536,9 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
|
||||
|
||||
ConfParamSLW *eskn = new ConfParamSLW(
|
||||
m_groupbox,
|
||||
ConfLink(new ConfLinkRclRep(config, "skippedNames", &m_sk)),
|
||||
ConfLink(new ConfLinkPlusMinus(
|
||||
rclconf, config, "skippedNames",
|
||||
std::bind(&RclConfig::getSkippedNames, rclconf), &m_sk)),
|
||||
QObject::tr("Skipped names"),
|
||||
QObject::tr("These are patterns for file or directory "
|
||||
" names which should not be indexed."));
|
||||
@ -463,7 +572,9 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
|
||||
|
||||
ConfParamSLW *encs = new ConfParamSLW(
|
||||
m_groupbox,
|
||||
ConfLink(new ConfLinkRclRep(config, "noContentSuffixes", &m_sk)),
|
||||
ConfLink(new ConfLinkPlusMinus(
|
||||
rclconf, config, "noContentSuffixes",
|
||||
std::bind(&RclConfig::getStopSuffixes, rclconf), &m_sk)),
|
||||
QObject::tr("Ignored endings"),
|
||||
QObject::tr("These are file name endings for files which will be "
|
||||
"indexed by name only \n(no MIME type identification "
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user