mimemap processing recentered in rclconfig. Handle directory-local suffix to mime-type definitions. Implement gaim log handling

This commit is contained in:
dockes
2005-11-21 14:31:24 +00:00
parent 64377c44d3
commit ad67a6cbb7
16 changed files with 192 additions and 152 deletions
+88 -7
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.11 2005-11-17 12:47:03 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.12 2005-11-21 14:31:24 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
#include <unistd.h>
#include <errno.h>
@@ -10,11 +10,13 @@ static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.11 2005-11-17 12:47:03 dockes E
#include "pathut.h"
#include "conftree.h"
#include "debuglog.h"
#include "smallut.h"
using namespace std;
RclConfig::RclConfig()
: m_ok(false), conf(0), mimemap(0), mimeconf(0)
: m_ok(false), conf(0), mimemap(0), mimeconf(0), stopsuffixes(0)
{
static int loginit = 0;
if (!loginit) {
@@ -94,13 +96,21 @@ bool RclConfig::getConfParam(const std::string &name, int *ivp)
*ivp = int(lval);
return true;
}
bool RclConfig::getConfParam(const std::string &name, bool *value)
bool RclConfig::getConfParam(const std::string &name, bool *bvp)
{
int ival;
if (!getConfParam(name, &ival))
*bvp = false;
string s;
if (!getConfParam(name, s))
return false;
if (*value)
*value = ival ? true : false;
if (s.empty())
return true;
if (isdigit(s[0])) {
int val = atoi(s.c_str());
*bvp = val ? true : false;
} else if (strchr("yYoOtT", s[0])) {
*bvp = true;
}
return true;
}
@@ -127,6 +137,55 @@ std::list<string> RclConfig::getAllMimeTypes()
return lst;
}
bool RclConfig::getStopSuffixes(list<string>& sufflist)
{
if (stopsuffixes == 0 && (stopsuffixes = new list<string>) != 0) {
string stp;
if (mimemap->get("recoll_noindex", stp, keydir)) {
ConfTree::stringToStrings(stp, *stopsuffixes);
}
}
if (stopsuffixes) {
sufflist = *stopsuffixes;
return true;
}
return false;
}
string RclConfig::getMimeTypeFromSuffix(const string &suff)
{
string mtype;
mimemap->get(suff, mtype, keydir);
return mtype;
}
string RclConfig::getMimeHandlerDef(const std::string &mtype)
{
string hs;
if (!mimeconf->get(mtype, hs, "index")) {
LOGDEB(("getMimeHandler: no handler for '%s'\n", mtype.c_str()));
}
return hs;
}
string RclConfig::getMimeViewerDef(const string &mtype)
{
string hs;
mimeconf->get(mtype, hs, "view");
return hs;
}
/**
* Return icon name
*/
string RclConfig::getMimeIconName(const string &mtype)
{
string hs;
mimeconf->get(mtype, hs, "icons");
return hs;
}
// Look up an executable filter.
// We look in RECOLL_BINDIR, RECOLL_CONFDIR, then let the system use
// the PATH
@@ -152,3 +211,25 @@ string find_filter(RclConfig *conf, const string &icmd)
return icmd;
}
/**
* Return decompression command line for given mime type
*/
bool RclConfig::getUncompressor(const string &mtype, list<string>& cmd)
{
string hs;
mimeconf->get(mtype, hs, "");
if (hs.empty())
return false;
list<string> tokens;
ConfTree::stringToStrings(hs, tokens);
if (tokens.empty()) {
LOGERR(("getUncompressor: empty spec for mtype %s\n", mtype.c_str()));
return false;
}
if (stringlowercmp("uncompress", tokens.front()))
return false;
list<string>::iterator it = tokens.begin();
cmd.assign(++it, tokens.end());
return true;
}
+40 -18
View File
@@ -1,26 +1,12 @@
#ifndef _RCLCONFIG_H_INCLUDED_
#define _RCLCONFIG_H_INCLUDED_
/* @(#$Id: rclconfig.h,v 1.7 2005-11-17 12:47:03 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: rclconfig.h,v 1.8 2005-11-21 14:31:24 dockes Exp $ (C) 2004 J.F.Dockes */
#include <list>
#include "conftree.h"
class RclConfig {
int m_ok;
string reason; // Explanation for bad state
string confdir; // Directory where the files are stored
ConfTree *conf; // Parsed main configuration
string keydir; // Current directory used for parameter fetches.
ConfTree *mimemap; // These are independant of current keydir. We might
ConfTree *mimeconf; // want to change it one day.
// Parameters auto-fetched on setkeydir
string defcharset; // These are stored locally to avoid
string deflang; // a config lookup each time.
bool guesscharset; // They are fetched initially or on setKeydir()
public:
RclConfig();
@@ -29,7 +15,7 @@ class RclConfig {
bool ok() {return m_ok;}
const string &getReason() {return reason;}
string getConfDir() {return confdir;}
ConfTree *getConfig() {return m_ok ? conf : 0;}
//ConfTree *getConfig() {return m_ok ? conf : 0;}
/// Get generic configuration parameter according to current keydir
bool getConfParam(const string &name, string &value)
@@ -55,12 +41,48 @@ class RclConfig {
conf->get("guesscharset", str, keydir);
guesscharset = ConfTree::stringToBool(str);
}
ConfTree *getMimeMap() {return m_ok ? mimemap : 0;}
ConfTree *getMimeConf() {return m_ok ? mimeconf : 0;}
/**
* Check if input mime type is a compressed one, and return command to
* uncompress if it is
* The returned command has substitutable places for input file name
* and temp dir name, and will return output name
*/
bool getUncompressor(const std::string &mtpe, std::list<std::string>& cmd);
bool getStopSuffixes(std::list<std::string>& sufflist);
std::string getMimeTypeFromSuffix(const std::string &suffix);
std::string getMimeHandlerDef(const std::string &mtype);
/**
* Return external viewer exec string for given mime type
*/
std::string getMimeViewerDef(const std::string &mtype);
/**
* Return icon name for mime type
*/
string getMimeIconName(const string &mtype);
const string &getDefCharset() {return defcharset;}
const string &getDefLang() {return deflang;}
bool getGuessCharset() {return guesscharset;}
std::list<string> getAllMimeTypes();
private:
int m_ok;
string reason; // Explanation for bad state
string confdir; // Directory where the files are stored
ConfTree *conf; // Parsed main configuration
string keydir; // Current directory used for parameter fetches.
ConfTree *mimemap; // These are independant of current keydir.
ConfTree *mimeconf;
ConfTree *mimemap_local; //
std::list<std::string> *stopsuffixes;
// Parameters auto-fetched on setkeydir
string defcharset; // These are stored locally to avoid
string deflang; // a config lookup each time.
bool guesscharset; // They are fetched initially or on setKeydir()
};
std::string find_filter(RclConfig *conf, const string& cmd);