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