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 std::shared_ptr<BACKGROUND_JOB> aJob ) :
178 m_monitor( aMonitor ), m_job( aJob )
192 m_job->m_status = aMessage;
221 std::shared_ptr<BACKGROUND_JOB> job = std::make_shared<BACKGROUND_JOB>();
224 job->m_reporter = std::make_shared<BACKGROUND_JOB_REPORTER>(
this, job );
226 std::lock_guard<std::shared_mutex> lock(
m_mutex );
257 list->Remove( aJob );
262 std::lock_guard<std::shared_mutex> lock(
m_mutex );
264 [&]( std::shared_ptr<BACKGROUND_JOB> job )
273 statusBar->CallAfter(
276 statusBar->HideBackgroundProgressBar();
277 statusBar->SetBackgroundStatusText( wxT(
"" ) );
291 return dialog == evtWindow;
302 std::shared_lock<std::shared_mutex> lock(
m_mutex, std::try_to_lock );
304 for( std::shared_ptr<BACKGROUND_JOB> job :
m_jobs )
316 wxSize windowSize = list->GetSize();
317 list->SetPosition( aPos - windowSize );
325 std::shared_lock<std::shared_mutex> lock(
m_mutex, std::try_to_lock );
332 if(
m_jobs.front() == aJob )
337 statusBar->CallAfter(
340 statusBar->ShowBackgroundProgressBar();
341 statusBar->SetBackgroundProgress( aJob->m_currentProgress );
342 statusBar->SetBackgroundProgressMax( aJob->m_maxProgress );
343 statusBar->SetBackgroundStatusText( aJob->m_status );
355 list->UpdateJob( aJob );
372 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.