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