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, see <https://www.gnu.org/licenses/>.
19 */
20
21#if defined( _WIN32 )
22#include <windows.h>
23#endif
24
25#include <build_version.h>
26#include <eda_base_frame.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 // dpi fixes
56 m_notebook->SetMinSize( FromDIP( m_notebook->GetMinSize() ) );
57
58 SetEvtHandlerEnabled( false );
59
60 const int c_iconSize = 16;
61 wxVector<wxBitmapBundle> images;
62
63 images.push_back( KiBitmapBundleDef( BITMAPS::info, c_iconSize ) ); // INFORMATION
64 images.push_back( KiBitmapBundleDef( BITMAPS::recent, c_iconSize ) ); // VERSION
65 images.push_back( KiBitmapBundleDef( BITMAPS::preference, c_iconSize ) ); // DEVELOPERS
66 images.push_back( KiBitmapBundleDef( BITMAPS::editor, c_iconSize ) ); // DOCWRITERS
67 images.push_back( KiBitmapBundleDef( BITMAPS::library, c_iconSize ) ); // LIBRARIANS
68 images.push_back( KiBitmapBundleDef( BITMAPS::color_materials, c_iconSize ) ); // ARTISTS
69 images.push_back( KiBitmapBundleDef( BITMAPS::language, c_iconSize ) ); // TRANSLATORS
70 images.push_back( KiBitmapBundleDef( BITMAPS::zip, c_iconSize ) ); // PACKAGERS
71 images.push_back( KiBitmapBundleDef( BITMAPS::tools, c_iconSize ) ); // LICENSE
72
73 m_notebook->SetImages( images );
74
75 if( m_info.GetAppIcon().IsOk() )
76 {
77 SetIcon( m_info.GetAppIcon() );
78 m_bitmapApp->SetBitmap( m_info.GetAppIcon() );
79 }
80 else
81 {
82 wxIcon icon;
83
84 if( IsNightlyVersion() )
85 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly ) );
86 else
87 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad ) );
88
89 SetIcon( icon );
90 m_bitmapApp->SetBitmap( icon );
91 }
92
93 m_titleName = aParent->GetAboutTitle();
96
97 // On windows, display the number of GDI objects in use. Can be useful when some GDI objects
98 // are not displayed because the max count of GDI objects (usually 10000) is reached
99 // So displaying this number can help to diagnose strange display issues
100 wxString extraInfo;
101
102 #if defined( _WIN32 )
103 uint32_t gdi_count = GetGuiResources( GetCurrentProcess(), GR_GDIOBJECTS );
104 extraInfo.Printf( _( "GDI objects in use %u" ), gdi_count );
105 extraInfo.Prepend( wxT( "\n" ) );
106 #endif
107
108 m_staticTextBuildVersion->SetLabel( wxS( "Version: " ) + m_info.GetBuildVersion() );
109 m_staticTextLibVersion->SetLabel( m_info.GetLibVersion() + extraInfo );
110
111 SetTitle( wxString::Format( _( "About %s" ), m_titleName ) );
113
114 SetEvtHandlerEnabled( true );
115 GetSizer()->SetSizeHints( this );
116 SetFocus();
117 Centre();
118}
119
120
122{
123#ifndef __WXMAC__
124 delete m_images;
125#endif
126}
127
128
130{
132 m_info.GetDescription() );
133
134 wxString version = GetVersionInfoData( m_untranslatedTitleName, true );
135
136 createNotebookHtmlPage( m_notebook, _( "Version" ), IMAGES::VERSION, version, true );
137
139 m_info.GetDevelopers() );
141 m_info.GetDocWriters() );
142
144 m_info.GetLibrarians() );
145
147 m_info.GetArtists() );
149 m_info.GetTranslators() );
151 m_info.GetPackagers() );
152
153 createNotebookHtmlPage( m_notebook, _( "License" ), IMAGES::LICENSE, m_info.GetLicense() );
154}
155
156void DIALOG_ABOUT::createNotebookPageByCategory( wxNotebook* aParent, const wxString& aCaption,
157 IMAGES aIconIndex,
158 const CONTRIBUTORS& aContributors )
159{
160 wxString html;
161
162 for( size_t i=0; i < aContributors.GetCount(); ++i )
163 {
164 CONTRIBUTOR* contributor = &aContributors.Item( i );
165 wxString category = contributor->GetCategory();
166
167 // to construct the next row we expect to have a category and a contributor that was
168 // not considered up to now
169 if( category == wxEmptyString || contributor->IsChecked() )
170 continue;
171
172 html += wxString::Format( wxS( "<p><b><u>%s:</u></b><ul>" ),
173 contributor->GetCategory() );
174
175 // Now, all contributors of the same category will follow
176 for( size_t j=0; j < aContributors.GetCount(); ++j )
177 {
178 CONTRIBUTOR* sub_contributor = &aContributors.Item( j );
179
180 if ( sub_contributor->GetCategory() == category )
181 {
182 // No URL supplied, display normal text control
183 if( sub_contributor->GetUrl().IsEmpty() )
184 {
185 html += wxString::Format( wxS( "<li>%s</li>" ),
186 sub_contributor->GetName() );
187 }
188 else
189 {
190 html += wxString::Format( wxS( "<li><a href='%s'>%s</a></li>" ),
191 sub_contributor->GetUrl(),
192 sub_contributor->GetName() );
193 }
194
195 // this contributor was added to the GUI, thus can be ignored next time
196 sub_contributor->SetChecked( true );
197 }
198 }
199
200 html += wxS( "</ul></p>" );
201 }
202
203 createNotebookHtmlPage( aParent, aCaption, aIconIndex, html, true );
204}
205
206
207void DIALOG_ABOUT::createNotebookHtmlPage( wxNotebook* aParent, const wxString& aCaption,
208 IMAGES aIconIndex, const wxString& html,
209 bool aSelection )
210{
211 wxPanel* panel = new wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
212 wxTAB_TRAVERSAL );
213
214 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
215
216 int flags = aSelection ? wxHW_SCROLLBAR_AUTO : ( wxHW_SCROLLBAR_AUTO | wxHW_NO_SELECTION );
217
218 // the HTML page is going to be created with previously created HTML content
219 HTML_WINDOW* htmlWindow = new HTML_WINDOW( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
220 flags );
221
222 // HTML font set to font properties as they are used for widgets to have an unique look
223 // under different platforms with HTML
224 wxFont font = GetFont();
225 htmlWindow->SetStandardFonts( font.GetPointSize(), font.GetFaceName(), font.GetFaceName() );
226 htmlWindow->SetPage( html );
227
228 // the HTML window shall not be used to open external links, thus this task is delegated
229 // to users default browser
230 htmlWindow->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED,
231 wxHtmlLinkEventHandler( DIALOG_ABOUT::onHtmlLinkClicked ), NULL, this );
232
233 // no additional space around the HTML window as it is also the case by the other notebook
234 // pages
235 bSizer->Add( htmlWindow, 1, wxEXPAND, 0 );
236 panel->SetSizer( bSizer );
237
238 aParent->AddPage( panel, aCaption, false, static_cast<int>( aIconIndex ) );
239}
240
241
242void DIALOG_ABOUT::onHtmlLinkClicked( wxHtmlLinkEvent& event )
243{
244 ::wxLaunchDefaultBrowser( event.GetLinkInfo().GetHref() );
245}
246
247
248void DIALOG_ABOUT::onCopyVersionInfo( wxCommandEvent& event )
249{
250 wxLogNull doNotLog; // disable logging of failed clipboard actions
251
252 if( !wxTheClipboard->Open() )
253 {
254 wxMessageBox( _( "Could not open clipboard to write version information." ),
255 _( "Clipboard Error" ), wxOK | wxICON_EXCLAMATION, this );
256 return;
257 }
258
259 wxString msg_version = GetVersionInfoData( m_untranslatedTitleName );
260
261 wxTheClipboard->SetData( new wxTextDataObject( msg_version ) );
262 wxTheClipboard->Flush(); // Allow clipboard data to be available after KiCad closes
263 wxTheClipboard->Close();
264 m_btCopyVersionInfo->SetLabel( _( "Copied..." ) );
265}
266
267
268void DIALOG_ABOUT::onDonateClick( wxCommandEvent& event )
269{
270 if( TOOL_MANAGER* mgr = static_cast<EDA_BASE_FRAME*>( GetParent() )->GetToolManager() )
271 mgr->RunAction( "common.SuiteControl.donate" );
272}
273
274
275void DIALOG_ABOUT::onReportBug( wxCommandEvent& event )
276{
277 if( TOOL_MANAGER* mgr = static_cast<EDA_BASE_FRAME*>( GetParent() )->GetToolManager() )
278 mgr->RunAction( "common.SuiteControl.reportBug" );
279}
280
281
282void DIALOG_ABOUT::OnNotebookPageChanged( wxNotebookEvent& aEvent )
283{
284 // Work around wxMac issue where the notebook pages are blank
285#ifdef __WXMAC__
286 int page = aEvent.GetSelection();
287
288 if( page >= 0 )
289 m_notebook->ChangeSelection( static_cast<unsigned>( page ) );
290#endif
291}
wxBitmapBundle KiBitmapBundleDef(BITMAPS aBitmap, int aDefHeight)
Constructs and returns a bitmap bundle for the given icon ID, with the default bitmap size being aDef...
Definition bitmap.cpp:112
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:100
@ icon_kicad_nightly
@ color_materials
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:41
A contributor, a person which was involved in the development of the application or which has contrib...
Definition aboutinfo.h:153
wxString & GetName()
Definition aboutinfo.h:166
wxString & GetUrl()
Definition aboutinfo.h:167
wxString & GetCategory()
Definition aboutinfo.h:168
bool IsChecked()
Definition aboutinfo.h:170
void SetChecked(bool status)
Definition aboutinfo.h:169
wxStaticText * m_staticTextBuildVersion
wxStaticBitmap * m_bitmapApp
DIALOG_ABOUT_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("About"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(570, 500), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxStaticText * m_staticTextLibVersion
wxButton * m_btCopyVersionInfo
wxNotebook * m_notebook
wxStaticText * m_staticTextAppTitle
void OnNotebookPageChanged(wxNotebookEvent &aEvent) override
wxString m_titleName
wxImageList * m_images
wxString m_untranslatedTitleName
void createNotebooks()
ABOUT_APP_INFO & m_info
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
wxString GetAboutTitle() const
Add dark theme support to wxHtmlWindow.
Definition html_window.h:31
bool SetPage(const wxString &aSource) override
Master controller class:
IMAGES
@ TRANSLATORS
@ INFORMATION
#define _(s)
Base window classes and related definitions.