Remove player activity logging. Fixes #2122.
[dcpomatic.git] / src / wx / player_config_dialog.cc
1 /*
2     Copyright (C) 2012-2019 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 /** @file src/player_config_dialog.cc
22  *  @brief A dialogue to edit DCP-o-matic Player configuration.
23  */
24
25 #include "config_dialog.h"
26 #include "wx_util.h"
27 #include "editable_list.h"
28 #include "filter_dialog.h"
29 #include "file_picker_ctrl.h"
30 #include "dir_picker_ctrl.h"
31 #include "server_dialog.h"
32 #include "make_chain_dialog.h"
33 #include "email_dialog.h"
34 #include "name_format_editor.h"
35 #include "nag_dialog.h"
36 #include "check_box.h"
37 #include "static_text.h"
38 #include "lib/config.h"
39 #include "lib/ratio.h"
40 #include "lib/filter.h"
41 #include "lib/dcp_content_type.h"
42 #include "lib/log.h"
43 #include "lib/util.h"
44 #include "lib/cross.h"
45 #include "lib/exceptions.h"
46 #include <dcp/locale_convert.h>
47 #include <dcp/exceptions.h>
48 #include <dcp/certificate_chain.h>
49 #include <wx/stdpaths.h>
50 #include <wx/preferences.h>
51 #include <wx/spinctrl.h>
52 #include <wx/filepicker.h>
53 #include <RtAudio.h>
54 #include <boost/filesystem.hpp>
55 #include <iostream>
56
57 using std::vector;
58 using std::string;
59 using std::list;
60 using std::cout;
61 using std::pair;
62 using std::make_pair;
63 using std::map;
64 using boost::bind;
65 using std::shared_ptr;
66 using std::function;
67 using boost::optional;
68 #if BOOST_VERSION >= 106100
69 using namespace boost::placeholders;
70 #endif
71 using dcp::locale_convert;
72
73 class PlayerGeneralPage : public GeneralPage
74 {
75 public:
76         PlayerGeneralPage (wxSize panel_size, int border)
77                 : GeneralPage (panel_size, border)
78         {}
79
80 private:
81         void setup ()
82         {
83                 wxGridBagSizer* table = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
84                 _panel->GetSizer()->Add (table, 1, wxALL | wxEXPAND, _border);
85
86                 int r = 0;
87                 add_language_controls (table, r);
88                 add_update_controls (table, r);
89
90                 add_label_to_sizer (table, _panel, _("Start player as"), true, wxGBPosition(r, 0));
91                 _player_mode = new wxChoice (_panel, wxID_ANY);
92                 _player_mode->Append (_("window"));
93                 _player_mode->Append (_("full screen"));
94                 _player_mode->Append (_("full screen with controls on other monitor"));
95                 table->Add (_player_mode, wxGBPosition(r, 1));
96                 ++r;
97
98                 add_label_to_sizer (table, _panel, _("Dual-screen displays"), true, wxGBPosition(r, 0));
99                 _image_display = new wxChoice (_panel, wxID_ANY);
100                 _image_display->Append (_("Image on primary, controls on secondary"));
101                 _image_display->Append (_("Image on secondary, controls on primary"));
102                 table->Add (_image_display, wxGBPosition(r, 1));
103                 ++r;
104
105                 add_label_to_sizer (table, _panel, _("Video display mode"), true, wxGBPosition(r, 0));
106                 _video_display_mode = new wxChoice (_panel, wxID_ANY);
107                 _video_display_mode->Append (_("Simple (safer)"));
108                 _video_display_mode->Append (_("OpenGL (faster)"));
109                 table->Add (_video_display_mode, wxGBPosition(r, 1));
110                 ++r;
111
112                 wxStaticText* restart = add_label_to_sizer (table, _panel, _("(restart DCP-o-matic to change display mode)"), false, wxGBPosition(r, 0));
113                 wxFont font = restart->GetFont();
114                 font.SetStyle (wxFONTSTYLE_ITALIC);
115                 font.SetPointSize (font.GetPointSize() - 1);
116                 restart->SetFont (font);
117                 ++r;
118
119                 _respect_kdm = new CheckBox (_panel, _("Respect KDM validity periods"));
120                 table->Add (_respect_kdm, wxGBPosition(r, 0), wxGBSpan(1, 2));
121                 ++r;
122
123                 add_label_to_sizer (table, _panel, _("Debug log file"), true, wxGBPosition (r, 0));
124                 _debug_log_file = new FilePickerCtrl (_panel, _("Select debug log file"), "*", false, true);
125                 table->Add (_debug_log_file, wxGBPosition(r, 1));
126                 ++r;
127
128                 _player_mode->Bind (wxEVT_CHOICE, bind(&PlayerGeneralPage::player_mode_changed, this));
129                 _image_display->Bind (wxEVT_CHOICE, bind(&PlayerGeneralPage::image_display_changed, this));
130                 _video_display_mode->Bind (wxEVT_CHOICE, bind(&PlayerGeneralPage::video_display_mode_changed, this));
131                 _respect_kdm->Bind (wxEVT_CHECKBOX, bind(&PlayerGeneralPage::respect_kdm_changed, this));
132                 _debug_log_file->Bind (wxEVT_FILEPICKER_CHANGED, bind(&PlayerGeneralPage::debug_log_file_changed, this));
133         }
134
135         void config_changed ()
136         {
137                 GeneralPage::config_changed ();
138
139                 Config* config = Config::instance ();
140
141                 switch (config->player_mode()) {
142                 case Config::PLAYER_MODE_WINDOW:
143                         checked_set (_player_mode, 0);
144                         break;
145                 case Config::PLAYER_MODE_FULL:
146                         checked_set (_player_mode, 1);
147                         break;
148                 case Config::PLAYER_MODE_DUAL:
149                         checked_set (_player_mode, 2);
150                         break;
151                 }
152
153                 switch (config->video_view_type()) {
154                 case Config::VIDEO_VIEW_SIMPLE:
155                         checked_set (_video_display_mode, 0);
156                         break;
157                 case Config::VIDEO_VIEW_OPENGL:
158                         checked_set (_video_display_mode, 1);
159                         break;
160                 }
161
162                 checked_set (_image_display, config->image_display());
163                 checked_set (_respect_kdm, config->respect_kdm_validity_periods());
164                 if (config->player_debug_log_file()) {
165                         checked_set (_debug_log_file, *config->player_debug_log_file());
166                 }
167         }
168
169 private:
170         void player_mode_changed ()
171         {
172                 switch (_player_mode->GetSelection()) {
173                 case 0:
174                         Config::instance()->set_player_mode(Config::PLAYER_MODE_WINDOW);
175                         break;
176                 case 1:
177                         Config::instance()->set_player_mode(Config::PLAYER_MODE_FULL);
178                         break;
179                 case 2:
180                         Config::instance()->set_player_mode(Config::PLAYER_MODE_DUAL);
181                         break;
182                 }
183         }
184
185         void image_display_changed ()
186         {
187                 Config::instance()->set_image_display(_image_display->GetSelection());
188         }
189
190         void video_display_mode_changed ()
191         {
192                 if (_video_display_mode->GetSelection() == 0) {
193                         Config::instance()->set_video_view_type (Config::VIDEO_VIEW_SIMPLE);
194                 } else {
195                         Config::instance()->set_video_view_type (Config::VIDEO_VIEW_OPENGL);
196                 }
197         }
198
199         void respect_kdm_changed ()
200         {
201                 Config::instance()->set_respect_kdm_validity_periods(_respect_kdm->GetValue());
202         }
203
204         void debug_log_file_changed ()
205         {
206                 Config::instance()->set_player_debug_log_file(wx_to_std(_debug_log_file->GetPath()));
207         }
208
209         wxChoice* _player_mode;
210         wxChoice* _image_display;
211         wxChoice* _video_display_mode;
212         wxCheckBox* _respect_kdm;
213         FilePickerCtrl* _debug_log_file;
214 };
215
216
217 /** @class PlayerAdvancedPage
218  *  @brief Advanced page of the preferences dialog for the player.
219  */
220 class PlayerAdvancedPage : public Page
221 {
222 public:
223         PlayerAdvancedPage (wxSize panel_size, int border)
224                 : Page (panel_size, border)
225                 , _log_general (0)
226                 , _log_warning (0)
227                 , _log_error (0)
228                 , _log_timing (0)
229         {}
230
231         wxString GetName () const
232         {
233                 return _("Advanced");
234         }
235
236 #ifdef DCPOMATIC_OSX
237         wxBitmap GetLargeIcon () const
238         {
239                 return wxBitmap ("advanced", wxBITMAP_TYPE_PNG_RESOURCE);
240         }
241 #endif
242
243 private:
244         void add_top_aligned_label_to_sizer (wxSizer* table, wxWindow* parent, wxString text)
245         {
246                 int flags = wxALIGN_TOP | wxTOP | wxLEFT;
247 #ifdef __WXOSX__
248                 flags |= wxALIGN_RIGHT;
249                 text += wxT (":");
250 #endif
251                 wxStaticText* m = new StaticText (parent, text);
252                 table->Add (m, 0, flags, DCPOMATIC_SIZER_Y_GAP);
253         }
254
255         void setup ()
256         {
257                 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
258                 table->AddGrowableCol (1, 1);
259                 _panel->GetSizer()->Add (table, 1, wxALL | wxEXPAND, _border);
260
261                 {
262                         add_top_aligned_label_to_sizer (table, _panel, _("Log"));
263                         wxBoxSizer* t = new wxBoxSizer (wxVERTICAL);
264                         _log_general = new CheckBox (_panel, _("General"));
265                         t->Add (_log_general, 1, wxEXPAND | wxALL);
266                         _log_warning = new CheckBox (_panel, _("Warnings"));
267                         t->Add (_log_warning, 1, wxEXPAND | wxALL);
268                         _log_error = new CheckBox (_panel, _("Errors"));
269                         t->Add (_log_error, 1, wxEXPAND | wxALL);
270                         /// TRANSLATORS: translate the word "Timing" here; do not include the "Config|" prefix
271                         _log_timing = new CheckBox (_panel, S_("Config|Timing"));
272                         t->Add (_log_timing, 1, wxEXPAND | wxALL);
273                         table->Add (t, 0, wxALL, 6);
274                 }
275
276 #ifdef DCPOMATIC_WINDOWS
277                 _win32_console = new CheckBox (_panel, _("Open console window"));
278                 table->Add (_win32_console, 1, wxEXPAND | wxALL);
279                 table->AddSpacer (0);
280 #endif
281
282                 _log_general->Bind (wxEVT_CHECKBOX, boost::bind (&PlayerAdvancedPage::log_changed, this));
283                 _log_warning->Bind (wxEVT_CHECKBOX, boost::bind (&PlayerAdvancedPage::log_changed, this));
284                 _log_error->Bind (wxEVT_CHECKBOX, boost::bind (&PlayerAdvancedPage::log_changed, this));
285                 _log_timing->Bind (wxEVT_CHECKBOX, boost::bind (&PlayerAdvancedPage::log_changed, this));
286 #ifdef DCPOMATIC_WINDOWS
287                 _win32_console->Bind (wxEVT_CHECKBOX, boost::bind (&PlayerAdvancedPage::win32_console_changed, this));
288 #endif
289         }
290
291         void config_changed ()
292         {
293                 Config* config = Config::instance ();
294
295                 checked_set (_log_general, config->log_types() & LogEntry::TYPE_GENERAL);
296                 checked_set (_log_warning, config->log_types() & LogEntry::TYPE_WARNING);
297                 checked_set (_log_error, config->log_types() & LogEntry::TYPE_ERROR);
298                 checked_set (_log_timing, config->log_types() & LogEntry::TYPE_TIMING);
299 #ifdef DCPOMATIC_WINDOWS
300                 checked_set (_win32_console, config->win32_console());
301 #endif
302         }
303
304         void log_changed ()
305         {
306                 int types = 0;
307                 if (_log_general->GetValue ()) {
308                         types |= LogEntry::TYPE_GENERAL;
309                 }
310                 if (_log_warning->GetValue ()) {
311                         types |= LogEntry::TYPE_WARNING;
312                 }
313                 if (_log_error->GetValue ())  {
314                         types |= LogEntry::TYPE_ERROR;
315                 }
316                 if (_log_timing->GetValue ()) {
317                         types |= LogEntry::TYPE_TIMING;
318                 }
319                 Config::instance()->set_log_types (types);
320         }
321
322 #ifdef DCPOMATIC_WINDOWS
323         void win32_console_changed ()
324         {
325                 Config::instance()->set_win32_console (_win32_console->GetValue ());
326         }
327 #endif
328
329         wxCheckBox* _log_general;
330         wxCheckBox* _log_warning;
331         wxCheckBox* _log_error;
332         wxCheckBox* _log_timing;
333 #ifdef DCPOMATIC_WINDOWS
334         wxCheckBox* _win32_console;
335 #endif
336 };
337
338
339 wxPreferencesEditor*
340 create_player_config_dialog ()
341 {
342         wxPreferencesEditor* e = new wxPreferencesEditor (_("DCP-o-matic Player Preferences"));
343
344 #ifdef DCPOMATIC_OSX
345         /* Width that we force some of the config panels to be on OSX so that
346            the containing window doesn't shrink too much when we select those panels.
347            This is obviously an unpleasant hack.
348         */
349         wxSize ps = wxSize (520, -1);
350         int const border = 16;
351 #else
352         wxSize ps = wxSize (-1, -1);
353         int const border = 8;
354 #endif
355
356         e->AddPage (new PlayerGeneralPage(wxSize(-1, 500), border));
357         e->AddPage (new SoundPage(ps, border));
358         e->AddPage (new LocationsPage(ps, border));
359         e->AddPage (new KeysPage(ps, border));
360         e->AddPage (new PlayerAdvancedPage(ps, border));
361         return e;
362 }