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