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