2 * Copyright (C) 2010-2015 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2012 Todd Naugle <toddn@harrisonconsoles.com>
4 * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "libpbd-config.h"
25 #include <boost/scoped_ptr.hpp>
27 #include <glibmm/spawn.h>
30 #include "pbd/openuri.h"
33 #include <curl/curl.h>
34 extern bool cocoa_open_url (const char*);
37 #ifdef PLATFORM_WINDOWS
39 # include <shellapi.h>
41 # include <sys/types.h>
46 PBD::open_uri (const char* uri)
48 #ifdef PLATFORM_WINDOWS
49 gunichar2* wuri = g_utf8_to_utf16 (uri, -1, NULL, NULL, NULL);
50 ShellExecuteW(NULL, L"open", (LPCWSTR)wuri, NULL, NULL, SW_SHOWNORMAL);
54 return cocoa_open_url (uri);
56 EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa ();
57 boost::scoped_ptr<EnvironmentalProtectionAgency> current_epa;
59 /* revert all environment settings back to whatever they were when ardour started
63 current_epa.reset (new EnvironmentalProtectionAgency(true)); /* will restore settings when we leave scope */
64 global_epa->restore ();
68 while (s.find("\\") != std::string::npos)
69 s.replace(s.find("\\"), 1, "\\\\");
70 while (s.find("\"") != std::string::npos)
71 s.replace(s.find("\\"), 1, "\\\"");
74 std::string command = "xdg-open ";
75 command += '"' + s + '"';
77 (void) system (command.c_str());
79 if (::vfork () == 0) {
80 ::execlp ("xdg-open", "xdg-open", s.c_str(), (char*)NULL);
85 #endif /* not PLATFORM_WINDOWS and not __APPLE__ */
90 PBD::open_uri (const std::string& uri)
92 return open_uri (uri.c_str());
96 PBD::open_folder (const std::string& d)
99 CURL *curl = curl_easy_init ();
102 char * e = curl_easy_escape (curl, d.c_str(), d.size());
103 std::string url = "file:///" + std::string(e);
104 rv = PBD::open_uri (url);
109 return PBD::open_uri (d);