X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fscreens_panel.cc;h=d5445b035a27c21aedcb7bf358617d48a337cf7d;hb=85be674b29dd61fe08a50f0b84c8402e9df61d94;hp=fbff896ca401581ac47104e75faf5a7438cd3714;hpb=082e4bd08f946c8f7dd2e05c7fc26dfefdc7e15f;p=dcpomatic.git diff --git a/src/wx/screens_panel.cc b/src/wx/screens_panel.cc index fbff896ca..d5445b035 100644 --- a/src/wx/screens_panel.cc +++ b/src/wx/screens_panel.cc @@ -26,6 +26,7 @@ #include "wx_util.h" #include "lib/cinema.h" #include "lib/config.h" +#include "lib/scope_guard.h" #include "lib/screen.h" #include "lib/timer.h" #include @@ -44,6 +45,9 @@ using std::shared_ptr; using std::string; using std::vector; using boost::optional; +#if BOOST_VERSION >= 106100 +using namespace boost::placeholders; +#endif using namespace dcpomatic; @@ -67,6 +71,8 @@ ScreensPanel::ScreensPanel (wxWindow* parent) add_cinemas (); + auto side_buttons = new wxBoxSizer (wxVERTICAL); + auto target_buttons = new wxBoxSizer (wxVERTICAL); _add_cinema = new Button (this, _("Add Cinema...")); @@ -82,7 +88,18 @@ ScreensPanel::ScreensPanel (wxWindow* parent) _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); + side_buttons->Add (target_buttons, 0, 0); + + auto check_buttons = new wxBoxSizer (wxVERTICAL); + + _check_all = new Button (this, _("Check all")); + check_buttons->Add (_check_all, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); + _uncheck_all = new Button (this, _("Uncheck all")); + check_buttons->Add (_uncheck_all, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); + + side_buttons->Add (check_buttons, 1, wxEXPAND | wxTOP, DCPOMATIC_BUTTON_STACK_GAP * 8); + + targets->Add (side_buttons, 0, 0); sizer->Add (targets, 1, wxEXPAND); @@ -98,6 +115,9 @@ ScreensPanel::ScreensPanel (wxWindow* parent) _edit_screen->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::edit_screen_clicked, this)); _remove_screen->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::remove_screen_clicked, this)); + _check_all->Bind (wxEVT_BUTTON, boost::bind(&ScreensPanel::check_all, this)); + _uncheck_all->Bind (wxEVT_BUTTON, boost::bind(&ScreensPanel::uncheck_all, this)); + SetSizer (sizer); UErrorCode status = U_ZERO_ERROR; @@ -107,6 +127,8 @@ ScreensPanel::ScreensPanel (wxWindow* parent) ucol_setAttribute(_collator, UCOL_STRENGTH, UCOL_PRIMARY, &status); ucol_setAttribute(_collator, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status); } + + _config_connection = Config::instance()->Changed.connect(boost::bind(&ScreensPanel::config_changed, this, _1)); } @@ -121,6 +143,32 @@ ScreensPanel::~ScreensPanel () } +void +ScreensPanel::check_all () +{ + for (auto cinema = _targets->GetFirstChild(_targets->GetRootItem()); cinema.IsOk(); cinema = _targets->GetNextSibling(cinema)) { + _targets->CheckItem(cinema, wxCHK_CHECKED); + for (auto screen = _targets->GetFirstChild(cinema); screen.IsOk(); screen = _targets->GetNextSibling(screen)) { + _targets->CheckItem(screen, wxCHK_CHECKED); + set_screen_checked(screen, true); + } + } +} + + +void +ScreensPanel::uncheck_all () +{ + for (auto cinema = _targets->GetFirstChild(_targets->GetRootItem()); cinema.IsOk(); cinema = _targets->GetNextSibling(cinema)) { + _targets->CheckItem(cinema, wxCHK_UNCHECKED); + for (auto screen = _targets->GetFirstChild(cinema); screen.IsOk(); screen = _targets->GetNextSibling(screen)) { + _targets->CheckItem(screen, wxCHK_UNCHECKED); + set_screen_checked(screen, false); + } + } +} + + void ScreensPanel::setup_sensitivity () { @@ -183,18 +231,27 @@ ScreensPanel::add_screen (shared_ptr cinema, shared_ptr screen) void ScreensPanel::add_cinema_clicked () { - auto d = new CinemaDialog (GetParent(), _("Add Cinema")); - if (d->ShowModal () == wxID_OK) { - auto cinema = make_shared(d->name(), d->emails(), d->notes(), d->utc_offset_hour(), d->utc_offset_minute()); + auto dialog = new CinemaDialog (GetParent(), _("Add Cinema")); + ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + + if (dialog->ShowModal() == wxID_OK) { + auto cinema = make_shared(dialog->name(), dialog->emails(), dialog->notes(), dialog->utc_offset_hour(), dialog->utc_offset_minute()); auto cinemas = Config::instance()->cinemas(); cinemas.sort( [this](shared_ptr a, shared_ptr 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 item; for (auto existing_cinema: cinemas) { - if (!item && compare(d->name(), existing_cinema->name) < 0) { + if (!item && compare(dialog->name(), existing_cinema->name) < 0) { if (auto existing_item = cinema_to_item(existing_cinema)) { item = add_cinema (cinema, *existing_item); } @@ -209,11 +266,9 @@ ScreensPanel::add_cinema_clicked () _targets->UnselectAll (); _targets->Select (*item); } - - Config::instance()->add_cinema (cinema); } - d->Destroy (); + selection_changed (); } @@ -238,23 +293,22 @@ ScreensPanel::edit_cinema_clicked () return; } - auto d = new CinemaDialog ( + auto dialog = new CinemaDialog( GetParent(), _("Edit cinema"), cinema->name, cinema->emails, cinema->notes, cinema->utc_offset_hour(), cinema->utc_offset_minute() ); - - if (d->ShowModal() == wxID_OK) { - cinema->name = d->name(); - cinema->emails = d->emails(); - cinema->notes = d->notes(); - cinema->set_utc_offset_hour(d->utc_offset_hour()); - cinema->set_utc_offset_minute(d->utc_offset_minute()); + ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + + if (dialog->ShowModal() == wxID_OK) { + cinema->name = dialog->name(); + cinema->emails = dialog->emails(); + 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(d->name())); - Config::instance()->changed (Config::CINEMAS); + _targets->SetItemText (*item, std_to_wx(dialog->name())); } - - d->Destroy (); } @@ -290,35 +344,34 @@ ScreensPanel::add_screen_clicked () return; } - auto d = new ScreenDialog (GetParent(), _("Add Screen")); - if (d->ShowModal () != wxID_OK) { - d->Destroy (); + auto dialog = new ScreenDialog(GetParent(), _("Add Screen")); + ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + + if (dialog->ShowModal () != wxID_OK) { return; } for (auto screen: cinema->screens()) { - if (screen->name == d->name()) { + if (screen->name == dialog->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() + std_to_wx(dialog->name()).data() ) ); return; } } - auto screen = std::make_shared(d->name(), d->notes(), d->recipient(), d->recipient_file(), d->trusted_devices()); + auto screen = std::make_shared(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); - - d->Destroy (); } @@ -331,7 +384,7 @@ ScreensPanel::edit_screen_clicked () auto edit_screen = _selected_screens[0]; - auto d = new ScreenDialog ( + auto dialog = new ScreenDialog( GetParent(), _("Edit screen"), edit_screen->name, edit_screen->notes, @@ -339,37 +392,36 @@ ScreensPanel::edit_screen_clicked () edit_screen->recipient_file, edit_screen->trusted_devices ); + ScopeGuard sg = [dialog]() { dialog->Destroy(); }; - if (d->ShowModal() != wxID_OK) { - d->Destroy (); + if (dialog->ShowModal() != wxID_OK) { return; } auto cinema = edit_screen->cinema; for (auto screen: cinema->screens()) { - if (screen != edit_screen && screen->name == d->name()) { + if (screen != edit_screen && screen->name == dialog->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() + std_to_wx(dialog->name()).data() ) ); return; } } - edit_screen->name = d->name(); - edit_screen->notes = d->notes(); - edit_screen->recipient = d->recipient(); - edit_screen->recipient_file = d->recipient_file(); - edit_screen->trusted_devices = d->trusted_devices(); + edit_screen->name = dialog->name(); + edit_screen->notes = dialog->notes(); + 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(d->name())); - Config::instance()->changed (Config::CINEMAS); - - d->Destroy (); + _targets->SetItemText (*item, std_to_wx(dialog->name())); } @@ -393,7 +445,7 @@ ScreensPanel::remove_screen_clicked () _targets->DeleteItem(*item); } - Config::instance()->changed (Config::CINEMAS); + notify_cinemas_changed(); } @@ -401,15 +453,7 @@ vector> ScreensPanel::screens () const { vector> output; - - for (auto item = _targets->GetFirstItem(); item.IsOk(); item = _targets->GetNextItem(item)) { - if (_targets->GetCheckedState(item) == wxCHK_CHECKED) { - if (auto screen = item_to_screen(item)) { - output.push_back (screen); - } - } - } - + std::copy (_checked_screens.begin(), _checked_screens.end(), std::back_inserter(output)); return output; } @@ -462,7 +506,7 @@ ScreensPanel::add_cinemas () void -ScreensPanel::search_changed () +ScreensPanel::clear_and_re_add() { _targets->DeleteAllItems (); @@ -472,6 +516,13 @@ ScreensPanel::search_changed () _screen_to_item.clear (); add_cinemas (); +} + + +void +ScreensPanel::search_changed () +{ + clear_and_re_add(); _ignore_selection_change = true; @@ -624,3 +675,31 @@ 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() +{ + _ignore_cinemas_changed = true; + ScopeGuard sg = [this]() { _ignore_cinemas_changed = false; }; + + 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; +} + + +void +ScreensPanel::config_changed(Config::Property property) +{ + if (property == Config::Property::CINEMAS && !_ignore_cinemas_changed) { + clear_and_re_add(); + } +} + +