Fix shared_ptr for Film.
authorCarl Hetherington <cth@carlh.net>
Wed, 24 Oct 2012 22:58:26 +0000 (23:58 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 24 Oct 2012 22:58:26 +0000 (23:58 +0100)
19 files changed:
src/lib/film.cc
src/lib/format.cc
src/lib/format.h
src/lib/job_manager.cc
src/lib/job_manager.h
src/tools/dvdomatic.cc
src/wx/dci_name_dialog.cc
src/wx/dci_name_dialog.h
src/wx/dcp_range_dialog.cc
src/wx/dcp_range_dialog.h
src/wx/film_editor.cc
src/wx/film_editor.h
src/wx/film_viewer.cc
src/wx/film_viewer.h
src/wx/job_wrapper.cc
src/wx/job_wrapper.h
src/wx/properties_dialog.cc
src/wx/properties_dialog.h
test/test.cc

index 0104f5a16ad74d46b35a8a0fedaa08457bd2c379..72da570f0db6dedf1a4118a7b7c8f7955a0425fe 100644 (file)
@@ -266,8 +266,8 @@ Film::make_dcp (bool transcode)
                }
        }
        
-       o->padding = format()->dcp_padding (this);
-       o->ratio = format()->ratio_as_float (this);
+       o->padding = format()->dcp_padding (shared_from_this ());
+       o->ratio = format()->ratio_as_float (shared_from_this ());
        o->decode_subtitles = with_subtitles ();
 
        shared_ptr<Job> r;
index 2eb4990da4951f01605d05a6da882a071af578db..eb42593feada4da576d645842bbd44cb13d60b42 100644 (file)
 #include "format.h"
 #include "film.h"
 
-using namespace std;
+using std::string;
+using std::setprecision;
+using std::stringstream;
+using std::vector;
+using boost::shared_ptr;
 
 vector<Format const *> Format::_formats;
 
@@ -143,7 +147,7 @@ FixedFormat::FixedFormat (int r, Size dcp, string id, string n, string d)
 }
 
 int
-Format::dcp_padding (Film const * f) const
+Format::dcp_padding (shared_ptr<const Film> f) const
 {
        int p = rint ((_dcp_size.width - (_dcp_size.height * ratio_as_integer(f) / 100.0)) / 2.0);
 
@@ -162,13 +166,13 @@ VariableFormat::VariableFormat (Size dcp, string id, string n, string d)
 }
 
 int
-VariableFormat::ratio_as_integer (Film const * f) const
+VariableFormat::ratio_as_integer (shared_ptr<const Film> f) const
 {
        return rint (ratio_as_float (f) * 100);
 }
 
 float
-VariableFormat::ratio_as_float (Film const * f) const
+VariableFormat::ratio_as_float (shared_ptr<const Film> f) const
 {
        return float (f->size().width) / f->size().height;
 }
index 35dd4fb856ac4ed86e8ba31c7d503e63c5e97eb6..2118237a406525e99295765270d4133e3cf98e87 100644 (file)
@@ -41,12 +41,12 @@ public:
        /** @return the aspect ratio multiplied by 100
         *  (e.g. 239 for Cinemascope 2.39:1)
         */
-       virtual int ratio_as_integer (Film const * f) const = 0;
+       virtual int ratio_as_integer (boost::shared_ptr<const Film> f) const = 0;
 
        /** @return the ratio as a floating point number */
-       virtual float ratio_as_float (Film const * f) const = 0;
+       virtual float ratio_as_float (boost::shared_ptr<const Film> f) const = 0;
 
