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