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"
32 using namespace boost;
34 /** Must be called in the GUI thread */
35 JobManagerView::JobManagerView (wxWindow* parent)
38 _sizer = new wxFlexGridSizer (3, 6, 6);
39 _sizer->AddGrowableCol (1, 1);
42 Connect (wxID_ANY, wxEVT_TIMER, wxTimerEventHandler (JobManagerView::periodic), 0, this);
43 _timer.reset (new wxTimer (this));
50 JobManagerView::periodic (wxTimerEvent &)
55 /** Update the view by examining the state of each job.
56 * Must be called in the GUI thread.
59 JobManagerView::update ()
61 list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
63 for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
65 if (_job_records.find (*i) == _job_records.end ()) {
66 add_label_to_sizer (_sizer, this, (*i)->name ());
69 r.gauge = new wxGauge (this, wxID_ANY, 100);
70 _sizer->Add (r.gauge, 1, wxEXPAND);
71 r.informed_of_finish = false;
72 r.message = add_label_to_sizer (_sizer, this, "");
78 string const st = (*i)->status ();
80 if (!(*i)->finished ()) {
81 float const p = (*i)->overall_progress ();
83 _job_records[*i].message->SetLabel (std_to_wx (st));
84 _job_records[*i].gauge->SetValue (p * 100);
86 _job_records[*i].message->SetLabel (wxT ("Running"));
87 _job_records[*i].gauge->Pulse ();
91 /* Hack to work around our lack of cross-thread
92 signalling; we tell the job to emit_finished()
93 from here (the GUI thread).
96 if ((*i)->finished () && !_job_records[*i].informed_of_finish) {
97 _job_records[*i].gauge->SetValue (100);
98 _job_records[*i].message->SetLabel (std_to_wx (st));
101 (*i)->emit_finished ();
102 } catch (OpenFileError& e) {
104 s << "Error: " << e.what();
105 error_dialog (this, s.str ());
108 _job_records[*i].informed_of_finish = true;