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"
35 using boost::shared_ptr;
37 Config* Config::_instance = 0;
39 /** Construct default configuration */
41 : _num_local_encoding_threads (2)
43 , _reference_scaler (Scaler::from_id ("bicubic"))
45 , _sound_processor (SoundProcessor::from_id ("dolby_cp750"))
47 ifstream f (file().c_str ());
49 while (getline (f, line)) {
58 size_t const s = line.find (' ');
59 if (s == string::npos) {
63 string const k = line.substr (0, s);
64 string const v = line.substr (s + 1);
66 if (k == "num_local_encoding_threads") {
67 _num_local_encoding_threads = atoi (v.c_str ());
68 } else if (k == "default_directory") {
69 _default_directory = v;
70 } else if (k == "server_port") {
71 _server_port = atoi (v.c_str ());
72 } else if (k == "reference_scaler") {
73 _reference_scaler = Scaler::from_id (v);
74 } else if (k == "reference_filter") {
75 _reference_filters.push_back (Filter::from_id (v));
76 } else if (k == "server") {
77 _servers.push_back (ServerDescription::create_from_metadata (v));
78 } else if (k == "tms_ip") {
80 } else if (k == "tms_path") {
82 } else if (k == "tms_user") {
84 } else if (k == "tms_password") {
86 } else if (k == "sound_processor") {
87 _sound_processor = SoundProcessor::from_id (v);
92 /** @return Filename to write configuration to */
96 boost::filesystem::path p;
97 p /= g_get_user_config_dir ();
102 /** @return Singleton instance */
106 if (_instance == 0) {
107 _instance = new Config;
113 /** Write our configuration to disk */
115 Config::write () const
117 ofstream f (file().c_str ());
118 f << "num_local_encoding_threads " << _num_local_encoding_threads << "\n"
119 << "default_directory " << _default_directory << "\n"
120 << "server_port " << _server_port << "\n"
121 << "reference_scaler " << _reference_scaler->id () << "\n";
123 for (vector<Filter const *>::const_iterator i = _reference_filters.begin(); i != _reference_filters.end(); ++i) {
124 f << "reference_filter " << (*i)->id () << "\n";
127 for (vector<ServerDescription*>::const_iterator i = _servers.begin(); i != _servers.end(); ++i) {
128 f << "server " << (*i)->as_metadata () << "\n";
131 f << "tms_ip " << _tms_ip << "\n";
132 f << "tms_path " << _tms_path << "\n";
133 f << "tms_user " << _tms_user << "\n";
134 f << "tms_password " << _tms_password << "\n";
135 f << "sound_processor " << _sound_processor->id ();
139 Config::default_directory_or (string a) const
141 if (_default_directory.empty() || !boost::filesystem::exists (_default_directory)) {
145 return _default_directory;