|
a/src/common/rclconfig.cpp |
|
b/src/common/rclconfig.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.35 2006-12-13 09:13:18 dockes Exp $ (C) 2004 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.36 2006-12-14 13:53:42 dockes Exp $ (C) 2004 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
17 |
* Free Software Foundation, Inc.,
|
17 |
* Free Software Foundation, Inc.,
|
18 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
*/
|
19 |
*/
|
20 |
#ifndef TEST_RCLCONFIG
|
20 |
#ifndef TEST_RCLCONFIG
|
21 |
#include <unistd.h>
|
21 |
#include <unistd.h>
|
|
|
22 |
#include <fcntl.h>
|
22 |
#include <stdio.h>
|
23 |
#include <stdio.h>
|
23 |
#include <errno.h>
|
24 |
#include <errno.h>
|
24 |
#include <langinfo.h>
|
25 |
#include <langinfo.h>
|
25 |
|
26 |
|
26 |
#include <sys/types.h>
|
27 |
#include <sys/types.h>
|
|
... |
|
... |
68 |
if (access(m_confdir.c_str(), 0) < 0) {
|
69 |
if (access(m_confdir.c_str(), 0) < 0) {
|
69 |
if (!initUserConfig())
|
70 |
if (!initUserConfig())
|
70 |
return;
|
71 |
return;
|
71 |
}
|
72 |
}
|
72 |
|
73 |
|
73 |
list<string>cfns;
|
74 |
list<string> cdirs;
|
74 |
string cpath;
|
75 |
cdirs.push_back(m_confdir);
|
|
|
76 |
cdirs.push_back(path_cat(m_datadir, "examples"));
|
75 |
|
77 |
|
76 |
cpath = path_cat(m_confdir, "recoll.conf");
|
|
|
77 |
cfns.push_back(cpath);
|
|
|
78 |
cpath = path_cat(m_datadir, "examples/recoll.conf");
|
|
|
79 |
cfns.push_back(cpath);
|
|
|
80 |
m_conf = new ConfStack<ConfTree>(cfns, true);
|
78 |
m_conf = new ConfStack<ConfTree>("recoll.conf", cdirs, true);
|
81 |
if (m_conf == 0 || !m_conf->ok()) {
|
79 |
if (m_conf == 0 || !m_conf->ok()) {
|
82 |
m_reason = string("No main configuration file: ");
|
80 |
m_reason = string("No/bad main configuration file in: ") + m_confdir;
|
83 |
for (list<string>::const_iterator it = cfns.begin(); it != cfns.end();
|
|
|
84 |
it++)
|
|
|
85 |
m_reason += "[" + *it + "] ";
|
|
|
86 |
m_reason += " do not exist or cannot be parsed";
|
|
|
87 |
return;
|
81 |
return;
|
88 |
}
|
82 |
}
|
89 |
|
83 |
|
90 |
cfns.clear();
|
|
|
91 |
cpath = path_cat(m_confdir, "mimemap");
|
|
|
92 |
cfns.push_back(cpath);
|
|
|
93 |
cpath = path_cat(m_datadir, "examples/mimemap");
|
|
|
94 |
cfns.push_back(cpath);
|
|
|
95 |
mimemap = new ConfStack<ConfTree>(cfns, true);
|
84 |
mimemap = new ConfStack<ConfTree>("mimemap", cdirs, true);
|
96 |
if (mimemap == 0 || !mimemap->ok()) {
|
85 |
if (mimemap == 0 || !mimemap->ok()) {
|
97 |
m_reason = string("No mime map configuration file: ");
|
86 |
m_reason = string("No or bad mimemap file in: ") + m_confdir;
|
98 |
for (list<string>::const_iterator it = cfns.begin(); it != cfns.end();
|
|
|
99 |
it++)
|
|
|
100 |
m_reason += "[" + *it + "] ";
|
|
|
101 |
m_reason += " do not exist or cannot be parsed";
|
|
|
102 |
return;
|
87 |
return;
|
103 |
}
|
88 |
}
|
104 |
|
89 |
|
105 |
cfns.clear();
|
|
|
106 |
cpath = path_cat(m_confdir, "mimeconf");
|
|
|
107 |
cfns.push_back(cpath);
|
|
|
108 |
cpath = path_cat(m_datadir, "examples/mimeconf");
|
|
|
109 |
cfns.push_back(cpath);
|
|
|
110 |
mimeconf = new ConfStack<ConfTree>(cfns, true);
|
90 |
mimeconf = new ConfStack<ConfTree>("mimeconf", cdirs, true);
|
111 |
if (mimeconf == 0 || !mimeconf->ok()) {
|
91 |
if (mimeconf == 0 || !mimeconf->ok()) {
|
112 |
m_reason = string("No mime configuration file: ");
|
92 |
m_reason = string("No/bad mimeconf in: ") + m_confdir;
|
113 |
for (list<string>::const_iterator it = cfns.begin(); it != cfns.end();
|
93 |
return;
|
114 |
it++)
|
94 |
}
|
115 |
m_reason += "[" + *it + "] ";
|
95 |
mimeview = new ConfStack<ConfTree>("mimeview", cdirs, true);
|
116 |
m_reason += " do not exist or cannot be parsed";
|
96 |
if (mimeconf == 0 || !mimeconf->ok()) {
|
|
|
97 |
m_reason = string("No/bad mimeview in: ") + m_confdir;
|
117 |
return;
|
98 |
return;
|
118 |
}
|
99 |
}
|
119 |
|
100 |
|
120 |
setKeyDir("");
|
101 |
setKeyDir("");
|
121 |
|
102 |
|
|
... |
|
... |
198 |
} else {
|
179 |
} else {
|
199 |
// Note: it seems that all versions of iconv will take
|
180 |
// Note: it seems that all versions of iconv will take
|
200 |
// iso-8859. Some won't take iso8859
|
181 |
// iso-8859. Some won't take iso8859
|
201 |
localecharset = string("ISO-8859-1");
|
182 |
localecharset = string("ISO-8859-1");
|
202 |
}
|
183 |
}
|
203 |
LOGDEB(("RclConfig::getDefCharset: localecharset [%s]\n",
|
184 |
LOGDEB1(("RclConfig::getDefCharset: localecharset [%s]\n",
|
204 |
localecharset.c_str()));
|
185 |
localecharset.c_str()));
|
205 |
}
|
186 |
}
|
206 |
|
187 |
|
207 |
if (defcharset.empty()) {
|
188 |
if (defcharset.empty()) {
|
208 |
defcharset = localecharset;
|
189 |
defcharset = localecharset;
|
|
... |
|
... |
213 |
} else {
|
194 |
} else {
|
214 |
return defcharset;
|
195 |
return defcharset;
|
215 |
}
|
196 |
}
|
216 |
}
|
197 |
}
|
217 |
|
198 |
|
218 |
// Get all known document mime values. We get them from the mimeconf
|
199 |
// Get all known document mime values (for indexing). We get them from
|
219 |
// 'index' submap: values not in there (ie from mimemap or idfile) can't
|
200 |
// the mimeconf 'index' submap: values not in there (ie from mimemap
|
220 |
// possibly belong to documents in the database.
|
201 |
// or idfile) can't possibly belong to documents in the database.
|
221 |
std::list<string> RclConfig::getAllMimeTypes()
|
202 |
std::list<string> RclConfig::getAllMimeTypes()
|
222 |
{
|
203 |
{
|
223 |
std::list<string> lst;
|
204 |
std::list<string> lst;
|
224 |
if (mimeconf == 0)
|
205 |
if (mimeconf == 0)
|
225 |
return lst;
|
206 |
return lst;
|
|
... |
|
... |
259 |
}
|
240 |
}
|
260 |
|
241 |
|
261 |
string RclConfig::getMimeViewerDef(const string &mtype)
|
242 |
string RclConfig::getMimeViewerDef(const string &mtype)
|
262 |
{
|
243 |
{
|
263 |
string hs;
|
244 |
string hs;
|
264 |
mimeconf->get(mtype, hs, "view");
|
245 |
mimeview->get(mtype, hs, "view");
|
265 |
return hs;
|
246 |
return hs;
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
bool RclConfig::getMimeViewerDefs(vector<pair<string, string> >& defs)
|
|
|
250 |
{
|
|
|
251 |
if (mimeview == 0)
|
|
|
252 |
return false;
|
|
|
253 |
list<string>tps = mimeview->getNames("view");
|
|
|
254 |
for (list<string>::const_iterator it = tps.begin(); it != tps.end();it++) {
|
|
|
255 |
defs.push_back(pair<string, string>(*it, getMimeViewerDef(*it)));
|
|
|
256 |
}
|
|
|
257 |
return true;
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
bool RclConfig::setMimeViewerDef(const string& mt, const string& def)
|
|
|
261 |
{
|
|
|
262 |
string pconfname = path_cat(m_confdir, "mimeview");
|
|
|
263 |
// Make sure this exists
|
|
|
264 |
close(open(pconfname.c_str(), O_CREAT|O_WRONLY, 0600));
|
|
|
265 |
ConfTree tree(pconfname.c_str());
|
|
|
266 |
if (!tree.set(mt, def, "view")) {
|
|
|
267 |
m_reason = string("RclConfig::setMimeViewerDef: cant set value in ")
|
|
|
268 |
+ pconfname;
|
|
|
269 |
return false;
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
list<string> cdirs;
|
|
|
273 |
cdirs.push_back(m_confdir);
|
|
|
274 |
cdirs.push_back(path_cat(m_datadir, "examples"));
|
|
|
275 |
|
|
|
276 |
delete mimeview;
|
|
|
277 |
mimeview = new ConfStack<ConfTree>("mimeview", cdirs, true);
|
|
|
278 |
if (mimeconf == 0 || !mimeconf->ok()) {
|
|
|
279 |
m_reason = string("No/bad mimeview in: ") + m_confdir;
|
|
|
280 |
return false;
|
|
|
281 |
}
|
|
|
282 |
return true;
|
266 |
}
|
283 |
}
|
267 |
|
284 |
|
268 |
/**
|
285 |
/**
|
269 |
* Return icon name and path
|
286 |
* Return icon name and path
|
270 |
*/
|
287 |
*/
|
|
... |
|
... |
410 |
"# with the same name in the central directory. The syntax for setting\n"
|
427 |
"# with the same name in the central directory. The syntax for setting\n"
|
411 |
"# values is identical.\n"
|
428 |
"# values is identical.\n"
|
412 |
;
|
429 |
;
|
413 |
|
430 |
|
414 |
// Create initial user config by creating commented empty files
|
431 |
// Create initial user config by creating commented empty files
|
415 |
static const char *configfiles[] = {"recoll.conf", "mimemap", "mimeconf"};
|
432 |
static const char *configfiles[] = {"recoll.conf", "mimemap", "mimeconf",
|
|
|
433 |
"mimeview"};
|
416 |
static int ncffiles = sizeof(configfiles) / sizeof(char *);
|
434 |
static int ncffiles = sizeof(configfiles) / sizeof(char *);
|
417 |
bool RclConfig::initUserConfig()
|
435 |
bool RclConfig::initUserConfig()
|
418 |
{
|
436 |
{
|
419 |
// Explanatory text
|
437 |
// Explanatory text
|
420 |
char blurb[sizeof(blurb0)+1025];
|
438 |
char blurb[sizeof(blurb0)+1025];
|
|
... |
|
... |
459 |
m_conf = new ConfStack<ConfTree>(*(r.m_conf));
|
477 |
m_conf = new ConfStack<ConfTree>(*(r.m_conf));
|
460 |
if (r.mimemap)
|
478 |
if (r.mimemap)
|
461 |
mimemap = new ConfStack<ConfTree>(*(r.mimemap));
|
479 |
mimemap = new ConfStack<ConfTree>(*(r.mimemap));
|
462 |
if (r.mimeconf)
|
480 |
if (r.mimeconf)
|
463 |
mimeconf = new ConfStack<ConfTree>(*(r.mimeconf));
|
481 |
mimeconf = new ConfStack<ConfTree>(*(r.mimeconf));
|
|
|
482 |
if (r.mimeview)
|
|
|
483 |
mimeview = new ConfStack<ConfTree>(*(r.mimeview));
|
464 |
if (r.stopsuffixes)
|
484 |
if (r.stopsuffixes)
|
465 |
stopsuffixes = new std::list<std::string>(*(r.stopsuffixes));
|
485 |
stopsuffixes = new std::list<std::string>(*(r.stopsuffixes));
|
466 |
defcharset = r.defcharset;
|
486 |
defcharset = r.defcharset;
|
467 |
guesscharset = r.guesscharset;
|
487 |
guesscharset = r.guesscharset;
|
468 |
}
|
488 |
}
|