1 /* Copyright (C) 2005 Jean-Francois Dockes
2  *   This program is free software; you can redistribute it and/or modify
3  *   it under the terms of the GNU General Public License as published by
4  *   the Free Software Foundation; either version 2 of the License, or
5  *   (at your option) any later version.
6  *
7  *   This program is distributed in the hope that it will be useful,
8  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *   GNU General Public License for more details.
11  *
12  *   You should have received a copy of the GNU General Public License
13  *   along with this program; if not, write to the
14  *   Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 #ifndef _GUIUTILS_H_INCLUDED_
18 #define _GUIUTILS_H_INCLUDED_
19 
20 #include <string>
21 #include <list>
22 #include <vector>
23 #include <set>
24 
25 #include <qstring.h>
26 #include <qstringlist.h>
27 
28 #include "dynconf.h"
29 extern RclDynConf *g_dynconf;
30 
31 #include "advshist.h"
32 extern AdvSearchHist *g_advshistory;
33 
34 using std::string;
35 using std::list;
36 using std::vector;
37 
38 /** Holder for preferences (gets saved to user Qt prefs) */
39 class PrefsPack {
40 public:
41     // Simple search entry behaviour
42     bool ssearchNoComplete;
43     bool ssearchStartOnComplete;
44     // Decide if we display the doc category filter control as a
45     // toolbar+combobox or as a button group under simple search
46     enum FilterCtlStyle {FCS_BT, FCS_CMB, FCS_MN};
47     int filterCtlStyle;
48     int respagesize{8};
49     int historysize{0};
50     int maxhltextkbs;
51     QString reslistfontfamily;
52     int reslistfontsize;
53     // Not saved in prefs for now. Computed from qt defaults and used to
54     // set main character color for webkit/textbrowser reslist and
55     // snippets window.
56     QString fontcolor;
57     QString qtermstyle; // CSS style for query terms in reslist and other places
58     // Result list format string
59     QString reslistformat;
60     string  creslistformat;
61     QString reslistheadertext;
62     // This is either empty or the contents of the recoll-dark.css
63     // file if we are in dark mode. It is set in the header before the
64     // possible user string above. Not saved/restored to prefs as it
65     // is controled by darkMode
66     QString darkreslistheadertext;
67     // Date strftime format
68     string reslistdateformat;
69 
70     //  General Qt style sheet.
71     QString qssFile;
72     // Dark mode set-> style sheet is the default dark one. + special reslist header
73     bool darkMode;
74 
75     QString snipCssFile;
76     QString queryStemLang;
77     enum ShowMode {SHOW_NORMAL, SHOW_MAX, SHOW_FULL};
78     int showmode{SHOW_NORMAL};
79     int pvwidth; // Preview window geom
80     int pvheight;
81     bool ssearchTypSav; // Remember last search mode (else always
82     // start with same)
83     int ssearchTyp{0};
84     // Use single app (default: xdg-open), instead of per-mime settings
85     bool useDesktopOpen;
86     // Remember sort state between invocations ?
87     bool keepSort;
88     QString sortField;
89     bool sortActive;
90     bool sortDesc;
91     // Abstract preferences. Building abstracts can slow result display
92     bool queryBuildAbstract{true};
93     bool queryReplaceAbstract{false};
94     // Synthetized abstract length (chars) and word context size (words)
95     int syntAbsLen;
96     int syntAbsCtx;
97     // Abstract snippet separator
98     QString abssep;
99     // Snippets window max list size
100     int snipwMaxLength;
101     // Snippets window sort by page (dflt: by weight)
102     bool snipwSortByPage;
103     // Display Snippets links even for un-paged documents
104     bool alwaysSnippets;
105     bool startWithAdvSearchOpen{false};
106     // Try to display html if it exists in the internfile stack.
107     bool previewHtml;
108     bool previewActiveLinks;
109     // Use <pre> tag to display highlighted text/plain inside html (else
110     // we use <br> at end of lines, which lets textedit wrap lines).
111     enum PlainPre {PP_BR, PP_PRE, PP_PREWRAP};
112     int  previewPlainPre;
113     bool collapseDuplicates;
114     bool showResultsAsTable;
115 
116     // Extra query indexes. This are stored in the history file, not qt prefs
117     vector<string> allExtraDbs;
118     vector<string> activeExtraDbs;
119     // Temporary value while we run a saved query. Erased right after use.
120     bool useTmpActiveExtraDbs{false};
121     vector<string> tmpActiveExtraDbs;
122     // Advanced search subdir restriction: we don't activate the last value
123     // but just remember previously entered values
124     QStringList asearchSubdirHist;
125     // Textual history of simple searches (this is just the combobox list)
126     QStringList ssearchHistory;
127     // Make phrase out of search terms and add to search in simple search
128     bool ssearchAutoPhrase;
129     double ssearchAutoPhraseThreshPC;
130     // Ignored file types in adv search (startup default)
131     QStringList asearchIgnFilTyps;
132     bool        fileTypesByCats;
133     // Words that are automatically turned to ext:xx specs in the query
134     // language entry.
135     QString autoSuffs;
136     bool    autoSuffsEnable;
137     // Synonyms file
138     QString synFile;
139     bool    synFileEnable;
140 
141     // Remembered term match mode
142     int termMatchType{0};
143 
144     // Program version that wrote this. Not used for now, in prevision
145     // of the case where we might need an incompatible change
146     int rclVersion{1505};
147     // Suppress all noises
148     bool noBeeps;
149 
150     bool noToolbars{false};
151     bool noClearSearch{false};
152     bool noStatusBar{false};
153     bool noMenuBar{false};
154     bool noSSTypCMB{false};
155     bool resTableTextNoShift{false};
156     bool resTableNoHoverMeta{false};
157     bool noResTableHeader{false};
158     bool showResTableVHeader{false};
159     bool noResTableRowJumpSC{false};
160     bool showTrayIcon{false};
161     bool closeToTray{false};
162     bool trayMessages{false};
163 
164     // See widgets/qxtconfirmationmessage.
165     // Values -1/positive. -1 will trigger the dialog.
166     int showTempFileWarning{-1};
167 
168     // Advanced search window clause list state
169     vector<int> advSearchClauses;
170 
171     // Default paragraph format for result list
172     static const char *dfltResListFormat;
173 
174     std::string stemlang();
175 
176     void setupDarkCSS();
177 
178     // MIME types for which we prefer to use stored text from preview
179     // rather than extracting the possibly nicer HTML because the
180     // extractor is very slow. This is compiled in and there is no UI
181     // for now.
182     std::set<std::string> preferStoredTextMimes{"application/x-hwp"};
183 };
184 
185 /** Global preferences record */
186 extern PrefsPack prefs;
187 
188 /** Read write settings from disk file */
189 extern void rwSettings(bool dowrite);
190 
191 extern QString g_stringAllStem, g_stringNoStem;
192 
193 #endif /* _GUIUTILS_H_INCLUDED_ */
194