vfs: check userland buffers before reading them.
[haiku.git] / src / apps / text_search / Model.h
blob9edc823eadcc3fd5f02da29fd112c13886a4a003
1 /*
2 * Copyright (c) 1998-2007 Matthijs Hollemans
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5 #ifndef MODEL_H
6 #define MODEL_H
8 #include <Entry.h>
9 #include <File.h>
10 #include <FindDirectory.h>
11 #include <List.h>
12 #include <Menu.h>
13 #include <Message.h>
14 #include <Rect.h>
15 #include <String.h>
17 #include "GlobalDefs.h"
20 enum {
21 MSG_START_CANCEL = 1000,
22 MSG_RECURSE_LINKS,
23 MSG_RECURSE_DIRS,
24 MSG_SKIP_DOT_DIRS,
25 MSG_CASE_SENSITIVE,
26 MSG_REGULAR_EXPRESSION,
27 MSG_TEXT_ONLY,
28 MSG_INVOKE_PE,
29 MSG_CHECKBOX_SHOW_LINES,
30 MSG_SEARCH_TEXT,
31 MSG_INVOKE_ITEM,
32 MSG_SELECT_HISTORY,
33 MSG_NODE_MONITOR_PULSE,
34 MSG_START_NODE_MONITORING,
36 MSG_REPORT_FILE_NAME,
37 MSG_REPORT_RESULT,
38 MSG_REPORT_ERROR,
39 MSG_SEARCH_FINISHED,
41 MSG_NEW_WINDOW,
42 MSG_OPEN_PANEL,
43 MSG_REFS_RECEIVED,
44 MSG_TRY_QUIT,
45 MSG_QUIT_NOW,
47 MSG_TRIM_SELECTION,
48 MSG_COPY_TEXT,
49 MSG_SELECT_IN_TRACKER,
50 MSG_SELECT_ALL,
51 MSG_OPEN_SELECTION
54 enum state_t {
55 STATE_IDLE = 0,
56 STATE_SEARCH,
57 STATE_CANCEL,
58 STATE_UPDATE
61 class Model {
62 public:
63 Model();
65 status_t LoadPrefs();
66 status_t SavePrefs();
68 void AddToHistory(const char* text);
69 void FillHistoryMenu(BMenu* menu) const;
71 public:
72 // The directory we were invoked from.
73 entry_ref fDirectory;
75 // The selected files we were invoked upon.
76 BMessage fSelectedFiles;
78 // Whether we need to look into subdirectories.
79 bool fRecurseDirs;
81 // Whether we need to follow symbolic links.
82 bool fRecurseLinks;
84 // Whether we should skip subdirectories that start with a dot.
85 bool fSkipDotDirs;
87 // Whether the search is case sensitive.
88 bool fCaseSensitive;
90 // Whether the search pattern is a regular expression.
91 bool fRegularExpression;
93 // Whether we look at text files only.
94 bool fTextOnly;
96 // Whether we open the item in Pe and jump to the correct line.
97 bool fInvokePe;
99 // The dimensions of the window.
100 BRect fFrame;
102 // What are we doing.
103 state_t fState;
105 // Current directory of the filepanel
106 BString fFilePanelPath;
108 // Show lines ?
109 bool fShowLines;
111 // Grep string encoding ?
112 uint32 fEncoding;
114 private:
115 bool _LoadHistory(BList& items) const;
116 status_t _SaveHistory(const BList& items) const;
117 void _FreeHistory(const BList& items) const;
118 status_t _OpenFile(BFile* file, const char* name,
119 uint32 openMode = B_READ_ONLY,
120 directory_which which
121 = B_USER_SETTINGS_DIRECTORY,
122 BVolume* volume = NULL) const;
125 #endif // MODEL_H