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