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