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