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