2 Copyright (C) 2012-2015 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"
29 using boost::shared_ptr;
31 JobView::JobView (shared_ptr<Job> job, wxWindow* parent, wxWindow* container, wxFlexGridSizer* table)
35 , _container (container)
44 int n = insert_position ();
46 _gauge_message = new wxBoxSizer (wxVERTICAL);
47 _gauge = new wxGauge (_container, wxID_ANY, 100);
48 /* This seems to be required to allow the gauge to shrink under OS X */
49 _gauge->SetMinSize (wxSize (0, -1));
50 _gauge_message->Add (_gauge, 0, wxEXPAND | wxLEFT | wxRIGHT);
51 _message = new wxStaticText (_container, wxID_ANY, wxT (" \n "), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_MIDDLE);
52 _gauge_message->Add (_message, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
53 _table->Insert (n, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
56 _buttons = new wxBoxSizer (wxHORIZONTAL);
58 _cancel = new wxButton (_container, wxID_ANY, _("Cancel"));
59 _cancel->Bind (wxEVT_BUTTON, &JobView::cancel_clicked, this);
60 _buttons->Add (_cancel, 1, wxALIGN_CENTER_VERTICAL);
62 _details = new wxButton (_container, wxID_ANY, _("Details..."));
63 _details->Bind (wxEVT_BUTTON, &JobView::details_clicked, this);
64 _details->Enable (false);
65 _buttons->Add (_details, 1, wxALIGN_CENTER_VERTICAL);
67 finish_setup (_container, _buttons);
69 _table->Insert (n, _buttons, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
71 _progress_connection = _job->Progress.connect (boost::bind (&JobView::progress, this));
72 _finished_connection = _job->Finished.connect (boost::bind (&JobView::finished, this));
80 JobView::maybe_pulse ()
82 if (_gauge && _job->running() && !_job->progress()) {
90 string whole = "<b>" + _job->name () + "</b>\n";
91 if (!_job->sub_name().empty ()) {
92 whole += _job->sub_name() + " ";
94 whole += _job->status ();
95 if (whole != _last_message) {
96 _message->SetLabelMarkup (std_to_wx (whole));
97 /* This hack fixes the size of _message on OS X */
98 _message->InvalidateBestSize ();
99 _message->SetSize (_message->GetBestSize ());
100 _gauge_message->Layout ();
101 _last_message = whole;
103 if (_job->progress ()) {
104 _gauge->SetValue (min (100.0f, _job->progress().get() * 100));
113 if (!_job->finished_cancelled ()) {
114 _gauge->SetValue (100);
117 _cancel->Enable (false);
118 if (!_job->error_details().empty ()) {
119 _details->Enable (true);
124 JobView::details_clicked (wxCommandEvent &)
126 string s = _job->error_summary();
127 s[0] = toupper (s[0]);
128 error_dialog (_parent, std_to_wx(s), std_to_wx(_job->error_details()));
132 JobView::cancel_clicked (wxCommandEvent &)
134 if (confirm_dialog (_parent, _("Are you sure you want to cancel this job?"))) {
140 JobView::insert (int pos)
142 _table->Insert (pos, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
143 _table->Insert (pos + 1, _buttons, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
150 _table->Detach (_gauge_message);
151 _table->Detach (_buttons);