Prevent duplicate screen names within a cinema (#1007).
authorCarl Hetherington <cth@carlh.net>
Thu, 17 Nov 2016 01:28:27 +0000 (01:28 +0000)
committerCarl Hetherington <cth@carlh.net>
Thu, 17 Nov 2016 01:28:27 +0000 (01:28 +0000)
ChangeLog
src/wx/screens_panel.cc

index 3a3a5f5a0a1542f3d65f3b795507d33fb52764f8..efd31871fa663a599ecf3c213e76fc9e84b6f556 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2016-11-17  Carl Hetherington  <cth@carlh.net>
+
+       * Prevent duplicate screen names within a cinema (#1007).
+
 2016-11-16  Carl Hetherington  <cth@carlh.net>
 
        * Version 2.10.1 released.
index 6643632642b0ff6b6dd223e7621f4e0d2c6f8b80..3fabba46a567221f312e658c01350ca934e8df80 100644 (file)
@@ -205,9 +205,23 @@ ScreensPanel::add_screen_clicked ()
 
        ScreenDialog* d = new ScreenDialog (GetParent(), _("Add Screen"));
        if (d->ShowModal () != wxID_OK) {
+               d->Destroy ();
                return;
        }
 
+       BOOST_FOREACH (shared_ptr<Screen> i, c->screens ()) {
+               if (i->name == d->name()) {
+                       error_dialog (
+                               GetParent(),
+                               wxString::Format (
+                                       _("You cannot add a screen called '%s' as the cinema already has a screen with this name."),
+                                       std_to_wx(d->name()).data()
+                                       )
+                               );
+                       return;
+               }
+       }
+
        shared_ptr<Screen> s (new Screen (d->name(), d->recipient(), d->trusted_devices()));
        c->add_screen (s);
        optional<wxTreeItemId> id = add_screen (c, s);
@@ -230,15 +244,32 @@ ScreensPanel::edit_screen_clicked ()
        pair<wxTreeItemId, shared_ptr<Screen> > s = *_selected_screens.begin();
 
        ScreenDialog* d = new ScreenDialog (GetParent(), _("Edit screen"), s.second->name, s.second->notes, s.second->recipient, s.second->trusted_devices);
-       if (d->ShowModal () == wxID_OK) {
-               s.second->name = d->name ();
-               s.second->notes = d->notes ();
-               s.second->recipient = d->recipient ();
-               s.second->trusted_devices = d->trusted_devices ();
-               _targets->SetItemText (s.first, std_to_wx (d->name()));
-               Config::instance()->changed ();
+       if (d->ShowModal () != wxID_OK) {
+               d->Destroy ();
+               return;
        }
 
+       shared_ptr<Cinema> c = s.second->cinema;
+       BOOST_FOREACH (shared_ptr<Screen> i, c->screens ()) {
+               if (i != s.second && i->name == d->name()) {
+                       error_dialog (
+                               GetParent(),
+                               wxString::Format (
+                                       _("You cannot change this screen's name to '%s' as the cinema already has a screen with this name."),
+                                       std_to_wx(d->name()).data()
+                                       )
+                               );
+                       return;
+               }
+       }
+
+       s.second->name = d->name ();
+       s.second->notes = d->notes ();
+       s.second->recipient = d->recipient ();
+       s.second->trusted_devices = d->trusted_devices ();
+       _targets->SetItemText (s.first, std_to_wx (d->name()));
+       Config::instance()->changed ();
+
        d->Destroy ();
 }