22#include <unordered_map>
27#include <wx/settings.h>
28#include <wx/scrolwin.h>
30#include <wx/stattext.h>
41 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxSize( -1, 75 ),
45 SetSizeHints( wxDefaultSize, wxDefaultSize );
47 wxBoxSizer* mainSizer;
48 mainSizer =
new wxBoxSizer( wxVERTICAL );
50 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) );
52 m_stName =
new wxStaticText(
this, wxID_ANY, aJob->m_name );
54 m_stName->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT,
55 wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD,
false,
57 mainSizer->Add(
m_stName, 0, wxALL | wxEXPAND, 1 );
59 m_stStatus =
new wxStaticText(
this, wxID_ANY, aJob->GetStatus(), wxDefaultPosition,
62 mainSizer->Add(
m_stStatus, 0, wxALL | wxEXPAND, 1 );
64 m_progress =
new wxGauge(
this, wxID_ANY, aJob->m_maxProgress, wxDefaultPosition,
65 wxDefaultSize, wxGA_HORIZONTAL );
67 mainSizer->Add(
m_progress, 0, wxALL | wxEXPAND, 1 );
69 SetSizer( mainSizer );
87 std::shared_ptr<BACKGROUND_JOB>
m_job;
95 wxFrame( parent, wxID_ANY,
_(
"Background Jobs" ), pos, wxSize( 300, 150 ),
96 wxFRAME_NO_TASKBAR | wxBORDER_SIMPLE )
98 SetSizeHints( wxDefaultSize, wxDefaultSize );
101 bSizer1 =
new wxBoxSizer( wxVERTICAL );
104 wxSize( -1, -1 ), wxVSCROLL );
128 void Add( std::shared_ptr<BACKGROUND_JOB> aJob )
142 void Remove( std::shared_ptr<BACKGROUND_JOB> aJob )
173 const std::shared_ptr<BACKGROUND_JOB>& aJob ) :
190 m_job->SetStatus( aMessage );
214 m_job->m_maxProgress.store( 1000 );
215 m_job->m_currentProgress.store(
static_cast<int>( 1000 * aProgress ) );
228 std::shared_ptr<BACKGROUND_JOB> job = std::make_shared<BACKGROUND_JOB>();
231 job->m_reporter = std::make_shared<BACKGROUND_JOB_REPORTER>(
this, job );
233 std::lock_guard<std::shared_mutex> lock(
m_mutex );
252 std::shared_ptr<BACKGROUND_JOB> frontJob;
255 std::lock_guard<std::shared_mutex> lock(
m_mutex );
264 list->Remove( aJob );
272 statusBar->CallAfter(
275 statusBar->HideBackgroundProgressBar();
276 statusBar->SetBackgroundStatusText( wxT(
"" ) );
282 frontJob =
m_jobs.front();
310 std::lock_guard<std::shared_mutex> lock(
m_mutex );
316 return static_cast<wxObject*>( dialog ) == aWindow;
327 std::lock_guard<std::shared_mutex> lock(
m_mutex );
329 for(
const std::shared_ptr<BACKGROUND_JOB>& job :
m_jobs )
339 wxSize windowSize = list->GetSize();
340 list->SetPosition( aPos - windowSize );
350 std::shared_lock<std::shared_mutex> lock(
m_mutex );
358 statusBar->CallAfter(
361 statusBar->ShowBackgroundProgressBar();
362 statusBar->SetBackgroundProgressMax( aJob->m_maxProgress );
363 statusBar->SetBackgroundProgress( aJob->m_currentProgress );
364 statusBar->SetBackgroundStatusText( aJob->GetStatus() );
374 list->UpdateJob( aJob );
382 std::shared_ptr<BACKGROUND_JOB> frontJob;
385 std::lock_guard<std::shared_mutex> lock(
m_mutex );
390 frontJob =
m_jobs.front();
401 std::lock_guard<std::shared_mutex> lock(
m_mutex );
405 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 m_jobs, m_shownDialogs and m_statusBars.
std::shared_ptr< BACKGROUND_JOB > Create(const wxString &aName)
Creates a background job with the given name.
void onListWindowDestroyed(wxWindowDestroyEvent &aEvent)
Handles a list window that its parent destroys without a close event.
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
void removeShownDialog(wxObject *aWindow)
Removes a list window from m_shownDialogs.
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.
void SetCurrentProgress(double aProgress) override
Set the progress value to aProgress (0..1).
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.
virtual void AdvancePhase() override
Use the next available virtual zone of the dialog progress bar.
PROGRESS_REPORTER_BASE(int aNumPhases)
virtual void SetCurrentProgress(double aProgress) override
Set the progress value to aProgress (0..1).
std::atomic_int m_numPhases
std::atomic_bool m_cancelled
void SetNumPhases(int aNumPhases) override
Set the number of phases.