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
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();
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 & 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.