Tidy up now we have a x-thread signaller.
authorCarl Hetherington <cth@carlh.net>
Wed, 24 Oct 2012 19:12:43 +0000 (20:12 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 24 Oct 2012 19:12:43 +0000 (20:12 +0100)
src/lib/copy_from_dvd_job.cc
src/lib/examine_content_job.cc
src/lib/film.cc
src/lib/film.h
src/lib/job.cc
src/lib/job.h
src/wx/job_manager_view.cc
src/wx/job_manager_view.h

index c43723aa03a33895daa0e689807040ff8643de55..573dd7866742b0f43edeeee37147578d47dd8127 100644 (file)
@@ -93,6 +93,25 @@ CopyFromDVDJob::run ()
                }
        }
 
+       const string dvd_dir = _film->dir ("dvd");
+
+       string largest_file;
+       uintmax_t largest_size = 0;
+       for (filesystem::directory_iterator i = filesystem::directory_iterator (dvd_dir); i != filesystem::directory_iterator(); ++i) {
+               uintmax_t const s = filesystem::file_size (*i);
+               if (s > largest_size) {
+
+#if BOOST_FILESYSTEM_VERSION == 3              
+                       largest_file = filesystem::path(*i).generic_string();
+#else
+                       largest_file = i->string ();
+#endif
+                       largest_size = s;
+               }
+       }
+
+       _film->set_content (largest_file);
+       
        int const r = pclose (f);
        if (WEXITSTATUS (r) != 0) {
                set_error ("call to vobcopy failed");
index 0187e17767f45bbfa008d27cc2778d1943ac209f..8fadce2f66a93404b17aaafef44c31a36a99fe93 100644 (file)
@@ -21,6 +21,7 @@
  *  @brief A class to run through content at high speed to find its length.
  */
 
+#include <boost/filesystem.hpp>
 #include "examine_content_job.h"
 #include "options.h"
 #include "decoder_factory.h"
@@ -98,6 +99,28 @@ ExamineContentJob::run ()
                
        }
 
+       string const tdir = _film->dir ("thumbs");
+       vector<int> thumbs;
+
+       for (filesystem::directory_iterator i = filesystem::directory_iterator (tdir); i != filesystem::directory_iterator(); ++i) {
+
+               /* Aah, the sweet smell of progress */
+#if BOOST_FILESYSTEM_VERSION == 3              
+               string const l = filesystem::path(*i).leaf().generic_string();
+#else
+               string const l = i->leaf ();
+#endif
+               
+               size_t const d = l.find (".png");
+               size_t const t = l.find (".tmp");
+               if (d != string::npos && t == string::npos) {
+                       thumbs.push_back (atoi (l.substr (0, d).c_str()));
+               }
+       }
+
+       sort (thumbs.begin(), thumbs.end());
+       _film->set_thumbs (thumbs);     
+
        ascend ();
        set_progress (1);
        set_state (FINISHED_OK);
index 8afa1e245969b1a7d95856c1b2ddaeebd8f5b9f0..8b7700445abd28252926502005082e085d7fcfa8 100644 (file)
@@ -273,29 +273,6 @@ Film::make_dcp (bool transcode)
        JobManager::instance()->add (shared_ptr<Job> (new MakeDCPJob (shared_from_this(), o, r)));
 }
 
-void
-Film::copy_from_dvd_post_gui ()
-{
-       const string dvd_dir = dir ("dvd");
-
-       string largest_file;
-       uintmax_t largest_size = 0;
-       for (filesystem::directory_iterator i = filesystem::directory_iterator (dvd_dir); i != filesystem::directory_iterator(); ++i) {
-               uintmax_t const s = filesystem::file_size (*i);
-               if (s > largest_size) {
-
-#if BOOST_FILESYSTEM_VERSION == 3              
-                       largest_file = filesystem::path(*i).generic_string();
-#else
-                       largest_file = i->string ();
-#endif
-                       largest_size = s;
-               }
-       }
-
-       set_content (largest_file);
-}
-
 /** Start a job to examine our content file */
 void
 Film::examine_content ()
@@ -311,40 +288,16 @@ Film::examine_content ()
        dir ("thumbs");
        
        _examine_content_job.reset (new ExamineContentJob (shared_from_this(), shared_ptr<Job> ()));
-       _examine_content_job->Finished.connect (sigc::mem_fun (*this, &Film::examine_content_post_gui));
+       _examine_content_job->Finished.connect (sigc::mem_fun (*this, &Film::examine_content_finished));
        JobManager::instance()->add (_examine_content_job);
 }
 
 void
