Rename ConfigDialog -> FullConfigDialog.
[dcpomatic.git] / src / wx / config_dialog.cc
index 796972384e6a84c39ba2ccf3899ab9b2c0655a85..40c0c304690ee028e6d2f76cae9593f16b7ff96d 100644 (file)
@@ -34,6 +34,7 @@
 #include "email_dialog.h"
 #include "name_format_editor.h"
 #include "nag_dialog.h"
+#include "config_move_dialog.h"
 #include "lib/config.h"
 #include "lib/ratio.h"
 #include "lib/filter.h"
@@ -212,6 +213,11 @@ private:
                table->Add (_server_encoding_threads, wxGBPosition (r, 1));
                ++r;
 
+               add_label_to_sizer (table, _panel, _("Configuration file"), true, wxGBPosition (r, 0));
+               _config_file = new FilePickerCtrl (_panel, _("Select configuration file"), "*.xml", true);
+               table->Add (_config_file, wxGBPosition (r, 1));
+               ++r;
+
                add_label_to_sizer (table, _panel, _("Cinema and screen database file"), true, wxGBPosition (r, 0));
                _cinemas_file = new FilePickerCtrl (_panel, _("Select cinema and screen database file"), "*.xml", true);
                table->Add (_cinemas_file, wxGBPosition (r, 1));
@@ -265,6 +271,7 @@ private:
 
                _set_language->Bind         (wxEVT_CHECKBOX,           boost::bind (&GeneralPage::set_language_changed,  this));
                _language->Bind             (wxEVT_CHOICE,             boost::bind (&GeneralPage::language_changed,      this));
+               _config_file->Bind          (wxEVT_FILEPICKER_CHANGED, boost::bind (&GeneralPage::config_file_changed,   this));
                _cinemas_file->Bind         (wxEVT_FILEPICKER_CHANGED, boost::bind (&GeneralPage::cinemas_file_changed,  this));
                _preview_sound->Bind        (wxEVT_CHECKBOX,           boost::bind (&GeneralPage::preview_sound_changed, this));
                _preview_sound_output->Bind (wxEVT_CHOICE,             boost::bind (&GeneralPage::preview_sound_output_changed, this));
@@ -325,25 +332,30 @@ private:
                checked_set (_check_for_test_updates, config->check_for_test_updates ());
                checked_set (_issuer, config->dcp_issuer ());
                checked_set (_creator, config->dcp_creator ());
+               checked_set (_config_file, config->config_file());
                checked_set (_cinemas_file, config->cinemas_file());
                checked_set (_preview_sound, config->preview_sound());
 
                 optional<string> const current_so = get_preview_sound_output ();
-                string configured_so;
+                optional<string> configured_so;
 
                 if (config->preview_sound_output()) {
                         configured_so = config->preview_sound_output().get();
                 } else {
                         /* No configured output means we should use the default */
                         RtAudio audio (DCPOMATIC_RTAUDIO_API);
-                        configured_so = audio.getDeviceInfo(audio.getDefaultOutputDevice()).name;
+                       try {
+                               configured_so = audio.getDeviceInfo(audio.getDefaultOutputDevice()).name;
+                       } catch (RtAudioError& e) {
+                               /* Probably no audio devices at all */
+                       }
                 }
 