-       int dcp_padding (Film const * f) const;
+       int dcp_padding (boost::shared_ptr<const Film> f) const;
 
        /** @return size in pixels of the images that we should
         *  put in a DCP for this ratio.  This size will not correspond
@@ -106,11 +106,11 @@ class FixedFormat : public Format
 public:
        FixedFormat (int, Size, std::string, std::string, std::string);
 
-       int ratio_as_integer (Film const *) const {
+       int ratio_as_integer (boost::shared_ptr<const Film>) const {
                return _ratio;
        }
 
-       float ratio_as_float (Film const *) const {
+       float ratio_as_float (boost::shared_ptr<const Film>) const {
                return _ratio / 100.0;
        }
 
@@ -127,8 +127,8 @@ class VariableFormat : public Format
 public:
        VariableFormat (Size, std::string, std::string, std::string);
 
-       int ratio_as_integer (Film const * f) const;
-       float ratio_as_float (Film const * f) const;
+       int ratio_as_integer (boost::shared_ptr<const Film> f) const;
+       float ratio_as_float (boost::shared_ptr<const Film> f) const;
 
        std::string name () const;
 };
index 5cc34035710715bb447da49b7822cff8777da77a..1fae179656222b299192d71652ad5abe719ec844 100644 (file)
@@ -26,6 +26,7 @@
 #include "job_manager.h"
 #include "job.h"
 #include "cross.h"
+#include "ui_signaller.h"
 
 using std::string;
 using std::list;
@@ -34,6 +35,7 @@ using boost::shared_ptr;
 JobManager* JobManager::_instance = 0;
 
 JobManager::JobManager ()
+       : _last_active_jobs (false)
 {
        boost::thread (boost::bind (&JobManager::scheduler, this));
 }
@@ -88,11 +90,13 @@ JobManager::errors () const
        return false;
 }      
 
-
 void
 JobManager::scheduler ()
 {
        while (1) {
+
+               bool active_jobs = false;
+
                {
                        boost::mutex::scoped_lock lm (_mutex);
                        for (list<shared_ptr<Job> >::iterator i = _jobs.begin(); i != _jobs.end(); ++i) {
@@ -110,9 +114,18 @@ JobManager::scheduler ()
                                                break;
                                        }
                                }
+
+                               if (!(*i)->finished ()) {
+                                       active_jobs = true;
+                               }
                        }
                }
 
+               if (active_jobs != _last_active_jobs) {
+                       _last_active_jobs = active_jobs;
+                       ui_signaller->emit (boost::bind (boost::ref (ActiveJobsChanged), active_jobs));
+               }
+
                dvdomatic_sleep (1);
        }
 }
index 4b70738f0bb4a121c7e7b9e5c7c699ccfe3d4aa1..cc1c1d28fc20b9250e101c4b7251bf10e9faf2e7 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <list>
 #include <boost/thread/mutex.hpp>
+#include <boost/signals2.hpp>
 
 class Job;
 
@@ -39,6 +40,8 @@ public:
        bool work_to_do () const;
        bool errors () const;
 
+       boost::signals2::signal<void (bool)> ActiveJobsChanged;
+
        static JobManager* instance ();
 
 private:
@@ -48,5 +51,7 @@ private:
        mutable boost::mutex _mutex;
        std::list<boost::shared_ptr<Job> > _jobs;
 
+       bool _last_active_jobs;
+
        static JobManager* _instance;
 };
index add0f614482d2a319359ed9399597e7a0d3f1c6f..b5c81da07f2ba8cbcb42318532704264c7f45884 100644 (file)
 #include "lib/version.h"
 #include "lib/ui_signaller.h"
 
-using namespace std;
-using namespace boost;
+using std::string;
+using std::stringstream;
+using std::map;
+using std::make_pair;
+using boost::shared_ptr;
 
 static FilmEditor* film_editor = 0;
 static FilmViewer* film_viewer = 0;
 
-static Film* film = 0;
+static shared_ptr<Film> film;
 
 static void set_menu_sensitivity ();
 
@@ -95,8 +98,7 @@ maybe_save_then_delete_film ()
                }
        }
        
-       delete film;
-       film = 0;
+       film.reset ();
 }
 
 enum Sensitivity {
@@ -264,11 +266,11 @@ public:
                
                if (r == wxID_OK) {
                        maybe_save_then_delete_film ();
-                       film = new Film (d->get_path (), false);
+                       film.reset (new Film (d->get_path (), false));
 #if BOOST_FILESYSTEM_VERSION == 3              
-                       film->set_name (filesystem::path (d->get_path()).filename().generic_string());
+                       film->set_name (boost::filesystem::path (d->get_path()).filename().generic_string());
 #else          
-                       film->set_name (filesystem::path (d->get_path()).filename());
+                       film->set_name (boost::filesystem::path (d->get_path()).filename());
 #endif
                        set_film ();
                }
@@ -284,7 +286,7 @@ public:
                
                if (r == wxID_OK) {
                        maybe_save_then_delete_film ();
-                       film = new Film (wx_to_std (c->GetPath ()));
+                       film.reset (new Film (wx_to_std (c->GetPath ())));
                        set_film ();
                }
        }
@@ -376,7 +378,7 @@ class App : public wxApp
                dvdomatic_setup ();
 
                if (argc == 2 && boost::filesystem::is_directory (wx_to_std (argv[1]))) {
-                       film = new Film (wx_to_std (argv[1]));
+                       film.reset (new Film (wx_to_std (argv[1])));
                }
 
                Frame* f = new Frame (_("DVD-o-matic"));
index ee8864ff95b277c807c27b6f36e3176fdb4f9272..bb6c2580797f8ff20b4bfcf22de5047e6071ea72 100644 (file)
@@ -22,7 +22,9 @@
 #include "wx_util.h"
 #include "film.h"
 
-DCINameDialog::DCINameDialog (wxWindow* parent, Film* film)
+using boost::shared_ptr;
+
+DCINameDialog::DCINameDialog (wxWindow* parent, shared_ptr<Film> film)
        : wxDialog (parent, wxID_ANY, _("DCI name"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
        , _film (film)
 {
index d06420a6e03a1f73974e9939c8f631a06da18c0f..1fd5436b8c94438880b5c4339de370a198b427dc 100644 (file)
 
 #include <wx/dialog.h>
 #include <wx/textctrl.h>
+#include <boost/shared_ptr.hpp>
 
 class Film;
 
 class DCINameDialog : public wxDialog
 {
 public:
-       DCINameDialog (wxWindow *, Film *);
+       DCINameDialog (wxWindow *, boost::shared_ptr<Film>);
 
 private:
        void audio_language_changed (wxCommandEvent &);
@@ -44,5 +45,5 @@ private:
        wxTextCtrl* _facility;
        wxTextCtrl* _package_type;
 
-       Film* _film;
+       boost::shared_ptr<Film> _film;
 };
index 6363275caf81940cd41683cda93d9ab65a9d17d3..509db121ed239ffa6132683c855329afd2bc325a 100644 (file)
@@ -21,7 +21,9 @@
 #include "dcp_range_dialog.h"
 #include "wx_util.h"
 
-DCPRangeDialog::DCPRangeDialog (wxWindow* p, Film* f)
+using boost::shared_ptr;
+
+DCPRangeDialog::DCPRangeDialog (wxWindow* p, shared_ptr<Film> f)
        : wxDialog (p, wxID_ANY, wxString (_("DCP Range")))
        , _film (f)
 {
index ea15154baa5a7234f23e91186f074fc2092e085b..2c5c3cec24eb49de0c77bcc5988da3f32c49b34c 100644 (file)
@@ -27,7 +27,7 @@ class Film;
 class DCPRangeDialog : public wxDialog
 {
 public:
-       DCPRangeDialog (wxWindow *, Film *);
+       DCPRangeDialog (wxWindow *, boost::shared_ptr<Film>);
 
        boost::signals2::signal<void (int, TrimAction)> Changed;
 
@@ -40,7 +40,7 @@ private:
        void set_sensitivity ();
        void emit_changed ();
        
-       Film* _film;
+       boost::shared_ptr<Film> _film;
        wxRadioButton* _whole;
        wxRadioButton* _first;
        wxSpinCtrl* _n_frames;
index b90731cf3464393cad2920177f3300d92d018bcc..34223ce0570999491b8cb967b1b3b835299df21a 100644 (file)
 #include "dci_name_dialog.h"
 #include "scaler.h"
 
-using namespace std;
-using namespace boost;
+using std::string;
+using std::stringstream;
+using std::pair;
+using std::fixed;
+using std::setprecision;
+using std::list;
+using std::vector;
+using boost::shared_ptr;
 
 /** @param f Film to edit */
