KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2024 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 <widgets/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, wxS( "invalid" ) },
45 { PVS_STABLE, wxS( "stable" ) },
46 { PVS_TESTING, wxS( "testing" ) },
47 { PVS_DEVELOPMENT, wxS( "development" ) },
48 { PVS_DEPRECATED, wxS( "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( FromDIP( 350 ), FromDIP( 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 m_splitter1->Disconnect( wxEVT_IDLE, wxIdleEventHandler( PANEL_PACKAGES_VIEW::SetSashOnIdle ),
109 NULL, this );
110
111 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
112 cfg->m_PackageManager.sash_pos = m_splitter1->GetSashPosition();
113
114 m_gridVersions->PopEventHandler( true );
115}
116
117
119{
121
122 m_currentSelected = nullptr;
123 m_updateablePackages.clear();
124 m_packagePanels.clear();
125 m_packageInitialOrder.clear();
126 m_packageListWindow->GetSizer()->Clear( true ); // Delete panels
127 m_packageListWindow->GetSizer()->FitInside( m_packageListWindow );
128 m_packageListWindow->Layout();
129}
130
131
132void PANEL_PACKAGES_VIEW::SetData( const std::vector<PACKAGE_VIEW_DATA>& aPackageData )
133{
134 ClearData();
135
136 for( const PACKAGE_VIEW_DATA& data : aPackageData )
137 {
139 m_pinCallback, data );
140
141 package_panel->SetSelectCallback(
142 [package_panel, this] ()
143 {
144 if( m_currentSelected && m_currentSelected != package_panel )
146
147 package_panel->SetSelected( true );
148 m_currentSelected = package_panel;
149 setPackageDetails( package_panel->GetPackageData() );
150
151 Layout();
152 } );
153
154 m_packagePanels.insert( { data.package.identifier, package_panel } );
155 m_packageInitialOrder.push_back( data.package.identifier );
156
157 if( data.state == PPS_UPDATE_AVAILABLE && !data.pinned )
158 m_updateablePackages.insert( data.package.identifier );
159 }
160
163}
164
165
167{
168 const PCM_PACKAGE& package = aPackageData.package;
169
170 // Details
171 wxString details;
172
173 details << wxT( "<h5>" ) + package.name + wxT( "</h5>" );
174
175 auto format_desc =
176 []( const wxString& text ) -> wxString
177 {
178 wxString result;
179 bool inURL = false;
180 wxString url;
181
182 for( unsigned i = 0; i < text.length(); ++i )
183 {
184 wxUniChar c = text[i];
185
186 if( inURL )
187 {
188 if( c == ' ' || c == '\n')
189 {
190 result += wxString::Format( wxT( "<a href='%s'>%s</a>" ), url, url );
191 inURL = false;
192
193 if( c == '\n' )
194 result += wxT( "</p><p>" );
195 else
196 result += c;
197 }
198 else
199 {
200 url += c;
201 }
202 }
203 else if( text.Mid( i, 5 ) == wxT( "http:" )
204 || text.Mid( i, 6 ) == wxT( "https:" ) )
205 {
206 url = c;
207 inURL = true;
208 }
209 else if( c == '\n' )
210 {
211 result += wxT( "</p><p>" );
212 }
213 else
214 {
215 result += c;
216 }
217 }
218
219 if( inURL )
220 result += wxString::Format( wxT( "<a href='%s'>%s</a>" ), url, url );
221
222 return result;
223 };
224
225 wxString desc = package.description_full;
226 details << wxT( "<p>" ) + format_desc( desc ) + wxT( "</p>" );
227
228 details << wxT( "<p><b>" ) + _( "Metadata" ) + wxT( "</b></p>" );
229 details << wxT( "<ul>" );
230 details << wxT( "<li>" ) + _( "Package identifier: " ) + package.identifier + wxT( "</li>" );
231 details << wxT( "<li>" ) + _( "License: " ) + package.license + wxT( "</li>" );
232
233 if( package.tags.size() > 0 )
234 {
235 wxString tags_str;
236
237 for( const std::string& tag : package.tags )
238 {
239 if( !tags_str.IsEmpty() )
240 tags_str += ", ";
241
242 tags_str += tag;
243 }
244
245 details << wxT( "<li>" ) + _( "Tags: " ) + tags_str + wxT( "</li>" );
246 }
247
248 auto format_entry =
249 []( const std::pair<const std::string, wxString>& entry ) -> wxString
250 {
251 wxString name = entry.first;
252 wxString url = EscapeHTML( entry.second );
253
254 if( name == wxT( "email" ) )
255 return wxString::Format( wxT( "<a href='mailto:%s'>%s</a>" ), url, url );
256 else if( url.StartsWith( wxT( "http:" ) ) || url.StartsWith( wxT( "https:" ) ) )
257 return wxString::Format( wxT( "<a href='%s'>%s</a>" ), url, url );
258 else
259 return entry.second;
260 };
261
262 auto write_contact =
263 [&]( const wxString& type, const PCM_CONTACT& contact )
264 {
265 details << wxT( "<li>" ) + type + wxT( ": " ) + contact.name + wxT( "<ul>" );
266
267 for( const std::pair<const std::string, wxString>& entry : contact.contact )
268 {
269 details << wxT( "<li>" );
270 details << entry.first + wxT( ": " ) + format_entry( entry );
271 details << wxT( "</li>" );
272 }
273
274 details << wxT( "</ul>" );
275 };
276
277 write_contact( _( "Author" ), package.author );
278
279 if( package.maintainer )
280 write_contact( _( "Maintainer" ), *package.maintainer );
281
282 if( package.resources.size() > 0 )
283 {
284 details << wxT( "<li>" ) + _( "Resources" ) + wxT( "<ul>" );
285
286 for( const std::pair<const std::string, wxString>& entry : package.resources )
287 {
288 details << wxT( "<li>" );
289 details << entry.first + wxT( ": " );
290 details << format_entry( entry ) + wxT( "</li>" );
291 }
292
293 details << wxT( "</ul>" );
294 }
295
296 details << wxT( "</ul>" );
297
298 m_infoText->SetPage( details );
299
300 wxSizeEvent dummy;
301 OnSizeInfoBox( dummy );
302
303 // Versions table
304 m_gridVersions->Freeze();
305
306 if( m_gridVersions->GetNumberRows() != 0 )
307 m_gridVersions->DeleteRows( 0, m_gridVersions->GetNumberRows() );
308
309 int row = 0;
310 wxString current_version;
311
312 if( aPackageData.state == PPS_INSTALLED || aPackageData.state == PPS_UPDATE_AVAILABLE )
313 current_version = m_pcm->GetInstalledPackageVersion( package.identifier );
314
315 wxFont bold_font = m_gridVersions->GetDefaultCellFont().Bold();
316
317 for( const PACKAGE_VERSION& version : package.versions )
318 {
319 if( !version.compatible && !m_showAllVersions->IsChecked() )
320 continue;
321
322 m_gridVersions->InsertRows( row );
323
324 m_gridVersions->SetCellValue( row, COL_VERSION, version.version );
325 m_gridVersions->SetCellValue( row, COL_DOWNLOAD_SIZE,
326 toHumanReadableSize( version.download_size ) );
327 m_gridVersions->SetCellValue( row, COL_INSTALL_SIZE,
328 toHumanReadableSize( version.install_size ) );
329 m_gridVersions->SetCellValue( row, COL_COMPATIBILITY,
330 version.compatible ? wxT( "\u2714" ) : wxEmptyString );
331 m_gridVersions->SetCellValue( row, COL_STATUS, STATUS_ENUM_TO_STR.at( version.status ) );
332
333 m_gridVersions->SetCellAlignment( row, COL_COMPATIBILITY, wxALIGN_CENTER, wxALIGN_CENTER );
334
335 if( current_version == version.version )
336 {
337 for( int col = 0; col < m_gridVersions->GetNumberCols(); col++ )
338 m_gridVersions->SetCellFont( row, col, bold_font );
339 }
340
341 row++;
342 }
343
344 for( int col = 0; col < m_gridVersions->GetNumberCols(); col++ )
345 {
346 // Set the width to see the full contents
347 m_gridVersions->SetColSize( col, m_gridVersions->GetVisibleWidth( col ) );
348 }
349
350 // Autoselect preferred or installed version
351 if( m_gridVersions->GetNumberRows() >= 1 )
352 {
353 wxString version = m_currentSelected->GetPackageData().current_version;
354
355 if( version.IsEmpty() )
356 version = m_currentSelected->GetPreferredVersion();
357
358 if( !version.IsEmpty() )
359 {
360 for( int i = 0; i < m_gridVersions->GetNumberRows(); i++ )
361 {
362 if( m_gridVersions->GetCellValue( i, COL_VERSION ) == version )
363 {
364 m_gridVersions->SelectRow( i );
365 m_gridVersions->SetGridCursor( i, COL_VERSION );
366 break;
367 }
368 }
369 }
370 else
371 {
372 // Fall back to first row.
373 m_gridVersions->SelectRow( 0 );
374 }
375 }
376
377 m_gridVersions->Thaw();
378
379 updateDetailsButtons();
380
381 m_infoText->Show( true );
382 m_sizerVersions->Show( true );
383 m_sizerVersions->Layout();
384
385 wxSize size = m_infoScrollWindow->GetTargetWindow()->GetBestVirtualSize();
386 m_infoScrollWindow->SetVirtualSize( size );
387}
388
389
391{
392 m_infoText->SetPage( wxEmptyString );
393 m_infoText->Show( false );
394 m_sizerVersions->Show( false );
395
396 wxSize size = m_infoScrollWindow->GetTargetWindow()->GetBestVirtualSize();
397 m_infoScrollWindow->SetVirtualSize( size );
398
399 // Clean up grid just so we don't keep stale info around (it's already been hidden).
400 m_gridVersions->Freeze();
401
402 if( m_gridVersions->GetNumberRows() > 0 )
403 m_gridVersions->DeleteRows( 0, m_gridVersions->GetNumberRows() );
404
405 m_gridVersions->Thaw();
406}
407
408
409wxString PANEL_PACKAGES_VIEW::toHumanReadableSize( const std::optional<uint64_t> size ) const
410{
411 if( !size )
412 return wxT( "-" );
413
414 uint64_t b = *size;
415
416 if( b >= 1024 * 1024 )
417 return wxString::Format( wxT( "%.1f MB" ), b / 1000.0 / 1000.0 );
418
419 if( b >= 1024 )
420 return wxString::Format( wxT( "%lld kB" ), b / 1000 );
421
422 return wxString::Format( wxT( "%lld B" ), b );
423}
424
425
427{
428 if( !m_currentSelected )
429 return false;
430
431 return m_gridVersions->GetNumberRows() == 1 || m_gridVersions->GetSelectedRows().size() == 1;
432}
433
434
436{
437 if( !m_currentSelected )
438 return false;
439
440 const PACKAGE_VIEW_DATA& packageData = m_currentSelected->GetPackageData();
441
442 switch( packageData.state )
443 {
446 case PPS_PENDING_UPDATE: return false;
447 default: break;
448 }
449
450 return m_gridVersions->GetNumberRows() == 1 || m_gridVersions->GetSelectedRows().size() == 1;
451}
452
453
454void PANEL_PACKAGES_VIEW::SetPackageState( const wxString& aPackageId,
455 const PCM_PACKAGE_STATE aState, const bool aPinned )
456{
457 auto it = m_packagePanels.find( aPackageId );
458
459 if( it != m_packagePanels.end() )
460 {
461 it->second->SetState( aState, aPinned );
462
463 if( m_currentSelected && m_currentSelected == it->second )
464 {
465 wxMouseEvent dummy;
467 }
468
469 if( aState == PPS_UPDATE_AVAILABLE && !aPinned )
470 {
471 m_updateablePackages.insert( aPackageId );
472 }
473 else
474 {
475 m_updateablePackages.erase( aPackageId );
476 }
477
479 }
480}
481
482
484{
485 m_gridVersions->ClearSelection();
486 m_gridVersions->SelectRow( event.GetRow() );
487
489}
490
491
493{
494 if( !canDownload() )
495 {
496 wxBell();
497 return;
498 }
499
500 if( m_gridVersions->GetNumberRows() == 1 )
501 m_gridVersions->SelectRow( 0 );
502
503 const wxArrayInt selectedRows = m_gridVersions->GetSelectedRows();
504
505 wxString version = m_gridVersions->GetCellValue( selectedRows[0], COL_VERSION );
506 const PCM_PACKAGE& package = m_currentSelected->GetPackageData().package;
507
508 auto ver_it = std::find_if( package.versions.begin(), package.versions.end(),
509 [&]( const PACKAGE_VERSION& ver )
510 {
511 return ver.version == version;
512 } );
513
514 wxASSERT_MSG( ver_it != package.versions.end(), "Could not find package version" );
515
516 if( !ver_it->download_url )
517 {
518 wxMessageBox( _( "Package download url is not specified" ),
519 _( "Error downloading package" ), wxICON_INFORMATION | wxOK,
520 wxGetTopLevelParent( this ) );
521 return;
522 }
523
524 const wxString& url = *ver_it->download_url;
525
526 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
527 KICAD_SETTINGS* app_settings = mgr.GetAppSettings<KICAD_SETTINGS>();
528
529 wxWindow* topLevelParent = wxGetTopLevelParent( this );
530 wxFileDialog dialog( topLevelParent, _( "Save Package" ), app_settings->m_PcmLastDownloadDir,
531 wxString::Format( wxT( "%s_v%s.zip" ), package.identifier, version ),
532 wxT( "ZIP files (*.zip)|*.zip" ), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
533
534 if( dialog.ShowModal() == wxID_CANCEL )
535 return;
536
537 wxString path = dialog.GetPath();
538 app_settings->m_PcmLastDownloadDir = wxPathOnly( path );
539
540 std::ofstream output( path.ToUTF8(), std::ios_base::binary );
541
542 std::unique_ptr<WX_PROGRESS_REPORTER> reporter =
543 std::make_unique<WX_PROGRESS_REPORTER>( this, _( "Downloading package" ), 1 );
544
545 bool success = m_pcm->DownloadToStream( url, &output, reporter.get(), 0 );
546
547 output.close();
548
549 if( success )
550 {
551 if( ver_it->download_sha256 )
552 {
553 std::ifstream stream( path.ToUTF8(), std::ios_base::binary );
554
555 bool matches = m_pcm->VerifyHash( stream, *ver_it->download_sha256 );
556
557 stream.close();
558
559 if( !matches
560 && wxMessageBox(
561 _( "Integrity of the downloaded package could not be verified, hash "
562 "does not match. Are you sure you want to keep this file?" ),
563 _( "Keep downloaded file" ), wxICON_EXCLAMATION | wxYES_NO,
564 wxGetTopLevelParent( this ) )
565 == wxNO )
566 {
567 wxRemoveFile( path );
568 }
569 }
570 }
571 else
572 {
573 if( wxFileExists( path ) )
574 wxRemoveFile( path );
575 }
576}
577
578
580{
581 if( !canRunAction() )
582 {
583 wxBell();
584 return;
585 }
586
587 PCM_PACKAGE_ACTION action = getAction();
588
589 if( action == PPA_UNINSTALL )
590 {
593 return;
594 }
595
596 if( m_gridVersions->GetNumberRows() == 1 )
597 m_gridVersions->SelectRow( 0 );
598
599 const wxArrayInt selectedRows = m_gridVersions->GetSelectedRows();
600
601 wxString version = m_gridVersions->GetCellValue( selectedRows[0], COL_VERSION );
602 const PCM_PACKAGE& package = m_currentSelected->GetPackageData().package;
603
604 auto ver_it = std::find_if( package.versions.begin(), package.versions.end(),
605 [&]( const PACKAGE_VERSION& ver )
606 {
607 return ver.version == version;
608 } );
609
610 wxCHECK_RET( ver_it != package.versions.end(), "Could not find package version" );
611
612 if( !ver_it->compatible
613 && wxMessageBox( _( "This package version is incompatible with your KiCad version or "
614 "platform. Are you sure you want to install it anyway?" ),
615 _( "Install package" ), wxICON_EXCLAMATION | wxYES_NO,
616 wxGetTopLevelParent( this ) )
617 == wxNO )
618 {
619 return;
620 }
621
622 m_actionCallback( m_currentSelected->GetPackageData(), action, version );
623}
624
625
627{
629 {
630 wxMouseEvent dummy;
632 }
633
635}
636
637
638void PANEL_PACKAGES_VIEW::OnSearchTextChanged( wxCommandEvent& event )
639{
641
644
645 m_currentSelected = nullptr;
646
648}
649
650
652{
653 // Sort by descending rank, ascending index
654 std::vector<std::pair<int, int>> package_ranks;
655
656 const wxString search_term = m_searchCtrl->GetValue().Trim();
657
658 for( size_t index = 0; index < m_packageInitialOrder.size(); index++ )
659 {
660 int rank = 1;
661 const PCM_PACKAGE& pkg =
662 m_packagePanels[m_packageInitialOrder[index]]->GetPackageData().package;
663
664 if( search_term.size() > 2 )
665 rank = m_pcm->GetPackageSearchRank( pkg, search_term );
666
667 // Packages with no versions are delisted and should not be shown
668 if( pkg.versions.size() == 0 )
669 rank = 0;
670
671 package_ranks.emplace_back( rank, index );
672 }
673
674 std::sort( package_ranks.begin(), package_ranks.end(),
675 []( const std::pair<int, int>& a, const std::pair<int, int>& b )
676 {
677 return a.first > b.first || ( a.first == b.first && a.second < b.second );
678 } );
679
680 // Rearrange panels, hide ones with 0 rank
681 wxSizer* sizer = m_packageListWindow->GetSizer();
682 sizer->Clear( false ); // Don't delete panels
683
684 for( const std::pair<int, int>& pair : package_ranks )
685 {
687
688 if( pair.first > 0 )
689 {
690 sizer->Add( panel, 0, wxEXPAND );
691 panel->Show();
692 }
693 else
694 {
695 panel->Hide();
696 }
697 }
698
699 m_packageListWindow->FitInside();
700 m_packageListWindow->SetScrollRate( 0, 15 );
701 m_packageListWindow->SendSizeEvent( wxSEND_EVENT_POST );
702}
703
704
706{
707 m_buttonDownload->Enable( canDownload() );
708
709 if( canRunAction() )
710 {
711 m_buttonAction->Enable();
712
713 PCM_PACKAGE_ACTION action = getAction();
714
715 switch( action )
716 {
717 case PPA_INSTALL: m_buttonAction->SetLabel( _( "Install" ) ); break;
718 case PPA_UNINSTALL: m_buttonAction->SetLabel( _( "Uninstall" ) ); break;
719 case PPA_UPDATE: m_buttonAction->SetLabel( _( "Update" ) ); break;
720 }
721 }
722 else
723 {
724 m_buttonAction->Disable();
725 m_buttonAction->SetLabel( _( "Pending" ) );
726 }
727}
728
729
731{
732 wxASSERT_MSG( m_gridVersions->GetNumberRows() == 1
733 || m_gridVersions->GetSelectedRows().size() == 1,
734 wxT( "getAction() called with ambiguous version selection" ) );
735
736 int selected_row = 0;
737
738 if( m_gridVersions->GetSelectedRows().size() == 1 )
739 selected_row = m_gridVersions->GetSelectedRows()[0];
740
741 wxString version = m_gridVersions->GetCellValue( selected_row, COL_VERSION );
742 const PACKAGE_VIEW_DATA& package = m_currentSelected->GetPackageData();
743
744 switch( package.state )
745 {
746 case PPS_AVAILABLE:
747 case PPS_UNAVAILABLE:
748 return PPA_INSTALL; // Only action for not installed package is to install it
749 case PPS_INSTALLED:
751 if( version == package.current_version )
752 return PPA_UNINSTALL;
753 else
754 return PPA_UPDATE;
755 default:
756 return PPA_INSTALL; // For pending states return value does not matter as button will be disabled
757 }
758}
759
760
761void PANEL_PACKAGES_VIEW::OnSizeInfoBox( wxSizeEvent& aEvent )
762{
763 wxSize infoSize = KIPLATFORM::UI::GetUnobscuredSize( m_infoText->GetParent() );
764 infoSize.x -= 10;
765 m_infoText->SetMinSize( infoSize );
766 m_infoText->SetMaxSize( infoSize );
767 m_infoText->SetSize( infoSize );
768 m_infoText->Layout();
769
770 infoSize.y = m_infoText->GetInternalRepresentation()->GetHeight() + 12;
771 m_infoText->SetMinSize( infoSize );
772 m_infoText->SetMaxSize( infoSize );
773 m_infoText->SetSize( infoSize );
774 m_infoText->Layout();
775
776 Refresh();
777}
778
779
780void PANEL_PACKAGES_VIEW::OnURLClicked( wxHtmlLinkEvent& aEvent )
781{
782 const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
783 ::wxLaunchDefaultBrowser( info.GetHref() );
784}
785
786
787void PANEL_PACKAGES_VIEW::OnInfoMouseWheel( wxMouseEvent& event )
788{
789 // Transfer scrolling from the info window to its parent scroll window
790 m_infoScrollWindow->HandleOnMouseWheel( event );
791}
792
793
794void PANEL_PACKAGES_VIEW::SetSashOnIdle( wxIdleEvent& aEvent )
795{
796 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
797 m_splitter1->SetSashPosition( cfg->m_PackageManager.sash_pos );
798
799 m_packageListWindow->FitInside();
800
801 m_splitter1->Disconnect( wxEVT_IDLE, wxIdleEventHandler( PANEL_PACKAGES_VIEW::SetSashOnIdle ),
802 NULL, this );
803}
804
805
807{
808 m_buttonUpdateAll->Enable( m_updateablePackages.size() > 0 );
809}
810
811
812void PANEL_PACKAGES_VIEW::OnUpdateAllClicked( wxCommandEvent& event )
813{
814 // The map will be modified by the callback so we copy the list here
815 std::vector<wxString> packages;
816
817 std::copy( m_updateablePackages.begin(), m_updateablePackages.end(),
818 std::back_inserter( packages ) );
819
820 for( const wxString& pkg_id : packages )
821 {
822 auto it = m_packagePanels.find( pkg_id );
823
824 if( it != m_packagePanels.end() )
825 {
826 const PACKAGE_VIEW_DATA& data = it->second->GetPackageData();
827
829 }
830 }
831}
const char * name
Definition: DXF_plotter.cpp:57
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.
T * GetAppSettings()
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:559
void SetBorders(bool aLeft, bool aRight, bool aTop, bool aBottom)
Definition: wx_panel.h:39
void SetPaneMinimums(int aFirst, int aSecond)
#define GRID_CELL_MARGIN
#define _(s)
wxSize GetUnobscuredSize(const wxWindow *aWindow)
Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl,...
Definition: gtk/ui.cpp:195
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
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:57
@ PPS_INSTALLED
Definition: pcm.h:60
@ PPS_PENDING_UPDATE
Definition: pcm.h:64
@ PPS_UNAVAILABLE
Definition: pcm.h:59
@ PPS_UPDATE_AVAILABLE
Definition: pcm.h:63
@ PPS_PENDING_UNINSTALL
Definition: pcm.h:62
@ PPS_PENDING_INSTALL
Definition: pcm.h:61
@ PPS_AVAILABLE
Definition: pcm.h:58
PCM_PACKAGE_ACTION
Definition: pcm.h:70
@ PPA_UNINSTALL
Definition: pcm.h:72
@ PPA_UPDATE
Definition: pcm.h:73
@ PPA_INSTALL
Definition: pcm.h:71
@ PVS_INVALID
Definition: pcm_data.h:53
@ PVS_DEVELOPMENT
Definition: pcm_data.h:56
@ PVS_STABLE
Definition: pcm_data.h:54
@ PVS_TESTING
Definition: pcm_data.h:55
@ PVS_DEPRECATED
Definition: pcm_data.h:57
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
std::vector< FAB_LAYER_COLOR > dummy
wxString EscapeHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
< Package version metadata Package metadata
Definition: pcm_data.h:75
std::optional< uint64_t > download_size
Definition: pcm_data.h:80
bool compatible
Definition: pcm_data.h:90
std::optional< uint64_t > install_size
Definition: pcm_data.h:81
wxString version
Definition: pcm_data.h:76
PCM_PACKAGE_VERSION_STATUS status
Definition: pcm_data.h:82
< 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:96
wxString name
Definition: pcm_data.h:97
std::vector< PACKAGE_VERSION > versions
Definition: pcm_data.h:108