Make batch converter basically work.
authorCarl Hetherington <cth@carlh.net>
Sat, 4 May 2013 19:58:31 +0000 (20:58 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 4 May 2013 19:58:31 +0000 (20:58 +0100)
src/lib/job.cc
src/lib/job.h
src/tools/dvdomatic.cc
src/tools/dvdomatic_batch.cc
src/wx/batch_view.cc [deleted file]
src/wx/batch_view.h [deleted file]
src/wx/job_manager_view.cc
src/wx/job_manager_view.h
src/wx/wscript

index 1c66d87d379a7ba8395fa128be4c4aa26876220b..9a5812fa7426dfb451fb619951b606769be16e06 100644 (file)
@@ -26,6 +26,7 @@
 #include <libdcp/exceptions.h>
 #include "job.h"
 #include "util.h"
+#include "cross.h"
 
 #include "i18n.h"
 
@@ -155,6 +156,13 @@ Job::finished_cancelled () const
        return _state == FINISHED_CANCELLED;
 }
 
+bool
+Job::paused () const
+{
+       boost::mutex::scoped_lock lm (_state_mutex);
+       return _state == PAUSED;
+}
+       
 /** Set the state of this job.
  *  @param s New state.
  */
@@ -190,6 +198,10 @@ Job::set_progress (float p)
        _progress_unknown = false;
        _stack.back().normalised = p;
        boost::this_thread::interruption_point ();
+
+       if (paused ()) {
+               dvdomatic_sleep (1);
+       }
 }
 
 /** @return fractional overall progress, or -1 if not known */
@@ -326,3 +338,19 @@ Job::cancel ()
        _thread->interrupt ();
        _thread->join ();
 }
+
+void
+Job::pause ()
+{
+       if (running ()) {
+               set_state (PAUSED);
+       }
+}
+
+void
+Job::resume ()
+{
+       if (paused ()) {
+               set_state (RUNNING);
+       }
+}
index fd036bce29c921625bfe71d099214fdd8a508821..37fa56d2082e83e4b6ea49c484152d8b75142e11 100644 (file)
@@ -47,6 +47,8 @@ public:
        virtual void run () = 0;
        
        void start ();
+       void pause ();
+       void resume ();
        void cancel ();
 
        bool is_new () const;
@@ -55,6 +57,7 @@ public:
        bool finished_ok () const;
        bool finished_in_error () const;
        bool finished_cancelled () const;
+       bool paused () const;
 
        std::string error_summary () const;
        std::string error_details () const;
@@ -79,6 +82,7 @@ protected:
        enum State {
                NEW,            ///< the job hasn't been started yet
                RUNNING,        ///< the job is running
+               PAUSED,         ///< the job has been paused
                FINISHED_OK,    ///< the job has finished successfully
                FINISHED_ERROR, ///< the job has finished in error
                FINISHED_CANCELLED ///< the job was cancelled
index 2740a09655c6254c684878f42b86bc939d9af192..ff1560f0eaa83652551b48a527d2b9264e89cf6a 100644 (file)
@@ -224,7 +224,7 @@ public:
 
                film_editor = new FilmEditor (film, panel);
                film_viewer = new FilmViewer (film, panel);
-               JobManagerView* job_manager_view = new JobManagerView (panel);
+               JobManagerView* job_manager_view = new JobManagerView (panel, static_cast<JobManagerView::Buttons> (0));
 
                _top_sizer = new wxBoxSizer (wxHORIZONTAL);
                _top_sizer->Add (film_editor, 0, wxALL, 6);
index 102f29408de67ae2374944e9cd1ba355b0dc2ee1..7a3d38d9c6d287b6f5106383c950a395ab6a3542 100644 (file)
 */
 
 #include <wx/aboutdlg.h>
+#include <wx/stdpaths.h>
 #include <wx/wx.h>
 #include "lib/version.h"
 #include "lib/compose.hpp"
 #include "lib/config.h"
 #include "lib/util.h"
+#include "lib/film.h"
+#include "lib/job_manager.h"
 #include "wx/wx_util.h"
 #include "wx/wx_ui_signaller.h"
-#include "wx/batch_view.h"
+#include "wx/job_manager_view.h"
+
+using boost::shared_ptr;
 
 enum {
-       ID_file_quit = 1,
+       ID_file_add_film = 1,
+       ID_file_quit,
        ID_help_about
 };
 
@@ -36,6 +42,7 @@ void
 setup_menu (wxMenuBar* m)
 {
        wxMenu* file = new wxMenu;
+       file->Append (ID_file_add_film, _("&Add Film..."));
        file->Append (ID_file_quit, _("&Quit"));
 
        wxMenu* help = new wxMenu;
@@ -55,6 +62,7 @@ public:
                setup_menu (bar);
                SetMenuBar (bar);
 
+               Connect (ID_file_add_film, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::file_add_film));
                Connect (ID_file_quit, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::file_quit));
                Connect (ID_help_about, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::help_about));
 
