Assorted whitespace cleanup and typo fixes.
[haiku.git] / src / kits / tracker / FSUtils.h
blob23c91e6537f1cb2ae852ae920badc36e79a97493
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
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:
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.
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.
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.
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.
34 #ifndef FS_UTILS_H
35 #define FS_UTILS_H
38 #include <FindDirectory.h>
39 #include <List.h>
40 #include <ObjectList.h>
41 #include <Point.h>
42 #include <StorageDefs.h>
44 #include <vector>
46 #include "Model.h"
49 // APIs/code in FSUtils.h and FSUtils.cpp is slated for a major cleanup
50 // -- in other words, you will find a lot of ugly cruft in here
52 class BDirectory;
53 class BEntry;
54 class BList;
55 class BFile;
57 namespace BPrivate {
59 class BInfoWindow;
61 //! Controls the copy engine; may be overriden to specify how conflicts are
62 // handled, etc.
63 class CopyLoopControl {
64 public:
65 virtual ~CopyLoopControl();
67 virtual void Init(uint32 jobKind);
68 virtual void Init(int32 totalItems, off_t totalSize,
69 const entry_ref* destDir = NULL,
70 bool showCount = true);
72 //! Inform that a file error occurred while copying <name>.
73 // \return \c True if user decided to continue
74 virtual bool FileError(const char* message,
75 const char* name, status_t error,
76 bool allowContinue);
78 virtual void UpdateStatus(const char* name,
79 const entry_ref& ref, int32 count,
80 bool optional = false);
82 //! \return \c true if canceled
83 virtual bool CheckUserCanceled();
85 enum OverwriteMode {
86 kSkip, // do not replace, go to next entry
87 kReplace, // remove entry before copying new one
88 kMerge // for folders: leave existing folder, update
89 // contents leaving nonconflicting items
90 // for files: save original attributes on file
93 //! Override to always overwrite, never overwrite, let user decide,
94 // compare dates, etc.
95 virtual OverwriteMode OverwriteOnConflict(const BEntry* srcEntry,
96 const char* destName,
97 const BDirectory* destDir,
98 bool srcIsDir, bool dstIsDir);
100 //! Override to prevent copying of a given file or directory
101 virtual bool SkipEntry(const BEntry*, bool file);
103 //! During a file copy, this is called every time a chunk of data
104 // is copied. Users may override to keep a running checksum.
105 virtual void ChecksumChunk(const char* block, size_t size);
107 //! This is called when a file is finished copying. Users of this
108 // class may override to verify that the checksum they've been
109 // computing in ChecksumChunk matches. If this returns true,
110 // the copy will continue. If false, if will abort.
111 virtual bool ChecksumFile(const entry_ref*);
113 virtual bool SkipAttribute(const char* attributeName);
114 virtual bool PreserveAttribute(const char* attributeName);
118 //! This is the Tracker copy-specific version of CopyLoopControl.
119 class TrackerCopyLoopControl : public CopyLoopControl {
120 public:
121 TrackerCopyLoopControl();
122 TrackerCopyLoopControl(uint32 jobKind);
123 TrackerCopyLoopControl(int32 totalItems,
124 off_t totalSize);
125 virtual ~TrackerCopyLoopControl();
127 virtual void Init(uint32 state);
128 virtual void Init(int32 totalItems, off_t totalSize,
129 const entry_ref* destDir = NULL,
130 bool showCount = true);
132 virtual bool FileError(const char* message,
133 const char* name, status_t error,
134 bool allowContinue);
136 virtual void UpdateStatus(const char* name,
137 const entry_ref& ref, int32 count,
138 bool optional = false);
140 virtual bool CheckUserCanceled();
142 virtual bool SkipAttribute(const char* attributeName);
145 // One can specify an entry_ref list with the source entries. This will
146 // then trigger the feature to pull additional source entries from the
147 // status window, such that the user can drop additional items onto the
148 // progress display of the ongoing copy process to copy these items to
149 // the same target directory.
150 typedef BObjectList<entry_ref> EntryList;
152 void SetSourceList(EntryList* list);
154 private:
155 thread_id fThread;
157 EntryList* fSourceList;
161 #define B_DESKTOP_DIR_NAME "Desktop"
162 #define B_DISKS_DIR_NAME "Disks"
163 #define B_TRASH_DIR_NAME "Trash"
165 #ifndef _IMPEXP_TRACKER
166 #define _IMPEXP_TRACKER
167 #endif
168 _IMPEXP_TRACKER status_t FSCopyAttributesAndStats(BNode*, BNode*);
170 _IMPEXP_TRACKER void FSDuplicate(BObjectList<entry_ref>* srcList,
171 BList* pointList);
172 _IMPEXP_TRACKER void FSMoveToFolder(BObjectList<entry_ref>* srcList, BEntry*,
173 uint32 moveMode, BList* pointList = NULL);
174 _IMPEXP_TRACKER void FSMakeOriginalName(char* name, BDirectory* destDir,
175 const char* suffix);
176 _IMPEXP_TRACKER bool FSIsTrashDir(const BEntry*);
177 _IMPEXP_TRACKER bool FSIsPrintersDir(const BEntry*);
178 _IMPEXP_TRACKER bool FSIsDeskDir(const BEntry*);
179 _IMPEXP_TRACKER bool FSIsHomeDir(const BEntry*);
180 _IMPEXP_TRACKER bool FSIsRootDir(const BEntry*);
181 _IMPEXP_TRACKER void FSMoveToTrash(BObjectList<entry_ref>* srcList,
182 BList* pointList = NULL, bool async = true);
183 // Deprecated
185 void FSDeleteRefList(BObjectList<entry_ref>*, bool, bool confirm = true);
186 void FSDelete(entry_ref*, bool, bool confirm = true);
187 void FSRestoreRefList(BObjectList<entry_ref>* list, bool async);
189 _IMPEXP_TRACKER status_t FSLaunchItem(const entry_ref* application,
190 const BMessage* refsReceived, bool async, bool openWithOK);
191 // Preferred way of launching; only pass an actual application in
192 // <application>, not a document; to open documents with the preferred
193 // app, pase 0 in <application> and stuff all the document refs into
194 // <refsReceived> Consider having silent mode that does not show alerts,
195 // just returns error code
197 _IMPEXP_TRACKER status_t FSOpenWith(BMessage* listOfRefs);
198 // runs the Open With window; pas a list of refs
200 _IMPEXP_TRACKER void FSEmptyTrash();
201 _IMPEXP_TRACKER status_t FSCreateNewFolderIn(const node_ref* destDir,
202 entry_ref* newRef, node_ref* new_node);
203 _IMPEXP_TRACKER void FSCreateTrashDirs();
204 _IMPEXP_TRACKER status_t FSGetTrashDir(BDirectory* trashDir, dev_t volume);
205 _IMPEXP_TRACKER status_t FSGetDeskDir(BDirectory* deskDir);
206 _IMPEXP_TRACKER status_t FSRecursiveCalcSize(BInfoWindow*,
207 CopyLoopControl* loopControl, BDirectory*, off_t* runningSize,
208 int32* fileCount, int32* dirCount);
210 bool FSInTrashDir(const entry_ref*);
212 // doesn't need to be exported
213 bool FSGetPoseLocation(const BNode* node, BPoint* point);
214 status_t FSSetPoseLocation(BEntry* entry, BPoint point);
215 status_t FSSetPoseLocation(ino_t destDirInode, BNode* destNode, BPoint point);
216 status_t FSGetBootDeskDir(BDirectory* deskDir);
218 status_t FSGetOriginalPath(BEntry* entry, BPath* path);
220 enum ReadAttrResult {
221 kReadAttrFailed,
222 kReadAttrNativeOK,
223 kReadAttrForeignOK
226 ReadAttrResult ReadAttr(const BNode*, const char* hostAttrName,
227 const char* foreignAttrName, type_code, off_t, void*, size_t,
228 void (*swapFunc)(void*) = 0, bool isForeign = false);
229 // Endian swapping ReadAttr call; endianness is determined by trying
230 // first the native attribute name, then the foreign one; an endian
231 // swapping function can be passed, if null data won't be swapped;
232 // if <isForeign> set the foreign endianness will be read directly
233 // without first trying the native one
235 ReadAttrResult GetAttrInfo(const BNode*, const char* hostAttrName,
236 const char* foreignAttrName, type_code* = NULL, size_t* = NULL);
238 status_t FSCreateNewFolder(const entry_ref*);
239 status_t FSRecursiveCreateFolder(const char* path);
240 void FSMakeOriginalName(BString &name, const BDirectory* destDir,
241 const char* suffix = 0);
243 status_t FSGetParentVirtualDirectoryAware(const BEntry& entry, entry_ref& _ref);
244 status_t FSGetParentVirtualDirectoryAware(const BEntry& entry, BEntry& _entry);
245 status_t FSGetParentVirtualDirectoryAware(const BEntry& entry, BNode& _node);
247 status_t TrackerLaunch(const entry_ref* appRef, bool async);
248 status_t TrackerLaunch(const BMessage* refs, bool async,
249 bool okToRunOpenWith = true);
250 status_t TrackerLaunch(const entry_ref* appRef, const BMessage* refs,
251 bool async, bool okToRunOpenWith = true);
252 status_t LaunchBrokenLink(const char*, const BMessage*);
254 status_t FSFindTrackerSettingsDir(BPath*, bool autoCreate = true);
256 bool FSIsDeskDir(const BEntry*);
258 // two separate ifYouDoAction and toDoAction versions are needed for
259 // localization purposes. The first one is used in "If you do action..."
260 // sentence, the second one in the "To do action" sentence.
261 bool ConfirmChangeIfWellKnownDirectory(const BEntry* entry,
262 const char* ifYouDoAction, const char* toDoAction,
263 const char* toConfirmAction, bool dontAsk = false,
264 int32* confirmedAlready = NULL);
266 bool CheckDevicesEqual(const entry_ref* entry, const Model* targetModel);
268 // Deprecated calls use newer calls above instead
269 _IMPEXP_TRACKER void FSLaunchItem(const entry_ref* appRef,
270 BMessage* refs = NULL, int32 workspace = -1);
271 _IMPEXP_TRACKER status_t FSLaunchItem(const entry_ref* appRef,
272 BMessage* refs, int32 workspace, bool asynch);
273 _IMPEXP_TRACKER void FSOpenWithDocuments(const entry_ref* executableToLaunch,
274 BMessage* documentEntryRefs);
275 _IMPEXP_TRACKER status_t FSLaunchUsing(const entry_ref* ref,
276 BMessage* listOfRefs);
279 // some extra directory_which values
280 // move these to FindDirectory.h
281 const uint32 B_USER_MAIL_DIRECTORY = 3500;
282 const uint32 B_USER_QUERIES_DIRECTORY = 3501;
283 const uint32 B_USER_PEOPLE_DIRECTORY = 3502;
284 const uint32 B_USER_DOWNLOADS_DIRECTORY = 3503;
285 const uint32 B_USER_DESKBAR_APPS_DIRECTORY = 3504;
286 const uint32 B_USER_DESKBAR_PREFERENCES_DIRECTORY = 3505;
287 const uint32 B_USER_DESKBAR_DEVELOP_DIRECTORY = 3506;
288 const uint32 B_BOOT_DISK = 3507;
289 // map /boot into the directory_which enum for convenience
291 class WellKnowEntryList {
292 // matches up names, id's and node_refs of well known entries in the
293 // system hierarchy
294 public:
295 struct WellKnownEntry {
296 WellKnownEntry(const node_ref* node, directory_which which,
297 const char* name)
299 node(*node),
300 which(which),
301 name(name)
305 // mwcc needs these explicitly to use vector
306 WellKnownEntry(const WellKnownEntry &clone)
308 node(clone.node),
309 which(clone.which),
310 name(clone.name)
314 WellKnownEntry()
318 node_ref node;
319 directory_which which;
320 BString name;
323 static directory_which Match(const node_ref*);
324 static const WellKnownEntry* MatchEntry(const node_ref*);
325 static void Quit();
327 private:
328 const WellKnownEntry* MatchEntryCommon(const node_ref*);
329 WellKnowEntryList();
330 void AddOne(directory_which, const char* name);
331 void AddOne(directory_which, const char* path, const char* name);
332 void AddOne(directory_which, directory_which base,
333 const char* extension, const char* name);
335 std::vector<WellKnownEntry> entries;
336 static WellKnowEntryList* self;
339 #if B_BEOS_VERSION_DANO
340 #undef _IMPEXP_TRACKER
341 #endif
343 } // namespace BPrivate
345 using namespace BPrivate;
347 #endif // FS_UTILS_H