summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-08-30 22:28:03 +0200
committerCarl Hetherington <cth@carlh.net>2022-08-30 22:28:03 +0200
commitb16b0da184b349c9565a9e556b22164a2a158970 (patch)
treee85341d3df89ebfd69bacf4ae593d515b7b0d1ec
parent963a684d107f7135e6680c2ed7f88e8aa5810ea1 (diff)
Handle failures to write cinemas.xml more nicely.
-rw-r--r--src/wx/screens_panel.cc36
-rw-r--r--src/wx/screens_panel.h1
2 files changed, 30 insertions, 7 deletions
diff --git a/src/wx/screens_panel.cc b/src/wx/screens_panel.cc
index fa9373e36..6fb954252 100644
--- a/src/wx/screens_panel.cc
+++ b/src/wx/screens_panel.cc
@@ -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;
+}
+
+
diff --git a/src/wx/screens_panel.h b/src/wx/screens_panel.h
index ae730c2df..7c72f5873 100644
--- a/src/wx/screens_panel.h
+++ b/src/wx/screens_panel.h
@@ -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;