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