Added -L option to recoll for forcing language for messages

This commit is contained in:
Jean-Francois Dockes 2017-11-10 08:59:40 +01:00
parent 08fabf6872
commit ef4888d5ec
2 changed files with 156 additions and 142 deletions

View File

@ -61,13 +61,13 @@ void rememberTempFile(TempFile temp)
void forgetTempFile(string &fn) void forgetTempFile(string &fn)
{ {
if (fn.empty()) if (fn.empty())
return; return;
std::unique_lock<std::mutex> locker(thetempfileslock); std::unique_lock<std::mutex> locker(thetempfileslock);
for (vector<TempFile>::iterator it = o_tempfiles.begin(); for (vector<TempFile>::iterator it = o_tempfiles.begin();
it != o_tempfiles.end(); it++) { it != o_tempfiles.end(); it++) {
if ((*it) && !fn.compare((*it)->filename())) { if ((*it) && !fn.compare((*it)->filename())) {
it->reset(); it->reset();
} }
} }
fn.erase(); fn.erase();
} }
@ -87,34 +87,34 @@ RclMain *mainWindow;
void startManual(const string& helpindex) void startManual(const string& helpindex)
{ {
if (mainWindow) if (mainWindow)
mainWindow->startManual(helpindex); mainWindow->startManual(helpindex);
} }
bool maybeOpenDb(string &reason, bool force, bool *maindberror) bool maybeOpenDb(string &reason, bool force, bool *maindberror)
{ {
LOGDEB2("maybeOpenDb: force " << (force) << "\n" ); LOGDEB2("maybeOpenDb: force " << (force) << "\n" );
if (!rcldb) { if (!rcldb) {
reason = "Internal error: db not created"; reason = "Internal error: db not created";
return false; return false;
} }
if (force) if (force)
rcldb->close(); rcldb->close();
rcldb->rmQueryDb(""); rcldb->rmQueryDb("");
for (list<string>::const_iterator it = prefs.activeExtraDbs.begin(); for (list<string>::const_iterator it = prefs.activeExtraDbs.begin();
it != prefs.activeExtraDbs.end(); it++) { it != prefs.activeExtraDbs.end(); it++) {
LOGDEB("main: adding [" << *it << "]\n" ); LOGDEB("main: adding [" << *it << "]\n" );
rcldb->addQueryDb(*it); rcldb->addQueryDb(*it);
} }
Rcl::Db::OpenError error; Rcl::Db::OpenError error;
if (!rcldb->isopen() && !rcldb->open(Rcl::Db::DbRO, &error)) { if (!rcldb->isopen() && !rcldb->open(Rcl::Db::DbRO, &error)) {
reason = "Could not open database"; reason = "Could not open database";
if (maindberror) { if (maindberror) {
reason += " in " + theconfig->getDbDir() + reason += " in " + theconfig->getDbDir() +
" wait for indexing to complete?"; " wait for indexing to complete?";
*maindberror = (error == Rcl::Db::DbOpenMainDb) ? true : false; *maindberror = (error == Rcl::Db::DbOpenMainDb) ? true : false;
} }
return false; return false;
} }
rcldb->setAbstractParams(-1, prefs.syntAbsLen, prefs.syntAbsCtx); rcldb->setAbstractParams(-1, prefs.syntAbsLen, prefs.syntAbsCtx);
return true; return true;
@ -129,18 +129,18 @@ bool getStemLangs(vector<string>& vlangs)
// Try from db // Try from db
string reason; string reason;
if (maybeOpenDb(reason)) { if (maybeOpenDb(reason)) {
vlangs = rcldb->getStemLangs(); vlangs = rcldb->getStemLangs();
LOGDEB0("getStemLangs: from index: " << (stringsToString(vlangs)) << "\n" ); LOGDEB0("getStemLangs: from index: " << (stringsToString(vlangs)) << "\n" );
return true; return true;
} else { } else {
// Cant get the langs from the index. Maybe it just does not // Cant get the langs from the index. Maybe it just does not
// exist yet. So get them from the config // exist yet. So get them from the config
string slangs; string slangs;
if (theconfig->getConfParam("indexstemminglanguages", slangs)) { if (theconfig->getConfParam("indexstemminglanguages", slangs)) {
stringToStrings(slangs, vlangs); stringToStrings(slangs, vlangs);
return true; return true;
} }
return false; return false;
} }
} }
@ -160,11 +160,11 @@ void applyStyleSheet(const QString& ssfname)
const char *cfname = (const char *)ssfname.toLocal8Bit(); const char *cfname = (const char *)ssfname.toLocal8Bit();
LOGDEB0("Applying style sheet: [" << (cfname) << "]\n" ); LOGDEB0("Applying style sheet: [" << (cfname) << "]\n" );
if (cfname && *cfname) { if (cfname && *cfname) {
string stylesheet; string stylesheet;
file_to_string(cfname, stylesheet); file_to_string(cfname, stylesheet);
qApp->setStyleSheet(QString::fromUtf8(stylesheet.c_str())); qApp->setStyleSheet(QString::fromUtf8(stylesheet.c_str()));
} else { } else {
qApp->setStyleSheet(QString()); qApp->setStyleSheet(QString());
} }
} }
@ -172,41 +172,43 @@ extern void qInitImages_recoll();
static const char *thisprog; static const char *thisprog;
// ATTENTION A LA COMPATIBILITE AVEC LES OPTIONS DE recollq // BEWARE COMPATIBILITY WITH recollq OPTIONS letters
static int op_flags; static int op_flags;
#define OPT_h 0x4 #define OPT_a 0x1
#define OPT_c 0x20 #define OPT_c 0x2
#define OPT_q 0x40 #define OPT_f 0x4
#define OPT_o 0x80 #define OPT_h 0x8
#define OPT_l 0x100 #define OPT_L 0x10
#define OPT_f 0x200 #define OPT_l 0x20
#define OPT_a 0x400 #define OPT_o 0x40
#define OPT_t 0x800 #define OPT_q 0x80
#define OPT_v 0x1000 #define OPT_t 0x100
#define OPT_v 0x200
static const char usage [] = static const char usage [] =
"\n" "\n"
"recoll [-h] [-c <configdir>] [-q query]\n" "recoll [-h] [-c <configdir>] [-q query]\n"
" -h : Print help and exit\n" " -h : Print help and exit\n"
" -c <configdir> : specify config directory, overriding $RECOLL_CONFDIR\n" " -c <configdir> : specify config directory, overriding $RECOLL_CONFDIR\n"
" [-o|l|f|a] [-t] -q 'query' : search query to be executed as if entered\n" " -L <lang> : force language for GUI messages (e.g. -L fr)\n"
" into simple search. The default is to interpret the argument as a \n" " [-o|l|f|a] [-t] -q 'query' : search query to be executed as if entered\n"
" query language string (but see modifier options)\n" " into simple search. The default is to interpret the argument as a \n"
" In most cases, the query string should be quoted with single-quotes to\n" " query language string (but see modifier options)\n"
" avoid shell interpretation\n" " In most cases, the query string should be quoted with single-quotes to\n"
" -a : the query will be interpreted as an AND query.\n" " avoid shell interpretation\n"
" -o : the query will be interpreted as an OR query.\n" " -a : the query will be interpreted as an AND query.\n"
" -f : the query will be interpreted as a filename search\n" " -o : the query will be interpreted as an OR query.\n"
" -l : the query will be interpreted as a query language string (default)\n" " -f : the query will be interpreted as a filename search\n"
" -t : terminal display: no gui. Results go to stdout. MUST be given\n" " -l : the query will be interpreted as a query language string (default)\n"
" explicitly as -t (not ie, -at), and -q <query> MUST\n" " -t : terminal display: no gui. Results go to stdout. MUST be given\n"
" be last on the command line if this is used.\n" " explicitly as -t (not ie, -at), and -q <query> MUST\n"
" Use -t -h to see the additional non-gui options\n" " be last on the command line if this is used.\n"
"recoll -v : print version\n" " Use -t -h to see the additional non-gui options\n"
"recoll <url>\n" "recoll -v : print version\n"
" This is used to open a recoll url (including an ipath), and called\n" "recoll <url>\n"
" typically from another search interface like the Unity Dash\n" " This is used to open a recoll url (including an ipath), and called\n"
; " typically from another search interface like the Unity Dash\n"
;
static void static void
Usage(void) Usage(void)
{ {
@ -222,11 +224,11 @@ int main(int argc, char **argv)
// don't do the GUI thing and pass the whole to recollq for // don't do the GUI thing and pass the whole to recollq for
// command line / pipe usage. // command line / pipe usage.
if (!strcmp(argv[0], "recollq")) if (!strcmp(argv[0], "recollq"))
exit(recollq(&theconfig, argc, argv)); exit(recollq(&theconfig, argc, argv));
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
if (!strcmp(argv[i], "-t")) { if (!strcmp(argv[i], "-t")) {
exit(recollq(&theconfig, argc, argv)); exit(recollq(&theconfig, argc, argv));
} }
} }
QApplication app(argc, argv); QApplication app(argc, argv);
@ -235,35 +237,39 @@ int main(int argc, char **argv)
QCoreApplication::setApplicationName("recoll"); QCoreApplication::setApplicationName("recoll");
string a_config; string a_config;
string a_lang;
string question; string question;
string urltoview; string urltoview;
thisprog = argv[0]; thisprog = argv[0];
argc--; argv++; argc--; argv++;
while (argc > 0 && **argv == '-') { while (argc > 0 && **argv == '-') {
(*argv)++; (*argv)++;
if (!(**argv)) if (!(**argv))
Usage(); Usage();
while (**argv) while (**argv)
switch (*(*argv)++) { switch (*(*argv)++) {
case 'a': op_flags |= OPT_a; break; case 'a': op_flags |= OPT_a; break;
case 'c': op_flags |= OPT_c; if (argc < 2) Usage(); case 'c': op_flags |= OPT_c; if (argc < 2) Usage();
a_config = *(++argv); a_config = *(++argv);
argc--; goto b1; argc--; goto b1;
case 'f': op_flags |= OPT_f; break; case 'f': op_flags |= OPT_f; break;
case 'h': op_flags |= OPT_h; Usage();break; case 'h': op_flags |= OPT_h; Usage();break;
case 'l': op_flags |= OPT_l; break; case 'L': op_flags |= OPT_L; if (argc < 2) Usage();
case 'o': op_flags |= OPT_o; break; a_lang = *(++argv);
case 'q': op_flags |= OPT_q; if (argc < 2) Usage(); argc--; goto b1;
question = *(++argv); case 'l': op_flags |= OPT_l; break;
argc--; goto b1; case 'o': op_flags |= OPT_o; break;
case 'q': op_flags |= OPT_q; if (argc < 2) Usage();
question = *(++argv);
argc--; goto b1;
case 'v': op_flags |= OPT_v; case 'v': op_flags |= OPT_v;
fprintf(stdout, "%s\n", Rcl::version_string().c_str()); fprintf(stdout, "%s\n", Rcl::version_string().c_str());
return 0; return 0;
case 't': op_flags |= OPT_t; break; case 't': op_flags |= OPT_t; break;
default: Usage(); default: Usage();
} }
b1: argc--; argv++; b1: argc--; argv++;
} }
@ -271,37 +277,42 @@ int main(int argc, char **argv)
// to the query. This is for the common case recoll -q x y z to // to the query. This is for the common case recoll -q x y z to
// avoid needing quoting "x y z" // avoid needing quoting "x y z"
if (op_flags & OPT_q) if (op_flags & OPT_q)
while (argc > 0) { while (argc > 0) {
question += " "; question += " ";
question += *argv++; question += *argv++;
argc--; argc--;
} }
// Else the remaining argument should be an URL to be opened // Else the remaining argument should be an URL to be opened
if (argc == 1) { if (argc == 1) {
urltoview = *argv++;argc--; urltoview = *argv++;argc--;
if (urltoview.compare(0, 7, cstr_fileu)) { if (urltoview.compare(0, 7, cstr_fileu)) {
Usage(); Usage();
} }
} else if (argc > 0) } else if (argc > 0)
Usage(); Usage();
string reason; string reason;
theconfig = recollinit(recollCleanup, 0, reason, &a_config); theconfig = recollinit(recollCleanup, 0, reason, &a_config);
if (!theconfig || !theconfig->ok()) { if (!theconfig || !theconfig->ok()) {
QString msg = "Configuration problem: "; QString msg = "Configuration problem: ";
msg += QString::fromUtf8(reason.c_str()); msg += QString::fromUtf8(reason.c_str());
QMessageBox::critical(0, "Recoll", msg); QMessageBox::critical(0, "Recoll", msg);
exit(1); exit(1);
} }
// fprintf(stderr, "recollinit done\n"); // fprintf(stderr, "recollinit done\n");
// Translations for Qt standard widgets // Translations for Qt standard widgets
QString slang = QLocale::system().name().left(2); QString slang;
if (op_flags & OPT_L) {
slang = u8s2qs(a_lang);
} else {
slang = QLocale::system().name().left(2);
}
QTranslator qt_trans(0); QTranslator qt_trans(0);
qt_trans.load(QString("qt_%1").arg(slang), qt_trans.load(QString("qt_%1").arg(slang),
QLibraryInfo::location(QLibraryInfo::TranslationsPath)); QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qt_trans); app.installTranslator(&qt_trans);
// Translations for Recoll // Translations for Recoll
@ -315,9 +326,12 @@ int main(int argc, char **argv)
string historyfile = path_cat(theconfig->getConfDir(), "history"); string historyfile = path_cat(theconfig->getConfDir(), "history");
g_dynconf = new RclDynConf(historyfile); g_dynconf = new RclDynConf(historyfile);
if (!g_dynconf || !g_dynconf->ok()) { if (!g_dynconf || !g_dynconf->ok()) {
QString msg = app.translate("Main", "\"history\" file is damaged or un(read)writeable, please check or remove it: ") + QString::fromLocal8Bit(historyfile.c_str()); QString msg = app.translate
QMessageBox::critical(0, "Recoll", msg); ("Main",
exit(1); "\"history\" file is damaged or un(read)writeable, please check "
"or remove it: ") + QString::fromLocal8Bit(historyfile.c_str());
QMessageBox::critical(0, "Recoll", msg);
exit(1);
} }
g_advshistory = new AdvSearchHist; g_advshistory = new AdvSearchHist;
@ -326,7 +340,7 @@ int main(int argc, char **argv)
// fprintf(stderr, "Settings done\n"); // fprintf(stderr, "Settings done\n");
if (!prefs.qssFile.isEmpty()) { if (!prefs.qssFile.isEmpty()) {
applyStyleSheet(prefs.qssFile); applyStyleSheet(prefs.qssFile);
} }
QIcon icon; QIcon icon;
icon.addFile(QString::fromUtf8(":/images/recoll.png")); icon.addFile(QString::fromUtf8(":/images/recoll.png"));
@ -337,16 +351,16 @@ int main(int argc, char **argv)
mainWindow = &w; mainWindow = &w;
if (prefs.mainwidth > 100) { if (prefs.mainwidth > 100) {
QSize s(prefs.mainwidth, prefs.mainheight); QSize s(prefs.mainwidth, prefs.mainheight);
mainWindow->resize(s); mainWindow->resize(s);
} }
string dbdir = theconfig->getDbDir(); string dbdir = theconfig->getDbDir();
if (dbdir.empty()) { if (dbdir.empty()) {
QMessageBox::critical(0, "Recoll", QMessageBox::critical(
app.translate("Main", 0, "Recoll",
"No db directory in configuration")); app.translate("Main", "No db directory in configuration"));
exit(1); exit(1);
} }
rcldb = new Rcl::Db(theconfig); rcldb = new Rcl::Db(theconfig);
@ -362,22 +376,22 @@ int main(int argc, char **argv)
mainWindow->sSearch->searchTypCMB->setCurrentIndex(prefs.ssearchTyp); mainWindow->sSearch->searchTypCMB->setCurrentIndex(prefs.ssearchTyp);
mainWindow->sSearch->searchTypeChanged(prefs.ssearchTyp); mainWindow->sSearch->searchTypeChanged(prefs.ssearchTyp);
if (op_flags & OPT_q) { if (op_flags & OPT_q) {
SSearch::SSearchType stype; SSearch::SSearchType stype;
if (op_flags & OPT_o) { if (op_flags & OPT_o) {
stype = SSearch::SST_ANY; stype = SSearch::SST_ANY;
} else if (op_flags & OPT_f) { } else if (op_flags & OPT_f) {
stype = SSearch::SST_FNM; stype = SSearch::SST_FNM;
} else if (op_flags & OPT_a) { } else if (op_flags & OPT_a) {
stype = SSearch::SST_ALL; stype = SSearch::SST_ALL;
} else { } else {
stype = SSearch::SST_LANG; stype = SSearch::SST_LANG;
} }
mainWindow->sSearch->searchTypCMB->setCurrentIndex(int(stype)); mainWindow->sSearch->searchTypCMB->setCurrentIndex(int(stype));
mainWindow-> mainWindow->
sSearch->setSearchString(QString::fromLocal8Bit(question.c_str())); sSearch->setSearchString(QString::fromLocal8Bit(question.c_str()));
} else if (!urltoview.empty()) { } else if (!urltoview.empty()) {
LOGDEB("MAIN: got urltoview [" << (urltoview) << "]\n" ); LOGDEB("MAIN: got urltoview [" << (urltoview) << "]\n" );
mainWindow->setUrlToView(QString::fromLocal8Bit(urltoview.c_str())); mainWindow->setUrlToView(QString::fromLocal8Bit(urltoview.c_str()));
} }
return app.exec(); return app.exec();
} }
@ -388,21 +402,21 @@ QString myGetFileName(bool isdir, QString caption, bool filenosave)
QFileDialog dialog(0, caption); QFileDialog dialog(0, caption);
if (isdir) { if (isdir) {
dialog.setFileMode(QFileDialog::Directory); dialog.setFileMode(QFileDialog::Directory);
dialog.setOptions(QFileDialog::ShowDirsOnly); dialog.setOptions(QFileDialog::ShowDirsOnly);
} else { } else {
dialog.setFileMode(QFileDialog::AnyFile); dialog.setFileMode(QFileDialog::AnyFile);
if (filenosave) if (filenosave)
dialog.setAcceptMode(QFileDialog::AcceptOpen); dialog.setAcceptMode(QFileDialog::AcceptOpen);
else else
dialog.setAcceptMode(QFileDialog::AcceptSave); dialog.setAcceptMode(QFileDialog::AcceptSave);
} }
dialog.setViewMode(QFileDialog::List); dialog.setViewMode(QFileDialog::List);
QFlags<QDir::Filter> flags = QDir::NoDotAndDotDot | QDir::Hidden; QFlags<QDir::Filter> flags = QDir::NoDotAndDotDot | QDir::Hidden;
if (isdir) if (isdir)
flags |= QDir::Dirs; flags |= QDir::Dirs;
else else
flags |= QDir::Dirs | QDir::Files; flags |= QDir::Dirs | QDir::Files;
dialog.setFilter(flags); dialog.setFilter(flags);
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {

View File

@ -137,10 +137,10 @@ Usage(void)
exit(1); exit(1);
} }
// ATTENTION A LA COMPATIBILITE AVEC LES OPTIONS DE recoll // BEWARE COMPATIBILITy WITH recoll OPTIONS letters
// -q, -t and -l are accepted and ignored // -q, -t and -l are accepted and ignored
// -a/f/o -c have the same meaning // -a/f/o -c have the same meaning
// -h is not used // -h and -v -> Usage()
static int op_flags; static int op_flags;
#define OPT_A 0x1 #define OPT_A 0x1