use the (should be renamed) history file to store external databases lists

This commit is contained in:
dockes 2006-09-11 09:08:44 +00:00
parent dbe8763140
commit d2d2c73794
9 changed files with 290 additions and 121 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.13 2006-09-08 09:02:47 dockes Exp $ (C) 2005 Jean-Francois Dockes"; static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.14 2006-09-11 09:08:44 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
@ -162,32 +162,26 @@ void rwSettings(bool writing)
// known dbs and active (searched) ones. // known dbs and active (searched) ones.
// When starting up, we also add from the RECOLL_EXTRA_DBS environment // When starting up, we also add from the RECOLL_EXTRA_DBS environment
// variable. // variable.
QStringList qsl; // This are stored inside the dynamic configuration file (aka: history),
// as they are likely to depend on RECOLL_CONFDIR.
const string allEdbsSk = "allExtDbs";
const string actEdbsSk = "actExtDbs";
if (writing) { if (writing) {
LOGDEB(("settings: writing to dynconf\n"));
g_dynconf->eraseAll(allEdbsSk);
for (list<string>::const_iterator it = prefs.allExtraDbs.begin(); for (list<string>::const_iterator it = prefs.allExtraDbs.begin();
it != prefs.allExtraDbs.end(); it++) { it != prefs.allExtraDbs.end(); it++) {
string b64; g_dynconf->enterString(allEdbsSk, *it);
base64_encode(*it, b64);
qsl.push_back(QString::fromAscii(b64.c_str()));
} }
settings.writeEntry("/Recoll/prefs/query/allExtraDbs", qsl);
qsl.clear(); g_dynconf->eraseAll(actEdbsSk);
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++) {
string b64; g_dynconf->enterString(actEdbsSk, *it);
base64_encode(*it, b64);
qsl.push_back(QString::fromAscii(b64.c_str()));
} }
settings.writeEntry("/Recoll/prefs/query/activeExtraDbs", qsl);
} else { } else {
qsl = settings.readListEntry("/Recoll/prefs/query/allExtraDbs"); prefs.allExtraDbs = g_dynconf->getStringList(allEdbsSk);
prefs.allExtraDbs.clear();
for (QStringList::iterator it = qsl.begin(); it != qsl.end(); it++) {
string dec;
base64_decode((*it).ascii(), dec);
prefs.allExtraDbs.push_back(dec);
}
const char *cp; const char *cp;
if ((cp = getenv("RECOLL_EXTRA_DBS")) != 0) { if ((cp = getenv("RECOLL_EXTRA_DBS")) != 0) {
list<string> dbl; list<string> dbl;
@ -207,13 +201,7 @@ void rwSettings(bool writing)
prefs.allExtraDbs.push_back(dbdir); prefs.allExtraDbs.push_back(dbdir);
} }
} }
qsl = settings.readListEntry("/Recoll/prefs/query/activeExtraDbs"); prefs.activeExtraDbs = g_dynconf->getStringList(actEdbsSk);
prefs.activeExtraDbs.clear();
for (QStringList::iterator it = qsl.begin(); it != qsl.end(); it++) {
string dec;
base64_decode((*it).ascii(), dec);
prefs.activeExtraDbs.push_back(dec);
}
} }
#if 0 #if 0

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: main.cpp,v 1.46 2006-09-08 09:02:47 dockes Exp $ (C) 2005 J.F.Dockes"; static char rcsid[] = "@(#$Id: main.cpp,v 1.47 2006-09-11 09:08:44 dockes Exp $ (C) 2005 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
@ -68,6 +68,8 @@ const string recoll_datadir = RECOLL_DATADIR;
RclConfig *rclconfig; RclConfig *rclconfig;
Rcl::Db *rcldb; Rcl::Db *rcldb;
RclHistory *g_dynconf;
int recollNeedsExit; int recollNeedsExit;
static string dbdir; static string dbdir;
static RclMain *mainWindow; static RclMain *mainWindow;
@ -194,7 +196,6 @@ int main(int argc, char **argv)
translatdir.c_str() ); translatdir.c_str() );
app.installTranslator( &translator ); app.installTranslator( &translator );
rwSettings(false);
string reason; string reason;
rclconfig = recollinit(recollCleanup, sigcleanup, reason, &a_config); rclconfig = recollinit(recollCleanup, sigcleanup, reason, &a_config);
@ -205,6 +206,17 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
string historyfile = path_cat(rclconfig->getConfDir(), "history");
g_dynconf = new RclHistory(historyfile);
if (!g_dynconf || !g_dynconf->ok()) {
QString msg = app.translate("Main", "Configuration problem (dynconf");
QMessageBox::critical(0, "Recoll", msg);
exit(1);
}
rwSettings(false);
// Create main window and set its size to previous session's // Create main window and set its size to previous session's
#ifdef WITH_KDE #ifdef WITH_KDE
#if 0 #if 0

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: rclmain.cpp,v 1.28 2006-09-04 15:13:01 dockes Exp $ (C) 2005 J.F.Dockes"; static char rcsid[] = "@(#$Id: rclmain.cpp,v 1.29 2006-09-11 09:08:44 dockes Exp $ (C) 2005 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
@ -91,8 +91,6 @@ void RclMain::init()
QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize); QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize);
resList->setFont(nfont); resList->setFont(nfont);
} }
string historyfile = path_cat(rclconfig->getConfDir(), "history");
m_history = new RclDHistory(historyfile);
connect(sSearch, SIGNAL(startSearch(Rcl::AdvSearchData)), connect(sSearch, SIGNAL(startSearch(Rcl::AdvSearchData)),
this, SLOT(startAdvSearch(Rcl::AdvSearchData))); this, SLOT(startAdvSearch(Rcl::AdvSearchData)));
@ -352,7 +350,6 @@ void RclMain::showAdvSearchDialog()
asearchform = new AdvSearch(0, tr("Advanced search"), FALSE, asearchform = new AdvSearch(0, tr("Advanced search"), FALSE,
WStyle_Customize | WStyle_NormalBorder | WStyle_Customize | WStyle_NormalBorder |
WStyle_Title | WStyle_SysMenu); WStyle_Title | WStyle_SysMenu);
asearchform->setSizeGripEnabled(FALSE);
connect(asearchform, SIGNAL(startSearch(Rcl::AdvSearchData)), connect(asearchform, SIGNAL(startSearch(Rcl::AdvSearchData)),
this, SLOT(startAdvSearch(Rcl::AdvSearchData))); this, SLOT(startAdvSearch(Rcl::AdvSearchData)));
asearchform->show(); asearchform->show();
@ -369,7 +366,6 @@ void RclMain::showSortDialog()
sortform = new SortForm(0, tr("Sort criteria"), FALSE, sortform = new SortForm(0, tr("Sort criteria"), FALSE,
WStyle_Customize | WStyle_NormalBorder | WStyle_Customize | WStyle_NormalBorder |
WStyle_Title | WStyle_SysMenu); WStyle_Title | WStyle_SysMenu);
sortform->setSizeGripEnabled(FALSE);
connect(sortform, SIGNAL(sortDataChanged(RclSortSpec)), connect(sortform, SIGNAL(sortDataChanged(RclSortSpec)),
this, SLOT(sortDataChanged(RclSortSpec))); this, SLOT(sortDataChanged(RclSortSpec)));
sortform->show(); sortform->show();
@ -387,7 +383,6 @@ void RclMain::showUIPrefs()
uiprefs = new UIPrefsDialog(0, tr("User interface preferences"), FALSE, uiprefs = new UIPrefsDialog(0, tr("User interface preferences"), FALSE,
WStyle_Customize | WStyle_NormalBorder | WStyle_Customize | WStyle_NormalBorder |
WStyle_Title | WStyle_SysMenu); WStyle_Title | WStyle_SysMenu);
uiprefs->setSizeGripEnabled(FALSE);
connect(uiprefs, SIGNAL(uiprefsDone()), this, SLOT(setUIPrefs())); connect(uiprefs, SIGNAL(uiprefsDone()), this, SLOT(setUIPrefs()));
uiprefs->show(); uiprefs->show();
} else { } else {
@ -458,7 +453,7 @@ void RclMain::startPreview(int docnum)
} }
(void)curPreview->addEditorTab(); (void)curPreview->addEditorTab();
} }
m_history->enterDocument(fn, doc.ipath); g_dynconf->enterDoc(fn, doc.ipath);
if (!curPreview->loadFileInCurrentTab(fn, st.st_size, doc)) if (!curPreview->loadFileInCurrentTab(fn, st.st_size, doc))
curPreview->closeCurrentTab(); curPreview->closeCurrentTab();
} }
@ -544,7 +539,7 @@ void RclMain::startNativeViewer(int docnum)
QString::fromUtf8(prcmd.c_str()) + "]"; QString::fromUtf8(prcmd.c_str()) + "]";
stb->message(msg, 5000); stb->message(msg, 5000);
} }
m_history->enterDocument(fn, doc.ipath); g_dynconf->enterDoc(fn, doc.ipath);
system(ncmd.c_str()); system(ncmd.c_str());
} }
@ -601,11 +596,12 @@ void RclMain::showDocHistory()
DocSequence *docsource; DocSequence *docsource;
if (sortspecs.sortwidth > 0) { if (sortspecs.sortwidth > 0) {
DocSequenceHistory myseq(rcldb, m_history, string(tr("Document history").utf8())); DocSequenceHistory myseq(rcldb, g_dynconf,
string(tr("Document history").utf8()));
docsource = new DocSeqSorted(myseq, sortspecs, docsource = new DocSeqSorted(myseq, sortspecs,
string(tr("Document history (sorted)").utf8())); string(tr("Document history (sorted)").utf8()));
} else { } else {
docsource = new DocSequenceHistory(rcldb, m_history, docsource = new DocSequenceHistory(rcldb, g_dynconf,
string(tr("Document history").utf8())); string(tr("Document history").utf8()));
} }
Rcl::AdvSearchData sdata; Rcl::AdvSearchData sdata;

