Move subtitle export to its own dialogue.
[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)
38         : TableDialog (parent, _("Export subtitles"), 2, 1, true)
39         , _initial_name (name)
40 {
41         _split_reels = new CheckBox (this, _("Write reels into separate files"));
42         add (_split_reels, false);
43         add_spacer ();
44
45         add (_("Output file"), true);
46         /* Don't warn overwrite here, because on Linux (at least) if we specify a filename like foo
47            the wxFileDialog will check that foo exists, but we will add an extension so we actually
48            need to check if foo.mov (or similar) exists.  I can't find a way to make wxWidgets do this,
49            so disable its check and the caller will have to do it themselves.
50         */
51         _file = new FilePickerCtrl (this, _("Select output file"), _("Subtitle files (.xml)|*.xml"), false, false);
52         _file->SetPath (_initial_name);
53         add (_file);
54
55         _file->Bind (wxEVT_FILEPICKER_CHANGED, bind(&ExportSubtitlesDialog::file_changed, this));
56
57         layout ();
58
59         wxButton* ok = dynamic_cast<wxButton *>(FindWindowById(wxID_OK, this));
60         ok->Enable (false);
61 }
62
63
64 boost::filesystem::path
65 ExportSubtitlesDialog::path () const
66 {
67         wxFileName fn (_file->GetPath());
68         fn.SetExt (".xml");
69         return wx_to_std (fn.GetFullPath());
70 }
71
72
73 bool
74 ExportSubtitlesDialog::split_reels () const
75 {
76         return _split_reels->GetValue ();
77 }
78
79
80 void
81 ExportSubtitlesDialog::file_changed ()
82 {
83         wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
84         DCPOMATIC_ASSERT (ok);
85         ok->Enable (path().is_absolute());
86 }