diff --git a/src/qtgui/restable.cpp b/src/qtgui/restable.cpp index 4198a3a4..955d7730 100644 --- a/src/qtgui/restable.cpp +++ b/src/qtgui/restable.cpp @@ -154,6 +154,16 @@ static string gengetter(const string& fld, const Rcl::Doc& doc) return it->second; } +static string sizegetter(const string& fld, const Rcl::Doc& doc) +{ + map::const_iterator it = doc.meta.find(fld); + if (it == doc.meta.end()) { + return string(); + } + off_t size = atoll(it->second.c_str()); + return displayableBytes(size) + " (" + it->second + ")"; +} + static string dategetter(const string&, const Rcl::Doc& doc) { char datebuf[100]; @@ -162,7 +172,11 @@ static string dategetter(const string&, const Rcl::Doc& doc) time_t mtime = doc.dmtime.empty() ? atol(doc.fmtime.c_str()) : atol(doc.dmtime.c_str()); struct tm *tm = localtime(&mtime); +#ifndef sun + strftime(datebuf, 99, "%Y-%m-%d", tm); +#else strftime(datebuf, 99, "%x", tm); +#endif } return datebuf; } @@ -212,6 +226,8 @@ FieldGetter *RecollModel::chooseGetter(const string& field) return dategetter; else if (!stringlowercmp("datetime", field)) return datetimegetter; + else if (!stringlowercmp("bytes", field.substr(1))) + return sizegetter; else return gengetter; } diff --git a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp index fce9a24b..87908353 100644 --- a/src/rcldb/rcldb.cpp +++ b/src/rcldb/rcldb.cpp @@ -138,12 +138,6 @@ static inline string make_parentterm(const string& udi) return pterm; } -static inline void leftzeropad(string& s, unsigned len) -{ - if (s.length() && s.length() < len) - s = s.insert(0, len - s.length(), '0'); -} - /* See comment in class declaration: return all subdocuments of a * document given by its unique id. */ diff --git a/src/rcldb/rclquery.cpp b/src/rcldb/rclquery.cpp index bf9501a0..d7e6e6e1 100644 --- a/src/rcldb/rclquery.cpp +++ b/src/rcldb/rclquery.cpp @@ -54,13 +54,17 @@ static const string& docfToDatf(const string& df) } } -// Sort helper class +// Sort helper class. As Xapian sorting is lexicographic, we do some +// special processing for special fields like dates and sizes. User +// custom field data will have to be processed before insertion to +// achieve equivalent results. class QSorter : public Xapian::Sorter { public: QSorter(const string& f) : m_fld(docfToDatf(f) + "=") { m_ismtime = !m_fld.compare("dmtime="); + m_issize = !m_fld.compare("fbytes=") || !m_fld.compare("dbytes="); } virtual std::string operator()(const Xapian::Document& xdoc) const @@ -88,14 +92,22 @@ public: i2 = data.find_first_of("\n\r", i1); if (i2 == string::npos) return string(); - + + string term = data.substr(i1, i2-i1); + if (m_ismtime) { + return term; + } else if (m_issize) { + // Left zeropad values for appropriate numeric sorting + leftzeropad(term, 12); + return term; + } + // Process data for better sorting. We should actually do the // unicode thing // (http://unicode.org/reports/tr10/#Introduction), but just // removing accents and majuscules will remove the most // glaring weirdnesses (or not, depending on your national // approach to collating...) - string term = data.substr(i1, i2-i1); string sortterm; // We're not even sure the term is utf8 here (ie: url) if (!unacmaybefold(term, sortterm, "UTF-8", true)) { @@ -114,6 +126,7 @@ public: private: string m_fld; bool m_ismtime; + bool m_issize; }; Query::Query(Db *db) diff --git a/src/utils/smallut.cpp b/src/utils/smallut.cpp index bbcc7acd..f50b427d 100644 --- a/src/utils/smallut.cpp +++ b/src/utils/smallut.cpp @@ -562,16 +562,22 @@ bool pcSubst(const string& in, string& out, map& subs) // Convert byte count into unit (KB/MB...) appropriate for display string displayableBytes(off_t size) { - char sizebuf[30]; - const char * unit = " B "; + char sizebuf[50]; + const char *unit; - if (size > 1024 && size < 1024*1024) { + if (size < 1024) { + unit = " B "; + } else if (size < 1024*1024) { unit = " KB "; size /= 1024; - } else if (size >= 1024*1204) { + } else if (size < 1024*1024*1024) { unit = " MB "; size /= (1024*1024); + } else { + unit = " GB "; + size /= (1024*1024*1024); } + sprintf(sizebuf, OFFTPC "%s", size, unit); return string(sizebuf); } diff --git a/src/utils/smallut.h b/src/utils/smallut.h index 8e78331a..45466bd4 100644 --- a/src/utils/smallut.h +++ b/src/utils/smallut.h @@ -178,6 +178,12 @@ struct TempBuf { char *m_buf; }; +inline void leftzeropad(string& s, unsigned len) +{ + if (s.length() && s.length() < len) + s = s.insert(0, len - s.length(), '0'); +} + #ifndef deleteZ #define deleteZ(X) {delete X;X = 0;} #endif