X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fscreens_panel.cc;h=8db7a10355f14400e806baa134cf8acd18f17dde;hb=5d7ba3c7717288b13cb8b286474382580f3bdba9;hp=03c07e1c89728e22a4377c568edfca1c9c2a14c4;hpb=068291b7233b01573863d7fb5eda2a82883c748d;p=dcpomatic.git diff --git a/src/wx/screens_panel.cc b/src/wx/screens_panel.cc index 03c07e1c8..8db7a1035 100644 --- a/src/wx/screens_panel.cc +++ b/src/wx/screens_panel.cc @@ -1,29 +1,31 @@ /* - Copyright (C) 2015-2016 Carl Hetherington + Copyright (C) 2015-2018 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + DCP-o-matic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with DCP-o-matic. If not, see . */ -#include "lib/config.h" -#include "lib/cinema.h" -#include "lib/screen.h" #include "screens_panel.h" #include "wx_util.h" #include "cinema_dialog.h" #include "screen_dialog.h" +#include "dcpomatic_button.h" +#include "lib/config.h" +#include "lib/cinema.h" +#include "lib/screen.h" #include using std::list; @@ -34,6 +36,7 @@ using std::string; using std::make_pair; using boost::shared_ptr; using boost::optional; +using namespace dcpomatic; ScreensPanel::ScreensPanel (wxWindow* parent) : wxPanel (parent, wxID_ANY) @@ -51,42 +54,42 @@ ScreensPanel::ScreensPanel (wxWindow* parent) add_cinemas (); - wxGridSizer* target_buttons = new wxGridSizer (2, DCPOMATIC_BUTTON_STACK_GAP * 2, DCPOMATIC_SIZER_Y_GAP); - - _add_cinema = new wxButton (this, wxID_ANY, _("Add Cinema...")); - target_buttons->Add (_add_cinema, 1, wxEXPAND); - _add_screen = new wxButton (this, wxID_ANY, _("Add Screen...")); - target_buttons->Add (_add_screen, 1, wxEXPAND); - _edit_cinema = new wxButton (this, wxID_ANY, _("Edit Cinema...")); - target_buttons->Add (_edit_cinema, 1, wxEXPAND); - _edit_screen = new wxButton (this, wxID_ANY, _("Edit Screen...")); - target_buttons->Add (_edit_screen, 1, wxEXPAND); - _remove_cinema = new wxButton (this, wxID_ANY, _("Remove Cinema")); - target_buttons->Add (_remove_cinema, 1, wxEXPAND); - _remove_screen = new wxButton (this, wxID_ANY, _("Remove Screen")); - target_buttons->Add (_remove_screen, 1, wxEXPAND); + wxBoxSizer* target_buttons = new wxBoxSizer (wxVERTICAL); + + _add_cinema = new Button (this, _("Add Cinema...")); + target_buttons->Add (_add_cinema, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); + _edit_cinema = new Button (this, _("Edit Cinema...")); + target_buttons->Add (_edit_cinema, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); + _remove_cinema = new Button (this, _("Remove Cinema")); + target_buttons->Add (_remove_cinema, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); + _add_screen = new Button (this, _("Add Screen...")); + target_buttons->Add (_add_screen, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); + _edit_screen = new Button (this, _("Edit Screen...")); + target_buttons->Add (_edit_screen, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); + _remove_screen = new Button (this, _("Remove Screen")); + target_buttons->Add (_remove_screen, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); targets->Add (target_buttons, 0, 0); sizer->Add (targets, 1, wxEXPAND); - _search->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&ScreensPanel::search_changed, this)); - _targets->Bind (wxEVT_COMMAND_TREE_SEL_CHANGED, &ScreensPanel::selection_changed_shim, this); + _search->Bind (wxEVT_TEXT, boost::bind (&ScreensPanel::search_changed, this)); + _targets->Bind (wxEVT_TREE_SEL_CHANGED, &ScreensPanel::selection_changed_shim, this); - _add_cinema->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&ScreensPanel::add_cinema_clicked, this)); - _edit_cinema->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&ScreensPanel::edit_cinema_clicked, this)); - _remove_cinema->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&ScreensPanel::remove_cinema_clicked, this)); + _add_cinema->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::add_cinema_clicked, this)); + _edit_cinema->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::edit_cinema_clicked, this)); + _remove_cinema->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::remove_cinema_clicked, this)); - _add_screen->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&ScreensPanel::add_screen_clicked, this)); - _edit_screen->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&ScreensPanel::edit_screen_clicked, this)); - _remove_screen->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&ScreensPanel::remove_screen_clicked, this)); + _add_screen->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::add_screen_clicked, this)); + _edit_screen->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::edit_screen_clicked, this)); + _remove_screen->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::remove_screen_clicked, this)); SetSizer (sizer); } ScreensPanel::~ScreensPanel () { - _targets->Unbind (wxEVT_COMMAND_TREE_SEL_CHANGED, &ScreensPanel::selection_changed_shim, this); + _targets->Unbind (wxEVT_TREE_SEL_CHANGED, &ScreensPanel::selection_changed_shim, this); } void @@ -146,7 +149,7 @@ ScreensPanel::add_screen (shared_ptr c, shared_ptr s) void ScreensPanel::add_cinema_clicked () { - CinemaDialog* d = new CinemaDialog (this, _("Add Cinema")); + CinemaDialog* d = new CinemaDialog (GetParent(), _("Add Cinema")); if (d->ShowModal () == wxID_OK) { shared_ptr c (new Cinema (d->name(), d->emails(), d->notes(), d->utc_offset_hour(), d->utc_offset_minute())); Config::instance()->add_cinema (c); @@ -166,7 +169,7 @@ ScreensPanel::edit_cinema_clicked () pair > c = *_selected_cinemas.begin(); CinemaDialog* d = new CinemaDialog ( - this, _("Edit cinema"), c.second->name, c.second->emails, c.second->notes, c.second->utc_offset_hour(), c.second->utc_offset_minute() + GetParent(), _("Edit cinema"), c.second->name, c.second->emails, c.second->notes, c.second->utc_offset_hour(), c.second->utc_offset_minute() ); if (d->ShowModal () == wxID_OK) { @@ -176,7 +179,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 (); @@ -202,19 +205,33 @@ ScreensPanel::add_screen_clicked () shared_ptr c = _selected_cinemas.begin()->second; - ScreenDialog* d = new ScreenDialog (this, _("Add Screen")); + ScreenDialog* d = new ScreenDialog (GetParent(), _("Add Screen")); if (d->ShowModal () != wxID_OK) { + d->Destroy (); return; } - shared_ptr s (new Screen (d->name(), d->recipient(), d->trusted_devices())); + BOOST_FOREACH (shared_ptr 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 s (new Screen (d->name(), d->notes(), d->recipient(), d->trusted_devices())); c->add_screen (s); optional id = add_screen (c, s); if (id) { _targets->Expand (id.get ()); } - Config::instance()->changed (); + Config::instance()->changed (Config::CINEMAS); d->Destroy (); } @@ -228,16 +245,33 @@ ScreensPanel::edit_screen_clicked () pair > s = *_selected_screens.begin(); - ScreenDialog* d = new ScreenDialog (this, _("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 (); + 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) { + d->Destroy (); + return; } + shared_ptr c = s.second->cinema; + BOOST_FOREACH (shared_ptr 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 (Config::CINEMAS); + d->Destroy (); } @@ -263,7 +297,7 @@ ScreensPanel::remove_screen_clicked () _targets->Delete (i->first); } - Config::instance()->changed (); + Config::instance()->changed (Config::CINEMAS); } list >