Switch to side-by-side view

--- a/src/common/rclconfig.cpp
+++ b/src/common/rclconfig.cpp
@@ -98,13 +98,15 @@
     m_rmtstate.init(this, 0, "indexedmimetypes");
 }
 
-bool RclConfig::isDefaultConfig()
+bool RclConfig::isDefaultConfig() const
 {
     string defaultconf = path_cat(path_canon(path_home()), ".recoll/");
     string specifiedconf = path_canon(m_confdir);
     path_catslash(specifiedconf);
     return !defaultconf.compare(specifiedconf);
 }
+
+string RclConfig::o_localecharset; 
 
 RclConfig::RclConfig(const string *argcnf)
 {
@@ -157,207 +159,13 @@
 	    return;
     }
 
-    m_cdirs.push_back(m_confdir);
-    m_cdirs.push_back(path_cat(m_datadir, "examples"));
-    string cnferrloc = m_confdir + " or " + path_cat(m_datadir, "examples");
-
-    // Read and process "recoll.conf"
-    if (!updateMainConfig())
-	return;
-    // Other files
-    mimemap = new ConfStack<ConfTree>("mimemap", m_cdirs, true);
-    if (mimemap == 0 || !mimemap->ok()) {
-	m_reason = string("No or bad mimemap file in: ") + cnferrloc;
-	return;
-    }
-    mimeconf = new ConfStack<ConfSimple>("mimeconf", m_cdirs, true);
-    if (mimeconf == 0 || !mimeconf->ok()) {
-	m_reason = string("No/bad mimeconf in: ") + cnferrloc;
-	return;
-    }
-    mimeview = new ConfStack<ConfSimple>("mimeview", m_cdirs, false);
-    if (mimeview == 0)
-	mimeview = new ConfStack<ConfSimple>("mimeview", m_cdirs, true);
-    if (mimeview == 0 || !mimeview->ok()) {
-	m_reason = string("No/bad mimeview in: ") + cnferrloc;
-	return;
-    }
-    if (!readFieldsConfig(cnferrloc))
-	return;
-
-    m_ok = true;
-    setKeyDir(cstr_null);
-
-    m_stpsuffstate.init(this, mimemap, "recoll_noindex");
-    m_skpnstate.init(this, m_conf, "skippedNames");
-    m_rmtstate.init(this, m_conf, "indexedmimetypes");
-    return;
-}
-
-bool RclConfig::updateMainConfig()
-{
-    ConfStack<ConfTree> *newconf = 
-	new ConfStack<ConfTree>("recoll.conf", m_cdirs, true);
-    if (newconf == 0 || !newconf->ok()) {
-	if (m_conf)
-	    return false;
-	string where;
-	stringsToString(m_cdirs, where);
-	m_reason = string("No/bad main configuration file in: ") + where;
-	m_ok = false;
-        m_skpnstate.init(this, 0, "skippedNames");
-        m_rmtstate.init(this, 0, "indexedmimetypes");
-	return false;
-    }
-    delete m_conf;
-    m_conf = newconf;
-    m_skpnstate.init(this, m_conf, "skippedNames");
-    m_rmtstate.init(this, m_conf, "indexedmimetypes");
-
-
-    setKeyDir(cstr_null);
-    bool nocjk = false;
-    if (getConfParam("nocjk", &nocjk) && nocjk == true) {
-	TextSplit::cjkProcessing(false);
-    } else {
-	int ngramlen;
-	if (getConfParam("cjkngramlen", &ngramlen)) {
-	    TextSplit::cjkProcessing(true, (unsigned int)ngramlen);
-	} else {
-	    TextSplit::cjkProcessing(true);
-	}
-    }
-
-    bool nonum = false;
-    if (getConfParam("nonumbers", &nonum) && nonum == true) {
-	TextSplit::noNumbers();
-    }
-
-    bool fnmpathname = true;
-    if (getConfParam("skippedPathsFnmPathname", &fnmpathname)
-	&& fnmpathname == false) {
-	FsTreeWalker::setNoFnmPathname();
-    }
-
-#ifndef RCL_INDEX_STRIPCHARS
-    static int m_index_stripchars_init = 0;
-    if (!m_index_stripchars_init) {
-	getConfParam("indexStripChars", &o_index_stripchars);
-	m_index_stripchars_init = 1;
-    }
-#endif
-
-    return true;
-}
-
-ConfNull *RclConfig::cloneMainConfig()
-{
-    ConfNull *conf = new ConfStack<ConfTree>("recoll.conf", m_cdirs, false);
-    if (conf == 0 || !conf->ok()) {
-	m_reason = string("Can't read config");
-	return 0;
-    }
-    return conf;
-}
-
-// Remember what directory we're under (for further conf->get()s), and 
-// prefetch a few common values.
-void RclConfig::setKeyDir(const string &dir) 
-{
-    if (!dir.compare(m_keydir))
-        return;
-
-    m_keydirgen++;
-    m_keydir = dir;
-    if (m_conf == 0)
-	return;
-
-    if (!m_conf->get("defaultcharset", defcharset, m_keydir))
-	defcharset.erase();
-}
-
-bool RclConfig::getConfParam(const string &name, int *ivp)
-{
-    string value;
-    if (!getConfParam(name, value))
-	return false;
-    errno = 0;
-    long lval = strtol(value.c_str(), 0, 0);
-    if (lval == 0 && errno)
-	return 0;
-    if (ivp)
-	*ivp = int(lval);
-    return true;
-}
-
-bool RclConfig::getConfParam(const string &name, bool *bvp)
-{
-    if (!bvp) 
-	return false;
-
-    *bvp = false;
-    string s;
-    if (!getConfParam(name, s))
-	return false;
-    *bvp = stringToBool(s);
-    return true;
-}
-
-bool RclConfig::getConfParam(const string &name, vector<string> *svvp)
-{
-    if (!svvp) 
-	return false;
-    svvp->clear();
-    string s;
-    if (!getConfParam(name, s))
-	return false;
-    return stringToStrings(s, *svvp);
-}
-bool RclConfig::getConfParam(const string &name, list<string> *svvp)
-{
-    if (!svvp) 
-	return false;
-    svvp->clear();
-    string s;
-    if (!getConfParam(name, s))
-	return false;
-    return stringToStrings(s, *svvp);
-}
-
-list<string> RclConfig::getTopdirs()
-{
-    list<string> tdl;
-    if (!getConfParam("topdirs", &tdl)) {
-	LOGERR(("RclConfig::getTopdirs: no top directories in config or bad list format\n"));
-	return tdl;
-    }
-
-    for (list<string>::iterator it = tdl.begin(); it != tdl.end(); it++) {
-	*it = path_tildexpand(*it);
-	*it = path_canon(*it);
-    }
-    return tdl;
-}
-
-// Get charset to be used for transcoding to utf-8 if unspecified by doc
-// For document contents:
-//  If defcharset was set (from the config or a previous call, this
-//   is done in setKeydir), use it.
-//  Else, try to guess it from the locale
-//  Use cp1252 (as a superset of iso8859-1) as ultimate default
-//
-// For filenames, same thing except that we do not use the config file value
-// (only the locale).
-const string& RclConfig::getDefCharset(bool filename) 
-{
     // This can't change once computed inside a process. It would be
     // nicer to move this to a static class initializer to avoid
     // possible threading issues but this doesn't work (tried) as
     // things would not be ready. In practise we make sure that this
-    // is called from the main thread at once, by calling
-    // getDefCharset from recollinit
-    static string localecharset; 
-    if (localecharset.empty()) {
+    // is called from the main thread at once, by constructing a config
+    // from recollinit
+    if (o_localecharset.empty()) {
 	const char *cp;
 	cp = nl_langinfo(CODESET);
 	// We don't keep US-ASCII. It's better to use a superset
@@ -370,27 +178,216 @@
 	    && strcmp(cp, "646")
 #endif
 	    ) {
-	    localecharset = string(cp);
+	    o_localecharset = string(cp);
 	} else {
 	    // Use cp1252 instead of iso-8859-1, it's a superset.
-	    localecharset = string(cstr_cp1252);
+	    o_localecharset = string(cstr_cp1252);
 	}
 	LOGDEB1(("RclConfig::getDefCharset: localecharset [%s]\n",
-		localecharset.c_str()));
-    }
-
-    if (defcharset.empty()) {
-	defcharset = localecharset;
-    }
-
+		 o_localecharset.c_str()));
+    }
+
+    m_cdirs.push_back(m_confdir);
+    m_cdirs.push_back(path_cat(m_datadir, "examples"));
+    string cnferrloc = m_confdir + " or " + path_cat(m_datadir, "examples");
+
+    // Read and process "recoll.conf"
+    if (!updateMainConfig())
+	return;
+    // Other files
+    mimemap = new ConfStack<ConfTree>("mimemap", m_cdirs, true);
+    if (mimemap == 0 || !mimemap->ok()) {
+	m_reason = string("No or bad mimemap file in: ") + cnferrloc;
+	return;
+    }
+    mimeconf = new ConfStack<ConfSimple>("mimeconf", m_cdirs, true);
+    if (mimeconf == 0 || !mimeconf->ok()) {
+	m_reason = string("No/bad mimeconf in: ") + cnferrloc;
+	return;
+    }
+    mimeview = new ConfStack<ConfSimple>("mimeview", m_cdirs, false);
+    if (mimeview == 0)
+	mimeview = new ConfStack<ConfSimple>("mimeview", m_cdirs, true);
+    if (mimeview == 0 || !mimeview->ok()) {
+	m_reason = string("No/bad mimeview in: ") + cnferrloc;
+	return;
+    }
+    if (!readFieldsConfig(cnferrloc))
+	return;
+
+    m_ok = true;
+    setKeyDir(cstr_null);
+
+    m_stpsuffstate.init(this, mimemap, "recoll_noindex");
+    m_skpnstate.init(this, m_conf, "skippedNames");
+    m_rmtstate.init(this, m_conf, "indexedmimetypes");
+    return;
+}
+
+bool RclConfig::updateMainConfig()
+{
+    ConfStack<ConfTree> *newconf = 
+	new ConfStack<ConfTree>("recoll.conf", m_cdirs, true);
+    if (newconf == 0 || !newconf->ok()) {
+	if (m_conf)
+	    return false;
+	string where;
+	stringsToString(m_cdirs, where);
+	m_reason = string("No/bad main configuration file in: ") + where;
+	m_ok = false;
+        m_skpnstate.init(this, 0, "skippedNames");
+        m_rmtstate.init(this, 0, "indexedmimetypes");
+	return false;
+    }
+    delete m_conf;
+    m_conf = newconf;
+    m_skpnstate.init(this, m_conf, "skippedNames");
+    m_rmtstate.init(this, m_conf, "indexedmimetypes");
+
+
+    setKeyDir(cstr_null);
+    bool nocjk = false;
+    if (getConfParam("nocjk", &nocjk) && nocjk == true) {
+	TextSplit::cjkProcessing(false);
+    } else {
+	int ngramlen;
+	if (getConfParam("cjkngramlen", &ngramlen)) {
+	    TextSplit::cjkProcessing(true, (unsigned int)ngramlen);
+	} else {
+	    TextSplit::cjkProcessing(true);
+	}
+    }
+
+    bool nonum = false;
+    if (getConfParam("nonumbers", &nonum) && nonum == true) {
+	TextSplit::noNumbers();
+    }
+
+    bool fnmpathname = true;
+    if (getConfParam("skippedPathsFnmPathname", &fnmpathname)
+	&& fnmpathname == false) {
+	FsTreeWalker::setNoFnmPathname();
+    }
+
+#ifndef RCL_INDEX_STRIPCHARS
+    static int m_index_stripchars_init = 0;
+    if (!m_index_stripchars_init) {
+	getConfParam("indexStripChars", &o_index_stripchars);
+	m_index_stripchars_init = 1;
+    }
+#endif
+
+    return true;
+}
+
+ConfNull *RclConfig::cloneMainConfig()
+{
+    ConfNull *conf = new ConfStack<ConfTree>("recoll.conf", m_cdirs, false);
+    if (conf == 0 || !conf->ok()) {
+	m_reason = string("Can't read config");
+	return 0;
+    }
+    return conf;
+}
+
+// Remember what directory we're under (for further conf->get()s), and 
+// prefetch a few common values.
+void RclConfig::setKeyDir(const string &dir) 
+{
+    if (!dir.compare(m_keydir))
+        return;
+
+    m_keydirgen++;
+    m_keydir = dir;
+    if (m_conf == 0)
+	return;
+
+    if (!m_conf->get("defaultcharset", m_defcharset, m_keydir))
+	m_defcharset.erase();
+}
+
+bool RclConfig::getConfParam(const string &name, int *ivp) const
+{
+    string value;
+    if (!getConfParam(name, value))
+	return false;
+    errno = 0;
+    long lval = strtol(value.c_str(), 0, 0);
+    if (lval == 0 && errno)
+	return 0;
+    if (ivp)
+	*ivp = int(lval);
+    return true;
+}
+
+bool RclConfig::getConfParam(const string &name, bool *bvp) const
+{
+    if (!bvp) 
+	return false;
+
+    *bvp = false;
+    string s;
+    if (!getConfParam(name, s))
+	return false;
+    *bvp = stringToBool(s);
+    return true;
+}
+
+bool RclConfig::getConfParam(const string &name, vector<string> *svvp) const
+{
+    if (!svvp) 
+	return false;
+    svvp->clear();
+    string s;
+    if (!getConfParam(name, s))
+	return false;
+    return stringToStrings(s, *svvp);
+}
+bool RclConfig::getConfParam(const string &name, list<string> *svvp) const
+{
+    if (!svvp) 
+	return false;
+    svvp->clear();
+    string s;
+    if (!getConfParam(name, s))
+	return false;
+    return stringToStrings(s, *svvp);
+}
+
+list<string> RclConfig::getTopdirs() const
+{
+    list<string> tdl;
+    if (!getConfParam("topdirs", &tdl)) {
+	LOGERR(("RclConfig::getTopdirs: no top directories in config or bad list format\n"));
+	return tdl;
+    }
+
+    for (list<string>::iterator it = tdl.begin(); it != tdl.end(); it++) {
+	*it = path_tildexpand(*it);
+	*it = path_canon(*it);
+    }
+    return tdl;
+}
+
+// Get charset to be used for transcoding to utf-8 if unspecified by doc
+// For document contents:
+//  If defcharset was set (from the config or a previous call, this
+//   is done in setKeydir), use it.
+//  Else, try to guess it from the locale
+//  Use cp1252 (as a superset of iso8859-1) as ultimate default
+//
+// For filenames, same thing except that we do not use the config file value
+// (only the locale).
+const string& RclConfig::getDefCharset(bool filename) const
+{
     if (filename) {
-	return localecharset;
+	return o_localecharset;
     } else {
-	return defcharset;
-    }
-}
-
-bool RclConfig::addLocalFields(map<string, string> *tgt)
+	return m_defcharset.empty() ? o_localecharset : m_defcharset;
+    }
+}
+
+bool RclConfig::addLocalFields(map<string, string> *tgt) const
 {
     LOGDEB0(("RclConfig::addLocalFields: keydir [%s]\n", m_keydir.c_str()));
     string sfields;
@@ -421,7 +418,7 @@
 //
 // This unfortunately means that searches by file names and mime type
 // filtering don't work well together.
-vector<string> RclConfig::getAllMimeTypes()
+vector<string> RclConfig::getAllMimeTypes() const
 {
     vector<string> lst;
     if (mimeconf == 0)
@@ -506,14 +503,14 @@
     }
 }
 
