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 , _colour_lut_index (0)
46 , _j2k_bandwidth (250000000)
47 , _reference_scaler (Scaler::from_id ("bicubic"))
49 , _sound_processor (SoundProcessor::from_id ("dolby_cp750"))
51 ifstream f (file().c_str ());
54 shared_ptr<Cinema> cinema;
56 while (getline (f, line)) {
65 size_t const s = line.find (' ');
66 if (s == string::npos) {
70 string const k = line.substr (0, s);
71 string const v = line.substr (s + 1);
73 if (k == "num_local_encoding_threads") {
74 _num_local_encoding_threads = atoi (v.c_str ());
75 } else if (k == "default_directory") {
76 _default_directory = v;
77 } else if (k == "server_port") {
78 _server_port = atoi (v.c_str ());
79 } else if (k == "colour_lut_index") {
80 _colour_lut_index = atoi (v.c_str ());
81 } else if (k == "j2k_bandwidth") {
82 _j2k_bandwidth = atoi (v.c_str ());
83 } else if (k == "reference_scaler") {
84 _reference_scaler = Scaler::from_id (v);
85 } else if (k == "reference_filter") {
86 _reference_filters.push_back (Filter::from_id (v));
87 } else if (k == "server") {
88 _servers.push_back (ServerDescription::create_from_metadata (v));
89 } else if (k == "tms_ip") {
91 } else if (k == "tms_path") {
93 } else if (k == "tms_user") {
95 } else if (k == "tms_password") {
97 } else if (k == "sound_processor") {
98 _sound_processor = SoundProcessor::from_id (v);
99 } else if (k == "cinema") {
101 _cinemas.push_back (cinema);
103 cinema.reset (new Cinema (v, ""));
104 } else if (k == "cinema_email") {
107 } else if (k == "screen") {
108 shared_ptr<Screen> s (new Screen (v));
109 cinema->screens.push_back (s);
114 _cinemas.push_back (cinema);
118 /** @return Filename to write configuration to */
120 Config::file () const
122 boost::filesystem::path p;
123 p /= g_get_user_config_dir ();
128 /** @return Singleton instance */
132 if (_instance == 0) {
133 _instance = new Config;
139 /** Write our configuration to disk */
141 Config::write () const
143 ofstream f (file().c_str ());
144 f << "num_local_encoding_threads " << _num_local_encoding_threads << "\n"
145 << "default_directory " << _default_directory << "\n"
146 << "server_port " << _server_port << "\n"
147 << "colour_lut_index " << _colour_lut_index << "\n"
148 << "j2k_bandwidth " << _j2k_bandwidth << "\n"
149 << "reference_scaler " << _reference_scaler->id () << "\n";
151 for (vector<Filter const *>::const_iterator i = _reference_filters.begin(); i != _reference_filters.end(); ++i) {
152 f << "reference_filter " << (*i)->id () << "\n";
155 for (vector<ServerDescription*>::const_iterator i = _servers.begin(); i != _servers.end(); ++i) {
156 f << "server " << (*i)->as_metadata () << "\n";
159 f << "tms_ip " << _tms_ip << "\n";
160 f << "tms_path " << _tms_path << "\n";
161 f << "tms_user " << _tms_user << "\n";
162 f << "tms_password " << _tms_password << "\n";
163 f << "sound_processor " << _sound_processor->id () << "\n";
165 for (list<shared_ptr<Cinema> >::const_iterator i = _cinemas.begin(); i != _cinemas.end(); ++i) {
166 f << "cinema " << (*i)->name << "\n";
167 f << "cinema_email " << (*i)->email << "\n";
168 for (list<shared_ptr<Screen> >::iterator j = (*i)->screens.begin(); j != (*i)->screens.end(); ++j) {
169 f << "screen " << (*j)->name << "\n";
175 Config::default_directory_or (string a) const
177 if (_default_directory.empty() || !boost::filesystem::exists (_default_directory)) {
181 return _default_directory;