Fix various bad automatic merges in i18n files.
[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 JobView::JobView (shared_ptr<Job> job, wxWindow* parent, wxWindow* container, wxFlexGridSizer* table)
32         : _job (job)
33         , _table (table)
34         , _parent (parent)
35         , _container (container)
36 {
37
38 }
39
40 void
41 JobView::setup ()
42 {
43         int n = insert_position ();
44
45         std::cout << "insert @ " << n << "\n";
46
47         _gauge_message = new wxBoxSizer (wxVERTICAL);
48         _gauge = new wxGauge (_container, wxID_ANY, 100);
49         /* This seems to be required to allow the gauge to shrink under OS X */
50         _gauge->SetMinSize (wxSize (0, -1));
51         _gauge_message->Add (_gauge, 0, wxEXPAND | wxLEFT | wxRIGHT);
52         _message = new wxStaticText (_container, wxID_ANY, wxT (" \n "));
53         _gauge_message->Add (_message, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
54         _table->Insert (n, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
55         ++n;
56
57         wxBoxSizer* buttons = new wxBoxSizer (wxHORIZONTAL);
58
59         _cancel = new wxButton (_container, wxID_ANY, _("Cancel"));
60         _cancel->Bind (wxEVT_COMMAND_BUTTON_CLICKED, &JobView::cancel_clicked, this);
61         buttons->Add (_cancel, 1, wxALIGN_CENTER_VERTICAL);
62
63         _details = new wxButton (_container, wxID_ANY, _("Details..."));
64         _details->Bind (wxEVT_COMMAND_BUTTON_CLICKED, &JobView::details_clicked, this);
65         _details->Enable (false);
66         buttons->Add (_details, 1, wxALIGN_CENTER_VERTICAL);
67
68         finish_setup (_container, buttons);
69
70         _table->Insert (n, buttons, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
71
72         _progress_connection = _job->Progress.connect (boost::bind (&JobView::progress, this));
73         _finished_connection = _job->Finished.connect (boost::bind (&JobView::finished, this));
74
75         progress ();
76
77         _table->Layout ();
78 }
79
80 void
81 JobView::maybe_pulse ()
82 {
83         if (_job->running() && !_job->progress ()) {
84                 _gauge->Pulse ();
85         }
86 }
87
88 void
89 JobView::progress ()
90 {
91         string whole = "<b>" + _job->name () + "</b>\n";
92         if (!_job->sub_name().empty ()) {
93                 whole += _job->sub_name() + " ";
94         }
95         whole += _job->status ();
96         if (whole != _last_message) {
97                 _message->SetLabelMarkup (std_to_wx (whole));
98                 _gauge_message->Layout ();
99                 _last_message = whole;
100         }
101         if (_job->progress ()) {
102                 _gauge->SetValue (min (100.0f, _job->progress().get() * 100));
103         }
104 }
105
106 void
107 JobView::finished ()
108 {
109         progress ();
110
111         if (!_job->finished_cancelled ()) {
112                 _gauge->SetValue (100);
113         }
114
115         _cancel->Enable (false);
116         if (!_job->error_details().empty ()) {
117                 _details->Enable (true);
118         }
119 }
120
121 void
122 JobView::details_clicked (wxCommandEvent &)
123 {
124         string s = _job->error_summary();
125         s[0] = toupper (s[0]);
126         error_dialog (_parent, std_to_wx (String::compose ("%1.\n\n%2", s, _job->error_details())));
127 }
128
129 void
130 JobView::cancel_clicked (wxCommandEvent &)
131 {
132         if (confirm_dialog (_parent, _("Are you sure you want to cancel this job?"))) {
133                 _job->cancel ();
134         }
135 }