Generalise add_files_path to initial_paths().
authorCarl Hetherington <cth@carlh.net>
Tue, 3 Jan 2023 19:34:01 +0000 (20:34 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 3 Jan 2023 19:34:01 +0000 (20:34 +0100)
src/lib/config.cc
src/lib/config.h
src/wx/content_panel.cc

index e3be484e242542fbdd5f5d3107f306d6ceb479f9..21e6703061cede3a1a37e24d7c8f50cdb51f301e 100644 (file)
@@ -185,7 +185,8 @@ Config::set_defaults ()
        _player_kdm_directory = boost::none;
        _audio_mapping = boost::none;
        _custom_languages.clear ();
-       _add_files_path = boost::none;
+       _initial_paths.clear();
+       _initial_paths["AddFilesPath"] = boost::none;
        _use_isdcf_name_by_default = true;
        _write_kdms_to_disk = true;
        _email_kdms = false;
@@ -599,7 +600,9 @@ try
                } catch (std::runtime_error& e) {}
        }
 
-       _add_files_path = f.optional_string_child("AddFilesPath");
+       for (auto& initial: _initial_paths) {
+               initial.second = f.optional_string_child(initial.first);
+       }
        _use_isdcf_name_by_default = f.optional_bool_child("UseISDCFNameByDefault").get_value_or(true);
        _write_kdms_to_disk = f.optional_bool_child("WriteKDMsToDisk").get_value_or(true);
        _email_kdms = f.optional_bool_child("EmailKDMs").get_value_or(false);
@@ -1071,9 +1074,10 @@ Config::write_config () const
        for (auto const& i: _custom_languages) {
                root->add_child("CustomLanguage")->add_child_text(i.to_string());
        }
-       if (_add_files_path) {
-               /* [XML] AddFilesPath The default path that will be offered in the picker when adding files to a film. */
-               root->add_child("AddFilesPath")->add_child_text(_add_files_path->string());
+       for (auto const& initial: _initial_paths) {
+               if (initial.second) {
+                       root->add_child(initial.first)->add_child_text(initial.second->string());
+               }
        }
        root->add_child("UseISDCFNameByDefault")->add_child_text(_use_isdcf_name_by_default ? "1" : "0");
        root->add_child("WriteKDMsToDisk")->add_child_text(_write_kdms_to_disk ? "1" : "0");
@@ -1591,3 +1595,22 @@ save_all_config_as_zip (boost::filesystem::path zip_file)
        zipper.close ();
 }
 
+
+void
+Config::set_initial_path(string id, boost::filesystem::path path)
+{
+       auto iter = _initial_paths.find(id);
+       DCPOMATIC_ASSERT(iter != _initial_paths.end());
+       iter->second = path;
+       changed();
+}
+
+
+optional<boost::filesystem::path>
+Config::initial_path(string id) const
+{
+       auto iter = _initial_paths.find(id);
+       DCPOMATIC_ASSERT(iter != _initial_paths.end());
+       return iter->second;
+}
+
index 2535bd82ae0d5ef3f34ca891b04c0f15623888d0..b6a1a535d08e10f53db404d4e4b94bb4e28f8d08 100644 (file)
@@ -565,9 +565,7 @@ public:
                return _custom_languages;
        }
 
-       boost::optional<boost::filesystem::path> add_files_path () const {
-               return _add_files_path;
-       }
+       boost::optional<boost::filesystem::path> initial_path(std::string id) const;
 
        bool use_isdcf_name_by_default () const {
                return _use_isdcf_name_by_default;
@@ -1128,10 +1126,7 @@ public:
 
        void add_custom_language (dcp::LanguageTag tag);
 
-       void set_add_files_path (boost::filesystem::path p) {
-               _add_files_path = p;
-               changed ();
-       }
+       void set_initial_path(std::string id, boost::filesystem::path path);
 
        void set_use_isdcf_name_by_default (bool use) {
                maybe_set (_use_isdcf_name_by_default, use);
@@ -1403,7 +1398,7 @@ private:
        boost::optional<boost::filesystem::path> _player_kdm_directory;
        boost::optional<AudioMapping> _audio_mapping;
        std::vector<dcp::LanguageTag> _custom_languages;
-       boost::optional<boost::filesystem::path> _add_files_path;
+       std::map<std::string, boost::optional<boost::filesystem::path>> _initial_paths;
        bool _use_isdcf_name_by_default;
        bool _write_kdms_to_disk;
        bool _email_kdms;
index 9de22e8446639c304a70467bdec046bfa9947627..e035d1795a46638d0f68607785d22e7ef1fd51d4 100644 (file)
@@ -579,7 +579,7 @@ ContentPanel::add_file_clicked ()
                return;
        }
 
-       auto path = Config::instance()->add_files_path();
+       auto path = Config::instance()->initial_path("AddFilesPath");
 
        /* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using
           non-Latin filenames or paths.
@@ -609,7 +609,7 @@ ContentPanel::add_file_clicked ()
        add_files (path_list);
 
        if (!path_list.empty()) {
-               Config::instance()->set_add_files_path(path_list[0].parent_path());
+               Config::instance()->set_initial_path("AddFilesPath", path_list[0].parent_path());
        }
 
        d->Destroy ();
@@ -619,7 +619,7 @@ ContentPanel::add_file_clicked ()
 void
 ContentPanel::add_folder_clicked ()
 {
-       auto const initial_path = Config::instance()->add_files_path();
+       auto const initial_path = Config::instance()->initial_path("AddFilesPath");
 
        auto d = new wxDirDialog(_splitter, _("Choose a folder"), std_to_wx(initial_path ? initial_path->string() : home_directory().string()), wxDD_DIR_MUST_EXIST);
        ScopeGuard sg = [d]() { d->Destroy(); };
@@ -673,7 +673,7 @@ ContentPanel::add_folder(boost::filesystem::path folder)
 void
 ContentPanel::add_dcp_clicked ()
 {
-       auto const initial_path = Config::instance()->add_files_path();
+       auto const initial_path = Config::instance()->initial_path("AddFilesPath");
 
        auto d = new wxDirDialog(_splitter, _("Choose a DCP folder"), std_to_wx(initial_path ? initial_path->string() : home_directory().string()), wxDD_DIR_MUST_EXIST);
        ScopeGuard sg = [d]() { d->Destroy(); };