Reverse order of jobs in the batch converter view.
[dcpomatic.git] / src / wx / job_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 #include "job_view.h"
22 #include "wx_util.h"
23 #include "lib/job.h"
24 #include "lib/compose.hpp"
25 #include <wx/wx.h>
26
27 using std::string;
28 using std::min;
29 using boost::shared_ptr;
30
31 /** @param top Put this view at the top of table, otherwise put it at the bottom */
32 JobView::JobView (shared_ptr<Job> job, wxWindow* parent, wxWindow* container, wxFlexGridSizer* table, bool top)
33         : _job (job)
34         , _parent (parent)
35 {
36         int n = top ? 0 : (table->GetEffectiveRowsCount() * table->GetEffectiveColsCount());
37
38         _gauge_message = new wxBoxSizer (wxVERTICAL);
39         _gauge = new wxGauge (container, wxID_ANY, 100);
40         /* This seems to be required to allow the gauge to shrink under OS X */
41         _gauge->SetMinSize (wxSize (0, -1));
42         _gauge_message->Add (_gauge, 0, wxEXPAND | wxLEFT | wxRIGHT);
43         _message = new wxStaticText (container, wxID_ANY, wxT (" \n "));
44         _gauge_message->Add (_message, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
45         table->Insert (n, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
46         ++n;
47
48         _cancel = new wxButton (container, wxID_ANY, _("Cancel"));
49         _cancel->Bind (wxEVT_COMMAND_BUTTON_CLICKED, &JobView::cancel_clicked, this);
50         table->Insert (n, _cancel, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
51         ++n;
52
53         _pause = new wxButton (container, wxID_ANY, _("Pause"));
54         _pause->Bind (wxEVT_COMMAND_BUTTON_CLICKED, &JobView::pause_clicked, this);
55         table->Insert (n, _pause, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
56         ++n;
57
58         _details = new wxButton (container, wxID_ANY, _("Details..."));
59         _details->Bind (wxEVT_COMMAND_BUTTON_CLICKED, &JobView::details_clicked, this);
60         _details->Enable (false);
61         table->Insert (n, _details, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
62         ++n;
63
64         _progress_connection = job->Progress.connect (boost::bind (&JobView::progress, this));
65         _finished_connection = job->Finished.connect (boost::bind (&JobView::finished, this));
66
67         progress ();
68
69         table->Layout ();
70 }
71
72 void
73 JobView::maybe_pulse ()
74 {
75         if (_job->running() && !_job->progress ()) {
76                 _gauge->Pulse ();
77         }
78 }
79
80 void
81 JobView::progress ()
82 {
83         string whole = "<b>" + _job->name () + "</b>\n";
84         if (!_job->sub_name().empty ()) {
85                 whole += _job->sub_name() + " ";
86         }
87         whole += _job->status ();
88         if (whole != _last_message) {
89                 _message->SetLabelMarkup (std_to_wx (whole));
90                 _gauge_message->Layout ();
91                 _last_message = whole;
92         }
93         if (_job->progress ()) {
94                 _gauge->SetValue (min (100.0f, _job->progress().get() * 100));
95         }
96 }
97
98 void
99 JobView::finished ()
100 {
101         progress ();
102
103         if (!_job->finished_cancelled ()) {
104                 _gauge->SetValue (100);
105         }
106
107         _cancel->Enable (false);
108         _pause->Enable (false);
109         if (!_job->error_details().empty ()) {
110                 _details->Enable (true);
111         }
112 }
113
114 void
115 JobView::details_clicked (wxCommandEvent &)
116 {
117         string s = _job->error_summary();
118         s[0] = toupper (s[0]);
119         error_dialog (_parent, std_to_wx (String::compose ("%1.\n\n%2", s, _job->error_details())));
120 }
121
122 void
123 JobView::cancel_clicked (wxCommandEvent &)
124 {
125         if (confirm_dialog (_parent, _("Are you sure you want to cancel this job?"))) {
126                 _job->cancel ();
127         }
128 }
129
130 void
131 JobView::pause_clicked (wxCommandEvent &)
132 {
133         if (_job->paused()) {
134                 _job->resume ();
135                 _pause->SetLabel (_("Pause"));
136         } else {
137                 _job->pause ();
138                 _pause->SetLabel (_("Resume"));
139         }
140 }