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