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 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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
24
25
35
36
38{
39 wxCommandEvent dummy;
40 DATABASE_LIB_SETTINGS* settings = m_plugin->Settings();
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 DATABASE_LIB_SETTINGS* settings = m_plugin->Settings();
71
72 if( m_rbConnectionString->GetValue() )
73 {
74 settings->m_Source.connection_string = m_txtConnectionString->GetValue().ToStdString();
75 settings->m_Source.dsn.clear();
76 settings->m_Source.username.clear();
77 settings->m_Source.password.clear();
78 }
79 else
80 {
81 settings->m_Source.connection_string.clear();
82 settings->m_Source.dsn = m_txtDSN->GetValue().ToStdString();
83 settings->m_Source.username = m_txtUser->GetValue().ToStdString();
84 settings->m_Source.password = m_txtPassword->GetValue().ToStdString();
85 }
86
87 settings->m_Cache.max_size = m_spinCacheSize->GetValue();
88 settings->m_Cache.max_age = m_spinCacheTimeout->GetValue();
89
90 // Kept read-only elsewhere to avoid reformatting hand-edited files spuriously
91 settings->SetReadOnly( false );
92 settings->SaveToFile();
93 settings->SetReadOnly( true );
94
95 return true;
96}
97
98
99void DIALOG_DATABASE_LIB_SETTINGS::OnDSNSelected( wxCommandEvent& aEvent )
100{
101 m_txtConnectionString->Disable();
102 m_txtDSN->Enable();
103 m_txtUser->Enable();
104 m_txtPassword->Enable();
105}
106
107
109{
110 m_txtConnectionString->Enable();
111 m_txtDSN->Disable();
112 m_txtUser->Disable();
113 m_txtPassword->Disable();
114}
115
116
117void DIALOG_DATABASE_LIB_SETTINGS::OnBtnTest( wxCommandEvent& aEvent )
118{
119 wxString errorMsg;
120
121 if( m_plugin->TestConnection( &errorMsg ) )
122 {
123 m_stConnectionTestStatus->SetLabel( _( "Connected to database successfully" ) );
124 m_stConnectionTestStatus->SetToolTip( wxEmptyString );
125
126 wxCommandEvent dummy;
128 }
129 else
130 {
131 m_stConnectionTestStatus->SetLabel( wxString::Format( _( "Database connection failed: %s" ),
132 errorMsg ) );
133 m_stConnectionTestStatus->SetToolTip( errorMsg );
134 }
135}
136
137
139{
140 if( !m_plugin->TestConnection() )
141 {
142 m_stLibrariesStatus->SetLabel( _( "No connection to database" ) );
143 return;
144 }
145
146 std::vector<wxString> libs;
147 m_plugin->GetSubLibraryNames( libs );
148
149 m_stLibrariesStatus->SetLabel( wxString::Format( _( "Loaded %zu libraries" ), libs.size() ) );
150}
151
152
154{
155 return ( m_rbDSN->GetValue() && !m_txtDSN->IsEmpty() ) || !m_txtConnectionString->IsEmpty();
156}
DATABASE_CACHE_SETTINGS m_Cache
DIALOG_DATABASE_LIB_SETTINGS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Database Library Settings"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(500, 600), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
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...
void SetReadOnly(bool aReadOnly)
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
Calls Store() and then writes the contents of the JSON document to a file.
A KiCad database library provides both symbol and footprint metadata, so there are "shim" plugins on ...
#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