macOS / new boost build fixes.
[dcpomatic.git] / src / wx / content_advanced_dialog.cc
1 /*
2     Copyright (C) 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 "content_advanced_dialog.h"
23 #include "dcpomatic_button.h"
24 #include "filter_dialog.h"
25 #include "static_text.h"
26 #include "wx_util.h"
27 #include "lib/content.h"
28 #include "lib/filter.h"
29 #include "lib/ffmpeg_content.h"
30 #include "lib/video_content.h"
31 #include <wx/gbsizer.h>
32 #include <boost/bind.hpp>
33
34
35 using std::string;
36 using std::vector;
37 using boost::bind;
38 using boost::dynamic_pointer_cast;
39 using boost::shared_ptr;
40 #if BOOST_VERSION >= 106100
41 using namespace boost::placeholders;
42 #endif
43
44
45
46 ContentAdvancedDialog::ContentAdvancedDialog (wxWindow* parent, shared_ptr<Content> content)
47         : wxDialog (parent, wxID_ANY, _("Advanced content settings"))
48         , _content (content)
49 {
50         wxGridBagSizer* sizer = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
51
52         int r = 0;
53
54         wxClientDC dc (this);
55         wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
56 #ifdef __WXGTK3__
57         size.SetWidth (size.GetWidth() + 64);
58 #endif
59         size.SetHeight (-1);
60
61         add_label_to_sizer (sizer, this, _("Video filters"), true, wxGBPosition(r, 0));
62         _filters = new StaticText (this, _("None"), wxDefaultPosition, size);
63         _filters_button = new Button (this, _("Edit..."));
64         wxBoxSizer* filters = new wxBoxSizer (wxHORIZONTAL);
65         filters->Add (_filters, 1, wxALL | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
66         filters->Add (_filters_button, 0, wxALL, DCPOMATIC_SIZER_GAP);
67         sizer->Add (filters, wxGBPosition(r, 1));
68         ++r;
69
70         wxCheckBox* ignore_video = new wxCheckBox (this, wxID_ANY, _("Ignore this content's video and use only audio, subtitles and closed captions"));
71         sizer->Add (ignore_video, wxGBPosition(r, 0), wxGBSpan(1, 2));
72         ++r;
73
74         wxSizer* overall = new wxBoxSizer (wxVERTICAL);
75         overall->Add (sizer, 1, wxALL, DCPOMATIC_DIALOG_BORDER);
76         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
77         if (buttons) {
78                 overall->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
79         }
80
81         SetSizerAndFit (overall);
82
83         ignore_video->Enable (static_cast<bool>(_content->video));
84         ignore_video->SetValue (_content->video ? !content->video->use() : false);
85         setup_filters ();
86
87         ignore_video->Bind (wxEVT_CHECKBOX, bind(&ContentAdvancedDialog::ignore_video_changed, this, _1));
88         _filters_button->Bind (wxEVT_BUTTON, bind(&ContentAdvancedDialog::edit_filters, this));
89 }
90
91
92 void
93 ContentAdvancedDialog::ignore_video_changed (wxCommandEvent& ev)
94 {
95          if (_content->video) {
96                  _content->video->set_use (!ev.IsChecked());
97          }
98 }
99
100
101 void
102 ContentAdvancedDialog::setup_filters ()
103 {
104         shared_ptr<FFmpegContent> fcs = dynamic_pointer_cast<FFmpegContent>(_content);
105         if (!fcs) {
106                 checked_set (_filters, _("None"));
107                 _filters->Enable (false);
108                 _filters_button->Enable (false);
109                 return;
110         }
111
112         string p = Filter::ffmpeg_string (fcs->filters());
113         if (p.empty()) {
114                 checked_set (_filters, _("None"));
115         } else {
116                 if (p.length() > 25) {
117                         p = p.substr(0, 25) + "...";
118                 }
119                 checked_set (_filters, p);
120         }
121 }
122
123
124 void
125 ContentAdvancedDialog::edit_filters ()
126 {
127         shared_ptr<FFmpegContent> fcs = dynamic_pointer_cast<FFmpegContent>(_content);
128         if (!fcs) {
129                 return;
130         }
131
132         FilterDialog* d = new FilterDialog (this, fcs->filters());
133         d->ActiveChanged.connect (bind(&ContentAdvancedDialog::filters_changed, this, _1));
134         d->ShowModal ();
135         d->Destroy ();
136 }
137
138
139 void
140 ContentAdvancedDialog::filters_changed (vector<Filter const *> filters)
141 {
142         shared_ptr<FFmpegContent> fcs = dynamic_pointer_cast<FFmpegContent>(_content);
143         if (!fcs) {
144                 return;
145         }
146
147         fcs->set_filters (filters);
148         setup_filters ();
149 }
150