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