05421c20a7688ddf6b3fc8c4ea7667d16b151931
[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         int64_t default_video_bit_rate() const {
236                 return _default_video_bit_rate;
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         int64_t maximum_video_bit_rate() const {
352                 return _maximum_video_bit_rate;
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         bool player_restricted_menus() const {
538                 return _player_restricted_menus;
539         }
540
541         bool playlist_editor_restricted_menus() const {
542                 return _playlist_editor_restricted_menus;
543         }
544
545         int image_display () const {
546                 return _image_display;
547         }
548
549         enum VideoViewType {
550                 VIDEO_VIEW_SIMPLE,
551                 VIDEO_VIEW_OPENGL
552         };
553
554         VideoViewType video_view_type () const {
555                 return _video_view_type;
556         }
557
558         bool respect_kdm_validity_periods () const {
559                 return _respect_kdm_validity_periods;
560         }
561
562         boost::optional<boost::filesystem::path> player_debug_log_file () const {
563                 return _player_debug_log_file;
564         }
565
566         boost::optional<boost::filesystem::path> player_content_directory () const {
567                 return _player_content_directory;
568         }
569
570         boost::optional<boost::filesystem::path> player_playlist_directory () const {
571                 return _player_playlist_directory;
572         }
573
574         boost::optional<boost::filesystem::path> player_kdm_directory () const {
575                 return _player_kdm_directory;
576         }
577
578         AudioMapping audio_mapping (int output_channels);
579
580         std::vector<dcp::LanguageTag> custom_languages () const {
581                 return _custom_languages;
582         }
583
584         boost::optional<boost::filesystem::path> initial_path(std::string id) const;
585
586         bool use_isdcf_name_by_default () const {
587                 return _use_isdcf_name_by_default;
588         }
589
590         bool write_kdms_to_disk () const {
591                 return _write_kdms_to_disk;
592         }
593
594         bool email_kdms () const {
595                 return _email_kdms;
596         }
597
598         dcp::Formulation default_kdm_type () const {
599                 return _default_kdm_type;
600         }
601
602         RoughDuration default_kdm_duration () const {
603                 return _default_kdm_duration;
604         }
605
606         double auto_crop_threshold () const {
607                 return _auto_crop_threshold;
608         }
609
610         boost::optional<std::string> last_release_notes_version () const {
611                 return _last_release_notes_version;
612         }
613
614         boost::optional<int> main_divider_sash_position() const {
615                 return _main_divider_sash_position;
616         }
617
618         boost::optional<int> main_content_divider_sash_position() const {
619                 return _main_content_divider_sash_position;
620         }
621
622         enum class DefaultAddFileLocation {
623                 SAME_AS_LAST_TIME,
624                 SAME_AS_PROJECT
625         };
626
627         DefaultAddFileLocation default_add_file_location() const {
628                 return _default_add_file_location;
629         }
630
631         bool allow_smpte_bv20() const {
632                 return _allow_smpte_bv20;
633         }
634
635 #ifdef DCPOMATIC_GROK
636         class Grok
637         {
638         public:
639                 Grok() = default;
640                 Grok(cxml::ConstNodePtr node);
641
642                 void as_xml(xmlpp::Element* node) const;
643
644                 bool enable = false;
645                 boost::filesystem::path binary_location;
646                 int selected = 0;
647                 std::string licence_server;
648                 int licence_port = 5000;
649                 std::string licence;
650         };
651
652         boost::optional<Grok> grok() const {
653                 return _grok;
654         }
655 #endif
656
657         int isdcf_name_part_length() const {
658                 return _isdcf_name_part_length;
659         }
660
661         /* SET (mostly) */
662
663         void set_master_encoding_threads (int n) {
664                 maybe_set (_master_encoding_threads, n);
665         }
666
667         void set_server_encoding_threads (int n) {
668                 maybe_set (_server_encoding_threads, n);
669         }
670
671         void set_default_directory (boost::filesystem::path d) {
672                 if (_default_directory && *_default_directory == d) {
673                         return;
674                 }
675                 _default_directory = d;
676                 changed ();
677         }
678
679         /** @param p New server port */
680         void set_server_port_base (int p) {
681                 maybe_set (_server_port_base, p);
682         }
683
684         void set_only_servers_encode (bool o) {
685                 maybe_set (_only_servers_encode, o);
686         }
687
688         void set_tms_protocol (FileTransferProtocol p) {
689                 maybe_set (_tms_protocol, p);
690         }
691
692         void set_tms_passive(bool passive) {
693                 maybe_set(_tms_passive, passive);
694         }
695
696         /** @param i IP address of a TMS that we can copy DCPs to */
697         void set_tms_ip (std::string i) {
698                 maybe_set (_tms_ip, i);
699         }
700
701         /** @param p Path on a TMS that we should changed DCPs to */
702         void set_tms_path (std::string p) {
703                 maybe_set (_tms_path, p);
704         }
705
706         /** @param u User name to log into the TMS with */
707         void set_tms_user (std::string u) {
708                 maybe_set (_tms_user, u);
709         }
710
711         /** @param p Password to log into the TMS with */
712         void set_tms_password (std::string p) {
713                 maybe_set (_tms_password, p);
714         }
715
716         void add_cinema (std::shared_ptr<Cinema> c) {
717                 _cinemas.push_back (c);
718                 changed (CINEMAS);
719         }
720
721         void remove_cinema (std::shared_ptr<Cinema> c) {
722                 _cinemas.remove (c);
723                 changed (CINEMAS);
724         }
725
726         void add_dkdm_recipient (std::shared_ptr<DKDMRecipient> c) {
727                 _dkdm_recipients.push_back (c);
728                 changed (DKDM_RECIPIENTS);
729         }
730
731         void remove_dkdm_recipient (std::shared_ptr<DKDMRecipient> c) {
732                 _dkdm_recipients.remove (c);
733                 changed (DKDM_RECIPIENTS);
734         }
735
736         void set_allowed_dcp_frame_rates (std::list<int> const & r) {
737                 maybe_set (_allowed_dcp_frame_rates, r);
738         }
739
740         void set_allow_any_dcp_frame_rate (bool a) {
741                 maybe_set (_allow_any_dcp_frame_rate, a);
742         }
743
744         void set_allow_any_container (bool a) {
745                 maybe_set (_allow_any_container, a);
746         }
747
748         void set_allow_96hhz_audio (bool a) {
749                 maybe_set (_allow_96khz_audio, a);
750         }
751
752         void set_use_all_audio_channels (bool a) {
753                 maybe_set (_use_all_audio_channels, a);
754         }
755
756         void set_show_experimental_audio_processors (bool e) {
757                 maybe_set (_show_experimental_audio_processors, e, SHOW_EXPERIMENTAL_AUDIO_PROCESSORS);
758         }
759
760         void set_language (std::string l) {
761                 if (_language && _language.get() == l) {
762                         return;
763                 }
764                 _language = l;
765                 changed ();
766         }
767
768         void unset_language () {
769                 if (!_language) {
770                         return;
771                 }
772
773                 _language = boost::none;
774                 changed ();
775         }
776
777         void set_default_still_length (int s) {
778                 maybe_set (_default_still_length, s);
779         }
780
781         void set_default_dcp_content_type (DCPContentType const * t) {
782                 maybe_set (_default_dcp_content_type, t);
783         }
784
785         void set_default_dcp_audio_channels (int c) {
786                 maybe_set (_default_dcp_audio_channels, c);
787         }
788
789         void set_dcp_issuer (std::string i) {
790                 maybe_set (_dcp_issuer, i);
791         }
792
793         void set_dcp_creator (std::string c) {
794                 maybe_set (_dcp_creator, c);
795         }
796
797         void set_dcp_company_name (std::string c) {
798                 maybe_set (_dcp_company_name, c);
799         }
800
801         void set_dcp_product_name (std::string c) {
802                 maybe_set (_dcp_product_name, c);
803         }
804
805         void set_dcp_product_version (std::string c) {
806                 maybe_set (_dcp_product_version, c);
807         }
808
809         void set_dcp_j2k_comment (std::string c) {
810                 maybe_set (_dcp_j2k_comment, c);
811         }
812
813         void set_default_video_bit_rate(int64_t b) {
814                 maybe_set(_default_video_bit_rate, b);
815         }
816
817         void set_default_audio_delay (int d) {
818                 maybe_set (_default_audio_delay, d);
819         }
820
821         void set_default_interop (bool i) {
822                 maybe_set (_default_interop, i);
823         }
824
825         void set_default_audio_language(dcp::LanguageTag tag) {
826                 maybe_set(_default_audio_language, tag);
827         }
828
829         void unset_default_audio_language() {
830                 maybe_set(_default_audio_language, boost::optional<dcp::LanguageTag>());
831         }
832
833         void set_default_territory(dcp::LanguageTag::RegionSubtag tag) {
834                 maybe_set(_default_territory, tag);
835         }
836
837         void unset_default_territory() {
838                 maybe_set(_default_territory, boost::optional<dcp::LanguageTag::RegionSubtag>());
839         }
840
841         void set_default_metadata (std::map<std::string, std::string> const& metadata) {
842                 maybe_set (_default_metadata, metadata);
843         }
844
845         void set_upload_after_make_dcp (bool u) {
846                 maybe_set (_upload_after_make_dcp, u);
847         }
848
849         void set_mail_server (std::string s) {
850                 maybe_set (_mail_server, s);
851         }
852
853         void set_mail_port (int p) {
854                 maybe_set (_mail_port, p);
855         }
856
857         void set_mail_protocol (EmailProtocol p) {
858                 maybe_set (_mail_protocol, p);
859         }
860
861         void set_mail_user (std::string u) {
862                 maybe_set (_mail_user, u);
863         }
864
865         void set_mail_password (std::string p) {
866                 maybe_set (_mail_password, p);
867         }
868
869         void set_kdm_subject (std::string s) {
870                 maybe_set (_kdm_subject, s);
871         }
872
873         void set_kdm_from (std::string f) {
874                 maybe_set (_kdm_from, f);
875         }
876
877         void set_kdm_cc (std::vector<std::string> f) {
878                 maybe_set (_kdm_cc, f);
879         }
880
881         void set_kdm_bcc (std::string f) {
882                 maybe_set (_kdm_bcc, f);
883         }
884
885         void set_kdm_email (std::string e) {
886                 maybe_set (_kdm_email, e);
887         }
888
889         void reset_kdm_email ();
890
891         void set_notification_subject (std::string s) {
892                 maybe_set (_notification_subject, s);
893         }
894
895         void set_notification_from (std::string f) {
896                 maybe_set (_notification_from, f);
897         }
898
899         void set_notification_to (std::string t) {
900                 maybe_set (_notification_to, t);
901         }
902
903         void set_notification_cc (std::vector<std::string> f) {
904                 maybe_set (_notification_cc, f);
905         }
906
907         void set_notification_bcc (std::string f) {
908                 maybe_set (_notification_bcc, f);
909         }
910
911         void set_notification_email (std::string e) {
912                 maybe_set (_notification_email, e);
913         }
914
915         void reset_notification_email ();
916
917         void set_signer_chain (std::shared_ptr<const dcp::CertificateChain> s) {
918                 maybe_set (_signer_chain, s);
919         }
920
921         void set_decryption_chain (std::shared_ptr<const dcp::CertificateChain> c) {
922                 maybe_set (_decryption_chain, c);
923         }
924
925         void set_check_for_updates (bool c) {
926                 maybe_set (_check_for_updates, c);
927                 if (!c) {
928                         set_check_for_test_updates (false);
929                 }
930         }
931
932         void set_check_for_test_updates (bool c) {
933                 maybe_set (_check_for_test_updates, c);
934         }
935
936         void set_maximum_video_bit_rate(int64_t b) {
937                 maybe_set(_maximum_video_bit_rate, b);
938         }
939
940         void set_log_types (int t) {
941                 maybe_set (_log_types, t);
942         }
943
944         void set_analyse_ebur128 (bool a) {
945                 maybe_set (_analyse_ebur128, a);
946         }
947
948         void set_automatic_audio_analysis (bool a) {
949                 maybe_set (_automatic_audio_analysis, a);
950         }
951
952 #ifdef DCPOMATIC_WINDOWS
953         void set_win32_console (bool c) {
954                 maybe_set (_win32_console, c);
955         }
956 #endif
957
958         void set_dkdms (std::shared_ptr<DKDMGroup> dkdms) {
959                 _dkdms = dkdms;
960                 changed ();
961         }
962
963         void set_cinemas_file (boost::filesystem::path file);
964
965         void set_show_hints_before_make_dcp (bool s) {
966                 maybe_set (_show_hints_before_make_dcp, s);
967         }
968
969         void set_confirm_kdm_email (bool s) {
970                 maybe_set (_confirm_kdm_email, s);
971         }
972
973         void set_sound (bool s) {
974                 maybe_set (_sound, s, SOUND);
975         }
976
977         void set_sound_output (std::string o) {
978                 maybe_set (_sound_output, o, SOUND_OUTPUT);
979         }
980
981         void set_last_player_load_directory (boost::filesystem::path d) {
982                 maybe_set (_last_player_load_directory, d);
983         }
984
985         void set_last_kdm_write_type (KDMWriteType t) {
986                 maybe_set (_last_kdm_write_type, t);
987         }
988
989         void set_last_dkdm_write_type (DKDMWriteType t) {
990                 maybe_set (_last_dkdm_write_type, t);
991         }
992
993         void unset_sound_output () {
994                 if (!_sound_output) {
995                         return;
996                 }
997
998                 _sound_output = boost::none;
999                 changed ();
1000         }
1001
1002         void set_kdm_container_name_format (dcp::NameFormat n) {
1003                 maybe_set (_kdm_container_name_format, n);
1004         }
1005
1006         void set_kdm_filename_format (dcp::NameFormat n) {
1007                 maybe_set (_kdm_filename_format, n);
1008         }
1009
1010         void set_dkdm_filename_format (dcp::NameFormat n) {
1011                 maybe_set (_dkdm_filename_format, n);
1012         }
1013
1014         void set_dcp_metadata_filename_format (dcp::NameFormat n) {
1015                 maybe_set (_dcp_metadata_filename_format, n);
1016         }
1017
1018         void set_dcp_asset_filename_format (dcp::NameFormat n) {
1019                 maybe_set (_dcp_asset_filename_format, n);
1020         }
1021
1022         void set_frames_in_memory_multiplier (int m) {
1023                 maybe_set (_frames_in_memory_multiplier, m);
1024         }
1025
1026         void set_decode_reduction (boost::optional<int> r) {
1027                 maybe_set (_decode_reduction, r);
1028         }
1029
1030         void set_default_notify (bool n) {
1031                 maybe_set (_default_notify, n);
1032         }
1033
1034         void clear_history () {
1035                 _history.clear ();
1036                 changed ();
1037         }
1038
1039         void clear_player_history () {
1040                 _player_history.clear ();
1041                 changed ();
1042         }
1043
1044         void add_to_history (boost::filesystem::path p);
1045         void clean_history ();
1046         void add_to_player_history (boost::filesystem::path p);
1047         void clean_player_history ();
1048
1049         void set_jump_to_selected (bool j) {
1050                 maybe_set (_jump_to_selected, j);
1051         }
1052
1053         void set_nagged (Nag nag, bool nagged) {
1054                 maybe_set (_nagged[nag], nagged);
1055         }
1056
1057         void set_cover_sheet (std::string s) {
1058                 maybe_set (_cover_sheet, s);
1059         }
1060
1061         void reset_cover_sheet ();
1062
1063         void set_notification (Notification n, bool v) {
1064                 maybe_set (_notification[n], v);
1065         }
1066
1067         void set_barco_username (std::string u) {
1068                 maybe_set (_barco_username, u);
1069         }
1070
1071         void unset_barco_username () {
1072                 maybe_set (_barco_username, boost::optional<std::string>());
1073         }
1074
1075         void set_barco_password (std::string p) {
1076                 maybe_set (_barco_password, p);
1077         }
1078
1079         void unset_barco_password () {
1080                 maybe_set (_barco_password, boost::optional<std::string>());
1081         }
1082
1083         void set_christie_username (std::string u) {
1084                 maybe_set (_christie_username, u);
1085         }
1086
1087         void unset_christie_username () {
1088                 maybe_set (_christie_username, boost::optional<std::string>());
1089         }
1090
1091         void set_christie_password (std::string p) {
1092                 maybe_set (_christie_password, p);
1093         }
1094
1095         void unset_christie_password () {
1096                 maybe_set (_christie_password, boost::optional<std::string>());
1097         }
1098
1099         void set_gdc_username (std::string u) {
1100                 maybe_set (_gdc_username, u);
1101         }
1102
1103         void unset_gdc_username () {
1104                 maybe_set (_gdc_username, boost::optional<std::string>());
1105         }
1106
1107         void set_gdc_password (std::string p) {
1108                 maybe_set (_gdc_password, p);
1109         }
1110
1111         void unset_gdc_password () {
1112                 maybe_set (_gdc_password, boost::optional<std::string>());
1113         }
1114
1115         void set_player_mode (PlayerMode m) {
1116                 maybe_set (_player_mode, m);
1117         }
1118
1119         void set_image_display (int n) {
1120                 maybe_set (_image_display, n);
1121         }
1122
1123         void set_video_view_type (VideoViewType v) {
1124                 maybe_set (_video_view_type, v);
1125         }
1126
1127         void set_respect_kdm_validity_periods (bool r) {
1128                 maybe_set (_respect_kdm_validity_periods, r);
1129         }
1130
1131         void set_player_debug_log_file (boost::filesystem::path p) {
1132                 maybe_set (_player_debug_log_file, p, PLAYER_DEBUG_LOG);
1133         }
1134
1135         void unset_player_debug_log_file () {
1136                 if (!_player_debug_log_file) {
1137                         return;
1138                 }
1139                 _player_debug_log_file = boost::none;
1140                 changed (PLAYER_DEBUG_LOG);
1141         }
1142
1143         void set_player_content_directory (boost::filesystem::path p) {
1144                 maybe_set (_player_content_directory, p, PLAYER_CONTENT_DIRECTORY);
1145         }
1146
1147         void unset_player_content_directory () {
1148                 if (!_player_content_directory) {
1149                         return;
1150                 }
1151                 _player_content_directory = boost::none;
1152                 changed (PLAYER_CONTENT_DIRECTORY);
1153         }
1154
1155         void set_player_playlist_directory (boost::filesystem::path p) {
1156                 maybe_set (_player_playlist_directory, p, PLAYER_PLAYLIST_DIRECTORY);
1157         }
1158
1159         void unset_player_playlist_directory () {
1160                 if (!_player_playlist_directory) {
1161                         return;
1162                 }
1163                 _player_playlist_directory = boost::none;
1164                 changed (PLAYER_PLAYLIST_DIRECTORY);
1165         }
1166
1167         void set_player_kdm_directory (boost::filesystem::path p) {
1168                 maybe_set (_player_kdm_directory, p);
1169         }
1170
1171         void unset_player_kdm_directory () {
1172                 if (!_player_kdm_directory) {
1173                         return;
1174                 }
1175                 _player_kdm_directory = boost::none;
1176                 changed ();
1177         }
1178
1179         void set_audio_mapping (AudioMapping m);
1180         void set_audio_mapping_to_default ();
1181
1182         void add_custom_language (dcp::LanguageTag tag);
1183
1184         void set_initial_path(std::string id, boost::filesystem::path path);
1185
1186         void set_use_isdcf_name_by_default (bool use) {
1187                 maybe_set (_use_isdcf_name_by_default, use);
1188         }
1189
1190         void set_write_kdms_to_disk (bool write) {
1191                 maybe_set (_write_kdms_to_disk, write);
1192         }
1193
1194         void set_email_kdms (bool email) {
1195                 maybe_set (_email_kdms, email);
1196         }
1197
1198         void set_default_kdm_type (dcp::Formulation type) {
1199                 maybe_set (_default_kdm_type, type);
1200         }
1201
1202         void set_default_kdm_duration (RoughDuration duration) {
1203                 maybe_set (_default_kdm_duration, duration);
1204         }
1205
1206         void set_auto_crop_threshold (double threshold) {
1207                 maybe_set (_auto_crop_threshold, threshold, AUTO_CROP_THRESHOLD);
1208         }
1209
1210         void set_last_release_notes_version (std::string version) {
1211                 maybe_set (_last_release_notes_version, version);
1212         }
1213
1214         void unset_last_release_notes_version() {
1215                 maybe_set(_last_release_notes_version, boost::optional<std::string>());
1216         }
1217
1218         ExportConfig& export_config() {
1219                 return _export;
1220         }
1221
1222         void set_main_divider_sash_position(int position) {
1223                 maybe_set(_main_divider_sash_position, position);
1224         }
1225
1226         void set_main_content_divider_sash_position(int position) {
1227                 maybe_set(_main_content_divider_sash_position, position);
1228         }
1229
1230         void set_default_add_file_location(DefaultAddFileLocation location) {
1231                 maybe_set(_default_add_file_location, location);
1232         }
1233
1234         void set_allow_smpte_bv20(bool allow) {
1235                 maybe_set(_allow_smpte_bv20, allow, ALLOW_SMPTE_BV20);
1236         }
1237
1238 #ifdef DCPOMATIC_GROK
1239         void set_grok(Grok const& grok);
1240 #endif
1241
1242         void set_isdcf_name_part_length(int length) {
1243                 maybe_set(_isdcf_name_part_length, length, ISDCF_NAME_PART_LENGTH);
1244         }
1245
1246
1247         void changed (Property p = OTHER);
1248         boost::signals2::signal<void (Property)> Changed;
1249         /** Emitted if read() failed on an existing Config file.  There is nothing
1250             a listener can do about it: this is just for information.
1251         */
1252         enum class LoadFailure {
1253                 CONFIG,
1254                 CINEMAS,
1255                 DKDM_RECIPIENTS
1256         };
1257         static boost::signals2::signal<void (LoadFailure)> FailedToLoad;
1258         /** Emitted if read() issued a warning which the user might want to know about */
1259         static boost::signals2::signal<void (std::string)> Warning;
1260         /** Emitted if there is a something wrong the contents of our config.  Handler can call
1261          *  true to ask Config to solve the problem (by discarding and recreating the bad thing)
1262          */
1263         enum BadReason {
1264                 BAD_SIGNER_UTF8_STRINGS,      ///< signer chain contains UTF-8 strings (not PRINTABLESTRING)
1265                 BAD_SIGNER_INCONSISTENT,      ///< signer chain is somehow inconsistent
1266                 BAD_DECRYPTION_INCONSISTENT,  ///< KDM decryption chain is somehow inconsistent
1267                 BAD_SIGNER_VALIDITY_TOO_LONG, ///< signer certificate validity periods are >10 years
1268                 BAD_SIGNER_DN_QUALIFIER,      ///< some signer certificate has a bad dnQualifier (DoM #2716).
1269         };
1270
1271         static boost::signals2::signal<bool (BadReason)> Bad;
1272
1273         void write () const override;
1274         void write_config () const;
1275         void write_cinemas () const;
1276         void write_dkdm_recipients () const;
1277         void link (boost::filesystem::path new_file) const;
1278         void copy_and_link (boost::filesystem::path new_file) const;
1279         bool have_write_permission () const;
1280
1281         void save_template (std::shared_ptr<const Film> film, std::string name) const;
1282         bool existing_template (std::string name) const;
1283         std::list<std::string> templates () const;
1284         boost::filesystem::path template_read_path (std::string name) const;
1285         boost::filesystem::path template_write_path (std::string name) const;
1286         void rename_template (std::string old_name, std::string new_name) const;
1287         void delete_template (std::string name) const;
1288
1289         boost::optional<BadReason> check_certificates () const;
1290
1291         static Config* instance ();
1292         static void drop ();
1293         static void restore_defaults ();
1294         static bool have_existing (std::string);
1295         static boost::filesystem::path config_read_file ();
1296         static boost::filesystem::path config_write_file ();
1297
1298         template <class T>
1299         void maybe_set (T& member, T new_value, Property prop = OTHER) {
1300                 if (member == new_value) {
1301                         return;
1302                 }
1303                 member = new_value;
1304                 changed (prop);
1305         }
1306
1307         template <class T>
1308         void maybe_set (boost::optional<T>& member, T new_value, Property prop = OTHER) {
1309                 if (member && member.get() == new_value) {
1310                         return;
1311                 }
1312                 member = new_value;
1313                 changed (prop);
1314         }
1315
1316 private:
1317         Config ();
1318         void read () override;
1319         void read_config();
1320         void read_cinemas();
1321         void read_dkdm_recipients();
1322         void set_defaults ();
1323         void set_kdm_email_to_default ();
1324         void set_notification_email_to_default ();
1325         void set_cover_sheet_to_default ();
1326         void read_cinemas (cxml::Document const & f);
1327         void read_dkdm_recipients (cxml::Document const & f);
1328         std::shared_ptr<dcp::CertificateChain> create_certificate_chain ();
1329         boost::filesystem::path directory_or (boost::optional<boost::filesystem::path> dir, boost::filesystem::path a) const;
1330         void add_to_history_internal (std::vector<boost::filesystem::path>& h, boost::filesystem::path p);
1331         void clean_history_internal (std::vector<boost::filesystem::path>& h);
1332         void backup ();
1333
1334         /** number of threads which a master DoM should use for J2K encoding on the local machine */
1335         int _master_encoding_threads;
1336         /** number of threads which a server should use for J2K encoding on the local machine */
1337         int _server_encoding_threads;
1338         /** default directory to put new films in */
1339         boost::optional<boost::filesystem::path> _default_directory;
1340         /** base port number to use for J2K encoding servers;
1341          *  this port and the two above it will be used.
1342          */
1343         int _server_port_base;
1344         /** true to broadcast on the `any' address to look for servers */
1345         bool _use_any_servers;
1346         /** J2K encoding servers that should definitely be used */
1347         std::vector<std::string> _servers;
1348         bool _only_servers_encode;
1349         FileTransferProtocol _tms_protocol;
1350         bool _tms_passive;
1351         /** The IP address of a TMS that we can copy DCPs to */
1352         std::string _tms_ip;
1353         /** The path on a TMS that we should write DCPs to */
1354         std::string _tms_path;
1355         /** User name to log into the TMS with */
1356         std::string _tms_user;
1357         /** Password to log into the TMS with */
1358         std::string _tms_password;
1359         /** The list of possible DCP frame rates that DCP-o-matic will use */
1360         std::list<int> _allowed_dcp_frame_rates;
1361         /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
1362         bool _allow_any_dcp_frame_rate;
1363         /** Allow any container ratio, not just the standard ones.  GDC SX-2001 will not play Flat
1364             DCPs at 25fps but will play 16:9, so this is very useful for some users.
1365             https://www.dcpomatic.com/forum/viewtopic.php?f=2&t=1119&p=4468
1366         */
1367         bool _allow_any_container;
1368         bool _allow_96khz_audio;
1369         bool _use_all_audio_channels;
1370         /** Offer the upmixers in the audio processor settings */
1371         bool _show_experimental_audio_processors;
1372         boost::optional<std::string> _language;
1373         /** Default length of still image content (seconds) */
1374         int _default_still_length;
1375         DCPContentType const * _default_dcp_content_type;
1376         int _default_dcp_audio_channels;
1377         std::string _dcp_issuer;
1378         std::string _dcp_creator;
1379         std::string _dcp_company_name;
1380         std::string _dcp_product_name;
1381         std::string _dcp_product_version;
1382         std::string _dcp_j2k_comment;
1383         int64_t _default_video_bit_rate;
1384         int _default_audio_delay;
1385         bool _default_interop;
1386         boost::optional<dcp::LanguageTag> _default_audio_language;
1387         boost::optional<dcp::LanguageTag::RegionSubtag> _default_territory;
1388         std::map<std::string, std::string> _default_metadata;
1389         /** Default directory to offer to write KDMs to; if it's not set,
1390             the home directory will be offered.
1391         */
1392         boost::optional<boost::filesystem::path> _default_kdm_directory;
1393         bool _upload_after_make_dcp;
1394         std::list<std::shared_ptr<Cinema>> _cinemas;
1395         std::list<std::shared_ptr<DKDMRecipient>> _dkdm_recipients;
1396         std::string _mail_server;
1397         int _mail_port;
1398         EmailProtocol _mail_protocol;
1399         std::string _mail_user;
1400         std::string _mail_password;
1401         std::string _kdm_subject;
1402         std::string _kdm_from;
1403         std::vector<std::string> _kdm_cc;
1404         std::string _kdm_bcc;
1405         std::string _kdm_email;
1406         std::string _notification_subject;
1407         std::string _notification_from;
1408         std::string _notification_to;
1409         std::vector<std::string> _notification_cc;
1410         std::string _notification_bcc;
1411         std::string _notification_email;
1412         std::shared_ptr<const dcp::CertificateChain> _signer_chain;
1413         /** Chain used to decrypt KDMs; the leaf of this chain is the target
1414          *  certificate for making KDMs given to DCP-o-matic.
1415          */
1416         std::shared_ptr<const dcp::CertificateChain> _decryption_chain;
1417         /** true to check for updates on startup */
1418         bool _check_for_updates;
1419         bool _check_for_test_updates;
1420         /** maximum allowed video bit rate in bits per second */
1421         int64_t _maximum_video_bit_rate;
1422         int _log_types;
1423         bool _analyse_ebur128;
1424         bool _automatic_audio_analysis;
1425 #ifdef DCPOMATIC_WINDOWS
1426         bool _win32_console;
1427 #endif
1428         std::vector<boost::filesystem::path> _history;
1429         std::vector<boost::filesystem::path> _player_history;
1430         std::shared_ptr<DKDMGroup> _dkdms;
1431         boost::filesystem::path _cinemas_file;
1432         boost::filesystem::path _dkdm_recipients_file;
1433         bool _show_hints_before_make_dcp;
1434         bool _confirm_kdm_email;
1435         dcp::NameFormat _kdm_filename_format;
1436         dcp::NameFormat _dkdm_filename_format;
1437         dcp::NameFormat _kdm_container_name_format;
1438         dcp::NameFormat _dcp_metadata_filename_format;
1439         dcp::NameFormat _dcp_asset_filename_format;
1440         bool _jump_to_selected;
1441         bool _nagged[NAG_COUNT];
1442         bool _sound;
1443         /** name of a specific sound output stream to use, or empty to use the default */
1444         boost::optional<std::string> _sound_output;
1445         std::string _cover_sheet;
1446         boost::optional<boost::filesystem::path> _last_player_load_directory;
1447         boost::optional<KDMWriteType> _last_kdm_write_type;
1448         boost::optional<DKDMWriteType> _last_dkdm_write_type;
1449         int _frames_in_memory_multiplier;
1450         boost::optional<int> _decode_reduction;
1451         bool _default_notify;
1452         bool _notification[NOTIFICATION_COUNT];
1453         boost::optional<std::string> _barco_username;
1454         boost::optional<std::string> _barco_password;
1455         boost::optional<std::string> _christie_username;
1456         boost::optional<std::string> _christie_password;
1457         boost::optional<std::string> _gdc_username;
1458         boost::optional<std::string> _gdc_password;
1459         PlayerMode _player_mode;
1460         bool _player_restricted_menus = false;
1461         bool _playlist_editor_restricted_menus = false;
1462         int _image_display;
1463         VideoViewType _video_view_type;
1464         bool _respect_kdm_validity_periods;
1465         /** Log file containing debug information for the player */
1466         boost::optional<boost::filesystem::path> _player_debug_log_file;
1467         /** A directory containing DCPs whose contents are presented to the user
1468             in the dual-screen player mode.  DCPs on the list can be loaded
1469             for playback.
1470         */
1471         boost::optional<boost::filesystem::path> _player_content_directory;
1472         boost::optional<boost::filesystem::path> _player_playlist_directory;
1473         boost::optional<boost::filesystem::path> _player_kdm_directory;
1474         boost::optional<AudioMapping> _audio_mapping;
1475         std::vector<dcp::LanguageTag> _custom_languages;
1476         std::map<std::string, boost::optional<boost::filesystem::path>> _initial_paths;
1477         bool _use_isdcf_name_by_default;
1478         bool _write_kdms_to_disk;
1479         bool _email_kdms;
1480         dcp::Formulation _default_kdm_type;
1481         RoughDuration _default_kdm_duration;
1482         double _auto_crop_threshold;
1483         boost::optional<std::string> _last_release_notes_version;
1484         boost::optional<int> _main_divider_sash_position;
1485         boost::optional<int> _main_content_divider_sash_position;
1486         DefaultAddFileLocation _default_add_file_location;
1487         bool _allow_smpte_bv20;
1488         int _isdcf_name_part_length;
1489
1490 #ifdef DCPOMATIC_GROK
1491         boost::optional<Grok> _grok;
1492 #endif
1493
1494         ExportConfig _export;
1495
1496         static int const _current_version;
1497
1498         /** Singleton instance, or 0 */
1499         static Config* _instance;
1500 };
1501
1502
1503 #endif