diff --git a/src/qtgui/guiutils.cpp b/src/qtgui/guiutils.cpp index 5c077483..225634eb 100644 --- a/src/qtgui/guiutils.cpp +++ b/src/qtgui/guiutils.cpp @@ -1,5 +1,5 @@ #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 /* * 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::const_iterator it; fprintf(stderr, "All extra Dbs:\n"); diff --git a/src/qtgui/uiprefs.ui b/src/qtgui/uiprefs.ui index e73cfe74..434d3553 100644 --- a/src/qtgui/uiprefs.ui +++ b/src/qtgui/uiprefs.ui @@ -290,7 +290,7 @@ May be slow for big documents. Add database - Select the recoll.conf file defining the database you want to add, then click Add Database + Select the xapiandb directory for the database you want to add, then click Add Database @@ -304,7 +304,7 @@ May be slow for big documents. - Select the recoll.conf file defining the database you want to add, then click Add Database + Select the xapiandb directory for the database you want to add, then click Add Database @@ -315,7 +315,7 @@ May be slow for big documents. Browse - Select the recoll.conf file defining the database you want to add, then click Add Database + Select the xapiandb directory for the database you want to add, then click Add Database diff --git a/src/qtgui/uiprefs.ui.h b/src/qtgui/uiprefs.ui.h index 1cef1cbd..ba425c56 100644 --- a/src/qtgui/uiprefs.ui.h +++ b/src/qtgui/uiprefs.ui.h @@ -25,6 +25,8 @@ ** These will automatically be called by the form's constructor and ** destructor. *****************************************************************************/ +#include + #include #include #include @@ -37,6 +39,7 @@ #include "recoll.h" #include "guiutils.h" #include "rcldb.h" +#include "pathut.h" void UIPrefsDialog::init() { @@ -135,6 +138,21 @@ void UIPrefsDialog::accept() prefs.queryBuildAbstract = buildAbsCB->isChecked(); prefs.queryReplaceAbstract = buildAbsCB->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); string reason; maybeOpenDb(reason, true); @@ -190,10 +208,8 @@ void UIPrefsDialog::showBrowserDialog() } //////////////////////////////////////////// -// External / extra search databases setup: this should modify to take -// effect only when Ok is clicked. Currently modifs take effect as soon as -// done in the Gui -// Also needed: means to remove entry from 'all' list (del button? ) +// External / extra search databases setup +// TBD: a way to remove entry from 'all' list (del button? ) 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() { for (unsigned int i = 0; i < allDbsLB->count();i++) { QListBoxItem *item = allDbsLB->item(i); if (item && item->isSelected()) { allDbsLB->setSelected(i, false); - string dbname = (const char*)item->text().local8Bit(); - if (std::find(prefs.activeExtraDbs.begin(), prefs.activeExtraDbs.end(), - dbname) == prefs.activeExtraDbs.end()) { + if (!actDbsLB->findItem(item->text(), + Qt::CaseSensitive|Qt::ExactMatch)) { actDbsLB->insertItem(item->text()); - prefs.activeExtraDbs.push_back(dbname); } } } actDbsLB->sort(); } +/** + * Make all extra dbs active + */ void UIPrefsDialog::addAADbPB_clicked() { for (unsigned int i = 0; i < allDbsLB->count();i++) { @@ -230,19 +249,15 @@ void UIPrefsDialog::addAADbPB_clicked() addADbPB_clicked(); } +/** + * Remove the selected entries from the list of active extra search dbs + */ void UIPrefsDialog::delADbPB_clicked() { list rmi; for (unsigned int i = 0; i < actDbsLB->count(); i++) { QListBoxItem *item = actDbsLB->item(i); if (item && item->isSelected()) { - string dbname = (const char*)item->text().local8Bit(); - list::iterator sit; - if ((sit = ::std::find(prefs.activeExtraDbs.begin(), - prefs.activeExtraDbs.end(), dbname)) != - prefs.activeExtraDbs.end()) { - prefs.activeExtraDbs.erase(sit); - } 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() { for (unsigned int i = 0; i < actDbsLB->count(); i++) { @@ -259,22 +277,39 @@ void UIPrefsDialog::delAADbPB_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() { string dbdir = (const char *)extraDbLE->text().local8Bit(); + path_catslash(dbdir); if (!Rcl::Db::testDbDir(dbdir)) { 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; } - - if (::std::find(prefs.allExtraDbs.begin(), prefs.allExtraDbs.end(), - dbdir) != prefs.allExtraDbs.end()) { + struct stat st1, st2; + stat(dbdir.c_str(), &st1); + 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", tr("The selected directory is already in the database list")); return; } - prefs.allExtraDbs.push_back(dbdir); allDbsLB->insertItem(extraDbLE->text()); allDbsLB->sort(); } diff --git a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp index aba34990..a213939f 100644 --- a/src/rcldb/rcldb.cpp +++ b/src/rcldb/rcldb.cpp @@ -1,5 +1,5 @@ #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 /* * 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; } +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 bool Db::close() { diff --git a/src/rcldb/rcldb.h b/src/rcldb/rcldb.h index 0b2599c0..4c2b8227 100644 --- a/src/rcldb/rcldb.h +++ b/src/rcldb/rcldb.h @@ -16,7 +16,7 @@ */ #ifndef _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 #include @@ -181,6 +181,7 @@ class Db { /** Get a list of existing stemming databases */ std::list getStemLangs(); + string getDbDir(); private: AdvSearchData m_asdata;