-                if (!current_so || *current_so != configured_so) {
+                if (configured_so && current_so != configured_so) {
                         /* Update _preview_sound_output with the configured value */
                         unsigned int i = 0;
                         while (i < _preview_sound_output->GetCount()) {
-                                if (_preview_sound_output->GetString(i) == std_to_wx(configured_so)) {
+                                if (_preview_sound_output->GetString(i) == std_to_wx(*configured_so)) {
                                         _preview_sound_output->SetSelection (i);
                                         break;
                                 }
@@ -434,6 +446,32 @@ private:
                Config::instance()->set_dcp_creator (wx_to_std (_creator->GetValue ()));
        }
 
+       void config_file_changed ()
+       {
+               Config* config = Config::instance();
+               boost::filesystem::path new_file = wx_to_std(_config_file->GetPath());
+               if (new_file == config->config_file()) {
+                       return;
+               }
+               bool copy_and_link = true;
+               if (boost::filesystem::exists(new_file)) {
+                       ConfigMoveDialog* d = new ConfigMoveDialog (_panel, new_file);
+                       if (d->ShowModal() == wxID_OK) {
+                               copy_and_link = false;
+                       }
+                       d->Destroy ();
+               }
+
+               if (copy_and_link) {
+                       config->write ();
+                       if (new_file != config->config_file()) {
+                               config->copy_and_link (new_file);
+                       }
+               } else {
+                       config->link (new_file);
+               }
+       }
+
        void cinemas_file_changed ()
        {
                Config::instance()->set_cinemas_file (wx_to_std (_cinemas_file->GetPath ()));
@@ -459,6 +497,7 @@ private:
        wxChoice* _language;
        wxSpinCtrl* _master_encoding_threads;
        wxSpinCtrl* _server_encoding_threads;
+       FilePickerCtrl* _config_file;
        FilePickerCtrl* _cinemas_file;
        wxCheckBox* _preview_sound;
        wxChoice* _preview_sound_output;
@@ -573,24 +612,22 @@ private:
 
                _isdcf_metadata_button->Bind (wxEVT_BUTTON, boost::bind (&DefaultsPage::edit_isdcf_metadata_clicked, this));
 
-               vector<Ratio const *> ratios = Ratio::all ();
-               for (size_t i = 0; i < ratios.size(); ++i) {
-                       _container->Append (std_to_wx (ratios[i]->nickname ()));
+               BOOST_FOREACH (Ratio const * i, Ratio::containers()) {
+                       _container->Append (std_to_wx(i->container_nickname()));
                }
 
                _container->Bind (wxEVT_CHOICE, boost::bind (&DefaultsPage::container_changed, this));
 
                _scale_to->Append (_("Guess from content"));
 
-               for (size_t i = 0; i < ratios.size(); ++i) {
-                       _scale_to->Append (std_to_wx (ratios[i]->nickname ()));
+               BOOST_FOREACH (Ratio const * i, Ratio::all()) {
+                       _scale_to->Append (std_to_wx(i->image_nickname()));
                }
 
                _scale_to->Bind (wxEVT_CHOICE, boost::bind (&DefaultsPage::scale_to_changed, this));
 
-               vector<DCPContentType const *> const ct = DCPContentType::all ();
-               for (size_t i = 0; i < ct.size(); ++i) {
-                       _dcp_content_type->Append (std_to_wx (ct[i]->pretty_name ()));
+               BOOST_FOREACH (DCPContentType const * i, DCPContentType::all()) {
+                       _dcp_content_type->Append (std_to_wx (i->pretty_name ()));
                }
 
                setup_audio_channels_choice (_dcp_audio_channels, 2);
@@ -613,11 +650,15 @@ private:
        {
                Config* config = Config::instance ();
 
-               vector<Ratio const *> ratios = Ratio::all ();
-               for (size_t i = 0; i < ratios.size(); ++i) {
-                       if (ratios[i] == config->default_container ()) {
+               vector<Ratio const *> containers = Ratio::containers ();
+               for (size_t i = 0; i < containers.size(); ++i) {
+                       if (containers[i] == config->default_container ()) {
                                _container->SetSelection (i);
                        }
+               }
+
+               vector<Ratio const *> ratios = Ratio::all ();
+               for (size_t i = 0; i < ratios.size(); ++i) {
                        if (ratios[i] == config->default_scale_to ()) {
                                _scale_to->SetSelection (i + 1);
                        }
@@ -689,7 +730,7 @@ private:
 
        void container_changed ()
        {
-               vector<Ratio const *> ratio = Ratio::all ();
+               vector<Ratio const *> ratio = Ratio::containers ();
                Config::instance()->set_default_container (ratio[_container->GetSelection()]);
        }
 
@@ -1864,7 +1905,7 @@ private:
 };
 
 wxPreferencesEditor*
-create_config_dialog ()
+create_full_config_dialog ()
 {
        wxPreferencesEditor* e = new wxPreferencesEditor ();