Cleaned up the dynconf/history code by using a container template
This commit is contained in:
@@ -79,10 +79,12 @@ bool AdvSearchHist::read()
|
||||
{
|
||||
if (!g_dynconf)
|
||||
return false;
|
||||
list<string> lxml = g_dynconf->getStringList(advSearchHistSk);
|
||||
|
||||
for (list<string>::const_iterator it = lxml.begin(); it != lxml.end();
|
||||
it++) {
|
||||
|
||||
// getStringEntries() return the entries in order (lower key
|
||||
// first), but we want most recent first, so revert
|
||||
vector<string> lxml =
|
||||
g_dynconf->getStringEntries<vector>(advSearchHistSk);
|
||||
for (auto it = lxml.rbegin(); it != lxml.rend(); it++) {
|
||||
std::shared_ptr<SearchData> sd = xmlToSearchData(*it);
|
||||
if (sd)
|
||||
m_entries.push_back(sd);
|
||||
|
||||
+21
-21
@@ -316,19 +316,17 @@ void rwSettings(bool writing)
|
||||
// as they are likely to depend on RECOLL_CONFDIR.
|
||||
if (writing) {
|
||||
g_dynconf->eraseAll(allEdbsSk);
|
||||
for (list<string>::const_iterator it = prefs.allExtraDbs.begin();
|
||||
it != prefs.allExtraDbs.end(); it++) {
|
||||
g_dynconf->enterString(allEdbsSk, *it);
|
||||
for (const auto& dbdir : prefs.allExtraDbs) {
|
||||
g_dynconf->enterString(allEdbsSk, dbdir);
|
||||
}
|
||||
|
||||
g_dynconf->eraseAll(actEdbsSk);
|
||||
for (list<string>::const_iterator it = prefs.activeExtraDbs.begin();
|
||||
it != prefs.activeExtraDbs.end(); it++) {
|
||||
g_dynconf->enterString(actEdbsSk, *it);
|
||||
for (const auto& dbdir : prefs.activeExtraDbs) {
|
||||
g_dynconf->enterString(actEdbsSk, dbdir);
|
||||
|
||||
}
|
||||
} else {
|
||||
prefs.allExtraDbs = g_dynconf->getStringList(allEdbsSk);
|
||||
prefs.allExtraDbs = g_dynconf->getStringEntries<vector>(allEdbsSk);
|
||||
const char *cp;
|
||||
if ((cp = getenv("RECOLL_EXTRA_DBS")) != 0) {
|
||||
vector<string> dbl;
|
||||
@@ -337,17 +335,18 @@ void rwSettings(bool writing)
|
||||
dit++) {
|
||||
string dbdir = path_canon(*dit);
|
||||
path_catslash(dbdir);
|
||||
if (std::find(prefs.allExtraDbs.begin(),
|
||||
prefs.allExtraDbs.end(), dbdir) !=
|
||||
if (std::find(prefs.allExtraDbs.begin(),
|
||||
prefs.allExtraDbs.end(), dbdir) !=
|
||||
prefs.allExtraDbs.end())
|
||||
continue;
|
||||
bool stripped;
|
||||
if (!Rcl::Db::testDbDir(dbdir, &stripped)) {
|
||||
LOGERR("Not a xapian index: [" << (dbdir) << "]\n" );
|
||||
LOGERR("Not a xapian index: [" << dbdir << "]\n");
|
||||
continue;
|
||||
}
|
||||
if (stripped != o_index_stripchars) {
|
||||
LOGERR("Incompatible character stripping: [" << (dbdir) << "]\n" );
|
||||
LOGERR("Incompatible character stripping: [" << dbdir <<
|
||||
"]\n");
|
||||
continue;
|
||||
}
|
||||
prefs.allExtraDbs.push_back(dbdir);
|
||||
@@ -355,16 +354,17 @@ void rwSettings(bool writing)
|
||||
}
|
||||
|
||||
// Get the remembered "active external indexes":
|
||||
prefs.activeExtraDbs = g_dynconf->getStringList(actEdbsSk);
|
||||
prefs.activeExtraDbs = g_dynconf->getStringEntries<vector>(actEdbsSk);
|
||||
|
||||
// Clean up the list: remove directories which are not
|
||||
// actually there: useful for removable volumes.
|
||||
for (list<string>::iterator it = prefs.activeExtraDbs.begin();
|
||||
it != prefs.activeExtraDbs.end();) {
|
||||
for (auto it = prefs.activeExtraDbs.begin();
|
||||
it != prefs.activeExtraDbs.end();) {
|
||||
bool stripped;
|
||||
if (!Rcl::Db::testDbDir(*it, &stripped) ||
|
||||
stripped != o_index_stripchars) {
|
||||
LOGINFO("Not a Xapian index or char stripping differs: [" << *it << "]\n" );
|
||||
LOGINFO("Not a Xapian index or char stripping differs: [" <<
|
||||
*it << "]\n");
|
||||
it = prefs.activeExtraDbs.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
@@ -418,14 +418,14 @@ void rwSettings(bool writing)
|
||||
while (prefs.asearchSubdirHist.size() > 20)
|
||||
prefs.asearchSubdirHist.pop_back();
|
||||
g_dynconf->eraseAll(asbdSk);
|
||||
for (QStringList::iterator it = prefs.asearchSubdirHist.begin();
|
||||
it != prefs.asearchSubdirHist.end(); it++) {
|
||||
g_dynconf->enterString(asbdSk, (const char *)((*it).toUtf8()));
|
||||
for (const auto& qdbd : prefs.asearchSubdirHist) {
|
||||
g_dynconf->enterString(asbdSk, qs2utf8s(qdbd));
|
||||
}
|
||||
} else {
|
||||
list<string> tl = g_dynconf->getStringList(asbdSk);
|
||||
for (list<string>::iterator it = tl.begin(); it != tl.end(); it++)
|
||||
prefs.asearchSubdirHist.push_front(QString::fromUtf8(it->c_str()));
|
||||
vector<string> tl = g_dynconf->getStringEntries<vector>(asbdSk);
|
||||
for (const auto& dbd: tl) {
|
||||
prefs.asearchSubdirHist.push_back(u8s2qs(dbd.c_str()));
|
||||
}
|
||||
}
|
||||
if (!writing)
|
||||
havereadsettings = true;
|
||||
|
||||
@@ -99,8 +99,8 @@ class PrefsPack {
|
||||
bool showResultsAsTable;
|
||||
|
||||
// Extra query indexes. This are stored in the history file, not qt prefs
|
||||
list<string> allExtraDbs;
|
||||
list<string> activeExtraDbs;
|
||||
vector<string> allExtraDbs;
|
||||
vector<string> activeExtraDbs;
|
||||
// Advanced search subdir restriction: we don't activate the last value
|
||||
// but just remember previously entered values
|
||||
QStringList asearchSubdirHist;
|
||||
|
||||
+3
-4
@@ -101,10 +101,9 @@ bool maybeOpenDb(string &reason, bool force, bool *maindberror)
|
||||
if (force)
|
||||
rcldb->close();
|
||||
rcldb->rmQueryDb("");
|
||||
for (list<string>::const_iterator it = prefs.activeExtraDbs.begin();
|
||||
it != prefs.activeExtraDbs.end(); it++) {
|
||||
LOGDEB("main: adding [" << *it << "]\n" );
|
||||
rcldb->addQueryDb(*it);
|
||||
for (const auto& dbdir : prefs.activeExtraDbs) {
|
||||
LOGDEB("main: adding [" << dbdir << "]\n");
|
||||
rcldb->addQueryDb(dbdir);
|
||||
}
|
||||
Rcl::Db::OpenError error;
|
||||
if (!rcldb->isopen() && !rcldb->open(Rcl::Db::DbRO, &error)) {
|
||||
|
||||
@@ -300,9 +300,8 @@ bool SSearch::startSimpleSearch(const string& u8, int maxexp)
|
||||
sdata->setMaxExpand(maxexp);
|
||||
}
|
||||
|
||||
for (list<string>::const_iterator it = prefs.activeExtraDbs.begin();
|
||||
it != prefs.activeExtraDbs.end(); it++) {
|
||||
xml << " <EX>" << base64_encode(*it) << "</EX>";
|
||||
for (const auto& dbdir : prefs.activeExtraDbs) {
|
||||
xml << " <EX>" << base64_encode(dbdir) << "</EX>";
|
||||
}
|
||||
|
||||
xml << "</SD>\n";
|
||||
|
||||
+8
-12
@@ -231,22 +231,18 @@ void UIPrefsDialog::setFromPrefs()
|
||||
|
||||
// Initialize the extra indexes listboxes
|
||||
idxLV->clear();
|
||||
for (list<string>::iterator it = prefs.allExtraDbs.begin();
|
||||
it != prefs.allExtraDbs.end(); it++) {
|
||||
for (const auto& dbdir : prefs.allExtraDbs) {
|
||||
QListWidgetItem *item =
|
||||
new QListWidgetItem(QString::fromLocal8Bit(it->c_str()),
|
||||
idxLV);
|
||||
new QListWidgetItem(QString::fromLocal8Bit(dbdir.c_str()), idxLV);
|
||||
if (item)
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
for (list<string>::iterator it = prefs.activeExtraDbs.begin();
|
||||
it != prefs.activeExtraDbs.end(); it++) {
|
||||
QList<QListWidgetItem *>items =
|
||||
idxLV->findItems (QString::fromLocal8Bit(it->c_str()),
|
||||
Qt::MatchFixedString|Qt::MatchCaseSensitive);
|
||||
for (QList<QListWidgetItem *>::iterator it = items.begin();
|
||||
it != items.end(); it++) {
|
||||
(*it)->setCheckState(Qt::Checked);
|
||||
for (const auto& dbdir : prefs.activeExtraDbs) {
|
||||
auto items =
|
||||
idxLV->findItems (QString::fromLocal8Bit(dbdir.c_str()),
|
||||
Qt::MatchFixedString|Qt::MatchCaseSensitive);
|
||||
for (auto& entry : items) {
|
||||
entry->setCheckState(Qt::Checked);
|
||||
}
|
||||
}
|
||||
idxLV->sortItems();
|
||||
|
||||
Reference in New Issue
Block a user