Supporters update.
[dcpomatic.git] / src / wx / export_subtitles_dialog.cc
1 /*
2     Copyright (C) 2017-2020 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
22 #include "check_box.h"
23 #include "export_subtitles_dialog.h"
24 #include "file_picker_ctrl.h"
25 #include "wx_util.h"
26 #include <dcp/warnings.h>
27 LIBDCP_DISABLE_WARNINGS
28 #include <wx/filepicker.h>
29 LIBDCP_ENABLE_WARNINGS
30 #include <boost/bind/bind.hpp>
31
32
33 using std::string;
34 using boost::bind;
35
36
37 ExportSubtitlesDialog::ExportSubtitlesDialog (wxWindow* parent, int reels, bool interop)
38         : TableDialog (parent, _("Export subtitles"), 2, 1, true)
39         , _interop (interop)
40         , _include_font (0)
41 {
42         _split_reels = new CheckBox (this, _("Write reels into separate files"));
43         add (_split_reels, false);
44         add_spacer ();
45
46         if (reels > 1) {
47                 _split_reels->Enable (false);
48         }
49
50         _include_font = new CheckBox (this, _("Define font in output and export font file"));
51         add (_include_font, false);
52         add_spacer ();
53
54         if (!_interop) {
55                 _include_font->Enable (false);
56         }
57
58         wxString const wildcard = _interop ? _("Subtitle files (.xml)|*.xml") : _("Subtitle files (.mxf)|*.mxf");
59
60         _file_label = add (_("Output file"), true);
61         _file = new FilePickerCtrl(this, _("Select output file"), wildcard, false, true, "ExportSubtitlesPath");
62         add (_file);
63
64         _dir_label = add (_("Output folder"), true);
65         _dir = new DirPickerCtrl (this);
66         add (_dir);
67
68         _split_reels->bind(&ExportSubtitlesDialog::setup_sensitivity, this);
69         _include_font->bind(&ExportSubtitlesDialog::setup_sensitivity, this);
70         _file->Bind (wxEVT_FILEPICKER_CHANGED, bind(&ExportSubtitlesDialog::setup_sensitivity, this));
71         _dir->Bind (wxEVT_DIRPICKER_CHANGED, bind(&ExportSubtitlesDialog::setup_sensitivity, this));
72
73         layout ();
74         setup_sensitivity ();
75 }
76
77
78 void
79 ExportSubtitlesDialog::setup_sensitivity ()
80 {
81         bool const multi = split_reels() || (_interop && _include_font->GetValue());
82         _file_label->Enable (!multi);
83         _file->Enable (!multi);
84         _dir_label->Enable (multi);
85         _dir->Enable (multi);
86
87         wxButton* ok = dynamic_cast<wxButton *> (FindWindowById(wxID_OK, this));
88         DCPOMATIC_ASSERT (ok);
89         ok->Enable (path().is_absolute());
90 }
91
92
93 /** @return Either a full path to a file, if the output will be one file, or
94  *  a full path to a directory.
95  */
96 boost::filesystem::path
97 ExportSubtitlesDialog::path () const
98 {
99         if (_file->IsEnabled()) {
100                 if (auto path = _file->path()) {
101                         wxFileName fn(std_to_wx(path->string()));
102                         fn.SetExt(_interop ? "xml" : "mxf");
103                         return wx_to_std(fn.GetFullPath());
104                 }
105         }
106
107         return wx_to_std (_dir->GetPath());
108 }
109
110
111 bool
112 ExportSubtitlesDialog::split_reels () const
113 {
114         return _split_reels->GetValue ();
115 }
116
117
118 bool
119 ExportSubtitlesDialog::include_font () const
120 {
121         return !_interop || _include_font->GetValue();
122 }
123