xref: /haiku/src/kits/tracker/Tracker.h (revision 5e96d7d537fbec23bad4ae9b4c8e7b02e769f0c6)
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 		class WatchingInterface;
168 
169 	private:
170 		// callbacks for ChildParentSoon calls
171 		bool CloseParentWaitingForChild(const entry_ref* child,
172 				const node_ref* parent);
173 		bool LaunchAndCloseParentIfOK(const entry_ref* launchThis,
174 				const node_ref* closeThis, const BMessage* messageToBundle);
175 		bool SelectChildInParent(const entry_ref* child,
176 				const node_ref* parent);
177 		void SelectPoseAtLocationInParent(node_ref parent, BPoint location);
178 		bool CloseParentWindowCommon(BContainerWindow*);
179 
180 		void InitMimeTypes();
181 		bool InstallMimeIfNeeded(const char* type, int32 bitsID,
182 				const char* shortDescription, const char* longDescription,
183 				const char* preferredAppSignature, uint32 forceMask = 0);
184 			// used by InitMimeTypes - checks if a metamime of a given <type>
185 			// is installed and if it has all the specified attributes;
186 			// if not, the whole mime type is installed and all attributes
187 			// are set; nulls can be passed for attributes that don't matter;
188 			// returns true if anything had to be changed <forceMask> can be
189 			// used to forcibly set a metamime attribute, even if it exists
190 
191 		void InstallDefaultTemplates();
192 		void InstallTemporaryBackgroundImages();
193 
194 		void InstallIndices();
195 		void InstallIndices(dev_t);
196 
197 		void CloseAllWindows();
198 		void CloseWindowAndChildren(const node_ref*);
199 		void CloseAllInWorkspace();
200 		void OpenInfoWindows(BMessage*);
201 		void MoveRefsToTrash(const BMessage*);
202 		void OpenContainerWindow(Model*, BMessage* refsList = NULL,
203 			OpenSelector openSelector = kOpen, uint32 openFlags = 0,
204 			bool checkAlreadyOpen = true,
205 			const BMessage* stateMessage = NULL);
206 			// pass either a Model or a list of entries to open
207 		void _OpenPreviouslyOpenedWindows(const char* pathFilter = NULL);
208 
209 		void SetDefaultPrinter(const BMessage*);
210 		void EditQueries(const BMessage*);
211 
212 		BInfoWindow* FindInfoWindow(const node_ref*) const;
213 
214 		BDeskWindow* GetDeskWindow() const;
215 
216 		status_t OpenRef(const entry_ref*, const node_ref* nodeToClose = NULL,
217 				const node_ref* nodeToSelect = NULL,
218 				OpenSelector selector = kOpen,
219 				const BMessage* messageToBundle = NULL);
220 
221 		MimeTypeList*			fMimeTypeList;
222 		WindowList				fWindowList;
223 		BClipboardRefsWatcher*	fClipboardRefsWatcher;
224 		BTrashWatcher*			fTrashWatcher;
225 		TaskLoop*				fTaskLoop;
226 		int32 					fNodeMonitorCount;
227 		WatchingInterface*		fWatchingInterface;
228 
229 		TrackerSettingsWindow*	fSettingsWindow;
230 
231 		typedef BApplication _inherited;
232 };
233 
234 
235 inline TaskLoop*
236 TTracker::MainTaskLoop() const
237 {
238 	return fTaskLoop;
239 }
240 
241 
242 inline BClipboardRefsWatcher*
243 TTracker::ClipboardRefsWatcher() const
244 {
245 	return fClipboardRefsWatcher;
246 }
247 
248 } // namespace BPrivate
249 
250 using namespace BPrivate;
251 
252 #endif	// _TRACKER_H
253