-string RclConfig::getMimeTypeFromSuffix(const string& suff)
+string RclConfig::getMimeTypeFromSuffix(const string& suff) const
 {
     string mtype;
     mimemap->get(suff, mtype, m_keydir);
     return mtype;
 }
 
-string RclConfig::getSuffixFromMimeType(const string &mt)
+string RclConfig::getSuffixFromMimeType(const string &mt) const
 {
     string suffix;
     vector<string>sfs = mimemap->getNames(cstr_null);
@@ -528,7 +525,7 @@
 }
 
 /** Get list of file categories from mimeconf */
-bool RclConfig::getMimeCategories(vector<string>& cats) 
+bool RclConfig::getMimeCategories(vector<string>& cats) const
 {
     if (!mimeconf)
 	return false;
@@ -536,7 +533,7 @@
     return true;
 }
 
-bool RclConfig::isMimeCategory(string& cat) 
+bool RclConfig::isMimeCategory(string& cat) const
 {
     vector<string>cats;
     getMimeCategories(cats);
@@ -548,7 +545,7 @@
 }
 
 /** Get list of mime types for category from mimeconf */
-bool RclConfig::getMimeCatTypes(const string& cat, vector<string>& tps)
+bool RclConfig::getMimeCatTypes(const string& cat, vector<string>& tps) const
 {
     tps.clear();
     if (!mimeconf)
@@ -581,7 +578,7 @@
     return hs;
 }
 
