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,
60 mainSizer->Add(
m_stName, 0, wxALL | wxEXPAND, 1 );
62 m_stStatus =
new wxStaticText(
this, wxID_ANY, aJob->m_status, wxDefaultPosition,
65 mainSizer->Add(
m_stStatus, 0, wxALL | wxEXPAND, 1 );
67 m_progress =
new wxGauge(
this, wxID_ANY, aJob->m_maxProgress, wxDefaultPosition,
68 wxDefaultSize, wxGA_HORIZONTAL );
70 mainSizer->Add(
m_progress, 0, wxALL | wxEXPAND, 1 );
72 SetSizer( mainSizer );
90 std::shared_ptr<BACKGROUND_JOB>
m_job;
98 wxFrame( parent, wxID_ANY,
_(
"Background Jobs" ), pos, wxSize( 300, 150 ),
99 wxFRAME_NO_TASKBAR | wxBORDER_SIMPLE )
101 SetSizeHints( wxDefaultSize, wxDefaultSize );
104 bSizer1 =
new wxBoxSizer( wxVERTICAL );
107 wxSize( -1, -1 ), wxVSCROLL );
131 void Add( std::shared_ptr<BACKGROUND_JOB> aJob )
145 void Remove( std::shared_ptr<BACKGROUND_JOB> aJob )
176 const std::shared_ptr<BACKGROUND_JOB>& aJob ) :
178 m_monitor( aMonitor ),
193 m_job->m_status = aMessage;
222 std::shared_ptr<BACKGROUND_JOB> job = std::make_shared<BACKGROUND_JOB>();
225 job->m_reporter = std::make_shared<BACKGROUND_JOB_REPORTER>(
this, job );
227 std::lock_guard<std::shared_mutex> lock(
m_mutex );
258 list->Remove( aJob );
263 std::lock_guard<std::shared_mutex> lock(
m_mutex );
265 [&]( std::shared_ptr<BACKGROUND_JOB> job )
278 statusBar->CallAfter(
281 statusBar->HideBackgroundProgressBar();
282 statusBar->SetBackgroundStatusText( wxT(
"" ) );
296 return dialog == evtWindow;
307 std::shared_lock<std::shared_mutex> lock(
m_mutex, std::try_to_lock );
309 for(
const std::shared_ptr<BACKGROUND_JOB>& job :
m_jobs )
319 wxSize windowSize = list->GetSize();
320 list->SetPosition( aPos - windowSize );
328 std::shared_lock<std::shared_mutex> lock(
m_mutex, std::try_to_lock );
335 if(
m_jobs.front() == aJob )
340 statusBar->CallAfter(
343 statusBar->ShowBackgroundProgressBar();
344 statusBar->SetBackgroundProgress( aJob->m_currentProgress );
345 statusBar->SetBackgroundProgressMax( aJob->m_maxProgress );
346 statusBar->SetBackgroundStatusText( aJob->m_status );
358 list->UpdateJob( aJob );
375 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, const 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
std::atomic_bool m_cancelled
void SetNumPhases(int aNumPhases) override
Set the number of phases.