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