-bool RclConfig::getGuiFilterNames(vector<string>& cats) 
+bool RclConfig::getGuiFilterNames(vector<string>& cats) const
 {
     if (!mimeconf)
 	return false;
@@ -589,7 +586,7 @@
     return true;
 }
 
-bool RclConfig::getGuiFilter(const string& catfiltername, string& frag)
+bool RclConfig::getGuiFilter(const string& catfiltername, string& frag) const
 {
     frag.clear();
     if (!mimeconf)
@@ -623,7 +620,7 @@
 }
 
 
-string RclConfig::getMissingHelperDesc()
+string RclConfig::getMissingHelperDesc() const
 {
     string fmiss = path_cat(getConfDir(), "missing");
     string out;
@@ -735,6 +732,7 @@
 
 // Return specifics for field name:
 bool RclConfig::getFieldTraits(const string& _fld, const FieldTraits **ftpp)
+    const
 {
     string fld = fieldCanon(_fld);
     map<string, FieldTraits>::const_iterator pit = m_fldtotraits.find(fld);
@@ -751,7 +749,7 @@
     }
 }
 
-set<string> RclConfig::getIndexedFields()
+set<string> RclConfig::getIndexedFields() const
 {
     set<string> flds;
     if (m_fields == 0)
@@ -762,7 +760,7 @@
     return flds;
 }
 
