remember sort criteria

This commit is contained in:
dockes 2006-09-21 09:37:28 +00:00
parent e3f89dca7e
commit 34341eae24
8 changed files with 75 additions and 31 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.19 2006-09-15 16:49:27 dockes Exp $ (C) 2005 Jean-Francois Dockes";
static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.20 2006-09-21 09:37:28 dockes Exp $ (C) 2005 Jean-Francois Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -157,6 +157,11 @@ void rwSettings(bool writing)
SETTING_RW(prefs.syntAbsCtx, "/Recoll/prefs/query/syntAbsCtx",
Num, 4);
SETTING_RW(prefs.sortWidth, "/Recoll/prefs/query/sortWidth",
Num, 100);
SETTING_RW(prefs.sortSpec, "/Recoll/prefs/query/sortSpec",
Num, 0);
// Ssearch combobox history list
if (writing) {
settings.writeEntry("/Recoll/prefs/query/ssearchHistory",

View File

@ -17,7 +17,7 @@
#ifndef _GUIUTILS_H_INCLUDED_
#define _GUIUTILS_H_INCLUDED_
/*
* @(#$Id: guiutils.h,v 1.11 2006-09-15 16:49:27 dockes Exp $ (C) 2005 Jean-Francois Dockes
* @(#$Id: guiutils.h,v 1.12 2006-09-21 09:37:28 dockes Exp $ (C) 2005 Jean-Francois Dockes
* jean-francois.dockes@wanadoo.fr
*
* This program is free software; you can redistribute it and/or modify
@ -84,6 +84,10 @@ class PrefsPack {
int syntAbsLen;
int syntAbsCtx;
// Sort specs (sort_w.cpp knows how to deal with the values
int sortWidth;
int sortSpec;
PrefsPack() :
showicons(true),
respagesize(8),

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: rclmain.cpp,v 1.32 2006-09-13 13:53:35 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: rclmain.cpp,v 1.33 2006-09-21 09:37:28 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -368,8 +368,8 @@ void RclMain::showSortDialog()
sortform = new SortForm(0, tr("Sort criteria"), FALSE,
WStyle_Customize | WStyle_NormalBorder |
WStyle_Title | WStyle_SysMenu);
connect(sortform, SIGNAL(sortDataChanged(RclSortSpec)),
this, SLOT(sortDataChanged(RclSortSpec)));
connect(sortform, SIGNAL(sortDataChanged(DocSeqSortSpec)),
this, SLOT(sortDataChanged(DocSeqSortSpec)));
sortform->show();
} else {
// Close and reopen, in hope that makes us visible...
@ -694,7 +694,7 @@ void RclMain::showDocHistory()
}
void RclMain::sortDataChanged(RclSortSpec spec)
void RclMain::sortDataChanged(DocSeqSortSpec spec)
{
LOGDEB(("RclMain::sortDataChanged\n"));
sortspecs = spec;

View File

@ -55,7 +55,7 @@ public slots:
virtual void showAboutDialog();
virtual void startManual();
virtual void showDocHistory();
virtual void sortDataChanged(RclSortSpec spec);
virtual void sortDataChanged(DocSeqSortSpec spec);
virtual void showUIPrefs();
virtual void setUIPrefs();
virtual void enableNextPage(bool);
@ -72,7 +72,7 @@ private:
AdvSearch *asearchform;
SortForm *sortform;
UIPrefsDialog *uiprefs;
RclSortSpec sortspecs;
DocSeqSortSpec sortspecs;
int m_searchId; // Serial number of current search for this process.
// Used to match to preview windows
virtual void init();

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: sort_w.cpp,v 1.1 2006-09-04 15:13:01 dockes Exp $ (C) 2006 J.F.Dockes";
static char rcsid[] = "@(#$Id: sort_w.cpp,v 1.2 2006-09-21 09:37:28 dockes Exp $ (C) 2006 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -25,6 +25,8 @@ static char rcsid[] = "@(#$Id: sort_w.cpp,v 1.1 2006-09-04 15:13:01 dockes Exp $
#include "sortseq.h"
#include "debuglog.h"
#include "guiutils.h"
#include "sort_w.h"
void SortForm::init()
@ -35,8 +37,30 @@ void SortForm::init()
labels[2] = "Mime type";
labels[3] = 0;
fldCMB1->insertStrList(labels, 3);
fldCMB1->setCurrentItem(0);
fldCMB2->insertStrList(labels, 3); fldCMB2->setCurrentItem(0);
fldCMB2->insertStrList(labels, 3);
// Initialize values from prefs:
mcntSB->setValue(prefs.sortWidth);
unsigned int spec = (unsigned int)prefs.sortSpec;
// We use 4 bits per spec hi is direction, 3 low bits = sort field
unsigned int v, d;
v = spec & (0xf & ~(1<<3));
d = spec & (1 << 3);
spec >>= 4;
fldCMB1->setCurrentItem(v < 3 ? v : 0);
descCB1->setChecked(d!=0?true:false);
v = spec & (0xf & ~(1<<3));
d = spec & (1 << 3);
spec >>= 4;
fldCMB2->setCurrentItem(v < 3 ? v : 0);
descCB2->setChecked(d!=0?true:false);
// Always start with sort disabled
sortCB->setChecked(false);
// signals and slots connections
connect(resetPB, SIGNAL(clicked()), this, SLOT(reset()));
connect(closePB, SIGNAL(clicked()), this, SLOT(close()));
@ -62,7 +86,7 @@ void SortForm::reset()
void SortForm::setData()
{
LOGDEB(("SortForm::setData\n"));
RclSortSpec spec;
DocSeqSortSpec spec;
mcntSB->setEnabled(sortCB->isChecked());
fldCMB1->setEnabled(sortCB->isChecked());
@ -76,23 +100,34 @@ void SortForm::setData()
bool desc = descCB1->isChecked();
switch (fldCMB1->currentItem()) {
case 1:
spec.addCrit(RclSortSpec::RCLFLD_MTIME, desc?true:false);
spec.addCrit(DocSeqSortSpec::RCLFLD_MTIME, desc?true:false);
break;
case 2:
spec.addCrit(RclSortSpec::RCLFLD_MIMETYPE, desc?true:false);
spec.addCrit(DocSeqSortSpec::RCLFLD_MIMETYPE, desc?true:false);
break;
}
desc = descCB2->isChecked();
switch (fldCMB2->currentItem()) {
case 1:
spec.addCrit(RclSortSpec::RCLFLD_MTIME, desc?true:false);
spec.addCrit(DocSeqSortSpec::RCLFLD_MTIME, desc?true:false);
break;
case 2:
spec.addCrit(RclSortSpec::RCLFLD_MIMETYPE, desc?true:false);
spec.addCrit(DocSeqSortSpec::RCLFLD_MIMETYPE, desc?true:false);
break;
}
spec.sortwidth = mcntSB->value();
// Set data in prefs;
prefs.sortWidth = spec.sortwidth;
unsigned int spec = 0, v, d;
v = fldCMB1->currentItem() & 0x7;
d = descCB1->isChecked() ? 8 : 0;
spec |= (d|v);
v = fldCMB2->currentItem() & 0x7;
d = descCB2->isChecked() ? 8 : 0;
spec |= (d|v) << 4;
prefs.sortSpec = (int) spec;
}
emit sortDataChanged(spec);
}

View File

@ -1,4 +1,4 @@
/* @(#$Id: sort_w.h,v 1.1 2006-09-04 15:13:01 dockes Exp $ (C) 2005 J.F.Dockes */
/* @(#$Id: sort_w.h,v 1.2 2006-09-21 09:37:28 dockes Exp $ (C) 2005 J.F.Dockes */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -39,7 +39,7 @@ public slots:
virtual void setData();
signals:
void sortDataChanged(RclSortSpec);
void sortDataChanged(DocSeqSortSpec);
private:
virtual void init();

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.7 2006-04-20 09:20:10 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.8 2006-09-21 09:37:28 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -25,9 +25,9 @@ static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.7 2006-04-20 09:20:10 dockes Exp
using std::string;
class CompareDocs {
RclSortSpec ss;
DocSeqSortSpec ss;
public:
CompareDocs(const RclSortSpec &sortspec) : ss(sortspec) {}
CompareDocs(const DocSeqSortSpec &sortspec) : ss(sortspec) {}
// It's not too clear in the std::sort doc what this should do. This
// behaves as operator<
@ -39,7 +39,7 @@ public:
// 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:
case DocSeqSortSpec::RCLFLD_MTIME:
{
long xmtime = x->dmtime.empty() ? atol(x->fmtime.c_str()) :
atol(x->dmtime.c_str());
@ -53,21 +53,21 @@ public:
return 0;
}
break;
case RclSortSpec::RCLFLD_URL:
case DocSeqSortSpec::RCLFLD_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:
case DocSeqSortSpec::RCLFLD_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:
case DocSeqSortSpec::RCLFLD_MIMETYPE:
LOGDEB1((" MIMETYPE\n"));
if (ss.dirs[i] ? x->mimetype > y->mimetype :
x->mimetype < y->mimetype)
@ -82,7 +82,7 @@ public:
}
};
DocSeqSorted::DocSeqSorted(DocSequence &iseq, RclSortSpec &sortspec,
DocSeqSorted::DocSeqSorted(DocSequence &iseq, DocSeqSortSpec &sortspec,
const std::string &t)
: DocSequence(t)
{

View File

@ -16,16 +16,16 @@
*/
#ifndef _SORTSEQ_H_INCLUDED_
#define _SORTSEQ_H_INCLUDED_
/* @(#$Id: sortseq.h,v 1.6 2006-04-20 09:20:10 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: sortseq.h,v 1.7 2006-09-21 09:37:28 dockes Exp $ (C) 2004 J.F.Dockes */
#include <vector>
#include <string>
#include "docseq.h"
class RclSortSpec {
class DocSeqSortSpec {
public:
RclSortSpec() : sortwidth(0) {}
DocSeqSortSpec() : sortwidth(0) {}
int sortwidth; // We only re-sort the first sortwidth most relevant docs
enum Field {RCLFLD_URL, RCLFLD_IPATH, RCLFLD_MIMETYPE, RCLFLD_MTIME};
void addCrit(Field fld, bool desc = false) {
@ -42,14 +42,14 @@ class RclSortSpec {
*/
class DocSeqSorted : public DocSequence {
public:
DocSeqSorted(DocSequence &iseq, RclSortSpec &sortspec,
DocSeqSorted(DocSequence &iseq, DocSeqSortSpec &sortspec,
const std::string &t);
virtual ~DocSeqSorted() {}
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0);
virtual int getResCnt() {return m_spec.sortwidth;}
private:
RclSortSpec m_spec;
DocSeqSortSpec m_spec;
std::vector<Rcl::Doc> m_docs;
std::vector<Rcl::Doc *> m_docsp;
};