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