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
16status_t
17OpenWithTracker(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
29status_t
30OpenWithTracker(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
42status_t
43OpenWithTracker(directory_which which, const char* relativePath = NULL,
44	bool createDirectory = false, BVolume* volume = NULL)
45{
46	status_t status;
47	BPath path;
48	find_directory(which, &path, createDirectory, volume);
49
50	if (relativePath)
51		path.Append(relativePath);
52
53	entry_ref ref;
54	BEntry entry(path.Path());
55
56	if (!entry.Exists())
57		return B_NAME_NOT_FOUND;
58
59	status = entry.GetRef(&ref);
60	if (status != B_OK)
61		return status;
62
63	return OpenWithTracker(&ref);
64}
65
66
67#endif	// _OPEN_WITH_TRACKER_H
68
69