00cc8646894f6519d1e2726f3e7a4fbc1e11d8f3 from master; make the config dialog update...
[dcpomatic.git] / src / lib / config.h
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 /** @file src/config.h
21  *  @brief Class holding configuration.
22  */
23
24 #ifndef DCPOMATIC_CONFIG_H
25 #define DCPOMATIC_CONFIG_H
26
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>
36 #include <vector>
37
38 class ServerDescription;
39 class Scaler;
40 class Filter;
41 class CinemaSoundProcessor;
42 class DCPContentType;
43 class Ratio;
44 class Cinema;
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 to use for J2K encoding on the local machine */
53         int num_local_encoding_threads () const {
54                 return _num_local_encoding_threads;
55         }
56
57         boost::filesystem::path default_directory () const {
58                 return _default_directory;
59         }
60
61         boost::filesystem::path default_directory_or (boost::filesystem::path a) const;
62
63         /** @return base port number to use for J2K encoding servers */
64         int server_port_base () const {
65                 return _server_port_base;
66         }
67
68         void set_use_any_servers (bool u) {
69                 _use_any_servers = u;
70                 changed ();
71         }
72
73         bool use_any_servers () const {
74                 return _use_any_servers;
75         }
76
77         /** @param s New list of servers */
78         void set_servers (std::vector<std::string> s) {
79                 _servers = s;
80                 changed ();
81         }
82
83         /** @return Host names / IP addresses of J2K encoding servers that should definitely be used */
84         std::vector<std::string> servers () const {
85                 return _servers;
86         }
87
88         /** @return The IP address of a TMS that we can copy DCPs to */
89         std::string tms_ip () const {
90                 return _tms_ip;
91         }
92         
93         /** @return The path on a TMS that we should changed DCPs to */
94         std::string tms_path () const {
95                 return _tms_path;
96         }
97
98         /** @return User name to log into the TMS with */
99         std::string tms_user () const {
100                 return _tms_user;
101         }
102
103         /** @return Password to log into the TMS with */
104         std::string tms_password () const {
105                 return _tms_password;
106         }
107
108         /** @return The cinema sound processor that we are using */
109         CinemaSoundProcessor const * cinema_sound_processor () const {
110                 return _cinema_sound_processor;
111         }
112
113         std::list<boost::shared_ptr<Cinema> > cinemas () const {
114                 return _cinemas;
115         }
116         
117         std::list<int> allowed_dcp_frame_rates () const {
118                 return _allowed_dcp_frame_rates;
119         }
120
121         bool allow_any_dcp_frame_rate () const {
122                 return _allow_any_dcp_frame_rate;
123         }
124         
125         ISDCFMetadata default_isdcf_metadata () const {
126                 return _default_isdcf_metadata;
127         }
128
129         boost::optional<std::string> language () const {
130                 return _language;
131         }
132
133         int default_still_length () const {
134                 return _default_still_length;
135         }
136
137         Ratio const * default_container () const {
138                 return _default_container;
139         }
140
141         DCPContentType const * default_dcp_content_type () const {
142                 return _default_dcp_content_type;
143         }
144
145         std::string dcp_issuer () const {
146                 return _dcp_issuer;
147         }
148
149         int default_j2k_bandwidth () const {
150                 return _default_j2k_bandwidth;
151         }
152
153         int default_audio_delay () const {
154                 return _default_audio_delay;
155         }
156
157         std::vector<PresetColourConversion> colour_conversions () const {
158                 return _colour_conversions;
159         }
160
161         std::string mail_server () const {
162                 return _mail_server;
163         }
164
165         std::string mail_user () const {
166                 return _mail_user;
167         }
168
169         std::string mail_password () const {
170                 return _mail_password;
171         }
172
173         std::string kdm_subject () const {
174                 return _kdm_subject;
175         }
176
177         std::string kdm_from () const {
178                 return _kdm_from;
179         }
180
181         std::string kdm_cc () const {
182                 return _kdm_cc;
183         }
184
185         std::string kdm_bcc () const {
186                 return _kdm_bcc;
187         }
188         
189         std::string kdm_email () const {
190                 return _kdm_email;
191         }
192
193         boost::shared_ptr<const dcp::Signer> signer () const {
194                 return _signer;
195         }
196
197         dcp::Certificate decryption_certificate () const {
198                 return _decryption_certificate;
199         }
200
201         std::string decryption_private_key () const {
202                 return _decryption_private_key;
203         }
204
205         bool check_for_updates () const {
206                 return _check_for_updates;
207         }
208
209         bool check_for_test_updates () const {
210                 return _check_for_test_updates;
211         }
212
213         int maximum_j2k_bandwidth () const {
214                 return _maximum_j2k_bandwidth;
215         }
216
217         int log_types () const {
218                 return _log_types;
219         }
220
221 #ifdef DCPOMATIC_WINDOWS        
222         bool win32_console () const {
223                 return _win32_console;
224         }
225 #endif  
226
227         std::vector<boost::filesystem::path> history () const {
228                 return _history;
229         }
230
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);
234         }
235
236         void set_default_directory (boost::filesystem::path d) {
237                 maybe_set (_default_directory, d);
238         }
239
240         /** @param p New server port */
241         void set_server_port_base (int p) {
242                 maybe_set (_server_port_base, p);
243         }
244
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);
248         }
249
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);
253         }
254
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);
258         }
259
260         /** @param p Password to log into the TMS with */
261         void set_tms_password (std::string p) {
262                 maybe_set (_tms_password, p);
263         }
264
265         void add_cinema (boost::shared_ptr<Cinema> c) {
266                 _cinemas.push_back (c);
267                 changed ();
268         }
269
270         void remove_cinema (boost::shared_ptr<Cinema> c) {
271                 _cinemas.remove (c);
272                 changed ();
273         }
274
275         void set_allowed_dcp_frame_rates (std::list<int> const & r) {
276                 maybe_set (_allowed_dcp_frame_rates, r);
277         }
278
279         void set_allow_any_dcp_frame_rate (bool a) {
280                 maybe_set (_allow_any_dcp_frame_rate, a);
281         }
282
283         void set_default_isdcf_metadata (ISDCFMetadata d) {
284                 maybe_set (_default_isdcf_metadata, d);
285         }
286
287         void set_language (std::string l) {
288                 if (_language && _language.get() == l) {
289                         return;
290                 }
291                 _language = l;
292                 changed ();
293         }
294
295         void unset_language () {
296                 if (!_language) {
297                         return;
298                 }
299                         
300                 _language = boost::none;
301                 changed ();
302         }
303
304         void set_default_still_length (int s) {
305                 maybe_set (_default_still_length, s);
306         }
307
308         void set_default_container (Ratio const * c) {
309                 maybe_set (_default_container, c);
310         }
311
312         void set_default_dcp_content_type (DCPContentType const * t) {
313                 maybe_set (_default_dcp_content_type, t);
314         }
315
316         void set_dcp_issuer (std::string i) {
317                 maybe_set (_dcp_issuer, i);
318         }
319
320         void set_default_j2k_bandwidth (int b) {
321                 maybe_set (_default_j2k_bandwidth, b);
322         }
323
324         void set_default_audio_delay (int d) {
325                 maybe_set (_default_audio_delay, d);
326         }
327
328         void set_colour_conversions (std::vector<PresetColourConversion> const & c) {
329                 maybe_set (_colour_conversions, c);
330         }
331
332         void set_mail_server (std::string s) {
333                 maybe_set (_mail_server, s);
334         }
335
336         void set_mail_user (std::string u) {
337                 maybe_set (_mail_user, u);
338         }
339
340         void set_mail_password (std::string p) {
341                 maybe_set (_mail_password, p);
342         }
343
344         void set_kdm_subject (std::string s) {
345                 maybe_set (_kdm_subject, s);
346         }
347
348         void set_kdm_from (std::string f) {
349                 maybe_set (_kdm_from, f);
350         }
351
352         void set_kdm_cc (std::string f) {
353                 maybe_set (_kdm_cc, f);
354         }
355
356         void set_kdm_bcc (std::string f) {
357                 maybe_set (_kdm_bcc, f);
358         }
359         
360         void set_kdm_email (std::string e) {
361                 maybe_set (_kdm_email, e);
362         }
363
364         void reset_kdm_email ();
365
366         void set_signer (boost::shared_ptr<const dcp::Signer> s) {
367                 maybe_set (_signer, s);
368         }
369
370         void set_decryption_certificate (dcp::Certificate c) {
371                 maybe_set (_decryption_certificate, c);
372         }
373
374         void set_decryption_private_key (std::string k) {
375                 maybe_set (_decryption_private_key, k);
376         }
377
378         void set_check_for_updates (bool c) {
379                 maybe_set (_check_for_updates, c);
380         }
381
382         void set_check_for_test_updates (bool c) {
383                 maybe_set (_check_for_test_updates, c);
384         }
385
386         void set_maximum_j2k_bandwidth (int b) {
387                 maybe_set (_maximum_j2k_bandwidth, b);
388         }
389
390         void set_log_types (int t) {
391                 maybe_set (_log_types, t);
392         }
393
394 #ifdef DCPOMATIC_WINDOWS        
395         void set_win32_console (bool c) {
396                 maybe_set (_win32_console, c);
397         }
398 #endif  
399
400         void clear_history () {
401                 _history.clear ();
402                 changed ();
403         }
404
405         void add_to_history (boost::filesystem::path p);
406         
407         void changed ();
408         boost::signals2::signal<void ()> Changed;
409
410         static Config* instance ();
411         static void drop ();
412         static void restore_defaults ();
413
414 private:
415         Config ();
416         boost::filesystem::path file () const;
417         void read ();
418         void write () const;
419         void make_decryption_keys ();
420         void set_defaults ();
421         void set_kdm_email_to_default ();
422
423         template <class T>
424         void maybe_set (T& member, T new_value) {
425                 if (member == new_value) {
426                         return;
427                 }
428                 member = new_value;
429                 changed ();
430         }
431
432         /** number of threads to use for J2K encoding on the local machine */
433         int _num_local_encoding_threads;
434         /** default directory to put new films in */
435         boost::filesystem::path _default_directory;
436         /** base port number to use for J2K encoding servers;
437          *  this port and the one above it will be used.
438          */
439         int _server_port_base;
440         /** true to broadcast on the `any' address to look for servers */
441         bool _use_any_servers;
442         /** J2K encoding servers that should definitely be used */
443         std::vector<std::string> _servers;
444         /** The IP address of a TMS that we can copy DCPs to */
445         std::string _tms_ip;
446         /** The path on a TMS that we should write DCPs to */
447         std::string _tms_path;
448         /** User name to log into the TMS with */
449         std::string _tms_user;
450         /** Password to log into the TMS with */
451         std::string _tms_password;
452         /** Our cinema sound processor */
453         CinemaSoundProcessor const * _cinema_sound_processor;
454         std::list<int> _allowed_dcp_frame_rates;
455         /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
456         bool _allow_any_dcp_frame_rate;
457         /** Default ISDCF metadata for newly-created Films */
458         ISDCFMetadata _default_isdcf_metadata;
459         boost::optional<std::string> _language;
460         int _default_still_length;
461         Ratio const * _default_container;
462         DCPContentType const * _default_dcp_content_type;
463         std::string _dcp_issuer;
464         int _default_j2k_bandwidth;
465         int _default_audio_delay;
466         std::vector<PresetColourConversion> _colour_conversions;
467         std::list<boost::shared_ptr<Cinema> > _cinemas;
468         std::string _mail_server;
469         std::string _mail_user;
470         std::string _mail_password;
471         std::string _kdm_subject;
472         std::string _kdm_from;
473         std::string _kdm_cc;
474         std::string _kdm_bcc;
475         std::string _kdm_email;
476         boost::shared_ptr<const dcp::Signer> _signer;
477         dcp::Certificate _decryption_certificate;
478         std::string _decryption_private_key;
479         /** true to check for updates on startup */
480         bool _check_for_updates;
481         bool _check_for_test_updates;
482         /** maximum allowed J2K bandwidth in bits per second */
483         int _maximum_j2k_bandwidth;
484         int _log_types;
485 #ifdef DCPOMATIC_WINDOWS        
486         bool _win32_console;
487 #endif  
488         std::vector<boost::filesystem::path> _history;
489         
490         /** Singleton instance, or 0 */
491         static Config* _instance;
492 };
493
494 #endif