From a3db7c1937c88ba2ebb32db252e4dbc2956996bf Mon Sep 17 00:00:00 2001 From: dockes Date: Mon, 11 Sep 2006 12:05:39 +0000 Subject: [PATCH] remember history of restrict subdirs in adv search --- src/qtgui/advsearch.ui | 58 ++++++++++++++++++++++++++++----------- src/qtgui/advsearch_w.cpp | 54 ++++++++++++++++++++++++------------ src/qtgui/guiutils.cpp | 23 ++++++++++++---- src/qtgui/guiutils.h | 5 +++- src/qtgui/ssearch_w.cpp | 10 +++++-- src/qtgui/ssearchb.ui | 2 +- src/query/history.cpp | 16 ++++++++++- src/query/history.h | 3 +- 8 files changed, 126 insertions(+), 45 deletions(-) diff --git a/src/qtgui/advsearch.ui b/src/qtgui/advsearch.ui index 8a731e1c..99fb7f85 100644 --- a/src/qtgui/advsearch.ui +++ b/src/qtgui/advsearch.ui @@ -332,9 +332,17 @@ unnamed - + - subtreeLE + subtreeCMB + + + + 7 + 0 + 8 + 0 + @@ -342,6 +350,24 @@ 0 + + true + + + 10 + + + 20 + + + AtTop + + + true + + + Enter top directory for search + @@ -364,20 +390,20 @@ - - - line1 - - - HLine - - - Sunken - - - Horizontal - - + + + line1 + + + HLine + + + Sunken + + + Horizontal + + layout25 diff --git a/src/qtgui/advsearch_w.cpp b/src/qtgui/advsearch_w.cpp index 1e685f85..34411805 100644 --- a/src/qtgui/advsearch_w.cpp +++ b/src/qtgui/advsearch_w.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: advsearch_w.cpp,v 1.1 2006-09-04 15:13:01 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: advsearch_w.cpp,v 1.2 2006-09-11 12:05:38 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -25,6 +25,7 @@ static char rcsid[] = "@(#$Id: advsearch_w.cpp,v 1.1 2006-09-04 15:13:01 dockes #include #include #include +#include #include #include #include @@ -44,26 +45,33 @@ using std::string; #include "rclconfig.h" #include "debuglog.h" #include "searchdata.h" +#include "guiutils.h" extern RclConfig *rclconfig; void AdvSearch::init() { // signals and slots connections - connect( delFiltypPB, SIGNAL( clicked() ), this, SLOT( delFiltypPB_clicked() ) ); - connect( searchPB, SIGNAL( clicked() ), this, SLOT( searchPB_clicked() ) ); - connect( restrictFtCB, SIGNAL( toggled(bool) ), this, SLOT( restrictFtCB_toggled(bool) ) ); - connect( dismissPB, SIGNAL( clicked() ), this, SLOT( close() ) ); - connect( browsePB, SIGNAL( clicked() ), this, SLOT( browsePB_clicked() ) ); - connect( addFiltypPB, SIGNAL( clicked() ), this, SLOT( addFiltypPB_clicked() ) ); - connect( andWordsLE, SIGNAL( returnPressed() ), this, SLOT( searchPB_clicked() ) ); - connect( orWordsLE, SIGNAL( returnPressed() ), this, SLOT( searchPB_clicked() ) ); - connect( noWordsLE, SIGNAL( returnPressed() ), this, SLOT( searchPB_clicked() ) ); - connect( phraseLE, SIGNAL( returnPressed() ), this, SLOT( searchPB_clicked() ) ); - connect( subtreeLE, SIGNAL( returnPressed() ), this, SLOT( searchPB_clicked() ) ); - connect( delAFiltypPB, SIGNAL( clicked() ), this, SLOT( delAFiltypPB_clicked() ) ); - connect( addAFiltypPB, SIGNAL( clicked() ), this, SLOT( addAFiltypPB_clicked() ) ); - + connect(delFiltypPB, SIGNAL(clicked()), this, SLOT(delFiltypPB_clicked())); + connect(searchPB, SIGNAL(clicked()), this, SLOT(searchPB_clicked())); + connect(restrictFtCB, SIGNAL(toggled(bool)), + this, SLOT(restrictFtCB_toggled(bool))); + connect(dismissPB, SIGNAL(clicked()), this, SLOT(close())); + connect(browsePB, SIGNAL(clicked()), this, SLOT(browsePB_clicked())); + connect(addFiltypPB, SIGNAL(clicked()), this, SLOT(addFiltypPB_clicked())); + connect(andWordsLE, SIGNAL(returnPressed()), + this, SLOT(searchPB_clicked())); + connect(orWordsLE, SIGNAL(returnPressed()), + this, SLOT(searchPB_clicked())); + connect(noWordsLE, SIGNAL(returnPressed()), + this, SLOT(searchPB_clicked())); + connect(phraseLE, SIGNAL(returnPressed()), this, SLOT(searchPB_clicked())); + connect(subtreeCMB->lineEdit(), SIGNAL(returnPressed()), + this, SLOT(searchPB_clicked())); + connect(delAFiltypPB, SIGNAL(clicked()), + this, SLOT(delAFiltypPB_clicked())); + connect(addAFiltypPB, SIGNAL(clicked()), + this, SLOT(addAFiltypPB_clicked())); list types = rclconfig->getAllMimeTypes(); @@ -73,6 +81,8 @@ void AdvSearch::init() } yesFiltypsLB->insertStringList(ql); + subtreeCMB->insertStringList(prefs.asearchSubdirHist); + subtreeCMB->setEditText(""); } @@ -174,8 +184,16 @@ void AdvSearch::searchPB_clicked() mydata.filetypes.push_back(string((const char *)ctext)); } } - if (!subtreeLE->text().isEmpty()) { - mydata.topdir = string((const char*)(subtreeLE->text().utf8())); + + if (!subtreeCMB->currentText().isEmpty()) { + mydata.topdir = + string((const char*)(subtreeCMB->currentText().utf8())); + // If this was started by clicking, need to insert the new entry + if (subtreeCMB->text(0) != subtreeCMB->currentText()) + subtreeCMB->insertItem(subtreeCMB->currentText(), 0); + prefs.asearchSubdirHist.clear(); + for (int index = 0; index < subtreeCMB->count(); index++) + prefs.asearchSubdirHist.push_back(subtreeCMB->text(index)); } emit startSearch(mydata); } @@ -184,6 +202,6 @@ void AdvSearch::searchPB_clicked() void AdvSearch::browsePB_clicked() { QString dir = QFileDialog::getExistingDirectory(); - subtreeLE->setText(dir); + subtreeCMB->setEditText(dir); } diff --git a/src/qtgui/guiutils.cpp b/src/qtgui/guiutils.cpp index fd868801..45ff8b57 100644 --- a/src/qtgui/guiutils.cpp +++ b/src/qtgui/guiutils.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.14 2006-09-11 09:08:44 dockes Exp $ (C) 2005 Jean-Francois Dockes"; +static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.15 2006-09-11 12:05:38 dockes Exp $ (C) 2005 Jean-Francois Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -167,7 +167,6 @@ void rwSettings(bool writing) const string allEdbsSk = "allExtDbs"; const string actEdbsSk = "actExtDbs"; if (writing) { - LOGDEB(("settings: writing to dynconf\n")); g_dynconf->eraseAll(allEdbsSk); for (list::const_iterator it = prefs.allExtraDbs.begin(); it != prefs.allExtraDbs.end(); it++) { @@ -203,7 +202,6 @@ void rwSettings(bool writing) } prefs.activeExtraDbs = g_dynconf->getStringList(actEdbsSk); } - #if 0 { list::const_iterator it; @@ -219,6 +217,21 @@ void rwSettings(bool writing) } } #endif + + + const string asbdSk = "asearchSbd"; + if (writing) { + while (prefs.asearchSubdirHist.size() > 20) + prefs.asearchSubdirHist.pop_back(); + g_dynconf->eraseAll(asbdSk); + for (QStringList::iterator it = prefs.asearchSubdirHist.begin(); + it != prefs.asearchSubdirHist.end(); it++) { + g_dynconf->enterString(asbdSk, (const char *)((*it).utf8())); + } + } else { + list tl = g_dynconf->getStringList(asbdSk); + for (list::iterator it = tl.begin(); it != tl.end(); it++) + prefs.asearchSubdirHist.push_front(QString::fromUtf8(it->c_str())); + } + } - - diff --git a/src/qtgui/guiutils.h b/src/qtgui/guiutils.h index 52766353..6a8222b0 100644 --- a/src/qtgui/guiutils.h +++ b/src/qtgui/guiutils.h @@ -17,7 +17,7 @@ #ifndef _GUIUTILS_H_INCLUDED_ #define _GUIUTILS_H_INCLUDED_ /* - * @(#$Id: guiutils.h,v 1.6 2006-04-27 09:23:10 dockes Exp $ (C) 2005 Jean-Francois Dockes + * @(#$Id: guiutils.h,v 1.7 2006-09-11 12:05:38 dockes Exp $ (C) 2005 Jean-Francois Dockes * jean-francois.dockes@wanadoo.fr * * This program is free software; you can redistribute it and/or modify @@ -68,6 +68,9 @@ class PrefsPack { // to the qt settings file to avoid any bin string/ charset conv issues list allExtraDbs; list activeExtraDbs; + // Advanced search subdir restriction: we don't activate the last value + // but just remember previously entered values + QStringList asearchSubdirHist; // Textual history of simple searches (this is just the combobox list) QStringList ssearchHistory; diff --git a/src/qtgui/ssearch_w.cpp b/src/qtgui/ssearch_w.cpp index 48eed7f5..aec973a3 100644 --- a/src/qtgui/ssearch_w.cpp +++ b/src/qtgui/ssearch_w.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: ssearch_w.cpp,v 1.2 2006-09-11 07:10:25 dockes Exp $ (C) 2006 J.F.Dockes"; +static char rcsid[] = "@(#$Id: ssearch_w.cpp,v 1.3 2006-09-11 12:05:38 dockes Exp $ (C) 2006 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -66,6 +66,8 @@ void SSearch::startSimpleSearch() { LOGDEB(("SSearch::startSimpleSearch\n")); + if (queryText->currentText().length() == 0) + return; Rcl::AdvSearchData sdata; QCString u8 = queryText->currentText().utf8(); switch (searchTypCMB->currentItem()) { @@ -81,6 +83,8 @@ void SSearch::startSimpleSearch() break; } + // Search terms history + // Need to remove any previous occurence of the search entry from // the listbox list, The qt listbox doesn't do lru correctly (if // already in the list the new entry would remain at it's place, @@ -96,11 +100,13 @@ void SSearch::startSimpleSearch() } } } while (changed); + if (queryText->text(0) != queryText->currentText()) + queryText->insertItem(queryText->currentText(), 0); // Save the current state of the listbox list to file prefs.ssearchHistory.clear(); for (int index = 0; index < queryText->count(); index++) - prefs.ssearchHistory.push_back(queryText->text(index)); + prefs.ssearchHistory.push_back(queryText->text(index).utf8()); emit startSearch(sdata); } diff --git a/src/qtgui/ssearchb.ui b/src/qtgui/ssearchb.ui index 4d9f16d1..b5b35f92 100644 --- a/src/qtgui/ssearchb.ui +++ b/src/qtgui/ssearchb.ui @@ -103,7 +103,7 @@ AtTop - true + false Enter search terms here diff --git a/src/query/history.cpp b/src/query/history.cpp index e51ec8b3..512020b0 100644 --- a/src/query/history.cpp +++ b/src/query/history.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: history.cpp,v 1.6 2006-09-11 09:08:44 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: history.cpp,v 1.7 2006-09-11 12:05:39 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -150,6 +150,20 @@ bool RclHistory::eraseAll(const string &sk) } return true; } +bool RclHistory::truncate(const string &sk, unsigned int n) +{ + // Is this doc already in history ? If it is we remove the old entry + list names = m_data.getNames(sk); + if (names.size() <= n) + return true; + unsigned int i = 0; + for (list::const_iterator it = names.begin(); + it != names.end(); it++, i++) { + if (i >= n) + m_data.erase(*it, sk); + } + return true; +} bool RclHistory::enterString(const string sk, const string value) diff --git a/src/query/history.h b/src/query/history.h index 47514552..f4a7a0ff 100644 --- a/src/query/history.h +++ b/src/query/history.h @@ -16,7 +16,7 @@ */ #ifndef _HISTORY_H_INCLUDED_ #define _HISTORY_H_INCLUDED_ -/* @(#$Id: history.h,v 1.4 2006-09-11 09:08:44 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: history.h,v 1.5 2006-09-11 12:05:39 dockes Exp $ (C) 2004 J.F.Dockes */ /** * Dynamic configuration storage @@ -101,6 +101,7 @@ class RclHistory { bool enterString(const string sk, const string value); list getStringList(const string sk); bool eraseAll(const string& sk); + bool truncate(const string& sk, unsigned int n); private: unsigned int m_mlen;