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