Merge delay-decode-take2 branch into master.
[dcpomatic.git] / src / wx / kdm_dialog.cc
index 02b91a1e2aa3e30b4fa479230b7b74d8b0cd02de..5fb031324e4d9d5f649f9902b6748df0b9fc05b3 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2014 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/datectrl.h>
 #include <wx/timectrl.h>
 #include <wx/stdpaths.h>
+#include <wx/listctrl.h>
 #include "lib/cinema.h"
 #include "lib/config.h"
+#include "lib/film.h"
 #include "kdm_dialog.h"
 #include "cinema_dialog.h"
 #include "screen_dialog.h"
@@ -37,10 +39,11 @@ using std::string;
 using std::map;
 using std::list;
 using std::pair;
+using std::cout;
 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"))
 {
        wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
@@ -80,30 +83,59 @@ KDMDialog::KDMDialog (wxWindow* parent)
 
        wxFlexGridSizer* table = new wxFlexGridSizer (3, 2, 6);
        add_label_to_sizer (table, this, _("From"), true);
-       _from_date = new wxDatePickerCtrl (this, wxID_ANY);
+       wxDateTime from;
+       from.SetToCurrent ();
+       _from_date = new wxDatePickerCtrl (this, wxID_ANY, from);
        table->Add (_from_date, 1, wxEXPAND);
-       _from_time = new wxTimePickerCtrl (this, wxID_ANY);
+       _from_time = new wxTimePickerCtrl (this, wxID_ANY, from);
        table->Add (_from_time, 1, wxEXPAND);
-       
+
        add_label_to_sizer (table, this, _("Until"), true);
-       _until_date = new wxDatePickerCtrl (this, wxID_ANY);
+       wxDateTime to = from;
+       /* 1 week from now */
+       to.Add (wxDateSpan (0, 0, 1, 0));
+       _until_date = new wxDatePickerCtrl (this, wxID_ANY, to);
        table->Add (_until_date, 1, wxEXPAND);
-       _until_time = new wxTimePickerCtrl (this, wxID_ANY);
+       _until_time = new wxTimePickerCtrl (this, wxID_ANY, to);
        table->Add (_until_time, 1, wxEXPAND);
 
+       vertical->Add (table, 0, wxEXPAND | wxALL, 6);
+
+       _dcps = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL);
+       wxListItem ip;
+       ip.SetId (0);
+       ip.SetText (_("DCP"));
+       ip.SetWidth (400);
+       _dcps->InsertColumn (0, ip);
+       vertical->Add (_dcps, 0, wxEXPAND | wxALL, 6);
+       
+       list<boost::filesystem::path> dcps = film->dcps ();
+       for (list<boost::filesystem::path>::const_iterator i = dcps.begin(); i != dcps.end(); ++i) {
+               wxListItem item;
+               int const n = _dcps->GetItemCount ();
+               item.SetId (n);
+               _dcps->InsertItem (item);
+               _dcps->SetItem (n, 0, std_to_wx (i->string ()));
+
+               if (dcps.size() == 1 || i->string() == film->dcp_name ()) {
+                       _dcps->SetItemState (n, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
+               }
+       }
+       
+       table = new wxFlexGridSizer (2, 2, 6);
+
        _write_to = new wxRadioButton (this, wxID_ANY, _("Write to"));
        table->Add (_write_to, 1, wxEXPAND);
 
 #ifdef DCPOMATIC_USE_OWN_DIR_PICKER
        _folder = new DirPickerCtrl (this); 
 #else  
-       _folder = new wxDirPickerCtrl (this, wxID_ANY);
+       _folder = new wxDirPickerCtrl (this, wxID_ANY, wxEmptyString, wxDirSelectorPromptStr, wxDefaultPosition, wxSize (300, -1));
 #endif
 
        _folder->SetPath (wxStandardPaths::Get().GetDocumentsDir());
        
        table->Add (_folder, 1, wxEXPAND);
-       table->AddSpacer (0);
 
        _email = new wxRadioButton (this, wxID_ANY, _("Send by email"));
        table->Add (_email, 1, wxEXPAND);
@@ -116,6 +148,8 @@ KDMDialog::KDMDialog (wxWindow* parent)
                vertical->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
        }
 
+       _write_to->SetValue (true);
+
        _targets->Bind       (wxEVT_COMMAND_TREE_SEL_CHANGED, boost::bind (&KDMDialog::setup_sensitivity, this));
 
        _add_cinema->Bind    (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KDMDialog::add_cinema_clicked, this));
