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