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