35 #include <wx/filedlg.h> 37 #include <wx/tokenzr.h> 40 #define GRID_CELL_MARGIN 4 53 std::shared_ptr<PLUGIN_CONTENT_MANAGER> aPcm ) :
69 m_searchCtrl->SetMinSize( wxSize( -1, GetTextExtent( wxT(
"qb" ) ).y + 10 ) );
93 wxColor background = wxStaticText::GetClassDefaultAttributes().colBg;
138 [package_panel,
this]()
165 details << wxT(
"<h5>" ) + package.
name + wxT(
"</h5>" );
168 [](
const wxString&
text ) -> wxString
174 for(
unsigned i = 0; i <
text.length(); ++i )
176 wxUniChar c =
text[i];
192 else if(
text.Mid( i, 5 ) == wxT(
"http:" ) ||
text.Mid( i, 6 ) == wxT(
"https:" ) )
199 result += wxT(
"</p><p>" );
210 wxString desc = package.description_full;
211 details << wxT(
"<p>" ) + format_desc( desc ) + wxT(
"</p>" );
213 details << wxT(
"<p><b>" ) +
_(
"Metadata" ) + wxT(
"</b></p>" );
214 details << wxT(
"<ul>" );
215 details << wxT(
"<li>" ) +
_(
"Package identifier: " ) + package.identifier + wxT(
"</li>" );
216 details << wxT(
"<li>" ) +
_(
"License: " ) + package.license + wxT(
"</li>" );
218 if( package.tags.size() > 0 )
222 for(
const std::string& tag : package.tags )
224 if( !tags_str.IsEmpty() )
225 tags_str += wxT(
", " );
230 details << wxT(
"<li>" ) +
_(
"Tags: " ) + tags_str + wxT(
"</li>" );
234 [](
const std::pair<const std::string, wxString>& entry ) -> wxString
236 wxString
name = entry.first;
239 if(
name == wxT(
"email" ) )
241 else if( url.StartsWith( wxT(
"http:" ) ) || url.StartsWith( wxT(
"https:" ) ) )
248 [&](
const wxString& type,
const PCM_CONTACT& contact )
250 details << wxT(
"<li>" ) + type + wxT(
": " ) + contact.name + wxT(
"<ul>" );
252 for(
const std::pair<const std::string, wxString>& entry : contact.contact )
253 details << wxT(
"<li>" ) + entry.first + wxT(
": " ) + format_entry( entry ) + wxT(
"</li>" );
255 details << wxT(
"</ul>" );
258 write_contact(
_(
"Author" ), package.author );
260 if( package.maintainer )
261 write_contact(
_(
"Maintainer" ), package.maintainer.get() );
263 if( package.resources.size() > 0 )
265 details << wxT(
"<li>" ) +
_(
"Resources" ) + wxT(
"<ul>" );
267 for(
const std::pair<const std::string, wxString>& entry : package.resources )
268 details << wxT(
"<li>" ) + entry.first + wxS(
": " ) + format_entry( entry ) + wxT(
"</li>" );
270 details << wxT(
"</ul>" );
273 details << wxT(
"</ul>" );
287 wxString current_version;
290 current_version =
m_pcm->GetInstalledPackageVersion( package.identifier );
307 version.
compatible ? wxT(
"\u2714" ) : wxEmptyString );
312 if( current_version == version.
version )
332 if( !version.IsEmpty() )
387 uint64_t b = size.get();
389 if( b >= 1024 * 1024 )
429 it->second->SetState( aState );
460 const wxArrayInt selectedRows =
m_gridVersions->GetSelectedRows();
463 const PCM_PACKAGE&
package = m_currentSelected->GetPackageData().package;
465 auto ver_it = std::find_if( package.versions.begin(), package.versions.end(),
468 return ver.version == version;
471 wxASSERT_MSG( ver_it != package.
versions.end(), wxT(
"Could not find package version" ) );
473 if( !ver_it->download_url )
475 wxMessageBox(
_(
"Package download url is not specified" ),
476 _(
"Error downloading package" ), wxICON_INFORMATION | wxOK,
this );
480 const wxString& url = ver_it->download_url.get();
485 wxFileDialog dialog(
this,
_(
"Save package" ), app_settings->m_PcmLastDownloadDir,
489 if( dialog.ShowModal() == wxID_CANCEL )
492 wxString
path = dialog.GetPath();
493 app_settings->m_PcmLastDownloadDir = wxPathOnly(
path );
495 std::ofstream output(
path.ToUTF8(), std::ios_base::binary );
497 std::unique_ptr<WX_PROGRESS_REPORTER> reporter(
500 bool success =
m_pcm->DownloadToStream( url, &output, reporter.get(), 0 );
506 if( ver_it->download_sha256 )
508 std::ifstream stream(
path.ToUTF8(), std::ios_base::binary );
510 bool matches =
m_pcm->VerifyHash( stream, ver_it->download_sha256.get() );
516 _(
"Integrity of the downloaded package could not be verified, hash " 517 "does not match. Are you sure you want to keep this file?" ),
518 _(
"Keep downloaded file" ), wxICON_EXCLAMATION | wxYES_NO,
this )
521 wxRemoveFile(
path );
527 if( wxFileExists(
path ) )
528 wxRemoveFile(
path );
544 const wxArrayInt selectedRows =
m_gridVersions->GetSelectedRows();
547 const PCM_PACKAGE&
package = m_currentSelected->GetPackageData().package;
549 auto ver_it = std::find_if( package.versions.begin(), package.versions.end(),
552 return ver.version == version;
555 wxASSERT_MSG( ver_it != package.
versions.end(), wxT(
"Could not find package version" ) );
557 if( !ver_it->compatible
558 && wxMessageBox(
_(
"This package version is incompatible with your kicad version or " 559 "platform. Are you sure you want to install it anyway?" ),
560 _(
"Install package" ), wxICON_EXCLAMATION | wxYES_NO,
this )
598 std::vector<std::pair<int, int>> package_ranks;
600 const wxString search_term =
m_searchCtrl->GetValue().Trim();
608 if( search_term.size() > 2 )
609 rank =
m_pcm->GetPackageSearchRank( pkg, search_term );
615 package_ranks.emplace_back( rank, index );
618 std::sort( package_ranks.begin(), package_ranks.end(),
619 [](
const std::pair<int, int>& a,
const std::pair<int, int>& b )
621 return a.first > b.first || ( a.first == b.first && a.second < b.second );
626 sizer->Clear(
false );
628 for(
const std::pair<int, int>& pair : package_ranks )
634 sizer->Add( panel, 0, wxEXPAND );
658 wxSize infoSize =
m_infoText->GetParent()->GetClientSize();
665 infoSize.y =
m_infoText->GetInternalRepresentation()->GetHeight() + 12;
677 const wxHtmlLinkInfo&
info = aEvent.GetLinkInfo();
678 ::wxLaunchDefaultBrowser(
info.GetHref() );
< Package version metadata Package metadata
void SetData(const std::vector< PACKAGE_VIEW_DATA > &aPackageData, ActionCallback aCallback)
Recreates package panels and displays data.
void OnURLClicked(wxHtmlLinkEvent &event) override
Respond to scrolling over the window.
std::shared_ptr< PLUGIN_CONTENT_MANAGER > m_pcm
PCM_PACKAGE_VERSION_STATUS status
wxString toHumanReadableSize(const boost::optional< uint64_t > size) const
Returns true if it the download operation can be performed.
wxButton * m_buttonDownload
void OnSizeInfoBox(wxSizeEvent &aEvent) override
Respond to a URL in the info window.
boost::optional< uint64_t > download_size
wxCheckBox * m_showAllVersions
boost::optional< uint64_t > install_size
bool canDownload() const
Returns true if the install operation can be performed.
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
wxString ZipFileWildcard()
std::vector< wxString > m_packageInitialOrder
void ClearData()
Selects full row of the clicked cell.
void unsetPackageDetails()
Bytes to Kb/Mb/Gb string or "-" if absent.
void OnInstallVersionClicked(wxCommandEvent &event) override
Shows all versions including incompatible ones.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
wxScrolledWindow * m_infoScrollWindow
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=false, bool aKeep=true)
Calculates the specified column based on the actual size of the text on screen.
void updateDetailsButtons()
Updates details panel.
< Collection of data relevant to the package display panel Callback for (un)install button
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
static std::unordered_map< PCM_PACKAGE_VERSION_STATUS, wxString > STATUS_ENUM_TO_STR
void SetPackageState(const wxString &aPackageId, const PCM_PACKAGE_STATE aState) const
Set the state of package.
void OnShowAllVersionsClicked(wxCommandEvent &event) override
Ranks packages for entered search term and rearranges/hides panels according to their rank.
void m_splitter1OnIdle(wxIdleEvent &)
Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting back of...
void SetBorders(bool aLeft, bool aRight, bool aTop, bool aBottom)
void SetSelected(bool aSelected)
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
Class PANEL_PACKAGES_VIEW_BASE.
wxBoxSizer * m_sizerVersions
Repository reference to a resource.
void OnDownloadVersionClicked(wxCommandEvent &event) override
Schedules installation of selected package version.
T * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
Definition of file extensions used in Kicad.
bool SetPage(const wxString &aSource) override
void SetSashOnIdle(wxIdleEvent &)
WX_SPLITTER_WINDOW * m_splitter1
wxScrolledWindow * m_packageListWindow
void OnClick(wxMouseEvent &event) override
void SetSelectCallback(const std::function< void()> &aCallback)
Marks panel as selected.
void OnInfoMouseWheel(wxMouseEvent &event) override
Replacement of wxFormBuilder's ill-advised m_splitter1OnIdle.
std::vector< PACKAGE_VERSION > versions
void OnSearchTextChanged(wxCommandEvent &event)
void OnVersionsCellClicked(wxGridEvent &event) override
Opens file chooser dialog and downloads selected package version archive.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
wxButton * m_buttonInstall
PACKAGE_MANAGER m_PackageManager
wxString EscapeHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
void setPackageDetails(const PACKAGE_VIEW_DATA &aPackageData)
Clears details panel.
const PACKAGE_VIEW_DATA & GetPackageData() const
PANEL_PACKAGE * m_currentSelected
void updatePackageList()
< Updates package listing according to search term
std::unordered_map< wxString, PANEL_PACKAGE * > m_packagePanels
std::function< void(const PACKAGE_VIEW_DATA &aData, PCM_PACKAGE_ACTION aAction, const wxString &aVersion)> ActionCallback
PANEL_PACKAGES_VIEW(wxWindow *parent, std::shared_ptr< PLUGIN_CONTENT_MANAGER > aPcm)
ActionCallback m_actionCallback
wxString GetPreferredVersion() const
wxSearchCtrl * m_searchCtrl
void SetPaneMinimums(int aFirst, int aSecond)