Simple and optional messagebox notification when jobs finish.
authorCarl Hetherington <cth@carlh.net>
Fri, 11 May 2018 22:29:45 +0000 (23:29 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 27 May 2018 22:05:45 +0000 (23:05 +0100)
src/lib/config.cc
src/lib/config.h
src/wx/job_view.cc
src/wx/job_view.h

index e2f2bbeb97a81fff2ccbf19ae50798916394cd89..026c92c837f832886328c4273f07bf2e9fc49b08 100644 (file)
@@ -147,6 +147,7 @@ Config::set_defaults ()
        */
        _frames_in_memory_multiplier = 3;
        _decode_reduction = optional<int>();
+       _default_notify = false;
 
        _allowed_dcp_frame_rates.clear ();
        _allowed_dcp_frame_rates.push_back (24);
@@ -429,6 +430,7 @@ try
        }
        _frames_in_memory_multiplier = f.optional_number_child<int>("FramesInMemoryMultiplier").get_value_or(3);
        _decode_reduction = f.optional_number_child<int>("DecodeReduction");
+       _default_notify = f.optional_bool_child("DefaultNotify").get_value_or(false);
 
        /* Replace any cinemas from config.xml with those from the configured file */
        if (boost::filesystem::exists (_cinemas_file)) {
@@ -745,6 +747,9 @@ Config::write_config () const
                root->add_child("DecodeReduction")->add_child_text(raw_convert<string>(_decode_reduction.get()));
        }
 
+       /* [XML] DefaultNotify 1 to default jobs to notify when complete, otherwise 0 */
+       root->add_child("DefaultNotify")->add_child_text(_default_notify ? "1" : "0");
+
        try {
                doc.write_to_file_formatted(config_file().string());
        } catch (xmlpp::exception& e) {
index c625e92424247314004232d92d48264d1314520b..1e16fc840a607814bd8fcef1891151cb2918a569 100644 (file)
@@ -381,6 +381,10 @@ public:
                return _decode_reduction;
        }
 
+       bool default_notify () const {
+               return _default_notify;
+       }
+
        /* SET (mostly) */
 
        void set_master_encoding_threads (int n) {
@@ -662,6 +666,10 @@ public:
                maybe_set (_decode_reduction, r);
        }
 
+       void set_default_notify (bool n) {
+               maybe_set (_default_notify, n);
+       }
+
        void clear_history () {
                _history.clear ();
                changed ();
@@ -723,7 +731,7 @@ public:
 
        /** If set, this overrides the standard path (in home, Library, AppData or wherever) for config.xml and cinemas.xml */
        static boost::optional<boost::filesystem::path> override_path;
-       
+
 private:
        Config ();
        static boost::filesystem::path path (std::string file, bool create_directories = true);
@@ -850,6 +858,7 @@ private:
        boost::optional<DKDMWriteType> _last_dkdm_write_type;
        int _frames_in_memory_multiplier;
        boost::optional<int> _decode_reduction;
+       bool _default_notify;
 
        static int const _current_version;
 
index a36d6de8a56680834d2697251d49e0fd2865f5f6..b3b6ee68439ce9f294f07473949ff7a2e956951d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 #include "wx_util.h"
 #include "lib/job.h"
 #include "lib/compose.hpp"
+#include "lib/config.h"
 #include <wx/wx.h>
 
 using std::string;
 using std::min;
 using boost::shared_ptr;
+using boost::bind;
 
 JobView::JobView (shared_ptr<Job> job, wxWindow* parent, wxWindow* container, wxFlexGridSizer* table)
        : _job (job)
@@ -66,7 +68,14 @@ JobView::setup ()
 
        finish_setup (_container, _buttons);
 
-       _table->Insert (n, _buttons, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
+       _controls = new wxBoxSizer (wxVERTICAL);
+       _controls->Add (_buttons);
+       _notify = new wxCheckBox (_container, wxID_ANY, _("Notify when complete"));
+       _notify->Bind (wxEVT_CHECKBOX, bind (&JobView::notify_clicked, this));
+       _notify->SetValue (Config::instance()->default_notify());
+       _controls->Add (_notify);
+
+       _table->Insert (n, _controls, 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));
@@ -115,9 +124,14 @@ JobView::finished ()
        }
 
        _cancel->Enable (false);
+       _notify->Enable (false);
        if (!_job->error_details().empty ()) {
                _details->Enable (true);
        }
+
+       if (_notify->GetValue ()) {
+               wxMessageBox (std_to_wx(_job->name() + ": " + _job->status()), _("DCP-o-matic"), wxICON_INFORMATION);
+       }
 }
 
 void
@@ -140,7 +154,7 @@ 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->Insert (pos + 1, _controls, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
        _table->Layout ();
 }
 
@@ -148,5 +162,11 @@ void
 JobView::detach ()
 {
        _table->Detach (_gauge_message);
-       _table->Detach (_buttons);
+       _table->Detach (_controls);
+}
+
+void
+JobView::notify_clicked ()
+{
+       Config::instance()->set_default_notify (_notify->GetValue ());
 }
index 8c0214d9dc9438ad7e80a66ad68dbfc1559976ba..d58a90831e37ae075faa54f730fcc338f07e508a 100644 (file)
@@ -35,6 +35,7 @@ class wxGauge;
 class wxStaticText;
 class wxButton;
 class wxSizer;
+class wxCheckBox;
 
 class JobView : public boost::noncopyable
 {
@@ -59,7 +60,9 @@ protected:
 
        boost::shared_ptr<Job> _job;
        wxFlexGridSizer* _table;
+       /** sizer for buttons (cancel, details, pause etc.) */
        wxBoxSizer* _buttons;
+       /** sizer for the guage and the message underneath it */
        wxBoxSizer* _gauge_message;
 
 private:
@@ -69,6 +72,7 @@ private:
        void progress ();
        void details_clicked (wxCommandEvent &);
        void cancel_clicked (wxCommandEvent &);
+       void notify_clicked ();
 
        wxWindow* _parent;
        wxWindow* _container;
@@ -76,6 +80,9 @@ private:
        wxStaticText* _message;
        wxButton* _cancel;
        wxButton* _details;
+       wxCheckBox* _notify;
+       /** sizer for all right-hand-size controls */
+       wxBoxSizer* _controls;
        std::string _last_message;
 
        boost::signals2::scoped_connection _progress_connection;