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