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 // dpi fixes
60 m_notebook->SetMinSize( FromDIP( m_notebook->GetMinSize() ) );
61
62 SetEvtHandlerEnabled( false );
63
64 const int c_iconSize = 16;
65 wxVector<wxBitmapBundle> images;
66
67 images.push_back( KiBitmapBundleDef( BITMAPS::info, c_iconSize ) ); // INFORMATION
68 images.push_back( KiBitmapBundleDef( BITMAPS::recent, c_iconSize ) ); // VERSION
69 images.push_back( KiBitmapBundleDef( BITMAPS::preference, c_iconSize ) ); // DEVELOPERS
70 images.push_back( KiBitmapBundleDef( BITMAPS::editor, c_iconSize ) ); // DOCWRITERS
71 images.push_back( KiBitmapBundleDef( BITMAPS::library, c_iconSize ) ); // LIBRARIANS
72 images.push_back( KiBitmapBundleDef( BITMAPS::color_materials, c_iconSize ) ); // ARTISTS
73 images.push_back( KiBitmapBundleDef( BITMAPS::language, c_iconSize ) ); // TRANSLATORS
74 images.push_back( KiBitmapBundleDef( BITMAPS::zip, c_iconSize ) ); // PACKAGERS
75 images.push_back( KiBitmapBundleDef( BITMAPS::tools, c_iconSize ) ); // LICENSE
76
77 m_notebook->SetImages( images );
78
79 if( m_info.GetAppIcon().IsOk() )
80 {
81 SetIcon( m_info.GetAppIcon() );
82 m_bitmapApp->SetBitmap( m_info.GetAppIcon() );
83 }
84 else
85 {
86 wxIcon icon;
87
88 if( IsNightlyVersion() )
89 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly ) );
90 else
91 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad ) );
92
93 SetIcon( icon );
94 m_bitmapApp->SetBitmap( icon );
95 }
96
97 m_titleName = aParent->GetAboutTitle();
100
101 // On windows, display the number of GDI objects in use. Can be useful when some GDI objects
102 // are not displayed because the max count of GDI objects (usually 10000) is reached
103 // So displaying this number can help to diagnose strange display issues
104 wxString extraInfo;
105
106 #if defined( _WIN32 )
107 uint32_t gdi_count = GetGuiResources( GetCurrentProcess(), GR_GDIOBJECTS );
108 extraInfo.Printf( _( "GDI objects in use %u" ), gdi_count );
109 extraInfo.Prepend( wxT( "\n" ) );
110 #endif
111
112 m_staticTextBuildVersion->SetLabel( wxS( "Version: " ) + m_info.GetBuildVersion() );
113 m_staticTextLibVersion->SetLabel( m_info.GetLibVersion() + extraInfo );
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{
136 m_info.GetDescription() );
137
138 wxString version = GetVersionInfoData( m_untranslatedTitleName, true );
139
140 createNotebookHtmlPage( m_notebook, _( "Version" ), IMAGES::VERSION, version, true );
141
143 m_info.GetDevelopers() );
145 m_info.GetDocWriters() );
146
148 m_info.GetLibrarians() );
149
151 m_info.GetArtists() );
153 m_info.GetTranslators() );
155 m_info.GetPackagers() );
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 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:116
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
@ 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:45
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
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:35
bool SetPage(const wxString &aSource) override
Master controller class:
IMAGES
@ TRANSLATORS
@ INFORMATION
#define _(s)
Base window classes and related definitions.