KiCad PCB EDA Suite
panel_packages_view.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) 2021 Andrew Lutsenko, anlutsenko at gmail dot com
5 * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "panel_packages_view.h"
22#include <grid_tricks.h>
23#include <html_window.h>
24#include <pgm_base.h>
25#include <kiplatform/ui.h>
29#include <string_utils.h>
30#include <widgets/wx_panel.h>
32
33#include <cmath>
34#include <fstream>
35#include <wx/filedlg.h>
36#include <wx/font.h>
37#include <wx/tokenzr.h>
38
39
40#define GRID_CELL_MARGIN 4
41
42
43std::unordered_map<PCM_PACKAGE_VERSION_STATUS, wxString> PANEL_PACKAGES_VIEW::STATUS_ENUM_TO_STR = {
44 { PVS_INVALID, "invalid" },
45 { PVS_STABLE, "stable" },
46 { PVS_TESTING, "testing" },
47 { PVS_DEVELOPMENT, "development" },
48 { PVS_DEPRECATED, "deprecated" }
49};
50
51
53 std::shared_ptr<PLUGIN_CONTENT_MANAGER> aPcm,
54 const ActionCallback& aActionCallback,
55 const PinCallback& aPinCallback ) :
57 m_actionCallback( aActionCallback ),
58 m_pinCallback( aPinCallback ),
59 m_pcm( aPcm )
60{
61 // Replace wxFormBuilder's sash initializer with one which will respect m_initialSashPos.
62 m_splitter1->Disconnect( wxEVT_IDLE,
64 NULL, this );
65 m_splitter1->Connect( wxEVT_IDLE, wxIdleEventHandler( PANEL_PACKAGES_VIEW::SetSashOnIdle ),
66 NULL, this );
67
68 m_splitter1->SetPaneMinimums( 350, 450 );
69
70#ifdef __WXGTK__
71 // wxSearchCtrl vertical height is not calculated correctly on some GTK setups
72 // See https://gitlab.com/kicad/code/kicad/-/issues/9019
73 m_searchCtrl->SetMinSize( wxSize( -1, GetTextExtent( wxT( "qb" ) ).y + 10 ) );
74#endif
75
77 m_searchCtrl->SetDescriptiveText( _( "Filter" ) );
78
79 m_panelList->SetBorders( false, true, false, false );
80
81 m_gridVersions->PushEventHandler( new GRID_TRICKS( m_gridVersions ) );
82
83 for( int col = 0; col < m_gridVersions->GetNumberCols(); col++ )
84 {
85 const wxString& heading = m_gridVersions->GetColLabelValue( col );
86 int headingWidth = GetTextExtent( heading ).x + 2 * GRID_CELL_MARGIN;
87
88 // Set the minimal width to the column label size.
89 m_gridVersions->SetColMinimalWidth( col, headingWidth );
90 m_gridVersions->SetColSize( col, m_gridVersions->GetVisibleWidth( col ) );
91 }
92
93 // Most likely should be changed to wxGridSelectNone once WxWidgets>=3.1.5 is mandatory.
94 m_gridVersions->SetSelectionMode( WX_GRID::wxGridSelectRows );
95
96 wxColor background = wxStaticText::GetClassDefaultAttributes().colBg;
97 m_panelList->SetBackgroundColour( background );
98 m_packageListWindow->SetBackgroundColour( background );
99 m_infoScrollWindow->SetBackgroundColour( background );
100 m_infoScrollWindow->EnableScrolling( false, true );
101
102 ClearData();
103}
104
105
107{
108 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
109 cfg->m_PackageManager.sash_pos = m_splitter1->GetSashPosition();
110
111 m_gridVersions->PopEventHandler( true );
112}
113
114
116{
118
119 m_currentSelected = nullptr;
120 m_updateablePackages.clear();
121 m_packagePanels.clear();
122 m_packageInitialOrder.clear();
123 m_packageListWindow->GetSizer()->Clear( true ); // Delete panels
124 m_packageListWindow->GetSizer()->FitInside( m_packageListWindow );
125 m_packageListWindow->Layout();
126}
127
128
129void PANEL_PACKAGES_VIEW::SetData( const std::vector<PACKAGE_VIEW_DATA>& aPackageData )
130{
131 ClearData();
132
133 for( const PACKAGE_VIEW_DATA& data : aPackageData )
134 {
136 m_pinCallback, data );
137
138 package_panel->SetSelectCallback(
139 [package_panel, this] ()
140 {
141 if( m_currentSelected && m_currentSelected != package_panel )
143
144 package_panel->SetSelected( true );
145 m_currentSelected = package_panel;
146 setPackageDetails( package_panel->GetPackageData() );
147
148 Layout();
149 } );
150
151 m_packagePanels.insert( { data.package.identifier, package_panel } );
152 m_packageInitialOrder.push_back( data.package.identifier );
153
154 if( data.state == PPS_UPDATE_AVAILABLE && !data.pinned )
155 m_updateablePackages.insert( data.package.identifier );
156 }
157
160}
161
162
164{
165 const PCM_PACKAGE& package = aPackageData.package;
166
167 // Details
168 wxString details;
169
170 details << wxT( "<h5>" ) + package.name + wxT( "</h5>" );
171
172 auto format_desc =
173 []( const wxString& text ) -> wxString
174 {
175 wxString result;
176 bool inURL = false;
177 wxString url;
178
179 for( unsigned i = 0; i < text.length(); ++i )
180 {
181 wxUniChar c = text[i];
182
183 if( inURL )
184 {
185 if( c == ' ' )
186 {
187 result += wxString::Format( wxT( "<a href='%s'>%s</a>" ), url, url );
188 inURL = false;
189
190 result += c;
191 }
192 else
193 {
194 url += c;
195 }
196 }
197 else if( text.Mid( i, 5 ) == wxT( "http:" )
198 || text.Mid( i, 6 ) == wxT( "https:" ) )
199 {
200 url = c;
201 inURL = true;
202 }
203 else if( c == '\n' )
204 {
205 result += wxT( "</p><p>" );
206 }
207 else
208 {
209 result += c;
210 }
211 }
212
213 return result;
214 };
215
216 wxString desc = package.description_full;
217 details << wxT( "<p>" ) + format_desc( desc ) + wxT( "</p>" );
218
219 details << wxT( "<p><b>" ) + _( "Metadata" ) + wxT( "</b></p>" );
220 details << wxT( "<ul>" );
221 details << wxT( "<li>" ) + _( "Package identifier: " ) + package.identifier + wxT( "</li>" );
222 details << wxT( "<li>" ) + _( "License: " ) + package.license + wxT( "</li>" );
223
224 if( package.tags.size() > 0 )
225 {
226 wxString tags_str;
227
228 for( const std::string& tag : package.tags )
229 {
230 if( !tags_str.IsEmpty() )
231 tags_str += ", ";
232
233 tags_str += tag;
234 }
235
236 details << wxT( "<li>" ) + _( "Tags: " ) + tags_str + wxT( "</li>" );
237 }
238
239 auto format_entry =
240 []( const std::pair<const std::string, wxString>& entry ) -> wxString
241 {
242 wxString name = entry.first;
243 wxString url = EscapeHTML( entry.second );
244
245 if( name == wxT( "email" ) )
246 return wxString::Format( wxT( "<a href='mailto:%s'>%s</a>" ), url, url );
247 else if( url.StartsWith( wxT( "http:" ) ) || url.StartsWith( wxT( "https:" ) ) )
248 return wxString::Format( wxT( "<a href='%s'>%s</a>" ), url, url );
249 else
250 return entry.second;
251 };
252
253 auto write_contact =
254 [&]( const wxString& type, const PCM_CONTACT& contact )
255 {
256 details << wxT( "<li>" ) + type + wxT( ": " ) + contact.name + wxT( "<ul>" );
257
258 for( const std::pair<const std::string, wxString>& entry : contact.contact )
259 {
260 details << wxT( "<li>" );
261 details << entry.first + wxT( ": " ) + format_entry( entry );
262 details << wxT( "</li>" );
263 }
264
265 details << wxT( "</ul>" );
266 };
267
268 write_contact( _( "Author" ), package.author );
269
270 if( package.maintainer )
271 write_contact( _( "Maintainer" ), *package.maintainer );
272
273 if( package.resources.size() > 0 )
274 {
275 details << wxT( "<li>" ) + _( "Resources" ) + wxT( "<ul>" );
276
277 for( const std::pair<const std::string, wxString>& entry : package.resources )
278 {
279 details << wxT( "<li>" );
280 details << entry.first + wxT( ": " );
281 details << format_entry( entry ) + wxT( "</li>" );
282 }
283
284 details << wxT( "</ul>" );
285 }
286
287 details << wxT( "</ul>" );
288
289 m_infoText->SetPage( details );
290
291 wxSizeEvent dummy;
293
294 // Versions table
295 m_gridVersions->Freeze();
296
297 if( m_gridVersions->GetNumberRows() != 0 )
298 m_gridVersions->DeleteRows( 0, m_gridVersions->GetNumberRows() );
299
300 int row = 0;
301 wxString current_version;
302
303 if( aPackageData.state == PPS_INSTALLED || aPackageData.state == PPS_UPDATE_AVAILABLE )
304 current_version = m_pcm->GetInstalledPackageVersion( package.identifier );
305
306 wxFont bold_font = m_gridVersions->GetDefaultCellFont().Bold();
307
308 for( const PACKAGE_VERSION& version : package.versions )
309 {
310 if( !version.compatible && !m_showAllVersions->IsChecked() )
311 continue;
312
313 m_gridVersions->InsertRows( row );
314
315 m_gridVersions->SetCellValue( row, COL_VERSION, version.version );
316 m_gridVersions->SetCellValue( row, COL_DOWNLOAD_SIZE,
318 m_gridVersions->SetCellValue( row, COL_INSTALL_SIZE,
320 m_gridVersions->SetCellValue( row, COL_COMPATIBILITY,
321 version.compatible ? wxT( "\u2714" ) : wxEmptyString );
322 m_gridVersions->SetCellValue( row, COL_STATUS, STATUS_ENUM_TO_STR.at( version.status ) );
323
324 m_gridVersions->SetCellAlignment( row, COL_COMPATIBILITY, wxALIGN_CENTER, wxALIGN_CENTER );
325
326 if( current_version == version.version )
327 {
328 for( int col = 0; col < m_gridVersions->GetNumberCols(); col++ )
329 m_gridVersions->SetCellFont( row, col, bold_font );
330 }
331
332 row++;
333 }
334
335 for( int col = 0; col < m_gridVersions->GetNumberCols(); col++ )
336 {
337 // Set the width to see the full contents
338 m_gridVersions->SetColSize( col, m_gridVersions->GetVisibleWidth( col ) );
339 }
340
341 // Autoselect preferred or installed version
342 if( m_gridVersions->GetNumberRows() >= 1 )
343 {
345
346 if( version.IsEmpty() )
348
349 if( !version.IsEmpty() )
350 {
351 for( int i = 0; i < m_gridVersions->GetNumberRows(); i++ )
352 {
353 if( m_gridVersions->GetCellValue( i, COL_VERSION ) == version )
354 {
355 m_gridVersions->SelectRow( i );
356 m_gridVersions->SetGridCursor( i, COL_VERSION );
357 break;
358 }
359 }
360 }
361 else
362 {
363 // Fall back to first row.
364 m_gridVersions->SelectRow( 0 );
365 }
366 }
367
368 m_gridVersions->Thaw();
369
371
372 m_infoText->Show( true );
373 m_sizerVersions->Show( true );
374 m_sizerVersions->Layout();
375
376 wxSize size = m_infoScrollWindow->GetTargetWindow()->GetBestVirtualSize();
377 m_infoScrollWindow->SetVirtualSize( size );
378}
379
380
382{
383 m_infoText->SetPage( wxEmptyString );
384 m_infoText->Show( false );
385 m_sizerVersions->Show( false );
386
387 wxSize size = m_infoScrollWindow->GetTargetWindow()->GetBestVirtualSize();
388 m_infoScrollWindow->SetVirtualSize( size );
389
390 // Clean up grid just so we don't keep stale info around (it's already been hidden).
391 m_gridVersions->Freeze();
392
393 if( m_gridVersions->GetNumberRows() > 0 )
394 m_gridVersions->DeleteRows( 0, m_gridVersions->GetNumberRows() );
395
396 m_gridVersions->Thaw();
397}
398
399
400wxString PANEL_PACKAGES_VIEW::toHumanReadableSize( const std::optional<uint64_t> size ) const
401{
402 if( !size )
403 return wxT( "-" );
404
405 uint64_t b = *size;
406
407 if( b >= 1024 * 1024 )
408 return wxString::Format( wxT( "%.1f MB" ), b / 1000.0 / 1000.0 );
409
410 if( b >= 1024 )
411 return wxString::Format( wxT( "%lld kB" ), b / 1000 );
412
413 return wxString::Format( wxT( "%lld B" ), b );
414}
415
416
418{
419 if( !m_currentSelected )
420 return false;
421
422 return m_gridVersions->GetNumberRows() == 1 || m_gridVersions->GetSelectedRows().size() == 1;
423}
424
425
427{
428 if( !m_currentSelected )
429 return false;
430
431 const PACKAGE_VIEW_DATA& packageData = m_currentSelected->GetPackageData();
432
433 switch( packageData.state )
434 {
437 case PPS_PENDING_UPDATE: return false;
438 default: break;
439 }
440
441 return m_gridVersions->GetNumberRows() == 1 || m_gridVersions->GetSelectedRows().size() == 1;
442}
443
444
445void PANEL_PACKAGES_VIEW::SetPackageState( const wxString& aPackageId,
446 const PCM_PACKAGE_STATE aState, const bool aPinned )
447{
448 auto it = m_packagePanels.find( aPackageId );
449
450 if( it != m_packagePanels.end() )
451 {
452 it->second->SetState( aState, aPinned );
453
454 if( m_currentSelected && m_currentSelected == it->second )
455 {
456 wxMouseEvent dummy;
458 }
459
460 if( aState == PPS_UPDATE_AVAILABLE && !aPinned )
461 {
462 m_updateablePackages.insert( aPackageId );
463 }
464 else
465 {
466 m_updateablePackages.erase( aPackageId );
467 }
468
470 }
471}
472
473
475{
476 m_gridVersions->ClearSelection();
477 m_gridVersions->SelectRow( event.GetRow() );
478
480}
481
482
484{
485 if( !canDownload() )
486 {
487 wxBell();
488 return;
489 }
490
491 if( m_gridVersions->GetNumberRows() == 1 )
492 m_gridVersions->SelectRow( 0 );
493
494 const wxArrayInt selectedRows = m_gridVersions->GetSelectedRows();
495
496 wxString version = m_gridVersions->GetCellValue( selectedRows[0], COL_VERSION );
497 const PCM_PACKAGE& package = m_currentSelected->GetPackageData().package;
498
499 auto ver_it = std::find_if( package.versions.begin(), package.versions.end(),
500 [&]( const PACKAGE_VERSION& ver )
501 {
502 return ver.version == version;
503 } );
504
505 wxASSERT_MSG( ver_it != package.versions.end(), "Could not find package version" );
506
507 if( !ver_it->download_url )
508 {
509 wxMessageBox( _( "Package download url is not specified" ),
510 _( "Error downloading package" ), wxICON_INFORMATION | wxOK, this );
511 return;
512 }
513
514 const wxString& url = *ver_it->download_url;
515
516 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
517 KICAD_SETTINGS* app_settings = mgr.GetAppSettings<KICAD_SETTINGS>();
518
519 wxFileDialog dialog( this, _( "Save package" ), app_settings->m_PcmLastDownloadDir,
520 wxString::Format( wxT( "%s_v%s.zip" ), package.identifier, version ),
521 wxT( "ZIP files (*.zip)|*.zip" ), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
522
523 if( dialog.ShowModal() == wxID_CANCEL )
524 return;
525
526 wxString path = dialog.GetPath();
527 app_settings->m_PcmLastDownloadDir = wxPathOnly( path );
528
529 std::ofstream output( path.ToUTF8(), std::ios_base::binary );
530
531 std::unique_ptr<WX_PROGRESS_REPORTER> reporter =
532 std::make_unique<WX_PROGRESS_REPORTER>( this, _( "Downloading package" ), 1 );
533
534 bool success = m_pcm->DownloadToStream( url, &output, reporter.get(), 0 );
535
536 output.close();
537
538 if( success )
539 {
540 if( ver_it->download_sha256 )
541 {
542 std::ifstream stream( path.ToUTF8(), std::ios_base::binary );
543
544 bool matches = m_pcm->VerifyHash( stream, *ver_it->download_sha256 );
545
546 stream.close();
547
548 if( !matches
549 && wxMessageBox(
550 _( "Integrity of the downloaded package could not be verified, hash "
551 "does not match. Are you sure you want to keep this file?" ),
552 _( "Keep downloaded file" ), wxICON_EXCLAMATION | wxYES_NO, this )
553 == wxNO )
554 {
555 wxRemoveFile( path );
556 }
557 }
558 }
559 else
560 {
561 if( wxFileExists( path ) )
562 wxRemoveFile( path );
563 }
564}
565
566
568{
569 if( !canRunAction() )
570 {
571 wxBell();
572 return;
573 }
574
575 PCM_PACKAGE_ACTION action = getAction();
576
577 if( action == PPA_UNINSTALL )
578 {
581 return;
582 }
583
584 if( m_gridVersions->GetNumberRows() == 1 )
585 m_gridVersions->SelectRow( 0 );
586
587 const wxArrayInt selectedRows = m_gridVersions->GetSelectedRows();
588
589 wxString version = m_gridVersions->GetCellValue( selectedRows[0], COL_VERSION );
590 const PCM_PACKAGE& package = m_currentSelected->GetPackageData().package;
591
592 auto ver_it = std::find_if( package.versions.begin(), package.versions.end(),
593 [&]( const PACKAGE_VERSION& ver )
594 {
595 return ver.version == version;
596 } );
597
598 wxCHECK_RET( ver_it != package.versions.end(), "Could not find package version" );
599
600 if( !ver_it->compatible
601 && wxMessageBox( _( "This package version is incompatible with your kicad version or "
602 "platform. Are you sure you want to install it anyway?" ),
603 _( "Install package" ), wxICON_EXCLAMATION | wxYES_NO, this )
604 == wxNO )
605 {
606 return;
607 }
608
610}
611
612
614{
616 {
617 wxMouseEvent dummy;
619 }
620
622}
623
624
625void PANEL_PACKAGES_VIEW::OnSearchTextChanged( wxCommandEvent& event )
626{
628
631
632 m_currentSelected = nullptr;
633
635}
636
637
639{
640 // Sort by descending rank, ascending index
641 std::vector<std::pair<int, int>> package_ranks;
642
643 const wxString search_term = m_searchCtrl->GetValue().Trim();
644
645 for( size_t index = 0; index < m_packageInitialOrder.size(); index++ )
646 {
647 int rank = 1;
648 const PCM_PACKAGE& pkg =
649 m_packagePanels[m_packageInitialOrder[index]]->GetPackageData().package;
650
651 if( search_term.size() > 2 )
652 rank = m_pcm->GetPackageSearchRank( pkg, search_term );
653
654 // Packages with no versions are delisted and should not be shown
655 if( pkg.versions.size() == 0 )
656 rank = 0;
657
658 package_ranks.emplace_back( rank, index );
659 }
660
661 std::sort( package_ranks.begin(), package_ranks.end(),
662 []( const std::pair<int, int>& a, const std::pair<int, int>& b )
663 {
664 return a.first > b.first || ( a.first == b.first && a.second < b.second );
665 } );
666
667 // Rearrange panels, hide ones with 0 rank
668 wxSizer* sizer = m_packageListWindow->GetSizer();
669 sizer->Clear( false ); // Don't delete panels
670
671 for( const std::pair<int, int>& pair : package_ranks )
672 {
674
675 if( pair.first > 0 )
676 {
677 sizer->Add( panel, 0, wxEXPAND );
678 panel->Show();
679 }
680 else
681 {
682 panel->Hide();
683 }
684 }
685
686 m_packageListWindow->FitInside();
687 m_packageListWindow->SetScrollRate( 0, 15 );
688 m_packageListWindow->SendSizeEvent( wxSEND_EVENT_POST );
689}
690
691
693{
694 m_buttonDownload->Enable( canDownload() );
695
696 if( canRunAction() )
697 {
698 m_buttonAction->Enable();
699
700 PCM_PACKAGE_ACTION action = getAction();
701
702 switch( action )
703 {
704 case PPA_INSTALL: m_buttonAction->SetLabel( _( "Install" ) ); break;
705 case PPA_UNINSTALL: m_buttonAction->SetLabel( _( "Uninstall" ) ); break;
706 case PPA_UPDATE: m_buttonAction->SetLabel( _( "Update" ) ); break;
707 }
708 }
709 else
710 {
711 m_buttonAction->Disable();
712 m_buttonAction->SetLabel( _( "Pending" ) );
713 }
714}
715
716
718{
719 wxASSERT_MSG( m_gridVersions->GetNumberRows() == 1
720 || m_gridVersions->GetSelectedRows().size() == 1,
721 wxT( "getAction() called with ambiguous version selection" ) );
722
723 int selected_row = 0;
724
725 if( m_gridVersions->GetSelectedRows().size() == 1 )
726 selected_row = m_gridVersions->GetSelectedRows()[0];
727
728 wxString version = m_gridVersions->GetCellValue( selected_row, COL_VERSION );
729 const PACKAGE_VIEW_DATA& package = m_currentSelected->GetPackageData();
730
731 switch( package.state )
732 {
733 case PPS_AVAILABLE:
734 case PPS_UNAVAILABLE:
735 return PPA_INSTALL; // Only action for not installed package is to install it
736 case PPS_INSTALLED:
738 if( version == package.current_version )
739 return PPA_UNINSTALL;
740 else
741 return PPA_UPDATE;
742 default:
743 return PPA_INSTALL; // For pending states return value does not matter as button will be disabled
744 }
745}
746
747
748void PANEL_PACKAGES_VIEW::OnSizeInfoBox( wxSizeEvent& aEvent )
749{
750 wxSize infoSize = KIPLATFORM::UI::GetUnobscuredSize( m_infoText->GetParent() );
751 infoSize.x -= 10;
752 m_infoText->SetMinSize( infoSize );
753 m_infoText->SetMaxSize( infoSize );
754 m_infoText->SetSize( infoSize );
755 m_infoText->Layout();
756
757 infoSize.y = m_infoText->GetInternalRepresentation()->GetHeight() + 12;
758 m_infoText->SetMinSize( infoSize );
759 m_infoText->SetMaxSize( infoSize );
760 m_infoText->SetSize( infoSize );
761 m_infoText->Layout();
762
763 Refresh();
764}
765
766
767void PANEL_PACKAGES_VIEW::OnURLClicked( wxHtmlLinkEvent& aEvent )
768{
769 const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
770 ::wxLaunchDefaultBrowser( info.GetHref() );
771}
772
773
774void PANEL_PACKAGES_VIEW::OnInfoMouseWheel( wxMouseEvent& event )
775{
776 // Transfer scrolling from the info window to its parent scroll window
777 m_infoScrollWindow->HandleOnMouseWheel( event );
778}
779
780
781void PANEL_PACKAGES_VIEW::SetSashOnIdle( wxIdleEvent& aEvent )
782{
783 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
784 m_splitter1->SetSashPosition( cfg->m_PackageManager.sash_pos );
785
786 m_packageListWindow->FitInside();
787
788 m_splitter1->Disconnect( wxEVT_IDLE, wxIdleEventHandler( PANEL_PACKAGES_VIEW::SetSashOnIdle ),
789 NULL, this );
790}
791
792
794{
795 m_buttonUpdateAll->Enable( m_updateablePackages.size() > 0 );
796}
797
798
799void PANEL_PACKAGES_VIEW::OnUpdateAllClicked( wxCommandEvent& event )
800{
801 // The map will be modified by the callback so we copy the list here
802 std::vector<wxString> packages;
803
804 std::copy( m_updateablePackages.begin(), m_updateablePackages.end(),
805 std::back_inserter( packages ) );
806
807 for( const wxString& pkg_id : packages )
808 {
809 auto it = m_packagePanels.find( pkg_id );
810
811 if( it != m_packagePanels.end() )
812 {
813 const PACKAGE_VIEW_DATA& data = it->second->GetPackageData();
814
816 }
817 }
818}
const char * name
Definition: DXF_plotter.cpp:56
PACKAGE_MANAGER m_PackageManager
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
bool SetPage(const wxString &aSource) override
Definition: html_window.cpp:38
wxString m_PcmLastDownloadDir
Class PANEL_PACKAGES_VIEW_BASE.
WX_SPLITTER_WINDOW * m_splitter1
wxScrolledWindow * m_packageListWindow
void m_splitter1OnIdle(wxIdleEvent &)
wxScrolledWindow * m_infoScrollWindow
void OnInfoMouseWheel(wxMouseEvent &event) override
Replacement of wxFormBuilder's ill-advised m_splitter1OnIdle.
std::unordered_set< wxString > m_updateablePackages
void OnUpdateAllClicked(wxCommandEvent &event) override
void ClearData()
Selects full row of the clicked cell.
void updateDetailsButtons()
Called when package state changes, currently used to calculate Update All button state.
void OnVersionActionClicked(wxCommandEvent &event) override
Shows all versions including incompatible ones.
void OnSizeInfoBox(wxSizeEvent &aEvent) override
Respond to a URL in the info window.
bool canDownload() const
Returns true if the package action can be performed.
void OnDownloadVersionClicked(wxCommandEvent &event) override
Schedules relevant action for selected package version.
wxString toHumanReadableSize(const std::optional< uint64_t > size) const
Returns true if it the download operation can be performed.
void OnSearchTextChanged(wxCommandEvent &event)
void updateCommonState()
Updates details panel.
void updatePackageList()
< Updates package listing according to search term
const ActionCallback & m_actionCallback
std::unordered_map< wxString, PANEL_PACKAGE * > m_packagePanels
void setPackageDetails(const PACKAGE_VIEW_DATA &aPackageData)
Clears details panel.
const PinCallback & m_pinCallback
std::shared_ptr< PLUGIN_CONTENT_MANAGER > m_pcm
PCM_PACKAGE_ACTION getAction() const
bool canRunAction() const
Returns implied action for the action button.
PANEL_PACKAGE * m_currentSelected
void unsetPackageDetails()
Bytes to Kb/Mb/Gb string or "-" if absent.
void SetData(const std::vector< PACKAGE_VIEW_DATA > &aPackageData)
Recreates package panels and displays data.
void OnVersionsCellClicked(wxGridEvent &event) override
Opens file chooser dialog and downloads selected package version archive.
void OnURLClicked(wxHtmlLinkEvent &event) override
Respond to scrolling over the window.
void SetSashOnIdle(wxIdleEvent &)
Enqueues all available package updates.
static std::unordered_map< PCM_PACKAGE_VERSION_STATUS, wxString > STATUS_ENUM_TO_STR
void SetPackageState(const wxString &aPackageId, const PCM_PACKAGE_STATE aState, const bool aPinned)
Set the state of package.
std::vector< wxString > m_packageInitialOrder
PANEL_PACKAGES_VIEW(wxWindow *parent, std::shared_ptr< PLUGIN_CONTENT_MANAGER > aPcm, const ActionCallback &aCallback, const PinCallback &aPinCallback)
void OnShowAllVersionsClicked(wxCommandEvent &event) override
Ranks packages for entered search term and rearranges/hides panels according to their rank.
void OnClick(wxMouseEvent &event) override
const PACKAGE_VIEW_DATA & GetPackageData() const
Definition: panel_package.h:92
void SetSelected(bool aSelected)
void SetSelectCallback(const std::function< void()> &aCallback)
Marks panel as selected.
wxString GetPreferredVersion() const
T * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=true, bool aKeep=false)
Calculates the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:377
void SetBorders(bool aLeft, bool aRight, bool aTop, bool aBottom)
Definition: wx_panel.h:38
void SetPaneMinimums(int aFirst, int aSecond)
#define _(s)
wxSize GetUnobscuredSize(const wxWindow *aWindow)
Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl,...
Definition: gtk/ui.cpp:126
std::function< void(const wxString &aPackageId, const PCM_PACKAGE_STATE aState, const bool aPinned)> PinCallback
Definition: panel_package.h:60
std::function< void(const PACKAGE_VIEW_DATA &aData, PCM_PACKAGE_ACTION aAction, const wxString &aVersion)> ActionCallback
Definition: panel_package.h:57
#define GRID_CELL_MARGIN
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
PCM_PACKAGE_STATE
Definition: pcm.h:55
@ PPS_INSTALLED
Definition: pcm.h:58
@ PPS_PENDING_UPDATE
Definition: pcm.h:62
@ PPS_UNAVAILABLE
Definition: pcm.h:57
@ PPS_UPDATE_AVAILABLE
Definition: pcm.h:61
@ PPS_PENDING_UNINSTALL
Definition: pcm.h:60
@ PPS_PENDING_INSTALL
Definition: pcm.h:59
@ PPS_AVAILABLE
Definition: pcm.h:56
PCM_PACKAGE_ACTION
Definition: pcm.h:68
@ PPA_UNINSTALL
Definition: pcm.h:70
@ PPA_UPDATE
Definition: pcm.h:71
@ PPA_INSTALL
Definition: pcm.h:69
@ PVS_INVALID
Definition: pcm_data.h:52
@ PVS_DEVELOPMENT
Definition: pcm_data.h:55
@ PVS_STABLE
Definition: pcm_data.h:53
@ PVS_TESTING
Definition: pcm_data.h:54
@ PVS_DEPRECATED
Definition: pcm_data.h:56
see class PGM_BASE
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:74
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
wxString EscapeHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
< Package version metadata Package metadata
Definition: pcm_data.h:74
std::optional< uint64_t > download_size
Definition: pcm_data.h:79
bool compatible
Definition: pcm_data.h:89
std::optional< uint64_t > install_size
Definition: pcm_data.h:80
wxString version
Definition: pcm_data.h:75
PCM_PACKAGE_VERSION_STATUS status
Definition: pcm_data.h:81
< Collection of data relevant to the package display panel Callback for (un)install button
Definition: panel_package.h:31
wxString update_version
Definition: panel_package.h:39
wxString current_version
Definition: panel_package.h:38
PCM_PACKAGE_STATE state
Definition: panel_package.h:34
Repository reference to a resource.
Definition: pcm_data.h:95
wxString name
Definition: pcm_data.h:96
std::vector< PACKAGE_VERSION > versions
Definition: pcm_data.h:107