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