@@ -65,24 +73,60 @@ public:
 
                wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
 
-               BatchView* batch_view = new BatchView (panel);
-               sizer->Add (batch_view, 1, wxALL | wxEXPAND, 6);
+               JobManagerView* job_manager_view = new JobManagerView (panel, JobManagerView::PAUSE);
+               sizer->Add (job_manager_view, 1, wxALL | wxEXPAND, 6);
 
                wxSizer* buttons = new wxBoxSizer (wxHORIZONTAL);
                wxButton* add = new wxButton (panel, wxID_ANY, _("Add Film..."));
+               add->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (Frame::add_film));
                buttons->Add (add, 1, wxALL, 6);
-               wxButton* start = new wxButton (panel, wxID_ANY, _("Start..."));
-               buttons->Add (start, 1, wxALL, 6);
 
                sizer->Add (buttons, 0, wxALL, 6);
 
                panel->SetSizer (sizer);
+
+               Connect (wxID_ANY, wxEVT_CLOSE_WINDOW, wxCloseEventHandler (Frame::close));
        }
 
 private:
+       bool should_close ()
+       {
+               if (!JobManager::instance()->work_to_do ()) {
+                       return true;
+               }
+
+               wxMessageDialog* d = new wxMessageDialog (
+                       0,
+                       _("There are unfinished jobs; are you sure you want to quit?"),
+                       _("Unfinished jobs"),
+                       wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
+                       );
+
+               bool const r = d->ShowModal() == wxID_YES;
+               d->Destroy ();
+               return r;
+       }
+               
+       void close (wxCloseEvent& ev)
+       {
+               if (!should_close ()) {
+                       ev.Veto ();
+                       return;
+               }
+
+               ev.Skip ();
+       }
+
+       void file_add_film (wxCommandEvent& ev)
+       {
+               add_film (ev);
+       }
+       
        void file_quit (wxCommandEvent &)
        {
-               Close (true);
+               if (should_close ()) {
+                       Close (true);
+               }
        }
 
        void help_about (wxCommandEvent &)
@@ -116,6 +160,33 @@ private:
                info.SetWebSite (wxT ("http://carlh.net/software/dvdomatic"));
                wxAboutBox (info);
        }
+
+       void add_film (wxCommandEvent &)
+       {
+               wxDirDialog* c = new wxDirDialog (this, _("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
+               int r;
+               while (1) {
+                       r = c->ShowModal ();
+                       if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
+                               error_dialog (this, _("You did not select a folder.  Make sure that you select a folder before clicking Open."));
+                       } else {
+                               break;
+                       }
+               }
+                       
+               if (r == wxID_OK) {
+                       try {
+                               shared_ptr<Film> film (new Film (wx_to_std (c->GetPath ())));
+                               film->make_dcp ();
+                       } catch (std::exception& e) {
+                               wxString p = c->GetPath ();
+                               wxCharBuffer b = p.ToUTF8 ();
+                               error_dialog (this, wxString::Format (_("Could not open film at %s (%s)"), p.data(), std_to_wx (e.what()).data()));
+                       }
+               }
+
+               c->Destroy ();
+       }
 };
 
 class App : public wxApp
diff --git a/src/wx/batch_view.cc b/src/wx/batch_view.cc
deleted file mode 100644 (file)
index bfe30d8..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#include "batch_view.h"
-
-BatchView::BatchView (wxWindow* parent)
-       : wxScrolledWindow (parent)
-{
-       _panel = new wxPanel (this);
-       wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
-       sizer->Add (_panel, 1, wxEXPAND);
-       SetSizer (sizer);
-       
-       _table = new wxFlexGridSizer (5, 6, 6);
-       _table->AddGrowableCol (1, 1);
-       _panel->SetSizer (_table);
-}
diff --git a/src/wx/batch_view.h b/src/wx/batch_view.h
deleted file mode 100644 (file)
index 6316ac7..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
-    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#include <wx/wx.h>
-
-class BatchView : public wxScrolledWindow
-{
-public:
-       BatchView (wxWindow *);
-
-private:       
-       wxPanel* _panel;
-       wxFlexGridSizer* _table;
-};
index f7d2315ccf68ea5ae3078d15eece597a8c6ded58..53be88ca7b44fe4e20bd1f12094bd47d938864ac 100644 (file)
@@ -34,15 +34,21 @@ using std::map;
 using boost::shared_ptr;
 
 /** Must be called in the GUI thread */
