diff --git a/src/qtgui/advshist.cpp b/src/qtgui/advshist.cpp index c7fce88d..881c6528 100644 --- a/src/qtgui/advshist.cpp +++ b/src/qtgui/advshist.cpp @@ -28,14 +28,12 @@ using namespace Rcl; AdvSearchHist::AdvSearchHist() { read(); - m_current = -1; } AdvSearchHist::~AdvSearchHist() { - for (vector >::iterator it = m_entries.begin(); - it != m_entries.end(); it++) { - it->reset(); + for (auto& entry : m_entries) { + entry.reset(); } } @@ -71,7 +69,11 @@ bool AdvSearchHist::push(std::shared_ptr sd) m_current++; string xml = sd->asXML(); - g_dynconf->enterString(advSearchHistSk, xml, 100); + // dynconf interprets <= 0 as unlimited size, but we want 0 to + // disable saving history + if (prefs.historysize != 0) { + g_dynconf->enterString(advSearchHistSk, xml, prefs.historysize); + } return true; } diff --git a/src/qtgui/advshist.h b/src/qtgui/advshist.h index 92b31ded..a8ac2b63 100644 --- a/src/qtgui/advshist.h +++ b/src/qtgui/advshist.h @@ -58,7 +58,7 @@ public: private: bool read(); - int m_current; + int m_current{-1}; std::vector > m_entries; }; diff --git a/src/qtgui/guiutils.cpp b/src/qtgui/guiutils.cpp index c19872fe..79ef724f 100644 --- a/src/qtgui/guiutils.cpp +++ b/src/qtgui/guiutils.cpp @@ -137,6 +137,7 @@ void rwSettings(bool writing) SETTING_RW(prefs.ssearchAutoPhraseThreshPC, "/Recoll/prefs/ssearchAutoPhraseThreshPC", Double, 2.0); SETTING_RW(prefs.respagesize, "/Recoll/prefs/reslist/pagelen", Int, 8); + SETTING_RW(prefs.historysize, "/Recoll/prefs/historysize", Int, 0); SETTING_RW(prefs.collapseDuplicates, "/Recoll/prefs/reslist/collapseDuplicates", Bool, false); SETTING_RW(prefs.showResultsAsTable, diff --git a/src/qtgui/guiutils.h b/src/qtgui/guiutils.h index d741f0a8..2d3ec863 100644 --- a/src/qtgui/guiutils.h +++ b/src/qtgui/guiutils.h @@ -44,7 +44,8 @@ class PrefsPack { // toolbar+combobox or as a button group under simple search enum FilterCtlStyle {FCS_BT, FCS_CMB, FCS_MN}; int filterCtlStyle; - int respagesize; + int respagesize{8}; + int historysize{0}; int maxhltextmbs; QString reslistfontfamily; // Not saved in prefs for now. Computed from qt defaults and used to @@ -73,7 +74,7 @@ class PrefsPack { int resArea; // Area for "results" toolbar bool ssearchTypSav; // Remember last search mode (else always // start with same) - int ssearchTyp; + int ssearchTyp{0}; // Use single app (default: xdg-open), instead of per-mime settings bool useDesktopOpen; // Remember sort state between invocations ? @@ -82,8 +83,8 @@ class PrefsPack { bool sortActive; bool sortDesc; // Abstract preferences. Building abstracts can slow result display - bool queryBuildAbstract; - bool queryReplaceAbstract; + bool queryBuildAbstract{true}; + bool queryReplaceAbstract{false}; // Synthetized abstract length (chars) and word context size (words) int syntAbsLen; int syntAbsCtx; @@ -93,7 +94,7 @@ class PrefsPack { int snipwMaxLength; // Snippets window sort by page (dflt: by weight) bool snipwSortByPage; - bool startWithAdvSearchOpen; + bool startWithAdvSearchOpen{false}; // Try to display html if it exists in the internfile stack. bool previewHtml; bool previewActiveLinks; @@ -130,16 +131,16 @@ class PrefsPack { vector restableColWidths; // Remembered term match mode - int termMatchType; + int termMatchType{0}; // Program version that wrote this. Not used for now, in prevision // of the case where we might need an incompatible change - int rclVersion; + int rclVersion{1505}; // Suppress all noises bool noBeeps; - bool showTrayIcon; - bool closeToTray; + bool showTrayIcon{false}; + bool closeToTray{false}; int showTempFileWarning; @@ -151,18 +152,6 @@ class PrefsPack { std::string stemlang(); - PrefsPack() : - respagesize(8), - reslistfontsize(10), - ssearchTyp(0), - queryBuildAbstract(true), - queryReplaceAbstract(false), - startWithAdvSearchOpen(false), - termMatchType(0), - rclVersion(1505), - showTrayIcon(false), - closeToTray(false) - {} }; /** Global preferences record */ diff --git a/src/qtgui/ssearch_w.cpp b/src/qtgui/ssearch_w.cpp index 9544815d..00bb963e 100644 --- a/src/qtgui/ssearch_w.cpp +++ b/src/qtgui/ssearch_w.cpp @@ -364,8 +364,16 @@ void SSearch::startSimpleSearch() QString txt = currentText().trimmed(); if (txt.isEmpty()) return; - prefs.ssearchHistory.insert(0, txt); - prefs.ssearchHistory.removeDuplicates(); + if (prefs.historysize) { + prefs.ssearchHistory.insert(0, txt); + prefs.ssearchHistory.removeDuplicates(); + } + if (prefs.historysize >= 0) { + for (int i = (int)prefs.ssearchHistory.count(); + i > prefs.historysize; i--) { + prefs.ssearchHistory.removeLast(); + } + } } void SSearch::setPrefs() diff --git a/src/qtgui/uiprefs.ui b/src/qtgui/uiprefs.ui index 83a9eda5..228f2166 100644 --- a/src/qtgui/uiprefs.ui +++ b/src/qtgui/uiprefs.ui @@ -61,7 +61,7 @@ - Style sheet + Application Qt style sheet false @@ -259,14 +259,37 @@ - - - Suppress all beeps. - - - false - - + + + + + + 1 + 0 + + + + Limit the size of the search history. Use 0 to disable, -1 for unlimited. + + + Maximum size of search history (0: disable, -1: unlimited): + + + false + + + + + + + -1 + + + 0 + + + + @@ -338,6 +361,16 @@ + + + + Suppress all beeps. + + + false + + + diff --git a/src/qtgui/uiprefs_w.cpp b/src/qtgui/uiprefs_w.cpp index a06294ad..879a4585 100644 --- a/src/qtgui/uiprefs_w.cpp +++ b/src/qtgui/uiprefs_w.cpp @@ -110,6 +110,7 @@ void UIPrefsDialog::setFromPrefs() // Entries per result page spinbox pageLenSB->setValue(prefs.respagesize); + maxHistSizeSB->setValue(prefs.historysize); collapseDupsCB->setChecked(prefs.collapseDuplicates); maxHLTSB->setValue(prefs.maxhltextmbs); @@ -294,6 +295,7 @@ void UIPrefsDialog::accept() m_mainWindow->setFilterCtlStyle(prefs.filterCtlStyle); prefs.respagesize = pageLenSB->value(); + prefs.historysize = maxHistSizeSB->value(); prefs.collapseDuplicates = collapseDupsCB->isChecked(); prefs.maxhltextmbs = maxHLTSB->value();