2 Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 /** @file src/job_manager_view.cc
22 * @brief Class generating a GTK widget to show the progress of jobs.
25 #include "job_manager_view.h"
26 #include "batch_job_view.h"
27 #include "normal_job_view.h"
29 #include "lib/job_manager.h"
32 #include "lib/exceptions.h"
33 #include "lib/compose.hpp"
34 #include <boost/foreach.hpp>
42 using boost::shared_ptr;
43 using boost::weak_ptr;
45 #if BOOST_VERSION >= 106100
46 using namespace boost::placeholders;
49 /** @param parent Parent window.
50 * @param batch true to use BatchJobView, false to use NormalJobView.
52 * Must be called in the GUI thread.
54 JobManagerView::JobManagerView (wxWindow* parent, bool batch)
55 : wxScrolledWindow (parent)
58 _panel = new wxPanel (this);
59 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
60 sizer->Add (_panel, 1, wxEXPAND);
63 _table = new wxFlexGridSizer (2, 6, 6);
64 _table->AddGrowableCol (0, 1);
65 _panel->SetSizer (_table);
67 SetScrollRate (0, 32);
68 EnableScrolling (false, true);
70 Bind (wxEVT_TIMER, boost::bind (&JobManagerView::periodic, this));
71 _timer.reset (new wxTimer (this));
74 JobManager::instance()->JobAdded.connect (bind (&JobManagerView::job_added, this, _1));
75 JobManager::instance()->JobsReordered.connect (bind (&JobManagerView::replace, this));
79 JobManagerView::job_added (weak_ptr<Job> j)
81 shared_ptr<Job> job = j.lock ();
83 shared_ptr<JobView> v;
85 v.reset (new BatchJobView (job, this, _panel, _table));
87 v.reset (new NormalJobView (job, this, _panel, _table));
90 _job_records.push_back (v);
98 JobManagerView::periodic ()
100 for (list<shared_ptr<JobView> >::iterator i = _job_records.begin(); i != _job_records.end(); ++i) {
101 (*i)->maybe_pulse ();
106 JobManagerView::replace ()
108 /* Make a new version of _job_records which reflects the order in JobManager's job list */
110 list<shared_ptr<JobView> > new_job_records;
112 BOOST_FOREACH (shared_ptr<Job> i, JobManager::instance()->get()) {
113 /* Find this job's JobView */
114 BOOST_FOREACH (shared_ptr<JobView> j, _job_records) {
116 new_job_records.push_back (j);
122 BOOST_FOREACH (shared_ptr<JobView> i, _job_records) {
126 _job_records = new_job_records;
128 BOOST_FOREACH (shared_ptr<JobView> i, _job_records) {
129 i->insert (i->insert_position ());
136 JobManagerView::job_list_changed ()
138 BOOST_FOREACH (shared_ptr<JobView> i, _job_records) {
139 i->job_list_changed ();