xref: /haiku/src/apps/terminal/HyperLink.cpp (revision c663ca2171fe8fee125a8d1fd64500b0deb5e814)
1 /*
2  * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "HyperLink.h"
8 
9 #include <errno.h>
10 #include <stdlib.h>
11 
12 #include "TermConst.h"
13 
14 
15 HyperLink::HyperLink()
16 	:
17 	fAddress(),
18 	fType(TYPE_URL)
19 {
20 }
21 
22 
23 HyperLink::HyperLink(const BString& address, Type type,
24 	const BString& baseAddress)
25 	:
26 	fAddress(address),
27 	fBaseAddress(baseAddress.IsEmpty() ? address : baseAddress),
28 	fType(type)
29 {
30 }
31 
32 
33 status_t
34 HyperLink::Open()
35 {
36 	if (!IsValid())
37 		return B_BAD_VALUE;
38 
39 	// open with the "open" program
40 	BString address(fAddress);
41 	address.CharacterEscape(kShellEscapeCharacters, '\\');
42 	BString commandLine;
43 	commandLine.SetToFormat("/bin/open %s", address.String());
44 	return system(commandLine) == 0 ? B_OK : errno;
45 }
46