KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_git_credentials.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 The KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
23#include <git/kigit_failure.h>
24#include <kiplatform/ui.h>
25
26#include <wx/dcclient.h>
27
28DIALOG_GIT_CREDENTIALS::DIALOG_GIT_CREDENTIALS( wxWindow* aParent, const wxString& aUrl, const wxString& aExplanation,
29 KIGIT_COMMON::GIT_CONN_TYPE aConnType, const wxString& aDefaultUsername,
30 const wxString& aDefaultSSHKey ) :
32 m_connType( aConnType )
33{
34 OptOut( this );
35
36 if( aUrl.IsEmpty() )
37 {
38 m_promptLabel->SetLabelText( _( "Authentication is required to access the remote repository." ) );
39 }
40 else
41 {
42 // Long remote paths would otherwise widen the dialog past the screen
43 wxClientDC dc( m_promptLabel );
44 dc.SetFont( m_promptLabel->GetFont() );
45 const wxString safeUrl = KIGIT::StripEmbeddedUserinfo( aUrl );
46 wxString url = wxControl::Ellipsize( safeUrl, dc, wxELLIPSIZE_MIDDLE, FromDIP( 400 ), wxELLIPSIZE_FLAGS_NONE );
47
48 m_promptLabel->SetLabelText( wxString::Format( _( "Authentication is required to access %s." ), url ) );
49 m_promptLabel->Wrap( FromDIP( 500 ) );
50 m_promptLabel->SetToolTip( safeUrl );
51 }
52
53 if( !aExplanation.IsEmpty() )
54 {
56
57 m_explanationLabel->SetLabelText( aExplanation );
58 m_explanationLabel->SetForegroundColour( theme.removed.ToColour() );
59 m_explanationLabel->Wrap( FromDIP( 500 ) );
60 m_explanationLabel->Show();
61 }
62
65
66 m_userCtrl->SetValue( m_urlUsername.IsEmpty() ? aDefaultUsername : m_urlUsername );
67
68 if( !aDefaultSSHKey.IsEmpty() )
69 m_keyPicker->SetFileName( wxFileName( aDefaultSSHKey ) );
70
71 // Keyed on the address, not the session, so a type chosen here earlier cannot lock the choice
74
77
79
81
83
84 Layout();
85 GetSizer()->Fit( this );
86 Centre();
87}
88
89
90void DIALOG_GIT_CREDENTIALS::OnConnTypeChanged( wxCommandEvent& aEvent )
91{
92 if( m_authChoice->GetSelection() == 1 )
94 else
96
98 aEvent.Skip();
99}
100
101
103{
105
106 m_keyLabel->Enable( ssh );
107 m_keyPicker->Enable( ssh );
108
109 // The server refuses any user other than the one the SSH address names
110 m_userCtrl->Enable( !ssh || m_urlUsername.IsEmpty() );
111
112 if( ssh )
113 {
114 m_passLabel->SetLabel( _( "Key passphrase:" ) );
115 m_passCtrl->SetHint( _( "Leave empty if the key has no passphrase." ) );
116 }
117 else
118 {
119 m_passLabel->SetLabel( _( "Password / token:" ) );
120 m_passCtrl->SetHint( wxEmptyString );
121 }
122}
123
124
126{
127 return m_userCtrl->GetValue();
128}
129
130
132{
133 return m_passCtrl->GetValue();
134}
135
136
138{
139 return m_keyPicker->GetFileName().GetFullPath();
140}
141
142
147
148
150{
151 return m_saveCheck->IsChecked();
152}
DIALOG_GIT_CREDENTIALS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Git Authentication Required"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE)
KIGIT_COMMON::GIT_CONN_TYPE GetConnType() const
KIGIT_COMMON::GIT_CONN_TYPE m_connType
On macOS a disabled wxRadioBox reports its first entry, so the type is kept here.
DIALOG_GIT_CREDENTIALS(wxWindow *aParent, const wxString &aUrl, const wxString &aExplanation, KIGIT_COMMON::GIT_CONN_TYPE aConnType, const wxString &aDefaultUsername, const wxString &aDefaultSSHKey)
wxString m_urlUsername
The user an SSH address names, which the server requires.
void OnConnTypeChanged(wxCommandEvent &aEvent) override
void OptOut(wxWindow *aWindow)
Opt out of control state saving.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
wxColour ToColour() const
Definition color4d.cpp:221
static REMOTE_URL ParseRemoteURL(const wxString &aURL)
#define _(s)
APIEXPORT wxString StripEmbeddedUserinfo(const wxString &aText)
Remove the user and password from every URL quoted in a message, since the remote's can carry a passw...
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition wxgtk/ui.cpp:54
Diff colors with defaults for light backgrounds.
Definition diff_scene.h:278
static DIFF_COLOR_THEME ForText(bool aDarkTheme)
Resolve change colors for UI text. Pass the desktop theme captured on the UI thread.