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