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