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