diff --git a/src/qtgui/preview_w.cpp b/src/qtgui/preview_w.cpp index dea8d520..1d84ffae 100644 --- a/src/qtgui/preview_w.cpp +++ b/src/qtgui/preview_w.cpp @@ -876,10 +876,7 @@ bool Preview::loadDocInCurrentTab(const Rcl::Doc &idoc, int docnum) // Enter document in document history - string udi; - if (idoc.getmeta(Rcl::Doc::keyudi, &udi)) { - historyEnterDoc(g_dynconf, udi); - } + historyEnterDoc(rcldb, g_dynconf, idoc); editor->setFocus(); emit(previewExposed(this, m_searchId, docnum)); diff --git a/src/qtgui/rclm_preview.cpp b/src/qtgui/rclm_preview.cpp index 7cfa4a9f..87667219 100644 --- a/src/qtgui/rclm_preview.cpp +++ b/src/qtgui/rclm_preview.cpp @@ -80,7 +80,7 @@ bool RclMain::containerUpToDate(Rcl::Doc& doc) } // We can only run indexing on the main index (dbidx 0) - bool ismainidx = rcldb->whatDbIdx(doc) == 0; + bool ismainidx = rcldb->fromMainIndex(doc); // Indexer already running? bool ixnotact = (m_indexerState == IXST_NOTRUNNING); diff --git a/src/qtgui/rclm_view.cpp b/src/qtgui/rclm_view.cpp index cb0ff2ee..94193ca1 100644 --- a/src/qtgui/rclm_view.cpp +++ b/src/qtgui/rclm_view.cpp @@ -310,7 +310,9 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term) } } - bool enterHistory = false; + // Can't remember what enterHistory was actually for. Set it to + // true always for now + bool enterHistory = true; bool istempfile = false; LOGDEB("StartNativeViewer: groksipath " << groksipath << " wantsf " << @@ -451,8 +453,8 @@ void RclMain::execViewer(const map& subs, bool enterHistory, stb->showMessage(msg, 10000); } - if (!enterHistory) - historyEnterDoc(g_dynconf, doc.meta[Rcl::Doc::keyudi]); + if (enterHistory) + historyEnterDoc(rcldb, g_dynconf, doc); // Do the zeitgeist thing zg_send_event(ZGSEND_OPEN, doc); diff --git a/src/query/docseqhist.cpp b/src/query/docseqhist.cpp index fda4ded2..eb04ff6f 100644 --- a/src/query/docseqhist.cpp +++ b/src/query/docseqhist.cpp @@ -34,21 +34,24 @@ using std::vector; // The U distinguishes udi-based entries from older fn+ipath ones bool RclDHistoryEntry::encode(string& value) { - string budi; + string budi, bdir; base64_encode(udi, budi); - value = string("U ") + lltodecstr(unixtime) + " " + budi; + base64_encode(dbdir, bdir); + value = string("V ") + lltodecstr(unixtime) + " " + budi + " " + bdir; return true; } // Decode. We support historical entries which were like "time b64fn [b64ipath]" -// Current entry format is "U time b64udi" +// Previous entry format is "U time b64udi" +// Current entry format "V time b64udi [b64dir]" bool RclDHistoryEntry::decode(const string &value) { vector vall; stringToStrings(value, vall); vector::const_iterator it = vall.begin(); - udi.erase(); + udi.clear(); + dbdir.clear(); string fn, ipath; switch (vall.size()) { case 2: @@ -57,8 +60,8 @@ bool RclDHistoryEntry::decode(const string &value) base64_decode(*it++, fn); break; case 3: - if (!it->compare("U")) { - // New udi-based entry + if (!it->compare("U") || !it->compare("V")) { + // New udi-based entry, no dir it++; unixtime = atoll((*it++).c_str()); base64_decode(*it++, udi); @@ -69,6 +72,13 @@ bool RclDHistoryEntry::decode(const string &value) base64_decode(*it, ipath); } break; + case 4: + // New udi-based entry, with directory + it++; + unixtime = atoll((*it++).c_str()); + base64_decode(*it++, udi); + base64_decode(*it++, dbdir); + break; default: return false; } @@ -77,23 +87,31 @@ bool RclDHistoryEntry::decode(const string &value) // Old style entry found, make an udi, using the fs udi maker make_udi(fn, ipath, udi); } - LOGDEB1("RclDHistoryEntry::decode: udi [" << udi << "]\n"); + LOGDEB1("RclDHistoryEntry::decode: udi [" << udi << "] dbdir [" << + dbdir << "]\n"); return true; } bool RclDHistoryEntry::equal(const DynConfEntry& other) { const RclDHistoryEntry& e = dynamic_cast(other); - return e.udi == udi; + return e.udi == udi && e.dbdir == dbdir; } -bool historyEnterDoc(RclDynConf *dncf, const string& udi) +bool historyEnterDoc(Rcl::Db *db, RclDynConf *dncf, const Rcl::Doc& doc) { - LOGDEB1("historyEnterDoc: [" << udi << "] into " << dncf->getFilename() << - "\n"); - RclDHistoryEntry ne(time(0), udi); - RclDHistoryEntry scratch; - return dncf->insertNew(docHistSubKey, ne, scratch, 200); + string udi; + if (db && doc.getmeta(Rcl::Doc::keyudi, &udi)) { + std::string dbdir = db->whatIndexForResultDoc(doc); + LOGDEB("historyEnterDoc: [" << udi << ", " << dbdir << "] into " << + dncf->getFilename() << "\n"); + RclDHistoryEntry ne(time(0), udi, dbdir); + RclDHistoryEntry scratch; + return dncf->insertNew(docHistSubKey, ne, scratch, 200); + } else { + LOGDEB("historyEnterDoc: doc has no udi\n"); + } + return false; } vector getDocHistory(RclDynConf* dncf) @@ -111,8 +129,10 @@ bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, string *sh) if (num < 0 || num >= (int)m_history.size()) return false; + // We get the history oldest first, but our users expect newest first RclDHistoryEntry& hentry = m_history[m_history.size() - 1 - num]; + if (sh) { if (m_prevtime < 0 || abs (float(m_prevtime) - float(hentry.unixtime)) > 86400) { @@ -126,9 +146,7 @@ bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, string *sh) } } - // For now history does not store an index id. Use empty doc as ref. - Rcl::Doc idxdoc; - bool ret = m_db->getDoc(hentry.udi, idxdoc, doc); + bool ret = m_db->getDoc(hentry.udi, hentry.dbdir, doc); if (!ret || doc.pc == -1) { doc.url = "UNKNOWN"; doc.ipath = ""; diff --git a/src/query/docseqhist.h b/src/query/docseqhist.h index 344b4a48..404df03f 100644 --- a/src/query/docseqhist.h +++ b/src/query/docseqhist.h @@ -31,14 +31,15 @@ namespace Rcl { class RclDHistoryEntry : public DynConfEntry { public: RclDHistoryEntry() : unixtime(0) {} - RclDHistoryEntry(time_t t, const string& u) - : unixtime(t), udi(u) {} + RclDHistoryEntry(time_t t, const std::string& u, const std::string& d) + : unixtime(t), udi(u), dbdir(d) {} virtual ~RclDHistoryEntry() {} - virtual bool decode(const string &value); - virtual bool encode(string& value); + virtual bool decode(const std::string &value); + virtual bool encode(std::string& value); virtual bool equal(const DynConfEntry& other); time_t unixtime; - string udi; + std::string udi; + std::string dbdir; }; /** A DocSequence coming from the history file. @@ -46,14 +47,14 @@ class RclDHistoryEntry : public DynConfEntry { * metadata for an url key */ class DocSequenceHistory : public DocSequence { public: - DocSequenceHistory(Rcl::Db *d, RclDynConf *h, const string &t) + DocSequenceHistory(Rcl::Db *d, RclDynConf *h, const std::string &t) : DocSequence(t), m_db(d), m_hist(h) {} virtual ~DocSequenceHistory() {} - virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0); + virtual bool getDoc(int num, Rcl::Doc &doc, std::string *sh = 0); virtual int getResCnt(); - virtual string getDescription() {return m_description;} - void setDescription(const string& desc) {m_description = desc;} + virtual std::string getDescription() {return m_description;} + void setDescription(const std::string& desc) {m_description = desc;} protected: virtual Rcl::Db *getDb(); private: @@ -64,6 +65,6 @@ private: std::vector m_history; }; -extern bool historyEnterDoc(RclDynConf *dncf, const string& udi); +extern bool historyEnterDoc(Rcl::Db *db, RclDynConf *dncf, const Rcl::Doc& doc); #endif /* _DOCSEQ_H_INCLUDED_ */ diff --git a/src/query/dynconf.cpp b/src/query/dynconf.cpp index 31f21497..a0c649b9 100644 --- a/src/query/dynconf.cpp +++ b/src/query/dynconf.cpp @@ -98,7 +98,7 @@ bool RclDynConf::insertNew(const string &sk, DynConfEntry &n, DynConfEntry &s, n.encode(value); LOGDEB1("Encoded value [" << value << "] (" << value.size() << ")\n"); if (!m_data.set(string(nname), value, sk)) { - LOGERR("RclDHistory::insertNew: set failed\n"); + LOGERR("RclDynConf::insertNew: set failed\n"); return false; } return true; diff --git a/src/query/dynconf.h b/src/query/dynconf.h index c458ba4b..5a9e1dfd 100644 --- a/src/query/dynconf.h +++ b/src/query/dynconf.h @@ -147,7 +147,7 @@ Container> out.push_back(entry); } } - return std::move(out); + return out; } template