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