e70622b30e8b0cb6c0e66b85f45e4265949ee437
[dcpomatic.git] / src / wx / job_manager_view.cc
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 /** @file src/job_manager_view.cc
22  *  @brief Class generating a GTK widget to show the progress of jobs.
23  */
24
25 #include "job_manager_view.h"
26 #include "job_view.h"
27 #include "wx_util.h"
28 #include "lib/job_manager.h"
29 #include "lib/job.h"
30 #include "lib/util.h"
31 #include "lib/exceptions.h"
32 #include "lib/compose.hpp"
33 #include <iostream>
34
35 using std::string;
36 using std::list;
37 using std::map;
38 using std::min;
39 using std::cout;
40 using boost::shared_ptr;
41 using boost::weak_ptr;
42
43 /** @param parent Parent window.
44  *  @param latest_at_top true to put the last-added job at the top of the view,
45  *  false to put it at the bottom.
46  *
47  *  Must be called in the GUI thread.
48  */
49 JobManagerView::JobManagerView (wxWindow* parent, bool latest_at_top)
50         : wxScrolledWindow (parent)
51         , _latest_at_top (latest_at_top)
52 {
53         _panel = new wxPanel (this);
54         wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
55         sizer->Add (_panel, 1, wxEXPAND);
56         SetSizer (sizer);
57
58         _table = new wxFlexGridSizer (4, 4, 6);
59         _table->AddGrowableCol (0, 1);
60         _panel->SetSizer (_table);
61
62         SetScrollRate (0, 32);
63         EnableScrolling (false, true);
64
65         Bind (wxEVT_TIMER, boost::bind (&JobManagerView::periodic, this));
66         _timer.reset (new wxTimer (this));
67         _timer->Start (1000);
68
69         JobManager::instance()->JobAdded.connect (bind (&JobManagerView::job_added, this, _1));
70 }
71
72 void
73 JobManagerView::job_added (weak_ptr<Job> j)
74 {
75         shared_ptr<Job> job = j.lock ();
76         if (job) {
77                 _job_records.push_back (shared_ptr<JobView> (new JobView (job, this, _panel, _table, _latest_at_top)));
78         }
79
80         FitInside();
81 }
82
83 void
84 JobManagerView::periodic ()
85 {
86         for (list<shared_ptr<JobView> >::iterator i = _job_records.begin(); i != _job_records.end(); ++i) {
87                 (*i)->maybe_pulse ();
88         }
89 }