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