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