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