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