-string RclConfig::fieldCanon(const string& f)
+string RclConfig::fieldCanon(const string& f) const
 {
     string fld = stringtolower(f);
     map<string, string>::const_iterator it = m_aliastocanon.find(fld);
@@ -776,6 +774,7 @@
 }
 
 vector<string> RclConfig::getFieldSectNames(const string &sk, const char* patrn)
+    const
 {
     if (m_fields == 0)
         return vector<string>();
@@ -783,14 +782,14 @@
 }
 
 bool RclConfig::getFieldConfParam(const string &name, const string &sk, 
-                                  string &value)
+                                  string &value) const
 {
     if (m_fields == 0)
         return false;
     return m_fields->get(name, value, sk);
 }
 
-string RclConfig::getMimeViewerAllEx()
+string RclConfig::getMimeViewerAllEx() const
 {
     string hs;
     if (mimeview == 0)
@@ -807,12 +806,12 @@
 	m_reason = string("RclConfig:: cant set value. Readonly?");
 	return false;
     }
-	
+
     return true;
 }
 
 string RclConfig::getMimeViewerDef(const string &mtype, const string& apptag,
-				   bool useall)
+				   bool useall) const
 {
     LOGDEB2(("RclConfig::getMimeViewerDef: mtype [%s] apptag [%s]\n",
 	     mtype.c_str(), apptag.c_str()));
@@ -851,7 +850,7 @@
     return hs;
 }
 
