diff --git a/src/qtgui/preview/preview.ui.h b/src/qtgui/preview/preview.ui.h index 5bedd265..855dcc7d 100644 --- a/src/qtgui/preview/preview.ui.h +++ b/src/qtgui/preview/preview.ui.h @@ -333,6 +333,7 @@ class LoadThread : public QThread { {} virtual void run() { + DebugLog::getdbl()->setloglevel(DEBDEB1); FileInterner interner(filename, rclconfig, tmpdir, mtype); if (interner.internfile(*out, ipath) != FileInterner::FIDone) { *statusp = -1; @@ -355,6 +356,7 @@ class ToRichThread : public QThread { {} virtual void run() { + DebugLog::getdbl()->setloglevel(DEBDEB1); string rich = plaintorich(in, terms, termoffsets); out = QString::fromUtf8(rich.c_str(), rich.length()); } @@ -416,7 +418,6 @@ void Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc) doc.mimetype.c_str()); return; } - LOGDEB(("Load file done\n")); // Highlight search terms: progress.setLabelText(tr("Creating preview text")); diff --git a/src/qtgui/recollmain.ui b/src/qtgui/recollmain.ui index f843c3ea..7fb82fc6 100644 --- a/src/qtgui/recollmain.ui +++ b/src/qtgui/recollmain.ui @@ -8,7 +8,7 @@ 0 0 - 631 + 678 212 @@ -22,7 +22,7 @@ - 590 + 678 160 @@ -99,6 +99,20 @@ Ctrl+S + + + line4 + + + VLine + + + Sunken + + + Vertical + + listPrevPB @@ -121,6 +135,17 @@ Next page + + + sortPB + + + true + + + Sorting + + spacer1 @@ -317,7 +342,7 @@ advSearchPB clicked() RecollMain - advSearchPB_clicked() + showAdvSearchDialog() helpAbout_RecollAction @@ -343,11 +368,19 @@ queryText clear() + + sortPB + clicked() + RecollMain + showSortDialog() + + sortseq.h preview.h recoll.h advsearch.h + sort.h recollmain.ui.h @@ -363,6 +396,9 @@ std::string stemlang; Preview *curPreview; advsearch *asearchform; + SortForm *sortform; + int sortwidth; + RclSortSpec sortspecs; DocSequence *docsource; @@ -378,11 +414,13 @@ listPrevPB_clicked() listNextPB_clicked() previewClosed( Preview * w ) - advSearchPB_clicked() + showAdvSearchDialog() + showSortDialog() startAdvSearch( Rcl::AdvSearchData sdata ) showAboutDialog() showDocHistory() searchTextChanged( const QString & text ) + sortDataChanged(int cnt, RclSortSpec spec) init() diff --git a/src/qtgui/recollmain.ui.h b/src/qtgui/recollmain.ui.h index 7e4ae476..19130ba3 100644 --- a/src/qtgui/recollmain.ui.h +++ b/src/qtgui/recollmain.ui.h @@ -62,7 +62,9 @@ void RecollMain::init() dostem = false; curPreview = 0; asearchform = 0; + sortform = 0; docsource = 0; + sortwidth = 0; reslistTE->viewport()->installEventFilter(this); } @@ -386,14 +388,13 @@ void RecollMain::queryText_returnPressed() if (docsource) delete docsource; -#if TRYSORT - DocSequenceDb myseq(rcldb); - RclSortSpec ss; - ss.addCrit(RclSortSpec::RCLFLD_MTIME, false); - docsource = new DocSeqSorted(myseq, 10000, ss); -#else - docsource = new DocSequenceDb(rcldb); -#endif + + if (sortwidth > 0) { + DocSequenceDb myseq(rcldb); + docsource = new DocSeqSorted(myseq, sortwidth, sortspecs); + } else { + docsource = new DocSequenceDb(rcldb); + } listNextPB_clicked(); } @@ -570,7 +571,7 @@ void RecollMain::previewClosed(Preview *w) } // Open advanced search dialog. -void RecollMain::advSearchPB_clicked() +void RecollMain::showAdvSearchDialog() { if (asearchform == 0) { asearchform = new advsearch(0, tr("Advanced search"), FALSE, @@ -585,6 +586,22 @@ void RecollMain::advSearchPB_clicked() } } +void RecollMain::showSortDialog() +{ + if (sortform == 0) { + sortform = new SortForm(0, tr("Sort criteria"), FALSE, + WStyle_Customize | WStyle_NormalBorder | + WStyle_Title | WStyle_SysMenu); + sortform->setSizeGripEnabled(FALSE); + connect(sortform, SIGNAL(sortDataChanged(int, RclSortSpec)), + this, SLOT(sortDataChanged(int, RclSortSpec))); + sortform->show(); + } else { + sortform->show(); + } + +} + // Execute an advanced search query. The parameters normally come from // the advanced search dialog void RecollMain::startAdvSearch(Rcl::AdvSearchData sdata) @@ -608,14 +625,14 @@ void RecollMain::startAdvSearch(Rcl::AdvSearchData sdata) curPreview = 0; if (docsource) delete docsource; -#if TRYSORT - DocSequenceDb myseq(rcldb); - RclSortSpec ss; - ss.addCrit(RclSortSpec::RCLFLD_MTIME, true); - docsource = new DocSeqSorted(myseq, 10000, ss); -#else - docsource = new DocSequenceDb(rcldb); -#endif + + if (sortwidth > 0) { + DocSequenceDb myseq(rcldb); + docsource = new DocSeqSorted(myseq, sortwidth, sortspecs); + } else { + docsource = new DocSequenceDb(rcldb); + } + listNextPB_clicked(); } @@ -705,3 +722,10 @@ void RecollMain::searchTextChanged(const QString & text) } } + +void RecollMain::sortDataChanged(int cnt, RclSortSpec spec) +{ + LOGDEB(("RecollMain::sortDataChanged\n")); + sortwidth = cnt; + sortspecs = spec; +} diff --git a/src/qtgui/sort.ui b/src/qtgui/sort.ui index 706d96bb..ef766676 100644 --- a/src/qtgui/sort.ui +++ b/src/qtgui/sort.ui @@ -1,197 +1,227 @@ -sort +SortForm - sort + SortForm 0 0 - 360 - 163 + 351 + 154 - Form1 + Sort Criteria - + - layout2 + unnamed - - - 12 - 12 - 336 - 23 - - - + - unnamed + layout10 - + - textLabel1 + unnamed - - NoFrame - - - Plain - - - Sort at most the - - - - - mcntSB - - - 10000 - - - 100 - - - - - textLabel2 - - - most relevant results by: - - - - - - - layout3 - - - - 12 - 41 - 336 - 23 - - - - - unnamed - - - - fldCMB1 - - - - - descCB1 - - - Descending - - - - - - - layout6 - - - - 12 - 70 - 336 - 23 - - - - - unnamed - - - - fldCMB2 - - - - - descCB2 - - - Descending - - - - - - - layout10 - - - - 12 - 99 - 336 - 23 - - - - - unnamed - - - - fldCMB3 - - - - - descCB3 - - - Descending - - - - - - - descCB4 - - - - 183 - 130 - 164 - 18 - - - - Descending - - - - - fldCMB4 - - - - 13 - 129 - 164 - 21 - - - + + + layout9 + + + + unnamed + + + + sortCB + + + Sort the + + + + + mcntSB + + + false + + + 10000 + + + 100 + + + + + textLabel2 + + + most relevant results by: + + + + + + + layout3 + + + + unnamed + + + + fldCMB1 + + + false + + + + + descCB1 + + + false + + + Descending + + + + + + + layout6 + + + + unnamed + + + + fldCMB2 + + + false + + + + + descCB2 + + + false + + + Descending + + + + + + + layout7 + + + + unnamed + + + + resetPB + + + true + + + Reset + + + + + closePB + + + true + + + Close + + + + + + + + + + resetPB + clicked() + SortForm + reset() + + + closePB + clicked() + SortForm + close() + + + mcntSB + valueChanged(int) + SortForm + setData() + + + fldCMB1 + activated(const QString&) + SortForm + setData() + + + fldCMB2 + activated(const QString&) + SortForm + setData() + + + descCB1 + stateChanged(int) + SortForm + setData() + + + descCB2 + stateChanged(int) + SortForm + setData() + + + sortCB + toggled(bool) + SortForm + setData() + + + sortseq.h sort.ui.h + + sortDataChanged(int, RclSortSpec) + + + reset() + setData() + init() diff --git a/src/qtgui/sort.ui.h b/src/qtgui/sort.ui.h index e3776b55..9e57e262 100644 --- a/src/qtgui/sort.ui.h +++ b/src/qtgui/sort.ui.h @@ -10,10 +10,66 @@ ** destructor. *****************************************************************************/ +#include "sortseq.h" +#include "debuglog.h" -void sort::init() +void SortForm::init() { - + const char *labels[5]; + labels[0] = ""; + labels[1] = "Date"; + labels[2] = "Mime type"; + labels[3] = 0; + fldCMB1->insertStrList(labels, 3); + fldCMB1->setCurrentItem(0); + fldCMB2->insertStrList(labels, 3); + fldCMB2->setCurrentItem(0); } +void SortForm::reset() +{ + mcntSB->setValue(100); + fldCMB1->setCurrentItem(0); + fldCMB2->setCurrentItem(0); + descCB1->setChecked(false); + descCB1->setChecked(false); +} +void SortForm::setData() +{ + LOGDEB(("SortForm::setData\n")); + RclSortSpec spec; + int width; + + mcntSB->setEnabled(sortCB->isChecked()); + fldCMB1->setEnabled(sortCB->isChecked()); + descCB1->setEnabled(sortCB->isChecked()); + fldCMB2->setEnabled(sortCB->isChecked()); + descCB2->setEnabled(sortCB->isChecked()); + + if (!sortCB->isChecked()) { + width = 0; + } else { + bool desc = descCB1->isChecked(); + switch (fldCMB1->currentItem()) { + case 1: + spec.addCrit(RclSortSpec::RCLFLD_MTIME, desc?true:false); + break; + case 2: + spec.addCrit(RclSortSpec::RCLFLD_MIMETYPE, desc?true:false); + break; + } + + desc = descCB2->isChecked(); + switch (fldCMB2->currentItem()) { + case 1: + spec.addCrit(RclSortSpec::RCLFLD_MTIME, desc?true:false); + break; + case 2: + spec.addCrit(RclSortSpec::RCLFLD_MIMETYPE, desc?true:false); + break; + } + width = mcntSB->value(); + } + emit sortDataChanged(width, spec); +} diff --git a/src/query/sortseq.cpp b/src/query/sortseq.cpp index 02f8dbda..b27e4856 100644 --- a/src/query/sortseq.cpp +++ b/src/query/sortseq.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.2 2005-12-02 14:18:44 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.3 2005-12-02 16:18:20 dockes Exp $ (C) 2005 J.F.Dockes"; #endif #include @@ -13,38 +13,51 @@ class CompareDocs { public: CompareDocs(const RclSortSpec &sortspec) : ss(sortspec) {} - int operator()(const Rcl::Doc &x, const Rcl::Doc &y) + // It's not too clear in the std::sort doc what this should do. This + // behaves as operator< + int operator()(const Rcl::Doc *x, const Rcl::Doc *y) { - LOGDEB(("Comparing .. \n")); + LOGDEB1(("Comparing .. \n")); + + // Compare using each criterion in term. Further comparisons must only + // be made if previous order ones are equal. for (unsigned int i = 0; i < ss.crits.size(); i++) { switch (ss.crits[i]) { case RclSortSpec::RCLFLD_MTIME: { - LOGDEB((" MTIME\n")); - long xmtime = x.dmtime.empty() ? atol(x.fmtime.c_str()) : - atol(x.dmtime.c_str()); - long ymtime = y.dmtime.empty() ? atol(y.fmtime.c_str()) : - atol(y.dmtime.c_str()); + long xmtime = x->dmtime.empty() ? atol(x->fmtime.c_str()) : + atol(x->dmtime.c_str()); + long ymtime = y->dmtime.empty() ? atol(y->fmtime.c_str()) : + atol(y->dmtime.c_str()); + LOGDEB1((" MTIME %ld %ld\n", xmtime, ymtime)); if (ss.dirs[i] ? xmtime > ymtime : xmtime < ymtime) return 1; + else if (xmtime != ymtime) + return 0; } break; case RclSortSpec::RCLFLD_URL: - LOGDEB((" URL\n")); - if (ss.dirs[i] ? x.url > y.url : x.url < y.url) + LOGDEB1((" URL\n")); + if (ss.dirs[i] ? x->url > y->url : x->url < y->url) return 1; + else if (x->url != y->url) + return 0; break; case RclSortSpec::RCLFLD_IPATH: - LOGDEB((" IPATH\n")); - if (ss.dirs[i] ? x.ipath > y.ipath : x.ipath < y.ipath) + LOGDEB1((" IPATH\n")); + if (ss.dirs[i] ? x->ipath > y->ipath : x->ipath < y->ipath) return 1; + else if (x->ipath != y->ipath) + return 0; break; case RclSortSpec::RCLFLD_MIMETYPE: - LOGDEB((" MIMETYPE\n")); - if (ss.dirs[i] ? x.mimetype > y.mimetype : - x.mimetype < y.mimetype) + LOGDEB1((" MIMETYPE\n")); + if (ss.dirs[i] ? x->mimetype > y->mimetype : + x->mimetype < y->mimetype) return 1; + else if (x->mimetype != y->mimetype) + return 0; break; } } @@ -58,21 +71,25 @@ DocSeqSorted::DocSeqSorted(DocSequence &iseq, int cnt, RclSortSpec &sortspec) LOGDEB(("DocSeqSorted:: count %d\n", cnt)); m_docs.resize(cnt); - m_pcs.resize(cnt); int i; for (i = 0; i < cnt; i++) { - if (!iseq.getDoc(i, m_docs[i], &m_pcs[i])) { + int percent; + if (!iseq.getDoc(i, m_docs[i], &percent)) { LOGERR(("DocSeqSorted: getDoc failed for doc %d\n", i)); break; } + m_docs[i].pc = percent; } m_count = i; LOGDEB(("DocSeqSorted:: m_count %d\n", m_count)); m_docs.resize(m_count); - m_pcs.resize(m_count); + m_docsp.resize(m_count); + for (i = 0; i < m_count; i++) + m_docsp[i] = &m_docs[i]; + m_title = string("Sorted ") + iseq.title(); CompareDocs cmp(sortspec); - sort(m_docs.begin(), m_docs.end(), cmp); + sort(m_docsp.begin(), m_docsp.end(), cmp); } bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, int *percent, string *) @@ -82,7 +99,7 @@ bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, int *percent, string *) if (num >= m_count) return false; if (percent) - *percent = m_pcs[num]; - doc = m_docs[num]; + *percent = (*m_docsp[num]).pc; + doc = *m_docsp[num]; return true; } diff --git a/src/query/sortseq.h b/src/query/sortseq.h index af46b44a..ad839a97 100644 --- a/src/query/sortseq.h +++ b/src/query/sortseq.h @@ -1,6 +1,6 @@ #ifndef _SORTSEQ_H_INCLUDED_ #define _SORTSEQ_H_INCLUDED_ -/* @(#$Id: sortseq.h,v 1.1 2005-12-01 16:23:09 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: sortseq.h,v 1.2 2005-12-02 16:18:20 dockes Exp $ (C) 2004 J.F.Dockes */ #include #include @@ -33,7 +33,7 @@ class DocSeqSorted : public DocSequence { std::string m_title; int m_count; std::vector m_docs; - std::vector m_pcs; + std::vector m_docsp; }; #endif /* _SORTSEQ_H_INCLUDED_ */ diff --git a/src/rcldb/rcldb.h b/src/rcldb/rcldb.h index 7b767c46..5ac1c87f 100644 --- a/src/rcldb/rcldb.h +++ b/src/rcldb/rcldb.h @@ -1,6 +1,6 @@ #ifndef _DB_H_INCLUDED_ #define _DB_H_INCLUDED_ -/* @(#$Id: rcldb.h,v 1.19 2005-11-25 09:12:26 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: rcldb.h,v 1.20 2005-12-02 16:18:20 dockes Exp $ (C) 2004 J.F.Dockes */ #include #include @@ -48,6 +48,8 @@ class Doc { string text; + int pc; // used by sortseq, convenience + void erase() { url.erase(); ipath.erase();