From 30bf4052f882270d4dcc0066f0b37ab33830abdc Mon Sep 17 00:00:00 2001 From: dockes Date: Fri, 25 Nov 2005 14:36:46 +0000 Subject: [PATCH] show history newest first + prune duplicate entries --- src/qtgui/recollmain.ui.h | 20 +++++++++-- src/query/history.cpp | 72 +++++++++++++++++++++++++++------------ src/utils/conftree.cpp | 18 ++-------- src/utils/smallut.cpp | 16 ++++++++- src/utils/smallut.h | 6 +++- 5 files changed, 90 insertions(+), 42 deletions(-) diff --git a/src/qtgui/recollmain.ui.h b/src/qtgui/recollmain.ui.h index 27196574..6ddda70a 100644 --- a/src/qtgui/recollmain.ui.h +++ b/src/qtgui/recollmain.ui.h @@ -239,6 +239,18 @@ static string urltolocalpath(string url) { return url.substr(7, string::npos); } +// Translate paragraph number in list window to doc number. This depends on +// how we format the title etc.. +static int reldocnumfromparnum(int par) +{ + return par - 2; +} +// Translate paragraph number in list window to doc number. This depends on +// how we format the title etc.. +static int parnumfromreldocnum(int docnum) +{ + return docnum + 2; +} // Double click in result list: use external viewer to display file void RecollMain::reslistTE_doubleClicked(int par, int) @@ -247,7 +259,7 @@ void RecollMain::reslistTE_doubleClicked(int par, int) reslist_dblclck = true; Rcl::Doc doc; - int reldocnum = par - 1; + int reldocnum = reldocnumfromparnum(par); if (!docsource->getDoc(reslist_winfirst + reldocnum, doc, 0)) return; @@ -332,12 +344,14 @@ void RecollMain::reslistTE_delayedclick() if (reslist_current != -1) { QColor color("white"); - reslistTE->setParagraphBackgroundColor(reslist_current+1, color); + reslistTE-> + setParagraphBackgroundColor(parnumfromreldocnum(reslist_current), + color); } QColor color("lightblue"); reslistTE->setParagraphBackgroundColor(par, color); - int reldocnum = par - 1; + int reldocnum = reldocnumfromparnum(par); if (curPreview && reslist_current == reldocnum) return; diff --git a/src/query/history.cpp b/src/query/history.cpp index 2cd149fa..3e3bc8e1 100644 --- a/src/query/history.cpp +++ b/src/query/history.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: history.cpp,v 1.1 2005-11-24 18:21:55 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: history.cpp,v 1.2 2005-11-25 14:36:45 dockes Exp $ (C) 2005 J.F.Dockes"; #endif #ifndef TEST_HISTORY @@ -24,29 +24,59 @@ bool RclQHistory::enterDocument(const string fn, const string ipath) { LOGDEB(("RclQHistory::enterDocument: [%s] [%s] into %s\n", fn.c_str(), ipath.c_str(), m_data.getFilename().c_str())); - // How many do we have - list names = m_data.getNames(docSubkey); - list::const_iterator it = names.begin(); - if (names.size() >= m_mlen) { - // Need to erase entries until we're back to size. Note that - // we don't ever erase anything. Problems will arise when - // history is 2 billion entries old - for (unsigned int i = 0; i < names.size() - m_mlen + 1; i++, it++) { - m_data.erase(*it, docSubkey); - it++; - } - } - - // Increment highest number - int hi = names.empty() ? 0 : atoi(names.back().c_str()); - hi++; - char nname[20]; - sprintf(nname, "%010d", hi); - + //Encode value part: 2 base64 of fn and ipath separated by a space string bfn, bipath; base64_encode(fn, bfn); base64_encode(ipath, bipath); string value = bfn + " " + bipath; + + // We trim whitespace from the value (if there is no ipath it now + // ends with a space), else the value later returned by conftree + // will be different because conftree does trim white space, and + // this breaks the comparisons below + trimstring(value); + + LOGDEB1(("Encoded value [%s] (%d)\n", value.c_str(), value.size())); + // Is this doc already in history ? If it is we remove the old entry + list names = m_data.getNames(docSubkey); + list::const_iterator it; + bool changed = false; + for (it = names.begin();it != names.end(); it++) { + string oval; + if (!m_data.get(*it, oval, docSubkey)) { + LOGDEB(("No data for %s\n", (*it).c_str())); + continue; + } + LOGDEB1(("Look at %s [%s] (%d)\n", + (*it).c_str(), oval.c_str(), oval.length())); + if (oval == value) { + LOGDEB1(("Erasing old entry\n")); + m_data.erase(*it, docSubkey); + changed = true; + } + } + // Maybe reget list + if (changed) + names = m_data.getNames(docSubkey); + + // How many do we have + if (names.size() >= m_mlen) { + // Need to erase entries until we're back to size. Note that + // we don't ever reset numbers. Problems will arise when + // history is 4 billion entries old + it = names.begin(); + for (unsigned int i = 0; i < names.size() - m_mlen + 1; i++, it++) { + m_data.erase(*it, docSubkey); + } + } + + // Increment highest number + unsigned int hi = names.empty() ? 0 : + (unsigned int)atoi(names.back().c_str()); + hi++; + char nname[20]; + sprintf(nname, "%010u", hi); + if (!m_data.set(string(nname), value, docSubkey)) { LOGERR(("RclQHistory::enterDocument: set failed\n")); return false; @@ -73,7 +103,7 @@ list< pair > RclQHistory::getDocHistory() LOGDEB(("RclQHistory::getDocHistory:fn: %s\n", fn.c_str())); if (vall.size() == 2) base64_decode(*it1, ipath); - mlist.push_back(pair(fn, ipath)); + mlist.push_front(pair(fn, ipath)); } } return mlist; diff --git a/src/utils/conftree.cpp b/src/utils/conftree.cpp index 7d64df6c..b31dce80 100755 --- a/src/utils/conftree.cpp +++ b/src/utils/conftree.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid [] = "@(#$Id: conftree.cpp,v 1.3 2005-11-25 08:50:39 dockes Exp $ (C) 2003 J.F.Dockes"; +static char rcsid [] = "@(#$Id: conftree.cpp,v 1.4 2005-11-25 14:36:45 dockes Exp $ (C) 2003 J.F.Dockes"; #endif #ifdef HAVE_CONFIG_H #include "config.h" @@ -15,6 +15,7 @@ static char rcsid [] = "@(#$Id: conftree.cpp,v 1.3 2005-11-25 08:50:39 dockes Ex #include "conftree.h" #include "pathut.h" +#include "smallut.h" #ifndef NO_NAMESPACES using namespace std; @@ -25,21 +26,6 @@ using std::list; #define MIN(A,B) ((A)<(B) ? (A) : (B)) #endif -/** Remove instances of characters belonging to set (default {space, - tab}) at beginning and end of input string */ -static void trimstring(string &s, const char *ws = " \t") -{ - string::size_type pos = s.find_first_not_of(ws); - if (pos == string::npos) { - s = ""; - return; - } - s.replace(0, pos, ""); - - pos = s.find_last_not_of(ws); - if (pos != string::npos && pos != s.length()-1) - s.replace(pos+1, string::npos, ""); -} #define LL 1024 void ConfSimple::parseinput(istream &input) diff --git a/src/utils/smallut.cpp b/src/utils/smallut.cpp index 78eb70b7..1bc23896 100644 --- a/src/utils/smallut.cpp +++ b/src/utils/smallut.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: smallut.cpp,v 1.9 2005-11-25 08:50:39 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: smallut.cpp,v 1.10 2005-11-25 14:36:45 dockes Exp $ (C) 2004 J.F.Dockes"; #endif #ifndef TEST_SMALLUT #include @@ -278,6 +278,20 @@ bool stringToBool(const string &s) return false; } +void trimstring(string &s, const char *ws) +{ + string::size_type pos = s.find_first_not_of(ws); + if (pos == string::npos) { + s = ""; + return; + } + s.replace(0, pos, ""); + + pos = s.find_last_not_of(ws); + if (pos != string::npos && pos != s.length()-1) + s.replace(pos+1, string::npos, ""); +} + #else #include diff --git a/src/utils/smallut.h b/src/utils/smallut.h index 275972ef..8d036cda 100644 --- a/src/utils/smallut.h +++ b/src/utils/smallut.h @@ -1,6 +1,6 @@ #ifndef _SMALLUT_H_INCLUDED_ #define _SMALLUT_H_INCLUDED_ -/* @(#$Id: smallut.h,v 1.9 2005-11-25 08:50:39 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: smallut.h,v 1.10 2005-11-25 14:36:46 dockes Exp $ (C) 2004 J.F.Dockes */ #include #include @@ -29,4 +29,8 @@ extern bool stringToStrings(const string &s, std::list &tokens); extern bool stringToBool(const string &s); +/** Remove instances of characters belonging to set (default {space, + tab}) at beginning and end of input string */ +extern void trimstring(string &s, const char *ws = " \t"); + #endif /* _SMALLUT_H_INCLUDED_ */