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