2 Copyright (C) 2012 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.
24 #include <boost/filesystem.hpp>
29 #include "sound_processor.h"
37 using boost::shared_ptr;
39 Config* Config::_instance = 0;
41 /** Construct default configuration */
43 : _num_local_encoding_threads (2)
45 , _reference_scaler (Scaler::from_id (N_("bicubic")))
47 , _sound_processor (SoundProcessor::from_id (N_("dolby_cp750")))
49 _allowed_dcp_frame_rates.push_back (24);
50 _allowed_dcp_frame_rates.push_back (25);
51 _allowed_dcp_frame_rates.push_back (30);
53 ifstream f (file().c_str ());
55 while (getline (f, line)) {
64 size_t const s = line.find (' ');
65 if (s == string::npos) {
69 string const k = line.substr (0, s);
70 string const v = line.substr (s + 1);
72 if (k == N_("num_local_encoding_threads")) {
73 _num_local_encoding_threads = atoi (v.c_str ());
74 } else if (k == N_("default_directory")) {
75 _default_directory = v;
76 } else if (k == N_("server_port")) {
77 _server_port = atoi (v.c_str ());
78 } else if (k == N_("reference_scaler")) {
79 _reference_scaler = Scaler::from_id (v);
80 } else if (k == N_("reference_filter")) {
81 _reference_filters.push_back (Filter::from_id (v));
82 } else if (k == N_("server")) {
83 _servers.push_back (ServerDescription::create_from_metadata (v));
84 } else if (k == N_("tms_ip")) {
86 } else if (k == N_("tms_path")) {
88 } else if (k == N_("tms_user")) {
90 } else if (k == N_("tms_password")) {
92 } else if (k == N_("sound_processor")) {
93 _sound_processor = SoundProcessor::from_id (v);
96 _default_dci_metadata.read (k, v);
100 /** @return Filename to write configuration to */
102 Config::file () const
104 boost::filesystem::path p;
105 p /= g_get_user_config_dir ();
106 p /= N_(".dvdomatic");
110 /** @return Singleton instance */
114 if (_instance == 0) {
115 _instance = new Config;
121 /** Write our configuration to disk */
123 Config::write () const
125 ofstream f (file().c_str ());
126 f << N_("num_local_encoding_threads ") << _num_local_encoding_threads << N_("\n")
127 << N_("default_directory ") << _default_directory << N_("\n")
128 << N_("server_port ") << _server_port << N_("\n")
129 << N_("reference_scaler ") << _reference_scaler->id () << N_("\n");
131 for (vector<Filter const *>::const_iterator i = _reference_filters.begin(); i != _reference_filters.end(); ++i) {
132 f << N_("reference_filter ") << (*i)->id () << N_("\n");
135 for (vector<ServerDescription*>::const_iterator i = _servers.begin(); i != _servers.end(); ++i) {
136 f << N_("server ") << (*i)->as_metadata () << N_("\n");
139 f << N_("tms_ip ") << _tms_ip << N_("\n");
140 f << N_("tms_path ") << _tms_path << N_("\n");
141 f << N_("tms_user ") << _tms_user << N_("\n");
142 f << N_("tms_password ") << _tms_password << N_("\n");
143 f << N_("sound_processor ") << _sound_processor->id () << N_("\n");
145 _default_dci_metadata.write (f);
149 Config::default_directory_or (string a) const
151 if (_default_directory.empty() || !boost::filesystem::exists (_default_directory)) {
155 return _default_directory;