Add preference for default KDM target directory (#1013).
authorCarl Hetherington <cth@carlh.net>
Fri, 16 Dec 2016 12:10:51 +0000 (12:10 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 16 Dec 2016 12:10:51 +0000 (12:10 +0000)
src/lib/config.cc
src/lib/config.h
src/wx/config_dialog.cc
src/wx/kdm_output_panel.cc

index 30ed1243b6890e70e010e4263ca1878c252761db..6530129604ec2344e0f687406026d1b780b898bf 100644 (file)
@@ -232,6 +232,7 @@ try
        _default_j2k_bandwidth = f.optional_number_child<int>("DefaultJ2KBandwidth").get_value_or (200000000);
        _default_audio_delay = f.optional_number_child<int>("DefaultAudioDelay").get_value_or (0);
        _default_interop = f.optional_bool_child("DefaultInterop").get_value_or (false);
+       _default_kdm_directory = f.optional_string_child("DefaultKDMDirectory");
 
        /* Load any cinemas from config.xml */
        read_cinemas (f);
@@ -416,6 +417,9 @@ Config::write_config_xml () const
        root->add_child("DefaultJ2KBandwidth")->add_child_text (raw_convert<string> (_default_j2k_bandwidth));
        root->add_child("DefaultAudioDelay")->add_child_text (raw_convert<string> (_default_audio_delay));
        root->add_child("DefaultInterop")->add_child_text (_default_interop ? "1" : "0");
+       if (_default_kdm_directory) {
+               root->add_child("DefaultKDMDirectory")->add_child_text (_default_kdm_directory->string ());
+       }
        root->add_child("MailServer")->add_child_text (_mail_server);
        root->add_child("MailPort")->add_child_text (raw_convert<string> (_mail_port));
        root->add_child("MailUser")->add_child_text (_mail_user);
@@ -501,17 +505,29 @@ Config::write_cinemas_xml () const
 boost::filesystem::path
 Config::default_directory_or (boost::filesystem::path a) const
 {
-       if (!_default_directory) {
+       return directory_or (_default_directory, a);
+}
+
+boost::filesystem::path
+Config::default_kdm_directory_or (boost::filesystem::path a) const
+{
+       return directory_or (_default_kdm_directory, a);
+}
+
+boost::filesystem::path
+Config::directory_or (optional<boost::filesystem::path> dir, boost::filesystem::path a) const
+{
+       if (!dir) {
                return a;
        }
 
        boost::system::error_code ec;
-       bool const e = boost::filesystem::exists (*_default_directory, ec);
+       bool const e = boost::filesystem::exists (*dir, ec);
        if (ec || !e) {
                return a;
        }
 
-       return *_default_directory;
+       return *dir;
 }
 
 void
index c5084670715d4a42f8c7b015b858a50801d1c77f..8b8d7c38ae4d5ea4dd9d5ec4887557846a544ada 100644 (file)
@@ -56,7 +56,12 @@ public:
                return _default_directory;
        }
 
+       boost::optional<boost::filesystem::path> default_kdm_directory () const {
+               return _default_kdm_directory;
+       }
+
        boost::filesystem::path default_directory_or (boost::filesystem::path a) const;
+       boost::filesystem::path default_kdm_directory_or (boost::filesystem::path a) const;
 
        enum Property {
                USE_ANY_SERVERS,
@@ -178,6 +183,14 @@ public:
                return _default_interop;
        }
 
+       void set_default_kdm_directory (boost::filesystem::path d) {
+               if (_default_kdm_directory && _default_kdm_directory.get() == d) {
+                       return;
+               }
+               _default_kdm_directory = d;
+               changed ();
+       }
+
        std::string mail_server () const {
                return _mail_server;
        }
@@ -549,6 +562,7 @@ private:
        void write_cinemas_xml () const;
        void read_cinemas (cxml::Document const & f);
        boost::shared_ptr<dcp::CertificateChain> create_certificate_chain ();
+       boost::filesystem::path directory_or (boost::optional<boost::filesystem::path> dir, boost::filesystem::path a) const;
 
        template <class T>
        void maybe_set (T& member, T new_value) {
@@ -599,6 +613,10 @@ private:
        int _default_j2k_bandwidth;
        int _default_audio_delay;
        bool _default_interop;
+       /** Default directory to offer to write KDMs to; if it's not set,
+           the home directory will be offered.
+       */
+       boost::optional<boost::filesystem::path> _default_kdm_directory;
        std::list<boost::shared_ptr<Cinema> > _cinemas;
        std::string _mail_server;
        int _mail_port;
index ee780dc5fac5be709c55047f888a19aad2966a05..b32ea9e27f3f8d4aef6e1655cf2a2f74865df2e3 100644 (file)
@@ -460,10 +460,19 @@ private:
                _standard = new wxChoice (_panel, wxID_ANY);
                table->Add (_standard);
 
+               add_label_to_sizer (table, _panel, _("Default KDM directory"), true);
+#ifdef DCPOMATIC_USE_OWN_PICKER
+               _kdm_directory = new DirPickerCtrl (_panel);
+#else
+               _kdm_directory = new wxDirPickerCtrl (_panel, wxDD_DIR_MUST_EXIST);
+#endif
+               table->Add (_kdm_directory, 1, wxEXPAND);
+
                _still_length->SetRange (1, 3600);
                _still_length->Bind (wxEVT_SPINCTRL, boost::bind (&DefaultsPage::still_length_changed, this));
 
                _directory->Bind (wxEVT_DIRPICKER_CHANGED, boost::bind (&DefaultsPage::directory_changed, this));
+               _kdm_directory->Bind (wxEVT_DIRPICKER_CHANGED, boost::bind (&DefaultsPage::kdm_directory_changed, this));
 
                _isdcf_metadata_button->Bind (wxEVT_BUTTON, boost::bind (&DefaultsPage::edit_isdcf_metadata_clicked, this));
 
@@ -515,6 +524,7 @@ private:
 
                checked_set (_still_length, config->default_still_length ());
                _directory->SetPath (std_to_wx (config->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir())).string ()));
+               _kdm_directory->SetPath (std_to_wx (config->default_kdm_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir())).string ()));
                checked_set (_j2k_bandwidth, config->default_j2k_bandwidth() / 1000000);
                _j2k_bandwidth->SetRange (50, config->maximum_j2k_bandwidth() / 1000000);
                checked_set (_dcp_audio_channels, locale_convert<string> (config->default_dcp_audio_channels()));
