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