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 <eda_base_frame.h>
28#include <wx/clipbrd.h>
29#include <wx/msgdlg.h>
30#include <wx/hyperlink.h>
31
32/* All KiCad icons are linked into shared library 'libbitmaps.a'.
33 * Icons:
34 * preference_xpm; // Icon for 'Developers' tab
35 * editor_xpm; // Icon for 'Doc Writers' tab
36 * color_materials_xpm; // Icon for 'Artists' tab
37 * language_xpm; // Icon for 'Translators' tab
38 * right_xpm; // Right arrow icon for list items
39 * info_xpm; // Bulb for description tab
40 * tools_xpm; // Sheet of paper icon for license info tab
41 */
42#include <bitmaps.h>
44#include <tool/tool_manager.h>
45
46#include "dialog_about.h"
47
48
50 DIALOG_ABOUT_BASE( aParent ),
51 m_images( nullptr ),
52 m_info( aAppInfo )
53{
54 wxASSERT( aParent != nullptr );
55
56 SetEvtHandlerEnabled( false );
57
58#ifdef __WXMAC__
59 // HiDPI-aware API; will be generally available in wxWidgets 3.4
60 wxVector<wxBitmapBundle> images;
61
62 images.push_back( KiBitmapBundle( BITMAPS::info ) ); // INFORMATION
63 images.push_back( KiBitmapBundle( BITMAPS::recent ) ); // VERSION
64 images.push_back( KiBitmapBundle( BITMAPS::preference ) ); // DEVELOPERS
65 images.push_back( KiBitmapBundle( BITMAPS::editor ) ); // DOCWRITERS
66 images.push_back( KiBitmapBundle( BITMAPS::library ) ); // LIBRARIANS
67 images.push_back( KiBitmapBundle( BITMAPS::color_materials ) ); // ARTISTS
68 images.push_back( KiBitmapBundle( BITMAPS::language ) ); // TRANSLATORS
69 images.push_back( KiBitmapBundle( BITMAPS::zip ) ); // PACKAGERS
70 images.push_back( KiBitmapBundle( BITMAPS::tools ) ); // LICENSE
71
72 m_notebook->SetImages( images );
73#else
74 // TODO: Change these to 16x16 versions when available
75 m_images = new wxImageList( 24, 24, false, 9 );
76
77 m_images->Add( KiBitmap( BITMAPS::info ) ); // INFORMATION
78 m_images->Add( KiBitmap( BITMAPS::recent ) ); // VERSION
79 m_images->Add( KiBitmap( BITMAPS::preference ) ); // DEVELOPERS
80 m_images->Add( KiBitmap( BITMAPS::editor ) ); // DOCWRITERS
81 m_images->Add( KiBitmap( BITMAPS::library ) ); // LIBRARIANS
82 m_images->Add( KiBitmap( BITMAPS::color_materials ) ); // ARTISTS
83 m_images->Add( KiBitmap( BITMAPS::language ) ); // TRANSLATORS
84 m_images->Add( KiBitmap( BITMAPS::zip ) ); // PACKAGERS
85 m_images->Add( KiBitmap( BITMAPS::tools ) ); // LICENSE
86
87 m_notebook->SetImageList( m_images );
88#endif
89
90 if( m_info.GetAppIcon().IsOk() )
91 {
92 SetIcon( m_info.GetAppIcon() );
93 m_bitmapApp->SetBitmap( m_info.GetAppIcon() );
94 }
95 else
96 {
97 wxIcon icon;
98
99 if( IsNightlyVersion() )
100 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly ) );
101 else
102 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad ) );
103
104 SetIcon( icon );
105 m_bitmapApp->SetBitmap( icon );
106 }
107
108 m_titleName = aParent->GetAboutTitle();
112 m_staticTextBuildVersion->SetLabel( wxS( "Version: " ) + m_info.GetBuildVersion() );
114
115 SetTitle( wxString::Format( _( "About %s" ), m_titleName ) );
117
118 SetEvtHandlerEnabled( true );
119 GetSizer()->SetSizeHints( this );
120 SetFocus();
121 Centre();
122}
123
124
126{
127#ifndef __WXMAC__
128 delete m_images;
129#endif
130}
131
132
134{
135 createNotebookHtmlPage( m_notebook, _( "About" ), IMAGES::INFORMATION,
137
138 wxString version = GetVersionInfoData( m_untranslatedTitleName, true );
139
140 createNotebookHtmlPage( m_notebook, _( "Version" ), IMAGES::VERSION, version, true );
141
142 createNotebookPageByCategory( m_notebook, _( "Developers" ) , IMAGES::DEVELOPERS,
144 createNotebookPageByCategory( m_notebook, _( "Doc Writers" ), IMAGES::DOCWRITERS,
146
147 createNotebookPageByCategory( m_notebook, _( "Librarians" ), IMAGES::LIBRARIANS,
149
150 createNotebookPageByCategory( m_notebook, _( "Artists" ), IMAGES::ARTISTS,
151 m_info.GetArtists() );
152 createNotebookPageByCategory( m_notebook, _( "Translators" ), IMAGES::TRANSLATORS,
154 createNotebookPageByCategory( m_notebook, _( "Packagers" ), IMAGES::PACKAGERS,
156
157 createNotebookHtmlPage( m_notebook, _( "License" ), IMAGES::LICENSE, m_info.GetLicense() );
158}
159
160void DIALOG_ABOUT::createNotebookPageByCategory( wxNotebook* aParent, const wxString& aCaption,
161 IMAGES aIconIndex,
162 const CONTRIBUTORS& aContributors )
163{
164 wxString html;
165
166 for( size_t i=0; i < aContributors.GetCount(); ++i )
167 {
168 CONTRIBUTOR* contributor = &aContributors.Item( i );
169 wxString category = contributor->GetCategory();
170
171 // to construct the next row we expect to have a category and a contributor that was
172 // not considered up to now
173 if( category == wxEmptyString || contributor->IsChecked() )
174 continue;
175
176 html += wxString::Format( wxS( "<p><b><u>%s:</u></b><ul>" ),
177 contributor->GetCategory() );
178
179 // Now, all contributors of the same category will follow
180 for( size_t j=0; j < aContributors.GetCount(); ++j )
181 {
182 CONTRIBUTOR* sub_contributor = &aContributors.Item( j );
183
184 if ( sub_contributor->GetCategory() == category )
185 {
186 // No URL supplied, display normal text control
187 if( sub_contributor->GetUrl().IsEmpty() )
188 {
189 html += wxString::Format( wxS( "<li>%s</li>" ),
190 sub_contributor->GetName() );
191 }
192 else
193 {
194 html += wxString::Format( wxS( "<li><a href='%s'>%s</a></li>" ),
195 sub_contributor->GetUrl(),
196 sub_contributor->GetName() );
197 }
198
199 // this contributor was added to the GUI, thus can be ignored next time
200 sub_contributor->SetChecked( true );
201 }
202 }
203
204 html += wxS( "</ul></p>" );
205 }
206
207 createNotebookHtmlPage( aParent, aCaption, aIconIndex, html, true );
208}
209
210
211void DIALOG_ABOUT::createNotebookHtmlPage( wxNotebook* aParent, const wxString& aCaption,
212 IMAGES aIconIndex, const wxString& html,
213 bool aSelection )
214{
215 wxPanel* panel = new wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
216 wxTAB_TRAVERSAL );
217
218 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
219
220 int flags = aSelection ? wxHW_SCROLLBAR_AUTO : ( wxHW_SCROLLBAR_AUTO | wxHW_NO_SELECTION );
221
222 // the HTML page is going to be created with previously created HTML content
223 HTML_WINDOW* htmlWindow = new HTML_WINDOW( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
224 flags );
225
226 // HTML font set to font properties as they are used for widgets to have an unique look
227 // under different platforms with HTML
228 wxFont font = GetFont();
229 htmlWindow->SetStandardFonts( font.GetPointSize(), font.GetFaceName(), font.GetFaceName() );
230 htmlWindow->SetPage( html );
231
232 // the HTML window shall not be used to open external links, thus this task is delegated
233 // to users default browser
234 htmlWindow->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED,
235 wxHtmlLinkEventHandler( DIALOG_ABOUT::onHtmlLinkClicked ), NULL, this );
236
237 // no additional space around the HTML window as it is also the case by the other notebook
238 // pages
239 bSizer->Add( htmlWindow, 1, wxEXPAND, 0 );
240 panel->SetSizer( bSizer );
241
242 aParent->AddPage( panel, aCaption, false, static_cast<int>( aIconIndex ) );
243}
244
245
246void DIALOG_ABOUT::onHtmlLinkClicked( wxHtmlLinkEvent& event )
247{
248 ::wxLaunchDefaultBrowser( event.GetLinkInfo().GetHref() );
249}
250
251
252void DIALOG_ABOUT::onCopyVersionInfo( wxCommandEvent& event )
253{
254 wxLogNull doNotLog; // disable logging of failed clipboard actions
255
256 if( !wxTheClipboard->Open() )
257 {
258 wxMessageBox( _( "Could not open clipboard to write version information." ),
259 _( "Clipboard Error" ), wxOK | wxICON_EXCLAMATION, this );
260 return;
261 }
262
263 wxString msg_version = GetVersionInfoData( m_untranslatedTitleName );
264
265 wxTheClipboard->SetData( new wxTextDataObject( msg_version ) );
266 wxTheClipboard->Flush(); // Allow clipboard data to be available after KiCad closes
267 wxTheClipboard->Close();
268 m_btCopyVersionInfo->SetLabel( _( "Copied..." ) );
269}
270
271
272void DIALOG_ABOUT::onDonateClick( wxCommandEvent& event )
273{
274 if( TOOL_MANAGER* mgr = static_cast<EDA_BASE_FRAME*>( GetParent() )->GetToolManager() )
275 mgr->RunAction( "common.SuiteControl.donate" );
276}
277
278
279void DIALOG_ABOUT::onReportBug( wxCommandEvent& event )
280{
281 if( TOOL_MANAGER* mgr = static_cast<EDA_BASE_FRAME*>( GetParent() )->GetToolManager() )
282 mgr->RunAction( "common.SuiteControl.reportBug" );
283}
284
285
286void DIALOG_ABOUT::OnNotebookPageChanged( wxNotebookEvent& aEvent )
287{
288 // Work around wxMac issue where the notebook pages are blank
289#ifdef __WXMAC__
290 int page = aEvent.GetSelection();
291
292 if( page >= 0 )
293 m_notebook->ChangeSelection( static_cast<unsigned>( page ) );
294#endif
295}
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:35
bool SetPage(const wxString &aSource) override
Definition: html_window.cpp:50
Master controller class:
Definition: tool_manager.h:62
IMAGES
Definition: dialog_about.h:37
#define _(s)
Base window classes and related definitions.