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