001b8d328c06e1b3156787c3d106f5ce009af851
[dcpomatic.git] / src / wx / self_dkdm_dialog.cc
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "self_dkdm_dialog.h"
22 #include "wx_util.h"
23 #include "kdm_output_panel.h"
24 #include "kdm_cpl_panel.h"
25 #include "lib/film.h"
26 #include "lib/screen.h"
27 #include <libcxml/cxml.h>
28 #ifdef DCPOMATIC_USE_OWN_PICKER
29 #include "dir_picker_ctrl.h"
30 #else
31 #include <wx/filepicker.h>
32 #endif
33 #include <wx/treectrl.h>
34 #include <wx/listctrl.h>
35 #include <wx/stdpaths.h>
36 #include <iostream>
37
38 using std::string;
39 using std::map;
40 using std::list;
41 using std::pair;
42 using std::cout;
43 using std::vector;
44 using std::make_pair;
45 using boost::shared_ptr;
46 using boost::bind;
47
48 SelfDKDMDialog::SelfDKDMDialog (wxWindow* parent, boost::shared_ptr<const Film> film)
49         : wxDialog (parent, wxID_ANY, _("Make DKDM for DCP-o-matic"))
50 {
51         /* Main sizer */
52         wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
53
54         /* Font for sub-headings */
55         wxFont subheading_font (*wxNORMAL_FONT);
56         subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
57
58         /* Sub-heading: CPL */
59         wxStaticText* h = new wxStaticText (this, wxID_ANY, _("CPL"));
60         h->SetFont (subheading_font);
61         vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_Y_GAP * 2);
62         _cpl = new KDMCPLPanel (this, film->cpls ());
63         vertical->Add (_cpl);
64
65         /* Sub-heading: output */
66         h = new wxStaticText (this, wxID_ANY, _("Output"));
67         h->SetFont (subheading_font);
68         vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
69
70         _internal = new wxRadioButton (this, wxID_ANY, _("Save to KDM Creator tool's list"));
71         vertical->Add (_internal, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP);
72
73         wxBoxSizer* w = new wxBoxSizer (wxHORIZONTAL);
74
75         _write_to = new wxRadioButton (this, wxID_ANY, _("Write to"));
76         w->Add (_write_to, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, DCPOMATIC_SIZER_GAP);
77
78 #ifdef DCPOMATIC_USE_OWN_PICKER
79         _folder = new DirPickerCtrl (this);
80 #else
81         _folder = new wxDirPickerCtrl (this, wxID_ANY, wxEmptyString, wxDirSelectorPromptStr, wxDefaultPosition, wxSize (300, -1));
82 #endif
83
84         _folder->SetPath (wxStandardPaths::Get().GetDocumentsDir());
85
86         w->Add (_folder, 1, wxEXPAND);
87
88         vertical->Add (w, 0, wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
89
90         /* Make an overall sizer to get a nice border, and put some buttons in */
91
92         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
93         overall_sizer->Add (vertical, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
94
95         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
96         if (buttons) {
97                 overall_sizer->Add (buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
98         }
99
100         setup_sensitivity ();
101
102         SetSizer (overall_sizer);
103         overall_sizer->Layout ();
104         overall_sizer->SetSizeHints (this);
105
106         _internal->Bind (wxEVT_COMMAND_RADIOBUTTON_SELECTED, bind (&SelfDKDMDialog::setup_sensitivity, this));
107         _write_to->Bind (wxEVT_COMMAND_RADIOBUTTON_SELECTED, bind (&SelfDKDMDialog::setup_sensitivity, this));
108 }
109
110 void
111 SelfDKDMDialog::setup_sensitivity ()
112 {
113         _folder->Enable (_write_to->GetValue ());
114
115         wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
116         if (ok) {
117                 ok->Enable (_cpl->has_selected ());
118         }
119 }
120
121 boost::filesystem::path
122 SelfDKDMDialog::cpl () const
123 {
124         return _cpl->cpl ();
125 }
126
127 bool
128 SelfDKDMDialog::internal () const
129 {
130         return _internal->GetValue ();
131 }
132
133 boost::filesystem::path
134 SelfDKDMDialog::directory () const
135 {
136         return wx_to_std (_folder->GetPath ());
137 }