-FilmEditor::FilmEditor (Film* f, wxWindow* parent)
+FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
        : wxPanel (parent)
        , _ignore_changes (Film::NONE)
        , _film (f)
@@ -231,6 +237,10 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent)
                _scaler->Append (std_to_wx ((*i)->name()));
        }
 
+       JobManager::instance()->ActiveJobsChanged.connect (
+               bind (&FilmEditor::active_jobs_changed, this, _1)
+               );
+
        /* And set their values from the Film */
        set_film (f);
        
@@ -587,7 +597,7 @@ FilmEditor::dcp_content_type_changed (wxCommandEvent &)
 
 /** Sets the Film that we are editing */
 void
-FilmEditor::set_film (Film* f)
+FilmEditor::set_film (shared_ptr<Film> f)
 {
        _film = f;
 
@@ -930,3 +940,9 @@ FilmEditor::setup_audio_details ()
                _audio->SetLabel (std_to_wx (s.str ()));
        }
 }
+
+void
+FilmEditor::active_jobs_changed (bool a)
+{
+       set_things_sensitive (!a);
+}
index f6e180979551b8eddf36610605062ee9d8986c17..2d3659615f7aadfbeee36a068168250100bee4a4 100644 (file)
@@ -37,9 +37,9 @@ class Film;
 class FilmEditor : public wxPanel
 {
 public:
-       FilmEditor (Film *, wxWindow *);
+       FilmEditor (boost::shared_ptr<Film>, wxWindow *);
 
-       void set_film (Film *);
+       void set_film (boost::shared_ptr<Film>);
        void setup_visibility ();
 
        boost::signals2::signal<void (std::string)> FileChanged;
@@ -85,10 +85,12 @@ private:
        wxControl* video_control (wxControl *);
        wxControl* still_control (wxControl *);
 
+       void active_jobs_changed (bool);
+
        Film::Property _ignore_changes;
 
        /** The film we are editing */
-       Film* _film;
+       boost::shared_ptr<Film> _film;
        /** The Film's name */
        wxTextCtrl* _name;
        wxStaticText* _dcp_name;
index 2496679aa83e0325a8e40a8163741bcf3d8719c4..79de49406d86d41a5f9150f31d1f58a6e8b9226d 100644 (file)
@@ -40,7 +40,7 @@ using boost::shared_ptr;
 class ThumbPanel : public wxPanel
 {
 public:
-       ThumbPanel (wxPanel* parent, Film* film)
+       ThumbPanel (wxPanel* parent, shared_ptr<Film> film)
                : wxPanel (parent)
                , _film (film)
                , _frame_rebuild_needed (false)
@@ -100,7 +100,7 @@ public:
                Refresh ();
        }
 
-       void set_film (Film* f)
+       void set_film (shared_ptr<Film> f)
        {
                _film = f;
                if (!_film) {
@@ -189,7 +189,7 @@ private:
                }
        }
 
-       Film* _film;
+       shared_ptr<Film> _film;
        shared_ptr<wxImage> _image;
        wxImage _transformed_image;
        /** currently-displayed thumbnail index */
@@ -224,9 +224,8 @@ EVT_PAINT (ThumbPanel::paint_event)
 EVT_SIZE (ThumbPanel::size_event)
 END_EVENT_TABLE ()
 
-FilmViewer::FilmViewer (Film* f, wxWindow* p)
+FilmViewer::FilmViewer (shared_ptr<Film> f, wxWindow* p)
        : wxPanel (p)
-       , _film (0)
 {
        _sizer = new wxBoxSizer (wxVERTICAL);
        SetSizer (_sizer);
@@ -293,7 +292,7 @@ FilmViewer::film_changed (Film::Property p)
 }
 
 void
-FilmViewer::set_film (Film* f)
+FilmViewer::set_film (shared_ptr<Film> f)
 {
        if (_film == f) {
                return;
index ecd6bc3080cf7d7717a9ff71068177428f9fbe5b..95bdf099da3f2d03877892299f118e9604a3edf1 100644 (file)
@@ -32,9 +32,9 @@ class ThumbPanel;
 class FilmViewer : public wxPanel
 {
 public:
-       FilmViewer (Film *, wxWindow *);
+       FilmViewer (boost::shared_ptr<Film>, wxWindow *);
 
-       void set_film (Film *);
+       void set_film (boost::shared_ptr<Film>);
        void setup_visibility ();
 
 private:
@@ -42,7 +42,7 @@ private:
        void set_thumbnail (int);
        void film_changed (Film::Property);
 
-       Film* _film;
+       boost::shared_ptr<Film> _film;
        wxBoxSizer* _sizer;
        ThumbPanel* _thumb_panel;
        wxSlider* _slider;
index cc7507547b8172dc9585629ee1b11ba7eb146a64..f2056cf498abacd429c92464d9176082e3e7c5c0 100644 (file)
 #include "job_wrapper.h"
 #include "wx_util.h"
 
-using namespace std;
+using boost::shared_ptr;
 
 void
-JobWrapper::make_dcp (wxWindow* parent, Film* film, bool transcode)
+JobWrapper::make_dcp (wxWindow* parent, shared_ptr<Film> film, bool transcode)
 {
        if (!film) {
                return;
index 4722cfdd4be0f72535142eb3b4096399108d2ae3..7120e9f106ec0acc8acb0ad397b1e19d7baf514a 100644 (file)
@@ -24,6 +24,6 @@ class Film;
 namespace JobWrapper
 {
 
-void make_dcp (wxWindow *, Film *, bool);
+void make_dcp (wxWindow *, boost::shared_ptr<Film>, bool);
        
 }
index b8a47e0e37fe1913dc242c4b6efaccf7bc203e69..0ffbd06cba7478d3dda36ab264f8568709b0c3af 100644 (file)
 #include "properties_dialog.h"
 #include "wx_util.h"
 
-using namespace std;
-using namespace boost;
+using std::string;
+using std::stringstream;
+using std::fixed;
+using std::setprecision;
+using boost::shared_ptr;
+using boost::lexical_cast;
 
-PropertiesDialog::PropertiesDialog (wxWindow* parent, Film* film)
+PropertiesDialog::PropertiesDialog (wxWindow* parent, shared_ptr<Film> film)
        : wxDialog (parent, wxID_ANY, _("Film Properties"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE)
        , _film (film)
 {
@@ -83,7 +87,7 @@ PropertiesDialog::frames_already_encoded () const
        stringstream u;
        try {
                u << _film->encoded_frames ();
-       } catch (thread_interrupted &) {
+       } catch (boost::thread_interrupted &) {
                return "";
        }
        
index f72c8341945f06cd34be59caba16cf11fba15375..308c0f7b3f5bdced158de82e7362bbdae7711006 100644 (file)
@@ -25,12 +25,12 @@ class ThreadedStaticText;
 class PropertiesDialog : public wxDialog
 {
 public:
-       PropertiesDialog (wxWindow *, Film *);
+       PropertiesDialog (wxWindow *, boost::shared_ptr<Film>);
 
 private:
        std::string frames_already_encoded () const;
 
-       Film* _film;
+       boost::shared_ptr<Film> _film;
        wxStaticText* _frames;
        wxStaticText* _disk_for_frames;
        wxStaticText* _total_disk;
index 2eaea1624f9e5fdf1102bab5731ff78ddfa9e626..ddb6cbb550514435c40fb82e2f5b2e65e50e0bf3 100644 (file)
@@ -123,11 +123,11 @@ BOOST_AUTO_TEST_CASE (format_test)
        
        Format const * f = Format::from_nickname ("Flat");
        BOOST_CHECK (f);
-       BOOST_CHECK_EQUAL (f->ratio_as_integer(0), 185);
+       BOOST_CHECK_EQUAL (f->ratio_as_integer(shared_ptr<const Film> ()), 185);
        
        f = Format::from_nickname ("Scope");
        BOOST_CHECK (f);
-       BOOST_CHECK_EQUAL (f->ratio_as_integer(0), 239);
+       BOOST_CHECK_EQUAL (f->ratio_as_integer(shared_ptr<const Film> ()), 239);
 }
 
 BOOST_AUTO_TEST_CASE (util_test)