small fixes for extra db selection

This commit is contained in:
dockes 2006-04-05 13:39:07 +00:00
parent a2509fa445
commit c11a64f8a3
5 changed files with 71 additions and 28 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.6 2006-04-05 12:50:42 dockes Exp $ (C) 2005 Jean-Francois Dockes"; static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.7 2006-04-05 13:39:07 dockes Exp $ (C) 2005 Jean-Francois Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -168,7 +168,7 @@ void rwSettings(bool writing)
} }
} }
#if 1 #if 0
{ {
list<string>::const_iterator it; list<string>::const_iterator it;
fprintf(stderr, "All extra Dbs:\n"); fprintf(stderr, "All extra Dbs:\n");

View File

@ -290,7 +290,7 @@ May be slow for big documents.</string>
<string>Add database</string> <string>Add database</string>
</property> </property>
<property name="toolTip" stdset="0"> <property name="toolTip" stdset="0">
<string>Select the recoll.conf file defining the database you want to add, then click Add Database</string> <string>Select the xapiandb directory for the database you want to add, then click Add Database</string>
</property> </property>
</widget> </widget>
<widget class="QLineEdit"> <widget class="QLineEdit">
@ -304,7 +304,7 @@ May be slow for big documents.</string>
</size> </size>
</property> </property>
<property name="toolTip" stdset="0"> <property name="toolTip" stdset="0">
<string>Select the recoll.conf file defining the database you want to add, then click Add Database</string> <string>Select the xapiandb directory for the database you want to add, then click Add Database</string>
</property> </property>
</widget> </widget>
<widget class="QPushButton"> <widget class="QPushButton">
@ -315,7 +315,7 @@ May be slow for big documents.</string>
<string>Browse</string> <string>Browse</string>
</property> </property>
<property name="toolTip" stdset="0"> <property name="toolTip" stdset="0">
<string>Select the recoll.conf file defining the database you want to add, then click Add Database</string> <string>Select the xapiandb directory for the database you want to add, then click Add Database</string>
</property> </property>
</widget> </widget>
</hbox> </hbox>

View File

@ -25,6 +25,8 @@
** These will automatically be called by the form's constructor and ** These will automatically be called by the form's constructor and
** destructor. ** destructor.
*****************************************************************************/ *****************************************************************************/
#include <sys/stat.h>
#include <string> #include <string>
#include <algorithm> #include <algorithm>
#include <list> #include <list>
@ -37,6 +39,7 @@
#include "recoll.h" #include "recoll.h"
#include "guiutils.h" #include "guiutils.h"
#include "rcldb.h" #include "rcldb.h"
#include "pathut.h"
void UIPrefsDialog::init() void UIPrefsDialog::init()
{ {
@ -135,6 +138,21 @@ void UIPrefsDialog::accept()
prefs.queryBuildAbstract = buildAbsCB->isChecked(); prefs.queryBuildAbstract = buildAbsCB->isChecked();
prefs.queryReplaceAbstract = buildAbsCB->isChecked() && prefs.queryReplaceAbstract = buildAbsCB->isChecked() &&
replAbsCB->isChecked(); replAbsCB->isChecked();
prefs.activeExtraDbs.clear();
for (unsigned int i = 0; i < actDbsLB->count(); i++) {
QListBoxItem *item = actDbsLB->item(i);
if (item)
prefs.activeExtraDbs.push_back((const char *)item->text().local8Bit());
}
prefs.allExtraDbs.clear();
for (unsigned int i = 0; i < allDbsLB->count(); i++) {
QListBoxItem *item = allDbsLB->item(i);
if (item)
prefs.allExtraDbs.push_back((const char *)item->text().local8Bit());
}
rwSettings(true); rwSettings(true);
string reason; string reason;
maybeOpenDb(reason, true); maybeOpenDb(reason, true);
@ -190,10 +208,8 @@ void UIPrefsDialog::showBrowserDialog()
} }
//////////////////////////////////////////// ////////////////////////////////////////////
// External / extra search databases setup: this should modify to take // External / extra search databases setup
// effect only when Ok is clicked. Currently modifs take effect as soon as // TBD: a way to remove entry from 'all' list (del button? )
// done in the Gui
// Also needed: means to remove entry from 'all' list (del button? )
void UIPrefsDialog::extraDbTextChanged(const QString &text) void UIPrefsDialog::extraDbTextChanged(const QString &text)
{ {
@ -204,24 +220,27 @@ void UIPrefsDialog::extraDbTextChanged(const QString &text)
} }
} }
// Add selected dbs to the active list /**
* Add the selected extra dbs to the active list
*/
void UIPrefsDialog::addADbPB_clicked() void UIPrefsDialog::addADbPB_clicked()
{ {
for (unsigned int i = 0; i < allDbsLB->count();i++) { for (unsigned int i = 0; i < allDbsLB->count();i++) {
QListBoxItem *item = allDbsLB->item(i); QListBoxItem *item = allDbsLB->item(i);
if (item && item->isSelected()) { if (item && item->isSelected()) {
allDbsLB->setSelected(i, false); allDbsLB->setSelected(i, false);
string dbname = (const char*)item->text().local8Bit(); if (!actDbsLB->findItem(item->text(),
if (std::find(prefs.activeExtraDbs.begin(), prefs.activeExtraDbs.end(), Qt::CaseSensitive|Qt::ExactMatch)) {
dbname) == prefs.activeExtraDbs.end()) {
actDbsLB->insertItem(item->text()); actDbsLB->insertItem(item->text());
prefs.activeExtraDbs.push_back(dbname);
} }
} }
} }
actDbsLB->sort(); actDbsLB->sort();
} }
/**
* Make all extra dbs active
*/
void UIPrefsDialog::addAADbPB_clicked() void UIPrefsDialog::addAADbPB_clicked()
{ {
for (unsigned int i = 0; i < allDbsLB->count();i++) { for (unsigned int i = 0; i < allDbsLB->count();i++) {
@ -230,19 +249,15 @@ void UIPrefsDialog::addAADbPB_clicked()
addADbPB_clicked(); addADbPB_clicked();
} }
/**
* Remove the selected entries from the list of active extra search dbs
*/
void UIPrefsDialog::delADbPB_clicked() void UIPrefsDialog::delADbPB_clicked()
{ {
list<int> rmi; list<int> rmi;
for (unsigned int i = 0; i < actDbsLB->count(); i++) { for (unsigned int i = 0; i < actDbsLB->count(); i++) {
QListBoxItem *item = actDbsLB->item(i); QListBoxItem *item = actDbsLB->item(i);
if (item && item->isSelected()) { if (item && item->isSelected()) {
string dbname = (const char*)item->text().local8Bit();
list<string>::iterator sit;
if ((sit = ::std::find(prefs.activeExtraDbs.begin(),
prefs.activeExtraDbs.end(), dbname)) !=
prefs.activeExtraDbs.end()) {
prefs.activeExtraDbs.erase(sit);
}
rmi.push_front(i); rmi.push_front(i);
} }
} }
@ -251,6 +266,9 @@ void UIPrefsDialog::delADbPB_clicked()
} }
} }
/**
* Remove all extra search databases from the active list
*/
void UIPrefsDialog::delAADbPB_clicked() void UIPrefsDialog::delAADbPB_clicked()
{ {
for (unsigned int i = 0; i < actDbsLB->count(); i++) { for (unsigned int i = 0; i < actDbsLB->count(); i++) {
@ -259,22 +277,39 @@ void UIPrefsDialog::delAADbPB_clicked()
delADbPB_clicked(); delADbPB_clicked();
} }
/**
* Add the current content of the extra db line editor to the list of all
* extra dbs. We do a textual comparison to check for duplicates, except for
* the main db for which we check inode numbers.
*/
void UIPrefsDialog::addExtraDbPB_clicked() void UIPrefsDialog::addExtraDbPB_clicked()
{ {
string dbdir = (const char *)extraDbLE->text().local8Bit(); string dbdir = (const char *)extraDbLE->text().local8Bit();
path_catslash(dbdir);
if (!Rcl::Db::testDbDir(dbdir)) { if (!Rcl::Db::testDbDir(dbdir)) {
QMessageBox::warning(0, "Recoll", QMessageBox::warning(0, "Recoll",
tr("The selected directory does not appear to be a Xapian database")); tr("The selected directory does not appear to be a Xapian database"));
return; return;
} }
struct stat st1, st2;
if (::std::find(prefs.allExtraDbs.begin(), prefs.allExtraDbs.end(), stat(dbdir.c_str(), &st1);
dbdir) != prefs.allExtraDbs.end()) { string rcldbdir;
if (rcldb)
rcldbdir = rcldb->getDbDir();
stat(rcldbdir.c_str(), &st2);
path_catslash(rcldbdir);
fprintf(stderr, "rcldbdir: [%s]\n", rcldbdir.c_str());
if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
QMessageBox::warning(0, "Recoll",
tr("This is the main/local database!"));
return;
}
if (allDbsLB->findItem(extraDbLE->text(),
Qt::CaseSensitive|Qt::ExactMatch)) {
QMessageBox::warning(0, "Recoll", QMessageBox::warning(0, "Recoll",
tr("The selected directory is already in the database list")); tr("The selected directory is already in the database list"));
return; return;
} }
prefs.allExtraDbs.push_back(dbdir);
allDbsLB->insertItem(extraDbLE->text()); allDbsLB->insertItem(extraDbLE->text());
allDbsLB->sort(); allDbsLB->sort();
} }

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.61 2006-04-05 12:50:42 dockes Exp $ (C) 2004 J.F.Dockes"; static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.62 2006-04-05 13:39:07 dockes Exp $ (C) 2004 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -237,6 +237,13 @@ bool Db::open(const string& dir, OpenMode mode, int qops)
return false; return false;
} }
string Db::getDbDir()
{
if (m_ndb == 0)
return "";
return m_ndb->m_basedir;
}
// Note: xapian has no close call, we delete and recreate the db // Note: xapian has no close call, we delete and recreate the db
bool Db::close() bool Db::close()
{ {

View File

@ -16,7 +16,7 @@
*/ */
#ifndef _DB_H_INCLUDED_ #ifndef _DB_H_INCLUDED_
#define _DB_H_INCLUDED_ #define _DB_H_INCLUDED_
/* @(#$Id: rcldb.h,v 1.29 2006-04-05 12:50:42 dockes Exp $ (C) 2004 J.F.Dockes */ /* @(#$Id: rcldb.h,v 1.30 2006-04-05 13:39:07 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string> #include <string>
#include <list> #include <list>
@ -181,6 +181,7 @@ class Db {
/** Get a list of existing stemming databases */ /** Get a list of existing stemming databases */
std::list<std::string> getStemLangs(); std::list<std::string> getStemLangs();
string getDbDir();
private: private:
AdvSearchData m_asdata; AdvSearchData m_asdata;