modified mechanism for confgui updates

This commit is contained in:
dockes 2007-10-09 09:43:10 +00:00
parent 839a463ddd
commit 0271de6d43
2 changed files with 47 additions and 41 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.52 2007-10-04 12:21:52 dockes Exp $ (C) 2004 J.F.Dockes"; static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.53 2007-10-09 09:43:10 dockes Exp $ (C) 2004 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -103,34 +103,46 @@ RclConfig::RclConfig(const string *argcnf)
return; return;
} }
list<string> cdirs; m_cdirs.push_back(m_confdir);
cdirs.push_back(m_confdir); m_cdirs.push_back(path_cat(m_datadir, "examples"));
cdirs.push_back(path_cat(m_datadir, "examples"));
string cnferrloc = m_confdir + " or " + path_cat(m_datadir, "examples"); string cnferrloc = m_confdir + " or " + path_cat(m_datadir, "examples");
m_conf = new ConfStack<ConfTree>("recoll.conf", cdirs, false); if (!updateMainConfig())
if (m_conf == 0 || !m_conf->ok()) {
m_reason = string("No/bad main configuration file in: ") + cnferrloc;
return; return;
}
mimemap = new ConfStack<ConfTree>("mimemap", cdirs, true); mimemap = new ConfStack<ConfTree>("mimemap", m_cdirs, true);
if (mimemap == 0 || !mimemap->ok()) { if (mimemap == 0 || !mimemap->ok()) {
m_reason = string("No or bad mimemap file in: ") + cnferrloc; m_reason = string("No or bad mimemap file in: ") + cnferrloc;
return; return;
} }
mimeconf = new ConfStack<ConfTree>("mimeconf", cdirs, true); mimeconf = new ConfStack<ConfTree>("mimeconf", m_cdirs, true);
if (mimeconf == 0 || !mimeconf->ok()) { if (mimeconf == 0 || !mimeconf->ok()) {
m_reason = string("No/bad mimeconf in: ") + cnferrloc; m_reason = string("No/bad mimeconf in: ") + cnferrloc;
return; return;
} }
mimeview = new ConfStack<ConfTree>("mimeview", cdirs, true); mimeview = new ConfStack<ConfTree>("mimeview", m_cdirs, true);
if (mimeconf == 0 || !mimeconf->ok()) { if (mimeconf == 0 || !mimeconf->ok()) {
m_reason = string("No/bad mimeview in: ") + cnferrloc; m_reason = string("No/bad mimeview in: ") + cnferrloc;
return; return;
} }
m_ok = true;
setKeyDir("");
return;
}
bool RclConfig::updateMainConfig()
{
LOGDEB(("RclConfig::updateMainConfig()\n"));
m_conf = new ConfStack<ConfTree>("recoll.conf", m_cdirs, true);
if (m_conf == 0 || !m_conf->ok()) {
string where;
stringsToString(m_cdirs, where);
m_reason = string("No/bad main configuration file in: ") + where;
m_ok = false;
return false;
}
setKeyDir(""); setKeyDir("");
bool nocjk = false; bool nocjk = false;
if (getConfParam("nocjk", &nocjk) && nocjk == true) { if (getConfParam("nocjk", &nocjk) && nocjk == true) {
@ -143,8 +155,17 @@ RclConfig::RclConfig(const string *argcnf)
TextSplit::cjkProcessing(true); TextSplit::cjkProcessing(true);
} }
} }
m_ok = true; return true;
return; }
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;
} }
bool RclConfig::getConfParam(const std::string &name, int *ivp) bool RclConfig::getConfParam(const std::string &name, int *ivp)

View File

