bcc8adbe14e1fd9ca9c3bceb9a47a6b90ca05c88
[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 "lib/warnings.h"
27 DCPOMATIC_DISABLE_WARNINGS
28 #include <wx/filepicker.h>
29 DCPOMATIC_ENABLE_WARNINGS
30 #include <boost/bind.hpp>
31
32
33 using std::string;
34 using boost::bind;
35
36
37 ExportSubtitlesDialog::ExportSubtitlesDialog (wxWindow* parent, string name, bool interop)
38         : TableDialog (parent, _("Export subtitles"), 2, 1, true)
39         , _initial_name (name)
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         if (interop) {
46                 _include_font = new CheckBox (this, _("Define font in output and export font file"));
47                 add (_include_font, false);
48                 add_spacer ();
49         }
50
51         add (_("Output file"), true);
52         /* Don't warn overwrite here, because on Linux (at least) if we specify a filename like foo
53            the wxFileDialog will check that foo exists, but we will add an extension so we actually
54            need to check if foo.mov (or similar) exists.  I can't find a way to make wxWidgets do this,
55            so disable its check and the caller will have to do it themselves.
56         */
57         _file = new FilePickerCtrl (this, _("Select output file"), _("Subtitle files (.xml)|*.xml"), false, false);
58         _file->SetPath (_initial_name);
59         add (_file);
60
61         _file->Bind (wxEVT_FILEPICKER_CHANGED, bind(&ExportSubtitlesDialog::file_changed, this));
62
63         layout ();
64
65         wxButton* ok = dynamic_cast<wxButton *>(FindWindowById(wxID_OK, this));
66         ok->Enable (false);
67 }
68
69
70 boost::filesystem::path
71 ExportSubtitlesDialog::path () const
72 {
73         wxFileName fn (_file->GetPath());
74         fn.SetExt (".xml");
75         return wx_to_std (fn.GetFullPath());
76 }
77
78
79 bool
80 ExportSubtitlesDialog::split_reels () const
81 {
82         return _split_reels->GetValue ();
83 }
84
85
86 bool
87 ExportSubtitlesDialog::include_font () const
88 {
89         return _include_font ? _include_font->GetValue () : true;
90 }
91
92
93 void
94 ExportSubtitlesDialog::file_changed ()
95 {
96         wxButton* ok = dynamic_cast<wxButton *> (FindWindowById(wxID_OK, this));
97         DCPOMATIC_ASSERT (ok);
98         ok->Enable (path().is_absolute());
99 }