2 Copyright (C) 2012 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.
20 /** @file src/job_manager_view.cc
21 * @brief Class generating a GTK widget to show the progress of jobs.
24 #include "lib/job_manager.h"
27 #include "lib/exceptions.h"
28 #include "job_manager_view.h"
35 using boost::shared_ptr;
36 using boost::weak_ptr;
41 JobRecord (shared_ptr<Job> job, wxScrolledWindow* window, wxPanel* panel, wxFlexGridSizer* table, bool pause)
49 wxStaticText* m = new wxStaticText (panel, wxID_ANY, std_to_wx (_job->name ()));
50 table->Insert (n, m, 0, wxALIGN_CENTER_VERTICAL | wxALL, 6);
53 _gauge = new wxGauge (panel, wxID_ANY, 100);
54 table->Insert (n, _gauge, 1, wxEXPAND | wxLEFT | wxRIGHT);
57 _message = new wxStaticText (panel, wxID_ANY, std_to_wx (""));
58 table->Insert (n, _message, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
61 _cancel = new wxButton (panel, wxID_ANY, _("Cancel"));
62 _cancel->Bind (wxEVT_COMMAND_BUTTON_CLICKED, &JobRecord::cancel_clicked, this);
63 table->Insert (n, _cancel, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
67 _pause = new wxButton (_panel, wxID_ANY, _("Pause"));
68 _pause->Bind (wxEVT_COMMAND_BUTTON_CLICKED, &JobRecord::pause_clicked, this);
69 table->Insert (n, _pause, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
73 _details = new wxButton (_panel, wxID_ANY, _("Details..."));
74 _details->Bind (wxEVT_COMMAND_BUTTON_CLICKED, &JobRecord::details_clicked, this);
75 _details->Enable (false);
76 table->Insert (n, _details, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
79 job->Progress.connect (boost::bind (&JobRecord::progress, this));
80 job->Finished.connect (boost::bind (&JobRecord::finished, this));
90 float const p = _job->overall_progress ();
92 checked_set (_message, _job->status ());
93 _gauge->SetValue (p * 100);
95 checked_set (_message, wx_to_std (_("Running")));
100 _window->FitInside ();
105 checked_set (_message, _job->status ());
106 if (!_job->finished_cancelled ()) {
107 _gauge->SetValue (100);
110 _cancel->Enable (false);
111 if (!_job->error_details().empty ()) {
112 _details->Enable (true);
116 _window->FitInside ();
119 void details_clicked (wxCommandEvent &)
121 string s = _job->error_summary();
122 s[0] = toupper (s[0]);
123 error_dialog (_window, std_to_wx (String::compose ("%1.\n\n%2", s, _job->error_details())));
126 void cancel_clicked (wxCommandEvent &)
131 void pause_clicked (wxCommandEvent &)
133 if (_job->paused()) {
135 _pause->SetLabel (_("Pause"));
138 _pause->SetLabel (_("Resume"));
142 boost::shared_ptr<Job> _job;
143 wxScrolledWindow* _window;
145 wxFlexGridSizer* _table;
147 wxStaticText* _message;
153 /** Must be called in the GUI thread */
154 JobManagerView::JobManagerView (wxWindow* parent, Buttons buttons)
155 : wxScrolledWindow (parent)
158 _panel = new wxPanel (this);
159 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
160 sizer->Add (_panel, 1, wxEXPAND);
164 if (buttons & PAUSE) {
168 _table = new wxFlexGridSizer (N, 6, 6);
169 _table->AddGrowableCol (1, 1);
170 _panel->SetSizer (_table);
172 SetScrollRate (0, 32);
174 JobManager::instance()->JobAdded.connect (bind (&JobManagerView::job_added, this, _1));
178 JobManagerView::job_added (weak_ptr<Job> j)
180 shared_ptr<Job> job = j.lock ();
182 _job_records.push_back (shared_ptr<JobRecord> (new JobRecord (job, this, _panel, _table, _buttons & PAUSE)));