View File

@ -71,7 +71,6 @@ private:
SortForm *sortform; SortForm *sortform;
UIPrefsDialog *uiprefs; UIPrefsDialog *uiprefs;
RclSortSpec sortspecs; RclSortSpec sortspecs;
RclDHistory *m_history;
virtual void init(); virtual void init();
}; };

View File

@ -16,12 +16,13 @@
*/ */
#ifndef _RECOLL_H_INCLUDED_ #ifndef _RECOLL_H_INCLUDED_
#define _RECOLL_H_INCLUDED_ #define _RECOLL_H_INCLUDED_
/* @(#$Id: recoll.h,v 1.15 2006-01-31 11:39:12 dockes Exp $ (C) 2004 J.F.Dockes */ /* @(#$Id: recoll.h,v 1.16 2006-09-11 09:08:44 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string> #include <string>
#include "rclconfig.h" #include "rclconfig.h"
#include "rcldb.h" #include "rcldb.h"
#include "idxthread.h" #include "idxthread.h"
#include "history.h"
// Misc declarations in need of sharing between the UI files // Misc declarations in need of sharing between the UI files
@ -32,5 +33,6 @@ extern RclConfig *rclconfig;
extern Rcl::Db *rcldb; extern Rcl::Db *rcldb;
extern int recollNeedsExit; extern int recollNeedsExit;
extern const std::string recoll_datadir; extern const std::string recoll_datadir;
extern RclHistory *g_dynconf;
#endif /* _RECOLL_H_INCLUDED_ */ #endif /* _RECOLL_H_INCLUDED_ */