-JobManagerView::JobManagerView (wxWindow* parent)
+JobManagerView::JobManagerView (wxWindow* parent, Buttons buttons)
        : wxScrolledWindow (parent)
+       , _buttons (buttons)
 {
        _panel = new wxPanel (this);
        wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
        sizer->Add (_panel, 1, wxEXPAND);
        SetSizer (sizer);
+
+       int N = 5;
+       if (buttons & PAUSE) {
+               ++N;
+       }
        
-       _table = new wxFlexGridSizer (5, 6, 6);
+       _table = new wxFlexGridSizer (N, 6, 6);
        _table->AddGrowableCol (1, 1);
        _panel->SetSizer (_table);
 
@@ -78,21 +84,33 @@ JobManagerView::update ()
                        _table->Insert (index, m, 0, wxALIGN_CENTER_VERTICAL | wxALL, 6);
                        
                        JobRecord r;
+                       int n = 1;
                        r.finalised = false;
                        r.gauge = new wxGauge (_panel, wxID_ANY, 100);
-                       _table->Insert (index + 1, r.gauge, 1, wxEXPAND | wxLEFT | wxRIGHT);
+                       _table->Insert (index + n, r.gauge, 1, wxEXPAND | wxLEFT | wxRIGHT);
+                       ++n;
                        
                        r.message = new wxStaticText (_panel, wxID_ANY, std_to_wx (""));
-                       _table->Insert (index + 2, r.message, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
+                       _table->Insert (index + n, r.message, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
+                       ++n;
 
                        r.cancel = new wxButton (_panel, wxID_ANY, _("Cancel"));
                        r.cancel->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (JobManagerView::cancel_clicked), 0, this);
-                       _table->Insert (index + 3, r.cancel, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
-
+                       _table->Insert (index + n, r.cancel, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
+                       ++n;
+
+                       if (_buttons & PAUSE) {
+                               r.pause = new wxButton (_panel, wxID_ANY, _("Pause"));
+                               r.pause->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (JobManagerView::pause_clicked), 0, this);
+                               _table->Insert (index + n, r.pause, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
+                               ++n;
+                       }
+                       
                        r.details = new wxButton (_panel, wxID_ANY, _("Details..."));
                        r.details->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (JobManagerView::details_clicked), 0, this);
                        r.details->Enable (false);
-                       _table->Insert (index + 4, r.details, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
+                       _table->Insert (index + n, r.details, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
+                       ++n;
                        
                        _job_records[*i] = r;
                }
@@ -155,3 +173,21 @@ JobManagerView::cancel_clicked (wxCommandEvent& ev)
                }
        }
 }
+
+void
+JobManagerView::pause_clicked (wxCommandEvent& ev)
+{
+       wxObject* o = ev.GetEventObject ();
+       for (map<boost::shared_ptr<Job>, JobRecord>::iterator i = _job_records.begin(); i != _job_records.end(); ++i) {
+               if (i->second.pause == o) {
+                       if (i->first->paused()) {
+                               i->first->resume ();
+                               i->second.pause->SetLabel (_("Pause"));
+                       } else {
+                               i->first->pause ();
+                               i->second.pause->SetLabel (_("Resume"));
+                       }
+               }
+       }
+}
+       
index 72ac85c02640423ee4c2f23b1756c8680adf645b..fc29eadb4760c3bb74d9f2a55b4142c9f7967e19 100644 (file)
@@ -33,13 +33,18 @@ class Job;
 class JobManagerView : public wxScrolledWindow
 {
 public:
-       JobManagerView (wxWindow *);
+       enum Buttons {
+               PAUSE = 0x1,
+       };
+               
+       JobManagerView (wxWindow *, Buttons);
 
        void update ();
 
 private:
        void periodic (wxTimerEvent &);
        void cancel_clicked (wxCommandEvent &);
+       void pause_clicked (wxCommandEvent &);
        void details_clicked (wxCommandEvent &);
 
        boost::shared_ptr<wxTimer> _timer;
@@ -49,9 +54,11 @@ private:
                wxGauge* gauge;
                wxStaticText* message;
                wxButton* cancel;
+               wxButton* pause;
                wxButton* details;
                bool finalised;
        };
                
        std::map<boost::shared_ptr<Job>, JobRecord> _job_records;
+       Buttons _buttons;
 };
index f1c3d1a6a47ce09eda0955a36c0c881a7007659f..42bb8ca8865ee679440fb0bb1395609ea0a90bf3 100644 (file)
@@ -6,7 +6,6 @@ import i18n
 sources = """
           audio_dialog.cc
           audio_plot.cc
-          batch_view.cc
           config_dialog.cc
           dci_metadata_dialog.cc
           dir_picker_ctrl.cc