2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
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.
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.
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.
23 #include "lib/compose.hpp"
28 using boost::shared_ptr;
30 JobView::JobView (shared_ptr<Job> job, wxScrolledWindow* window, wxPanel* panel, wxFlexGridSizer* table)
37 _gauge_message = new wxBoxSizer (wxVERTICAL);
38 _gauge = new wxGauge (panel, wxID_ANY, 100);
39 /* This seems to be required to allow the gauge to shrink under OS X */
40 _gauge->SetMinSize (wxSize (0, -1));
41 _gauge_message->Add (_gauge, 0, wxEXPAND | wxLEFT | wxRIGHT);
42 _message = new wxStaticText (panel, wxID_ANY, wxT (" \n "));
43 _gauge_message->Add (_message, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
44 table->Insert (n, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
47 _cancel = new wxButton (panel, wxID_ANY, _("Cancel"));
48 _cancel->Bind (wxEVT_COMMAND_BUTTON_CLICKED, &JobView::cancel_clicked, this);
49 table->Insert (n, _cancel, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
52 _pause = new wxButton (_panel, wxID_ANY, _("Pause"));
53 _pause->Bind (wxEVT_COMMAND_BUTTON_CLICKED, &JobView::pause_clicked, this);
54 table->Insert (n, _pause, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
57 _details = new wxButton (_panel, wxID_ANY, _("Details..."));
58 _details->Bind (wxEVT_COMMAND_BUTTON_CLICKED, &JobView::details_clicked, this);
59 _details->Enable (false);
60 table->Insert (n, _details, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
63 _progress_connection = job->Progress.connect (boost::bind (&JobView::progress, this));
64 _finished_connection = job->Finished.connect (boost::bind (&JobView::finished, this));
72 JobView::maybe_pulse ()
74 if (_job->running() && !_job->progress ()) {
82 string whole = "<b>" + _job->name () + "</b>\n";
83 if (!_job->sub_name().empty ()) {
84 whole += _job->sub_name() + " ";
86 whole += _job->status ();
87 if (whole != _last_message) {
88 _message->SetLabelMarkup (std_to_wx (whole));
89 _gauge_message->Layout ();
90 _last_message = whole;
92 if (_job->progress ()) {
93 _gauge->SetValue (min (100.0f, _job->progress().get() * 100));
102 if (!_job->finished_cancelled ()) {
103 _gauge->SetValue (100);
106 _cancel->Enable (false);
107 _pause->Enable (false);
108 if (!_job->error_details().empty ()) {
109 _details->Enable (true);
114 JobView::details_clicked (wxCommandEvent &)
116 string s = _job->error_summary();
117 s[0] = toupper (s[0]);
118 error_dialog (_window, std_to_wx (String::compose ("%1.\n\n%2", s, _job->error_details())));
122 JobView::cancel_clicked (wxCommandEvent &)
128 JobView::pause_clicked (wxCommandEvent &)
130 if (_job->paused()) {
132 _pause->SetLabel (_("Pause"));
135 _pause->SetLabel (_("Resume"));