Save adv search clause list + add delete button

This commit is contained in:
dockes 2006-11-17 15:26:40 +00:00
parent 350a7c49fe
commit 078b414cab
5 changed files with 119 additions and 11 deletions

View File

@ -118,6 +118,25 @@
</size>
</property>
</spacer>
<widget class="QPushButton">
<property name="name">
<cstring>delClausePB</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Delete clause</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>addClausePB</cstring>

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: advsearch_w.cpp,v 1.11 2006-11-17 10:08:12 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: advsearch_w.cpp,v 1.12 2006-11-17 15:26:40 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -50,6 +50,7 @@ using std::string;
extern RclConfig *rclconfig;
static const int initclausetypes[] = {1, 3, 0, 0, 2, 5};
static const unsigned int iclausescnt = sizeof(initclausetypes) / sizeof(int);
void AdvSearch::init()
{
@ -71,15 +72,29 @@ void AdvSearch::init()
connect(saveFileTypesPB, SIGNAL(clicked()),
this, SLOT(saveFileTypes()));
connect(addClausePB, SIGNAL(clicked()), this, SLOT(addClause()));
connect(delClausePB, SIGNAL(clicked()), this, SLOT(delClause()));
conjunctCMB->insertItem(tr("All clauses"));
conjunctCMB->insertItem(tr("Any clause"));
// Create preconfigured clauses
for (unsigned int i = 0; i < sizeof(initclausetypes) / sizeof(int); i++) {
for (unsigned int i = 0; i < iclausescnt; i++) {
addClause(initclausetypes[i]);
}
// Tune initial state according to last saved
{
std::list<SearchClauseW *>::iterator cit = m_clauseWins.begin();
for (vector<int>::iterator it = prefs.advSearchClauses.begin();
it != prefs.advSearchClauses.end(); it++) {
if (cit != m_clauseWins.end()) {
(*cit)->tpChange(*it);
cit++;
} else {
addClause(*it);
}
}
}
// Initialize lists of accepted and ignored mime types from config
// and settings
list<string> types = rclconfig->getAllMimeTypes();
@ -102,6 +117,21 @@ void AdvSearch::init()
clauseline->close();
}
void AdvSearch::saveCnf()
{
// Save my state
prefs.advSearchClauses.clear();
for (std::list<SearchClauseW *>::iterator cit = m_clauseWins.begin();
cit != m_clauseWins.end(); cit++) {
prefs.advSearchClauses.push_back((*cit)->sTpCMB->currentItem());
}
}
bool AdvSearch::close()
{
saveCnf();
return AdvSearchBase::close();
}
// Move selected file types from the searched to the ignored box
void AdvSearch::delFiltypPB_clicked()
@ -155,11 +185,38 @@ void AdvSearch::addClause(int tp)
clauseVBox->addWidget(w);
w->show();
w->tpChange(tp);
if (m_clauseWins.size() > iclausescnt) {
delClausePB->setEnabled(true);
} else {
delClausePB->setEnabled(false);
}
// Have to adjust the size else we lose the bottom buttons! Why?
QSize sz = AdvSearchBaseLayout->sizeHint();
resize(QSize(sz.width()+40, sz.height()+80));
}
void AdvSearch::delClause()
{
if (m_clauseWins.size() <= iclausescnt)
return;
delete m_clauseWins.back();
m_clauseWins.pop_back();
if (m_clauseWins.size() > iclausescnt) {
delClausePB->setEnabled(true);
} else {
delClausePB->setEnabled(false);
}
QSize sz = AdvSearchBaseLayout->sizeHint();
resize(QSize(sz.width()+40, sz.height()+80));
}
void AdvSearch::polish()
{
QSize sz = AdvSearchBaseLayout->sizeHint();
resize(QSize(sz.width()+40, sz.height()+80));
AdvSearchBase::polish();
}
// Move selected file types from the ignored to the searched box
void AdvSearch::addFiltypPB_clicked()
{
@ -248,10 +305,11 @@ void AdvSearch::searchPB_clicked()
for (int index = 0; index < subtreeCMB->count(); index++)
prefs.asearchSubdirHist.push_back(subtreeCMB->text(index));
}
saveCnf();
emit startSearch(sdata);
}
void AdvSearch::browsePB_clicked()
{
QString dir = QFileDialog::getExistingDirectory();

View File

@ -1,6 +1,6 @@
#ifndef _ADVSEARCH_W_H_INCLUDED_
#define _ADVSEARCH_W_H_INCLUDED_
/* @(#$Id: advsearch_w.h,v 1.6 2006-11-14 18:29:09 dockes Exp $ (C) 2005 J.F.Dockes */
/* @(#$Id: advsearch_w.h,v 1.7 2006-11-17 15:26:40 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
@ -46,8 +46,11 @@ public slots:
virtual void searchPB_clicked();
virtual void browsePB_clicked();
virtual void saveFileTypes();
virtual void delClause();
virtual void addClause();
virtual void addClause(int);
virtual bool close();
virtual void polish();
signals:
void startSearch(RefCntr<Rcl::SearchData>);
@ -55,6 +58,7 @@ signals:
private:
virtual void init();
std::list<SearchClauseW *> m_clauseWins;
void saveCnf();
};

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.23 2006-11-10 13:32:08 dockes Exp $ (C) 2005 Jean-Francois Dockes";
static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.24 2006-11-17 15:26:40 dockes Exp $ (C) 2005 Jean-Francois Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -147,6 +147,27 @@ void rwSettings(bool writing)
"/Recoll/prefs/startWithAdvSearchOpen", Bool, false);
SETTING_RW(prefs.startWithSortToolOpen,
"/Recoll/prefs/startWithSortToolOpen", Bool, false);
QString advSearchClauses;
QString ascdflt = QString::fromAscii("1 3 0 0 2 5 ");
if (writing) {
for (vector<int>::iterator it = prefs.advSearchClauses.begin();
it != prefs.advSearchClauses.end(); it++) {
char buf[20];
sprintf(buf, "%d ", *it);
advSearchClauses += QString::fromAscii(buf);
}
}
SETTING_RW(advSearchClauses, "/Recoll/prefs/adv/clauseList", , ascdflt);
if (!writing) {
list<string> clauses;
stringToStrings(advSearchClauses, clauses);
for (list<string>::iterator it = clauses.begin();
it != clauses.end(); it++) {
prefs.advSearchClauses.push_back(atoi(it->c_str()));
}
}
SETTING_RW(prefs.showicons, "/Recoll/prefs/reslist/showicons", Bool, true);
SETTING_RW(prefs.autoSearchOnWS, "/Recoll/prefs/reslist/autoSearchOnWS",
Bool, false);
@ -157,10 +178,10 @@ void rwSettings(bool writing)
"");
SETTING_RW(prefs.reslistfontsize, "/Recoll/prefs/reslist/fontSize", Num,
0);
QString rlfDflt =QString::fromAscii(
"%R %S %L &nbsp;&nbsp;<b>%T</b><br>"
"%M&nbsp;%D&nbsp;&nbsp;&nbsp;<i>%U</i><br>"
"%A %K");
QString rlfDflt =
QString::fromAscii("%R %S %L &nbsp;&nbsp;<b>%T</b><br>"
"%M&nbsp;%D&nbsp;&nbsp;&nbsp;<i>%U</i><br>"
"%A %K");
SETTING_RW(prefs.reslistformat, "/Recoll/prefs/reslist/format", , rlfDflt);
if (prefs.reslistformat.stripWhiteSpace().isEmpty())
prefs.reslistformat = rlfDflt;

View File

@ -17,7 +17,7 @@
#ifndef _GUIUTILS_H_INCLUDED_
#define _GUIUTILS_H_INCLUDED_
/*
* @(#$Id: guiutils.h,v 1.15 2006-11-10 13:32:08 dockes Exp $ (C) 2005 Jean-Francois Dockes
* @(#$Id: guiutils.h,v 1.16 2006-11-17 15:26:40 dockes Exp $ (C) 2005 Jean-Francois Dockes
* jean-francois.dockes@wanadoo.fr
*
* This program is free software; you can redistribute it and/or modify
@ -38,12 +38,15 @@
#include <string>
#include <list>
#include <vector>
#include <qstring.h>
#include <qstringlist.h>
#ifndef NO_NAMESPACES
using std::string;
using std::list;
using std::vector;
#endif
/** Start a browser on the help document */
@ -96,6 +99,9 @@ class PrefsPack {
// Remembered term match mode
int termMatchType;
// Advanced search window clause list state
vector<int> advSearchClauses;
PrefsPack() :
showicons(true),
respagesize(8),