swaroop: restart playback after player crash.
[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         /* SET (mostly) */
525
526         void set_master_encoding_threads (int n) {
527                 maybe_set (_master_encoding_threads, n);
528         }
529
530         void set_server_encoding_threads (int n) {
531                 maybe_set (_server_encoding_threads, n);
532         }
533
534         void set_default_directory (boost::filesystem::path d) {
535                 if (_default_directory && *_default_directory == d) {
536                         return;
537                 }
538                 _default_directory = d;
539                 changed ();
540         }
541
542         /** @param p New server port */
543         void set_server_port_base (int p) {
544                 maybe_set (_server_port_base, p);
545         }
546
547         void set_only_servers_encode (bool o) {
548                 maybe_set (_only_servers_encode, o);
549         }
550
551         void set_tms_protocol (Protocol p) {
552                 maybe_set (_tms_protocol, p);
553         }
554
555         /** @param i IP address of a TMS that we can copy DCPs to */
556         void set_tms_ip (std::string i) {
557                 maybe_set (_tms_ip, i);
558         }
559
560         /** @param p Path on a TMS that we should changed DCPs to */
561         void set_tms_path (std::string p) {
562                 maybe_set (_tms_path, p);
563         }
564
565         /** @param u User name to log into the TMS with */
566         void set_tms_user (std::string u) {
567                 maybe_set (_tms_user, u);
568         }
569
570         /** @param p Password to log into the TMS with */
571         void set_tms_password (std::string p) {
572                 maybe_set (_tms_password, p);
573         }
574
575         void add_cinema (boost::shared_ptr<Cinema> c) {
576                 _cinemas.push_back (c);
577                 changed (CINEMAS);
578         }
579
580         void remove_cinema (boost::shared_ptr<Cinema> c) {
581                 _cinemas.remove (c);
582                 changed (CINEMAS);
583         }
584
585         void set_allowed_dcp_frame_rates (std::list<int> const & r) {
586                 maybe_set (_allowed_dcp_frame_rates, r);
587         }
588
589         void set_allow_any_dcp_frame_rate (bool a) {
590                 maybe_set (_allow_any_dcp_frame_rate, a);
591         }
592
593         void set_allow_any_container (bool a) {
594                 maybe_set (_allow_any_container, a);
595         }
596
597         void set_default_isdcf_metadata (ISDCFMetadata d) {
598                 maybe_set (_default_isdcf_metadata, d);
599         }
600
601         void set_language (std::string l) {
602                 if (_language && _language.get() == l) {
603                         return;
604                 }
605                 _language = l;
606                 changed ();
607         }
608
609         void unset_language () {
610                 if (!_language) {
611                         return;
612                 }
613
614                 _language = boost::none;
615                 changed ();
616         }
617
618         void set_default_still_length (int s) {
619                 maybe_set (_default_still_length, s);
620         }
621
622         void set_default_container (Ratio const * c) {
623                 maybe_set (_default_container, c);
624         }
625
626         void set_default_scale_to (Ratio const * c) {
627                 maybe_set (_default_scale_to, c);
628         }
629
630         void set_default_dcp_content_type (DCPContentType const * t) {
631                 maybe_set (_default_dcp_content_type, t);
632         }
633
634         void set_default_dcp_audio_channels (int c) {
635                 maybe_set (_default_dcp_audio_channels, c);
636         }
637
638         void set_dcp_issuer (std::string i) {
639                 maybe_set (_dcp_issuer, i);
640         }
641
642         void set_dcp_creator (std::string c) {
643                 maybe_set (_dcp_creator, c);
644         }
645
646         void set_default_j2k_bandwidth (int b) {
647                 maybe_set (_default_j2k_bandwidth, b);
648         }
649
650         void set_default_audio_delay (int d) {
651                 maybe_set (_default_audio_delay, d);
652         }
653
654         void set_default_interop (bool i) {
655                 maybe_set (_default_interop, i);
656         }
657
658         void set_default_upload_after_make_dcp (bool u) {
659                 maybe_set (_default_upload_after_make_dcp, u);
660         }
661
662         void set_mail_server (std::string s) {
663                 maybe_set (_mail_server, s);
664         }
665
666         void set_mail_port (int p) {
667                 maybe_set (_mail_port, p);
668         }
669
670         void set_mail_user (std::string u) {
671                 maybe_set (_mail_user, u);
672         }
673
674         void set_mail_password (std::string p) {
675                 maybe_set (_mail_password, p);
676         }
677
678         void set_kdm_subject (std::string s) {
679                 maybe_set (_kdm_subject, s);
680         }
681
682         void set_kdm_from (std::string f) {
683                 maybe_set (_kdm_from, f);
684         }
685
686         void set_kdm_cc (std::vector<std::string> f) {
687                 maybe_set (_kdm_cc, f);
688         }
689
690         void set_kdm_bcc (std::string f) {
691                 maybe_set (_kdm_bcc, f);
692         }
693
694         void set_kdm_email (std::string e) {
695                 maybe_set (_kdm_email, e);
696         }
697
698         void reset_kdm_email ();
699
700         void set_notification_subject (std::string s) {
701                 maybe_set (_notification_subject, s);
702         }
703
704         void set_notification_from (std::string f) {
705                 maybe_set (_notification_from, f);
706         }
707
708         void set_notification_to (std::string t) {
709                 maybe_set (_notification_to, t);
710         }
711
712         void set_notification_cc (std::vector<std::string> f) {
713                 maybe_set (_notification_cc, f);
714         }
715
716         void set_notification_bcc (std::string f) {
717                 maybe_set (_notification_bcc, f);
718         }
719
720         void set_notification_email (std::string e) {
721                 maybe_set (_notification_email, e);
722         }
723
724         void reset_notification_email ();
725
726         void set_signer_chain (boost::shared_ptr<const dcp::CertificateChain> s) {
727                 maybe_set (_signer_chain, s);
728         }
729
730         void set_decryption_chain (boost::shared_ptr<const dcp::CertificateChain> c) {
731                 maybe_set (_decryption_chain, c);
732         }
733
734         void set_check_for_updates (bool c) {
735                 maybe_set (_check_for_updates, c);
736                 if (!c) {
737                         set_check_for_test_updates (false);
738                 }
739         }
740
741         void set_check_for_test_updates (bool c) {
742                 maybe_set (_check_for_test_updates, c);
743         }
744
745         void set_maximum_j2k_bandwidth (int b) {
746                 maybe_set (_maximum_j2k_bandwidth, b);
747         }
748
749         void set_log_types (int t) {
750                 maybe_set (_log_types, t);
751         }
752
753         void set_analyse_ebur128 (bool a) {
754                 maybe_set (_analyse_ebur128, a);
755         }
756
757         void set_automatic_audio_analysis (bool a) {
758                 maybe_set (_automatic_audio_analysis, a);
759         }
760
761 #ifdef DCPOMATIC_WINDOWS
762         void set_win32_console (bool c) {
763                 maybe_set (_win32_console, c);
764         }
765 #endif
766
767         void set_dkdms (boost::shared_ptr<DKDMGroup> dkdms) {
768                 _dkdms = dkdms;
769                 changed ();
770         }
771
772         void set_cinemas_file (boost::filesystem::path file);
773
774         void set_show_hints_before_make_dcp (bool s) {
775                 maybe_set (_show_hints_before_make_dcp, s);
776         }
777
778         void set_confirm_kdm_email (bool s) {
779                 maybe_set (_confirm_kdm_email, s);
780         }
781
782         void set_sound (bool s) {
783                 maybe_set (_sound, s, SOUND);
784         }
785
786         void set_sound_output (std::string o) {
787                 maybe_set (_sound_output, o, SOUND_OUTPUT);
788         }
789
790         void set_last_player_load_directory (boost::filesystem::path d) {
791                 maybe_set (_last_player_load_directory, d);
792         }
793
794         void set_last_kdm_write_type (KDMWriteType t) {
795                 maybe_set (_last_kdm_write_type, t);
796         }
797
798         void set_last_dkdm_write_type (DKDMWriteType t) {
799                 maybe_set (_last_dkdm_write_type, t);
800         }
801
802         void unset_sound_output () {
803                 if (!_sound_output) {
804                         return;
805                 }
806
807                 _sound_output = boost::none;
808                 changed ();
809         }
810
811         void set_kdm_container_name_format (dcp::NameFormat n) {
812                 maybe_set (_kdm_container_name_format, n);
813         }
814
815         void set_kdm_filename_format (dcp::NameFormat n) {
816                 maybe_set (_kdm_filename_format, n);
817         }
818
819         void set_dcp_metadata_filename_format (dcp::NameFormat n) {
820                 maybe_set (_dcp_metadata_filename_format, n);
821         }
822
823         void set_dcp_asset_filename_format (dcp::NameFormat n) {
824                 maybe_set (_dcp_asset_filename_format, n);
825         }
826
827         void set_frames_in_memory_multiplier (int m) {
828                 maybe_set (_frames_in_memory_multiplier, m);
829         }
830
831         void set_decode_reduction (boost::optional<int> r) {
832                 maybe_set (_decode_reduction, r);
833         }
834
835         void set_default_notify (bool n) {
836                 maybe_set (_default_notify, n);
837         }
838
839         void clear_history () {
840                 _history.clear ();
841                 changed ();
842         }
843
844         void clear_player_history () {
845                 _player_history.clear ();
846                 changed ();
847         }
848
849         void add_to_history (boost::filesystem::path p);
850         void add_to_player_history (boost::filesystem::path p);
851
852         void set_jump_to_selected (bool j) {
853                 maybe_set (_jump_to_selected, j);
854         }
855
856         void set_nagged (Nag nag, bool nagged) {
857                 maybe_set (_nagged[nag], nagged);
858         }
859
860         void set_cover_sheet (std::string s) {
861                 maybe_set (_cover_sheet, s);
862         }
863
864         void reset_cover_sheet ();
865
866         void set_notification (Notification n, bool v) {
867                 maybe_set (_notification[n], v);
868         }
869
870         void set_barco_username (std::string u) {
871                 maybe_set (_barco_username, u);
872         }
873
874         void unset_barco_username () {
875                 maybe_set (_barco_username, boost::optional<std::string>());
876         }
877
878         void set_barco_password (std::string p) {
879                 maybe_set (_barco_password, p);
880         }
881
882         void unset_barco_password () {
883                 maybe_set (_barco_password, boost::optional<std::string>());
884         }
885
886         void set_christie_username (std::string u) {
887                 maybe_set (_christie_username, u);
888         }
889
890         void unset_christie_username () {
891                 maybe_set (_christie_username, boost::optional<std::string>());
892         }
893
894         void set_christie_password (std::string p) {
895                 maybe_set (_christie_password, p);
896         }
897
898         void unset_christie_password () {
899                 maybe_set (_christie_password, boost::optional<std::string>());
900         }
901
902         void set_gdc_username (std::string u) {
903                 maybe_set (_gdc_username, u);
904         }
905
906         void unset_gdc_username () {
907                 maybe_set (_gdc_username, boost::optional<std::string>());
908         }
909
910         void set_gdc_password (std::string p) {
911                 maybe_set (_gdc_password, p);
912         }
913
914         void unset_gdc_password () {
915                 maybe_set (_gdc_password, boost::optional<std::string>());
916         }
917
918         void set_interface_complexity (Interface i) {
919                 maybe_set (_interface_complexity, i, INTERFACE_COMPLEXITY);
920         }
921
922         void set_player_mode (PlayerMode m) {
923                 maybe_set (_player_mode, m);
924         }
925
926         void set_image_display (int n) {
927                 maybe_set (_image_display, n);
928         }
929
930         void set_respect_kdm_validity_periods (bool r) {
931                 maybe_set (_respect_kdm_validity_periods, r);
932         }
933
934         void set_player_log_file (boost::filesystem::path p) {
935                 maybe_set (_player_log_file, p);
936         }
937
938         void unset_player_log_file () {
939                 if (!_player_log_file) {
940                         return;
941                 }
942                 _player_log_file = boost::none;
943                 changed ();
944         }
945
946         void set_player_dcp_directory (boost::filesystem::path p) {
947                 maybe_set (_player_dcp_directory, p, PLAYER_DCP_DIRECTORY);
948         }
949
950         void unset_player_dcp_directory () {
951                 if (!_player_dcp_directory) {
952                         return;
953                 }
954                 _player_dcp_directory = boost::none;
955                 changed (PLAYER_DCP_DIRECTORY);
956         }
957
958         void set_player_kdm_directory (boost::filesystem::path p) {
959                 maybe_set (_player_kdm_directory, p);
960         }
961
962         void unset_player_kdm_directory () {
963                 if (!_player_kdm_directory) {
964                         return;
965                 }
966                 _player_kdm_directory = boost::none;
967                 changed ();
968         }
969
970 #ifdef DCPOMATIC_VARIANT_SWAROOP
971         void set_player_background_image (boost::filesystem::path p) {
972                 maybe_set (_player_background_image, p, PLAYER_BACKGROUND_IMAGE);
973         }
974
975         void unset_player_background_image () {
976                 if (!_player_background_image) {
977                         return;
978                 }
979                 _player_background_image = boost::none;
980                 changed (PLAYER_BACKGROUND_IMAGE);
981         }
982
983         void set_kdm_server_url (std::string s) {
984                 maybe_set (_kdm_server_url, s);
985         }
986
987         void set_player_watermark_theatre (std::string p) {
988                 maybe_set (_player_watermark_theatre, p);
989         }
990
991         void set_player_watermark_period (int minutes) {
992                 maybe_set (_player_watermark_period, minutes);
993         }
994
995         void set_player_watermark_duration (int milliseconds) {
996                 maybe_set (_player_watermark_duration, milliseconds);
997         }
998
999         void set_required_monitors (std::vector<Monitor> monitors) {
1000                 maybe_set (_required_monitors, monitors);
1001         }
1002 #endif
1003
1004         void changed (Property p = OTHER);
1005         boost::signals2::signal<void (Property)> Changed;
1006         /** Emitted if read() failed on an existing Config file.  There is nothing
1007             a listener can do about it: this is just for information.
1008         */
1009         static boost::signals2::signal<void ()> FailedToLoad;
1010         /** Emitted if read() issued a warning which the user might want to know about */
1011         static boost::signals2::signal<void (std::string)> Warning;
1012         /** Emitted if there is a bad certificate in the signer chain.  Handler can call
1013          *  true to ask Config to re-create the chain.
1014          */
1015         static boost::signals2::signal<bool (void)> BadSignerChain;
1016
1017         void write () const;
1018         void write_config () const;
1019         void write_cinemas () const;
1020         void link (boost::filesystem::path new_file) const;
1021         void copy_and_link (boost::filesystem::path new_file) const;
1022         bool have_write_permission () const;
1023
1024         void save_template (boost::shared_ptr<const Film> film, std::string name) const;
1025         bool existing_template (std::string name) const;
1026         std::list<std::string> templates () const;
1027         boost::filesystem::path template_path (std::string name) const;
1028         void rename_template (std::string old_name, std::string new_name) const;
1029         void delete_template (std::string name) const;
1030
1031         static Config* instance ();
1032         static void drop ();
1033         static void restore_defaults ();
1034         static bool have_existing (std::string);
1035         static boost::filesystem::path config_file ();
1036         static boost::filesystem::path path (std::string file, bool create_directories = true);
1037
1038         /** If set, this overrides the standard path (in home, Library, AppData or wherever) for config.xml and cinemas.xml */
1039         static boost::optional<boost::filesystem::path> override_path;
1040
1041 private:
1042         Config ();
1043         void read ();
1044         void set_defaults ();
1045         void set_kdm_email_to_default ();
1046         void set_notification_email_to_default ();
1047         void set_cover_sheet_to_default ();
1048         void read_cinemas (cxml::Document const & f);
1049         boost::shared_ptr<dcp::CertificateChain> create_certificate_chain ();
1050         boost::filesystem::path directory_or (boost::optional<boost::filesystem::path> dir, boost::filesystem::path a) const;
1051         void add_to_history_internal (std::vector<boost::filesystem::path>& h, boost::filesystem::path p);
1052         void backup ();
1053
1054         template <class T>
1055         void maybe_set (T& member, T new_value, Property prop = OTHER) {
1056                 if (member == new_value) {
1057                         return;
1058                 }
1059                 member = new_value;
1060                 changed (prop);
1061         }
1062
1063         template <class T>
1064         void maybe_set (boost::optional<T>& member, T new_value, Property prop = OTHER) {
1065                 if (member && member.get() == new_value) {
1066                         return;
1067                 }
1068                 member = new_value;
1069                 changed (prop);
1070         }
1071
1072         /** number of threads which a master DoM should use for J2K encoding on the local machine */
1073         int _master_encoding_threads;
1074         /** number of threads which a server should use for J2K encoding on the local machine */
1075         int _server_encoding_threads;
1076         /** default directory to put new films in */
1077         boost::optional<boost::filesystem::path> _default_directory;
1078         /** base port number to use for J2K encoding servers;
1079          *  this port and the two above it will be used.
1080          */
1081         int _server_port_base;
1082         /** true to broadcast on the `any' address to look for servers */
1083         bool _use_any_servers;
1084         /** J2K encoding servers that should definitely be used */
1085         std::vector<std::string> _servers;
1086         bool _only_servers_encode;
1087         Protocol _tms_protocol;
1088         /** The IP address of a TMS that we can copy DCPs to */
1089         std::string _tms_ip;
1090         /** The path on a TMS that we should write DCPs to */
1091         std::string _tms_path;
1092         /** User name to log into the TMS with */
1093         std::string _tms_user;
1094         /** Password to log into the TMS with */
1095         std::string _tms_password;
1096         /** Our cinema sound processor */
1097         CinemaSoundProcessor const * _cinema_sound_processor;
1098         std::list<int> _allowed_dcp_frame_rates;
1099         /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
1100         bool _allow_any_dcp_frame_rate;
1101         /** Allow any container ratio, not just the standard ones.  GDC SX-2001 will not play Flat
1102             DCPs at 25fps but will play 16:9, so this is very useful for some users.
1103             https://www.dcpomatic.com/forum/viewtopic.php?f=2&t=1119&p=4468
1104         */
1105         bool _allow_any_container;
1106         /** Default ISDCF metadata for newly-created Films */
1107         ISDCFMetadata _default_isdcf_metadata;
1108         boost::optional<std::string> _language;
1109         /** Default length of still image content (seconds) */
1110         int _default_still_length;
1111         Ratio const * _default_container;
1112         Ratio const * _default_scale_to;
1113         DCPContentType const * _default_dcp_content_type;
1114         int _default_dcp_audio_channels;
1115         std::string _dcp_issuer;
1116         std::string _dcp_creator;
1117         int _default_j2k_bandwidth;
1118         int _default_audio_delay;
1119         bool _default_interop;
1120         /** Default directory to offer to write KDMs to; if it's not set,
1121             the home directory will be offered.
1122         */
1123         boost::optional<boost::filesystem::path> _default_kdm_directory;
1124         bool _default_upload_after_make_dcp;
1125         std::list<boost::shared_ptr<Cinema> > _cinemas;
1126         std::string _mail_server;
1127         int _mail_port;
1128         std::string _mail_user;
1129         std::string _mail_password;
1130         std::string _kdm_subject;
1131         std::string _kdm_from;
1132         std::vector<std::string> _kdm_cc;
1133         std::string _kdm_bcc;
1134         std::string _kdm_email;
1135         std::string _notification_subject;
1136         std::string _notification_from;
1137         std::string _notification_to;
1138         std::vector<std::string> _notification_cc;
1139         std::string _notification_bcc;
1140         std::string _notification_email;
1141         boost::shared_ptr<const dcp::CertificateChain> _signer_chain;
1142         /** Chain used to decrypt KDMs; the leaf of this chain is the target
1143          *  certificate for making KDMs given to DCP-o-matic.
1144          */
1145         boost::shared_ptr<const dcp::CertificateChain> _decryption_chain;
1146         /** true to check for updates on startup */
1147         bool _check_for_updates;
1148         bool _check_for_test_updates;
1149         /** maximum allowed J2K bandwidth in bits per second */
1150         int _maximum_j2k_bandwidth;
1151         int _log_types;
1152         bool _analyse_ebur128;
1153         bool _automatic_audio_analysis;
1154 #ifdef DCPOMATIC_WINDOWS
1155         bool _win32_console;
1156 #endif
1157         std::vector<boost::filesystem::path> _history;
1158         std::vector<boost::filesystem::path> _player_history;
1159         boost::shared_ptr<DKDMGroup> _dkdms;
1160         boost::filesystem::path _cinemas_file;
1161         bool _show_hints_before_make_dcp;
1162         bool _confirm_kdm_email;
1163         dcp::NameFormat _kdm_filename_format;
1164         dcp::NameFormat _kdm_container_name_format;
1165         dcp::NameFormat _dcp_metadata_filename_format;
1166         dcp::NameFormat _dcp_asset_filename_format;
1167         bool _jump_to_selected;
1168         bool _nagged[NAG_COUNT];
1169         bool _sound;
1170         /** name of a specific sound output stream to use, or empty to use the default */
1171         boost::optional<std::string> _sound_output;
1172         std::string _cover_sheet;
1173         boost::optional<boost::filesystem::path> _last_player_load_directory;
1174         boost::optional<KDMWriteType> _last_kdm_write_type;
1175         boost::optional<DKDMWriteType> _last_dkdm_write_type;
1176         int _frames_in_memory_multiplier;
1177         boost::optional<int> _decode_reduction;
1178         bool _default_notify;
1179         bool _notification[NOTIFICATION_COUNT];
1180         boost::optional<std::string> _barco_username;
1181         boost::optional<std::string> _barco_password;
1182         boost::optional<std::string> _christie_username;
1183         boost::optional<std::string> _christie_password;
1184         boost::optional<std::string> _gdc_username;
1185         boost::optional<std::string> _gdc_password;
1186         Interface _interface_complexity;
1187         PlayerMode _player_mode;
1188         int _image_display;
1189         bool _respect_kdm_validity_periods;
1190         boost::optional<boost::filesystem::path> _player_log_file;
1191         /** A directory containing DCPs whose contents are presented to the user
1192             in the dual-screen player mode.  DCPs on the list can be loaded
1193             for playback.
1194         */
1195         boost::optional<boost::filesystem::path> _player_dcp_directory;
1196         boost::optional<boost::filesystem::path> _player_kdm_directory;
1197 #ifdef DCPOMATIC_VARIANT_SWAROOP
1198         boost::optional<boost::filesystem::path> _player_background_image;
1199         std::string _kdm_server_url;
1200         std::string _player_watermark_theatre;
1201         /** watermark period in minutes */
1202         int _player_watermark_period;
1203         /** watermark duration in milliseconds */
1204         int _player_watermark_duration;
1205         std::vector<Monitor> _required_monitors;
1206 #endif
1207
1208         static int const _current_version;
1209
1210         /** Singleton instance, or 0 */
1211         static Config* _instance;
1212 };
1213
1214 #endif