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
HyperLink()15 HyperLink::HyperLink()
16 :
17 fAddress(),
18 fType(TYPE_URL)
19 {
20 }
21
22
HyperLink(const BString & address,Type type)23 HyperLink::HyperLink(const BString& address, Type type)
24 :
25 fText(address),
26 fAddress(address),
27 fType(type)
28 {
29 }
30
31
HyperLink(const BString & text,const BString & address,Type type)32 HyperLink::HyperLink(const BString& text, const BString& address, Type type)
33 :
34 fText(text),
35 fAddress(address),
36 fType(type)
37 {
38 }
39
40
41 status_t
Open()42 HyperLink::Open()
43 {
44 if (!IsValid())
45 return B_BAD_VALUE;
46
47 // open with the "open" program
48 BString address(fAddress);
49 address.CharacterEscape(kShellEscapeCharacters, '\\');
50 BString commandLine;
51 commandLine.SetToFormat("/bin/open %s", address.String());
52 return system(commandLine) == 0 ? B_OK : errno;
53 }
54