View File

@ -276,7 +276,7 @@ May be slow for big documents.</string>
<cstring>ExtraDb</cstring> <cstring>ExtraDb</cstring>
</property> </property>
<attribute name="title"> <attribute name="title">
<string>Extra Databases</string> <string>External Databases</string>
</attribute> </attribute>
<vbox> <vbox>
<property name="name"> <property name="name">
@ -352,10 +352,10 @@ May be slow for big documents.</string>
<cstring>textLabel2_2</cstring> <cstring>textLabel2_2</cstring>
</property> </property>
<property name="text"> <property name="text">
<string>All extra databases</string> <string>All databases</string>
</property> </property>
<property name="toolTip" stdset="0"> <property name="toolTip" stdset="0">
<string>All known extra databases</string> <string>Databases currently not used</string>
</property> </property>
</widget> </widget>
<widget class="QListBox"> <widget class="QListBox">
@ -456,10 +456,10 @@ May be slow for big documents.</string>
<cstring>textLabel3</cstring> <cstring>textLabel3</cstring>
</property> </property>
<property name="text"> <property name="text">
<string>Active extra databases</string> <string>Active databases</string>
</property> </property>
<property name="toolTip" stdset="0"> <property name="toolTip" stdset="0">
<string>Extra databases that will be searched in addition to the main one</string> <string>Databases that will be searched in addition to the main one</string>
</property> </property>
</widget> </widget>
<widget class="QListBox"> <widget class="QListBox">

