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