Fix warning.
[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 <vector>
28 #include <boost/shared_ptr.hpp>
29 #include <boost/signals2.hpp>
30 #include <boost/filesystem.hpp>
31 #include <dcp/metadata.h>
32 #include <dcp/certificates.h>
33 #include <dcp/signer.h>
34 #include "isdcf_metadata.h"
35 #include "colour_conversion.h"
36
37 class ServerDescription;
38 class Scaler;
39 class Filter;
40 class CinemaSoundProcessor;
41 class DCPContentType;
42 class Ratio;
43 class Cinema;
44
45 /** @class Config
46  *  @brief A singleton class holding configuration.
47  */
48 class Config : public boost::noncopyable
49 {
50 public:
51
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_scale () const {
138                 return _default_scale;
139         }
140
141         Ratio const * default_container () const {
142                 return _default_container;
143         }
144
145         DCPContentType const * default_dcp_content_type () const {
146                 return _default_dcp_content_type;
147         }
148
149         std::string dcp_issuer () const {
150                 return _dcp_issuer;
151         }
152
153         int default_j2k_bandwidth () const {
154                 return _default_j2k_bandwidth;
155         }
156
157         int default_audio_delay () const {
158                 return _default_audio_delay;
159         }
160
161         std::vector<PresetColourConversion> colour_conversions () const {
162                 return _colour_conversions;
163         }
164
165         std::string mail_server () const {
166                 return _mail_server;
167         }
168
169         std::string mail_user () const {
170                 return _mail_user;
171         }
172
173         std::string mail_password () const {
174                 return _mail_password;
175         }
176
177         std::string kdm_subject () const {
178                 return _kdm_subject;
179         }
180
181         std::string kdm_from () const {
182                 return _kdm_from;
183         }
184
185         std::string kdm_cc () const {
186                 return _kdm_cc;
187         }
188
189         std::string kdm_bcc () const {
190                 return _kdm_bcc;
191         }
192         
193         std::string kdm_email () const {
194                 return _kdm_email;
195         }
196
197         boost::shared_ptr<const dcp::Signer> signer () const {
198                 return _signer;
199         }
200
201         dcp::Certificate decryption_certificate () const {
202                 return _decryption_certificate;
203         }
204
205         std::string decryption_private_key () const {
206                 return _decryption_private_key;
207         }
208
209         bool check_for_updates () const {
210                 return _check_for_updates;
211         }
212
213         bool check_for_test_updates () const {
214                 return _check_for_test_updates;
215         }
216
217         int maximum_j2k_bandwidth () const {
218                 return _maximum_j2k_bandwidth;
219         }
220
221         int log_types () const {
222                 return _log_types;
223         }
224
225         std::vector<boost::filesystem::path> history () const {
226                 return _history;
227         }
228
229         /** @param n New number of local encoding threads */
230         void set_num_local_encoding_threads (int n) {
231                 _num_local_encoding_threads = n;
232                 changed ();
233         }
234
235         void set_default_directory (boost::filesystem::path d) {
236                 _default_directory = d;
237                 changed ();
238         }
239
240         /** @param p New server port */
241         void set_server_port_base (int p) {
242                 _server_port_base = p;
243                 changed ();
244         }
245
246         /** @param i IP address of a TMS that we can copy DCPs to */
247         void set_tms_ip (std::string i) {
248                 _tms_ip = i;
249                 changed ();
250         }
251
252         /** @param p Path on a TMS that we should changed DCPs to */
253         void set_tms_path (std::string p) {
254                 _tms_path = p;
255                 changed ();
256         }
257
258         /** @param u User name to log into the TMS with */
259         void set_tms_user (std::string u) {
260                 _tms_user = u;
261                 changed ();
262         }
263
264         /** @param p Password to log into the TMS with */
265         void set_tms_password (std::string p) {
266                 _tms_password = p;
267                 changed ();
268         }
269
270         void add_cinema (boost::shared_ptr<Cinema> c) {
271                 _cinemas.push_back (c);
272                 changed ();
273         }
274
275         void remove_cinema (boost::shared_ptr<Cinema> c) {
276                 _cinemas.remove (c);
277                 changed ();
278         }
279
280         void set_allowed_dcp_frame_rates (std::list<int> const & r) {
281                 _allowed_dcp_frame_rates = r;
282                 changed ();
283         }
284
285         void set_allow_any_dcp_frame_rate (bool a) {
286                 _allow_any_dcp_frame_rate = a;
287                 changed ();
288         }
289
290         void set_default_isdcf_metadata (ISDCFMetadata d) {
291                 _default_isdcf_metadata = d;
292                 changed ();
293         }
294
295         void set_language (std::string l) {
296                 _language = l;
297                 changed ();
298         }
299
300         void unset_language () {
301                 _language = boost::none;
302                 changed ();
303         }
304
305         void set_default_still_length (int s) {
306                 _default_still_length = s;
307                 changed ();
308         }
309
310         void set_default_scale (Ratio const * s) {
311                 _default_scale = s;
312                 changed ();
313         }
314
315         void set_default_container (Ratio const * c) {
316                 _default_container = c;
317                 changed ();
318         }
319
320         void set_default_dcp_content_type (DCPContentType const * t) {
321                 _default_dcp_content_type = t;
322                 changed ();
323         }
324
325         void set_dcp_issuer (std::string i) {
326                 _dcp_issuer = i;
327                 changed ();
328         }
329
330         void set_default_j2k_bandwidth (int b) {
331                 _default_j2k_bandwidth = b;
332                 changed ();
333         }
334
335         void set_default_audio_delay (int d) {
336                 _default_audio_delay = d;
337                 changed ();
338         }
339
340         void set_colour_conversions (std::vector<PresetColourConversion> const & c) {
341                 _colour_conversions = c;
342                 changed ();
343         }
344
345         void set_mail_server (std::string s) {
346                 _mail_server = s;
347                 changed ();
348         }
349
350         void set_mail_user (std::string u) {
351                 _mail_user = u;
352                 changed ();
353         }
354
355         void set_mail_password (std::string p) {
356                 _mail_password = p;
357                 changed ();
358         }
359
360         void set_kdm_subject (std::string s) {
361                 _kdm_subject = s;
362                 changed ();
363         }
364
365         void set_kdm_from (std::string f) {
366                 _kdm_from = f;
367                 changed ();
368         }
369
370         void set_kdm_cc (std::string f) {
371                 _kdm_cc = f;
372                 changed ();
373         }
374
375         void set_kdm_bcc (std::string f) {
376                 _kdm_bcc = f;
377                 changed ();
378         }
379         
380         void set_kdm_email (std::string e) {
381                 _kdm_email = e;
382                 changed ();
383         }
384
385         void reset_kdm_email ();
386
387         void set_signer (boost::shared_ptr<const dcp::Signer> s) {
388                 _signer = s;
389                 changed ();
390         }
391
392         void set_decryption_certificate (dcp::Certificate c) {
393                 _decryption_certificate = c;
394                 changed ();
395         }
396
397         void set_decryption_private_key (std::string k) {
398                 _decryption_private_key = k;
399                 changed ();
400         }
401
402         void set_check_for_updates (bool c) {
403                 _check_for_updates = c;
404                 changed ();
405         }
406
407         void set_check_for_test_updates (bool c) {
408                 _check_for_test_updates = c;
409                 changed ();
410         }
411
412         void set_maximum_j2k_bandwidth (int b) {
413                 _maximum_j2k_bandwidth = b;
414                 changed ();
415         }
416
417         void set_log_types (int t) {
418                 _log_types = t;
419                 changed ();
420         }
421
422         void clear_history () {
423                 _history.clear ();
424                 changed ();
425         }
426
427         void add_to_history (boost::filesystem::path p);
428         
429         void changed ();
430         boost::signals2::signal<void ()> Changed;
431
432         static Config* instance ();
433         static void drop ();
434
435 private:
436         Config ();
437         boost::filesystem::path file (bool) const;
438         void read ();
439         void write () const;
440         void make_decryption_keys ();
441
442         /** number of threads to use for J2K encoding on the local machine */
443         int _num_local_encoding_threads;
444         /** default directory to put new films in */
445         boost::filesystem::path _default_directory;
446         /** base port number to use for J2K encoding servers;
447          *  this port and the one above it will be used.
448          */
449         int _server_port_base;
450         /** true to broadcast on the `any' address to look for servers */
451         bool _use_any_servers;
452         /** J2K encoding servers that should definitely be used */
453         std::vector<std::string> _servers;
454         /** The IP address of a TMS that we can copy DCPs to */
455         std::string _tms_ip;
456         /** The path on a TMS that we should write DCPs to */
457         std::string _tms_path;
458         /** User name to log into the TMS with */
459         std::string _tms_user;
460         /** Password to log into the TMS with */
461         std::string _tms_password;
462         /** Our cinema sound processor */
463         CinemaSoundProcessor const * _cinema_sound_processor;
464         std::list<int> _allowed_dcp_frame_rates;
465         /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
466         bool _allow_any_dcp_frame_rate;
467         /** Default ISDCF metadata for newly-created Films */
468         ISDCFMetadata _default_isdcf_metadata;
469         boost::optional<std::string> _language;
470         int _default_still_length;
471         Ratio const * _default_scale;
472         Ratio const * _default_container;
473         DCPContentType const * _default_dcp_content_type;
474         std::string _dcp_issuer;
475         int _default_j2k_bandwidth;
476         int _default_audio_delay;
477         std::vector<PresetColourConversion> _colour_conversions;
478         std::list<boost::shared_ptr<Cinema> > _cinemas;
479         std::string _mail_server;
480         std::string _mail_user;
481         std::string _mail_password;
482         std::string _kdm_subject;
483         std::string _kdm_from;
484         std::string _kdm_cc;
485         std::string _kdm_bcc;
486         std::string _kdm_email;
487         boost::shared_ptr<const dcp::Signer> _signer;
488         dcp::Certificate _decryption_certificate;
489         std::string _decryption_private_key;
490         /** true to check for updates on startup */
491         bool _check_for_updates;
492         bool _check_for_test_updates;
493         /** maximum allowed J2K bandwidth in bits per second */
494         int _maximum_j2k_bandwidth;
495         int _log_types;
496         std::vector<boost::filesystem::path> _history;
497         
498         /** Singleton instance, or 0 */
499         static Config* _instance;
500 };
501
502 #endif