X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fscreens_panel.cc;h=042fcc5ab58184b9f39041c800b03b4daa81f275;hb=234623db3306626520e06cac985eb157379eff99;hp=a081e2dfccff4f80b7d8d64cedd2b2d7c14c72c1;hpb=c55877926307d7018942beb5fd65a39f278e05de;p=dcpomatic.git diff --git a/src/wx/screens_panel.cc b/src/wx/screens_panel.cc index a081e2dfc..042fcc5ab 100644 --- a/src/wx/screens_panel.cc +++ b/src/wx/screens_panel.cc @@ -1,19 +1,20 @@ /* - Copyright (C) 2015 Carl Hetherington + Copyright (C) 2015-2016 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 . */ @@ -33,6 +34,7 @@ using std::map; using std::string; using std::make_pair; using boost::shared_ptr; +using boost::optional; ScreensPanel::ScreensPanel (wxWindow* parent) : wxPanel (parent, wxID_ANY) @@ -50,30 +52,27 @@ ScreensPanel::ScreensPanel (wxWindow* parent) add_cinemas (); - _targets->ExpandAll (); - wxBoxSizer* target_buttons = new wxBoxSizer (wxVERTICAL); _add_cinema = new wxButton (this, wxID_ANY, _("Add Cinema...")); - target_buttons->Add (_add_cinema, 1, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP); + target_buttons->Add (_add_cinema, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); _edit_cinema = new wxButton (this, wxID_ANY, _("Edit Cinema...")); - target_buttons->Add (_edit_cinema, 1, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP); + target_buttons->Add (_edit_cinema, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); _remove_cinema = new wxButton (this, wxID_ANY, _("Remove Cinema")); - target_buttons->Add (_remove_cinema, 1, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP); - + target_buttons->Add (_remove_cinema, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); _add_screen = new wxButton (this, wxID_ANY, _("Add Screen...")); - target_buttons->Add (_add_screen, 1, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP); + target_buttons->Add (_add_screen, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); _edit_screen = new wxButton (this, wxID_ANY, _("Edit Screen...")); - target_buttons->Add (_edit_screen, 1, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP); + target_buttons->Add (_edit_screen, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); _remove_screen = new wxButton (this, wxID_ANY, _("Remove Screen")); - target_buttons->Add (_remove_screen, 1, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP); + 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, this); + _targets->Bind (wxEVT_COMMAND_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)); @@ -88,7 +87,7 @@ ScreensPanel::ScreensPanel (wxWindow* parent) ScreensPanel::~ScreensPanel () { - _targets->Unbind (wxEVT_COMMAND_TREE_SEL_CHANGED, &ScreensPanel::selection_changed, this); + _targets->Unbind (wxEVT_COMMAND_TREE_SEL_CHANGED, &ScreensPanel::selection_changed_shim, this); } void @@ -98,11 +97,11 @@ ScreensPanel::setup_sensitivity () bool const ss = _selected_screens.size() == 1; _edit_cinema->Enable (sc); - _remove_cinema->Enable (sc); + _remove_cinema->Enable (_selected_cinemas.size() >= 1); _add_screen->Enable (sc); _edit_screen->Enable (ss); - _remove_screen->Enable (ss); + _remove_screen->Enable (_selected_screens.size() >= 1); } void @@ -129,7 +128,7 @@ ScreensPanel::add_cinema (shared_ptr c) _targets->SortChildren (_root); } -void +optional ScreensPanel::add_screen (shared_ptr c, shared_ptr s) { CinemaMap::const_iterator i = _cinemas.begin(); @@ -138,19 +137,19 @@ ScreensPanel::add_screen (shared_ptr c, shared_ptr s) } if (i == _cinemas.end()) { - return; + return optional (); } _screens[_targets->AppendItem (i->first, std_to_wx (s->name))] = s; - _targets->Expand (i->first); + return i->first; } void ScreensPanel::add_cinema_clicked () { - CinemaDialog* d = new CinemaDialog (this, "Add Cinema"); + CinemaDialog* d = new CinemaDialog (this, _("Add Cinema")); if (d->ShowModal () == wxID_OK) { - shared_ptr c (new Cinema (d->name(), d->emails())); + shared_ptr c (new Cinema (d->name(), d->emails(), d->notes(), d->utc_offset_hour(), d->utc_offset_minute())); Config::instance()->add_cinema (c); add_cinema (c); } @@ -167,10 +166,16 @@ ScreensPanel::edit_cinema_clicked () pair > c = *_selected_cinemas.begin(); - CinemaDialog* d = new CinemaDialog (this, "Edit cinema", c.second->name, c.second->emails); + 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() + ); + if (d->ShowModal () == wxID_OK) { c.second->name = d->name (); c.second->emails = d->emails (); + c.second->notes = d->notes (); + 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 (); } @@ -181,14 +186,12 @@ ScreensPanel::edit_cinema_clicked () void ScreensPanel::remove_cinema_clicked () { - if (_selected_cinemas.size() != 1) { - return; + for (CinemaMap::iterator i = _selected_cinemas.begin(); i != _selected_cinemas.end(); ++i) { + Config::instance()->remove_cinema (i->second); + _targets->Delete (i->first); } - pair > c = *_selected_cinemas.begin(); - - Config::instance()->remove_cinema (c.second); - _targets->Delete (c.first); + selection_changed (); } void @@ -200,14 +203,17 @@ ScreensPanel::add_screen_clicked () shared_ptr c = _selected_cinemas.begin()->second; - ScreenDialog* d = new ScreenDialog (this, "Add Screen"); + ScreenDialog* d = new ScreenDialog (this, _("Add Screen")); if (d->ShowModal () != wxID_OK) { return; } shared_ptr s (new Screen (d->name(), d->recipient(), d->trusted_devices())); c->add_screen (s); - add_screen (c, s); + optional id = add_screen (c, s); + if (id) { + _targets->Expand (id.get ()); + } Config::instance()->changed (); @@ -223,9 +229,10 @@ ScreensPanel::edit_screen_clicked () pair > s = *_selected_screens.begin(); - ScreenDialog* d = new ScreenDialog (this, "Edit screen", s.second->name, s.second->recipient, s.second->trusted_devices); + 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())); @@ -238,29 +245,25 @@ ScreensPanel::edit_screen_clicked () void ScreensPanel::remove_screen_clicked () { - if (_selected_screens.size() != 1) { - return; - } + for (ScreenMap::iterator i = _selected_screens.begin(); i != _selected_screens.end(); ++i) { + CinemaMap::iterator j = _cinemas.begin (); + while (j != _cinemas.end ()) { + list > sc = j->second->screens (); + if (find (sc.begin(), sc.end(), i->second) != sc.end ()) { + break; + } - pair > s = *_selected_screens.begin(); - - CinemaMap::iterator i = _cinemas.begin (); - while (i != _cinemas.end ()) { - list > sc = i->second->screens (); - if (find (sc.begin(), sc.end(), s.second) != sc.end ()) { - break; + ++j; } - ++i; - } + if (j == _cinemas.end()) { + continue; + } - if (i == _cinemas.end()) { - return; + j->second->remove_screen (i->second); + _targets->Delete (i->first); } - i->second->remove_screen (s.second); - _targets->Delete (s.first); - Config::instance()->changed (); } @@ -287,7 +290,13 @@ ScreensPanel::screens () const } void -ScreensPanel::selection_changed (wxTreeEvent &) +ScreensPanel::selection_changed_shim (wxTreeEvent &) +{ + selection_changed (); +} + +void +ScreensPanel::selection_changed () { if (_ignore_selection_change) { return;