Switch to unified view

a/src/common/rclconfig.h b/src/common/rclconfig.h
1
#ifndef _RCLCONFIG_H_INCLUDED_
1
#ifndef _RCLCONFIG_H_INCLUDED_
2
#define _RCLCONFIG_H_INCLUDED_
2
#define _RCLCONFIG_H_INCLUDED_
3
/* @(#$Id: rclconfig.h,v 1.3 2004-12-17 13:01:01 dockes Exp $  (C) 2004 J.F.Dockes */
3
/* @(#$Id: rclconfig.h,v 1.4 2005-02-04 09:39:44 dockes Exp $  (C) 2004 J.F.Dockes */
4
4
5
#include "conftree.h"
5
#include "conftree.h"
6
6
7
class RclConfig {
7
class RclConfig {
8
    int m_ok;
8
    int m_ok;
9
    string confdir; // Directory where the files are stored
9
    string   confdir; // Directory where the files are stored
10
    ConfTree *conf; // Parsed main configuration
10
    ConfTree *conf;   // Parsed main configuration
11
    string keydir;  // Current directory used for parameter fetches.
11
    string keydir;    // Current directory used for parameter fetches.
12
    // Note: this will have to change if/when we support per directory maps
12
    
13
    ConfTree *mimemap;
13
    ConfTree *mimemap;  // These are independant of current keydir. We might
14
    ConfTree *mimeconf;
14
    ConfTree *mimeconf; // want to change it one day.
15
16
    // Parameters auto-fetched on setkeydir
17
    string defcharset;   // These are stored locally to avoid 
18
    string deflang;      // a config lookup each time.
19
    bool   guesscharset; // They are fetched initially or on setKeydir()
20
15
 public:
21
 public:
16
    // Let some parameters be accessed directly
17
    string defcharset; // These are stored locally to avoid a config lookup
18
    string deflang;    // each time.
19
    bool   guesscharset;
20
22
21
    RclConfig();
23
    RclConfig();
22
    ~RclConfig() {delete conf;delete mimemap;delete mimeconf;}
24
    ~RclConfig() {delete conf;delete mimemap;delete mimeconf;}
25
23
    bool ok() {return m_ok;}
26
    bool ok() {return m_ok;}
27
28
    string getConfDir() {return confdir;}
24
    ConfTree *getConfig() {return m_ok ? conf : 0;}
29
    ConfTree *getConfig() {return m_ok ? conf : 0;}
25
    ConfTree *getMimeMap() {return m_ok ? mimemap : 0;}
30
26
    ConfTree *getMimeConf() {return m_ok ? mimeconf : 0;}
31
    /// Get generic configuration parameter according to current keydir
32
    bool getConfParam(const string &name, string &value) 
33
    {
34
  if (conf == 0)
35
      return false;
36
  return conf->get(name, value, keydir);
37
    }
38
    /// Set current directory reference, and fetch automatic parameters.
27
    void setKeyDir(const string &dir) 
39
    void setKeyDir(const string &dir) 
28
    {
40
    {
29
    keydir = dir;
41
    keydir = dir;
30
    conf->get("defaultcharset", defcharset, keydir);
42
    conf->get("defaultcharset", defcharset, keydir);
31
    conf->get("defaultlanguage", deflang, keydir);
43
    conf->get("defaultlanguage", deflang, keydir);
32
    string str;
44
    string str;
33
    conf->get("guesscharset", str, keydir);
45
    conf->get("guesscharset", str, keydir);
34
    guesscharset = ConfTree::stringToBool(str);
46
    guesscharset = ConfTree::stringToBool(str);
35
    }
47
    }
36
    bool getConfParam(const string &name, string &value) 
48
    ConfTree *getMimeMap() {return m_ok ? mimemap : 0;}
37
    {
49
    ConfTree *getMimeConf() {return m_ok ? mimeconf : 0;}
38
  if (conf == 0)
39
      return false;
40
  return conf->get(name, value, keydir);
41
    }
42
    const string &getDefCharset() {
50
    const string &getDefCharset() {return defcharset;}
43
  return defcharset;
44
    }
45
    const string &getDefLang() {
51
    const string &getDefLang() {return deflang;}
46
  return deflang;
52
    bool getGuessCharset() {return guesscharset;}
47
    }
48
};
53
};
49
54
55
std::string find_filter(RclConfig *conf, const string& cmd);
50
56
51
#endif /* _RCLCONFIG_H_INCLUDED_ */
57
#endif /* _RCLCONFIG_H_INCLUDED_ */