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