diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index 6366a1cf..c7d7a31b 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -1,7 +1,8 @@ #ifndef lint -static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.10 2005-11-05 14:40:50 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.11 2005-11-17 12:47:03 dockes Exp $ (C) 2004 J.F.Dockes"; #endif #include +#include #include @@ -80,6 +81,29 @@ RclConfig::RclConfig() return; } +bool RclConfig::getConfParam(const std::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 std::string &name, bool *value) +{ + int ival; + if (!getConfParam(name, &ival)) + return false; + if (*value) + *value = ival ? true : false; + return true; +} + static ConfSimple::WalkerCode mtypesWalker(void *l, const char *nm, const char *value) { diff --git a/src/common/rclconfig.h b/src/common/rclconfig.h index 570fa9cb..27d3abb9 100644 --- a/src/common/rclconfig.h +++ b/src/common/rclconfig.h @@ -1,6 +1,6 @@ #ifndef _RCLCONFIG_H_INCLUDED_ #define _RCLCONFIG_H_INCLUDED_ -/* @(#$Id: rclconfig.h,v 1.6 2005-11-05 14:40:50 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: rclconfig.h,v 1.7 2005-11-17 12:47:03 dockes Exp $ (C) 2004 J.F.Dockes */ #include @@ -38,6 +38,13 @@ class RclConfig { return false; return conf->get(name, value, keydir); } + + /* + * Variants with autoconversion + */ + bool getConfParam(const std::string &name, int *value); + bool getConfParam(const std::string &name, bool *value); + /// Set current directory reference, and fetch automatic parameters. void setKeyDir(const string &dir) { diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index 60482f63..fd3de3b2 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: main.cpp,v 1.15 2005-11-16 15:07:20 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: main.cpp,v 1.16 2005-11-17 12:47:03 dockes Exp $ (C) 2005 J.F.Dockes"; #endif #include @@ -160,11 +160,8 @@ int main( int argc, char ** argv ) exit(1); } - string tmp; - rclconfig->getConfParam("showicons", tmp); - if (tmp.empty()) - tmp = "0"; - showicons = atoi(tmp.c_str()) ? true : false; + showicons = false; + rclconfig->getConfParam("showicons", &showicons); rclconfig->getConfParam("iconsdir", iconsdir); if (iconsdir.empty()) iconsdir = "/usr/local/share/recoll/images"; diff --git a/src/qtgui/recollmain.ui b/src/qtgui/recollmain.ui index 63e64617..7f898fe3 100644 --- a/src/qtgui/recollmain.ui +++ b/src/qtgui/recollmain.ui @@ -206,7 +206,7 @@ E&xit - + Ctrl+Q diff --git a/src/sampleconf/recoll.conf b/src/sampleconf/recoll.conf index bb7a1c02..e0181fe2 100644 --- a/src/sampleconf/recoll.conf +++ b/src/sampleconf/recoll.conf @@ -1,4 +1,4 @@ -# @(#$Id: recoll.conf,v 1.7 2005-11-16 15:07:20 dockes Exp $ (C) 2004 J.F.Dockes +# @(#$Id: recoll.conf,v 1.8 2005-11-17 12:47:03 dockes Exp $ (C) 2004 J.F.Dockes # Recoll default configuration file. This should be copied to # ~/.recoll/recoll.conf @@ -52,8 +52,7 @@ guesscharset = 0 # indexation of many bogus 'text' files usesystemfilecommand = 1 -# You could specify different parameters for a subdirectory like this. No -# tilde substitution there for now, sorry: -#[/home/me/englishdocs/plain] +# You could specify different parameters for a subdirectory like this. +#[~/englishdocs/plain] #defaultcharset = iso-8859-2 diff --git a/src/utils/conftree.cpp b/src/utils/conftree.cpp index 5e842a93..ef83aa06 100755 --- a/src/utils/conftree.cpp +++ b/src/utils/conftree.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid [] = "@(#$Id: conftree.cpp,v 1.1 2005-11-12 14:24:33 dockes Exp $ (C) 2003 J.F.Dockes"; +static char rcsid [] = "@(#$Id: conftree.cpp,v 1.2 2005-11-17 12:47:03 dockes Exp $ (C) 2003 J.F.Dockes"; #endif #ifdef HAVE_CONFIG_H #include "config.h" @@ -14,6 +14,7 @@ static char rcsid [] = "@(#$Id: conftree.cpp,v 1.1 2005-11-12 14:24:33 dockes Ex #include #include "conftree.h" +#include "pathut.h" #ifndef NO_NAMESPACES using namespace std; @@ -48,11 +49,10 @@ void ConfSimple::parseinput(istream &input) for (;;) { input.getline(cline, LL-1); - //fprintf(stderr, "Line: '%s'\n", cline); + // fprintf(stderr, "Line: '%s' status %d\n", cline, int(status)); if (!input.good()) { if (input.bad()) { status = STATUS_ERROR; - //fprintf(stderr, "ConfSimple:parseinput: fatal error\n"); return; } // Must be eof ? @@ -84,7 +84,10 @@ void ConfSimple::parseinput(istream &input) if (line[0] == '[') { trimstring(line, "[]"); - submapkey = line; + if (dotildexpand) + submapkey = path_tildexpand(line); + else + submapkey = line; continue; } @@ -118,25 +121,28 @@ void ConfSimple::parseinput(istream &input) } } -ConfSimple::ConfSimple(string *d, int readonly) + +ConfSimple::ConfSimple(string *d, int readonly, bool tildexp) { - filename = ""; data = d; + dotildexpand = tildexp; status = readonly ? STATUS_RO : STATUS_RW; stringstream input(*d, ios::in); parseinput(input); } -ConfSimple::ConfSimple(const char *fname, int readonly) + +ConfSimple::ConfSimple(const char *fname, int readonly, bool tildexp) { - filename = string(fname); data = 0; + filename = string(fname); + dotildexpand = tildexp; + status = readonly ? STATUS_RO : STATUS_RW; ifstream input; if (readonly) { input.open(fname, ios::in); - status = STATUS_RO; } else { ios::openmode mode = ios::in|ios::out; // It seems that there is no separate 'create if not exists' @@ -331,11 +337,6 @@ list ConfSimple::getKeys() return mylist; } -static inline void path_catslash(std::string &s) { - if (s.empty() || s[s.length() - 1] != '/') - s += '/'; -} - int ConfTree::get(const std::string &name, string &value, const string &sk) { if (sk.empty() || sk[0] != '/') { @@ -653,7 +654,7 @@ int main(int argc, char **argv) } } else { - ConfSimple parms(filename, 1); + ConfTree parms(filename, 1); if (parms.getStatus() == ConfSimple::STATUS_ERROR) { fprintf(stderr, "Open failed\n"); exit(1); diff --git a/src/utils/conftree.h b/src/utils/conftree.h index 49d403ba..09e8604f 100755 --- a/src/utils/conftree.h +++ b/src/utils/conftree.h @@ -37,23 +37,22 @@ using std::map; class ConfSimple { public: enum StatusCode {STATUS_ERROR=0, STATUS_RO=1, STATUS_RW=2}; - private: - string filename; // set if we're working with a file - string *data; // set if we're working with an in-memory string - map > submaps; - StatusCode status; - void parseinput(std::istream &input); - public: /** * Build the object by reading content from file. + * @param filename file to open + * @param readonly if true open readonly, else rw + * @param tildexp try tilde (home dir) expansion for subkey values */ - ConfSimple(const char *fname, int readonly = 0); + ConfSimple(const char *fname, int readonly = 0, bool tildexp = false); /** * Build the object by reading content from a string + * @param data points to the data to parse + * @param readonly if true open readonly, else rw + * @param tildexp try tilde (home dir) expansion for subsection names */ - ConfSimple(string *data, int readonly = 0); + ConfSimple(string *data, int readonly = 0, bool tildexp = false); virtual ~ConfSimple() {}; @@ -98,6 +97,15 @@ class ConfSimple { * Return all key names: */ std::list getKeys(); + + protected: + bool dotildexpand; + private: + string filename; // set if we're working with a file + string *data; // set if we're working with an in-memory string + map > submaps; + StatusCode status; + void parseinput(std::istream &input); }; /** @@ -124,7 +132,7 @@ class ConfTree : public ConfSimple { * Build the object by reading content from file. */ ConfTree(const char *fname, int readonly = 0) - : ConfSimple(fname, readonly) {} + : ConfSimple(fname, readonly, true) {} virtual ~ConfTree() {}; /** @@ -147,5 +155,4 @@ class ConfTree : public ConfSimple { static bool stringToBool(const string &s); }; - #endif /*_CONFTREE_H_ */