Finish off background image support for swaroop variant.
[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 #endif
501
502         /* SET (mostly) */
503
504         void set_master_encoding_threads (int n) {
505                 maybe_set (_master_encoding_threads, n);
506         }
507
508         void set_server_encoding_threads (int n) {
509                 maybe_set (_server_encoding_threads, n);
510         }
511
512         void set_default_directory (boost::filesystem::path d) {
513                 if (_default_directory && *_default_directory == d) {
514                         return;
515                 }
516                 _default_directory = d;
517                 changed ();
518         }
519
520         /** @param p New server port */
521         void set_server_port_base (int p) {
522                 maybe_set (_server_port_base, p);
523         }
524
525         void set_only_servers_encode (bool o) {
526                 maybe_set (_only_servers_encode, o);
527         }
528
529         void set_tms_protocol (Protocol p) {
530                 maybe_set (_tms_protocol, p);
531         }
532
533         /** @param i IP address of a TMS that we can copy DCPs to */
534         void set_tms_ip (std::string i) {
535                 maybe_set (_tms_ip, i);
536         }
537
538         /** @param p Path on a TMS that we should changed DCPs to */
539         void set_tms_path (std::string p) {
540                 maybe_set (_tms_path, p);
541         }
542
543         /** @param u User name to log into the TMS with */
544         void set_tms_user (std::string u) {
545                 maybe_set (_tms_user, u);
546         }
547
548         /** @param p Password to log into the TMS with */
549         void set_tms_password (std::string p) {
550                 maybe_set (_tms_password, p);
551         }
552
553         void add_cinema (boost::shared_ptr<Cinema> c) {
554                 _cinemas.push_back (c);
555                 changed (CINEMAS);
556         }
557
558         void remove_cinema (boost::shared_ptr<Cinema> c) {
559                 _cinemas.remove (c);
560                 changed (CINEMAS);
561         }
562
563         void set_allowed_dcp_frame_rates (std::list<int> const & r) {
564                 maybe_set (_allowed_dcp_frame_rates, r);
565         }
566
567         void set_allow_any_dcp_frame_rate (bool a) {
568                 maybe_set (_allow_any_dcp_frame_rate, a);
569         }
570
571         void set_allow_any_container (bool a) {
572                 maybe_set (_allow_any_container, a);
573         }
574
575         void set_default_isdcf_metadata (ISDCFMetadata d) {
576                 maybe_set (_default_isdcf_metadata, d);
577         }
578
579         void set_language (std::string l) {
580                 if (_language && _language.get() == l) {
581                         return;
582                 }
583                 _language = l;
584                 changed ();
585         }
586
587         void unset_language () {
588                 if (!_language) {
589                         return;
590                 }
591
592                 _language = boost::none;
593                 changed ();
594         }
595
596         void set_default_still_length (int s) {
597                 maybe_set (_default_still_length, s);
598         }
599
600         void set_default_container (Ratio const * c) {
601                 maybe_set (_default_container, c);
602         }
603
604         void set_default_scale_to (Ratio const * c) {
605                 maybe_set (_default_scale_to, c);
606         }
607
608         void set_default_dcp_content_type (DCPContentType const * t) {
609                 maybe_set (_default_dcp_content_type, t);
610         }
611
612         void set_default_dcp_audio_channels (int c) {
613                 maybe_set (_default_dcp_audio_channels, c);
614         }
615
616         void set_dcp_issuer (std::string i) {
617                 maybe_set (_dcp_issuer, i);
618         }
619
620         void set_dcp_creator (std::string c) {
621                 maybe_set (_dcp_creator, c);
622         }
623
624         void set_default_j2k_bandwidth (int b) {
625                 maybe_set (_default_j2k_bandwidth, b);
626         }
627
628         void set_default_audio_delay (int d) {
629                 maybe_set (_default_audio_delay, d);
630         }
631
632         void set_default_interop (bool i) {
633                 maybe_set (_default_interop, i);
634         }
635
636         void set_default_upload_after_make_dcp (bool u) {
637                 maybe_set (_default_upload_after_make_dcp, u);
638         }
639
640         void set_mail_server (std::string s) {
641                 maybe_set (_mail_server, s);
642         }
643
644         void set_mail_port (int p) {
645                 maybe_set (_mail_port, p);
646         }
647
648         void set_mail_user (std::string u) {
649                 maybe_set (_mail_user, u);
650         }
651
652         void set_mail_password (std::string p) {
653                 maybe_set (_mail_password, p);
654         }
655
656         void set_kdm_subject (std::string s) {
657                 maybe_set (_kdm_subject, s);
658         }
659
660         void set_kdm_from (std::string f) {
661                 maybe_set (_kdm_from, f);
662         }
663
664         void set_kdm_cc (std::vector<std::string> f) {
665                 maybe_set (_kdm_cc, f);
666         }
667
668         void set_kdm_bcc (std::string f) {
669                 maybe_set (_kdm_bcc, f);
670         }
671
672         void set_kdm_email (std::string e) {
673                 maybe_set (_kdm_email, e);
674         }
675
676         void reset_kdm_email ();
677
678         void set_notification_subject (std::string s) {
679                 maybe_set (_notification_subject, s);
680         }
681
682         void set_notification_from (std::string f) {
683                 maybe_set (_notification_from, f);
684         }
685
686         void set_notification_to (std::string t) {
687                 maybe_set (_notification_to, t);
688         }
689
690         void set_notification_cc (std::vector<std::string> f) {
691                 maybe_set (_notification_cc, f);
692         }
693
694         void set_notification_bcc (std::string f) {
695                 maybe_set (_notification_bcc, f);
696         }
697
698         void set_notification_email (std::string e) {
699                 maybe_set (_notification_email, e);
700         }
701
702         void reset_notification_email ();
703
704         void set_signer_chain (boost::shared_ptr<const dcp::CertificateChain> s) {
705                 maybe_set (_signer_chain, s);
706         }
707
708         void set_decryption_chain (boost::shared_ptr<const dcp::CertificateChain> c) {
709                 maybe_set (_decryption_chain, c);
710         }
711
712         void set_check_for_updates (bool c) {
713                 maybe_set (_check_for_updates, c);
714                 if (!c) {
715                         set_check_for_test_updates (false);
716                 }
717         }
718
719         void set_check_for_test_updates (bool c) {
720                 maybe_set (_check_for_test_updates, c);
721         }
722
723         void set_maximum_j2k_bandwidth (int b) {
724                 maybe_set (_maximum_j2k_bandwidth, b);
725         }
726
727         void set_log_types (int t) {
728                 maybe_set (_log_types, t);
729         }
730
731         void set_analyse_ebur128 (bool a) {
732                 maybe_set (_analyse_ebur128, a);
733         }
734
735         void set_automatic_audio_analysis (bool a) {
736                 maybe_set (_automatic_audio_analysis, a);
737         }
738
739 #ifdef DCPOMATIC_WINDOWS
740         void set_win32_console (bool c) {
741                 maybe_set (_win32_console, c);
742         }
743 #endif
744
745         void set_dkdms (boost::shared_ptr<DKDMGroup> dkdms) {
746                 _dkdms = dkdms;
747                 changed ();
748         }
749
750         void set_cinemas_file (boost::filesystem::path file);
751
752         void set_show_hints_before_make_dcp (bool s) {
753                 maybe_set (_show_hints_before_make_dcp, s);
754         }
755
756         void set_confirm_kdm_email (bool s) {
757                 maybe_set (_confirm_kdm_email, s);
758         }
759
760         void set_sound (bool s) {
761                 maybe_set (_sound, s, SOUND);
762         }
763
764         void set_sound_output (std::string o) {
765                 maybe_set (_sound_output, o, SOUND_OUTPUT);
766         }
767
768         void set_last_player_load_directory (boost::filesystem::path d) {
769                 maybe_set (_last_player_load_directory, d);
770         }
771
772         void set_last_kdm_write_type (KDMWriteType t) {
773                 maybe_set (_last_kdm_write_type, t);
774         }
775
776         void set_last_dkdm_write_type (DKDMWriteType t) {
777                 maybe_set (_last_dkdm_write_type, t);
778         }
779
780         void unset_sound_output () {
781                 if (!_sound_output) {
782                         return;
783                 }
784
785                 _sound_output = boost::none;
786                 changed ();
787         }
788
789         void set_kdm_container_name_format (dcp::NameFormat n) {
790                 maybe_set (_kdm_container_name_format, n);
791         }
792
793         void set_kdm_filename_format (dcp::NameFormat n) {
794                 maybe_set (_kdm_filename_format, n);
795         }
796
797         void set_dcp_metadata_filename_format (dcp::NameFormat n) {
798                 maybe_set (_dcp_metadata_filename_format, n);
799         }
800
801         void set_dcp_asset_filename_format (dcp::NameFormat n) {
802                 maybe_set (_dcp_asset_filename_format, n);
803         }
804
805         void set_frames_in_memory_multiplier (int m) {
806                 maybe_set (_frames_in_memory_multiplier, m);
807         }
808
809         void set_decode_reduction (boost::optional<int> r) {
810                 maybe_set (_decode_reduction, r);
811         }
812
813         void set_default_notify (bool n) {
814                 maybe_set (_default_notify, n);
815         }
816
817         void clear_history () {
818                 _history.clear ();
819                 changed ();
820         }
821
822         void clear_player_history () {
823                 _player_history.clear ();
824                 changed ();
825         }
826
827         void add_to_history (boost::filesystem::path p);
828         void add_to_player_history (boost::filesystem::path p);
829
830         void set_jump_to_selected (bool j) {
831                 maybe_set (_jump_to_selected, j);
832         }
833
834         void set_nagged (Nag nag, bool nagged) {
835                 maybe_set (_nagged[nag], nagged);
836         }
837
838         void set_cover_sheet (std::string s) {
839                 maybe_set (_cover_sheet, s);
840         }
841
842         void reset_cover_sheet ();
843
844         void set_notification (Notification n, bool v) {
845                 maybe_set (_notification[n], v);
846         }
847
848         void set_barco_username (std::string u) {
849                 maybe_set (_barco_username, u);
850         }
851
852         void unset_barco_username () {
853                 maybe_set (_barco_username, boost::optional<std::string>());
854         }
855
856         void set_barco_password (std::string p) {
857                 maybe_set (_barco_password, p);
858         }
859
860         void unset_barco_password () {
861                 maybe_set (_barco_password, boost::optional<std::string>());
862         }
863
864         void set_christie_username (std::string u) {
865                 maybe_set (_christie_username, u);
866         }
867
868         void unset_christie_username () {
869                 maybe_set (_christie_username, boost::optional<std::string>());
870         }
871
872         void set_christie_password (std::string p) {
873                 maybe_set (_christie_password, p);
874         }
875
876         void unset_christie_password () {
877                 maybe_set (_christie_password, boost::optional<std::string>());
878         }
879
880         void set_gdc_username (std::string u) {
881                 maybe_set (_gdc_username, u);
882         }
883
884         void unset_gdc_username () {
885                 maybe_set (_gdc_username, boost::optional<std::string>());
886         }
887
888         void set_gdc_password (std::string p) {
889                 maybe_set (_gdc_password, p);
890         }
891
892         void unset_gdc_password () {
893                 maybe_set (_gdc_password, boost::optional<std::string>());
894         }
895
896         void set_interface_complexity (Interface i) {
897                 maybe_set (_interface_complexity, i, INTERFACE_COMPLEXITY);
898         }
899
900         void set_player_mode (PlayerMode m) {
901                 maybe_set (_player_mode, m);
902         }
903
904         void set_image_display (int n) {
905                 maybe_set (_image_display, n);
906         }
907
908         void set_respect_kdm_validity_periods (bool r) {
909                 maybe_set (_respect_kdm_validity_periods, r);
910         }
911
912         void set_player_log_file (boost::filesystem::path p) {
913                 maybe_set (_player_log_file, p);
914         }
915
916         void unset_player_log_file () {
917                 if (!_player_log_file) {
918                         return;
919                 }
920                 _player_log_file = boost::none;
921                 changed ();
922         }
923
924         void set_player_dcp_directory (boost::filesystem::path p) {
925                 maybe_set (_player_dcp_directory, p, PLAYER_DCP_DIRECTORY);
926         }
927
928         void unset_player_dcp_directory () {
929                 if (!_player_dcp_directory) {
930                         return;
931                 }
932                 _player_dcp_directory = boost::none;
933                 changed (PLAYER_DCP_DIRECTORY);
934         }
935
936         void set_player_kdm_directory (boost::filesystem::path p) {
937                 maybe_set (_player_kdm_directory, p);
938         }
939
940         void unset_player_kdm_directory () {
941                 if (!_player_kdm_directory) {
942                         return;
943                 }
944                 _player_kdm_directory = boost::none;
945                 changed ();
946         }
947
948 #ifdef DCPOMATIC_VARIANT_SWAROOP
949         void set_player_background_image (boost::filesystem::path p) {
950                 maybe_set (_player_background_image, p, PLAYER_BACKGROUND_IMAGE);
951         }
952
953         void unset_player_background_image () {
954                 if (!_player_background_image) {
955                         return;
956                 }
957                 _player_background_image = boost::none;
958                 changed (PLAYER_BACKGROUND_IMAGE);
959         }
960 #endif
961
962         void changed (Property p = OTHER);
963         boost::signals2::signal<void (Property)> Changed;
964         /** Emitted if read() failed on an existing Config file.  There is nothing
965             a listener can do about it: this is just for information.
966         */
967         static boost::signals2::signal<void ()> FailedToLoad;
968         /** Emitted if read() issued a warning which the user might want to know about */
969         static boost::signals2::signal<void (std::string)> Warning;
970         /** Emitted if there is a bad certificate in the signer chain.  Handler can call
971          *  true to ask Config to re-create the chain.
972          */
973         static boost::signals2::signal<bool (void)> BadSignerChain;
974
975         void write () const;
976         void write_config () const;
977         void write_cinemas () const;
978         void link (boost::filesystem::path new_file) const;
979         void copy_and_link (boost::filesystem::path new_file) const;
980
981         void save_template (boost::shared_ptr<const Film> film, std::string name) const;
982         bool existing_template (std::string name) const;
983         std::list<std::string> templates () const;
984         boost::filesystem::path template_path (std::string name) const;
985         void rename_template (std::string old_name, std::string new_name) const;
986         void delete_template (std::string name) const;
987
988         static Config* instance ();
989         static void drop ();
990         static void restore_defaults ();
991         static bool have_existing (std::string);
992         static boost::filesystem::path config_file ();
993
994         /** If set, this overrides the standard path (in home, Library, AppData or wherever) for config.xml and cinemas.xml */
995         static boost::optional<boost::filesystem::path> override_path;
996
997 private:
998         Config ();
999         static boost::filesystem::path path (std::string file, bool create_directories = true);
1000         void read ();
1001         void set_defaults ();
1002         void set_kdm_email_to_default ();
1003         void set_notification_email_to_default ();
1004         void set_cover_sheet_to_default ();
1005         void read_cinemas (cxml::Document const & f);
1006         boost::shared_ptr<dcp::CertificateChain> create_certificate_chain ();
1007         boost::filesystem::path directory_or (boost::optional<boost::filesystem::path> dir, boost::filesystem::path a) const;
1008         void add_to_history_internal (std::vector<boost::filesystem::path>& h, boost::filesystem::path p);
1009         void backup ();
1010
1011         template <class T>
1012         void maybe_set (T& member, T new_value, Property prop = OTHER) {
1013                 if (member == new_value) {
1014                         return;
1015                 }
1016                 member = new_value;
1017                 changed (prop);
1018         }
1019
1020         template <class T>
1021         void maybe_set (boost::optional<T>& member, T new_value, Property prop = OTHER) {
1022                 if (member && member.get() == new_value) {
1023                         return;
1024                 }
1025                 member = new_value;
1026                 changed (prop);
1027         }
1028
1029         /** number of threads which a master DoM should use for J2K encoding on the local machine */
1030         int _master_encoding_threads;
1031         /** number of threads which a server should use for J2K encoding on the local machine */
1032         int _server_encoding_threads;
1033         /** default directory to put new films in */
1034         boost::optional<boost::filesystem::path> _default_directory;
1035         /** base port number to use for J2K encoding servers;
1036          *  this port and the two above it will be used.
1037          */
1038         int _server_port_base;
1039         /** true to broadcast on the `any' address to look for servers */
1040         bool _use_any_servers;
1041         /** J2K encoding servers that should definitely be used */
1042         std::vector<std::string> _servers;
1043         bool _only_servers_encode;
1044         Protocol _tms_protocol;
1045         /** The IP address of a TMS that we can copy DCPs to */
1046         std::string _tms_ip;
1047         /** The path on a TMS that we should write DCPs to */
1048         std::string _tms_path;
1049         /** User name to log into the TMS with */
1050         std::string _tms_user;
1051         /** Password to log into the TMS with */
1052         std::string _tms_password;
1053         /** Our cinema sound processor */
1054         CinemaSoundProcessor const * _cinema_sound_processor;
1055         std::list<int> _allowed_dcp_frame_rates;
1056         /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
1057         bool _allow_any_dcp_frame_rate;
1058         /** Allow any container ratio, not just the standard ones.  GDC SX-2001 will not play Flat
1059             DCPs at 25fps but will play 16:9, so this is very useful for some users.
1060             https://www.dcpomatic.com/forum/viewtopic.php?f=2&t=1119&p=4468
1061         */
1062         bool _allow_any_container;
1063         /** Default ISDCF metadata for newly-created Films */
1064         ISDCFMetadata _default_isdcf_metadata;
1065         boost::optional<std::string> _language;
1066         /** Default length of still image content (seconds) */
1067         int _default_still_length;
1068         Ratio const * _default_container;
1069         Ratio const * _default_scale_to;
1070         DCPContentType const * _default_dcp_content_type;
1071         int _default_dcp_audio_channels;
1072         std::string _dcp_issuer;
1073         std::string _dcp_creator;
1074         int _default_j2k_bandwidth;
1075         int _default_audio_delay;
1076         bool _default_interop;
1077         /** Default directory to offer to write KDMs to; if it's not set,
1078             the home directory will be offered.
1079         */
1080         boost::optional<boost::filesystem::path> _default_kdm_directory;
1081         bool _default_upload_after_make_dcp;
1082         std::list<boost::shared_ptr<Cinema> > _cinemas;
1083         std::string _mail_server;
1084         int _mail_port;
1085         std::string _mail_user;
1086         std::string _mail_password;
1087         std::string _kdm_subject;
1088         std::string _kdm_from;
1089         std::vector<std::string> _kdm_cc;
1090         std::string _kdm_bcc;
1091         std::string _kdm_email;
1092         std::string _notification_subject;
1093         std::string _notification_from;
1094         std::string _notification_to;
1095         std::vector<std::string> _notification_cc;
1096         std::string _notification_bcc;
1097         std::string _notification_email;
1098         boost::shared_ptr<const dcp::CertificateChain> _signer_chain;
1099         /** Chain used to decrypt KDMs; the leaf of this chain is the target
1100          *  certificate for making KDMs given to DCP-o-matic.
1101          */
1102         boost::shared_ptr<const dcp::CertificateChain> _decryption_chain;
1103         /** true to check for updates on startup */
1104         bool _check_for_updates;
1105         bool _check_for_test_updates;
1106         /** maximum allowed J2K bandwidth in bits per second */
1107         int _maximum_j2k_bandwidth;
1108         int _log_types;
1109         bool _analyse_ebur128;
1110         bool _automatic_audio_analysis;
1111 #ifdef DCPOMATIC_WINDOWS
1112         bool _win32_console;
1113 #endif
1114         std::vector<boost::filesystem::path> _history;
1115         std::vector<boost::filesystem::path> _player_history;
1116         boost::shared_ptr<DKDMGroup> _dkdms;
1117         boost::filesystem::path _cinemas_file;
1118         bool _show_hints_before_make_dcp;
1119         bool _confirm_kdm_email;
1120         dcp::NameFormat _kdm_filename_format;
1121         dcp::NameFormat _kdm_container_name_format;
1122         dcp::NameFormat _dcp_metadata_filename_format;
1123         dcp::NameFormat _dcp_asset_filename_format;
1124         bool _jump_to_selected;
1125         bool _nagged[NAG_COUNT];
1126         bool _sound;
1127         /** name of a specific sound output stream to use, or empty to use the default */
1128         boost::optional<std::string> _sound_output;
1129         std::string _cover_sheet;
1130         boost::optional<boost::filesystem::path> _last_player_load_directory;
1131         boost::optional<KDMWriteType> _last_kdm_write_type;
1132         boost::optional<DKDMWriteType> _last_dkdm_write_type;
1133         int _frames_in_memory_multiplier;
1134         boost::optional<int> _decode_reduction;
1135         bool _default_notify;
1136         bool _notification[NOTIFICATION_COUNT];
1137         boost::optional<std::string> _barco_username;
1138         boost::optional<std::string> _barco_password;
1139         boost::optional<std::string> _christie_username;
1140         boost::optional<std::string> _christie_password;
1141         boost::optional<std::string> _gdc_username;
1142         boost::optional<std::string> _gdc_password;
1143         Interface _interface_complexity;
1144         PlayerMode _player_mode;
1145         int _image_display;
1146         bool _respect_kdm_validity_periods;
1147         boost::optional<boost::filesystem::path> _player_log_file;
1148         /** A directory containing DCPs whose contents are presented to the user
1149             in the dual-screen player mode.  DCPs on the list can be loaded
1150             for playback.
1151         */
1152         boost::optional<boost::filesystem::path> _player_dcp_directory;
1153         boost::optional<boost::filesystem::path> _player_kdm_directory;
1154 #ifdef DCPOMATIC_VARIANT_SWAROOP
1155         boost::optional<boost::filesystem::path> _player_background_image;
1156 #endif
1157
1158         static int const _current_version;
1159
1160         /** Singleton instance, or 0 */
1161         static Config* _instance;
1162 };
1163
1164 #endif