@@ -547,6 +557,11 @@ private:
                Config::instance()->set_default_directory (wx_to_std (_directory->GetPath ()));
        }
 
+       void kdm_directory_changed ()
+       {
+               Config::instance()->set_default_kdm_directory (wx_to_std (_kdm_directory->GetPath ()));
+       }
+
        void edit_isdcf_metadata_clicked ()
        {
                ISDCFMetadataDialog* d = new ISDCFMetadataDialog (_panel, Config::instance()->default_isdcf_metadata (), false);
@@ -583,8 +598,10 @@ private:
        wxSpinCtrl* _still_length;
 #ifdef DCPOMATIC_USE_OWN_PICKER
        DirPickerCtrl* _directory;
+       DirPickerCtrl* _kdm_directory;
 #else
        wxDirPickerCtrl* _directory;
+       wxDirPickerCtrl* _kdm_directory;
 #endif
        wxChoice* _container;
        wxChoice* _dcp_content_type;
index 3919e6cebfdcfbc0bb8ce7c81c9aa76a52c67c73..a36c82024dfdf01740a14ae5ac7f7a73e8e2bd38 100644 (file)
@@ -81,7 +81,12 @@ KDMOutputPanel::KDMOutputPanel (wxWindow* parent, bool interop)
        _folder = new wxDirPickerCtrl (this, wxID_ANY, wxEmptyString, wxDirSelectorPromptStr, wxDefaultPosition, wxSize (300, -1));
 #endif
 
-       _folder->SetPath (wxStandardPaths::Get().GetDocumentsDir());
+       boost::optional<boost::filesystem::path> path = Config::instance()->default_kdm_directory ();
+       if (path) {
+               _folder->SetPath (std_to_wx (path->string ()));
+       } else {
+               _folder->SetPath (wxStandardPaths::Get().GetDocumentsDir());
+       }
 
        table->Add (_folder, 1, wxEXPAND);