Handle failure to write to cinemas file more nicely.
authorCarl Hetherington <cth@carlh.net>
Tue, 7 Mar 2017 10:18:06 +0000 (10:18 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 7 Mar 2017 10:18:06 +0000 (10:18 +0000)
ChangeLog
src/lib/config.cc
src/lib/config.h
src/tools/dcpomatic.cc
src/wx/screens_panel.cc

index 8a9d86d2f9da539cd156ad61a72666e9cb0f027a..f7e10cc3e7e6fe6547f59e9e16ec3277dcc59015 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-03-07  Carl Hetherington  <cth@carlh.net>
+
+       * Handle failure to write to cinemas file more nicely.
+
 2017-02-28  Carl Hetherington  <cth@carlh.net>
 
        * Updated de_DE translation from Carsten Kurz.
index 031c046c9368bd92e7de4723fd64ba32f57becf1..6a08125cfef35f08e008c97f46fdc418a02dc6c2 100644 (file)
@@ -366,12 +366,12 @@ Config::instance ()
 void
 Config::write () const
 {
-       write_config_xml ();
-       write_cinemas_xml ();
+       write_config ();
+       write_cinemas ();
 }
 
 void
-Config::write_config_xml () const
+Config::write_config () const
 {
        xmlpp::Document doc;
        xmlpp::Element* root = doc.create_root_node ("Config");
@@ -482,7 +482,7 @@ Config::write_config_xml () const
 }
 
 void
-Config::write_cinemas_xml () const
+Config::write_cinemas () const
 {
        xmlpp::Document doc;
        xmlpp::Element* root = doc.create_root_node ("Cinemas");
index 8b8d7c38ae4d5ea4dd9d5ec4887557846a544ada..1bdbcb96e284247f30f2020afd56a5fd2e8e59e4 100644 (file)
@@ -66,6 +66,7 @@ public:
        enum Property {
                USE_ANY_SERVERS,
                SERVERS,
+               CINEMAS,
                OTHER
        };
 
@@ -345,12 +346,12 @@ public:
 
        void add_cinema (boost::shared_ptr<Cinema> c) {
                _cinemas.push_back (c);
-               changed ();
+               changed (CINEMAS);
        }
 
        void remove_cinema (boost::shared_ptr<Cinema> c) {
                _cinemas.remove (c);
-               changed ();
+               changed (CINEMAS);
        }
 
        void set_allowed_dcp_frame_rates (std::list<int> const & r) {
@@ -539,6 +540,8 @@ public:
        static boost::signals2::signal<void ()> FailedToLoad;
 
        void write () const;
+       void write_config () const;
+       void write_cinemas () const;
 
        void save_template (boost::shared_ptr<const Film> film, std::string name) const;
        bool existing_template (std::string name) const;
@@ -558,8 +561,6 @@ private:
        void read ();
        void set_defaults ();
        void set_kdm_email_to_default ();
-       void write_config_xml () const;
-       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;
index 2b6a62f11f4ec4730fe5db983fc91183bbe5da78..d091512a04a94eed1073d43bf5a99b6570abaaa2 100644 (file)
@@ -214,8 +214,8 @@ public:
                SetIcon (wxIcon (std_to_wx ("id")));
 #endif
 
-               _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this));
-               config_changed ();
+               _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
+               config_changed (Config::OTHER);
 
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_new, this),                ID_file_new);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this),               ID_file_open);
@@ -277,9 +277,6 @@ public:
                wxAcceleratorTable accel_table (2, accel);
                SetAcceleratorTable (accel_table);
 
-               /* Instantly save any config changes when using the DCP-o-matic GUI */
-               Config::instance()->Changed.connect (boost::bind (&Config::write, Config::instance ()));
-
                UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
        }
 
@@ -925,8 +922,35 @@ private:
                m->Append (help, _("&Help"));
        }
 
-       void config_changed ()
+       void config_changed (Config::Property what)
        {
+               /* Instantly save any config changes when using the DCP-o-matic GUI */
+               if (what == Config::CINEMAS) {
+                       try {
+                               Config::instance()->write_cinemas();
+                       } catch (exception& e) {
+                               error_dialog (
+                                       this,
+                                       wxString::Format (
+                                               _("Could not write to cinemas file at %s.  Your changes have not been saved."),
+                                               std_to_wx (Config::instance()->cinemas_file().string()).data()
+                                               )
+                                       );
+                       }
+               } else {
+                       try {
+                               Config::instance()->write_config();
+                       } catch (exception& e) {
+                               error_dialog (
+                                       this,
+                                       wxString::Format (
+                                               _("Could not write to config file at %s.  Your changes have not been saved."),
+                                               std_to_wx (Config::instance()->cinemas_file().string()).data()
+                                               )
+                                       );
+                       }
+               }
+
                for (int i = 0; i < _history_items; ++i) {
                        delete _file_menu->Remove (ID_file_history + i);
                }
index 3abe1f970cd925bfacc7c611a1c6c4cf70bd4b68..908e94f4dab8b0bbb5d2f46796705f0a76d63846 100644 (file)
@@ -177,7 +177,7 @@ ScreensPanel::edit_cinema_clicked ()
                c.second->set_utc_offset_hour (d->utc_offset_hour ());
                c.second->set_utc_offset_minute (d->utc_offset_minute ());
                _targets->SetItemText (c.first, std_to_wx (d->name()));
-               Config::instance()->changed ();
+               Config::instance()->changed (Config::CINEMAS);
        }
 
        d->Destroy ();
@@ -229,7 +229,7 @@ ScreensPanel::add_screen_clicked ()
                _targets->Expand (id.get ());
        }
 
-       Config::instance()->changed ();
+       Config::instance()->changed (Config::CINEMAS);
 
        d->Destroy ();
 }
@@ -268,7 +268,7 @@ ScreensPanel::edit_screen_clicked ()
        s.second->recipient = d->recipient ();
        s.second->trusted_devices = d->trusted_devices ();
        _targets->SetItemText (s.first, std_to_wx (d->name()));
-       Config::instance()->changed ();
+       Config::instance()->changed (Config::CINEMAS);
 
        d->Destroy ();
 }
@@ -295,7 +295,7 @@ ScreensPanel::remove_screen_clicked ()
                _targets->Delete (i->first);
        }
 
-       Config::instance()->changed ();
+       Config::instance()->changed (Config::CINEMAS);
 }
 
 list<shared_ptr<Screen> >