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