Use a virtual method rather than a set of nasty dynamic casts.
authorCarl Hetherington <cth@carlh.net>
Sat, 4 Dec 2021 23:24:56 +0000 (00:24 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 6 Dec 2021 21:42:06 +0000 (22:42 +0100)
src/lib/analyse_audio_job.h
src/lib/job.h
src/lib/transcode_job.h
src/wx/job_view.cc

index 864a6a7cd738442d8bd119418f7a6a866947ce28..f8311da4724c2b3304be13a9bcc4dd3792a0421b 100644 (file)
@@ -54,9 +54,12 @@ public:
        AnalyseAudioJob (std::shared_ptr<const Film>, std::shared_ptr<const Playlist>, bool from_zero);
        ~AnalyseAudioJob ();
 
-       std::string name () const;
-       std::string json_name () const;
-       void run ();
+       std::string name () const override;
+       std::string json_name () const override;
+       void run () override;
+       bool enable_notify () const override {
+               return true;
+       }
 
        boost::filesystem::path path () const {
                return _path;
index b44fd1365ee503c6479f6148907145d473d656ff..8b89fd0c383fbbb41c4bb76183588b2a583b08b0 100644 (file)
@@ -50,6 +50,10 @@ public:
        virtual std::string json_name () const = 0;
        /** Run this job in the current thread. */
        virtual void run () = 0;
+       /** @return true if it should be possible to notify when this job finishes */
+       virtual bool enable_notify () const {
+               return false;
+       }
 
        void start ();
        bool pause_by_user ();
index 368a9b685117ff6425e0a43207032a05450e960e..6b2e8f9235d3637bddc22789ee63d6ec2ea8087f 100644 (file)
@@ -57,6 +57,9 @@ public:
        std::string json_name () const override;
        void run () override;
        std::string status () const override;
+       bool enable_notify () const override {
+               return true;
+       }
 
        void set_encoder (std::shared_ptr<Encoder> t);
 
index 77620142473af4a6d0823da4c283d2ffefbad0d9..06d10401f578c23a980fc92279aceea1d380930b 100644 (file)
@@ -40,7 +40,6 @@ using std::string;
 using std::min;
 using std::shared_ptr;
 using boost::bind;
-using std::dynamic_pointer_cast;
 
 
 JobView::JobView (shared_ptr<Job> job, wxWindow* parent, wxWindow* container, wxFlexGridSizer* table)
@@ -159,7 +158,7 @@ JobView::finished ()
                d->Destroy ();
        }
 
-       if ((dynamic_pointer_cast<TranscodeJob>(_job) || dynamic_pointer_cast<AnalyseAudioJob>(_job)) && _notify->GetValue()) {
+       if (_job->enable_notify() && _notify->GetValue()) {
                if (Config::instance()->notification(Config::MESSAGE_BOX)) {
                        wxMessageBox (std_to_wx(_job->name() + ": " + _job->status()), _("DCP-o-matic"), wxICON_INFORMATION);
                }