Rename TYPE_DEBUG_PLAYER to TYPE_DEBUG_VIDEO_VIEW.
[dcpomatic.git] / src / lib / config.h
1 /*
2     Copyright (C) 2012-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 /** @file src/config.h
22  *  @brief Class holding configuration.
23  */
24
25 #ifndef DCPOMATIC_CONFIG_H
26 #define DCPOMATIC_CONFIG_H
27
28 #include "isdcf_metadata.h"
29 #include "types.h"
30 #include "state.h"
31 #include "edid.h"
32 #include "audio_mapping.h"
33 #include <dcp/name_format.h>
34 #include <dcp/certificate_chain.h>
35 #include <dcp/encrypted_kdm.h>
36 #include <boost/shared_ptr.hpp>
37 #include <boost/signals2.hpp>
38 #include <boost/filesystem.hpp>
39 #include <vector>
40
41 class CinemaSoundProcessor;
42 class DCPContentType;
43 class Ratio;
44 class Cinema;
45 class Film;
46 class DKDMGroup;
47 class DKDMRecipient;
48
49 /** @class Config
50  *  @brief A singleton class holding configuration.
51  */
52 class Config : public State
53 {
54 public:
55         /** @return number of threads which a master DoM should use for J2K encoding on the local machine */
56         int master_encoding_threads () const {
57                 return _master_encoding_threads;
58         }
59
60         /** @return number of threads which a server should use for J2K encoding on the local machine */
61         int server_encoding_threads () const {
62                 return _server_encoding_threads;
63         }
64
65         boost::optional<boost::filesystem::path> default_directory () const {
66                 return _default_directory;
67         }
68
69         boost::optional<boost::filesystem::path> default_kdm_directory () const {
70                 return _default_kdm_directory;
71         }
72
73         boost::filesystem::path default_directory_or (boost::filesystem::path a) const;
74         boost::filesystem::path default_kdm_directory_or (boost::filesystem::path a) const;
75
76         enum Property {
77                 USE_ANY_SERVERS,
78                 SERVERS,
79                 CINEMAS,
80                 DKDM_RECIPIENTS,
81                 SOUND,
82                 SOUND_OUTPUT,
83                 INTERFACE_COMPLEXITY,
84                 PLAYER_CONTENT_DIRECTORY,
85                 PLAYER_PLAYLIST_DIRECTORY,
86                 PLAYER_DEBUG_LOG,
87                 HISTORY,
88                 SHOW_EXPERIMENTAL_AUDIO_PROCESSORS,
89                 AUDIO_MAPPING,
90 #ifdef DCPOMATIC_VARIANT_SWAROOP
91                 PLAYER_BACKGROUND_IMAGE,
92 #endif
93                 OTHER
94         };
95
96         /** @return base port number to use for J2K encoding servers */
97         int server_port_base () const {
98                 return _server_port_base;
99         }
100
101         void set_use_any_servers (bool u) {
102                 _use_any_servers = u;
103                 changed (USE_ANY_SERVERS);
104         }
105
106         bool use_any_servers () const {
107                 return _use_any_servers;
108         }
109
110         /** @param s New list of servers */
111         void set_servers (std::vector<std::string> s) {
112                 _servers = s;
113                 changed (SERVERS);
114         }
115
116         /** @return Host names / IP addresses of J2K encoding servers that should definitely be used */
117         std::vector<std::string> servers () const {
118                 return _servers;
119         }
120
121         bool only_servers_encode () const {
122                 return _only_servers_encode;
123         }
124
125         FileTransferProtocol tms_protocol () const {
126                 return _tms_protocol;
127         }
128
129         /** @return The IP address of a TMS that we can copy DCPs to */
130         std::string tms_ip () const {
131                 return _tms_ip;
132         }
133
134         /** @return The path on a TMS that we should changed DCPs to */
135         std::string tms_path () const {
136                 return _tms_path;
137         }
138
139         /** @return User name to log into the TMS with */
140         std::string tms_user () const {
141                 return _tms_user;
142         }
143
144         /** @return Password to log into the TMS with */
145         std::string tms_password () const {
146                 return _tms_password;
147         }
148
149         std::list<boost::shared_ptr<Cinema> > cinemas () const {
150                 return _cinemas;
151         }
152
153         std::list<boost::shared_ptr<DKDMRecipient> > dkdm_recipients () const {
154                 return _dkdm_recipients;
155         }
156
157         std::list<int> allowed_dcp_frame_rates () const {
158                 return _allowed_dcp_frame_rates;
159         }
160
161         bool allow_any_dcp_frame_rate () const {
162                 return _allow_any_dcp_frame_rate;
163         }
164
165         bool allow_any_container () const {
166                 return _allow_any_container;
167         }
168
169         bool show_experimental_audio_processors () const {
170                 return _show_experimental_audio_processors;
171         }
172
173         ISDCFMetadata default_isdcf_metadata () const {
174                 return _default_isdcf_metadata;
175         }
176
177         boost::optional<std::string> language () const {
178                 return _language;
179         }
180
181         int default_still_length () const {
182                 return _default_still_length;
183         }
184
185         Ratio const * default_container () const {
186                 return _default_container;
187         }
188
189         DCPContentType const * default_dcp_content_type () const {
190                 return _default_dcp_content_type;
191         }
192
193         int default_dcp_audio_channels () const {
194                 return _default_dcp_audio_channels;
195         }
196
197         std::string dcp_issuer () const {
198                 return _dcp_issuer;
199         }
200
201         std::string dcp_creator () const {
202                 return _dcp_creator;
203         }
204
205         int default_j2k_bandwidth () const {
206                 return _default_j2k_bandwidth;
207         }
208
209         int default_audio_delay () const {
210                 return _default_audio_delay;
211         }
212
213         bool default_interop () const {
214                 return _default_interop;
215         }
216
217         bool default_upload_after_make_dcp () {
218                 return _default_upload_after_make_dcp;
219         }
220
221         void set_default_kdm_directory (boost::filesystem::path d) {
222                 if (_default_kdm_directory && _default_kdm_directory.get() == d) {
223                         return;
224                 }
225                 _default_kdm_directory = d;
226                 changed ();
227         }
228
229         std::string mail_server () const {
230                 return _mail_server;
231         }
232
233         int mail_port () const {
234                 return _mail_port;
235         }
236
237         EmailProtocol mail_protocol () const {
238                 return _mail_protocol;
239         }
240
241         std::string mail_user () const {
242                 return _mail_user;
243         }
244
245         std::string mail_password () const {
246                 return _mail_password;
247         }
248
249         std::string kdm_subject () const {
250                 return _kdm_subject;
251         }
252
253         std::string kdm_from () const {
254                 return _kdm_from;
255         }
256
257         std::vector<std::string> kdm_cc () const {
258                 return _kdm_cc;
259         }
260
261         std::string kdm_bcc () const {
262                 return _kdm_bcc;
263         }
264
265         std::string kdm_email () const {
266                 return _kdm_email;
267         }
268
269         std::string notification_subject () const {
270                 return _notification_subject;
271         }
272
273         std::string notification_from () const {
274                 return _notification_from;
275         }
276
277         std::string notification_to () const {
278                 return _notification_to;
279         }
280
281         std::vector<std::string> notification_cc () const {
282                 return _notification_cc;
283         }
284
285         std::string notification_bcc () const {
286                 return _notification_bcc;
287         }
288
289         std::string notification_email () const {
290                 return _notification_email;
291         }
292
293         boost::shared_ptr<const dcp::CertificateChain> signer_chain () const {
294                 return _signer_chain;
295         }
296
297         boost::shared_ptr<const dcp::CertificateChain> decryption_chain () const {
298                 return _decryption_chain;
299         }
300
301         bool check_for_updates () const {
302                 return _check_for_updates;
303         }
304
305         bool check_for_test_updates () const {
306                 return _check_for_test_updates;
307         }
308
309         int maximum_j2k_bandwidth () const {
310                 return _maximum_j2k_bandwidth;
311         }
312
313         int log_types () const {
314                 return _log_types;
315         }
316
317         bool analyse_ebur128 () const {
318                 return _analyse_ebur128;
319         }
320
321         bool automatic_audio_analysis () const {
322                 return _automatic_audio_analysis;
323         }
324
325 #ifdef DCPOMATIC_WINDOWS
326         bool win32_console () const {
327                 return _win32_console;
328         }
329 #endif
330
331         std::vector<boost::filesystem::path> history () const {
332                 return _history;
333         }
334
335         std::vector<boost::filesystem::path> player_history () const {
336                 return _player_history;
337         }
338
339         boost::shared_ptr<DKDMGroup> dkdms () const {
340                 return _dkdms;
341         }
342
343         boost::filesystem::path cinemas_file () const {
344                 return _cinemas_file;
345         }
346
347         boost::filesystem::path dkdm_recipients_file () const {
348                 return _dkdm_recipients_file;
349         }
350
351         bool show_hints_before_make_dcp () const {
352                 return _show_hints_before_make_dcp;
353         }
354
355         bool confirm_kdm_email () const {
356                 return _confirm_kdm_email;
357         }
358
359         dcp::NameFormat kdm_container_name_format () const {
360                 return _kdm_container_name_format;
361         }
362
363         dcp::NameFormat kdm_filename_format () const {
364                 return _kdm_filename_format;
365         }
366
367         dcp::NameFormat dkdm_filename_format () const {
368                 return _dkdm_filename_format;
369         }
370
371         dcp::NameFormat dcp_metadata_filename_format () const {
372                 return _dcp_metadata_filename_format;
373         }
374
375         dcp::NameFormat dcp_asset_filename_format () const {
376                 return _dcp_asset_filename_format;
377         }
378
379         bool jump_to_selected () const {
380                 return _jump_to_selected;
381         }
382
383         enum Nag {
384                 NAG_DKDM_CONFIG,
385                 NAG_ENCRYPTED_METADATA,
386                 NAG_ALTER_DECRYPTION_CHAIN,
387                 NAG_BAD_SIGNER_CHAIN,
388                 /* Not really a nag but it's the same idea */
389                 NAG_INITIAL_SETUP,
390                 NAG_IMPORT_DECRYPTION_CHAIN,
391                 NAG_DELETE_DKDM,
392                 NAG_32_ON_64,
393                 NAG_COUNT
394         };
395
396         bool nagged (Nag nag) const {
397                 return _nagged[nag];
398         }
399
400         bool sound () const {
401                 return _sound;
402         }
403
404         std::string cover_sheet () const {
405                 return _cover_sheet;
406         }
407
408         boost::optional<std::string> sound_output () const {
409                 return _sound_output;
410         }
411
412         boost::optional<boost::filesystem::path> last_player_load_directory () const {
413                 return _last_player_load_directory;
414         }
415
416         enum KDMWriteType {
417                 KDM_WRITE_FLAT,
418                 KDM_WRITE_FOLDER,
419                 KDM_WRITE_ZIP
420         };
421
422         boost::optional<KDMWriteType> last_kdm_write_type () const {
423                 return _last_kdm_write_type;
424         }
425
426         enum DKDMWriteType {
427                 DKDM_WRITE_INTERNAL,
428                 DKDM_WRITE_FILE
429         };
430
431         boost::optional<DKDMWriteType> last_dkdm_write_type () const {
432                 return _last_dkdm_write_type;
433         }
434
435         int frames_in_memory_multiplier () const {
436                 return _frames_in_memory_multiplier;
437         }
438
439         boost::optional<int> decode_reduction () const {
440                 return _decode_reduction;
441         }
442
443         bool default_notify () const {
444                 return _default_notify;
445         }
446
447         enum Notification {
448                 MESSAGE_BOX,
449                 EMAIL,
450                 NOTIFICATION_COUNT
451         };
452
453         bool notification (Notification n) const {
454                 return _notification[n];
455         }
456
457         boost::optional<std::string> barco_username () const {
458                 return _barco_username;
459         }
460
461         boost::optional<std::string> barco_password () const {
462                 return _barco_password;
463         }
464
465         boost::optional<std::string> christie_username () const {
466                 return _christie_username;
467         }
468
469         boost::optional<std::string> christie_password () const {
470                 return _christie_password;
471         }
472
473         boost::optional<std::string> gdc_username () const {
474                 return _gdc_username;
475         }
476
477         boost::optional<std::string> gdc_password () const {
478                 return _gdc_password;
479         }
480
481         enum Interface {
482                 INTERFACE_SIMPLE,
483                 INTERFACE_FULL
484         };
485
486         Interface interface_complexity () const {
487                 return _interface_complexity;
488         }
489
490         enum PlayerMode {
491                 PLAYER_MODE_WINDOW, ///< one window containing image and controls
492                 PLAYER_MODE_FULL,   ///< just the image filling the screen
493                 PLAYER_MODE_DUAL    ///< image on one monitor and extended controls on the other
494         };
495
496         PlayerMode player_mode () const {
497                 return _player_mode;
498         }
499
500         int image_display () const {
501                 return _image_display;
502         }
503
504         enum VideoViewType {
505                 VIDEO_VIEW_SIMPLE,
506                 VIDEO_VIEW_OPENGL
507         };
508
509         VideoViewType video_view_type () const {
510                 return _video_view_type;
511         }
512
513         bool respect_kdm_validity_periods () const {
514                 return _respect_kdm_validity_periods;
515         }
516
517         boost::optional<boost::filesystem::path> player_activity_log_file () const {
518                 return _player_activity_log_file;
519         }
520
521         boost::optional<boost::filesystem::path> player_debug_log_file () const {
522                 return _player_debug_log_file;
523         }
524
525         boost::optional<boost::filesystem::path> player_content_directory () const {
526                 return _player_content_directory;
527         }
528
529         boost::optional<boost::filesystem::path> player_playlist_directory () const {
530                 return _player_playlist_directory;
531         }
532
533         boost::optional<boost::filesystem::path> player_kdm_directory () const {
534                 return _player_kdm_directory;
535         }
536
537         AudioMapping audio_mapping (int output_channels);
538
539 #ifdef DCPOMATIC_VARIANT_SWAROOP
540         boost::optional<boost::filesystem::path> player_background_image () const {
541                 return _player_background_image;
542         }
543
544         std::string kdm_server_url () const {
545                 return _kdm_server_url;
546         }
547
548         std::string player_watermark_theatre () const {
549                 return _player_watermark_theatre;
550         }
551
552         int player_watermark_period () const {
553                 return _player_watermark_period;
554         }
555
556         int player_watermark_duration () const {
557                 return _player_watermark_duration;
558         }
559
560         std::vector<Monitor> required_monitors () const {
561                 return _required_monitors;
562         }
563
564         boost::optional<boost::filesystem::path> player_lock_file () const {
565                 return _player_lock_file;
566         }
567 #endif
568
569         /* SET (mostly) */
570
571         void set_master_encoding_threads (int n) {
572                 maybe_set (_master_encoding_threads, n);
573         }
574
575         void set_server_encoding_threads (int n) {
576                 maybe_set (_server_encoding_threads, n);
577         }
578
579         void set_default_directory (boost::filesystem::path d) {
580                 if (_default_directory && *_default_directory == d) {
581                         return;
582                 }
583                 _default_directory = d;
584                 changed ();
585         }
586
587         /** @param p New server port */
588         void set_server_port_base (int p) {
589                 maybe_set (_server_port_base, p);
590         }
591
592         void set_only_servers_encode (bool o) {
593                 maybe_set (_only_servers_encode, o);
594         }
595
596         void set_tms_protocol (FileTransferProtocol p) {
597                 maybe_set (_tms_protocol, p);
598         }
599
600         /** @param i IP address of a TMS that we can copy DCPs to */
601         void set_tms_ip (std::string i) {
602                 maybe_set (_tms_ip, i);
603         }
604
605         /** @param p Path on a TMS that we should changed DCPs to */
606         void set_tms_path (std::string p) {
607                 maybe_set (_tms_path, p);
608         }
609
610         /** @param u User name to log into the TMS with */
611         void set_tms_user (std::string u) {
612                 maybe_set (_tms_user, u);
613         }
614
615         /** @param p Password to log into the TMS with */
616         void set_tms_password (std::string p) {
617                 maybe_set (_tms_password, p);
618         }
619
620         void add_cinema (boost::shared_ptr<Cinema> c) {
621                 _cinemas.push_back (c);
622                 changed (CINEMAS);
623         }
624
625         void remove_cinema (boost::shared_ptr<Cinema> c) {
626                 _cinemas.remove (c);
627                 changed (CINEMAS);
628         }
629
630         void add_dkdm_recipient (boost::shared_ptr<DKDMRecipient> c) {
631                 _dkdm_recipients.push_back (c);
632                 changed (DKDM_RECIPIENTS);
633         }
634
635         void remove_dkdm_recipient (boost::shared_ptr<DKDMRecipient> c) {
636                 _dkdm_recipients.remove (c);
637                 changed (DKDM_RECIPIENTS);
638         }
639
640         void set_allowed_dcp_frame_rates (std::list<int> const & r) {
641                 maybe_set (_allowed_dcp_frame_rates, r);
642         }
643
644         void set_allow_any_dcp_frame_rate (bool a) {
645                 maybe_set (_allow_any_dcp_frame_rate, a);
646         }
647
648         void set_allow_any_container (bool a) {
649                 maybe_set (_allow_any_container, a);
650         }
651
652         void set_show_experimental_audio_processors (bool e) {
653                 maybe_set (_show_experimental_audio_processors, e, SHOW_EXPERIMENTAL_AUDIO_PROCESSORS);
654         }
655
656         void set_default_isdcf_metadata (ISDCFMetadata d) {
657                 maybe_set (_default_isdcf_metadata, d);
658         }
659
660         void set_language (std::string l) {
661                 if (_language && _language.get() == l) {
662                         return;
663                 }
664                 _language = l;
665                 changed ();
666         }
667
668         void unset_language () {
669                 if (!_language) {
670                         return;
671                 }
672
673                 _language = boost::none;
674                 changed ();
675         }
676
677         void set_default_still_length (int s) {
678                 maybe_set (_default_still_length, s);
679         }
680
681         void set_default_container (Ratio const * c) {
682                 maybe_set (_default_container, c);
683         }
684
685         void set_default_dcp_content_type (DCPContentType const * t) {
686                 maybe_set (_default_dcp_content_type, t);
687         }
688
689         void set_default_dcp_audio_channels (int c) {
690                 maybe_set (_default_dcp_audio_channels, c);
691         }
692
693         void set_dcp_issuer (std::string i) {
694                 maybe_set (_dcp_issuer, i);
695         }
696
697         void set_dcp_creator (std::string c) {
698                 maybe_set (_dcp_creator, c);
699         }
700
701         void set_default_j2k_bandwidth (int b) {
702                 maybe_set (_default_j2k_bandwidth, b);
703         }
704
705         void set_default_audio_delay (int d) {
706                 maybe_set (_default_audio_delay, d);
707         }
708
709         void set_default_interop (bool i) {
710                 maybe_set (_default_interop, i);
711         }
712
713         void set_default_upload_after_make_dcp (bool u) {
714                 maybe_set (_default_upload_after_make_dcp, u);
715         }
716
717         void set_mail_server (std::string s) {
718                 maybe_set (_mail_server, s);
719         }
720
721         void set_mail_port (int p) {
722                 maybe_set (_mail_port, p);
723         }
724
725         void set_mail_protocol (EmailProtocol p) {
726                 maybe_set (_mail_protocol, p);
727         }
728
729         void set_mail_user (std::string u) {
730                 maybe_set (_mail_user, u);
731         }
732
733         void set_mail_password (std::string p) {
734                 maybe_set (_mail_password, p);
735         }
736
737         void set_kdm_subject (std::string s) {
738                 maybe_set (_kdm_subject, s);
739         }
740
741         void set_kdm_from (std::string f) {
742                 maybe_set (_kdm_from, f);
743         }
744
745         void set_kdm_cc (std::vector<std::string> f) {
746                 maybe_set (_kdm_cc, f);
747         }
748
749         void set_kdm_bcc (std::string f) {
750                 maybe_set (_kdm_bcc, f);
751         }
752
753         void set_kdm_email (std::string e) {
754                 maybe_set (_kdm_email, e);
755         }
756
757         void reset_kdm_email ();
758
759         void set_notification_subject (std::string s) {
760                 maybe_set (_notification_subject, s);
761         }
762
763         void set_notification_from (std::string f) {
764                 maybe_set (_notification_from, f);
765         }
766
767         void set_notification_to (std::string t) {
768                 maybe_set (_notification_to, t);
769         }
770
771         void set_notification_cc (std::vector<std::string> f) {
772                 maybe_set (_notification_cc, f);
773         }
774
775         void set_notification_bcc (std::string f) {
776                 maybe_set (_notification_bcc, f);
777         }
778
779         void set_notification_email (std::string e) {
780                 maybe_set (_notification_email, e);
781         }
782
783         void reset_notification_email ();
784
785         void set_signer_chain (boost::shared_ptr<const dcp::CertificateChain> s) {
786                 maybe_set (_signer_chain, s);
787         }
788
789         void set_decryption_chain (boost::shared_ptr<const dcp::CertificateChain> c) {
790                 maybe_set (_decryption_chain, c);
791         }
792
793         void set_check_for_updates (bool c) {
794                 maybe_set (_check_for_updates, c);
795                 if (!c) {
796                         set_check_for_test_updates (false);
797                 }
798         }
799
800         void set_check_for_test_updates (bool c) {
801                 maybe_set (_check_for_test_updates, c);
802         }
803
804         void set_maximum_j2k_bandwidth (int b) {
805                 maybe_set (_maximum_j2k_bandwidth, b);
806         }
807
808         void set_log_types (int t) {
809                 maybe_set (_log_types, t);
810         }
811
812         void set_analyse_ebur128 (bool a) {
813                 maybe_set (_analyse_ebur128, a);
814         }
815
816         void set_automatic_audio_analysis (bool a) {
817                 maybe_set (_automatic_audio_analysis, a);
818         }
819
820 #ifdef DCPOMATIC_WINDOWS
821         void set_win32_console (bool c) {
822                 maybe_set (_win32_console, c);
823         }
824 #endif
825
826         void set_dkdms (boost::shared_ptr<DKDMGroup> dkdms) {
827                 _dkdms = dkdms;
828                 changed ();
829         }
830
831         void set_cinemas_file (boost::filesystem::path file);
832
833         void set_dkdm_recipients_file (boost::filesystem::path file);
834
835         void set_show_hints_before_make_dcp (bool s) {
836                 maybe_set (_show_hints_before_make_dcp, s);
837         }
838
839         void set_confirm_kdm_email (bool s) {
840                 maybe_set (_confirm_kdm_email, s);
841         }
842
843         void set_sound (bool s) {
844                 maybe_set (_sound, s, SOUND);
845         }
846
847         void set_sound_output (std::string o) {
848                 maybe_set (_sound_output, o, SOUND_OUTPUT);
849         }
850
851         void set_last_player_load_directory (boost::filesystem::path d) {
852                 maybe_set (_last_player_load_directory, d);
853         }
854
855         void set_last_kdm_write_type (KDMWriteType t) {
856                 maybe_set (_last_kdm_write_type, t);
857         }
858
859         void set_last_dkdm_write_type (DKDMWriteType t) {
860                 maybe_set (_last_dkdm_write_type, t);
861         }
862
863         void unset_sound_output () {
864                 if (!_sound_output) {
865                         return;
866                 }
867
868                 _sound_output = boost::none;
869                 changed ();
870         }
871
872         void set_kdm_container_name_format (dcp::NameFormat n) {
873                 maybe_set (_kdm_container_name_format, n);
874         }
875
876         void set_kdm_filename_format (dcp::NameFormat n) {
877                 maybe_set (_kdm_filename_format, n);
878         }
879
880         void set_dkdm_filename_format (dcp::NameFormat n) {
881                 maybe_set (_dkdm_filename_format, n);
882         }
883
884         void set_dcp_metadata_filename_format (dcp::NameFormat n) {
885                 maybe_set (_dcp_metadata_filename_format, n);
886         }
887
888         void set_dcp_asset_filename_format (dcp::NameFormat n) {
889                 maybe_set (_dcp_asset_filename_format, n);
890         }
891
892         void set_frames_in_memory_multiplier (int m) {
893                 maybe_set (_frames_in_memory_multiplier, m);
894         }
895
896         void set_decode_reduction (boost::optional<int> r) {
897                 maybe_set (_decode_reduction, r);
898         }
899
900         void set_default_notify (bool n) {
901                 maybe_set (_default_notify, n);
902         }
903
904         void clear_history () {
905                 _history.clear ();
906                 changed ();
907         }
908
909         void clear_player_history () {
910                 _player_history.clear ();
911                 changed ();
912         }
913
914         void add_to_history (boost::filesystem::path p);
915         void clean_history ();
916         void add_to_player_history (boost::filesystem::path p);
917         void clean_player_history ();
918
919         void set_jump_to_selected (bool j) {
920                 maybe_set (_jump_to_selected, j);
921         }
922
923         void set_nagged (Nag nag, bool nagged) {
924                 maybe_set (_nagged[nag], nagged);
925         }
926
927         void set_cover_sheet (std::string s) {
928                 maybe_set (_cover_sheet, s);
929         }
930
931         void reset_cover_sheet ();
932
933         void set_notification (Notification n, bool v) {
934                 maybe_set (_notification[n], v);
935         }
936
937         void set_barco_username (std::string u) {
938                 maybe_set (_barco_username, u);
939         }
940
941         void unset_barco_username () {
942                 maybe_set (_barco_username, boost::optional<std::string>());
943         }
944
945         void set_barco_password (std::string p) {
946                 maybe_set (_barco_password, p);
947         }
948
949         void unset_barco_password () {
950                 maybe_set (_barco_password, boost::optional<std::string>());
951         }
952
953         void set_christie_username (std::string u) {
954                 maybe_set (_christie_username, u);
955         }
956
957         void unset_christie_username () {
958                 maybe_set (_christie_username, boost::optional<std::string>());
959         }
960
961         void set_christie_password (std::string p) {
962                 maybe_set (_christie_password, p);
963         }
964
965         void unset_christie_password () {
966                 maybe_set (_christie_password, boost::optional<std::string>());
967         }
968
969         void set_gdc_username (std::string u) {
970                 maybe_set (_gdc_username, u);
971         }
972
973         void unset_gdc_username () {
974                 maybe_set (_gdc_username, boost::optional<std::string>());
975         }
976
977         void set_gdc_password (std::string p) {
978                 maybe_set (_gdc_password, p);
979         }
980
981         void unset_gdc_password () {
982                 maybe_set (_gdc_password, boost::optional<std::string>());
983         }
984
985         void set_interface_complexity (Interface i) {
986                 maybe_set (_interface_complexity, i, INTERFACE_COMPLEXITY);
987         }
988
989         void set_player_mode (PlayerMode m) {
990                 maybe_set (_player_mode, m);
991         }
992
993         void set_image_display (int n) {
994                 maybe_set (_image_display, n);
995         }
996
997         void set_video_view_type (VideoViewType v) {
998                 maybe_set (_video_view_type, v);
999         }
1000
1001         void set_respect_kdm_validity_periods (bool r) {
1002                 maybe_set (_respect_kdm_validity_periods, r);
1003         }
1004
1005         void set_player_activity_log_file (boost::filesystem::path p) {
1006                 maybe_set (_player_activity_log_file, p);
1007         }
1008
1009         void unset_player_activity_log_file () {
1010                 if (!_player_activity_log_file) {
1011                         return;
1012                 }
1013                 _player_activity_log_file = boost::none;
1014                 changed ();
1015         }
1016
1017         void set_player_debug_log_file (boost::filesystem::path p) {
1018                 maybe_set (_player_debug_log_file, p, PLAYER_DEBUG_LOG);
1019         }
1020
1021         void unset_player_debug_log_file () {
1022                 if (!_player_debug_log_file) {
1023                         return;
1024                 }
1025                 _player_debug_log_file = boost::none;
1026                 changed (PLAYER_DEBUG_LOG);
1027         }
1028
1029         void set_player_content_directory (boost::filesystem::path p) {
1030                 maybe_set (_player_content_directory, p, PLAYER_CONTENT_DIRECTORY);
1031         }
1032
1033         void unset_player_content_directory () {
1034                 if (!_player_content_directory) {
1035                         return;
1036                 }
1037                 _player_content_directory = boost::none;
1038                 changed (PLAYER_CONTENT_DIRECTORY);
1039         }
1040
1041         void set_player_playlist_directory (boost::filesystem::path p) {
1042                 maybe_set (_player_playlist_directory, p, PLAYER_PLAYLIST_DIRECTORY);
1043         }
1044
1045         void unset_player_playlist_directory () {
1046                 if (!_player_playlist_directory) {
1047                         return;
1048                 }
1049                 _player_playlist_directory = boost::none;
1050                 changed (PLAYER_PLAYLIST_DIRECTORY);
1051         }
1052
1053         void set_player_kdm_directory (boost::filesystem::path p) {
1054                 maybe_set (_player_kdm_directory, p);
1055         }
1056
1057         void unset_player_kdm_directory () {
1058                 if (!_player_kdm_directory) {
1059                         return;
1060                 }
1061                 _player_kdm_directory = boost::none;
1062                 changed ();
1063         }
1064
1065         void set_audio_mapping (AudioMapping m);
1066         void set_audio_mapping_to_default ();
1067
1068 #ifdef DCPOMATIC_VARIANT_SWAROOP
1069         void set_player_background_image (boost::filesystem::path p) {
1070                 maybe_set (_player_background_image, p, PLAYER_BACKGROUND_IMAGE);
1071         }
1072
1073         void unset_player_background_image () {
1074                 if (!_player_background_image) {
1075                         return;
1076                 }
1077                 _player_background_image = boost::none;
1078                 changed (PLAYER_BACKGROUND_IMAGE);
1079         }
1080
1081         void set_kdm_server_url (std::string s) {
1082                 maybe_set (_kdm_server_url, s);
1083         }
1084
1085         void set_player_watermark_theatre (std::string p) {
1086                 maybe_set (_player_watermark_theatre, p);
1087         }
1088
1089         void set_player_watermark_period (int minutes) {
1090                 maybe_set (_player_watermark_period, minutes);
1091         }
1092
1093         void set_player_watermark_duration (int milliseconds) {
1094                 maybe_set (_player_watermark_duration, milliseconds);
1095         }
1096
1097         void set_required_monitors (std::vector<Monitor> monitors) {
1098                 maybe_set (_required_monitors, monitors);
1099         }
1100
1101         void set_player_lock_file (boost::filesystem::path p) {
1102                 maybe_set (_player_lock_file, p);
1103         }
1104
1105         void unset_player_lock_file () {
1106                 if (!_player_lock_file) {
1107                         return;
1108                 }
1109                 _player_lock_file = boost::none;
1110                 changed ();
1111         }
1112 #endif
1113
1114         void changed (Property p = OTHER);
1115         boost::signals2::signal<void (Property)> Changed;
1116         /** Emitted if read() failed on an existing Config file.  There is nothing
1117             a listener can do about it: this is just for information.
1118         */
1119         static boost::signals2::signal<void ()> FailedToLoad;
1120         /** Emitted if read() issued a warning which the user might want to know about */
1121         static boost::signals2::signal<void (std::string)> Warning;
1122         /** Emitted if there is a something wrong the contents of our config.  Handler can call
1123          *  true to ask Config to solve the problem (by discarding and recreating the bad thing)
1124          */
1125         enum BadReason {
1126                 BAD_SIGNER_UTF8_STRINGS,     ///< signer chain contains UTF-8 strings (not PRINTABLESTRING)
1127                 BAD_SIGNER_INCONSISTENT,     ///< signer chain is somehow inconsistent
1128                 BAD_DECRYPTION_INCONSISTENT, ///< KDM decryption chain is somehow inconsistent
1129         };
1130
1131         static boost::signals2::signal<bool (BadReason)> Bad;
1132
1133         void write () const;
1134         void write_config () const;
1135         void write_cinemas () const;
1136         void write_dkdm_recipients () const;
1137         void link (boost::filesystem::path new_file) const;
1138         void copy_and_link (boost::filesystem::path new_file) const;
1139         bool have_write_permission () const;
1140
1141         void save_template (boost::shared_ptr<const Film> film, std::string name) const;
1142         bool existing_template (std::string name) const;
1143         std::list<std::string> templates () const;
1144         boost::filesystem::path template_path (std::string name) const;
1145         void rename_template (std::string old_name, std::string new_name) const;
1146         void delete_template (std::string name) const;
1147
1148         static Config* instance ();
1149         static void drop ();
1150         static void restore_defaults ();
1151         static bool have_existing (std::string);
1152         static boost::filesystem::path config_file ();
1153
1154 private:
1155         Config ();
1156         void read ();
1157         void set_defaults ();
1158         void set_kdm_email_to_default ();
1159         void set_notification_email_to_default ();
1160         void set_cover_sheet_to_default ();
1161         void read_cinemas (cxml::Document const & f);
1162         void read_dkdm_recipients (cxml::Document const & f);
1163         boost::shared_ptr<dcp::CertificateChain> create_certificate_chain ();
1164         boost::filesystem::path directory_or (boost::optional<boost::filesystem::path> dir, boost::filesystem::path a) const;
1165         void add_to_history_internal (std::vector<boost::filesystem::path>& h, boost::filesystem::path p);
1166         void clean_history_internal (std::vector<boost::filesystem::path>& h);
1167         void backup ();
1168
1169         template <class T>
1170         void maybe_set (T& member, T new_value, Property prop = OTHER) {
1171                 if (member == new_value) {
1172                         return;
1173                 }
1174                 member = new_value;
1175                 changed (prop);
1176         }
1177
1178         template <class T>
1179         void maybe_set (boost::optional<T>& member, T new_value, Property prop = OTHER) {
1180                 if (member && member.get() == new_value) {
1181                         return;
1182                 }
1183                 member = new_value;
1184                 changed (prop);
1185         }
1186
1187         /** number of threads which a master DoM should use for J2K encoding on the local machine */
1188         int _master_encoding_threads;
1189         /** number of threads which a server should use for J2K encoding on the local machine */
1190         int _server_encoding_threads;
1191         /** default directory to put new films in */
1192         boost::optional<boost::filesystem::path> _default_directory;
1193         /** base port number to use for J2K encoding servers;
1194          *  this port and the two above it will be used.
1195          */
1196         int _server_port_base;
1197         /** true to broadcast on the `any' address to look for servers */
1198         bool _use_any_servers;
1199         /** J2K encoding servers that should definitely be used */
1200         std::vector<std::string> _servers;
1201         bool _only_servers_encode;
1202         FileTransferProtocol _tms_protocol;
1203         /** The IP address of a TMS that we can copy DCPs to */
1204         std::string _tms_ip;
1205         /** The path on a TMS that we should write DCPs to */
1206         std::string _tms_path;
1207         /** User name to log into the TMS with */
1208         std::string _tms_user;
1209         /** Password to log into the TMS with */
1210         std::string _tms_password;
1211         /** The list of possible DCP frame rates that DCP-o-matic will use */
1212         std::list<int> _allowed_dcp_frame_rates;
1213         /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
1214         bool _allow_any_dcp_frame_rate;
1215         /** Allow any container ratio, not just the standard ones.  GDC SX-2001 will not play Flat
1216             DCPs at 25fps but will play 16:9, so this is very useful for some users.
1217             https://www.dcpomatic.com/forum/viewtopic.php?f=2&t=1119&p=4468
1218         */
1219         bool _allow_any_container;
1220         /** Offer the upmixers in the audio processor settings */
1221         bool _show_experimental_audio_processors;
1222         /** Default ISDCF metadata for newly-created Films */
1223         ISDCFMetadata _default_isdcf_metadata;
1224         boost::optional<std::string> _language;
1225         /** Default length of still image content (seconds) */
1226         int _default_still_length;
1227         Ratio const * _default_container;
1228         DCPContentType const * _default_dcp_content_type;
1229         int _default_dcp_audio_channels;
1230         std::string _dcp_issuer;
1231         std::string _dcp_creator;
1232         int _default_j2k_bandwidth;
1233         int _default_audio_delay;
1234         bool _default_interop;
1235         /** Default directory to offer to write KDMs to; if it's not set,
1236             the home directory will be offered.
1237         */
1238         boost::optional<boost::filesystem::path> _default_kdm_directory;
1239         bool _default_upload_after_make_dcp;
1240         std::list<boost::shared_ptr<Cinema> > _cinemas;
1241         std::list<boost::shared_ptr<DKDMRecipient> > _dkdm_recipients;
1242         std::string _mail_server;
1243         int _mail_port;
1244         EmailProtocol _mail_protocol;
1245         std::string _mail_user;
1246         std::string _mail_password;
1247         std::string _kdm_subject;
1248         std::string _kdm_from;
1249         std::vector<std::string> _kdm_cc;
1250         std::string _kdm_bcc;
1251         std::string _kdm_email;
1252         std::string _notification_subject;
1253         std::string _notification_from;
1254         std::string _notification_to;
1255         std::vector<std::string> _notification_cc;
1256         std::string _notification_bcc;
1257         std::string _notification_email;
1258         boost::shared_ptr<const dcp::CertificateChain> _signer_chain;
1259 #ifdef DCPOMATIC_VARIANT_SWAROOP
1260         boost::filesystem::path _signer_chain_path;
1261 #endif
1262         /** Chain used to decrypt KDMs; the leaf of this chain is the target
1263          *  certificate for making KDMs given to DCP-o-matic.
1264          */
1265         boost::shared_ptr<const dcp::CertificateChain> _decryption_chain;
1266 #ifdef DCPOMATIC_VARIANT_SWAROOP
1267         boost::filesystem::path _decryption_chain_path;
1268 #endif
1269         /** true to check for updates on startup */
1270         bool _check_for_updates;
1271         bool _check_for_test_updates;
1272         /** maximum allowed J2K bandwidth in bits per second */
1273         int _maximum_j2k_bandwidth;
1274         int _log_types;
1275         bool _analyse_ebur128;
1276         bool _automatic_audio_analysis;
1277 #ifdef DCPOMATIC_WINDOWS
1278         bool _win32_console;
1279 #endif
1280         std::vector<boost::filesystem::path> _history;
1281         std::vector<boost::filesystem::path> _player_history;
1282         boost::shared_ptr<DKDMGroup> _dkdms;
1283         boost::filesystem::path _cinemas_file;
1284         boost::filesystem::path _dkdm_recipients_file;
1285         bool _show_hints_before_make_dcp;
1286         bool _confirm_kdm_email;
1287         dcp::NameFormat _kdm_filename_format;
1288         dcp::NameFormat _dkdm_filename_format;
1289         dcp::NameFormat _kdm_container_name_format;
1290         dcp::NameFormat _dcp_metadata_filename_format;
1291         dcp::NameFormat _dcp_asset_filename_format;
1292         bool _jump_to_selected;
1293         bool _nagged[NAG_COUNT];
1294         bool _sound;
1295         /** name of a specific sound output stream to use, or empty to use the default */
1296         boost::optional<std::string> _sound_output;
1297         std::string _cover_sheet;
1298         boost::optional<boost::filesystem::path> _last_player_load_directory;
1299         boost::optional<KDMWriteType> _last_kdm_write_type;
1300         boost::optional<DKDMWriteType> _last_dkdm_write_type;
1301         int _frames_in_memory_multiplier;
1302         boost::optional<int> _decode_reduction;
1303         bool _default_notify;
1304         bool _notification[NOTIFICATION_COUNT];
1305         boost::optional<std::string> _barco_username;
1306         boost::optional<std::string> _barco_password;
1307         boost::optional<std::string> _christie_username;
1308         boost::optional<std::string> _christie_password;
1309         boost::optional<std::string> _gdc_username;
1310         boost::optional<std::string> _gdc_password;
1311         Interface _interface_complexity;
1312         PlayerMode _player_mode;
1313         int _image_display;
1314         VideoViewType _video_view_type;
1315         bool _respect_kdm_validity_periods;
1316         /** Log file containing things the player does (e.g. started, stopped, loaded
1317             playlist etc.)  Does not contain debugging information.
1318         */
1319         boost::optional<boost::filesystem::path> _player_activity_log_file;
1320         /** Log file containing debug information for the player */
1321         boost::optional<boost::filesystem::path> _player_debug_log_file;
1322         /** A directory containing DCPs whose contents are presented to the user
1323             in the dual-screen player mode.  DCPs on the list can be loaded
1324             for playback.
1325         */
1326         boost::optional<boost::filesystem::path> _player_content_directory;
1327         boost::optional<boost::filesystem::path> _player_playlist_directory;
1328         boost::optional<boost::filesystem::path> _player_kdm_directory;
1329         boost::optional<AudioMapping> _audio_mapping;
1330 #ifdef DCPOMATIC_VARIANT_SWAROOP
1331         boost::optional<boost::filesystem::path> _player_background_image;
1332         std::string _kdm_server_url;
1333         std::string _player_watermark_theatre;
1334         /** watermark period in minutes */
1335         int _player_watermark_period;
1336         /** watermark duration in milliseconds */
1337         int _player_watermark_duration;
1338         std::vector<Monitor> _required_monitors;
1339         /** a file which, if specified, must be present for the player to work */
1340         boost::optional<boost::filesystem::path> _player_lock_file;
1341 #endif
1342
1343         static int const _current_version;
1344
1345         /** Singleton instance, or 0 */
1346         static Config* _instance;
1347 };
1348
1349 #endif