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