xref: /haiku/src/apps/text_search/Model.h (revision f2b4344867e97c3f4e742a1b4a15e6879644601a)
1 /*
2  * Copyright (c) 1998-2007 Matthijs Hollemans
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 #ifndef MODEL_H
23 #define MODEL_H
24 
25 #include <Entry.h>
26 #include <File.h>
27 #include <FindDirectory.h>
28 #include <List.h>
29 #include <Menu.h>
30 #include <Message.h>
31 #include <Rect.h>
32 #include <String.h>
33 
34 #include "GlobalDefs.h"
35 
36 
37 enum {
38 	MSG_START_CANCEL = 1000,
39 	MSG_RECURSE_LINKS,
40 	MSG_RECURSE_DIRS,
41 	MSG_SKIP_DOT_DIRS,
42 	MSG_CASE_SENSITIVE,
43 	MSG_ESCAPE_TEXT,
44 	MSG_TEXT_ONLY,
45 	MSG_INVOKE_PE,
46 	MSG_MENU_SHOW_LINES,
47 	MSG_CHECKBOX_SHOW_LINES,
48 	MSG_SEARCH_TEXT,
49 	MSG_INVOKE_ITEM,
50 	MSG_SELECT_HISTORY,
51 	MSG_NODE_MONITOR_PULSE,
52 	MSG_START_NODE_MONITORING,
53 
54 	MSG_REPORT_FILE_NAME,
55 	MSG_REPORT_RESULT,
56 	MSG_REPORT_ERROR,
57 	MSG_SEARCH_FINISHED,
58 
59 	MSG_NEW_WINDOW,
60 	MSG_OPEN_PANEL,
61 	MSG_REFS_RECEIVED,
62 	MSG_TRY_QUIT,
63 	MSG_QUIT_NOW,
64 
65 	MSG_TRIM_SELECTION,
66 	MSG_COPY_TEXT,
67 	MSG_SELECT_IN_TRACKER,
68 	MSG_SELECT_ALL,
69 	MSG_OPEN_SELECTION
70 };
71 
72 enum state_t {
73 	STATE_IDLE = 0,
74 	STATE_SEARCH,
75 	STATE_CANCEL,
76 	STATE_UPDATE
77 };
78 
79 class Model {
80 public:
81 								Model();
82 
83 			status_t			LoadPrefs();
84 			status_t			SavePrefs();
85 
86 			void				AddToHistory(const char* text);
87 			void				FillHistoryMenu(BMenu* menu) const;
88 
89 public:
90 			// The directory we were invoked from.
91 			entry_ref			fDirectory;
92 
93 			// The selected files we were invoked upon.
94 			BMessage			fSelectedFiles;
95 
96 			// Whether we need to look into subdirectories.
97 			bool				fRecurseDirs;
98 
99 			// Whether we need to follow symbolic links.
100 			bool				fRecurseLinks;
101 
102 			// Whether we should skip subdirectories that start with a dot.
103 			bool				fSkipDotDirs;
104 
105 			// Whether the search is case sensitive.
106 			bool				fCaseSensitive;
107 
108 			// Whether the search pattern will be escaped.
109 			bool				fEscapeText;
110 
111 			// Whether we look at text files only.
112 			bool				fTextOnly;
113 
114 			// Whether we open the item in Pe and jump to the correct line.
115 			bool				fInvokePe;
116 
117 			// Whether to show the contents of matching files.
118 			bool				fShowContents;
119 
120 			// The dimensions of the window.
121 			BRect				fFrame;
122 
123 			// What are we doing.
124 			state_t				fState;
125 
126 			// Current directory of the filepanel
127 			BString				fFilePanelPath;
128 
129 			// Grep string encoding ?
130 			uint32				fEncoding;
131 
132 private:
133 			bool				_LoadHistory(BList& items) const;
134 			status_t			_SaveHistory(const BList& items) const;
135 			void				_FreeHistory(const BList& items) const;
136 			status_t			_OpenFile(BFile* file, const char* name,
137 									uint32 openMode = B_READ_ONLY,
138 									directory_which which
139 										= B_USER_SETTINGS_DIRECTORY,
140 									BVolume* volume = NULL) const;
141 };
142 
143 #endif // MODEL_H
144