2 Copyright (C) 2012-2018 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/>.
24 #include "lib/compose.hpp"
25 #include "lib/config.h"
30 using boost::shared_ptr;
33 JobView::JobView (shared_ptr<Job> job, wxWindow* parent, wxWindow* container, wxFlexGridSizer* table)
37 , _container (container)
46 int n = insert_position ();
48 _gauge_message = new wxBoxSizer (wxVERTICAL);
49 _gauge = new wxGauge (_container, wxID_ANY, 100);
50 /* This seems to be required to allow the gauge to shrink under OS X */
51 _gauge->SetMinSize (wxSize (0, -1));
52 _gauge_message->Add (_gauge, 0, wxEXPAND | wxLEFT | wxRIGHT);
53 _message = new wxStaticText (_container, wxID_ANY, wxT (" \n "), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_MIDDLE);
54 _gauge_message->Add (_message, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
55 _table->Insert (n, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
58 _buttons = new wxBoxSizer (wxHORIZONTAL);
60 _cancel = new wxButton (_container, wxID_ANY, _("Cancel"));
61 _cancel->Bind (wxEVT_BUTTON, &JobView::cancel_clicked, this);
62 _buttons->Add (_cancel, 1, wxALIGN_CENTER_VERTICAL);
64 _details = new wxButton (_container, wxID_ANY, _("Details..."));
65 _details->Bind (wxEVT_BUTTON, &JobView::details_clicked, this);
66 _details->Enable (false);
67 _buttons->Add (_details, 1, wxALIGN_CENTER_VERTICAL);
69 finish_setup (_container, _buttons);
71 _controls = new wxBoxSizer (wxVERTICAL);
72 _controls->Add (_buttons);
73 _notify = new wxCheckBox (_container, wxID_ANY, _("Notify when complete"));
74 _notify->Bind (wxEVT_CHECKBOX, bind (&JobView::notify_clicked, this));
75 _notify->SetValue (Config::instance()->default_notify());
76 _controls->Add (_notify);
78 _table->Insert (n, _controls, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
80 _progress_connection = _job->Progress.connect (boost::bind (&JobView::progress, this));
81 _finished_connection = _job->Finished.connect (boost::bind (&JobView::finished, this));
89 JobView::maybe_pulse ()
91 if (_gauge && _job->running() && !_job->progress()) {
99 string whole = "<b>" + _job->name () + "</b>\n";
100 if (!_job->sub_name().empty ()) {
101 whole += _job->sub_name() + " ";
103 whole += _job->status ();
104 if (whole != _last_message) {
105 _message->SetLabelMarkup (std_to_wx (whole));
106 /* This hack fixes the size of _message on OS X */
107 _message->InvalidateBestSize ();
108 _message->SetSize (_message->GetBestSize ());
109 _gauge_message->Layout ();
110 _last_message = whole;
112 if (_job->progress ()) {
113 _gauge->SetValue (min (100.0f, _job->progress().get() * 100));
122 if (!_job->finished_cancelled ()) {
123 _gauge->SetValue (100);
126 _cancel->Enable (false);
127 _notify->Enable (false);
128 if (!_job->error_details().empty ()) {
129 _details->Enable (true);
132 if (_notify->GetValue ()) {
133 wxMessageBox (std_to_wx(_job->name() + ": " + _job->status()), _("DCP-o-matic"), wxICON_INFORMATION);
138 JobView::details_clicked (wxCommandEvent &)
140 string s = _job->error_summary();
141 s[0] = toupper (s[0]);
142 error_dialog (_parent, std_to_wx(s), std_to_wx(_job->error_details()));
146 JobView::cancel_clicked (wxCommandEvent &)
148 if (confirm_dialog (_parent, _("Are you sure you want to cancel this job?"))) {
154 JobView::insert (int pos)
156 _table->Insert (pos, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
157 _table->Insert (pos + 1, _controls, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
164 _table->Detach (_gauge_message);
165 _table->Detach (_controls);
169 JobView::notify_clicked ()
171 Config::instance()->set_default_notify (_notify->GetValue ());