KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_database_lib_settings.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) 2023 Jon Evans <[email protected]>
5 * Copyright (C) 2023 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
24
25
27 SCH_IO_DATABASE* aPlugin ) :
29 m_plugin( aPlugin )
30{
31 Layout();
34}
35
36
38{
39 wxCommandEvent dummy;
41
43
44 if( !settings->m_Source.connection_string.empty() )
45 {
46 m_rbConnectionString->SetValue( true );
48 }
49 else
50 {
51 m_rbDSN->SetValue( true );
53 m_txtDSN->SetValue( settings->m_Source.dsn );
54 m_txtUser->SetValue( settings->m_Source.username );
55 m_txtPassword->SetValue( settings->m_Source.password );
56 }
57
58 m_spinCacheSize->SetValue( settings->m_Cache.max_size );
59 m_spinCacheTimeout->SetValue( settings->m_Cache.max_age );
60
63
64 return true;
65}
66
67
69{
70 return true;
71}
72
73
74void DIALOG_DATABASE_LIB_SETTINGS::OnDSNSelected( wxCommandEvent& aEvent )
75{
76 m_txtConnectionString->Disable();
77 m_txtDSN->Enable();
78 m_txtUser->Enable();
79 m_txtPassword->Enable();
80}
81
82
84{
85 m_txtConnectionString->Enable();
86 m_txtDSN->Disable();
87 m_txtUser->Disable();
88 m_txtPassword->Disable();
89}
90
91
92void DIALOG_DATABASE_LIB_SETTINGS::OnBtnTest( wxCommandEvent& aEvent )
93{
94 wxString errorMsg;
95
96 if( m_plugin->TestConnection( &errorMsg ) )
97 {
98 m_stConnectionTestStatus->SetLabel( _( "Connected to database successfully" ) );
99 m_stConnectionTestStatus->SetToolTip( wxEmptyString );
100
101 wxCommandEvent dummy;
103 }
104 else
105 {
106 m_stConnectionTestStatus->SetLabel( wxString::Format( _( "Database connection failed: %s" ),
107 errorMsg ) );
108 m_stConnectionTestStatus->SetToolTip( errorMsg );
109 }
110}
111
112
114{
115 if( !m_plugin->TestConnection() )
116 {
117 m_stLibrariesStatus->SetLabel( _( "No connection to database" ) );
118 return;
119 }
120
121 std::vector<wxString> libs;
123
124 m_stLibrariesStatus->SetLabel( wxString::Format( _( "Loaded %zu libraries" ), libs.size() ) );
125}
126
127
129{
130 return ( m_rbDSN->GetValue() && !m_txtDSN->IsEmpty() ) || !m_txtConnectionString->IsEmpty();
131}
DATABASE_CACHE_SETTINGS m_Cache
Class DIALOG_DATABASE_LIB_SETTINGS_BASE.
void OnDSNSelected(wxCommandEvent &aEvent) override
DIALOG_DATABASE_LIB_SETTINGS(wxWindow *aParent, SCH_IO_DATABASE *aPlugin)
void OnConnectionStringSelected(wxCommandEvent &aEvent) override
void OnBtnTest(wxCommandEvent &aEvent) override
void OnBtnReloadConfig(wxCommandEvent &aEvent) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
A KiCad database library provides both symbol and footprint metadata, so there are "shim" plugins on ...
DATABASE_LIB_SETTINGS * Settings() const
bool TestConnection(wxString *aErrorMsg=nullptr)
void GetSubLibraryNames(std::vector< wxString > &aNames) override
Retrieves a list of sub-libraries in this library.
#define _(s)
std::vector< FAB_LAYER_COLOR > dummy
int max_age
Max age of cached rows before they expire, in seconds.
int max_size
Maximum number of single-row results to cache.
std::string connection_string