Handle failures to write cinemas.xml more nicely.
authorCarl Hetherington <cth@carlh.net>
Tue, 30 Aug 2022 20:28:03 +0000 (22:28 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 30 Aug 2022 20:28:03 +0000 (22:28 +0200)
src/wx/screens_panel.cc
src/wx/screens_panel.h

index fa9373e36bb7252c06b8e8b2ad3cca21750005b9..6fb9542526874c75e1f05c27144dc2f886eb2a3a 100644 (file)
@@ -237,6 +237,13 @@ ScreensPanel::add_cinema_clicked ()
                        [this](shared_ptr<Cinema> a, shared_ptr<Cinema> b) { return compare(a->name, b->name) < 0; }
                        );
 
+               try {
+                       Config::instance()->add_cinema(cinema);
+               } catch (FileError& e) {
+                       error_dialog(GetParent(), _("Could not write cinema details to the cinemas.xml file.  Check that the location of cinemas.xml is valid in DCP-o-matic's preferences."), std_to_wx(e.what()));
+                       return;
+               }
+
                optional<wxTreeListItem> item;
                for (auto existing_cinema: cinemas) {
                        if (!item && compare(dialog->name(), existing_cinema->name) < 0) {
@@ -254,8 +261,6 @@ ScreensPanel::add_cinema_clicked ()
                        _targets->UnselectAll ();
                        _targets->Select (*item);
                }
-
-               Config::instance()->add_cinema (cinema);
        }
 
        selection_changed ();
@@ -294,10 +299,10 @@ ScreensPanel::edit_cinema_clicked ()
                cinema->notes = dialog->notes();
                cinema->set_utc_offset_hour(dialog->utc_offset_hour());
                cinema->set_utc_offset_minute(dialog->utc_offset_minute());
+               notify_cinemas_changed();
                auto item = cinema_to_item(cinema);
                DCPOMATIC_ASSERT(item);
                _targets->SetItemText (*item, std_to_wx(dialog->name()));
-               Config::instance()->changed (Config::CINEMAS);
        }
 }
 
@@ -356,12 +361,12 @@ ScreensPanel::add_screen_clicked ()
 
        auto screen = std::make_shared<Screen>(dialog->name(), dialog->notes(), dialog->recipient(), dialog->recipient_file(), dialog->trusted_devices());
        cinema->add_screen (screen);
+       notify_cinemas_changed();
+
        auto id = add_screen (cinema, screen);
        if (id) {
                _targets->Expand (id.get ());
        }
-
-       Config::instance()->changed (Config::CINEMAS);
 }
 
 
@@ -407,10 +412,11 @@ ScreensPanel::edit_screen_clicked ()
        edit_screen->recipient = dialog->recipient();
        edit_screen->recipient_file = dialog->recipient_file();
        edit_screen->trusted_devices = dialog->trusted_devices();
+       notify_cinemas_changed();
+
        auto item = screen_to_item(edit_screen);
        DCPOMATIC_ASSERT (item);
        _targets->SetItemText (*item, std_to_wx(dialog->name()));
-       Config::instance()->changed (Config::CINEMAS);
 }
 
 
@@ -434,7 +440,7 @@ ScreensPanel::remove_screen_clicked ()
                _targets->DeleteItem(*item);
        }
 
-       Config::instance()->changed (Config::CINEMAS);
+       notify_cinemas_changed();
 }
 
 
@@ -657,3 +663,19 @@ ScreensPanel::compare (string const& utf8_a, string const& utf8_b)
                return strcoll(utf8_a.c_str(), utf8_b.c_str());
        }
 }
+
+
+bool
+ScreensPanel::notify_cinemas_changed()
+{
+       try {
+               Config::instance()->changed(Config::CINEMAS);
+       } catch (FileError& e) {
+               error_dialog(GetParent(), _("Could not write cinema details to the cinemas.xml file.  Check that the location of cinemas.xml is valid in DCP-o-matic's preferences."), std_to_wx(e.what()));
+               return false;
+       }
+
+       return true;
+}
+
+
index ae730c2df4c43caecd6a79ab9b00a65d3cfff38f..7c72f587362eb0544e269aa87f1eb45518ccab4c 100644 (file)
@@ -71,6 +71,7 @@ private:
        int compare (std::string const& utf8_a, std::string const& utf8_b);
        void check_all ();
        void uncheck_all ();
+       bool notify_cinemas_changed();
 
        std::shared_ptr<Cinema> item_to_cinema (wxTreeListItem item) const;
        std::shared_ptr<dcpomatic::Screen> item_to_screen (wxTreeListItem item) const;