View File

@ -16,7 +16,7 @@
*/ */
#ifndef _DOCSEQ_H_INCLUDED_ #ifndef _DOCSEQ_H_INCLUDED_
#define _DOCSEQ_H_INCLUDED_ #define _DOCSEQ_H_INCLUDED_
/* @(#$Id: docseq.h,v 1.7 2006-02-21 12:52:48 dockes Exp $ (C) 2004 J.F.Dockes */ /* @(#$Id: docseq.h,v 1.8 2006-09-11 09:08:44 dockes Exp $ (C) 2004 J.F.Dockes */
#include "rcldb.h" #include "rcldb.h"
#include "history.h" #include "history.h"
@ -71,7 +71,7 @@ class DocSequenceDb : public DocSequence {
/** A DocSequence coming from the history file */ /** A DocSequence coming from the history file */
class DocSequenceHistory : public DocSequence { class DocSequenceHistory : public DocSequence {
public: public:
DocSequenceHistory(Rcl::Db *d, RclDHistory *h, const std::string &t) DocSequenceHistory(Rcl::Db *d, RclHistory *h, const std::string &t)
: DocSequence(t), m_db(d), m_hist(h), m_prevnum(-1), m_prevtime(-1) {} : DocSequence(t), m_db(d), m_hist(h), m_prevnum(-1), m_prevtime(-1) {}
virtual ~DocSequenceHistory() {} virtual ~DocSequenceHistory() {}
@ -79,7 +79,7 @@ class DocSequenceHistory : public DocSequence {
virtual int getResCnt(); virtual int getResCnt();
private: private:
Rcl::Db *m_db; Rcl::Db *m_db;
RclDHistory *m_hist; RclHistory *m_hist;
int m_prevnum; int m_prevnum;
long m_prevtime; long m_prevtime;

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: history.cpp,v 1.5 2006-01-23 13:32:28 dockes Exp $ (C) 2005 J.F.Dockes"; static char rcsid[] = "@(#$Id: history.cpp,v 1.6 2006-09-11 09:08:44 dockes Exp $ (C) 2005 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
@ -33,66 +33,83 @@ using namespace std;
static const char *docSubkey = "docs"; static const char *docSubkey = "docs";
RclDHistory::RclDHistory(const string &fn, unsigned int mxs) // Encode/decode document history entry: Unix time + base64 of fn +
: m_mlen(mxs), m_data(fn.c_str()) // base64 of ipath separated by a space. If ipath is not set, there
// are only 2 parts
bool RclDHistoryEntry::encode(string& value)
{ {
char chartime[20];
sprintf(chartime, "%ld", unixtime);
string bfn, bipath;
base64_encode(fn, bfn);
base64_encode(ipath, bipath);
value = string(chartime) + " " + bfn + " " + bipath;
return true;
} }
bool RclDHistoryEntry::decode(const string &value)
bool RclDHistory::decodeValue(const string &value, RclDHistoryEntry *e)
{ {
list<string> vall; list<string> vall;
stringToStrings(value, vall); stringToStrings(value, vall);
list<string>::const_iterator it1 = vall.begin(); list<string>::const_iterator it1 = vall.begin();
if (vall.size() < 2) if (vall.size() < 2)
return false; return false;
e->unixtime = atol((*it1++).c_str()); unixtime = atol((*it1++).c_str());
base64_decode(*it1++, e->fn); base64_decode(*it1++, fn);
if (vall.size() == 3) if (vall.size() == 3)
base64_decode(*it1, e->ipath); base64_decode(*it1, ipath);
else else
e->ipath.erase(); ipath.erase();
return true; return true;
} }
bool RclDHistoryEntry::equal(const HistoryEntry& other)
bool RclDHistory::enterDocument(const string fn, const string ipath)
{ {
LOGDEB(("RclDHistory::enterDocument: [%s] [%s] into %s\n", const RclDHistoryEntry& e = dynamic_cast<const RclDHistoryEntry&>(other);
fn.c_str(), ipath.c_str(), m_data.getFilename().c_str())); return e.fn == fn && e.ipath == ipath;
// Encode value part: Unix time + base64 of fn + base64 of ipath }
// separated by a space. If ipath is not set, there are only 2 parts
char chartime[20];
time_t now = time(0);
sprintf(chartime, "%ld", (long)now);
string bfn, bipath;
base64_encode(fn, bfn);
base64_encode(ipath, bipath);
string value = string(chartime) + " " + bfn + " " + bipath;
LOGDEB1(("Encoded value [%s] (%d)\n", value.c_str(), value.size())); // Encode/decode simple string. base64 used to avoid problems with
// strange chars
bool RclSListEntry::encode(string& enc)
{
base64_encode(value, enc);
return true;
}
bool RclSListEntry::decode(const string &enc)
{
base64_decode(enc, value);
return true;
}
bool RclSListEntry::equal(const HistoryEntry& other)
{
const RclSListEntry& e = dynamic_cast<const RclSListEntry&>(other);
return e.value == value;
}
bool RclHistory::insertNew(const string &sk, HistoryEntry &n, HistoryEntry &s)
{
// Is this doc already in history ? If it is we remove the old entry // Is this doc already in history ? If it is we remove the old entry
list<string> names = m_data.getNames(docSubkey); list<string> names = m_data.getNames(sk);
list<string>::const_iterator it; list<string>::const_iterator it;
bool changed = false; bool changed = false;
for (it = names.begin(); it != names.end(); it++) { for (it = names.begin(); it != names.end(); it++) {
string oval; string oval;
if (!m_data.get(*it, oval, docSubkey)) { if (!m_data.get(*it, oval, sk)) {
LOGDEB(("No data for %s\n", (*it).c_str())); LOGDEB(("No data for %s\n", (*it).c_str()));
continue; continue;
} }
RclDHistoryEntry entry; s.decode(oval);
decodeValue(oval, &entry);
if (entry.fn == fn && entry.ipath == ipath) { if (s.equal(n)) {
LOGDEB(("Erasing old entry\n")); LOGDEB(("Erasing old entry\n"));
m_data.erase(*it, docSubkey); m_data.erase(*it, sk);
changed = true; changed = true;
} }
} }
// Maybe reget list // Maybe reget list
if (changed) if (changed)
names = m_data.getNames(docSubkey); names = m_data.getNames(sk);
// How many do we have // How many do we have
if (names.size() >= m_mlen) { if (names.size() >= m_mlen) {
@ -101,7 +118,7 @@ bool RclDHistory::enterDocument(const string fn, const string ipath)
// history is 4 billion entries old // history is 4 billion entries old
it = names.begin(); it = names.begin();
for (unsigned int i = 0; i < names.size() - m_mlen + 1; i++, it++) { for (unsigned int i = 0; i < names.size() - m_mlen + 1; i++, it++) {
m_data.erase(*it, docSubkey); m_data.erase(*it, sk);
} }
} }
@ -112,33 +129,65 @@ bool RclDHistory::enterDocument(const string fn, const string ipath)
char nname[20]; char nname[20];
sprintf(nname, "%010u", hi); sprintf(nname, "%010u", hi);
if (!m_data.set(string(nname), value, docSubkey)) { string value;
LOGERR(("RclDHistory::enterDocument: set failed\n")); n.encode(value);
LOGDEB1(("Encoded value [%s] (%d)\n", value.c_str(), value.size()));
if (!m_data.set(string(nname), value, sk)) {
LOGERR(("RclDHistory::insertNew: set failed\n"));
return false; return false;
} }
return true; return true;
}
bool RclHistory::eraseAll(const string &sk)
{
// Is this doc already in history ? If it is we remove the old entry
list<string> names = m_data.getNames(sk);
list<string>::const_iterator it;
for (it = names.begin(); it != names.end(); it++) {
m_data.erase(*it, sk);
}
return true;
} }
list<RclDHistoryEntry> RclDHistory::getDocHistory()
bool RclHistory::enterString(const string sk, const string value)
{ {
list<RclDHistoryEntry> mlist; RclSListEntry ne(value);
RclDHistoryEntry entry; RclSListEntry scratch;
list<string> names = m_data.getNames(docSubkey); return insertNew(sk, ne, scratch);
for (list<string>::const_iterator it = names.begin();
it != names.end(); it++) {
string value;
if (m_data.get(*it, value, docSubkey)) {
if (!decodeValue(value, &entry))
continue;
mlist.push_front(entry);
}
}
return mlist;
} }
list<string> RclHistory::getStringList(const string sk)
{
list<RclSListEntry> el = getHistory<RclSListEntry>(sk);
list<string> sl;
for (list<RclSListEntry>::const_iterator it = el.begin();
it != el.end(); it++)
sl.push_back(it->value);
return sl;
}
/// *************** History entries specific methods
bool RclHistory::enterDoc(const string fn, const string ipath)
{
LOGDEB(("RclDHistory::enterDoc: [%s] [%s] into %s\n",
fn.c_str(), ipath.c_str(), m_data.getFilename().c_str()));
RclDHistoryEntry ne(time(0), fn, ipath);
RclDHistoryEntry scratch;
return insertNew(docSubkey, ne, scratch);
}
list<RclDHistoryEntry> RclHistory::getDocHistory()
{
return getHistory<RclDHistoryEntry>(docSubkey);
}
#else #else
#include <string> #include <string>
#include <iostream>
#include "history.h" #include "history.h"
#include "debuglog.h" #include "debuglog.h"
@ -147,22 +196,71 @@ list<RclDHistoryEntry> RclDHistory::getDocHistory()
using namespace std; using namespace std;
#endif #endif
static string thisprog;
static string usage =
" [-e] [-s <subkey>]"
" \n\n"
;
static void
Usage(void)
{
cerr << thisprog << ": usage:\n" << usage;
exit(1);
}
static int op_flags;
#define OPT_e 0x2
#define OPT_s 0x4
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
RclDHistory hist("toto", 5); string sk = "docs";
thisprog = argv[0];
argc--; argv++;
while (argc > 0 && **argv == '-') {
(*argv)++;
if (!(**argv))
/* Cas du "adb - core" */
Usage();
while (**argv)
switch (*(*argv)++) {
case 's': op_flags |= OPT_s; if (argc < 2) Usage();
sk = *(++argv);
argc--;
goto b1;
case 'e': op_flags |= OPT_e; break;
default: Usage(); break;
}
b1: argc--; argv++;
}
if (argc != 0)
Usage();
RclHistory hist("toto", 5);
DebugLog::getdbl()->setloglevel(DEBDEB1); DebugLog::getdbl()->setloglevel(DEBDEB1);
DebugLog::setfilename("stderr"); DebugLog::setfilename("stderr");
for (int i = 0; i < 10; i++) { if (op_flags & OPT_e) {
char docname[100]; hist.eraseAll(sk);
sprintf(docname, "A very long document document name is very long indeed and this is the end of it here and exactly here:\n%d", i); } else {
hist.enterDocument(string(docname), "ipathx"); for (int i = 0; i < 10; i++) {
} char docname[100];
sprintf(docname, "A very long document document name"
"is very long indeed and this is the end of "
"it here and exactly here:\n%d", i);
hist.enterDoc(string(docname), "ipathx");
}
list< pair<string, string> > hlist = hist.getDocHistory(); list<RclDHistoryEntry> hlist = hist.getDocHistory();
for (list< pair<string, string> >::const_iterator it = hlist.begin(); for (list<RclDHistoryEntry>::const_iterator it = hlist.begin();
it != hlist.end(); it++) { it != hlist.end(); it++) {
printf("[%s] [%s]\n", it->first.c_str(), it->second.c_str()); printf("[%ld] [%s] [%s]\n", it->unixtime,
it->fn.c_str(), it->ipath.c_str());
}
} }
} }

View File

@ -16,7 +16,23 @@
*/ */
#ifndef _HISTORY_H_INCLUDED_ #ifndef _HISTORY_H_INCLUDED_
#define _HISTORY_H_INCLUDED_ #define _HISTORY_H_INCLUDED_
/* @(#$Id: history.h,v 1.3 2006-01-30 11:15:28 dockes Exp $ (C) 2004 J.F.Dockes */ /* @(#$Id: history.h,v 1.4 2006-09-11 09:08:44 dockes Exp $ (C) 2004 J.F.Dockes */
/**
* Dynamic configuration storage
*
* The term "history" is a misnomer as this code is now used to save
* all dynamic parameters except those that are stored in the global
* recollrc QT preferences file. Examples:
* - History of documents selected for preview
* - Active and inactive external databases (these should depend on the
* configuration directory and cant be stored in recollrc).
* - ...
*
* The storage is performed in a ConSimple file, with subkeys and
* encodings which depend on the data stored.
*
*/
#include <string> #include <string>
#include <list> #include <list>
@ -24,32 +40,90 @@
#include "conftree.h" #include "conftree.h"
/** Holder for data returned when querying history */ #ifndef NO_NAMESPACES
class RclDHistoryEntry { using namespace std;
#endif
class HistoryEntry {
public:
virtual bool decode(const string &value) = 0;
virtual bool encode(string& value) = 0;
virtual bool equal(const HistoryEntry &other) = 0;
};
/** Document history entry */
class RclDHistoryEntry : public HistoryEntry {
public: public:
RclDHistoryEntry() : unixtime(0) {} RclDHistoryEntry() : unixtime(0) {}
RclDHistoryEntry(long t, const string& f, const string& i)
: unixtime(t), fn(f), ipath(i) {}
virtual ~RclDHistoryEntry() {}
virtual bool decode(const string &value);
virtual bool encode(string& value);
virtual bool equal(const HistoryEntry& other);
long unixtime; long unixtime;
string fn; string fn;
string ipath; string ipath;
}; };
/**
* The documents history class. This is based on a ConfTree for no /** String storage generic object */
* imperative reason class RclSListEntry : public HistoryEntry {
*/
class RclDHistory {
public: public:
RclDHistory(const std::string &fn, unsigned int maxsize=1000); RclSListEntry() {}
bool ok() {return m_data.getStatus() == ConfSimple::STATUS_RW;} RclSListEntry(const string& v) : value(v) {}
virtual ~RclSListEntry() {}
virtual bool decode(const string &enc);
virtual bool encode(string& enc);
virtual bool equal(const HistoryEntry& other);
bool enterDocument(const std::string fn, const std::string ipath); string value;
std::list<RclDHistoryEntry> getDocHistory();
private:
bool decodeValue(const string &value, RclDHistoryEntry *e);
unsigned int m_mlen;
ConfSimple m_data;
}; };
/**
* The history class. This uses a ConfSimple for storage, and should be
* renamed something like dynconf, as it is used to stored quite a few
* things beyond doc history: all dynamic configuration parameters that are
* not suitable for QT settings because they are specific to a RECOLL_CONFDIR
*/
class RclHistory {
public:
RclHistory(const string &fn, unsigned int maxsize=100)
: m_mlen(maxsize), m_data(fn.c_str()) {}
bool ok() {return m_data.getStatus() == ConfSimple::STATUS_RW;}
// Specific methods for history entries
bool enterDoc(const string fn, const string ipath);
list<RclDHistoryEntry> getDocHistory();
// Generic methods used for string lists, designated by the subkey value
bool enterString(const string sk, const string value);
list<string> getStringList(const string sk);
bool eraseAll(const string& sk);
private:
unsigned int m_mlen;
ConfSimple m_data;
bool insertNew(const string& sk, HistoryEntry &n, HistoryEntry &s);
template<typename Tp> list<Tp> getHistory(const string& sk);
};
template<typename Tp> list<Tp> RclHistory::getHistory(const string &sk)
{
list<Tp> mlist;
Tp entry;
list<string> names = m_data.getNames(sk);
for (list<string>::const_iterator it = names.begin();
it != names.end(); it++) {
string value;
if (m_data.get(*it, value, sk)) {
if (!entry.decode(value))
continue;
mlist.push_front(entry);
}
}
return mlist;
}
#endif /* _HISTORY_H_INCLUDED_ */ #endif /* _HISTORY_H_INCLUDED_ */