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
28
30{
31 // Disable proxy menu in Unity window manager. Only usual menubar works with
32 // wxWidgets (at least <= 3.1). When the proxy menu menubar is enable, some
33 // important things for us do not work: menuitems UI events and shortcuts.
34 wxString wm;
35
36 if( wxGetEnv( wxT( "XDG_CURRENT_DESKTOP" ), &wm ) && wm.CmpNoCase( wxT( "Unity" ) ) == 0 )
37 wxSetEnv( wxT( "UBUNTU_MENUPROXY" ), wxT( "0" ) );
38
39#if !KICAD_USE_EGL \
40 || ( wxCHECK_VERSION( 3, 3, 2 ) && !wxHAS_EGL ) \
41 || ( !wxCHECK_VERSION( 3, 3, 2 ) && !wxUSE_GLCANVAS_EGL )
42 // Force the use of X11 backend (or wayland-x11 compatibility layer). This is
43 // required until wxWidgets supports the Wayland compositors
44 wxSetEnv( wxT( "GDK_BACKEND" ), wxT( "x11" ) );
45#endif
46
47 // Set GTK2-style input instead of xinput2. This disables touchscreen and smooth
48 // scrolling. It's needed to ensure that we are not getting multiple mouse scroll
49 // events.
50 wxSetEnv( wxT( "GDK_CORE_DEVICE_EVENTS" ), wxT( "1" ) );
51}
52
53
54bool KIPLATFORM::ENV::MoveToTrash( const wxString& aPath, wxString& aError )
55{
56 GError* err = nullptr;
57 GFile* file = g_file_new_for_path( aPath.fn_str() );
58
59 bool retVal = g_file_trash( file, nullptr, &err );
60
61 // Extract the error string if the operation failed
62 if( !retVal && err )
63 aError = err->message;
64
65 g_clear_error( &err );
66 g_object_unref( file );
67
68 return retVal;
69}
70
71
72bool KIPLATFORM::ENV::IsNetworkPath( const wxString& aPath )
73{
74 // placeholder, we "nerf" behavior if its a network path so return false by default
75 return false;
76}
77
78
80{
81 wxString docsPath = g_get_user_data_dir();
82
83 if( docsPath.IsEmpty() )
84 {
85 wxFileName fallback;
86
87 fallback.AssignDir( g_get_home_dir() );
88 fallback.AppendDir( wxT( ".local" ) );
89 fallback.AppendDir( wxT( "share" ) );
90 fallback.MakeAbsolute();
91
92 docsPath = fallback.GetFullPath();
93 }
94
95 return docsPath;
96}
97
98
100{
101 return g_get_user_config_dir();
102}
103
104
106{
107 return g_get_user_data_dir();
108}
109
110
112{
113 return g_get_user_data_dir();
114}
115
116
118{
119 return g_get_user_cache_dir();
120}
121
122
123bool KIPLATFORM::ENV::GetSystemProxyConfig( const wxString& aURL, PROXY_CONFIG& aCfg )
124{
125 bool success = false;
126
127 GProxyResolver* resolver = g_proxy_resolver_get_default();
128
129 if( !resolver )
130 return false;
131
132 GError* error = nullptr;
133 char** proxyList = g_proxy_resolver_lookup( resolver, aURL.utf8_str(), nullptr, &error );
134
135 if( error )
136 {
137 g_error_free( error );
138 return false;
139 }
140
141 if( !proxyList )
142 return false;
143
144 // GProxyResolver returns a NULL-terminated list of proxy URIs.
145 // We use the first non-direct proxy.
146 for( int i = 0; proxyList[i] != nullptr; i++ )
147 {
148 wxString proxyUriStr( proxyList[i], wxConvUTF8 );
149
150 // "direct://" means no proxy needed
151 if( proxyUriStr == wxT( "direct://" ) )
152 continue;
153
154 wxURI proxyUri( proxyUriStr );
155
156 // Clear any stale data from previous lookups
157 aCfg.host.clear();
158 aCfg.username.clear();
159 aCfg.password.clear();
160
161 // Build scheme://host:port string for curl.
162 // The scheme is required for non-HTTP proxies (socks5, https, etc.)
163 wxString scheme = proxyUri.GetScheme();
164
165 if( !scheme.IsEmpty() )
166 aCfg.host = scheme + wxT( "://" );
167
168 wxString server = proxyUri.GetServer();
169
170 // Bracket IPv6 addresses when port will be appended
171 bool isIPv6 = server.Contains( wxT( ":" ) );
172
173 if( isIPv6 && proxyUri.HasPort() )
174 aCfg.host += wxT( "[" ) + server + wxT( "]" );
175 else
176 aCfg.host += server;
177
178 if( proxyUri.HasPort() )
179 aCfg.host += wxT( ":" ) + proxyUri.GetPort();
180
181 // Extract credentials from userinfo (format: user[:password])
182 wxString userInfo = proxyUri.GetUserInfo();
183
184 if( !userInfo.IsEmpty() )
185 {
186 int colonPos = userInfo.Find( wxT( ":" ) );
187
188 if( colonPos != wxNOT_FOUND )
189 {
190 aCfg.username = userInfo.Left( colonPos );
191 aCfg.password = userInfo.Mid( colonPos + 1 );
192 }
193 else
194 {
195 aCfg.username = userInfo;
196 }
197 }
198
199 success = true;
200 break;
201 }
202
203 g_strfreev( proxyList );
204
205 return success;
206}
207
208
209bool KIPLATFORM::ENV::VerifyFileSignature( const wxString& aPath )
210{
211 return true;
212}
213
214
216{
217 return wxEmptyString;
218}
219
220
221void KIPLATFORM::ENV::SetAppDetailsForWindow( wxWindow* aWindow, const wxString& aRelaunchCommand,
222 const wxString& aRelaunchDisplayName )
223{
224}
225
226
228{
229 return wxEmptyString;
230}
231
232
233void KIPLATFORM::ENV::AddToRecentDocs( const wxString& aPath )
234{
235}
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...