KiCad PCB EDA Suite
Loading...
Searching...
No Matches
unix/environment.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 Ian McInerney <Ian.S.McInerney at ieee.org>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <glib.h>
22#include <gio/gio.h>
24#include <wx/filename.h>
25#include <wx/uri.h>
26#include <wx/utils.h>
27#include <wx/sysopt.h>
28
29
31{
32 // Disable proxy menu in Unity window manager. Only usual menubar works with
33 // wxWidgets (at least <= 3.1). When the proxy menu menubar is enable, some
34 // important things for us do not work: menuitems UI events and shortcuts.
35 wxString wm;
36
37 if( wxGetEnv( wxT( "XDG_CURRENT_DESKTOP" ), &wm ) && wm.CmpNoCase( wxT( "Unity" ) ) == 0 )
38 wxSetEnv( wxT( "UBUNTU_MENUPROXY" ), wxT( "0" ) );
39
40 bool forceX11 = false;
41
42#if wxCHECK_VERSION( 3, 3, 2 )
43 #if wxHAS_EGL
44 // Prefer GLX backend on X11 and EGL backend on Wayland.
45 if( !wxGetEnv( wxT( "WAYLAND_DISPLAY" ), nullptr ) )
46 wxSystemOptions::SetOption( "opengl.egl", 0 );
47 #else
48 // Forces GLX on X11 and XWayland
49 forceX11 = true;
50 #endif
51#else
52 #if !wxUSE_GLCANVAS_EGL
53 // Forces GLX on X11 and XWayland
54 forceX11 = true;
55 #endif
56#endif
57
58 if( forceX11 )
59 wxSetEnv( wxT( "GDK_BACKEND" ), wxT( "x11" ) );
60
61 // Set GTK2-style input instead of xinput2. This disables touchscreen and smooth
62 // scrolling. It's needed to ensure that we are not getting multiple mouse scroll
63 // events.
64 wxSetEnv( wxT( "GDK_CORE_DEVICE_EVENTS" ), wxT( "1" ) );
65}
66
67
68bool KIPLATFORM::ENV::MoveToTrash( const wxString& aPath, wxString& aError )
69{
70 GError* err = nullptr;
71 GFile* file = g_file_new_for_path( aPath.fn_str() );
72
73 bool retVal = g_file_trash( file, nullptr, &err );
74
75 // Extract the error string if the operation failed
76 if( !retVal && err )
77 aError = err->message;
78
79 g_clear_error( &err );
80 g_object_unref( file );
81
82 return retVal;
83}
84
85
86bool KIPLATFORM::ENV::IsNetworkPath( const wxString& aPath )
87{
88 // placeholder, we "nerf" behavior if its a network path so return false by default
89 return false;
90}
91
92
94{
95 wxString docsPath = g_get_user_data_dir();
96
97 if( docsPath.IsEmpty() )
98 {
99 wxFileName fallback;
100
101 fallback.AssignDir( g_get_home_dir() );
102 fallback.AppendDir( wxT( ".local" ) );
103 fallback.AppendDir( wxT( "share" ) );
104 fallback.MakeAbsolute();
105
106 docsPath = fallback.GetFullPath();
107 }
108
109 return docsPath;
110}
111
112
114{
115 return g_get_user_config_dir();
116}
117
118
120{
121 return g_get_user_data_dir();
122}
123
124
126{
127 return g_get_user_data_dir();
128}
129
130
132{
133 return g_get_user_cache_dir();
134}
135
136
137bool KIPLATFORM::ENV::GetSystemProxyConfig( const wxString& aURL, PROXY_CONFIG& aCfg )
138{
139 bool success = false;
140
141 GProxyResolver* resolver = g_proxy_resolver_get_default();
142
143 if( !resolver )
144 return false;
145
146 GError* error = nullptr;
147 char** proxyList = g_proxy_resolver_lookup( resolver, aURL.utf8_str(), nullptr, &error );
148
149 if( error )
150 {
151 g_error_free( error );
152 return false;
153 }
154
155 if( !proxyList )
156 return false;
157
158 // GProxyResolver returns a NULL-terminated list of proxy URIs.
159 // We use the first non-direct proxy.
160 for( int i = 0; proxyList[i] != nullptr; i++ )
161 {
162 wxString proxyUriStr( proxyList[i], wxConvUTF8 );
163
164 // "direct://" means no proxy needed
165 if( proxyUriStr == wxT( "direct://" ) )
166 continue;
167
168 wxURI proxyUri( proxyUriStr );
169
170 // Clear any stale data from previous lookups
171 aCfg.host.clear();
172 aCfg.username.clear();
173 aCfg.password.clear();
174
175 // Build scheme://host:port string for curl.
176 // The scheme is required for non-HTTP proxies (socks5, https, etc.)
177 wxString scheme = proxyUri.GetScheme();
178
179 if( !scheme.IsEmpty() )
180 aCfg.host = scheme + wxT( "://" );
181
182 wxString server = proxyUri.GetServer();
183
184 // Bracket IPv6 addresses when port will be appended
185 bool isIPv6 = server.Contains( wxT( ":" ) );
186
187 if( isIPv6 && proxyUri.HasPort() )
188 aCfg.host += wxT( "[" ) + server + wxT( "]" );
189 else
190 aCfg.host += server;
191
192 if( proxyUri.HasPort() )
193 aCfg.host += wxT( ":" ) + proxyUri.GetPort();
194
195 // Extract credentials from userinfo (format: user[:password])
196 wxString userInfo = proxyUri.GetUserInfo();
197
198 if( !userInfo.IsEmpty() )
199 {
200 int colonPos = userInfo.Find( wxT( ":" ) );
201
202 if( colonPos != wxNOT_FOUND )
203 {
204 aCfg.username = userInfo.Left( colonPos );
205 aCfg.password = userInfo.Mid( colonPos + 1 );
206 }
207 else
208 {
209 aCfg.username = userInfo;
210 }
211 }
212
213 success = true;
214 break;
215 }
216
217 g_strfreev( proxyList );
218
219 return success;
220}
221
222
223bool KIPLATFORM::ENV::VerifyFileSignature( const wxString& aPath )
224{
225 return true;
226}
227
228
230{
231 return wxEmptyString;
232}
233
234
235void KIPLATFORM::ENV::SetAppDetailsForWindow( wxWindow* aWindow, const wxString& aRelaunchCommand,
236 const wxString& aRelaunchDisplayName )
237{
238}
239
240
242{
243 return wxEmptyString;
244}
245
246
247void KIPLATFORM::ENV::AddToRecentDocs( const wxString& aPath )
248{
249}
static FILENAME_RESOLVER * resolver
bool IsNetworkPath(const wxString &aPath)
Determines if a given path is a network shared file apth On Windows for example, any form of path is ...
void Init()
Perform environment initialization tasks.
wxString GetCommandLineStr()
bool GetSystemProxyConfig(const wxString &aURL, PROXY_CONFIG &aCfg)
Retrieves platform level proxying requirements to reach the given url.
wxString GetUserDataPath()
Retrieves the operating system specific path for a user's data store.
wxString GetDocumentsPath()
Retrieves the operating system specific path for a user's documents.
wxString GetAppUserModelId()
Retrieves the app user model id, a special string used for taskbar grouping on Windows 7 and later.
void SetAppDetailsForWindow(wxWindow *aWindow, const wxString &aRelaunchCommand, const wxString &aRelaunchDisplayName)
Sets the relaunch command for taskbar pins, this is intended for Windows.
void AddToRecentDocs(const wxString &aPath)
bool MoveToTrash(const wxString &aPath, wxString &aError)
Move the specified file/directory to the trash bin/recycle bin.
wxString GetUserLocalDataPath()
Retrieves the operating system specific path for a user's local data store.
wxString GetUserConfigPath()
Retrieves the operating system specific path for a user's configuration store.
wxString GetUserCachePath()
Retrieves the operating system specific path for user's application cache.
bool VerifyFileSignature(const wxString &aPath)
Validates the code signing signature of a given file This is most likely only ever going to be applic...