#include <fstream>
#include <glib.h>
#include <boost/filesystem.hpp>
+#include <libcxml/cxml.h>
#include "config.h"
#include "server.h"
#include "scaler.h"
-#include "screen.h"
#include "filter.h"
#include "sound_processor.h"
+#include "i18n.h"
+
using std::vector;
using std::ifstream;
using std::string;
using std::ofstream;
+using std::list;
using boost::shared_ptr;
+using boost::optional;
Config* Config::_instance = 0;
Config::Config ()
: _num_local_encoding_threads (2)
, _server_port (6192)
- , _colour_lut_index (0)
- , _j2k_bandwidth (250000000)
- , _reference_scaler (Scaler::from_id ("bicubic"))
- , _tms_path (".")
- , _sound_processor (SoundProcessor::from_id ("dolby_cp750"))
+ , _reference_scaler (Scaler::from_id (N_("bicubic")))
+ , _tms_path (N_("."))
+ , _sound_processor (SoundProcessor::from_id (N_("dolby_cp750")))
+{
+ _allowed_dcp_frame_rates.push_back (24);
+ _allowed_dcp_frame_rates.push_back (25);
+ _allowed_dcp_frame_rates.push_back (30);
+ _allowed_dcp_frame_rates.push_back (48);
+ _allowed_dcp_frame_rates.push_back (50);
+ _allowed_dcp_frame_rates.push_back (60);
+
+ if (!boost::filesystem::exists (file (false))) {
+ read_old_metadata ();
+ return;
+ }
+
+ cxml::File f (file (false), "Config");
+ optional<string> c;
+
+ _num_local_encoding_threads = f.number_child<int> ("NumLocalEncodingThreads");
+ _default_directory = f.string_child ("DefaultDirectory");
+ _server_port = f.number_child<int> ("ServerPort");
+ c = f.optional_string_child ("ReferenceScaler");
+ if (c) {
+ _reference_scaler = Scaler::from_id (c.get ());
+ }
+
+ list<shared_ptr<cxml::Node> > filters = f.node_children ("ReferenceFilter");
+ for (list<shared_ptr<cxml::Node> >::iterator i = filters.begin(); i != filters.end(); ++i) {
+ _reference_filters.push_back (Filter::from_id ((*i)->content ()));
+ }
+
+ list<shared_ptr<cxml::Node> > servers = f.node_children ("Server");
+ for (list<shared_ptr<cxml::Node> >::iterator i = servers.begin(); i != servers.end(); ++i) {
+ _servers.push_back (new ServerDescription (*i));
+ }
+
+ _tms_ip = f.string_child ("TMSIP");
+ _tms_path = f.string_child ("TMSPath");
+ _tms_user = f.string_child ("TMSUser");
+ _tms_password = f.string_child ("TMSPassword");
+
+ c = f.optional_string_child ("SoundProcessor");
+ if (c) {
+ _sound_processor = SoundProcessor::from_id (c.get ());
+ }
+
+ _language = f.optional_string_child ("Language");
+ _default_dci_metadata = DCIMetadata (f.node_child ("DCIMetadata"));
+}
+
+void
+Config::read_old_metadata ()
{
- ifstream f (file().c_str ());
+ ifstream f (file(true).c_str ());
string line;
while (getline (f, line)) {
if (line.empty ()) {
string const k = line.substr (0, s);
string const v = line.substr (s + 1);
- if (k == "num_local_encoding_threads") {
+ if (k == N_("num_local_encoding_threads")) {
_num_local_encoding_threads = atoi (v.c_str ());
- } else if (k == "default_directory") {
+ } else if (k == N_("default_directory")) {
_default_directory = v;
- } else if (k == "server_port") {
+ } else if (k == N_("server_port")) {
_server_port = atoi (v.c_str ());
- } else if (k == "colour_lut_index") {
- _colour_lut_index = atoi (v.c_str ());
- } else if (k == "j2k_bandwidth") {
- _j2k_bandwidth = atoi (v.c_str ());
- } else if (k == "reference_scaler") {
+ } else if (k == N_("reference_scaler")) {
_reference_scaler = Scaler::from_id (v);
- } else if (k == "reference_filter") {
+ } else if (k == N_("reference_filter")) {
_reference_filters.push_back (Filter::from_id (v));
- } else if (k == "server") {
+ } else if (k == N_("server")) {
_servers.push_back (ServerDescription::create_from_metadata (v));
- } else if (k == "screen") {
- _screens.push_back (Screen::create_from_metadata (v));
- } else if (k == "tms_ip") {
+ } else if (k == N_("tms_ip")) {
_tms_ip = v;
- } else if (k == "tms_path") {
+ } else if (k == N_("tms_path")) {
_tms_path = v;
- } else if (k == "tms_user") {
+ } else if (k == N_("tms_user")) {
_tms_user = v;
- } else if (k == "tms_password") {
+ } else if (k == N_("tms_password")) {
_tms_password = v;
- } else if (k == "sound_processor") {
+ } else if (k == N_("sound_processor")) {
_sound_processor = SoundProcessor::from_id (v);
+ } else if (k == "language") {
+ _language = v;
}
+
+ _default_dci_metadata.read_old_metadata (k, v);
}
}
/** @return Filename to write configuration to */
string
-Config::file () const
+Config::file (bool old) const
{
boost::filesystem::path p;
p /= g_get_user_config_dir ();
- p /= ".dvdomatic";
+ if (old) {
+ p /= ".dcpomatic";
+ } else {
+ p /= ".dcpomatic.xml";
+ }
return p.string ();
}
void
Config::write () const
{
- ofstream f (file().c_str ());
- f << "num_local_encoding_threads " << _num_local_encoding_threads << "\n"
- << "default_directory " << _default_directory << "\n"
- << "server_port " << _server_port << "\n"
- << "colour_lut_index " << _colour_lut_index << "\n"
- << "j2k_bandwidth " << _j2k_bandwidth << "\n"
- << "reference_scaler " << _reference_scaler->id () << "\n";
+ xmlpp::Document doc;
+ xmlpp::Element* root = doc.create_root_node ("Config");
+
+ root->add_child("NumLocalEncodingThreads")->add_child_text (boost::lexical_cast<string> (_num_local_encoding_threads));
+ root->add_child("DefaultDirectory")->add_child_text (_default_directory);
+ root->add_child("ServerPort")->add_child_text (boost::lexical_cast<string> (_server_port));
+ if (_reference_scaler) {
+ root->add_child("ReferenceScaler")->add_child_text (_reference_scaler->id ());
+ }
for (vector<Filter const *>::const_iterator i = _reference_filters.begin(); i != _reference_filters.end(); ++i) {
- f << "reference_filter " << (*i)->id () << "\n";
+ root->add_child("ReferenceFilter")->add_child_text ((*i)->id ());
}
for (vector<ServerDescription*>::const_iterator i = _servers.begin(); i != _servers.end(); ++i) {
- f << "server " << (*i)->as_metadata () << "\n";
+ (*i)->as_xml (root->add_child ("Server"));
}
- for (vector<shared_ptr<Screen> >::const_iterator i = _screens.begin(); i != _screens.end(); ++i) {
- f << "screen " << (*i)->as_metadata () << "\n";
+ root->add_child("TMSIP")->add_child_text (_tms_ip);
+ root->add_child("TMSPath")->add_child_text (_tms_path);
+ root->add_child("TMSUser")->add_child_text (_tms_user);
+ root->add_child("TMSPassword")->add_child_text (_tms_password);
+ if (_sound_processor) {
+ root->add_child("SoundProcessor")->add_child_text (_sound_processor->id ());
}
+ if (_language) {
+ root->add_child("Language")->add_child_text (_language.get());
+ }
+
+ _default_dci_metadata.as_xml (root->add_child ("DCIMetadata"));
- f << "tms_ip " << _tms_ip << "\n";
- f << "tms_path " << _tms_path << "\n";
- f << "tms_user " << _tms_user << "\n";
- f << "tms_password " << _tms_password << "\n";
- f << "sound_processor " << _sound_processor->id ();
+ doc.write_to_file_formatted (file (false));
}
string
return _default_directory;
}
+
+void
+Config::drop ()
+{
+ delete _instance;
+ _instance = 0;
+}