1/*
2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT license.
4 */
5
6#include "HyperTextActions.h"
7
8#include <Entry.h>
9#include <Message.h>
10#include <Roster.h>
11
12
13// #pragma mark - URLAction
14
15
16URLAction::URLAction(const BString& url)
17	:
18	fURL(url)
19{
20}
21
22
23URLAction::~URLAction()
24{
25}
26
27
28void
29URLAction::Clicked(HyperTextView* view, BPoint where, BMessage* message)
30{
31	// be lazy and let /bin/open open the URL
32	entry_ref ref;
33	if (get_ref_for_path("/bin/open", &ref))
34		return;
35
36	const char* args[] = { "/bin/open", fURL.String(), NULL };
37	be_roster->Launch(&ref, 2, args);
38
39}
40
41
42// #pragma mark - OpenFileAction
43
44
45OpenFileAction::OpenFileAction(const BString& file)
46	:
47	fFile(file)
48{
49}
50
51
52OpenFileAction::~OpenFileAction()
53{
54}
55
56
57void
58OpenFileAction::Clicked(HyperTextView* view, BPoint where, BMessage* message)
59{
60	// get the entry ref and let Tracker open the file
61	entry_ref ref;
62	if (get_ref_for_path(fFile.String(), &ref) != B_OK
63		|| !BEntry(&ref).Exists()) {
64		return;
65	}
66
67    BMessenger tracker("application/x-vnd.Be-TRAK");
68    if (tracker.IsValid()) {
69		BMessage message(B_REFS_RECEIVED);
70		message.AddRef("refs", &ref);
71		tracker.SendMessage(&message);
72	} else
73        be_roster->Launch(&ref);
74}
75