xref: /haiku/src/apps/aboutsystem/HyperTextActions.cpp (revision 830f67ef991407f287dbc1238aa5f5906d90c991)
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 
16 URLAction::URLAction(const BString& url)
17 	:
18 	fURL(url)
19 {
20 }
21 
22 
23 URLAction::~URLAction()
24 {
25 }
26 
27 
28 void
29 URLAction::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[] = { fURL.String(), NULL };
37 	be_roster->Launch(&ref, 1, args);
38 }
39 
40 
41 // #pragma mark - OpenFileAction
42 
43 
44 OpenFileAction::OpenFileAction(const BString& file)
45 	:
46 	fFile(file)
47 {
48 }
49 
50 
51 OpenFileAction::~OpenFileAction()
52 {
53 }
54 
55 
56 void
57 OpenFileAction::Clicked(HyperTextView* view, BPoint where, BMessage* message)
58 {
59 	// get the entry ref and let Tracker open the file
60 	entry_ref ref;
61 	if (get_ref_for_path(fFile.String(), &ref) != B_OK
62 		|| !BEntry(&ref).Exists()) {
63 		return;
64 	}
65 
66 	BMessenger tracker("application/x-vnd.Be-TRAK");
67 	if (tracker.IsValid()) {
68 		BMessage message(B_REFS_RECEIVED);
69 		message.AddRef("refs", &ref);
70 		tracker.SendMessage(&message);
71 	} else
72 		be_roster->Launch(&ref);
73 }
74