Separate CPL choice for KDMs into a separate class.
[dcpomatic.git] / src / wx / kdm_dialog.cc
index 519317dcc9d07b804518585e5431822264471d88..a996463c54a6114d5e1c5fb6fa368368b3157a11 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2015 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
 
 */
 
-#include <wx/treectrl.h>
-#include <wx/datectrl.h>
-#include <wx/timectrl.h>
-#include "lib/cinema.h"
 #include "kdm_dialog.h"
-#include "new_cinema_dialog.h"
+#include "cinema_dialog.h"
+#include "screen_dialog.h"
 #include "wx_util.h"
-#ifdef __WXMSW__
-#include "dir_picker_ctrl.h"
-#else
-#include <wx/filepicker.h>
-#endif
-
-using namespace std;
+#include "screens_panel.h"
+#include "kdm_timing_panel.h"
+#include "kdm_output_panel.h"
+#include "kdm_cpl_panel.h"
+#include "lib/cinema.h"
+#include "lib/config.h"
+#include "lib/film.h"
+#include "lib/screen.h"
+#include <libcxml/cxml.h>
+#include <wx/treectrl.h>
+#include <wx/listctrl.h>
+#include <iostream>
+
+using std::string;
+using std::map;
+using std::list;
+using std::pair;
+using std::cout;
+using std::vector;
+using std::make_pair;
 using boost::shared_ptr;
 
-KDMDialog::KDMDialog (wxWindow* parent)
+KDMDialog::KDMDialog (wxWindow* parent, boost::shared_ptr<const Film> film)
        : wxDialog (parent, wxID_ANY, _("Make KDMs"))
 {
+       /* Main sizer */
        wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
 
-       add_label_to_sizer (vertical, this, "Make KDMs for");
-
-       wxBoxSizer* targets = new wxBoxSizer (wxHORIZONTAL);
-       
-       _targets = new wxTreeCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT | wxTR_MULTIPLE | wxTR_HAS_BUTTONS);
-       targets->Add (_targets, 1, wxEXPAND | wxALL, 6);
-
-       _root = _targets->AddRoot ("Foo");
-       shared_ptr<Cinema> csy (new Cinema ("City Screen York"));
-       add_cinema (csy);
-       add_screen (csy, shared_ptr<Screen> (new Screen ("Screen 1")));
-       add_screen (csy, shared_ptr<Screen> (new Screen ("Screen 2")));
-       add_screen (csy, shared_ptr<Screen> (new Screen ("Screen 3")));
-       _targets->ExpandAll ();
-
-       wxBoxSizer* target_buttons = new wxBoxSizer (wxVERTICAL);
-
-       _new_cinema = new wxButton (this, wxID_ANY, _("New Cinema..."));
-       target_buttons->Add (_new_cinema, 1, wxEXPAND | wxALL, 6);
-       _new_screen = new wxButton (this, wxID_ANY, _("New Screen..."));
-       target_buttons->Add (_new_screen, 1, wxEXPAND | wxALL, 6);
-
-       targets->Add (target_buttons, 0, wxEXPAND | wxALL, 6);
-
-       vertical->Add (targets, 0, wxEXPAND | wxALL, 6);
-
-       wxFlexGridSizer* table = new wxFlexGridSizer (3, 2, 6);
-       add_label_to_sizer (table, this, "From");
-       _from_date = new wxDatePickerCtrl (this, wxID_ANY);
-       table->Add (_from_date, 1, wxEXPAND);
-       _from_time = new wxTimePickerCtrl (this, wxID_ANY);
-       table->Add (_from_time, 1, wxEXPAND);
-       
-       add_label_to_sizer (table, this, "To");
-       _to_date = new wxDatePickerCtrl (this, wxID_ANY);
-       table->Add (_to_date, 1, wxEXPAND);
-       _to_time = new wxTimePickerCtrl (this, wxID_ANY);
-       table->Add (_to_time, 1, wxEXPAND);
-
-       add_label_to_sizer (table, this, "Write to");
-
-#ifdef __WXMSW__
-       _folder = new DirPickerCtrl (this);
-#else  
-       _folder = new wxDirPickerCtrl (this, wxDD_DIR_MUST_EXIST);
-#endif
-
-       table->Add (_folder, 1, wxEXPAND);
-       
-       vertical->Add (table, 1, wxEXPAND | wxALL, 6);
-
-       wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
+       /* Font for sub-headings */
+       wxFont subheading_font (*wxNORMAL_FONT);
+       subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
+
+       /* Sub-heading: Screens */
+       wxStaticText* h = new wxStaticText (this, wxID_ANY, _("Screens"));
+       h->SetFont (subheading_font);
+       vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL);
+       _screens = new ScreensPanel (this);
+       vertical->Add (_screens, 1, wxEXPAND);
+
+       /* Sub-heading: Timing */
+       h = new wxStaticText (this, wxID_ANY, S_("KDM|Timing"));
+       h->SetFont (subheading_font);
+       vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
+       _timing = new KDMTimingPanel (this);
+       vertical->Add (_timing);
+
+       /* Sub-heading: CPL */
+       h = new wxStaticText (this, wxID_ANY, _("CPL"));
+       h->SetFont (subheading_font);
+       vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
+       _cpl = new KDMCPLPanel (this, film->cpls ());
+       vertical->Add (_cpl);
+
+       /* Sub-heading: Output */
+       h = new wxStaticText (this, wxID_ANY, _("Output"));
+       h->SetFont (subheading_font);
+       vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
+       _output = new KDMOutputPanel (this, film->interop ());
+       vertical->Add (_output, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP);
+
+       /* Make an overall sizer to get a nice border, and put some buttons in */
+
+       wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
+       overall_sizer->Add (vertical, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
+
+       wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
        if (buttons) {
-               vertical->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
+               overall_sizer->Add (buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
        }
 
-       _targets->Connect (wxID_ANY, wxEVT_COMMAND_TREE_SEL_CHANGED, wxCommandEventHandler (KDMDialog::targets_selection_changed), 0, this);
-       _new_cinema->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (KDMDialog::new_cinema_clicked), 0, this);
-       _new_screen->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (KDMDialog::new_screen_clicked), 0, this);
+       /* Bind */
+
+       _screens->ScreensChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
 
