2 Copyright (C) 2012-2015 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"
29 #include <dcp/certificate_chain.h>
30 #include <boost/shared_ptr.hpp>
31 #include <boost/signals2.hpp>
32 #include <boost/filesystem.hpp>
35 class CinemaSoundProcessor;
41 * @brief A singleton class holding configuration.
43 class Config : public boost::noncopyable
46 /** @return number of threads to use for J2K encoding on the local machine */
47 int num_local_encoding_threads () const {
48 return _num_local_encoding_threads;
51 boost::filesystem::path default_directory () const {
52 return _default_directory;
55 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) {
70 changed (USE_ANY_SERVERS);
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 bool only_servers_encode () const {
89 return _only_servers_encode;
92 Protocol tms_protocol () const {
96 /** @return The IP address of a TMS that we can copy DCPs to */
97 std::string tms_ip () const {
101 /** @return The path on a TMS that we should changed DCPs to */
102 std::string tms_path () const {
106 /** @return User name to log into the TMS with */
107 std::string tms_user () const {
111 /** @return Password to log into the TMS with */
112 std::string tms_password () const {
113 return _tms_password;
116 /** @return The cinema sound processor that we are using */
117 CinemaSoundProcessor const * cinema_sound_processor () const {
118 return _cinema_sound_processor;
121 std::list<boost::shared_ptr<Cinema> > cinemas () const {
125 std::list<int> allowed_dcp_frame_rates () const {
126 return _allowed_dcp_frame_rates;
129 bool allow_any_dcp_frame_rate () const {
130 return _allow_any_dcp_frame_rate;
133 ISDCFMetadata default_isdcf_metadata () const {
134 return _default_isdcf_metadata;
137 boost::optional<std::string> language () const {
141 int default_still_length () const {
142 return _default_still_length;
145 Ratio const * default_container () const {
146 return _default_container;
149 DCPContentType const * default_dcp_content_type () const {
150 return _default_dcp_content_type;
153 std::string dcp_issuer () const {
157 std::string dcp_creator () const {
161 int default_j2k_bandwidth () const {
162 return _default_j2k_bandwidth;
165 int default_audio_delay () const {
166 return _default_audio_delay;
169 std::string mail_server () const {
173 int mail_port () const {
177 std::string mail_user () const {
181 std::string mail_password () const {
182 return _mail_password;
185 std::string kdm_subject () const {
189 std::string kdm_from () const {
193 std::string kdm_cc () const {
197 std::string kdm_bcc () const {
201 std::string kdm_email () const {
205 boost::shared_ptr<const dcp::CertificateChain> signer_chain () const {
206 return _signer_chain;
209 boost::shared_ptr<const dcp::CertificateChain> decryption_chain () const {
210 return _decryption_chain;
213 bool check_for_updates () const {
214 return _check_for_updates;
217 bool check_for_test_updates () const {
218 return _check_for_test_updates;
221 int maximum_j2k_bandwidth () const {
222 return _maximum_j2k_bandwidth;
225 int log_types () const {
229 #ifdef DCPOMATIC_WINDOWS
230 bool win32_console () const {
231 return _win32_console;
235 std::vector<boost::filesystem::path> history () const {
239 /** @param n New number of local encoding threads */
240 void set_num_local_encoding_threads (int n) {
241 maybe_set (_num_local_encoding_threads, n);
244 void set_default_directory (boost::filesystem::path d) {
245 maybe_set (_default_directory, d);
248 /** @param p New server port */
249 void set_server_port_base (int p) {
250 maybe_set (_server_port_base, p);
253 void set_only_servers_encode (bool o) {
254 maybe_set (_only_servers_encode, o);
257 void set_tms_protocol (Protocol p) {
258 maybe_set (_tms_protocol, p);
261 /** @param i IP address of a TMS that we can copy DCPs to */
262 void set_tms_ip (std::string i) {
263 maybe_set (_tms_ip, i);
266 /** @param p Path on a TMS that we should changed DCPs to */
267 void set_tms_path (std::string p) {
268 maybe_set (_tms_path, p);
271 /** @param u User name to log into the TMS with */
272 void set_tms_user (std::string u) {
273 maybe_set (_tms_user, u);
276 /** @param p Password to log into the TMS with */
277 void set_tms_password (std::string p) {
278 maybe_set (_tms_password, p);
281 void add_cinema (boost::shared_ptr<Cinema> c) {
282 _cinemas.push_back (c);
286 void remove_cinema (boost::shared_ptr<Cinema> c) {
291 void set_allowed_dcp_frame_rates (std::list<int> const & r) {
292 maybe_set (_allowed_dcp_frame_rates, r);
295 void set_allow_any_dcp_frame_rate (bool a) {
296 maybe_set (_allow_any_dcp_frame_rate, a);
299 void set_default_isdcf_metadata (ISDCFMetadata d) {
300 maybe_set (_default_isdcf_metadata, d);
303 void set_language (std::string l) {
304 if (_language && _language.get() == l) {
311 void unset_language () {
316 _language = boost::none;
320 void set_default_still_length (int s) {
321 maybe_set (_default_still_length, s);
324 void set_default_container (Ratio const * c) {
325 maybe_set (_default_container, c);
328 void set_default_dcp_content_type (DCPContentType const * t) {
329 maybe_set (_default_dcp_content_type, t);
332 void set_dcp_issuer (std::string i) {
333 maybe_set (_dcp_issuer, i);
336 void set_dcp_creator (std::string c) {
337 maybe_set (_dcp_creator, c);
340 void set_default_j2k_bandwidth (int b) {
341 maybe_set (_default_j2k_bandwidth, b);
344 void set_default_audio_delay (int d) {
345 maybe_set (_default_audio_delay, d);
348 void set_mail_server (std::string s) {
349 maybe_set (_mail_server, s);
352 void set_mail_port (int p) {
353 maybe_set (_mail_port, p);
356 void set_mail_user (std::string u) {
357 maybe_set (_mail_user, u);
360 void set_mail_password (std::string p) {
361 maybe_set (_mail_password, p);
364 void set_kdm_subject (std::string s) {
365 maybe_set (_kdm_subject, s);
368 void set_kdm_from (std::string f) {
369 maybe_set (_kdm_from, f);
372 void set_kdm_cc (std::string f) {
373 maybe_set (_kdm_cc, f);
376 void set_kdm_bcc (std::string f) {
377 maybe_set (_kdm_bcc, f);
380 void set_kdm_email (std::string e) {
381 maybe_set (_kdm_email, e);
384 void reset_kdm_email ();
386 void set_signer_chain (boost::shared_ptr<const dcp::CertificateChain> s) {
387 maybe_set (_signer_chain, s);
390 void set_decryption_chain (boost::shared_ptr<const dcp::CertificateChain> c) {
391 maybe_set (_decryption_chain, c);
394 void set_check_for_updates (bool c) {
395 maybe_set (_check_for_updates, c);
398 void set_check_for_test_updates (bool c) {
399 maybe_set (_check_for_test_updates, c);
402 void set_maximum_j2k_bandwidth (int b) {
403 maybe_set (_maximum_j2k_bandwidth, b);
406 void set_log_types (int t) {
407 maybe_set (_log_types, t);
410 #ifdef DCPOMATIC_WINDOWS
411 void set_win32_console (bool c) {
412 maybe_set (_win32_console, c);
416 void clear_history () {
421 void add_to_history (boost::filesystem::path p);
423 void changed (Property p = OTHER);
424 boost::signals2::signal<void (Property)> Changed;
428 static Config* instance ();
430 static void restore_defaults ();
431 static bool have_existing ();
435 static boost::filesystem::path file (bool create_directories = true);
437 void set_defaults ();
438 void set_kdm_email_to_default ();
441 void maybe_set (T& member, T new_value) {
442 if (member == new_value) {
449 /** number of threads to use for J2K encoding on the local machine */
450 int _num_local_encoding_threads;
451 /** default directory to put new films in */
452 boost::filesystem::path _default_directory;
453 /** base port number to use for J2K encoding servers;
454 * this port and the one above it will be used.
456 int _server_port_base;
457 /** true to broadcast on the `any' address to look for servers */
458 bool _use_any_servers;
459 /** J2K encoding servers that should definitely be used */
460 std::vector<std::string> _servers;
461 bool _only_servers_encode;
462 Protocol _tms_protocol;
463 /** The IP address of a TMS that we can copy DCPs to */
465 /** The path on a TMS that we should write DCPs to */
466 std::string _tms_path;
467 /** User name to log into the TMS with */
468 std::string _tms_user;
469 /** Password to log into the TMS with */
470 std::string _tms_password;
471 /** Our cinema sound processor */
472 CinemaSoundProcessor const * _cinema_sound_processor;
473 std::list<int> _allowed_dcp_frame_rates;
474 /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
475 bool _allow_any_dcp_frame_rate;
476 /** Default ISDCF metadata for newly-created Films */
477 ISDCFMetadata _default_isdcf_metadata;
478 boost::optional<std::string> _language;
479 /** Default length of still image content (seconds) */
480 int _default_still_length;
481 Ratio const * _default_container;
482 DCPContentType const * _default_dcp_content_type;
483 std::string _dcp_issuer;
484 std::string _dcp_creator;
485 int _default_j2k_bandwidth;
486 int _default_audio_delay;
487 std::list<boost::shared_ptr<Cinema> > _cinemas;
488 std::string _mail_server;
490 std::string _mail_user;
491 std::string _mail_password;
492 std::string _kdm_subject;
493 std::string _kdm_from;
495 std::string _kdm_bcc;
496 std::string _kdm_email;
497 boost::shared_ptr<const dcp::CertificateChain> _signer_chain;
498 /** Chain used to decrypt KDMs; the leaf of this chain is the target
499 * certificate for making KDMs given to DCP-o-matic.
501 boost::shared_ptr<const dcp::CertificateChain> _decryption_chain;
502 /** true to check for updates on startup */
503 bool _check_for_updates;
504 bool _check_for_test_updates;
505 /** maximum allowed J2K bandwidth in bits per second */
506 int _maximum_j2k_bandwidth;
508 #ifdef DCPOMATIC_WINDOWS
511 std::vector<boost::filesystem::path> _history;
513 /** Singleton instance, or 0 */
514 static Config* _instance;