Add preference for default KDM target directory (#1013).
[dcpomatic.git] / src / wx / kdm_output_panel.cc
1 /*
2     Copyright (C) 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 "lib/config.h"
22 #include "kdm_output_panel.h"
23 #include "wx_util.h"
24 #include "name_format_editor.h"
25 #include <dcp/types.h>
26 #ifdef DCPOMATIC_USE_OWN_PICKER
27 #include "dir_picker_ctrl.h"
28 #else
29 #include <wx/filepicker.h>
30 #endif
31 #include <wx/stdpaths.h>
32
33 KDMOutputPanel::KDMOutputPanel (wxWindow* parent, bool interop)
34         : wxPanel (parent, wxID_ANY)
35 {
36         wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, 0);
37
38         add_label_to_sizer (table, this, _("KDM type"), true);
39         _type = new wxChoice (this, wxID_ANY);
40         _type->Append ("Modified Transitional 1", ((void *) dcp::MODIFIED_TRANSITIONAL_1));
41         _type->Append ("Modified Transitional 1 (without AuthorizedDeviceInfo)", ((void *) dcp::MODIFIED_TRANSITIONAL_TEST));
42         if (!interop) {
43                 _type->Append ("DCI Any", ((void *) dcp::DCI_ANY));
44                 _type->Append ("DCI Specific", ((void *) dcp::DCI_SPECIFIC));
45         }
46         table->Add (_type, 1, wxEXPAND);
47         _type->SetSelection (0);
48
49         {
50                 int flags = wxALIGN_TOP | wxTOP | wxLEFT | wxRIGHT;
51                 wxString t = _("Filename format");
52 #ifdef __WXOSX__
53                 flags |= wxALIGN_RIGHT;
54                 t += wxT (":");
55 #endif
56                 wxStaticText* m = new wxStaticText (this, wxID_ANY, t);
57                 table->Add (m, 0, flags, DCPOMATIC_SIZER_Y_GAP);
58         }
59
60         dcp::NameFormat::Map titles;
61         titles['f'] = "film name";
62         titles['c'] = "cinema";
63         titles['s'] = "screen";
64         titles['b'] = "from date/time";
65         titles['e'] = "to date/time";
66         dcp::NameFormat::Map ex;
67         ex['f'] = "Bambi";
68         ex['c'] = "Lumière";
69         ex['s'] = "Screen 1";
70         ex['b'] = "2012/03/15 12:30";
71         ex['e'] = "2012/03/22 02:30";
72         _filename_format = new NameFormatEditor (this, Config::instance()->kdm_filename_format(), titles, ex, ".xml");
73         table->Add (_filename_format->panel(), 1, wxEXPAND);
74
75         _write_to = new wxCheckBox (this, wxID_ANY, _("Write to"));
76         table->Add (_write_to, 1, wxEXPAND);
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         boost::optional<boost::filesystem::path> path = Config::instance()->default_kdm_directory ();
85         if (path) {
86                 _folder->SetPath (std_to_wx (path->string ()));
87         } else {
88                 _folder->SetPath (wxStandardPaths::Get().GetDocumentsDir());
89         }
90
91         table->Add (_folder, 1, wxEXPAND);
92
93         _email = new wxCheckBox (this, wxID_ANY, _("Send by email"));
94         table->Add (_email, 1, wxEXPAND);
95         table->AddSpacer (0);
96
97         _write_to->SetValue (true);
98
99         _write_to->Bind (wxEVT_RADIOBUTTON, boost::bind (&KDMOutputPanel::setup_sensitivity, this));
100         _email->Bind    (wxEVT_RADIOBUTTON, boost::bind (&KDMOutputPanel::setup_sensitivity, this));
101
102         SetSizer (table);
103 }
104
105 void
106 KDMOutputPanel::setup_sensitivity ()
107 {
108         _folder->Enable (_write_to->GetValue ());
109 }
110
111 boost::filesystem::path
112 KDMOutputPanel::directory () const
113 {
114         return wx_to_std (_folder->GetPath ());
115 }
116
117 bool
118 KDMOutputPanel::write_to () const
119 {
120         return _write_to->GetValue ();
121 }
122
123 bool
124 KDMOutputPanel::email () const
125 {
126         return _email->GetValue ();
127 }
128
129 dcp::Formulation
130 KDMOutputPanel::formulation () const
131 {
132         return (dcp::Formulation) reinterpret_cast<intptr_t> (_type->GetClientData (_type->GetSelection()));
133 }
134
135 void
136 KDMOutputPanel::save_kdm_name_format () const
137 {
138         Config::instance()->set_kdm_filename_format (name_format ());
139 }
140
141 dcp::NameFormat
142 KDMOutputPanel::name_format () const
143 {
144         return _filename_format->get ();
145 }