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