25#include <unordered_map>
30#include <wx/settings.h>
31#include <wx/scrolwin.h>
33#include <wx/stattext.h>
44 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxSize( -1, 75 ),
48 SetSizeHints( wxDefaultSize, wxDefaultSize );
50 wxBoxSizer* mainSizer;
51 mainSizer =
new wxBoxSizer( wxVERTICAL );
53 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) );
55 m_stName =
new wxStaticText(
this, wxID_ANY, aJob->m_name );
57 m_stName->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT,
58 wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD,
false, wxEmptyString ) );
59 mainSizer->Add(
m_stName, 0, wxALL | wxEXPAND, 1 );
61 m_stStatus =
new wxStaticText(
this, wxID_ANY, aJob->m_status, wxDefaultPosition,
64 mainSizer->Add(
m_stStatus, 0, wxALL | wxEXPAND, 1 );
66 m_progress =
new wxGauge(
this, wxID_ANY, aJob->m_maxProgress, wxDefaultPosition, wxDefaultSize,
69 mainSizer->Add(
m_progress, 0, wxALL | wxEXPAND, 1 );
71 SetSizer( mainSizer );
89 std::shared_ptr<BACKGROUND_JOB>
m_job;
97 wxFrame( parent, wxID_ANY,
_(
"Background Jobs" ), pos, wxSize( 300, 150 ),
98 wxFRAME_NO_TASKBAR | wxBORDER_SIMPLE )
100 SetSizeHints( wxDefaultSize, wxDefaultSize );
103 bSizer1 =
new wxBoxSizer( wxVERTICAL );
106 wxSize( -1, -1 ), wxVSCROLL );
130 void Add( std::shared_ptr<BACKGROUND_JOB> aJob )
144 void Remove( std::shared_ptr<BACKGROUND_JOB> aJob )
175 std::shared_ptr<BACKGROUND_JOB> aJob ) :
177 m_monitor( aMonitor ), m_job( aJob )
191 m_job->m_status = aMessage;
220 std::shared_ptr<BACKGROUND_JOB> job = std::make_shared<BACKGROUND_JOB>();
223 job->m_reporter = std::make_shared<BACKGROUND_JOB_REPORTER>(
this, job );
225 std::lock_guard<std::shared_mutex> lock(
m_mutex );
256 list->Remove( aJob );
261 std::lock_guard<std::shared_mutex> lock(
m_mutex );
263 [&]( std::shared_ptr<BACKGROUND_JOB> job )
272 statusBar->CallAfter(
275 statusBar->HideBackgroundProgressBar();
276 statusBar->SetBackgroundStatusText( wxT(
"" ) );
290 return dialog == evtWindow;
301 std::shared_lock<std::shared_mutex> lock(
m_mutex, std::try_to_lock );
303 for( std::shared_ptr<BACKGROUND_JOB> job :
m_jobs )
315 wxSize windowSize = list->GetSize();
316 list->SetPosition( aPos - windowSize );
324 std::shared_lock<std::shared_mutex> lock(
m_mutex, std::try_to_lock );
331 if(
m_jobs.front() == aJob )
336 statusBar->CallAfter(
339 statusBar->ShowBackgroundProgressBar();
340 statusBar->SetBackgroundProgress( aJob->m_currentProgress );
341 statusBar->SetBackgroundProgressMax( aJob->m_maxProgress );
342 statusBar->SetBackgroundStatusText( aJob->m_status );
354 list->UpdateJob( aJob );
371 return statusBar == aStatusBar;
void UnregisterStatusBar(KISTATUSBAR *aStatusBar)
Removes status bar from handling.
std::vector< std::shared_ptr< BACKGROUND_JOB > > m_jobs
Holds a reference to all active background jobs Access to this vector should be protected by locks si...
BACKGROUND_JOBS_MONITOR()
void ShowList(wxWindow *aParent, wxPoint aPos)
Shows the background job list.
friend class BACKGROUND_JOB_LIST
std::shared_mutex m_mutex
Mutex to protect access to the m_jobs vector.
std::shared_ptr< BACKGROUND_JOB > Create(const wxString &aName)
Creates a background job with the given name.
void jobUpdated(std::shared_ptr< BACKGROUND_JOB > aJob)
Handles job status updates, intended to be called by BACKGROUND_JOB_REPORTER only.
void Remove(std::shared_ptr< BACKGROUND_JOB > job)
Removes the given background job from any lists and frees it.
void onListWindowClosed(wxCloseEvent &aEvent)
Handles removing the shown list window from our list of shown windows.
std::vector< KISTATUSBAR * > m_statusBars
std::vector< BACKGROUND_JOB_LIST * > m_shownDialogs
void RegisterStatusBar(KISTATUSBAR *aStatusBar)
Add a status bar for handling.
void Remove(std::shared_ptr< BACKGROUND_JOB > aJob)
wxBoxSizer * m_contentSizer
void onFocusLoss(wxFocusEvent &aEvent)
void Add(std::shared_ptr< BACKGROUND_JOB > aJob)
BACKGROUND_JOB_LIST(wxWindow *parent, const wxPoint &pos)
void UpdateJob(std::shared_ptr< BACKGROUND_JOB > aJob)
std::unordered_map< std::shared_ptr< BACKGROUND_JOB >, BACKGROUND_JOB_PANEL * > m_jobPanels
wxScrolledWindow * m_scrolledWindow
BACKGROUND_JOB_PANEL(wxWindow *aParent, std::shared_ptr< BACKGROUND_JOB > aJob)
std::shared_ptr< BACKGROUND_JOB > m_job
wxStaticText * m_stStatus
void SetNumPhases(int aNumPhases) override
Set the number of phases.
void AdvancePhase() override
Use the next available virtual zone of the dialog progress bar.
std::shared_ptr< BACKGROUND_JOB > m_job
void Report(const wxString &aMessage) override
Display aMessage in the progress bar dialog.
BACKGROUND_JOBS_MONITOR * m_monitor
BACKGROUND_JOB_REPORTER(BACKGROUND_JOBS_MONITOR *aMonitor, std::shared_ptr< BACKGROUND_JOB > aJob)
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
This implements all the tricky bits for thread safety, but the GUI is left to derived classes.
virtual void AdvancePhase() override
Use the next available virtual zone of the dialog progress bar.
std::atomic_int m_numPhases
void SetNumPhases(int aNumPhases) override
Set the number of phases.