xref: /haiku/src/kits/tracker/Tracker.h (revision fc7456e9b1ec38c941134ed6d01c438cf289381e)
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 
49 namespace BPrivate {
50 
51 class BClipboardRefsWatcher;
52 class BContainerWindow;
53 class BDeskWindow;
54 class BInfoWindow;
55 class BTrashWatcher;
56 class ExtraAttributeLazyInstaller;
57 class MimeTypeList;
58 class Model;
59 class BooleanValueSetting;
60 class ScalarValueSetting;
61 class HexScalarValueSetting;
62 class TaskLoop;
63 class TrackerSettingsWindow;
64 
65 
66 typedef LockingList<BWindow> WindowList;
67 	// this is because MW can't handle nested templates
68 
69 
70 const uint32 kNextSpecifier = 'snxt';
71 const uint32 kPreviousSpecifier = 'sprv';
72 const uint32 B_ENTRY_SPECIFIER = 'sref';
73 
74 
75 #define kPropertyEntry "Entry"
76 #define kPropertySelection "Selection"
77 
78 
79 class TTracker : public BApplication  {
80 public:
81 	TTracker();
82 	virtual ~TTracker();
83 
84 	// BApplication overrides
85 	virtual void Quit();
86 	virtual bool QuitRequested();
87 	virtual void ReadyToRun();
88 	virtual void MessageReceived(BMessage* message);
89 	virtual void Pulse();
90 	virtual void RefsReceived(BMessage* message);
91 	virtual void ArgvReceived(int32 argc, char** argv);
92 
93 	MimeTypeList* MimeTypes() const;
94 		// list of mime types that have a description and do not have
95 		// themselves as a preferred handler (case of applications)
96 
97 	bool TrashFull() const;
98 	bool IsTrashNode(const node_ref* node) const;
99 	bool InTrashNode(const entry_ref* ref) const;
100 
101 	void CloseParentWaitingForChildSoon(const entry_ref* child,
102 			const node_ref* parent);
103 		// closes parent, waits for child to open first
104 
105 	void SelectChildInParentSoon(const entry_ref* parent,
106 			const node_ref* child);
107 		// waits till child shows up in parent and selects it
108 
109 	void SelectPoseAtLocationSoon(node_ref parent, BPoint location);
110 		// Used to select next item when deleting in list view mode
111 
112 	enum OpenSelector {
113 		kOpen,
114 		kOpenWith,
115 		kRunOpenWithWindow
116 	};
117 
118 	bool EntryHasWindowOpen(const entry_ref*);
119 		// return true if there is an open window for an entry
120 
121 	status_t NeedMoreNodeMonitors();
122 		// call if ran out of node monitors to allocate more
123 		// return false if already using all we can get
124 	static status_t WatchNode(const node_ref*, uint32 flags,
125 				BMessenger target);
126 		// cover call for watch_node; if first watch_node fails,
127 		// tries bumping the node monitor limit and calls watch_node
128 		// again
129 
130 	TaskLoop* MainTaskLoop() const;
131 	BMessenger MountServer() const;
132 
133 	bool QueryActiveForDevice(dev_t);
134 	void CloseActiveQueryWindows(dev_t);
135 
136 	void SaveAllPoseLocations();
137 
138 	void CloseParent(node_ref closeThis);
139 
140 	void ShowSettingsWindow();
141 
142 	BContainerWindow* FindContainerWindow(const node_ref*,
143 		int32 number = 0) const;
144 	BContainerWindow* FindContainerWindow(const entry_ref*,
145 		int32 number = 0) const;
146 	BContainerWindow* FindParentContainerWindow(const entry_ref*) const;
147 		// right now works just on plain windows, not on query windows
148 
149 	BClipboardRefsWatcher* ClipboardRefsWatcher() const;
150 
151 protected:
152 	// scripting
153 	virtual BHandler* ResolveSpecifier(BMessage*, int32, BMessage*,
154 		int32, const char*);
155 	virtual status_t GetSupportedSuites(BMessage*);
156 
157 	bool HandleScriptingMessage(BMessage*);
158 
159 	bool ExecuteProperty(BMessage*, int32, const char*, BMessage*);
160 	bool CreateProperty(BMessage*, BMessage*, int32, const char*,
161 			BMessage*);
162 	bool DeleteProperty(BMessage*, int32,
163 			const char*, BMessage*);
164 	bool CountProperty(BMessage*, int32, const char*, BMessage*);
165 	bool GetProperty(BMessage*, int32, const char*, BMessage*);
166 	bool SetProperty(BMessage*, BMessage*, int32, const char*, BMessage*);
167 
168 private:
169 	class WatchingInterface;
170 
171 private:
172 	// callbacks for ChildParentSoon calls
173 	bool CloseParentWaitingForChild(const entry_ref* child,
174 			const node_ref* parent);
175 	bool LaunchAndCloseParentIfOK(const entry_ref* launchThis,
176 			const node_ref* closeThis, const BMessage* messageToBundle);
177 	bool SelectChildInParent(const entry_ref* parent,
178 			const node_ref* child);
179 	void SelectPoseAtLocationInParent(node_ref parent, BPoint location);
180 	bool CloseParentWindowCommon(BContainerWindow*);
181 
182 	void InitMimeTypes();
183 	bool InstallMimeIfNeeded(const char* type, int32 bitsID,
184 			const char* shortDescription, const char* longDescription,
185 			const char* preferredAppSignature, uint32 forceMask = 0);
186 		// used by InitMimeTypes - checks if a metamime of a given <type>
187 		// is installed and if it has all the specified attributes;
188 		// if not, the whole mime type is installed and all attributes
189 		// are set; nulls can be passed for attributes that don't matter;
190 		// returns true if anything had to be changed <forceMask> can be
191 		// used to forcibly set a metamime attribute, even if it exists
192 
193 	void InstallDefaultTemplates();
194 	void InstallTemporaryBackgroundImages();
195 
196 	void InstallIndices();
197 	void InstallIndices(dev_t);
198 
199 	void CloseAllWindows();
200 	void CloseWindowAndChildren(const node_ref*);
201 	void CloseAllInWorkspace();
202 	void OpenInfoWindows(BMessage*);
203 	void MoveRefsToTrash(const BMessage*);
204 	void SelectRefs(const BMessage*);
205 	void OpenContainerWindow(Model*, BMessage* refsList = NULL,
206 		OpenSelector openSelector = kOpen, uint32 openFlags = 0,
207 		bool checkAlreadyOpen = true,
208 		const BMessage* stateMessage = NULL);
209 		// pass either a Model or a list of entries to open
210 	void _OpenPreviouslyOpenedWindows(const char* pathFilter = NULL);
211 
212 	void SetDefaultPrinter(const BMessage*);
213 	void EditQueries(const BMessage*);
214 
215 	BInfoWindow* FindInfoWindow(const node_ref*) const;
216 
217 	BDeskWindow* GetDeskWindow() const;
218 
219 	status_t OpenRef(const entry_ref*, const node_ref* nodeToClose = NULL,
220 			const node_ref* nodeToSelect = NULL,
221 			OpenSelector selector = kOpen,
222 			const BMessage* messageToBundle = NULL);
223 
224 	MimeTypeList*			fMimeTypeList;
225 	WindowList				fWindowList;
226 	BClipboardRefsWatcher*	fClipboardRefsWatcher;
227 	BTrashWatcher*			fTrashWatcher;
228 	TaskLoop*				fTaskLoop;
229 	int32 					fNodeMonitorCount;
230 	WatchingInterface*		fWatchingInterface;
231 
232 	TrackerSettingsWindow*	fSettingsWindow;
233 
234 	typedef BApplication _inherited;
235 };
236 
237 
238 inline TaskLoop*
239 TTracker::MainTaskLoop() const
240 {
241 	return fTaskLoop;
242 }
243 
244 
245 inline BClipboardRefsWatcher*
246 TTracker::ClipboardRefsWatcher() const
247 {
248 	return fClipboardRefsWatcher;
249 }
250 
251 } // namespace BPrivate
252 
253 using namespace BPrivate;
254 
255 
256 #endif	// _TRACKER_H
257