@ -16,7 +16,7 @@
*/ */
#ifndef _RCLCONFIG_H_INCLUDED_ #ifndef _RCLCONFIG_H_INCLUDED_
#define _RCLCONFIG_H_INCLUDED_ #define _RCLCONFIG_H_INCLUDED_
/* @(#$Id: rclconfig.h,v 1.37 2007-10-01 06:19:21 dockes Exp $ (C) 2004 J.F.Dockes */ /* @(#$Id: rclconfig.h,v 1.38 2007-10-09 09:43:10 dockes Exp $ (C) 2004 J.F.Dockes */
#include <list> #include <list>
#include <string> #include <string>
@ -46,6 +46,13 @@ class RclConfig {
// themselves. // themselves.
static RclConfig* getMainConfig(); static RclConfig* getMainConfig();
// Return a writable clone of the main config. This belongs to the
// caller (must delete it when done)
ConfNull *cloneMainConfig();
/** (re)Read recoll.conf */
bool updateMainConfig();
bool ok() {return m_ok;} bool ok() {return m_ok;}
const string &getReason() {return m_reason;} const string &getReason() {return m_reason;}
@ -56,6 +63,8 @@ class RclConfig {
void setKeyDir(const string &dir) void setKeyDir(const string &dir)
{ {
m_keydir = dir; m_keydir = dir;
if (m_conf == 0)
return;
if (!m_conf->get("defaultcharset", defcharset, m_keydir)) if (!m_conf->get("defaultcharset", defcharset, m_keydir))
defcharset.erase(); defcharset.erase();
string str; string str;
@ -63,8 +72,6 @@ class RclConfig {
guesscharset = stringToBool(str); guesscharset = stringToBool(str);
} }
string getKeyDir() const {return m_keydir;} string getKeyDir() const {return m_keydir;}
/** Get all defined key directories in configuration */
list<string> getKeyDirs() {return m_conf->getSubKeys();}
/** Get generic configuration parameter according to current keydir */ /** Get generic configuration parameter according to current keydir */
bool getConfParam(const string &name, string &value) bool getConfParam(const string &name, string &value)
@ -73,28 +80,6 @@ class RclConfig {
return false; return false;
return m_conf->get(name, value, m_keydir); return m_conf->get(name, value, m_keydir);
} }
/** Set generic configuration parameter according to current keydir */
bool setConfParam(const string &name, const string &value)
{
if (m_conf == 0)
return false;
return m_conf->set(name, value, m_keydir);
}
/** Remove parameter from configuration */
bool eraseConfParam(const string &name)
{
if (m_conf == 0)
return false;
return m_conf->erase(name, m_keydir);
}
/** Remove parameter from configuration */
bool eraseKeyDir()
{
if (m_conf == 0)
return false;
return m_conf->eraseKey(m_keydir);
}
/** Variant with autoconversion to int */ /** Variant with autoconversion to int */
bool getConfParam(const std::string &name, int *value); bool getConfParam(const std::string &name, int *value);
/** Variant with autoconversion to bool */ /** Variant with autoconversion to bool */
@ -197,9 +182,10 @@ class RclConfig {
private: private:
int m_ok; int m_ok;
string m_reason; // Explanation for bad state string m_reason; // Explanation for bad state
string m_confdir; // Directory where the files are stored string m_confdir; // User directory where the customized files are stored
string m_datadir; // Example: /usr/local/share/recoll string m_datadir; // Example: /usr/local/share/recoll
string m_keydir; // Current directory used for parameter fetches. string m_keydir; // Current directory used for parameter fetches.
list<string> m_cdirs; // directory stack for the confstacks
ConfStack<ConfTree> *m_conf; // Parsed configuration files ConfStack<ConfTree> *m_conf; // Parsed configuration files
ConfStack<ConfTree> *mimemap; // The files don't change with keydir, ConfStack<ConfTree> *mimemap; // The files don't change with keydir,
@ -215,7 +201,6 @@ class RclConfig {
/** Create initial user configuration */ /** Create initial user configuration */
bool initUserConfig(); bool initUserConfig();
/** Copy from other */ /** Copy from other */
void initFrom(const RclConfig& r); void initFrom(const RclConfig& r);
/** Init pointers to 0 */ /** Init pointers to 0 */