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