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