xref: /haiku/src/kits/tracker/Tracker.h (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 #ifndef _TRACKER_H
35 #define _TRACKER_H
36 
37 
38 #include <Application.h>
39 #include <Resources.h>
40 #include <Entry.h>
41 
42 #include "LockingList.h"
43 #include "SettingsHandler.h"
44 #include "Utilities.h"
45 
46 #include "tracker_private.h"
47 
48 namespace BPrivate {
49 
50 class BClipboardRefsWatcher;
51 class BContainerWindow;
52 class BDeskWindow;
53 class BInfoWindow;
54 class BTrashWatcher;
55 class ExtraAttributeLazyInstaller;
56 class MimeTypeList;
57 class Model;
58 class BooleanValueSetting;
59 class ScalarValueSetting;
60 class HexScalarValueSetting;
61 class TaskLoop;
62 class TrackerSettingsWindow;
63 
64 typedef LockingList<BWindow> WindowList;
65 	// this is because MW can't handle nested templates
66 
67 
68 const uint32 kNextSpecifier = 'snxt';
69 const uint32 kPreviousSpecifier = 'sprv';
70 const uint32 B_ENTRY_SPECIFIER = 'sref';
71 
72 #define kPropertyEntry "Entry"
73 #define kPropertySelection "Selection"
74 
75 
76 
77 class TTracker : public BApplication {
78 	public:
79 		TTracker();
80 		virtual ~TTracker();
81 
82 		// BApplication overrides
83 		virtual void Quit();
84 		virtual bool QuitRequested();
85 		virtual void ReadyToRun();
86 		virtual void MessageReceived(BMessage*);
87 		virtual void Pulse();
88 		virtual void RefsReceived(BMessage*);
89 		virtual void ArgvReceived(int32 argc, char** argv);
90 
91 		MimeTypeList* MimeTypes() const;
92 			// list of mime types that have a description and do not have
93 			// themselves as a preferred handler (case of applications)
94 
95 		bool TrashFull() const;
96 		bool IsTrashNode(const node_ref*) const;
97 		bool InTrashNode(const entry_ref*) const;
98 
99 		void CloseParentWaitingForChildSoon(const entry_ref* child,
100 				const node_ref* parent);
101 			// closes parent, waits for child to open first
102 
103 		void SelectChildInParentSoon(const entry_ref* child,
104 				const node_ref* parent);
105 			// waits till child shows up in parent and selects it
106 
107 		void SelectPoseAtLocationSoon(node_ref parent, BPoint location);
108 			// Used to select next item when deleting in list view mode
109 
110 		enum OpenSelector {
111 			kOpen,
112 			kOpenWith,
113 			kRunOpenWithWindow
114 		};
115 
116 		bool EntryHasWindowOpen(const entry_ref*);
117 			// return true if there is an open window for an entry
118 
119 		status_t NeedMoreNodeMonitors();
120 			// call if ran out of node monitors to allocate more
121 			// return false if already using all we can get
122 		static status_t WatchNode(const node_ref*, uint32 flags,
123 					BMessenger target);
124 			// cover call for watch_node; if first watch_node fails,
125 			// tries bumping the node monitor limit and calls watch_node
126 			// again
127 
128 		TaskLoop* MainTaskLoop() const;
129 		BMessenger MountServer() const;
130 
131 		bool QueryActiveForDevice(dev_t);
132 		void CloseActiveQueryWindows(dev_t);
133 
134 		void SaveAllPoseLocations();
135 
136 		void CloseParent(node_ref closeThis);
137 
138 		void ShowSettingsWindow();
139 
140 		BContainerWindow* FindContainerWindow(const node_ref*,
141 			int32 number = 0) const;
142 		BContainerWindow* FindContainerWindow(const entry_ref*,
143 			int32 number = 0) const;
144 		BContainerWindow* FindParentContainerWindow(const entry_ref*) const;
145 			// right now works just on plain windows, not on query windows
146 
147 		BClipboardRefsWatcher* ClipboardRefsWatcher() const;
148 
149 	protected:
150 		// scripting
151 		virtual BHandler* ResolveSpecifier(BMessage*, int32, BMessage*,
152 			int32, const char*);
153 		virtual status_t GetSupportedSuites(BMessage*);
154 
155 		bool HandleScriptingMessage(BMessage*);
156 
157 		bool ExecuteProperty(BMessage*, int32, const char*, BMessage*);
158 		bool CreateProperty(BMessage*, BMessage*, int32, const char*,
159 				BMessage*);
160 		bool DeleteProperty(BMessage*, int32,
161 				const char*, BMessage*);
162 		bool CountProperty(BMessage*, int32, const char*, BMessage*);
163 		bool GetProperty(BMessage*, int32, const char*, BMessage*);
164 		bool SetProperty(BMessage*, BMessage*, int32, const char*, BMessage*);
165 
166 	private:
167 		// callbacks for ChildParentSoon calls
168 		bool CloseParentWaitingForChild(const entry_ref* child,
169 				const node_ref* parent);
170 		bool LaunchAndCloseParentIfOK(const entry_ref* launchThis,
171 				const node_ref* closeThis, const BMessage* messageToBundle);
172 		bool SelectChildInParent(const entry_ref* child,
173 				const node_ref* parent);
174 		void SelectPoseAtLocationInParent(node_ref parent, BPoint location);
175 		bool CloseParentWindowCommon(BContainerWindow*);
176 
177 		void InitMimeTypes();
178 		bool InstallMimeIfNeeded(const char* type, int32 bitsID,
179 				const char* shortDescription, const char* longDescription,
180 				const char* preferredAppSignature, uint32 forceMask = 0);
181 			// used by InitMimeTypes - checks if a metamime of a given <type>
182 			// is installed and if it has all the specified attributes;
183 			// if not, the whole mime type is installed and all attributes
184 			// are set; nulls can be passed for attributes that don't matter;
185 			// returns true if anything had to be changed <forceMask> can be
186 			// used to forcibly set a metamime attribute, even if it exists
187 
188 		void InstallDefaultTemplates();
189 		void InstallTemporaryBackgroundImages();
190 
191 		void InstallIndices();
192 		void InstallIndices(dev_t);
193 
194 		void CloseAllWindows();
195 		void CloseWindowAndChildren(const node_ref*);
196 		void CloseAllInWorkspace();
197 		void OpenInfoWindows(BMessage*);
198 		void MoveRefsToTrash(const BMessage*);
199 		void OpenContainerWindow(Model*, BMessage* refsList = NULL,
200 			OpenSelector openSelector = kOpen, uint32 openFlags = 0,
201 			bool checkAlreadyOpen = true,
202 			const BMessage* stateMessage = NULL);
203 			// pass either a Model or a list of entries to open
204 		void _OpenPreviouslyOpenedWindows(const char* pathFilter = NULL);
205 
206 		void SetDefaultPrinter(const BMessage*);
207 		void EditQueries(const BMessage*);
208 
209 		BInfoWindow* FindInfoWindow(const node_ref*) const;
210 
211 		BDeskWindow* GetDeskWindow() const;
212 
213 		status_t OpenRef(const entry_ref*, const node_ref* nodeToClose = NULL,
214 				const node_ref* nodeToSelect = NULL,
215 				OpenSelector selector = kOpen,
216 				const BMessage* messageToBundle = NULL);
217 
218 		MimeTypeList*			fMimeTypeList;
219 		WindowList				fWindowList;
220 		BClipboardRefsWatcher*	fClipboardRefsWatcher;
221 		BTrashWatcher*			fTrashWatcher;
222 		TaskLoop*				fTaskLoop;
223 		int32 					fNodeMonitorCount;
224 
225 		TrackerSettingsWindow*	fSettingsWindow;
226 
227 		typedef BApplication _inherited;
228 };
229 
230 
231 inline TaskLoop*
232 TTracker::MainTaskLoop() const
233 {
234 	return fTaskLoop;
235 }
236 
237 
238 inline BClipboardRefsWatcher*
239 TTracker::ClipboardRefsWatcher() const
240 {
241 	return fClipboardRefsWatcher;
242 }
243 
244 } // namespace BPrivate
245 
246 using namespace BPrivate;
247 
248 #endif	// _TRACKER_H
249