@@ -126,6 +160,9 @@ KDMDialog::KDMDialog (wxWindow* parent)
        _edit_screen->Bind   (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KDMDialog::edit_screen_clicked, this));
        _remove_screen->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KDMDialog::remove_screen_clicked, this));
 
+       _dcps->Bind          (wxEVT_COMMAND_LIST_ITEM_SELECTED,   boost::bind (&KDMDialog::setup_sensitivity, this));
+       _dcps->Bind          (wxEVT_COMMAND_LIST_ITEM_DESELECTED, boost::bind (&KDMDialog::setup_sensitivity, this));
+
        _write_to->Bind      (wxEVT_COMMAND_RADIOBUTTON_SELECTED, boost::bind (&KDMDialog::setup_sensitivity, this));
        _email->Bind         (wxEVT_COMMAND_RADIOBUTTON_SELECTED, boost::bind (&KDMDialog::setup_sensitivity, this));
 
@@ -175,6 +212,7 @@ KDMDialog::setup_sensitivity ()
 {
        bool const sc = selected_cinemas().size() == 1;
        bool const ss = selected_screens().size() == 1;
+       bool const sd = _dcps->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) != -1;
        
        _edit_cinema->Enable (sc);
        _remove_cinema->Enable (sc);
@@ -184,7 +222,7 @@ KDMDialog::setup_sensitivity ()
        _remove_screen->Enable (ss);
 
        wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK));
-       ok->Enable (sc || ss);
+       ok->Enable ((selected_cinemas().size() > 0 || selected_screens().size() > 0) && sd);
 
        _folder->Enable (_write_to->GetValue ());
 }
@@ -225,8 +263,6 @@ KDMDialog::add_cinema_clicked ()
        Config::instance()->add_cinema (c);
        add_cinema (c);
 
-       Config::instance()->write ();
-       
        d->Destroy ();
 }
 
@@ -246,7 +282,7 @@ KDMDialog::edit_cinema_clicked ()
        c.second->email = d->email ();
        _targets->SetItemText (c.first, std_to_wx (d->name()));
 
-       Config::instance()->write ();
+       Config::instance()->changed ();
 
        d->Destroy ();  
 }
@@ -262,8 +298,6 @@ KDMDialog::remove_cinema_clicked ()
 
        Config::instance()->remove_cinema (c.second);
        _targets->Delete (c.first);
-
-       Config::instance()->write ();   
 }
 
 void
@@ -284,7 +318,7 @@ KDMDialog::add_screen_clicked ()
        c->add_screen (s);
        add_screen (c, s);
 
-       Config::instance()->write ();
+       Config::instance()->changed ();
 
        d->Destroy ();
 }
@@ -305,7 +339,7 @@ KDMDialog::edit_screen_clicked ()
        s.second->certificate = d->certificate ();
        _targets->SetItemText (s.first, std_to_wx (d->name()));
 
-       Config::instance()->write ();
+       Config::instance()->changed ();
 
        d->Destroy ();
 }
@@ -320,9 +354,11 @@ KDMDialog::remove_screen_clicked ()
        pair<wxTreeItemId, shared_ptr<Screen> > s = selected_screens().front();
 
        map<wxTreeItemId, shared_ptr<Cinema> >::iterator i = _cinemas.begin ();
-       list<shared_ptr<Screen> > sc = i->second->screens ();
-       while (i != _cinemas.end() && find (sc.begin(), sc.end(), s.second) == sc.end()) {
-               ++i;
+       while (i != _cinemas.end ()) {
+               list<shared_ptr<Screen> > sc = i->second->screens ();
+               if (find (sc.begin(), sc.end(), s.second) != sc.end ()) {
+                       break;
+               }
        }
 
        if (i == _cinemas.end()) {
@@ -332,7 +368,7 @@ KDMDialog::remove_screen_clicked ()
        i->second->remove_screen (s.second);
        _targets->Delete (s.first);
 
-       Config::instance()->write ();
+       Config::instance()->changed ();
 }
 
 list<shared_ptr<Screen> >
@@ -382,7 +418,15 @@ KDMDialog::until () const
        return posix_time (_until_date, _until_time);
 }
 
-string
+boost::filesystem::path
+KDMDialog::dcp () const
+{
+       int const item = _dcps->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+       assert (item >= 0);
+       return wx_to_std (_dcps->GetItemText (item));
+}
+
+boost::filesystem::path
 KDMDialog::directory () const
 {
        return wx_to_std (_folder->GetPath ());