2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/config.h
21 * @brief Class holding configuration.
24 #ifndef DCPOMATIC_CONFIG_H
25 #define DCPOMATIC_CONFIG_H
27 #include "isdcf_metadata.h"
28 #include "colour_conversion.h"
29 #include "video_content.h"
30 #include <dcp/metadata.h>
31 #include <dcp/certificates.h>
32 #include <dcp/signer.h>
33 #include <boost/shared_ptr.hpp>
34 #include <boost/signals2.hpp>
35 #include <boost/filesystem.hpp>
38 class ServerDescription;
41 class CinemaSoundProcessor;
47 * @brief A singleton class holding configuration.
49 class Config : public boost::noncopyable
52 /** @return number of threads to use for J2K encoding on the local machine */
53 int num_local_encoding_threads () const {
54 return _num_local_encoding_threads;
57 boost::filesystem::path default_directory () const {
58 return _default_directory;
61 boost::filesystem::path default_directory_or (boost::filesystem::path a) const;
63 /** @return base port number to use for J2K encoding servers */
64 int server_port_base () const {
65 return _server_port_base;
68 void set_use_any_servers (bool u) {
73 bool use_any_servers () const {
74 return _use_any_servers;
77 /** @param s New list of servers */
78 void set_servers (std::vector<std::string> s) {
83 /** @return Host names / IP addresses of J2K encoding servers that should definitely be used */
84 std::vector<std::string> servers () const {
88 /** @return The IP address of a TMS that we can copy DCPs to */
89 std::string tms_ip () const {
93 /** @return The path on a TMS that we should changed DCPs to */
94 std::string tms_path () const {
98 /** @return User name to log into the TMS with */
99 std::string tms_user () const {
103 /** @return Password to log into the TMS with */
104 std::string tms_password () const {
105 return _tms_password;
108 /** @return The cinema sound processor that we are using */
109 CinemaSoundProcessor const * cinema_sound_processor () const {
110 return _cinema_sound_processor;
113 std::list<boost::shared_ptr<Cinema> > cinemas () const {
117 std::list<int> allowed_dcp_frame_rates () const {
118 return _allowed_dcp_frame_rates;
121 bool allow_any_dcp_frame_rate () const {
122 return _allow_any_dcp_frame_rate;
125 ISDCFMetadata default_isdcf_metadata () const {
126 return _default_isdcf_metadata;
129 boost::optional<std::string> language () const {
133 int default_still_length () const {
134 return _default_still_length;
137 Ratio const * default_container () const {
138 return _default_container;
141 DCPContentType const * default_dcp_content_type () const {
142 return _default_dcp_content_type;
145 std::string dcp_issuer () const {
149 int default_j2k_bandwidth () const {
150 return _default_j2k_bandwidth;
153 int default_audio_delay () const {
154 return _default_audio_delay;
157 std::vector<PresetColourConversion> colour_conversions () const {
158 return _colour_conversions;
161 std::string mail_server () const {
165 std::string mail_user () const {
169 std::string mail_password () const {
170 return _mail_password;
173 std::string kdm_subject () const {
177 std::string kdm_from () const {
181 std::string kdm_cc () const {
185 std::string kdm_bcc () const {
189 std::string kdm_email () const {
193 boost::shared_ptr<const dcp::Signer> signer () const {
197 dcp::Certificate decryption_certificate () const {
198 return _decryption_certificate;
201 std::string decryption_private_key () const {
202 return _decryption_private_key;
205 bool check_for_updates () const {
206 return _check_for_updates;
209 bool check_for_test_updates () const {
210 return _check_for_test_updates;
213 int maximum_j2k_bandwidth () const {
214 return _maximum_j2k_bandwidth;
217 int log_types () const {
221 #ifdef DCPOMATIC_WINDOWS
222 bool win32_console () const {
223 return _win32_console;
227 std::vector<boost::filesystem::path> history () const {
231 /** @param n New number of local encoding threads */
232 void set_num_local_encoding_threads (int n) {
233 maybe_set (_num_local_encoding_threads, n);
236 void set_default_directory (boost::filesystem::path d) {
237 maybe_set (_default_directory, d);
240 /** @param p New server port */
241 void set_server_port_base (int p) {
242 maybe_set (_server_port_base, p);
245 /** @param i IP address of a TMS that we can copy DCPs to */
246 void set_tms_ip (std::string i) {
247 maybe_set (_tms_ip, i);
250 /** @param p Path on a TMS that we should changed DCPs to */
251 void set_tms_path (std::string p) {
252 maybe_set (_tms_path, p);
255 /** @param u User name to log into the TMS with */
256 void set_tms_user (std::string u) {
257 maybe_set (_tms_user, u);
260 /** @param p Password to log into the TMS with */
261 void set_tms_password (std::string p) {
262 maybe_set (_tms_password, p);
265 void add_cinema (boost::shared_ptr<Cinema> c) {
266 _cinemas.push_back (c);
270 void remove_cinema (boost::shared_ptr<Cinema> c) {
275 void set_allowed_dcp_frame_rates (std::list<int> const & r) {
276 maybe_set (_allowed_dcp_frame_rates, r);
279 void set_allow_any_dcp_frame_rate (bool a) {
280 maybe_set (_allow_any_dcp_frame_rate, a);
283 void set_default_isdcf_metadata (ISDCFMetadata d) {
284 maybe_set (_default_isdcf_metadata, d);
287 void set_language (std::string l) {
288 if (_language && _language.get() == l) {
295 void unset_language () {
300 _language = boost::none;
304 void set_default_still_length (int s) {
305 maybe_set (_default_still_length, s);
308 void set_default_container (Ratio const * c) {
309 maybe_set (_default_container, c);
312 void set_default_dcp_content_type (DCPContentType const * t) {
313 maybe_set (_default_dcp_content_type, t);
316 void set_dcp_issuer (std::string i) {
317 maybe_set (_dcp_issuer, i);
320 void set_default_j2k_bandwidth (int b) {
321 maybe_set (_default_j2k_bandwidth, b);
324 void set_default_audio_delay (int d) {
325 maybe_set (_default_audio_delay, d);
328 void set_colour_conversions (std::vector<PresetColourConversion> const & c) {
329 maybe_set (_colour_conversions, c);
332 void set_mail_server (std::string s) {
333 maybe_set (_mail_server, s);
336 void set_mail_user (std::string u) {
337 maybe_set (_mail_user, u);
340 void set_mail_password (std::string p) {
341 maybe_set (_mail_password, p);
344 void set_kdm_subject (std::string s) {
345 maybe_set (_kdm_subject, s);
348 void set_kdm_from (std::string f) {
349 maybe_set (_kdm_from, f);
352 void set_kdm_cc (std::string f) {
353 maybe_set (_kdm_cc, f);
356 void set_kdm_bcc (std::string f) {
357 maybe_set (_kdm_bcc, f);
360 void set_kdm_email (std::string e) {
361 maybe_set (_kdm_email, e);
364 void reset_kdm_email ();
366 void set_signer (boost::shared_ptr<const dcp::Signer> s) {
367 maybe_set (_signer, s);
370 void set_decryption_certificate (dcp::Certificate c) {
371 maybe_set (_decryption_certificate, c);
374 void set_decryption_private_key (std::string k) {
375 maybe_set (_decryption_private_key, k);
378 void set_check_for_updates (bool c) {
379 maybe_set (_check_for_updates, c);
382 void set_check_for_test_updates (bool c) {
383 maybe_set (_check_for_test_updates, c);
386 void set_maximum_j2k_bandwidth (int b) {
387 maybe_set (_maximum_j2k_bandwidth, b);
390 void set_log_types (int t) {
391 maybe_set (_log_types, t);
394 #ifdef DCPOMATIC_WINDOWS
395 void set_win32_console (bool c) {
396 maybe_set (_win32_console, c);
400 void clear_history () {
405 void add_to_history (boost::filesystem::path p);
408 boost::signals2::signal<void ()> Changed;
412 static Config* instance ();
414 static void restore_defaults ();
418 boost::filesystem::path file () const;
420 void make_decryption_keys ();
421 void set_defaults ();
422 void set_kdm_email_to_default ();
425 void maybe_set (T& member, T new_value) {
426 if (member == new_value) {
433 /** number of threads to use for J2K encoding on the local machine */
434 int _num_local_encoding_threads;
435 /** default directory to put new films in */
436 boost::filesystem::path _default_directory;
437 /** base port number to use for J2K encoding servers;
438 * this port and the one above it will be used.
440 int _server_port_base;
441 /** true to broadcast on the `any' address to look for servers */
442 bool _use_any_servers;
443 /** J2K encoding servers that should definitely be used */
444 std::vector<std::string> _servers;
445 /** The IP address of a TMS that we can copy DCPs to */
447 /** The path on a TMS that we should write DCPs to */
448 std::string _tms_path;
449 /** User name to log into the TMS with */
450 std::string _tms_user;
451 /** Password to log into the TMS with */
452 std::string _tms_password;
453 /** Our cinema sound processor */
454 CinemaSoundProcessor const * _cinema_sound_processor;
455 std::list<int> _allowed_dcp_frame_rates;
456 /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
457 bool _allow_any_dcp_frame_rate;
458 /** Default ISDCF metadata for newly-created Films */
459 ISDCFMetadata _default_isdcf_metadata;
460 boost::optional<std::string> _language;
461 int _default_still_length;
462 Ratio const * _default_container;
463 DCPContentType const * _default_dcp_content_type;
464 std::string _dcp_issuer;
465 int _default_j2k_bandwidth;
466 int _default_audio_delay;
467 std::vector<PresetColourConversion> _colour_conversions;
468 std::list<boost::shared_ptr<Cinema> > _cinemas;
469 std::string _mail_server;
470 std::string _mail_user;
471 std::string _mail_password;
472 std::string _kdm_subject;
473 std::string _kdm_from;
475 std::string _kdm_bcc;
476 std::string _kdm_email;
477 boost::shared_ptr<const dcp::Signer> _signer;
478 dcp::Certificate _decryption_certificate;
479 std::string _decryption_private_key;
480 /** true to check for updates on startup */
481 bool _check_for_updates;
482 bool _check_for_test_updates;
483 /** maximum allowed J2K bandwidth in bits per second */
484 int _maximum_j2k_bandwidth;
486 #ifdef DCPOMATIC_WINDOWS
489 std::vector<boost::filesystem::path> _history;
491 /** Singleton instance, or 0 */
492 static Config* _instance;