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