xref: /haiku/headers/private/shared/OpenWithTracker.h (revision 7914280cb827ba44ae4a51bc0a2e8659bc849faf)
1 /*
2  * Copyright 2009 Haiku Inc.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #ifndef _OPEN_WITH_TRACKER_H
6 #define _OPEN_WITH_TRACKER_H
7 
8 
9 #include <Entry.h>
10 #include <FindDirectory.h>
11 #include <Message.h>
12 #include <Messenger.h>
13 #include <Path.h>
14 
15 
16 status_t
17 OpenWithTracker(const entry_ref* ref)
18 {
19 	status_t status;
20 	BMessage message(B_REFS_RECEIVED);
21 	message.AddRef("refs", ref);
22 
23 	BMessenger tracker("application/x-vnd.Be-TRAK");
24 	status = tracker.SendMessage(&message);
25 	return status;
26 }
27 
28 
29 status_t
30 OpenWithTracker(const char* path)
31 {
32 	status_t status;
33 	entry_ref ref;
34 	status = get_ref_for_path(path, &ref);
35 	if (status != B_OK)
36 		return status;
37 
38 	return OpenWithTracker(&ref);
39 }
40 
41 
42 status_t
43 OpenWithTracker(directory_which which, const char* relativePath,
44 	bool createDirectory = false, BVolume* volume = NULL)
45 {
46 	status_t status;
47 	BPath path;
48 	find_directory(which, &path, createDirectory, volume);
49 	path.Append(relativePath);
50 
51 	entry_ref ref;
52 	BEntry entry(path.Path());
53 
54 	if (!entry.Exists())
55 		return B_NAME_NOT_FOUND;
56 
57 	status = entry.GetRef(&ref);
58 	if (status != B_OK)
59 		return status;
60 
61 	return OpenWithTracker(&ref);
62 }
63 
64 
65 #endif	// _OPEN_WITH_TRACKER_H
66 
67