KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_about.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) 2010 Rafael Sokolowski <[email protected]>
5 * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.TXT for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25
26#include <build_version.h>
27#include <wx/clipbrd.h>
28#include <wx/msgdlg.h>
29#include <wx/hyperlink.h>
30
31/* All KiCad icons are linked into shared library 'libbitmaps.a'.
32 * Icons:
33 * preference_xpm; // Icon for 'Developers' tab
34 * editor_xpm; // Icon for 'Doc Writers' tab
35 * color_materials_xpm; // Icon for 'Artists' tab
36 * language_xpm; // Icon for 'Translators' tab
37 * right_xpm; // Right arrow icon for list items
38 * info_xpm; // Bulb for description tab
39 * tools_xpm; // Sheet of paper icon for license info tab
40 */
41#include <bitmaps.h>
43#include <tool/tool_manager.h>
44
45#include "dialog_about.h"
46
47
49 DIALOG_ABOUT_BASE( aParent ),
50 m_images( nullptr ),
51 m_info( aAppInfo )
52{
53 wxASSERT( aParent != nullptr );
54
55 SetEvtHandlerEnabled( false );
56
57#ifdef __WXMAC__
58 // HiDPI-aware API; will be generally available in wxWidgets 3.4
59 wxVector<wxBitmapBundle> images;
60
61 images.push_back( KiBitmapBundle( BITMAPS::info ) ); // INFORMATION
62 images.push_back( KiBitmapBundle( BITMAPS::recent ) ); // VERSION
63 images.push_back( KiBitmapBundle( BITMAPS::preference ) ); // DEVELOPERS
64 images.push_back( KiBitmapBundle( BITMAPS::editor ) ); // DOCWRITERS
65 images.push_back( KiBitmapBundle( BITMAPS::library ) ); // LIBRARIANS
66 images.push_back( KiBitmapBundle( BITMAPS::color_materials ) ); // ARTISTS
67 images.push_back( KiBitmapBundle( BITMAPS::language ) ); // TRANSLATORS
68 images.push_back( KiBitmapBundle( BITMAPS::zip ) ); // PACKAGERS
69 images.push_back( KiBitmapBundle( BITMAPS::tools ) ); // LICENSE
70
71 m_notebook->SetImages( images );
72#else
73 // TODO: Change these to 16x16 versions when available
74 m_images = new wxImageList( 24, 24, false, 9 );
75
76 m_images->Add( KiBitmap( BITMAPS::info ) ); // INFORMATION
77 m_images->Add( KiBitmap( BITMAPS::recent ) ); // VERSION
78 m_images->Add( KiBitmap( BITMAPS::preference ) ); // DEVELOPERS
79 m_images->Add( KiBitmap( BITMAPS::editor ) ); // DOCWRITERS
80 m_images->Add( KiBitmap( BITMAPS::library ) ); // LIBRARIANS
81 m_images->Add( KiBitmap( BITMAPS::color_materials ) ); // ARTISTS
82 m_images->Add( KiBitmap( BITMAPS::language ) ); // TRANSLATORS
83 m_images->Add( KiBitmap( BITMAPS::zip ) ); // PACKAGERS
84 m_images->Add( KiBitmap( BITMAPS::tools ) ); // LICENSE
85
86 m_notebook->SetImageList( m_images );
87#endif
88
89 if( m_info.GetAppIcon().IsOk() )
90 {
91 SetIcon( m_info.GetAppIcon() );
92 m_bitmapApp->SetBitmap( m_info.GetAppIcon() );
93 }
94 else
95 {
96 wxIcon icon;
97
98 if( IsNightlyVersion() )
99 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly ) );
100 else
101 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad ) );
102
103 SetIcon( icon );
104 m_bitmapApp->SetBitmap( icon );
105 }
106
107 m_titleName = aParent->GetAboutTitle();
111 m_staticTextBuildVersion->SetLabel( wxS( "Version: " ) + m_info.GetBuildVersion() );
113
114 SetTitle( wxString::Format( _( "About %s" ), m_titleName ) );
116
117 SetEvtHandlerEnabled( true );
118 GetSizer()->SetSizeHints( this );
119 SetFocus();
120 Centre();
121}
122
123
125{
126#ifndef __WXMAC__
127 delete m_images;
128#endif
129}
130
131
133{
134 createNotebookHtmlPage( m_notebook, _( "About" ), IMAGES::INFORMATION,
136
137 wxString version = GetVersionInfoData( m_untranslatedTitleName, true );
138
139 createNotebookHtmlPage( m_notebook, _( "Version" ), IMAGES::VERSION, version, true );
140
141 createNotebookPageByCategory( m_notebook, _( "Developers" ) , IMAGES::DEVELOPERS,
143 createNotebookPageByCategory( m_notebook, _( "Doc Writers" ), IMAGES::DOCWRITERS,
145
146 createNotebookPageByCategory( m_notebook, _( "Librarians" ), IMAGES::LIBRARIANS,
148
149 createNotebookPageByCategory( m_notebook, _( "Artists" ), IMAGES::ARTISTS,
150 m_info.GetArtists() );
151 createNotebookPageByCategory( m_notebook, _( "Translators" ), IMAGES::TRANSLATORS,
153 createNotebookPageByCategory( m_notebook, _( "Packagers" ), IMAGES::PACKAGERS,
155
156 createNotebookHtmlPage( m_notebook, _( "License" ), IMAGES::LICENSE, m_info.GetLicense() );
157}
158
159void DIALOG_ABOUT::createNotebookPageByCategory( wxNotebook* aParent, const wxString& aCaption,
160 IMAGES aIconIndex,
161 const CONTRIBUTORS& aContributors )
162{
163 wxString html;
164
165 for( size_t i=0; i < aContributors.GetCount(); ++i )
166 {
167 CONTRIBUTOR* contributor = &aContributors.Item( i );
168 wxString category = contributor->GetCategory();
169
170 // to construct the next row we expect to have a category and a contributor that was
171 // not considered up to now
172 if( category == wxEmptyString || contributor->IsChecked() )
173 continue;
174
175 html += wxString::Format( wxS( "<p><b><u>%s:</u></b><ul>" ),
176 contributor->GetCategory() );
177
178 // Now, all contributors of the same category will follow
179 for( size_t j=0; j < aContributors.GetCount(); ++j )
180 {
181 CONTRIBUTOR* sub_contributor = &aContributors.Item( j );
182
183 if ( sub_contributor->GetCategory() == category )
184 {
185 // No URL supplied, display normal text control
186 if( sub_contributor->GetUrl().IsEmpty() )
187 {
188 html += wxString::Format( wxS( "<li>%s</li>" ),
189 sub_contributor->GetName() );
190 }
191 else
192 {
193 html += wxString::Format( wxS( "<li><a href='%s'>%s</a></li>" ),
194 sub_contributor->GetUrl(),
195 sub_contributor->GetName() );
196 }
197
198 // this contributor was added to the GUI, thus can be ignored next time
199 sub_contributor->SetChecked( true );
200 }
201 }
202
203 html += wxS( "</ul></p>" );
204 }
205
206 createNotebookHtmlPage( aParent, aCaption, aIconIndex, html, true );
207}
208
209
210void DIALOG_ABOUT::createNotebookHtmlPage( wxNotebook* aParent, const wxString& aCaption,
211 IMAGES aIconIndex, const wxString& html,
212 bool aSelection )
213{
214 wxPanel* panel = new wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
215 wxTAB_TRAVERSAL );
216
217 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
218
219 int flags = aSelection ? wxHW_SCROLLBAR_AUTO : ( wxHW_SCROLLBAR_AUTO | wxHW_NO_SELECTION );
220
221 // the HTML page is going to be created with previously created HTML content
222 HTML_WINDOW* htmlWindow = new HTML_WINDOW( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
223 flags );
224
225 // HTML font set to font properties as they are used for widgets to have an unique look
226 // under different platforms with HTML
227 wxFont font = GetFont();
228 htmlWindow->SetStandardFonts( font.GetPointSize(), font.GetFaceName(), font.GetFaceName() );
229 htmlWindow->SetPage( html );
230
231 // the HTML window shall not be used to open external links, thus this task is delegated
232 // to users default browser
233 htmlWindow->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED,
234 wxHtmlLinkEventHandler( DIALOG_ABOUT::onHtmlLinkClicked ), NULL, this );
235
236 // no additional space around the HTML window as it is also the case by the other notebook
237 // pages
238 bSizer->Add( htmlWindow, 1, wxEXPAND, 0 );
239 panel->SetSizer( bSizer );
240
241 aParent->AddPage( panel, aCaption, false, static_cast<int>( aIconIndex ) );
242}
243
244
245void DIALOG_ABOUT::onHtmlLinkClicked( wxHtmlLinkEvent& event )
246{
247 ::wxLaunchDefaultBrowser( event.GetLinkInfo().GetHref() );
248}
249
250
251void DIALOG_ABOUT::onCopyVersionInfo( wxCommandEvent& event )
252{
253 wxLogNull doNotLog; // disable logging of failed clipboard actions
254
255 if( !wxTheClipboard->Open() )
256 {
257 wxMessageBox( _( "Could not open clipboard to write version information." ),
258 _( "Clipboard Error" ), wxOK | wxICON_EXCLAMATION, this );
259 return;
260 }
261
262 wxString msg_version = GetVersionInfoData( m_untranslatedTitleName );
263
264 wxTheClipboard->SetData( new wxTextDataObject( msg_version ) );
265 wxTheClipboard->Flush(); // Allow clipboard data to be available after KiCad closes
266 wxTheClipboard->Close();
267 m_btCopyVersionInfo->SetLabel( _( "Copied..." ) );
268}
269
270
271void DIALOG_ABOUT::onDonateClick( wxCommandEvent& event )
272{
273 if( TOOL_MANAGER* mgr = static_cast<EDA_BASE_FRAME*>( GetParent() )->GetToolManager() )
274 mgr->RunAction( "common.SuiteControl.donate" );
275}
276
277
278void DIALOG_ABOUT::onReportBug( wxCommandEvent& event )
279{
280 if( TOOL_MANAGER* mgr = static_cast<EDA_BASE_FRAME*>( GetParent() )->GetToolManager() )
281 mgr->RunAction( "common.SuiteControl.reportBug" );
282}
283
284
285void DIALOG_ABOUT::OnNotebookPageChanged( wxNotebookEvent& aEvent )
286{
287 // Work around wxMac issue where the notebook pages are blank
288#ifdef __WXMAC__
289 int page = aEvent.GetSelection();
290
291 if( page >= 0 )
292 m_notebook->ChangeSelection( static_cast<unsigned>( page ) );
293#endif
294}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104
wxString GetVersionInfoData(const wxString &aTitle, bool aHtml, bool aBrief)
Create a version info string for bug reports and the about dialog.
bool IsNightlyVersion()
Check if the build is meant to be nightly.
An object of this class is meant to be used to store application specific information like who has co...
Definition: aboutinfo.h:45
CONTRIBUTORS GetPackagers()
Definition: aboutinfo.h:91
CONTRIBUTORS GetLibrarians()
Definition: aboutinfo.h:88
wxString GetCopyright()
Definition: aboutinfo.h:100
wxString & GetLibVersion()
Definition: aboutinfo.h:112
CONTRIBUTORS GetDevelopers()
Definition: aboutinfo.h:86
CONTRIBUTORS GetDocWriters()
Definition: aboutinfo.h:87
wxString & GetBuildVersion()
Definition: aboutinfo.h:106
wxString & GetDescription()
Definition: aboutinfo.h:94
CONTRIBUTORS GetTranslators()
Definition: aboutinfo.h:90
CONTRIBUTORS GetArtists()
Definition: aboutinfo.h:89
wxIcon & GetAppIcon()
Wrapper to manage memory allocation for bitmaps.
Definition: aboutinfo.h:115
wxString & GetLicense()
Definition: aboutinfo.h:97
A contributor, a person which was involved in the development of the application or which has contrib...
Definition: aboutinfo.h:161
wxString & GetName()
Definition: aboutinfo.h:174
wxString & GetUrl()
Definition: aboutinfo.h:175
wxString & GetCategory()
Definition: aboutinfo.h:176
bool IsChecked()
Definition: aboutinfo.h:178
void SetChecked(bool status)
Definition: aboutinfo.h:177
Class DIALOG_ABOUT_BASE.
wxStaticText * m_staticTextBuildVersion
wxStaticBitmap * m_bitmapApp
wxStaticText * m_staticTextCopyright
wxStaticText * m_staticTextLibVersion
wxButton * m_btCopyVersionInfo
wxNotebook * m_notebook
wxStaticText * m_staticTextAppTitle
void OnNotebookPageChanged(wxNotebookEvent &aEvent) override
wxString m_titleName
Definition: dialog_about.h:84
wxImageList * m_images
Definition: dialog_about.h:83
wxString m_untranslatedTitleName
Definition: dialog_about.h:85
void createNotebooks()
ABOUT_APP_INFO & m_info
Definition: dialog_about.h:87
void createNotebookPageByCategory(wxNotebook *aParent, const wxString &aCaption, IMAGES aIconIndex, const CONTRIBUTORS &aContributors)
DIALOG_ABOUT(EDA_BASE_FRAME *aParent, ABOUT_APP_INFO &aAppInfo)
void onCopyVersionInfo(wxCommandEvent &event) override
void onHtmlLinkClicked(wxHtmlLinkEvent &event)
void onReportBug(wxCommandEvent &event) override
void onDonateClick(wxCommandEvent &event) override
void createNotebookHtmlPage(wxNotebook *aParent, const wxString &aCaption, IMAGES aIconIndex, const wxString &aHtmlMessage, bool aSelection=false)
The base frame for deriving all KiCad main window classes.
const wxString & GetUntranslatedAboutTitle() const
const wxString & GetAboutTitle() const
Add dark theme support to wxHtmlWindow.
Definition: html_window.h:34
bool SetPage(const wxString &aSource) override
Definition: html_window.cpp:38
Master controller class:
Definition: tool_manager.h:57
IMAGES
Definition: dialog_about.h:37
#define _(s)