21#include <unordered_map>
26#include <wx/settings.h>
27#include <wx/scrolwin.h>
29#include <wx/stattext.h>
40 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxSize( -1, 75 ),
44 SetSizeHints( wxDefaultSize, wxDefaultSize );
46 wxBoxSizer* mainSizer;
47 mainSizer =
new wxBoxSizer( wxVERTICAL );
49 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) );
51 m_stName =
new wxStaticText(
this, wxID_ANY, aJob->m_name );
53 m_stName->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT,
54 wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD,
false,
56 mainSizer->Add(
m_stName, 0, wxALL | wxEXPAND, 1 );
58 m_stStatus =
new wxStaticText(
this, wxID_ANY, aJob->m_status, wxDefaultPosition,
61 mainSizer->Add(
m_stStatus, 0, wxALL | wxEXPAND, 1 );
63 m_progress =
new wxGauge(
this, wxID_ANY, aJob->m_maxProgress, wxDefaultPosition,
64 wxDefaultSize, wxGA_HORIZONTAL );
66 mainSizer->Add(
m_progress, 0, wxALL | wxEXPAND, 1 );
68 SetSizer( mainSizer );
86 std::shared_ptr<BACKGROUND_JOB>
m_job;
94 wxFrame( parent, wxID_ANY,
_(
"Background Jobs" ), pos, wxSize( 300, 150 ),
95 wxFRAME_NO_TASKBAR | wxBORDER_SIMPLE )
97 SetSizeHints( wxDefaultSize, wxDefaultSize );
100 bSizer1 =
new wxBoxSizer( wxVERTICAL );
103 wxSize( -1, -1 ), wxVSCROLL );
127 void Add( std::shared_ptr<BACKGROUND_JOB> aJob )
141 void Remove( std::shared_ptr<BACKGROUND_JOB> aJob )
172 const std::shared_ptr<BACKGROUND_JOB>& aJob ) :
189 m_job->m_status = aMessage;
213 m_job->m_maxProgress.store( 1000 );
214 m_job->m_currentProgress.store(
static_cast<int>( 1000 * aProgress ) );
227 std::shared_ptr<BACKGROUND_JOB> job = std::make_shared<BACKGROUND_JOB>();
230 job->m_reporter = std::make_shared<BACKGROUND_JOB_REPORTER>(
this, job );
232 std::lock_guard<std::shared_mutex> lock(
m_mutex );
263 list->Remove( aJob );
268 std::lock_guard<std::shared_mutex> lock(
m_mutex );
270 [&]( std::shared_ptr<BACKGROUND_JOB> job )
283 statusBar->CallAfter(
286 statusBar->HideBackgroundProgressBar();
287 statusBar->SetBackgroundStatusText( wxT(
"" ) );
301 return dialog == evtWindow;
312 std::shared_lock<std::shared_mutex> lock(
m_mutex, std::try_to_lock );
314 for(
const std::shared_ptr<BACKGROUND_JOB>& job :
m_jobs )
324 wxSize windowSize = list->GetSize();
325 list->SetPosition( aPos - windowSize );
333 std::shared_lock<std::shared_mutex> lock(
m_mutex, std::try_to_lock );
340 if(
m_jobs.front() == aJob )
345 statusBar->CallAfter(
348 statusBar->ShowBackgroundProgressBar();
349 statusBar->SetBackgroundProgressMax( aJob->m_maxProgress );
350 statusBar->SetBackgroundProgress( aJob->m_currentProgress );
351 statusBar->SetBackgroundStatusText( aJob->m_status );
363 list->UpdateJob( aJob );
371 std::shared_ptr<BACKGROUND_JOB> frontJob;
374 std::lock_guard<std::shared_mutex> lock(
m_mutex );
379 frontJob =
m_jobs.front();
390 std::lock_guard<std::shared_mutex> lock(
m_mutex );
394 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.
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)
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.