-Film::examine_content_post_gui ()
+Film::examine_content_finished ()
 {
-       set_length (_examine_content_job->last_video_frame ());
        _examine_content_job.reset ();
-
-       string const tdir = dir ("thumbs");
-       vector<int> thumbs;
-
-       for (filesystem::directory_iterator i = filesystem::directory_iterator (tdir); i != filesystem::directory_iterator(); ++i) {
-
-               /* Aah, the sweet smell of progress */
-#if BOOST_FILESYSTEM_VERSION == 3              
-               string const l = filesystem::path(*i).leaf().generic_string();
-#else
-               string const l = i->leaf ();
-#endif
-               
-               size_t const d = l.find (".png");
-               size_t const t = l.find (".tmp");
-               if (d != string::npos && t == string::npos) {
-                       thumbs.push_back (atoi (l.substr (0, d).c_str()));
-               }
-       }
-
-       sort (thumbs.begin(), thumbs.end());
-       set_thumbs (thumbs);    
 }
 
-
 /** @return full paths to any audio files that this Film has */
 vector<string>
 Film::audio_files () const
@@ -369,7 +322,6 @@ void
 Film::copy_from_dvd ()
 {
        shared_ptr<Job> j (new CopyFromDVDJob (shared_from_this(), shared_ptr<Job> ()));
-       j->Finished.connect (sigc::mem_fun (*this, &Film::copy_from_dvd_post_gui));
        JobManager::instance()->add (j);
 }
 
index bf5fb936d5b0aea7c768c6e58d8e775e0c0fa6ae..384cf85109757e73fbbad4b6cf197a3410738d9c 100644 (file)
@@ -61,9 +61,7 @@ public:
        std::vector<std::string> audio_files () const;
        std::pair<Position, std::string> thumb_subtitle (int) const;
 
-       void copy_from_dvd_post_gui ();
        void examine_content ();
-       void examine_content_post_gui ();
        void send_dcp_to_tms ();
        void copy_from_dvd ();
 
@@ -392,6 +390,7 @@ private:
        std::string thumb_base_for_frame (int) const;
        void signal_changed (Property);
        std::string file_locked (std::string) const;
+       void examine_content_finished ();
        
        /** Complete path to directory containing the film metadata;
         *  must not be relative.
index f3d7deac02a4c5426674b0765083c3c8dbc55b6d..a7c2430b8b30eed2a439eccdb5f1a59a8255b702 100644 (file)
@@ -125,20 +125,10 @@ Job::set_state (State s)
 
        if (_state == FINISHED_OK || _state == FINISHED_ERROR) {
                _ran_for = elapsed_time ();
+               Finished ();
        }
 }
 
-/** A hack to work around our lack of cross-thread
- *  signalling; this emits Finished, and listeners
- *  assume that it will be emitted in the GUI thread,
- *  so this method must be called from the GUI thread.
- */
-void
-Job::emit_finished ()
-{
-       Finished ();
-}
-
 /** @return Time (in seconds) that this job has been running */
 int
 Job::elapsed_time () const
index b608f5da2b1ce028567e90642479fa8b8f537d86..1ada68e1f41fa751e1ce8ce2f475a77f37b0d03d 100644 (file)
@@ -64,13 +64,10 @@ public:
        void descend (float);
        float overall_progress () const;
 
-       void emit_finished ();
-
        boost::shared_ptr<Job> required () const {
                return _required;
        }
 
-       /** Emitted from the GUI thread */
        sigc::signal0<void> Finished;
 
 protected:
index 97da3936fdd4b96e1e4ba547fe7bdcd407aacfbd..a6eef6e34752d643a309069a278b669992f7d820 100644 (file)
@@ -79,7 +79,6 @@ JobManagerView::update ()
                        r.gauge = new wxGauge (_panel, wxID_ANY, 100);
                        _table->Insert (index + 1, r.gauge, 1, wxEXPAND | wxLEFT | wxRIGHT);
                        
-                       r.informed_of_finish = false;
                        r.message = new wxStaticText (_panel, wxID_ANY, std_to_wx (""));
                        _table->Insert (index + 2, r.message, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
                        
@@ -99,22 +98,9 @@ JobManagerView::update ()
                        }
                }
                
-               /* Hack to work around our lack of cross-thread
-                  signalling; we tell the job to emit_finished()
-                  from here (the GUI thread).
-               */
-               
-               if ((*i)->finished () && !_job_records[*i].informed_of_finish) {
+               if ((*i)->finished()) {
                        _job_records[*i].gauge->SetValue (100);
                        _job_records[*i].message->SetLabel (std_to_wx (st));
-
-                       try {
-                               (*i)->emit_finished ();
-                       } catch (OpenFileError& e) {
-                               error_dialog (this, String::compose ("Error: %1", e.what ()));
-                       }
-                       
-                       _job_records[*i].informed_of_finish = true;
                }
 
                index += 3;
index 5a3ae61cb8c6fab8c2b84dbcb97ee5a5c3e5b1a3..b10446cdda4f7d215df9b152e3f3ab1cbfd879e6 100644 (file)
@@ -46,7 +46,6 @@ private:
        struct JobRecord {
                wxGauge* gauge;
                wxStaticText* message;
-               bool informed_of_finish;
        };
                
        std::map<boost::shared_ptr<Job>, JobRecord> _job_records;