Make terminate_threads() less likely to leave _threads containing invalid pointers.
[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_COUNT
380         };
381
382         bool nagged (Nag nag) const {
383                 return _nagged[nag];
384         }
385
386         bool sound () const {
387                 return _sound;
388         }
389
390         std::string cover_sheet () const {
391                 return _cover_sheet;
392         }
393
394         boost::optional<std::string> sound_output () const {
395                 return _sound_output;
396         }
397
398         boost::optional<boost::filesystem::path> last_player_load_directory () const {
399                 return _last_player_load_directory;
400         }
401
402         enum KDMWriteType {
403                 KDM_WRITE_FLAT,
404                 KDM_WRITE_FOLDER,
405                 KDM_WRITE_ZIP
406         };
407
408         boost::optional<KDMWriteType> last_kdm_write_type () const {
409                 return _last_kdm_write_type;
410         }
411
412         enum DKDMWriteType {
413                 DKDM_WRITE_INTERNAL,
414                 DKDM_WRITE_FILE
415         };
416
417         boost::optional<DKDMWriteType> last_dkdm_write_type () const {
418                 return _last_dkdm_write_type;
419         }
420
421         int frames_in_memory_multiplier () const {
422                 return _frames_in_memory_multiplier;
423         }
424
425         boost::optional<int> decode_reduction () const {
426                 return _decode_reduction;
427         }
428
429         bool default_notify () const {
430                 return _default_notify;
431         }
432
433         enum Notification {
434                 MESSAGE_BOX,
435                 EMAIL,
436                 NOTIFICATION_COUNT
437         };
438
439         bool notification (Notification n) const {
440                 return _notification[n];
441         }
442
443         boost::optional<std::string> barco_username () const {
444                 return _barco_username;
445         }
446
447         boost::optional<std::string> barco_password () const {
448                 return _barco_password;
449         }
450
451         boost::optional<std::string> christie_username () const {
452                 return _christie_username;
453         }
454
455         boost::optional<std::string> christie_password () const {
456                 return _christie_password;
457         }
458
459         boost::optional<std::string> gdc_username () const {
460                 return _gdc_username;
461         }
462
463         boost::optional<std::string> gdc_password () const {
464                 return _gdc_password;
465         }
466
467         enum Interface {
468                 INTERFACE_SIMPLE,
469                 INTERFACE_FULL
470         };
471
472         Interface interface_complexity () const {
473                 return _interface_complexity;
474         }
475
476         enum PlayerMode {
477                 PLAYER_MODE_WINDOW,
478                 PLAYER_MODE_FULL,
479                 PLAYER_MODE_DUAL
480         };
481
482         PlayerMode player_mode () const {
483                 return _player_mode;
484         }
485
486         int image_display () const {
487                 return _image_display;
488         }
489
490         bool respect_kdm_validity_periods () const {
491                 return _respect_kdm_validity_periods;
492         }
493
494         boost::optional<boost::filesystem::path> player_activity_log_file () const {
495                 return _player_activity_log_file;
496         }
497
498         boost::optional<boost::filesystem::path> player_debug_log_file () const {
499                 return _player_debug_log_file;
500         }
501
502         boost::optional<boost::filesystem::path> player_content_directory () const {
503                 return _player_content_directory;
504         }
505
506         boost::optional<boost::filesystem::path> player_playlist_directory () const {
507                 return _player_playlist_directory;
508         }
509
510         boost::optional<boost::filesystem::path> player_kdm_directory () const {
511                 return _player_kdm_directory;
512         }
513
514 #ifdef DCPOMATIC_VARIANT_SWAROOP
515         boost::optional<boost::filesystem::path> player_background_image () const {
516                 return _player_background_image;
517         }
518
519         std::string kdm_server_url () const {
520                 return _kdm_server_url;
521         }
522
523         std::string player_watermark_theatre () const {
524                 return _player_watermark_theatre;
525         }
526
527         int player_watermark_period () const {
528                 return _player_watermark_period;
529         }
530
531         int player_watermark_duration () const {
532                 return _player_watermark_duration;
533         }
534
535         std::vector<Monitor> required_monitors () const {
536                 return _required_monitors;
537         }
538
539         boost::optional<boost::filesystem::path> player_lock_file () const {
540                 return _player_lock_file;
541         }
542 #endif
543
544         /* SET (mostly) */
545
546         void set_master_encoding_threads (int n) {
547                 maybe_set (_master_encoding_threads, n);
548         }
549
550         void set_server_encoding_threads (int n) {
551                 maybe_set (_server_encoding_threads, n);
552         }
553
554         void set_default_directory (boost::filesystem::path d) {
555                 if (_default_directory && *_default_directory == d) {
556                         return;
557                 }
558                 _default_directory = d;
559                 changed ();
560         }
561
562         /** @param p New server port */
563         void set_server_port_base (int p) {
564                 maybe_set (_server_port_base, p);
565         }
566
567         void set_only_servers_encode (bool o) {
568                 maybe_set (_only_servers_encode, o);
569         }
570
571         void set_tms_protocol (FileTransferProtocol p) {
572                 maybe_set (_tms_protocol, p);
573         }
574
575         /** @param i IP address of a TMS that we can copy DCPs to */
576         void set_tms_ip (std::string i) {
577                 maybe_set (_tms_ip, i);
578         }
579
580         /** @param p Path on a TMS that we should changed DCPs to */
581         void set_tms_path (std::string p) {
582                 maybe_set (_tms_path, p);
583         }
584
585         /** @param u User name to log into the TMS with */
586         void set_tms_user (std::string u) {
587                 maybe_set (_tms_user, u);
588         }
589
590         /** @param p Password to log into the TMS with */
591         void set_tms_password (std::string p) {
592                 maybe_set (_tms_password, p);
593         }
594
595         void add_cinema (boost::shared_ptr<Cinema> c) {
596                 _cinemas.push_back (c);
597                 changed (CINEMAS);
598         }
599
600         void remove_cinema (boost::shared_ptr<Cinema> c) {
601                 _cinemas.remove (c);
602                 changed (CINEMAS);
603         }
604
605         void set_allowed_dcp_frame_rates (std::list<int> const & r) {
606                 maybe_set (_allowed_dcp_frame_rates, r);
607         }
608
609         void set_allow_any_dcp_frame_rate (bool a) {
610                 maybe_set (_allow_any_dcp_frame_rate, a);
611         }
612
613         void set_allow_any_container (bool a) {
614                 maybe_set (_allow_any_container, a);
615         }
616
617         void set_default_isdcf_metadata (ISDCFMetadata d) {
618                 maybe_set (_default_isdcf_metadata, d);
619         }
620
621         void set_language (std::string l) {
622                 if (_language && _language.get() == l) {
623                         return;
624                 }
625                 _language = l;
626                 changed ();
627         }
628
629         void unset_language () {
630                 if (!_language) {
631                         return;
632                 }
633
634                 _language = boost::none;
635                 changed ();
636         }
637
638         void set_default_still_length (int s) {
639                 maybe_set (_default_still_length, s);
640         }
641
642         void set_default_container (Ratio const * c) {
643                 maybe_set (_default_container, c);
644         }
645
646         void set_default_scale_to (Ratio const * c) {
647                 maybe_set (_default_scale_to, c);
648         }
649
650         void set_default_dcp_content_type (DCPContentType const * t) {
651                 maybe_set (_default_dcp_content_type, t);
652         }
653
654         void set_default_dcp_audio_channels (int c) {
655                 maybe_set (_default_dcp_audio_channels, c);
656         }
657
658         void set_dcp_issuer (std::string i) {
659                 maybe_set (_dcp_issuer, i);
660         }
661
662         void set_dcp_creator (std::string c) {
663                 maybe_set (_dcp_creator, c);
664         }
665
666         void set_default_j2k_bandwidth (int b) {
667                 maybe_set (_default_j2k_bandwidth, b);
668         }
669
670         void set_default_audio_delay (int d) {
671                 maybe_set (_default_audio_delay, d);
672         }
673
674         void set_default_interop (bool i) {
675                 maybe_set (_default_interop, i);
676         }
677
678         void set_default_upload_after_make_dcp (bool u) {
679                 maybe_set (_default_upload_after_make_dcp, u);
680         }
681
682         void set_mail_server (std::string s) {
683                 maybe_set (_mail_server, s);
684         }
685
686         void set_mail_port (int p) {
687                 maybe_set (_mail_port, p);
688         }
689
690         void set_mail_protocol (EmailProtocol p) {
691                 maybe_set (_mail_protocol, p);
692         }
693
694         void set_mail_user (std::string u) {
695                 maybe_set (_mail_user, u);
696         }
697
698         void set_mail_password (std::string p) {
699                 maybe_set (_mail_password, p);
700         }
701
702         void set_kdm_subject (std::string s) {
703                 maybe_set (_kdm_subject, s);
704         }
705
706         void set_kdm_from (std::string f) {
707                 maybe_set (_kdm_from, f);
708         }
709
710         void set_kdm_cc (std::vector<std::string> f) {
711                 maybe_set (_kdm_cc, f);
712         }
713
714         void set_kdm_bcc (std::string f) {
715                 maybe_set (_kdm_bcc, f);
716         }
717
718         void set_kdm_email (std::string e) {
719                 maybe_set (_kdm_email, e);
720         }
721
722         void reset_kdm_email ();
723
724         void set_notification_subject (std::string s) {
725                 maybe_set (_notification_subject, s);
726         }
727
728         void set_notification_from (std::string f) {
729                 maybe_set (_notification_from, f);
730         }
731
732         void set_notification_to (std::string t) {
733                 maybe_set (_notification_to, t);
734         }
735
736         void set_notification_cc (std::vector<std::string> f) {
737                 maybe_set (_notification_cc, f);
738         }
739
740         void set_notification_bcc (std::string f) {
741                 maybe_set (_notification_bcc, f);
742         }
743
744         void set_notification_email (std::string e) {
745                 maybe_set (_notification_email, e);
746         }
747
748         void reset_notification_email ();
749
750         void set_signer_chain (boost::shared_ptr<const dcp::CertificateChain> s) {
751                 maybe_set (_signer_chain, s);
752         }
753
754         void set_decryption_chain (boost::shared_ptr<const dcp::CertificateChain> c) {
755                 maybe_set (_decryption_chain, c);
756         }
757
758         void set_check_for_updates (bool c) {
759                 maybe_set (_check_for_updates, c);
760                 if (!c) {
761                         set_check_for_test_updates (false);
762                 }
763         }
764
765         void set_check_for_test_updates (bool c) {
766                 maybe_set (_check_for_test_updates, c);
767         }
768
769         void set_maximum_j2k_bandwidth (int b) {
770                 maybe_set (_maximum_j2k_bandwidth, b);
771         }
772
773         void set_log_types (int t) {
774                 maybe_set (_log_types, t);
775         }
776
777         void set_analyse_ebur128 (bool a) {
778                 maybe_set (_analyse_ebur128, a);
779         }
780
781         void set_automatic_audio_analysis (bool a) {
782                 maybe_set (_automatic_audio_analysis, a);
783         }
784
785 #ifdef DCPOMATIC_WINDOWS
786         void set_win32_console (bool c) {
787                 maybe_set (_win32_console, c);
788         }
789 #endif
790
791         void set_dkdms (boost::shared_ptr<DKDMGroup> dkdms) {
792                 _dkdms = dkdms;
793                 changed ();
794         }
795
796         void set_cinemas_file (boost::filesystem::path file);
797
798         void set_show_hints_before_make_dcp (bool s) {
799                 maybe_set (_show_hints_before_make_dcp, s);
800         }
801
802         void set_confirm_kdm_email (bool s) {
803                 maybe_set (_confirm_kdm_email, s);
804         }
805
806         void set_sound (bool s) {
807                 maybe_set (_sound, s, SOUND);
808         }
809
810         void set_sound_output (std::string o) {
811                 maybe_set (_sound_output, o, SOUND_OUTPUT);
812         }
813
814         void set_last_player_load_directory (boost::filesystem::path d) {
815                 maybe_set (_last_player_load_directory, d);
816         }
817
818         void set_last_kdm_write_type (KDMWriteType t) {
819                 maybe_set (_last_kdm_write_type, t);
820         }
821
822         void set_last_dkdm_write_type (DKDMWriteType t) {
823                 maybe_set (_last_dkdm_write_type, t);
824         }
825
826         void unset_sound_output () {
827                 if (!_sound_output) {
828                         return;
829                 }
830
831                 _sound_output = boost::none;
832                 changed ();
833         }
834
835         void set_kdm_container_name_format (dcp::NameFormat n) {
836                 maybe_set (_kdm_container_name_format, n);
837         }
838
839         void set_kdm_filename_format (dcp::NameFormat n) {
840                 maybe_set (_kdm_filename_format, n);
841         }
842
843         void set_dcp_metadata_filename_format (dcp::NameFormat n) {
844                 maybe_set (_dcp_metadata_filename_format, n);
845         }
846
847         void set_dcp_asset_filename_format (dcp::NameFormat n) {
848                 maybe_set (_dcp_asset_filename_format, n);
849         }
850
851         void set_frames_in_memory_multiplier (int m) {
852                 maybe_set (_frames_in_memory_multiplier, m);
853         }
854
855         void set_decode_reduction (boost::optional<int> r) {
856                 maybe_set (_decode_reduction, r);
857         }
858
859         void set_default_notify (bool n) {
860                 maybe_set (_default_notify, n);
861         }
862
863         void clear_history () {
864                 _history.clear ();
865                 changed ();
866         }
867
868         void clear_player_history () {
869                 _player_history.clear ();
870                 changed ();
871         }
872
873         void add_to_history (boost::filesystem::path p);
874         void clean_history ();
875         void add_to_player_history (boost::filesystem::path p);
876         void clean_player_history ();
877
878         void set_jump_to_selected (bool j) {
879                 maybe_set (_jump_to_selected, j);
880         }
881
882         void set_nagged (Nag nag, bool nagged) {
883                 maybe_set (_nagged[nag], nagged);
884         }
885
886         void set_cover_sheet (std::string s) {
887                 maybe_set (_cover_sheet, s);
888         }
889
890         void reset_cover_sheet ();
891
892         void set_notification (Notification n, bool v) {
893                 maybe_set (_notification[n], v);
894         }
895
896         void set_barco_username (std::string u) {
897                 maybe_set (_barco_username, u);
898         }
899
900         void unset_barco_username () {
901                 maybe_set (_barco_username, boost::optional<std::string>());
902         }
903
904         void set_barco_password (std::string p) {
905                 maybe_set (_barco_password, p);
906         }
907
908         void unset_barco_password () {
909                 maybe_set (_barco_password, boost::optional<std::string>());
910         }
911
912         void set_christie_username (std::string u) {
913                 maybe_set (_christie_username, u);
914         }
915
916         void unset_christie_username () {
917                 maybe_set (_christie_username, boost::optional<std::string>());
918         }
919
920         void set_christie_password (std::string p) {
921                 maybe_set (_christie_password, p);
922         }
923
924         void unset_christie_password () {
925                 maybe_set (_christie_password, boost::optional<std::string>());
926         }
927
928         void set_gdc_username (std::string u) {
929                 maybe_set (_gdc_username, u);
930         }
931
932         void unset_gdc_username () {
933                 maybe_set (_gdc_username, boost::optional<std::string>());
934         }
935
936         void set_gdc_password (std::string p) {
937                 maybe_set (_gdc_password, p);
938         }
939
940         void unset_gdc_password () {
941                 maybe_set (_gdc_password, boost::optional<std::string>());
942         }
943
944         void set_interface_complexity (Interface i) {
945                 maybe_set (_interface_complexity, i, INTERFACE_COMPLEXITY);
946         }
947
948         void set_player_mode (PlayerMode m) {
949                 maybe_set (_player_mode, m);
950         }
951
952         void set_image_display (int n) {
953                 maybe_set (_image_display, n);
954         }
955
956         void set_respect_kdm_validity_periods (bool r) {
957                 maybe_set (_respect_kdm_validity_periods, r);
958         }
959
960         void set_player_activity_log_file (boost::filesystem::path p) {
961                 maybe_set (_player_activity_log_file, p);
962         }
963
964         void unset_player_activity_log_file () {
965                 if (!_player_activity_log_file) {
966                         return;
967                 }
968                 _player_activity_log_file = boost::none;
969                 changed ();
970         }
971
972         void set_player_debug_log_file (boost::filesystem::path p) {
973                 maybe_set (_player_debug_log_file, p, PLAYER_DEBUG_LOG);
974         }
975
976         void unset_player_debug_log_file () {
977                 if (!_player_debug_log_file) {
978                         return;
979                 }
980                 _player_debug_log_file = boost::none;
981                 changed (PLAYER_DEBUG_LOG);
982         }
983
984         void set_player_content_directory (boost::filesystem::path p) {
985                 maybe_set (_player_content_directory, p, PLAYER_CONTENT_DIRECTORY);
986         }
987
988         void unset_player_content_directory () {
989                 if (!_player_content_directory) {
990                         return;
991                 }
992                 _player_content_directory = boost::none;
993                 changed (PLAYER_CONTENT_DIRECTORY);
994         }
995
996         void set_player_playlist_directory (boost::filesystem::path p) {
997                 maybe_set (_player_playlist_directory, p, PLAYER_PLAYLIST_DIRECTORY);
998         }
999
1000         void unset_player_playlist_directory () {
1001                 if (!_player_playlist_directory) {
1002                         return;
1003                 }
1004                 _player_playlist_directory = boost::none;
1005                 changed (PLAYER_PLAYLIST_DIRECTORY);
1006         }
1007
1008         void set_player_kdm_directory (boost::filesystem::path p) {
1009                 maybe_set (_player_kdm_directory, p);
1010         }
1011
1012         void unset_player_kdm_directory () {
1013                 if (!_player_kdm_directory) {
1014                         return;
1015                 }
1016                 _player_kdm_directory = boost::none;
1017                 changed ();
1018         }
1019
1020 #ifdef DCPOMATIC_VARIANT_SWAROOP
1021         void set_player_background_image (boost::filesystem::path p) {
1022                 maybe_set (_player_background_image, p, PLAYER_BACKGROUND_IMAGE);
1023         }
1024
1025         void unset_player_background_image () {
1026                 if (!_player_background_image) {
1027                         return;
1028                 }
1029                 _player_background_image = boost::none;
1030                 changed (PLAYER_BACKGROUND_IMAGE);
1031         }
1032
1033         void set_kdm_server_url (std::string s) {
1034                 maybe_set (_kdm_server_url, s);
1035         }
1036
1037         void set_player_watermark_theatre (std::string p) {
1038                 maybe_set (_player_watermark_theatre, p);
1039         }
1040
1041         void set_player_watermark_period (int minutes) {
1042                 maybe_set (_player_watermark_period, minutes);
1043         }
1044
1045         void set_player_watermark_duration (int milliseconds) {
1046                 maybe_set (_player_watermark_duration, milliseconds);
1047         }
1048
1049         void set_required_monitors (std::vector<Monitor> monitors) {
1050                 maybe_set (_required_monitors, monitors);
1051         }
1052
1053         void set_player_lock_file (boost::filesystem::path p) {
1054                 maybe_set (_player_lock_file, p);
1055         }
1056
1057         void unset_player_lock_file () {
1058                 if (!_player_lock_file) {
1059                         return;
1060                 }
1061                 _player_lock_file = boost::none;
1062                 changed ();
1063         }
1064 #endif
1065
1066         void changed (Property p = OTHER);
1067         boost::signals2::signal<void (Property)> Changed;
1068         /** Emitted if read() failed on an existing Config file.  There is nothing
1069             a listener can do about it: this is just for information.
1070         */
1071         static boost::signals2::signal<void ()> FailedToLoad;
1072         /** Emitted if read() issued a warning which the user might want to know about */
1073         static boost::signals2::signal<void (std::string)> Warning;
1074         /** Emitted if there is a bad certificate in the signer chain.  Handler can call
1075          *  true to ask Config to re-create the chain.
1076          */
1077         static boost::signals2::signal<bool (void)> BadSignerChain;
1078
1079         void write () const;
1080         void write_config () const;
1081         void write_cinemas () const;
1082         void link (boost::filesystem::path new_file) const;
1083         void copy_and_link (boost::filesystem::path new_file) const;
1084         bool have_write_permission () const;
1085
1086         void save_template (boost::shared_ptr<const Film> film, std::string name) const;
1087         bool existing_template (std::string name) const;
1088         std::list<std::string> templates () const;
1089         boost::filesystem::path template_path (std::string name) const;
1090         void rename_template (std::string old_name, std::string new_name) const;
1091         void delete_template (std::string name) const;
1092
1093         static Config* instance ();
1094         static void drop ();
1095         static void restore_defaults ();
1096         static bool have_existing (std::string);
1097         static boost::filesystem::path config_file ();
1098
1099 private:
1100         Config ();
1101         void read ();
1102         void set_defaults ();
1103         void set_kdm_email_to_default ();
1104         void set_notification_email_to_default ();
1105         void set_cover_sheet_to_default ();
1106         void read_cinemas (cxml::Document const & f);
1107         boost::shared_ptr<dcp::CertificateChain> create_certificate_chain ();
1108         boost::filesystem::path directory_or (boost::optional<boost::filesystem::path> dir, boost::filesystem::path a) const;
1109         void add_to_history_internal (std::vector<boost::filesystem::path>& h, boost::filesystem::path p);
1110         void clean_history_internal (std::vector<boost::filesystem::path>& h);
1111         void backup ();
1112
1113         template <class T>
1114         void maybe_set (T& member, T new_value, Property prop = OTHER) {
1115                 if (member == new_value) {
1116                         return;
1117                 }
1118                 member = new_value;
1119                 changed (prop);
1120         }
1121
1122         template <class T>
1123         void maybe_set (boost::optional<T>& member, T new_value, Property prop = OTHER) {
1124                 if (member && member.get() == new_value) {
1125                         return;
1126                 }
1127                 member = new_value;
1128                 changed (prop);
1129         }
1130
1131         /** number of threads which a master DoM should use for J2K encoding on the local machine */
1132         int _master_encoding_threads;
1133         /** number of threads which a server should use for J2K encoding on the local machine */
1134         int _server_encoding_threads;
1135         /** default directory to put new films in */
1136         boost::optional<boost::filesystem::path> _default_directory;
1137         /** base port number to use for J2K encoding servers;
1138          *  this port and the two above it will be used.
1139          */
1140         int _server_port_base;
1141         /** true to broadcast on the `any' address to look for servers */
1142         bool _use_any_servers;
1143         /** J2K encoding servers that should definitely be used */
1144         std::vector<std::string> _servers;
1145         bool _only_servers_encode;
1146         FileTransferProtocol _tms_protocol;
1147         /** The IP address of a TMS that we can copy DCPs to */
1148         std::string _tms_ip;
1149         /** The path on a TMS that we should write DCPs to */
1150         std::string _tms_path;
1151         /** User name to log into the TMS with */
1152         std::string _tms_user;
1153         /** Password to log into the TMS with */
1154         std::string _tms_password;
1155         /** Our cinema sound processor */
1156         CinemaSoundProcessor const * _cinema_sound_processor;
1157         /** The list of possible DCP frame rates that DCP-o-matic will use */
1158         std::list<int> _allowed_dcp_frame_rates;
1159         /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
1160         bool _allow_any_dcp_frame_rate;
1161         /** Allow any container ratio, not just the standard ones.  GDC SX-2001 will not play Flat
1162             DCPs at 25fps but will play 16:9, so this is very useful for some users.
1163             https://www.dcpomatic.com/forum/viewtopic.php?f=2&t=1119&p=4468
1164         */
1165         bool _allow_any_container;
1166         /** Default ISDCF metadata for newly-created Films */
1167         ISDCFMetadata _default_isdcf_metadata;
1168         boost::optional<std::string> _language;
1169         /** Default length of still image content (seconds) */
1170         int _default_still_length;
1171         Ratio const * _default_container;
1172         Ratio const * _default_scale_to;
1173         DCPContentType const * _default_dcp_content_type;
1174         int _default_dcp_audio_channels;
1175         std::string _dcp_issuer;
1176         std::string _dcp_creator;
1177         int _default_j2k_bandwidth;
1178         int _default_audio_delay;
1179         bool _default_interop;
1180         /** Default directory to offer to write KDMs to; if it's not set,
1181             the home directory will be offered.
1182         */
1183         boost::optional<boost::filesystem::path> _default_kdm_directory;
1184         bool _default_upload_after_make_dcp;
1185         std::list<boost::shared_ptr<Cinema> > _cinemas;
1186         std::string _mail_server;
1187         int _mail_port;
1188         EmailProtocol _mail_protocol;
1189         std::string _mail_user;
1190         std::string _mail_password;
1191         std::string _kdm_subject;
1192         std::string _kdm_from;
1193         std::vector<std::string> _kdm_cc;
1194         std::string _kdm_bcc;
1195         std::string _kdm_email;
1196         std::string _notification_subject;
1197         std::string _notification_from;
1198         std::string _notification_to;
1199         std::vector<std::string> _notification_cc;
1200         std::string _notification_bcc;
1201         std::string _notification_email;
1202         boost::shared_ptr<const dcp::CertificateChain> _signer_chain;
1203 #ifdef DCPOMATIC_VARIANT_SWAROOP
1204         boost::filesystem::path _signer_chain_path;
1205 #endif
1206         /** Chain used to decrypt KDMs; the leaf of this chain is the target
1207          *  certificate for making KDMs given to DCP-o-matic.
1208          */
1209         boost::shared_ptr<const dcp::CertificateChain> _decryption_chain;
1210 #ifdef DCPOMATIC_VARIANT_SWAROOP
1211         boost::filesystem::path _decryption_chain_path;
1212 #endif
1213         /** true to check for updates on startup */
1214         bool _check_for_updates;
1215         bool _check_for_test_updates;
1216         /** maximum allowed J2K bandwidth in bits per second */
1217         int _maximum_j2k_bandwidth;
1218         int _log_types;
1219         bool _analyse_ebur128;
1220         bool _automatic_audio_analysis;
1221 #ifdef DCPOMATIC_WINDOWS
1222         bool _win32_console;
1223 #endif
1224         std::vector<boost::filesystem::path> _history;
1225         std::vector<boost::filesystem::path> _player_history;
1226         boost::shared_ptr<DKDMGroup> _dkdms;
1227         boost::filesystem::path _cinemas_file;
1228         bool _show_hints_before_make_dcp;
1229         bool _confirm_kdm_email;
1230         dcp::NameFormat _kdm_filename_format;
1231         dcp::NameFormat _kdm_container_name_format;
1232         dcp::NameFormat _dcp_metadata_filename_format;
1233         dcp::NameFormat _dcp_asset_filename_format;
1234         bool _jump_to_selected;
1235         bool _nagged[NAG_COUNT];
1236         bool _sound;
1237         /** name of a specific sound output stream to use, or empty to use the default */
1238         boost::optional<std::string> _sound_output;
1239         std::string _cover_sheet;
1240         boost::optional<boost::filesystem::path> _last_player_load_directory;
1241         boost::optional<KDMWriteType> _last_kdm_write_type;
1242         boost::optional<DKDMWriteType> _last_dkdm_write_type;
1243         int _frames_in_memory_multiplier;
1244         boost::optional<int> _decode_reduction;
1245         bool _default_notify;
1246         bool _notification[NOTIFICATION_COUNT];
1247         boost::optional<std::string> _barco_username;
1248         boost::optional<std::string> _barco_password;
1249         boost::optional<std::string> _christie_username;
1250         boost::optional<std::string> _christie_password;
1251         boost::optional<std::string> _gdc_username;
1252         boost::optional<std::string> _gdc_password;
1253         Interface _interface_complexity;
1254         PlayerMode _player_mode;
1255         int _image_display;
1256         bool _respect_kdm_validity_periods;
1257         /** Log file containing things the player does (e.g. started, stopped, loaded
1258             playlist etc.)  Does not contain debugging information.
1259         */
1260         boost::optional<boost::filesystem::path> _player_activity_log_file;
1261         /** Log file containing debug information for the player */
1262         boost::optional<boost::filesystem::path> _player_debug_log_file;
1263         /** A directory containing DCPs whose contents are presented to the user
1264             in the dual-screen player mode.  DCPs on the list can be loaded
1265             for playback.
1266         */
1267         boost::optional<boost::filesystem::path> _player_content_directory;
1268         boost::optional<boost::filesystem::path> _player_playlist_directory;
1269         boost::optional<boost::filesystem::path> _player_kdm_directory;
1270 #ifdef DCPOMATIC_VARIANT_SWAROOP
1271         boost::optional<boost::filesystem::path> _player_background_image;
1272         std::string _kdm_server_url;
1273         std::string _player_watermark_theatre;
1274         /** watermark period in minutes */
1275         int _player_watermark_period;
1276         /** watermark duration in milliseconds */
1277         int _player_watermark_duration;
1278         std::vector<Monitor> _required_monitors;
1279         /** a file which, if specified, must be present for the player to work */
1280         boost::optional<boost::filesystem::path> _player_lock_file;
1281 #endif
1282
1283         static int const _current_version;
1284
1285         /** Singleton instance, or 0 */
1286         static Config* _instance;
1287 };
1288
1289 #endif