diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index bddc575f..9d13ff4f 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2004 J.F.Dockes +/* Copyright (C) 2004-2022 J.F.Dockes * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -33,14 +33,11 @@ #endif #include -#include #include #include -#include #include #include #include -#include #include "cstr.h" #include "pathut.h" @@ -848,12 +845,19 @@ string RclConfig::getMimeHandlerDef(const string &mtype, bool filtertypes, const if (!m_excludeMTypes.empty() && m_excludeMTypes.count(stringtolower(mtype))) { IdxDiags::theDiags().record(IdxDiags::ExcludedMime, fn, mtype); LOGDEB1("RclConfig::getMimeHandlerDef: " << mtype << " in excluded mime list (fn " << - fn << ")\n"); + fn << ")\n"); return hs; } } if (!mimeconf->get(mtype, hs, "index")) { + if (mtype.find("text/") == 0) { + bool alltext{false}; + getConfParam("textunknownasplain", &alltext); + if (alltext && mimeconf->get("text/plain", hs, "index")) { + return hs; + } + } if (mtype != "inode/directory") { IdxDiags::theDiags().record(IdxDiags::NoHandler, fn, mtype); LOGDEB1("getMimeHandlerDef: no handler for '" << mtype << "' (fn " << fn << ")\n"); @@ -1233,6 +1237,16 @@ string RclConfig::getMimeViewerDef(const string &mtype, const string& apptag, bo if (apptag.empty() || !mimeview->get(mtype + string("|") + apptag, hs, "view")) mimeview->get(mtype, hs, "view"); + + // Last try for text/xxx if alltext is set + if (hs.empty() && mtype.find("text/") == 0 && mtype != "text/plain") { + bool alltext{false}; + getConfParam("textunknownasplain", &alltext); + if (alltext) { + return getMimeViewerDef("text/plain", apptag, useall); + } + } + return hs; } @@ -1425,7 +1439,7 @@ string RclConfig::getPidfile() const #endif // ! _WIN32 fn = path_cat(getCacheDir(), "index.pid"); -out: + out: LOGINF("RclConfig: pid/lock file: " << fn << "\n"); } return fn; diff --git a/src/internfile/mimehandler.cpp b/src/internfile/mimehandler.cpp index 8540f047..fe0c3c92 100644 --- a/src/internfile/mimehandler.cpp +++ b/src/internfile/mimehandler.cpp @@ -178,11 +178,12 @@ static RecollFilter *mhFactory(RclConfig *config, const string &mimeOrParams, MD5String("MimeHandlerNull", id); return nobuild ? 0 : new MimeHandlerNull(config, id); } else if (lmime.find("text/") == 0) { - // Try to handle unknown text/xx as text/plain. This - // only happen if the text/xx was defined as "internal" in - // mimeconf, not at random. For programs, for example this - // allows indexing and previewing as text/plain (no filter - // exec) but still opening with a specific editor. + // Try to handle unknown text/xx as text/plain. This only happen if the text/xx was defined + // as "internal" in mimeconf. + // This is historic, because the natural way with the current code would be to specify + // "internal text/plain" instead of just "internal"... + // Also see rclconfig for the textunknownisplain configuration variable which allows + // processing all unknown text/* as text/plain. LOGDEB2("mhFactory(" << lmime << "): returning MimeHandlerText(x)\n"); MD5String("MimeHandlerText", id); return nobuild ? 0 : new MimeHandlerText(config, id); diff --git a/src/sampleconf/mimemap b/src/sampleconf/mimemap index ba2c91e8..444f8011 100644 --- a/src/sampleconf/mimemap +++ b/src/sampleconf/mimemap @@ -39,6 +39,7 @@ .bas = text/plain .cpp = text/x-c .h = text/x-c +.hpp = text/x-c++ .c = text/x-c .cc = text/x-c .cxx = text/x-c diff --git a/src/sampleconf/recoll.conf b/src/sampleconf/recoll.conf index b921b5c5..69f60bac 100644 --- a/src/sampleconf/recoll.conf +++ b/src/sampleconf/recoll.conf @@ -15,8 +15,7 @@ # quoted with "double quotes". Double quotes processing is NOT applied to single value parameter, # and using quotes there will result in bad values. -# Parameters affecting what documents we -# index +# Parameters affecting what documents we index # Space-separated list of files or # directories to recursively index.Default to ~ (indexes @@ -227,6 +226,15 @@ compressedfilemaxkbs = 100000 # disable. textfilemaxmbs = 20 +# +# Process unknown text/xxx files as text/plain +# Allows indexing misc. text files identified as text/whatever by 'file' or 'xdg-mime' +# without having to explicitely set config entries for them. This works fine for indexing (but will +# cause processing of a lot of garbage though), but the documents indexed this way will be opened by +# the desktop viewer, even if text/plain has a specific editor. +# +#textunknownasplain=0 + # Index the file names of # unprocessed filesIndex the names of files the contents of # which we don't index because of an excluded or unsupported MIME