b32c695a907fa7e9b77c5bb0c4a0607a90a1bd70
[dcpomatic.git] / src / wx / job_manager_view.cc
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file src/job_manager_view.cc
21  *  @brief Class generating a GTK widget to show the progress of jobs.
22  */
23
24 #include "job_manager_view.h"
25 #include "job_view.h"
26 #include "wx_util.h"
27 #include "lib/job_manager.h"
28 #include "lib/job.h"
29 #include "lib/util.h"
30 #include "lib/exceptions.h"
31 #include "lib/compose.hpp"
32 #include <iostream>
33
34 using std::string;
35 using std::list;
36 using std::map;
37 using std::min;
38 using std::cout;
39 using boost::shared_ptr;
40 using boost::weak_ptr;
41
42 /** Must be called in the GUI thread */
43 JobManagerView::JobManagerView (wxWindow* parent)
44         : wxScrolledWindow (parent)
45 {
46         _panel = new wxPanel (this);
47         wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
48         sizer->Add (_panel, 1, wxEXPAND);
49         SetSizer (sizer);
50
51         _table = new wxFlexGridSizer (4, 4, 6);
52         _table->AddGrowableCol (0, 1);
53         _panel->SetSizer (_table);
54
55         SetScrollRate (0, 32);
56         EnableScrolling (false, true);
57
58         Bind (wxEVT_TIMER, boost::bind (&JobManagerView::periodic, this));
59         _timer.reset (new wxTimer (this));
60         _timer->Start (1000);
61
62         JobManager::instance()->JobAdded.connect (bind (&JobManagerView::job_added, this, _1));
63 }
64
65 void
66 JobManagerView::job_added (weak_ptr<Job> j)
67 {
68         shared_ptr<Job> job = j.lock ();
69         if (job) {
70                 _job_records.push_back (shared_ptr<JobView> (new JobView (job, this, _panel, _table)));
71         }
72 }
73
74 void
75 JobManagerView::periodic ()
76 {
77         for (list<shared_ptr<JobView> >::iterator i = _job_records.begin(); i != _job_records.end(); ++i) {
78                 (*i)->maybe_pulse ();
79         }
80 }