summaryrefslogtreecommitdiff
path: root/src/wx
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2017-01-28 00:35:55 +0000
committerCarl Hetherington <cth@carlh.net>2017-01-28 00:35:55 +0000
commitf5bc071ddac2355da1d116404cc37f4485e97699 (patch)
tree55da5257669b366fac0a6d9d214655f75867543a /src/wx
parent861267156da5960260c9a080dce94c0892fd012a (diff)
Add priority control buttons to batch converter (#961).
Diffstat (limited to 'src/wx')
-rw-r--r--src/wx/batch_job_view.cc46
-rw-r--r--src/wx/batch_job_view.h10
-rw-r--r--src/wx/job_manager_view.cc44
-rw-r--r--src/wx/job_manager_view.h2
-rw-r--r--src/wx/job_view.cc25
-rw-r--r--src/wx/job_view.h16
-rw-r--r--src/wx/normal_job_view.cc6
7 files changed, 134 insertions, 15 deletions
diff --git a/src/wx/batch_job_view.cc b/src/wx/batch_job_view.cc
index 2a5e690d7..772c726f2 100644
--- a/src/wx/batch_job_view.cc
+++ b/src/wx/batch_job_view.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -19,8 +19,11 @@
*/
#include "batch_job_view.h"
+#include "lib/job_manager.h"
#include <wx/sizer.h>
+#include <wx/button.h>
+using std::list;
using boost::shared_ptr;
BatchJobView::BatchJobView (shared_ptr<Job> job, wxWindow* parent, wxWindow* container, wxFlexGridSizer* table)
@@ -34,3 +37,44 @@ BatchJobView::insert_position () const
{
return _table->GetEffectiveRowsCount() * _table->GetEffectiveColsCount();
}
+
+void
+BatchJobView::finish_setup (wxWindow* parent, wxSizer* sizer)
+{
+ _higher_priority = new wxButton (parent, wxID_ANY, _("Higher prioirity"));
+ _higher_priority->Bind (wxEVT_BUTTON, boost::bind (&BatchJobView::higher_priority_clicked, this));
+ sizer->Add (_higher_priority, 1, wxALIGN_CENTER_VERTICAL);
+ _lower_priority = new wxButton (parent, wxID_ANY, _("Lower prioirity"));
+ _lower_priority->Bind (wxEVT_BUTTON, boost::bind (&BatchJobView::lower_priority_clicked, this));
+ sizer->Add (_lower_priority, 1, wxALIGN_CENTER_VERTICAL);
+}
+void
+BatchJobView::higher_priority_clicked ()
+{
+ JobManager::instance()->increase_priority (_job);
+}
+
+void
+BatchJobView::lower_priority_clicked ()
+{
+ JobManager::instance()->decrease_priority (_job);
+}
+
+void
+BatchJobView::job_list_changed ()
+{
+ bool high = false;
+ bool low = false;
+ list<shared_ptr<Job> > jobs = JobManager::instance()->get();
+ if (!jobs.empty ()) {
+ if (_job != jobs.front()) {
+ high = true;
+ }
+ if (_job != jobs.back()) {
+ low = true;
+ }
+ }
+
+ _higher_priority->Enable (high);
+ _lower_priority->Enable (low);
+}
diff --git a/src/wx/batch_job_view.h b/src/wx/batch_job_view.h
index d65596864..40dceff31 100644
--- a/src/wx/batch_job_view.h
+++ b/src/wx/batch_job_view.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -27,4 +27,12 @@ public:
private:
int insert_position () const;
+ void job_list_changed ();
+
+ void finish_setup (wxWindow* parent, wxSizer* sizer);
+ void higher_priority_clicked ();
+ void lower_priority_clicked ();
+
+ wxButton* _higher_priority;
+ wxButton* _lower_priority;
};
diff --git a/src/wx/job_manager_view.cc b/src/wx/job_manager_view.cc
index 6cea40c89..42d5f9dbe 100644
--- a/src/wx/job_manager_view.cc
+++ b/src/wx/job_manager_view.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -31,6 +31,7 @@
#include "lib/util.h"
#include "lib/exceptions.h"
#include "lib/compose.hpp"
+#include <boost/foreach.hpp>
#include <iostream>
using std::string;
@@ -40,6 +41,7 @@ using std::min;
using std::cout;
using boost::shared_ptr;
using boost::weak_ptr;
+using boost::bind;
/** @param parent Parent window.
* @param batch true to use BatchJobView, false to use NormalJobView.
@@ -67,6 +69,7 @@ JobManagerView::JobManagerView (wxWindow* parent, bool batch)
_timer->Start (1000);
JobManager::instance()->JobAdded.connect (bind (&JobManagerView::job_added, this, _1));
+ JobManager::instance()->JobsReordered.connect (bind (&JobManagerView::replace, this));
}
void
@@ -85,6 +88,7 @@ JobManagerView::job_added (weak_ptr<Job> j)
}
FitInside();
+ job_list_changed ();
}
void
@@ -94,3 +98,41 @@ JobManagerView::periodic ()
(*i)->maybe_pulse ();
}
}
+
+void
+JobManagerView::replace ()
+{
+ /* Make a new version of _job_records which reflects the order in JobManager's job list */
+
+ list<shared_ptr<JobView> > new_job_records;
+
+ BOOST_FOREACH (shared_ptr<Job> i, JobManager::instance()->get()) {
+ /* Find this job's JobView */
+ BOOST_FOREACH (shared_ptr<JobView> j, _job_records) {
+ if (j->job() == i) {
+ new_job_records.push_back (j);
+ break;
+ }
+ }
+ }
+
+ BOOST_FOREACH (shared_ptr<JobView> i, _job_records) {
+ i->detach ();
+ }
+
+ _job_records = new_job_records;
+
+ BOOST_FOREACH (shared_ptr<JobView> i, _job_records) {
+ i->insert (i->insert_position ());
+ }
+
+ job_list_changed ();
+}
+
+void
+JobManagerView::job_list_changed ()
+{
+ BOOST_FOREACH (shared_ptr<JobView> i, _job_records) {
+ i->job_list_changed ();
+ }
+}
diff --git a/src/wx/job_manager_view.h b/src/wx/job_manager_view.h
index 7784c71ee..77114a97c 100644
--- a/src/wx/job_manager_view.h
+++ b/src/wx/job_manager_view.h
@@ -40,6 +40,8 @@ public:
private:
void job_added (boost::weak_ptr<Job>);
void periodic ();
+ void replace ();
+ void job_list_changed ();
wxPanel* _panel;
wxFlexGridSizer* _table;
diff --git a/src/wx/job_view.cc b/src/wx/job_view.cc
index 8e7040c3b..13c3bc7ab 100644
--- a/src/wx/job_view.cc
+++ b/src/wx/job_view.cc
@@ -52,20 +52,20 @@ JobView::setup ()
_table->Insert (n, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
++n;
- wxBoxSizer* buttons = new wxBoxSizer (wxHORIZONTAL);
+ _buttons = new wxBoxSizer (wxHORIZONTAL);
_cancel = new wxButton (_container, wxID_ANY, _("Cancel"));
_cancel->Bind (wxEVT_BUTTON, &JobView::cancel_clicked, this);
- buttons->Add (_cancel, 1, wxALIGN_CENTER_VERTICAL);
+ _buttons->Add (_cancel, 1, wxALIGN_CENTER_VERTICAL);
_details = new wxButton (_container, wxID_ANY, _("Details..."));
_details->Bind (wxEVT_BUTTON, &JobView::details_clicked, this);
_details->Enable (false);
- buttons->Add (_details, 1, wxALIGN_CENTER_VERTICAL);
+ _buttons->Add (_details, 1, wxALIGN_CENTER_VERTICAL);
- finish_setup (_container, buttons);
+ finish_setup (_container, _buttons);
- _table->Insert (n, buttons, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
+ _table->Insert (n, _buttons, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
_progress_connection = _job->Progress.connect (boost::bind (&JobView::progress, this));
_finished_connection = _job->Finished.connect (boost::bind (&JobView::finished, this));
@@ -134,3 +134,18 @@ JobView::cancel_clicked (wxCommandEvent &)
_job->cancel ();
}
}
+
+void
+JobView::insert (int pos)
+{
+ _table->Insert (pos, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
+ _table->Insert (pos + 1, _buttons, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
+ _table->Layout ();
+}
+
+void
+JobView::detach ()
+{
+ _table->Detach (_gauge_message);
+ _table->Detach (_buttons);
+}
diff --git a/src/wx/job_view.h b/src/wx/job_view.h
index 8cd34fdab..8c0214d9d 100644
--- a/src/wx/job_view.h
+++ b/src/wx/job_view.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -42,19 +42,28 @@ public:
JobView (boost::shared_ptr<Job> job, wxWindow* parent, wxWindow* container, wxFlexGridSizer* table);
virtual ~JobView () {}
- void setup ();
+ virtual int insert_position () const = 0;
+ virtual void job_list_changed () {}
+ void setup ();
void maybe_pulse ();
+ void insert (int pos);
+ void detach ();
+
+ boost::shared_ptr<Job> job () const {
+ return _job;
+ }
protected:
virtual void finished ();
boost::shared_ptr<Job> _job;
wxFlexGridSizer* _table;
+ wxBoxSizer* _buttons;
+ wxBoxSizer* _gauge_message;
private:
- virtual int insert_position () const = 0;
virtual void finish_setup (wxWindow *, wxSizer *) {}
void progress ();
@@ -63,7 +72,6 @@ private:
wxWindow* _parent;
wxWindow* _container;
- wxBoxSizer* _gauge_message;
wxGauge* _gauge;
wxStaticText* _message;
wxButton* _cancel;
diff --git a/src/wx/normal_job_view.cc b/src/wx/normal_job_view.cc
index 9bfa332c9..22b3e1cc7 100644
--- a/src/wx/normal_job_view.cc
+++ b/src/wx/normal_job_view.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -48,11 +48,11 @@ NormalJobView::insert_position () const
void
NormalJobView::pause_clicked ()
{
- if (_job->paused()) {
+ if (_job->paused_by_user()) {
_job->resume ();
_pause->SetLabel (_("Pause"));
} else {
- _job->pause ();
+ _job->pause_by_user ();
_pause->SetLabel (_("Resume"));
}
}