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