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