-bool RclConfig::getMimeViewerDefs(vector<pair<string, string> >& defs)
+bool RclConfig::getMimeViewerDefs(vector<pair<string, string> >& defs) const
 {
     if (mimeview == 0)
 	return false;
@@ -874,7 +873,7 @@
     return true;
 }
 
-bool RclConfig::mimeViewerNeedsUncomp(const string &mimetype)
+bool RclConfig::mimeViewerNeedsUncomp(const string &mimetype) const
 {
     string s;
     vector<string> v;
@@ -886,6 +885,7 @@
 }
 
 string RclConfig::getMimeIconPath(const string &mtype, const string &apptag)
+    const
 {
     string iconname;
     if (!apptag.empty())
@@ -911,7 +911,7 @@
     return path_cat(iconpath, iconname) + ".png";
 }
 
-string RclConfig::getDbDir()
+string RclConfig::getDbDir() const
 {
     string dbdir;
     if (!getConfParam("dbdir", dbdir)) {
@@ -928,7 +928,7 @@
     return path_canon(dbdir);
 }
 
-bool RclConfig::sourceChanged()
+bool RclConfig::sourceChanged() const
 {
     if (m_conf && m_conf->sourceChanged())
 	return true;
@@ -943,18 +943,18 @@
     return false;
 }
 
-string RclConfig::getStopfile()
+string RclConfig::getStopfile() const
 {
     return path_cat(getConfDir(), "stoplist.txt");
 }
-string RclConfig::getPidfile()
+string RclConfig::getPidfile() const
 {
     return path_cat(getConfDir(), "index.pid");
 }
 
 // The index status file is fast changing, so it's possible to put it outside
 // of the config directory (for ssds, not sure this is really useful).
-string RclConfig::getIdxStatusFile()
+string RclConfig::getIdxStatusFile() const
 {
     string path;
     if (!getConfParam("idxstatusfile", path)) {
@@ -977,7 +977,7 @@
     return m_skpnlist;
 }
 
-vector<string> RclConfig::getSkippedPaths()
+vector<string> RclConfig::getSkippedPaths() const
 {
     vector<string> skpl;
     getConfParam("skippedPaths", &skpl);
@@ -997,7 +997,7 @@
     return skpl;
 }
 
-vector<string> RclConfig::getDaemSkippedPaths()
+vector<string> RclConfig::getDaemSkippedPaths() const
 {
     vector<string> dskpl;
     getConfParam("daemSkippedPaths", &dskpl);
@@ -1024,7 +1024,7 @@
 
 // Look up an executable filter.  We look in $RECOLL_FILTERSDIR,
 // filtersdir in config file, then let the system use the PATH
-string RclConfig::findFilter(const string &icmd)
+string RclConfig::findFilter(const string &icmd) const
 {
     // If the path is absolute, this is it
     if (icmd[0] == '/')
@@ -1066,7 +1066,7 @@
 /** 
  * Return decompression command line for given mime type
  */
-bool RclConfig::getUncompressor(const string &mtype, vector<string>& cmd)
+bool RclConfig::getUncompressor(const string &mtype, vector<string>& cmd) const
 {
     string hs;
 
@@ -1177,7 +1177,7 @@
     if (r.m_stopsuffixes)
 	m_stopsuffixes = new SuffixStore(*((SuffixStore*)r.m_stopsuffixes));
     m_maxsufflen = r.m_maxsufflen;
-    defcharset = r.defcharset;
+    m_defcharset = r.m_defcharset;
 
     m_stpsuffstate.init(this, mimemap, r.m_stpsuffstate.paramname);
     m_skpnstate.init(this, m_conf, r.m_skpnstate.paramname);