|
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.12 2006-01-19 17:11:46 dockes Exp $ (C) 2004 J.F.Dockes */
|
3 |
/* @(#$Id: rclconfig.h,v 1.13 2006-01-20 10:01:59 dockes Exp $ (C) 2004 J.F.Dockes */
|
4 |
|
4 |
|
5 |
#include <list>
|
5 |
#include <list>
|
6 |
|
6 |
|
7 |
#include "conftree.h"
|
7 |
#include "conftree.h"
|
8 |
#include "smallut.h"
|
8 |
#include "smallut.h"
|
9 |
|
9 |
|
10 |
class RclConfig {
|
10 |
class RclConfig {
|
11 |
public:
|
11 |
public:
|
12 |
|
12 |
|
13 |
RclConfig();
|
13 |
RclConfig();
|
14 |
~RclConfig() {
|
14 |
bool ok() {return m_ok;}
|
15 |
delete m_conf;
|
15 |
const string &getReason() {return m_reason;}
|
16 |
delete mimemap;
|
16 |
/** Return the directory where this config is stored */
|
17 |
delete mimeconf;
|
17 |
string getConfDir() {return m_confdir;}
|
18 |
delete mimemap_local;
|
18 |
|
19 |
delete stopsuffixes;
|
19 |
/** Set current directory reference, and fetch automatic parameters. */
|
|
|
20 |
void setKeyDir(const string &dir)
|
|
|
21 |
{
|
|
|
22 |
m_keydir = dir;
|
|
|
23 |
m_conf->get("defaultcharset", defcharset, m_keydir);
|
|
|
24 |
string str;
|
|
|
25 |
m_conf->get("guesscharset", str, m_keydir);
|
|
|
26 |
guesscharset = stringToBool(str);
|
20 |
}
|
27 |
}
|
21 |
|
28 |
|
22 |
bool ok() {return m_ok;}
|
|
|
23 |
const string &getReason() {return reason;}
|
|
|
24 |
string getConfDir() {return m_confdir;}
|
|
|
25 |
//ConfTree *getConfig() {return m_ok ? conf : 0;}
|
|
|
26 |
|
|
|
27 |
/// Get generic configuration parameter according to current keydir
|
29 |
/** Get generic configuration parameter according to current keydir */
|
28 |
bool getConfParam(const string &name, string &value)
|
30 |
bool getConfParam(const string &name, string &value)
|
29 |
{
|
31 |
{
|
30 |
if (m_conf == 0)
|
32 |
if (m_conf == 0)
|
31 |
return false;
|
33 |
return false;
|
32 |
return m_conf->get(name, value, keydir);
|
34 |
return m_conf->get(name, value, m_keydir);
|
33 |
}
|
35 |
}
|
|
|
36 |
/** Variant with autoconversion to int */
|
|
|
37 |
bool getConfParam(const std::string &name, int *value);
|
|
|
38 |
/** Variant with autoconversion to bool */
|
|
|
39 |
bool getConfParam(const std::string &name, bool *value);
|
|
|
40 |
/** Get default charset for current keydir (was set during setKeydir) */
|
|
|
41 |
const string &getDefCharset() {return defcharset;}
|
|
|
42 |
/** Get guessCharset for current keydir (was set during setKeydir) */
|
|
|
43 |
bool getGuessCharset() {return guesscharset;}
|
34 |
|
44 |
|
35 |
/*
|
|
|
36 |
* Variants with autoconversion
|
|
|
37 |
*/
|
|
|
38 |
bool getConfParam(const std::string &name, int *value);
|
|
|
39 |
bool getConfParam(const std::string &name, bool *value);
|
|
|
40 |
|
|
|
41 |
/// Set current directory reference, and fetch automatic parameters.
|
|
|
42 |
void setKeyDir(const string &dir)
|
|
|
43 |
{
|
|
|
44 |
keydir = dir;
|
|
|
45 |
m_conf->get("defaultcharset", defcharset, keydir);
|
|
|
46 |
string str;
|
|
|
47 |
m_conf->get("guesscharset", str, keydir);
|
|
|
48 |
guesscharset = stringToBool(str);
|
|
|
49 |
}
|
|
|
50 |
|
45 |
|
51 |
/**
|
46 |
/**
|
|
|
47 |
* Get list of ignored suffixes from mimemap
|
|
|
48 |
*
|
|
|
49 |
* The list is initialized on first call, and not changed for subsequent
|
|
|
50 |
* setKeydirs.
|
|
|
51 |
*/
|
|
|
52 |
bool getStopSuffixes(std::list<std::string>& sufflist);
|
|
|
53 |
|
|
|
54 |
/**
|
52 |
* Check if input mime type is a compressed one, and return command to
|
55 |
* Check in mimeconf if input mime type is a compressed one, and
|
53 |
* uncompress if it is
|
56 |
* return command to uncompress if it is.
|
|
|
57 |
*
|
54 |
* The returned command has substitutable places for input file name
|
58 |
* The returned command has substitutable places for input file name
|
55 |
* and temp dir name, and will return output name
|
59 |
* and temp dir name, and will return output name
|
56 |
*/
|
60 |
*/
|
57 |
bool getUncompressor(const std::string &mtpe, std::list<std::string>& cmd);
|
61 |
bool getUncompressor(const std::string &mtpe, std::list<std::string>& cmd);
|
58 |
bool getStopSuffixes(std::list<std::string>& sufflist);
|
62 |
|
|
|
63 |
/** Use mimemap to compute mimetype */
|
59 |
std::string getMimeTypeFromSuffix(const std::string &suffix);
|
64 |
std::string getMimeTypeFromSuffix(const std::string &suffix);
|
|
|
65 |
|
|
|
66 |
/** Get input filter from mimeconf for mimetype */
|
60 |
std::string getMimeHandlerDef(const std::string &mtype);
|
67 |
std::string getMimeHandlerDef(const std::string &mimetype);
|
61 |
/**
|
68 |
|
62 |
* Return external viewer exec string for given mime type
|
69 |
/** Get external viewer exec string from mimeconf for mimetype */
|
63 |
*/
|
|
|
64 |
std::string getMimeViewerDef(const std::string &mtype);
|
70 |
std::string getMimeViewerDef(const std::string &mimetype);
|
65 |
/**
|
71 |
|
66 |
* Return icon name for mime type
|
72 |
/** Get icon name from mimeconf for mimetype */
|
67 |
*/
|
|
|
68 |
string getMimeIconName(const string &mtype);
|
73 |
string getMimeIconName(const string &mtype);
|
69 |
|
74 |
|
70 |
const string &getDefCharset() {return defcharset;}
|
75 |
/** Get a list of all indexable mime types defined in mimemap */
|
71 |
bool getGuessCharset() {return guesscharset;}
|
|
|
72 |
std::list<string> getAllMimeTypes();
|
76 |
std::list<string> getAllMimeTypes();
|
73 |
|
77 |
|
|
|
78 |
/** Find exec file for external filter. cmd is the command name from the
|
|
|
79 |
* command string returned by getMimeHandlerDef */
|
74 |
std::string findFilter(const std::string& cmd);
|
80 |
std::string findFilter(const std::string& cmd);
|
75 |
|
81 |
|
|
|
82 |
~RclConfig() {
|
|
|
83 |
freeAll();
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
RclConfig(const RclConfig &r) {
|
|
|
87 |
initFrom(r);
|
|
|
88 |
}
|
|
|
89 |
RclConfig& operator=(const RclConfig &r) {
|
|
|
90 |
if (this != &r) {
|
|
|
91 |
freeAll();
|
|
|
92 |
initFrom(r);
|
|
|
93 |
}
|
|
|
94 |
return *this;
|
|
|
95 |
}
|
|
|
96 |
|
76 |
private:
|
97 |
private:
|
77 |
int m_ok;
|
98 |
int m_ok;
|
78 |
string reason; // Explanation for bad state
|
99 |
string m_reason; // Explanation for bad state
|
79 |
string m_confdir; // Directory where the files are stored
|
100 |
string m_confdir; // Directory where the files are stored
|
80 |
string m_datadir; // Example: /usr/local/share/recoll
|
101 |
string m_datadir; // Example: /usr/local/share/recoll
|
|
|
102 |
string m_keydir; // Current directory used for parameter fetches.
|
|
|
103 |
|
81 |
ConfTree *m_conf; // Parsed main configuration
|
104 |
ConfTree *m_conf; // Parsed main configuration
|
82 |
string keydir; // Current directory used for parameter fetches.
|
|
|
83 |
|
|
|
84 |
ConfTree *mimemap; // These are independant of current keydir.
|
105 |
ConfTree *mimemap; // These are independant of current keydir.
|
85 |
ConfTree *mimeconf;
|
106 |
ConfTree *mimeconf;
|
86 |
ConfTree *mimemap_local; //
|
107 |
ConfTree *mimemap_local; //
|
87 |
std::list<std::string> *stopsuffixes;
|
108 |
std::list<std::string> *stopsuffixes;
|
88 |
|
109 |
|
89 |
// Parameters auto-fetched on setkeydir
|
110 |
// Parameters auto-fetched on setkeydir
|
90 |
string defcharset; // These are stored locally to avoid
|
111 |
string defcharset; // These are stored locally to avoid
|
91 |
bool guesscharset; // They are fetched initially or on setKeydir()
|
112 |
bool guesscharset; // They are fetched initially or on setKeydir()
|
|
|
113 |
|
|
|
114 |
/** Create initial user configuration */
|
|
|
115 |
bool initUserConfig();
|
|
|
116 |
|
|
|
117 |
/** Copy from other */
|
|
|
118 |
void initFrom(const RclConfig& r);
|
|
|
119 |
/** Init pointers to 0 */
|
|
|
120 |
void zeroMe() {
|
|
|
121 |
m_ok = false;
|
|
|
122 |
m_conf = 0;
|
|
|
123 |
mimemap = 0;
|
|
|
124 |
mimeconf = 0;
|
|
|
125 |
mimemap_local = 0;
|
|
|
126 |
stopsuffixes = 0;
|
|
|
127 |
}
|
|
|
128 |
/** Free data then zero pointers */
|
|
|
129 |
void freeAll() {
|
|
|
130 |
delete m_conf;
|
|
|
131 |
delete mimemap;
|
|
|
132 |
delete mimeconf;
|
|
|
133 |
delete mimemap_local;
|
|
|
134 |
delete stopsuffixes;
|
|
|
135 |
// just in case
|
|
|
136 |
zeroMe();
|
|
|
137 |
}
|
92 |
};
|
138 |
};
|
93 |
|
139 |
|
94 |
|
140 |
|
95 |
#endif /* _RCLCONFIG_H_INCLUDED_ */
|
141 |
#endif /* _RCLCONFIG_H_INCLUDED_ */
|