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