-       _new_screen->Enable (false);
-       
-       SetSizer (vertical);
-       vertical->Layout ();
-       vertical->SetSizeHints (this);
+       setup_sensitivity ();
+
+       SetSizer (overall_sizer);
+       overall_sizer->Layout ();
+       overall_sizer->SetSizeHints (this);
 }
 
 void
-KDMDialog::targets_selection_changed (wxCommandEvent &)
+KDMDialog::setup_sensitivity ()
 {
-       wxArrayTreeItemIds s;
-       _targets->GetSelections (s);
-
-       bool selected_cinema = false;
-       for (size_t i = 0; i < s.GetCount(); ++i) {
-               if (_cinemas.find (s[i]) != _cinemas.end()) {
-                       selected_cinema = true;
-               }
+       _screens->setup_sensitivity ();
+       _output->setup_sensitivity ();
+
+       bool const sd = _cpl->has_selected ();
+
+       wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
+       if (ok) {
+               ok->Enable (!_screens->screens().empty() && sd);
        }
-       
-       _new_screen->Enable (selected_cinema);  
 }
 
-void
-KDMDialog::add_cinema (shared_ptr<Cinema> c)
+boost::filesystem::path
+KDMDialog::cpl () const
 {
-       _cinemas[_targets->AppendItem (_root, std_to_wx (c->name))] = c;
+       return _cpl->cpl ();
 }
 
-void
-KDMDialog::add_screen (shared_ptr<Cinema> c, shared_ptr<Screen> s)
+list<shared_ptr<Screen> >
+KDMDialog::screens () const
 {
-       map<wxTreeItemId, shared_ptr<Cinema> >::const_iterator i = _cinemas.begin();
-       while (i != _cinemas.end() && i->second != c) {
-               ++i;
-       }
+       return _screens->screens ();
+}
 
-       if (i == _cinemas.end()) {
-               return;
-       }
+boost::posix_time::ptime
+KDMDialog::from () const
+{
+       return _timing->from ();
+}
 
-       _screens[_targets->AppendItem (i->first, std_to_wx (s->name))] = s;
+boost::posix_time::ptime
+KDMDialog::until () const
+{
+       return _timing->until ();
 }
 
-void
-KDMDialog::new_cinema_clicked (wxCommandEvent &)
+boost::filesystem::path
+KDMDialog::directory () const
 {
-       NewCinemaDialog* d = new NewCinemaDialog (this);
-       d->ShowModal ();
-       d->Destroy ();
+       return _output->directory ();
 }
 
-void
-KDMDialog::new_screen_clicked (wxCommandEvent &)
+bool
+KDMDialog::write_to () const
 {
+       return _output->write_to ();
+}
 
+dcp::Formulation
+KDMDialog::formulation () const
+{
+       return _output->formulation ();
 }