fix the external index dialog to accept either xapian directory or recoll config directories

This commit is contained in:
Jean-Francois Dockes 2013-01-30 11:46:29 +01:00
parent d3631b5ddf
commit 6b40f9b3f4
3 changed files with 50 additions and 34 deletions

View File

@ -49,10 +49,13 @@ using namespace std;
#include "readfile.h"
#include "fstreewalk.h"
// Static, logically const, RclConfig members are initialized once from the
// first object build during process initialization.
#ifndef RCL_INDEX_STRIPCHARS
// We default to a case- and diacritics-less index for now
bool o_index_stripchars = true;
#endif
string RclConfig::o_localecharset;
bool ParamStale::needrecompute()
{
@ -107,8 +110,6 @@ bool RclConfig::isDefaultConfig() const
return !defaultconf.compare(specifiedconf);
}
string RclConfig::o_localecharset;
RclConfig::RclConfig(const string *argcnf)
{
zeroMe();

View File

@ -41,6 +41,7 @@
#include <qtextedit.h>
#include <qlist.h>
#include <QTimer>
#include <QListWidget>
#include "recoll.h"
#include "guiutils.h"
@ -445,6 +446,19 @@ void UIPrefsDialog::delExtraDbPB_clicked()
}
}
static bool samedir(const string& dir1, const string& dir2)
{
struct stat st1, st2;
if (stat(dir1.c_str(), &st1))
return false;
if (stat(dir2.c_str(), &st2))
return false;
if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
return true;
}
return false;
}
/**
* Browse to add another index.
* We do a textual comparison to check for duplicates, except for
@ -453,13 +467,27 @@ void UIPrefsDialog::delExtraDbPB_clicked()
void UIPrefsDialog::addExtraDbPB_clicked()
{
QString input = myGetFileName(true,
tr("Select xapian index directory "
"(ie: /home/buddy/.recoll/xapiandb)"));
tr("Select recoll config directory or "
"xapian index directory "
"(e.g.: /home/me/.recoll or "
"/home/me/.recoll/xapiandb)"));
if (input.isEmpty())
return;
string dbdir = (const char *)input.toLocal8Bit();
if (access(path_cat(dbdir, "recoll.conf").c_str(), 0) == 0) {
// Chosen dir is config dir.
RclConfig conf(&dbdir);
dbdir = conf.getDbDir();
if (dbdir.empty()) {
QMessageBox::warning(
0, "Recoll", tr("The selected directory looks like a Recoll "
"configuration directory but the configuration "
"could not be read"));
return;
}
}
LOGDEB(("ExtraDbDial: got: [%s]\n", dbdir.c_str()));
path_catslash(dbdir);
if (!Rcl::Db::testDbDir(dbdir)) {
@ -467,42 +495,25 @@ void UIPrefsDialog::addExtraDbPB_clicked()
tr("The selected directory does not appear to be a Xapian index"));
return;
}
struct stat st1, st2;
stat(dbdir.c_str(), &st1);
string rcldbdir = theconfig->getDbDir();
stat(rcldbdir.c_str(), &st2);
path_catslash(rcldbdir);
if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
if (samedir(dbdir, theconfig->getDbDir())) {
QMessageBox::warning(0, "Recoll",
tr("This is the main/local index!"));
return;
}
// For some reason, finditem (which we used to use to detect duplicates
// here) does not work anymore here: qt 4.6.3
QList<QListWidgetItem *>items =
idxLV->findItems (input, Qt::MatchFixedString|Qt::MatchCaseSensitive);
if (!items.empty()) {
QMessageBox::warning(0, "Recoll",
tr("The selected directory is already in the index list"));
return;
}
#if 0
string nv = (const char *)input.toLocal8Bit();
QListViewItemIterator it(idxLV);
while (it.current()) {
QCheckListItem *item = (QCheckListItem *)it.current();
string ov = (const char *)item->text().toLocal8Bit();
if (!ov.compare(nv)) {
QMessageBox::warning(0, "Recoll",
tr("The selected directory is already in the index list"));
for (int i = 0; i < idxLV->count(); i++) {
QListWidgetItem *item = idxLV->item(i);
string existingdir = (const char *)item->text().toLocal8Bit();
if (samedir(dbdir, existingdir)) {
QMessageBox::warning(
0, "Recoll", tr("The selected directory is already in the "
"index list"));
return;
}
++it;
}
#endif
QListWidgetItem *item = new QListWidgetItem(input, idxLV);
QListWidgetItem *item =
new QListWidgetItem(QString::fromLocal8Bit(dbdir.c_str()), idxLV);
item->setCheckState(Qt::Checked);
idxLV->sortItems();
}

View File

@ -112,7 +112,11 @@ url = dc:identifier xesam:url
# Section to define translations from extended file attribute names to
# field names. xattr use must be enabled at compile time for this to be
# used. Enter translations as "xattrname = fieldname". Case matters.
# The values from the extended attributes will extend, not replace, the
# data found from equivalent fields inside the document. As an example, the
# following would map a quite plausible "tags" extended attribute into the
# "keywords" field.
tags = keywords
########################
# Sections reserved for specific filters follow